Author Topic: Playing stereo files thru a single speaker?  (Read 3180 times)

SoundMike

  • Posts: 331
Does the BASS_DEVICE_MONO init flag only apply to MP1/2/3's (like the BASS_SAMPLE_MONO flag on create stream)?  I initialized a device with BASS_DEVICE_MONO and tried to create a stream from a stereo file, and set speaker assignment for Front Left, but for a WAV or WMA file I get error 42 (unavailable speaker).  Works OK with an MP3 file.

If only MP1/2/3's can be handled like this, can you suggest another way for me to play stereo files of other types thru a mono channel?

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Playing stereo files thru a single speaker?
« Reply #1 on: 1 Feb '06 - 13:12 »
You can use a decoding channel (BASS_STREAM_DECODE) and custom stream (BASS_StreamCreate) combo to play stereo files in mono. Your STREAMPROC would look something like this...

Code: [Select]
DWORD CALLBACK Stereo2MonoProc(HSTREAM handle, void *buffer, DWORD length, DWORD user)
{
short *buf=buffer; // assuming 16-bit sample data (short)
short *temp=malloc(length*2); // allocate decoding buffer (stereo = twice the size of mono)
int a, c=BASS_ChannelGetData(user, temp, length*2); // decode data (user = decoding channel)
for (a=0; a<c/4; a++)
buf[a]=(temp[a*2]+temp[a*2+1])/2; // stereo -> mono
free(temp);
return c/2;
}

SoundMike

  • Posts: 331
Re: Playing stereo files thru a single speaker?
« Reply #2 on: 2 Feb '06 - 08:48 »
Thanks, Ian.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: Playing stereo files thru a single speaker?
« Reply #3 on: 2 Feb '06 - 14:55 »
I forgot to mention that you could also use BASSmix to do it, instead of a custom stream...

Code: [Select]
mixer=BASS_Mixer_StreamCreate(freq, 1, 0); // create mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_DOWNMIX); // plug in the decoding channel

SoundMike

  • Posts: 331
Re: Playing stereo files thru a single speaker?
« Reply #4 on: 3 Feb '06 - 08:00 »
Even better :D especially as my development environment is VB - although that just puts off the day I'll need to include a C++ dll to efficiently handle some other STREAMPROC processing I want to do!