Sound for OpenB3D using openAL

Started by angros47, October 24, 2019, 23:56:57

Previous topic - Next topic

angros47

I saw several attempts to provide 3d sound to minib3d and OpenB3D. So, I made a port to C++:

https://sourceforge.net/projects/minib3d/files/OS3D%20pre-alpha.zip/download

In this way, it could be used both in BlitzMax and in other languages. It can load .wav, .mp3, .flac and .ogg files, and it supports the "classic" features (3d sound, and Doppler effect), plus some new ones, like occlusion/obstruction/exclusion using OpenB3D geometry, and reverberation zones.

Kippykip

Awesome! I've been using FMOD in my OpenB3D project, I basically just followed the examples and made some types that handle distance from the camera, and added two pivots spaced left + right of the TCamera and do a bit of panning depending which pivot is closest to the sound entity. If it's blocked by a wall then it reduces the volume by 50%.
[yt_search]https://www.youtube.com/watch?v=lBbqYEsbG2s[/yt_search]

This is the module I'm using:
https://github.com/maxmods/bah.mod/tree/master/fmod.mod

angros47

#2
Interesting. My library allows to set any reduction of volume (not just 50%), and since it happens through a lowpass filter, low frequencies are less attenuated than high frequencies (as it happens in a real situation). To decide the volume of attenuated sound, you can use the last parameter of CreateListener (1: no attenuation, 0: sound is totally attenuated, behind an obstacle). To check if there is any obstacle, EntityVisible is used, so the obstacle must be a pickable entity.

Regarding the command CreateListener: the first three parameters (Entity, Rolloff factor, and Doppler scale) are supposed to work more or less like in Blitz3D. Differently from Blitz3D, there is no Distance Scale parameter, since such a parameter would make more sense if it is individually set for each entity: bigger entities would require a different scale factor than smaller ones; for that reason, distance scale is estimated according to the ScaleX factor of every entity that emits sounds.

Another difference is that, instead of having a SoundLoop parameter, the command EmitSound has an optional loop parameter: in this way, the same sound can be made looping for one entity, and not looping for another.

Commands like PauseChannel, ResumeChannel and StopChannel are not implemented, since they would just be aliases to alSourcePause, alSourcePlay and alSourceStop, so a simple macro would do the trick.

I am aware that FMOD is a very complete sound library, and it is the first choice for many engines: still, it is a proprietary solution, and its usage is not free for commercial applications. For that reason, I preferred to develop a free, and open source solution, based on open source resources (OpenAL)

Kippykip

Quote from: angros47 on October 27, 2019, 17:05:18
Interesting. My library allows to set any reduction of volume (not just 50%), and since it happens through a lowpass filter, low frequencies are less attenuated than high frequencies (as it happens in a real situation). To decide the volume of attenuated sound, you can use the last parameter of CreateListener (1: no attenuation, 0: sound is totally attenuated, behind an obstacle). To check if there is any obstacle, EntityVisible is used, so the obstacle must be a pickable entity.

Regarding the command CreateListener: the first three parameters (Entity, Rolloff factor, and Doppler scale) are supposed to work more or less like in Blitz3D. Differently from Blitz3D, there is no Distance Scale parameter, since such a parameter would make more sense if it is individually set for each entity: bigger entities would require a different scale factor than smaller ones; for that reason, distance scale is estimated according to the ScaleX factor of every entity that emits sounds.

Another difference is that, instead of having a SoundLoop parameter, the command EmitSound has an optional loop parameter: in this way, the same sound can be made looping for one entity, and not looping for another.

Commands like PauseChannel, ResumeChannel and StopChannel are not implemented, since they would just be aliases to alSourcePause, alSourcePlay and alSourceStop, so a simple macro would do the trick.

I am aware that FMOD is a very complete sound library, and it is the first choice for many engines: still, it is a proprietary solution, and its usage is not free for commercial applications. For that reason, I preferred to develop a free, and open source solution, based on open source resources (OpenAL)
Yeah I really need audio streaming and being able to measure DB's, which FMOD was the only one I could find with these implemented in BMX.
If OpenAL gets full support with the above then I'll be changing straight to that lmao

angros47

What do mean with streaming? You want to be able to stream audio to other sources (like a chromecast)? Or to be able to play a stream (like an audio message coming from another user in real time?)

Also, the solution you used for panning is pretty clever, although it's not real 3d sound, since it would do nothing to simulate a sound coming from a source in front, or behind the listener, and it would do nothing to simulate the phase difference for each ear. Also, it could not take advantage form a system with more than two speakers. Your solution is stereo audio, not 3d audio (FMOD could provide 3d audio as well)

Derron

Streamed Audio for me means to eg play a longer ogg music file without having to load and completely decode it first.
So this also means one could play from a remote stream (some http(s)-ressource).


bye
Ron

angros47

I see. But would you need that for 3d sound? In theory it could be done, in OpenAL, by splitting the audio stream into several buffers, and using alSourceQueueBuffers . So far, I never tried. Usually modern system have enough memory to load some minutes of uncompressed audio (also, a 3d audio source has to be mono, so it would take less memory)

Does FMOD offers streaming to sources for 3d audio?

Or all you need is a way to play a long stream of background music, with no 3d effect?

Derron

Dunno what kippykip requires - I just chimed in to mention what "streamed audio" could mean.

Regardless of "modern systems" or not: streamed ogg/mp3/... files also mean you could load them from the internet - while playing. Eg you could play back an internet radio stream.



bye
Ron

angros47

I see. But it's not in the scope of my library. Also, any user who would like to listen an internet radio while playing could just open a web page (or a dedicated program) in background, there is no need to integrate such a function in the game itself

markcwm

Re: streamed audio, I was planning on using MaxMod2 by RedEye but the NG repo seems to need a major update as it uses an older version that only does WAV + OGG and I couldn't get it to work. What you probably want is the GoogleCode archive v1.07 but it doesn't do MP3 so maybe that's out for you, it does do FLAC which is a great open-source alternative to MP3.

Derron

#10
@ Internet radio
It was just an example of what streamed audio could mean - no mean to take this too serious. Maybe people want to stream their audio from a webservice (some live stream in game).
Also loading music files means
- load one by one with a delay on loading
- loading all in and use a lot of memory (assume 30 music tracks with 4 minutes = 120 minutes of uncompressed data = 900 MB audio or so)

In my game TVTower I allow players to extend audio playlists (so it chooses random tracks for a certain "area/screen" in the game). Could mean a lot of files to get loaded and decoded during startup/initialization.



@ markcwm
Yes, Brucey only ported what was needed (by me ;)). I am using "maxmod2" with NG + ogg on Windows (for Linux my streamed audio based on the Blitzmax-freeaudio seems to work without "cracklings").
Feel free to raise issues on github or a new thread here - as the current version compiles here and is in use (it played audio this morning :)).


bye
Ron

angros47

Just to make the scope of this library clear: in original Blitz3D, there are some commands related to sound that are used also in BlitzBasic, and some commands that are related to 3d sounds, that are prerogative of Blitz3D.

Just as OpenB3D implements the 3d graphic commands, but not the 2d ones (since there are already other modules for that), this library implements only the commands related to 3d sound. Commands like PlayCDTrack or similar stuff are not planned.

Kippykip

Quote from: angros47 on October 28, 2019, 20:33:11
I see. But would you need that for 3d sound? In theory it could be done, in OpenAL, by splitting the audio stream into several buffers, and using alSourceQueueBuffers . So far, I never tried. Usually modern system have enough memory to load some minutes of uncompressed audio (also, a 3d audio source has to be mono, so it would take less memory)

Does FMOD offers streaming to sources for 3d audio?

Or all you need is a way to play a long stream of background music, with no 3d effect?
I use it for dynamic music in my game that has a big playlist for Idle/Action music (kind of like Oblivion).
Not having realtime streaming causes a big stutter and a lot of ram usage whenever a track changes otherwise.
For the actual 3D sounds I just load the whole thing, which I've also noticed that loading say .OGG files uses far less ram usage than the native FreeAudio driver BMX uses.

angros47

Dynamic music, in my opinion, worked well with Midi music, or with FM synthesized music (like the original SCUMM engine did, for example... or also Wing Commander). In Wing commander, the music after a mission was always the same, but it was played in sad, or triumphant way, depending on how successful mission was. It was achieved by changing instruments, speed, and so on, while keeping the same notes

Kippykip

Quote from: angros47 on October 31, 2019, 22:10:10
Dynamic music, in my opinion, worked well with Midi music, or with FM synthesized music (like the original SCUMM engine did, for example... or also Wing Commander). In Wing commander, the music after a mission was always the same, but it was played in sad, or triumphant way, depending on how successful mission was. It was achieved by changing instruments, speed, and so on, while keeping the same notes
Yeah I really liked how Star Wars: Dark Forces did it for MS-Dos, depending on the action the midi would really smoothly transition into this battle/intense music.