Author Topic: Getting Unknown Error creating a 3D sample/stream  (Read 191 times)

somepotato

  • Posts: 6
I'm attempting to integrate BASS into my 3D engine -- but when I try to create a stream:
Code: [Select]
m_Handle = BASS_StreamCreateFile(FALSE, (void*)path, 0, 0, BASS_SAMPLE_MONO|BASS_SAMPLE_3D);
the handle is 0(error) and the error code is -1; is there anything I can do to help dig into why this might be the case? Thanks. (Oh and yeah, BASS_Init is called with the BASS_DEVICE_3D flag)

(sidenote: the (void*) was just to make sure the compiler wasn't being dumb and using the wchar_t codepath)

If you require any additional information, don't hesitate to ask.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #1 on: 3 Oct '17 - 13:40 »
To confirm whether it is causing the problem, does the BASS_StreamCreateFile call succeed if you remove the BASS_SAMPLE_3D flag? Please also upload the file in "path" to have a look at here:

   ftp.un4seen.com/incoming/

somepotato

  • Posts: 6
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #2 on: 3 Oct '17 - 22:07 »
It does work if I remove the 3D flag from the stream (while keeping the BASS_DEVICE_3D flag enabled in Init); I'm using this OGG to do my tests.

Thanks for the help!

Curiously, when I try to do this with samples, it takes awhile for the call to return (presumably it fully decodes it and everything), but still returns the unknown error, hinting that it might not be BASS's fault.
« Last Edit: 3 Oct '17 - 22:13 by somepotato »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #3 on: 4 Oct '17 - 16:41 »
Oh right, I see the problem now. That OGG file is stereo, while 3D channels need to be mono and the BASS_SAMPLE_MONO flag doesn't currently do anything to OGG files. The BASSmix add-on could be used to downmix stereo to mono, something like this:

Code: [Select]
m_Handle = BASS_StreamCreateFile(FALSE, (void*)path, 0, 0, BASS_STREAM_DECODE); // create decoder
BASS_CHANNELINFO ci;
BASS_ChannelGetInfo(m_Handle, &ci); // get its format
HSTREAM downmix = BASS_Mixer_StreamCreate(ci.freq, 1, BASS_MIXER_END|BASS_SAMPLE_3D); // create a mono mixer with same rate and 3D enabled
BASS_Mixer_StreamAddChannel(downmix, m_Handle, BASS_MIXER_NORAMPIN|BASS_MIXER_DOWNMIX); // plug in the decoder with downmixing enabled
BASS_ChannelPlay(downmix, FALSE); // start playing

If you happen to want to play only the left or right channel (or both separately), then you could use the BASSmix add-on's splitter feature instead, something like this:

Code: [Select]
m_Handle = BASS_StreamCreateFile(FALSE, (void*)path, 0, 0, BASS_STREAM_DECODE); // create decoder
int chanmap[2] = { 0, -1 }; // left channel only
HSTREAM split = BASS_Split_StreamCreate(m_Handle, BASS_SAMPLE_3D, chanmap); // create a splitter with 3D enabled
BASS_ChannelPlay(split, FALSE); // start playing

For the right channel, you would just change the 0 to 1 in "chanmap".

Please see the documentation for details on the mentioned functions.

somepotato

  • Posts: 6
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #4 on: 4 Oct '17 - 21:23 »
Ahh, didn't realize it didn't convert some files to mono; the mono flag in StreamCreateFile's documentation doesn't mention that limitation (for that matter the 3D limitation is only mentioned in SampleCreate).
What file formats does SAMPLE_MONO support? And do you know if BASS will support SAMPLE_MONO for OGGs in the upcoming future?

In the mean time it might be worth making the error code something easier to decode to avoid any headaches others might get upon attempting this.
Thanks for the heads up though!

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #5 on: 5 Oct '17 - 18:01 »
The BASS_SAMPLE_MONO flag currently only affects MP1/MP2/MP3, MOD, and MIDI files. And compressed WAV files when an ACM codec is used.

The function will fail with the BASS_ERROR_NO3D error code when attempting to enable 3D on a stereo file on other platforms, but BASS doesn't enforce that on Windows as I recall some drivers could handle the stereo/mono conversion back in the day. Internally, DirectSound is producing a generic error when asked to enable 3D on a stereo stream, which is resulting in the BASS_ERROR_UNKNOWN error code from BASS. But it's probably safe to assume what the problem is in that scenario, so I will have BASS treat it as a BASS_ERROR_NO3D error in the next update.

somepotato

  • Posts: 6
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #6 on: 5 Oct '17 - 20:26 »
Awesome, thanks for the heads up! I'd love to be able to use the mono flag on oggs because of the inherently better sound quality/smaller filesize (and using the mixer plugin only allows one channel while a game would ideally have multiple); however would it be possible for me to plug libopus or similar so I could add the support myself and allow multiple channels? I'm not entirely sure of the capabilities of the plugin system.

That being said, for development, I certainly can use MP3s in the meantime!

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #7 on: 6 Oct '17 - 17:29 »
You can have multiple mixers playing at the same time, but if you want to play a file multiple times (and assuming it isn't very large), it would be more efficient to downmix in advance and use the sample functions. Here's an old thread with some code that you could use for that:

   www.un4seen.com/forum/?topic=7962

If you are creating the audio files yourself, it would be even better (for reduced file size and processing) to make them mono to begin with :)

somepotato

  • Posts: 6
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #8 on: 6 Oct '17 - 23:49 »
Fair enough at making them mono to begin with but that's not always going to be easy (and for larger files precaching isn't going to be very viable because of user generated content); I'll figure something out though.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #9 on: 9 Oct '17 - 16:56 »
For convenience, here's an update that adds support for the BASS_SAMPLE_MONO flag to Ogg Vorbis files:

   www.un4seen.com/stuff/bass.zip

The BASS_SAMPLE_MONO flag support is extended further in BASS_SampleLoad to cover all file formats.

somepotato

  • Posts: 6
Re: Getting Unknown Error creating a 3D sample/stream
« Reply #10 on: 9 Oct '17 - 19:00 »
Awesome, thanks a lot! And thanks for updating the documentation too, hopefully it'll help others in the future.