Author Topic: [SOLVED] Encoding a mixer stream creates no output  (Read 2238 times)

konikos

  • Posts: 8
I try to mix two streams (microphone and float sample data) and encode the mix.
I do something like this:

Code: [Select]
recordStream := BASS_RecordStart(44100, 2, BASS_RECORD_PAUSE, nil, nil);
BASS_ChannelPlay(self.recordStream, FALSE);
musicStream := BASS_StreamCreate(44100, 2,
    BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT, STREAMPROC_DUMMY, nil);
mixStream := BASS_Mixer_StreamCreate(44100, 2, BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mixStream, musicStream, BASS_MIXER_BUFFER);

encoder := BASS_Encode_Start(mixStream, 'C:\\Temp\\bass.wav',
    BASS_ENCODE_PCM or BASS_ENCODE_AUTOFREE, nil, nil);
BASS_ChannelPlay(encoder, FALSE);

...

// Feed the data to the dummy stream
BASS_ChannelGetData(self.musicStream, samples,
    sampleSize or BASS_DATA_FLOAT);


No call to BASS fails, but the wav file is empty. Any ideas why?
« Last Edit: 28 Jun '11 - 16:31 by konikos »

radio42

  • Posts: 4576
Re: Encoding a mixer stream creates no output
« Reply #1 on: 26 Jun '11 - 20:26 »
You can not 'play' an encoder.
You need to 'play' the mixer (mixStream) instead.
But as the mixer is a decoding one, you would need to call BASS_ChannelGetData on it to pull any data from it and as such feed the encoder.

konikos

  • Posts: 8
Re: Encoding a mixer stream creates no output
« Reply #2 on: 27 Jun '11 - 07:57 »
I see my mistake, but can't the data from the mixer be automatically be fed to the encoder?

radio42

  • Posts: 4576
Re: Encoding a mixer stream creates no output
« Reply #3 on: 27 Jun '11 - 09:12 »
Yes, it can, but only if you do not make the mixer stream a decoding one and as such 'play' the mixer in real-time.
Else, you must always call BASS_ChannelGetData manually.

konikos

  • Posts: 8
Re: Encoding a mixer stream creates no output
« Reply #4 on: 27 Jun '11 - 19:08 »
So, is this the right solution? I try the next but I get clicks in the created file and the output file is much longer than the input

Code: [Select]
recordStream := BASS_RecordStart(44100, 2, BASS_RECORD_PAUSE, nil, nil);
BASS_ChannelPlay(self.recordStream, FALSE);
BASS_Mixer_StreamAddChannel(mixStream, recordStream, BASS_MIXER_BUFFER);
musicStream := BASS_StreamCreate(44100, 2,
    BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT, STREAMPROC_DUMMY, nil);
mixStream := BASS_Mixer_StreamCreate(44100, 2, BASS_STREAM_DECODE);
BASS_Mixer_StreamAddChannel(mixStream, musicStream, BASS_MIXER_BUFFER);

encoder := BASS_Encode_Start(mixStream, 'C:\\Temp\\bass.wav',
    BASS_ENCODE_PCM or BASS_ENCODE_AUTOFREE, nil, nil);

...

// Feed the data to the dummy stream
BASS_ChannelGetData(self.musicStream, samples,
    sampleSize or BASS_DATA_FLOAT);
BASS_ChannelGetData(mixStream, encBuffer, sampleSize);
BASS_Encode_Write(encoder, encBuffer, sampleSize);


I also tried without the recordStream with no luck. What am I doing wrong?
« Last Edit: 27 Jun '11 - 20:48 by konikos »

radio42

  • Posts: 4576
Re: Encoding a mixer stream creates no output
« Reply #5 on: 28 Jun '11 - 05:25 »
There would be no need to call "BASS_Encode_Write", as setting up an encoder on a mixer stream is like using a DSP.
The encoding is done automatically when you pull data from the mixer by either playing it or calling BASS_ChannelGetData on it.

konikos

  • Posts: 8
Re: Encoding a mixer stream creates no output
« Reply #6 on: 28 Jun '11 - 08:14 »
First of all, thanks for your help so far.
I removed the call to BASS_Encoder_Write but only the record stream is going to the file, the dummy stream is not mixed. I tried with a push stream but it didn't work either. What I am doing wrong (again)?
« Last Edit: 28 Jun '11 - 08:20 by konikos »

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Encoding a mixer stream creates no output
« Reply #7 on: 28 Jun '11 - 14:37 »
It looks like a "push" stream (rather than a "dummy" stream) is what you want. The code above could be modified like this...

Code: [Select]
musicStream := BASS_StreamCreate(44100, 2,
    BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT, STREAMPROC_PUSH, nil);

...

// Feed the data to the push stream
BASS_StreamPutData(self.musicStream, samples, sampleSize);

konikos

  • Posts: 8
Re: Encoding a mixer stream creates no output
« Reply #8 on: 28 Jun '11 - 16:30 »
That solved my problem! Thank you!

aybe

  • Posts: 145
Re: Encoding a mixer stream creates no output
« Reply #9 on: 1 Mar '14 - 03:57 »
You can not 'play' an encoder.
You need to 'play' the mixer (mixStream) instead.
But as the mixer is a decoding one, you would need to call BASS_ChannelGetData on it to pull any data from it and as such feed the encoder.

Thank you, I was starting to become crazy as why does the file remains to a size of 9Kb ...  ;D