Author Topic: Can not retrieve data from a decoding mixer  (Read 664 times)

aybe

  • Posts: 145
Can not retrieve data from a decoding mixer
« on: 16 Mar '12 - 21:38 »
I need to resample some audio to 11Khz mono;
The call to BASS_Mixer_ChannelGetData always returns 0 ...

Code: [Select]
            const string file = @"c:\audio.mp3";

            var init = !Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Handle);
            if (init) return;
            var stream = Bass.BASS_StreamCreateFile(file, 0, 0,
                                                    BASSFlag.BASS_SAMPLE_FLOAT |
                                                    BASSFlag.BASS_STREAM_DECODE);
            if (stream == 0) return;
            var mixer = BassMix.BASS_Mixer_StreamCreate(11025, 1,
                                                        BASSFlag.BASS_SAMPLE_FLOAT |
                                                        BASSFlag.BASS_STREAM_DECODE);
            if (mixer == 0) return;
            var add = BassMix.BASS_Mixer_StreamAddChannelEx(mixer, stream,
                                                            BASSFlag.BASS_MIXER_DOWNMIX |
                                                            BASSFlag.BASS_MIXER_BUFFER |
                                                            BASSFlag.BASS_MIXER_FILTER |
                                                            BASSFlag.BASS_MIXER_NORAMPIN,
                                                            0, 0);
            if (!add) return;
            const int samples = 11025 * 1; // 1 sec.
            const int length = samples * 4;
            var buffer = new float[samples];
            var getData = BassMix.BASS_Mixer_ChannelGetData(stream, buffer, length);
            if (getData == -1)
            {
                var bassErrorGetCode = Bass.BASS_ErrorGetCode();
            }

I tried specifying BASS_DATA_FLOAT flag but it's still the same.
Code: [Select]
var getData = BassMix.BASS_Mixer_ChannelGetData(stream, buffer, length | (int)BASSData.BASS_DATA_FLOAT);
Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 20424
Re: Can not retrieve data from a decoding mixer
« Reply #1 on: 19 Mar '12 - 15:11 »
You need to use BASS_ChannelGetData (with the mixer handle) there rather than BASS_Mixer_ChannelGetData.

aybe

  • Posts: 145
Re: Can not retrieve data from a decoding mixer
« Reply #2 on: 19 Mar '12 - 18:05 »
Great, it's working now !


What is the purpose of BassMix.BASS_Mixer_ChannelGetData then ?
I have read help many times but still don't understand since I couldn't make it work ...

This function is like the standard BASS_ChannelGetData, but it gets the data
from the channel's buffer instead of decoding it from the channel,
which means that the mixer does not miss out on any data.


Can you give a simple scenario where it should be used ?

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 20424
Re: Can not retrieve data from a decoding mixer
« Reply #3 on: 20 Mar '12 - 14:47 »
When the BASS_MIXER_BUFFER flag is used, the mixer will keep a copy of the latest data that it gets from the source, which is then made available to BASS_Mixer_ChannelGetData (and BASS_Mixer_ChannelGetLevel). BASS_Mixer_ChannelGetData doesn't get any data directly from the source, which is why nothing happened when you used it in the code above.

BASS_Mixer_ChannelGetData would typically be used for visualisation purposes, eg. if you want a spectrum display for the source channel. You couldn't use BASS_ChannelGetData in that case because doing that would be taking data away from the mixer, ie. the data that you take from the source for visualisation purposes would then not be available for the mixer to play.

aybe

  • Posts: 145
Re: Can not retrieve data from a decoding mixer
« Reply #4 on: 21 Mar '12 - 06:52 »
Ok I got it,

Thank you  :D :D