Author Topic: ogg/wav 3D  (Read 2555 times)

PhoenixX_2

  • Posts: 40
ogg/wav 3D
« on: 30 Dec '07 - 04:27 »
It seems that calling BASS_SampleCreate() with BASS_SAMPLE_3D | BASS_SAMPLE_MONO with OGG and WAV files that are stereo to report the error BASS_ERROR_UNKNOWN.

It took a while for me to realize that stereo -> mono conversion is only supported for MP1, MP2 and MP3 files.  For some reason, calling the function with just BASS_SAMPLE_MONO seems to... work.

My users are often importing stereo wav and ogg sounds - and want them to act 3D.

I guess, what I'm asking, is if there'd be ANY way to make BASS_SAMPLE_3D work for stereo ogg and wav files, as it does so transparently with MP* files?  If not, can we at least have a better error so newcomers aren't baffled like I dumbly-on-my-part was ;)?

Ian @ un4seen

  • Administrator
  • Posts: 20426
Re: ogg/wav 3D
« Reply #1 on: 30 Dec '07 - 18:08 »
You could use BASSmix to downmix stereo (and above) files to mono, and then create a sample of that. Something like this...

Code: [Select]
HSAMPLE LoadSample3D(char *filename, DWORD maxplay)
{
HSTREAM decoder=BASS_StreamCreateFile(FALSE, filename, 0, 0, BASS_STREAM_DECODE|BASS_SAMPLE_MONO); // open file for decoding
if (!decoder) return 0; // failed
DWORD length=BASS_ChannelGetLength(decoder); // get the length
void *data=malloc(length); // allocate buffer for decoded data
BASS_CHANNELINFO ci;
BASS_ChannelGetInfo(decoder, &ci); // get sample format
if (ci.chans>1) { // not mono, downmix...
HSTREAM mixer=BASS_Mixer_StreamCreate(ci.freq, 1, BASS_STREAM_DECODE|BASS_MIXER_END); // create mono mixer
BASS_Mixer_StreamAddChannel(mixer, decoder, BASS_MIXER_DOWNMIX|BASS_MIXER_NORAMPIN|BASS_STREAM_AUTOFREE); // plug-in the decoder (auto-free with the mixer)
decoder=mixer; // decode from the mixer
}
length=BASS_ChannelGetData(decoder, data, length); // decode data
BASS_StreamFree(decoder); // free the decoder/mixer
HSAMPLE sample=BASS_SampleCreate(length, ci.freq, 1, maxplay, BASS_SAMPLE_3D); // create sample
BASS_SampleSetData(sample, data); // set the sample data
free(data); // free the buffer
return sample;
}

Note this is using BASS 2.4. The sample creation calls would be slightly different with 2.3.
« Last Edit: 2 Jan '08 - 15:47 by Ian @ un4seen »

PhoenixX_2

  • Posts: 40
Re: ogg/wav 3D
« Reply #2 on: 1 Jan '08 - 16:32 »
I didn't figure that BASS Mix would do this kind of stuff.  Awesome, thanks Ian :).

PhoenixX_2

  • Posts: 40
Re: ogg/wav 3D
« Reply #3 on: 1 Jan '08 - 17:40 »
Sorry to bug.  It seems after upgrading to 2.3.0.3 from 2.3.0.1, BASS_SAMPLE_3D | BASS_SAMPLE_MONO works on these multi-channel (2 or more) wav files, except the end result's flags are just BASS_SAMPLE_3D.  It not being mono, it shouldn't work with 3D, should it ?

Ian @ un4seen

  • Administrator
  • Posts: 20426
Re: ogg/wav 3D
« Reply #4 on: 2 Jan '08 - 15:47 »
Nope, it shouldn't be possible to enable 3D with anything other than mono samples, although BASS doesn't actually enforce that (DirectSound does). What does BASS_SampleGetInfo say about it, in particular the "flags" and "chans" BASS_SAMPLE members?

Actually, that reminds me, the code above should use the BASS_SAMPLE_MONO flag to avoid the use of BASSmix when it's unnecessary :)

PhoenixX_2

  • Posts: 40
Re: ogg/wav 3D
« Reply #5 on: 2 Jan '08 - 18:35 »
Sorry.  It seems that stereo wavs fail with unknown when using 3D+mono flags.  That's all good (minus the lame error).

However, what I should have said, is that when a mono wav succeeds when using 3D+mono flags, flags has 3D set but not mono set (however, chans does show it only has one channel).  Not sure if this is expected behaviour.  I assume it does not matter anymore with the coming release of 2.4 having channel count separate from flags, if I'm not mistaken.

I did get all the code to work - I was using VB6 anyway, so I only used your code as reference.  It seemed to have worked quite well, and it doesn't slow down the loading process all too heavily.

Thanks for the help, bass, bassmidi and now bassmix, Ian :).

Ian @ un4seen

  • Administrator
  • Posts: 20426
Re: ogg/wav 3D
« Reply #6 on: 4 Jan '08 - 14:17 »
However, what I should have said, is that when a mono wav succeeds when using 3D+mono flags, flags has 3D set but not mono set (however, chans does show it only has one channel).  Not sure if this is expected behaviour.  I assume it does not matter anymore with the coming release of 2.4 having channel count separate from flags, if I'm not mistaken.

Yep, since the "chans" member was added (in 2.2 ;)), the MONO flag is just a loading modifier.