OpenAL extension - 3D audio, pitch, doppler effect and other stuff

#22

No worries, I am glad it’s working! Can’t wait for the windows support.

3 Likes

#23

Can anyone explain why one of this file (menu_text_types_out_02.wav) is played by this extension much more quietly then other (gem.wav)?
Standard Defold API play those files equally loud.
Archive.zip (20.2 KB)

p.s. macOS, happens only on desktop build. On iPhone sounds played equally.

0 Likes

#24

I’ve just tried your files on macOS and the menu*.wav file actually sounds a bit louder than the gem.wav.
Not sure what it could be in your case.

0 Likes

#25

gem is 44100Hz and menu_text_ is 22050Hz

Test this version of gem and see if that difference matters?
gem.zip (11.0 KB)

1 Like

#26

The point is to play menu_text… as loud as gem.wav (and the rest of files), not other way around. Or just to know why it is so quiet. I try to resample it, normalize it, etc… No effect.

0 Likes

#27

I guess make sure that the position of the source is correct. The further the sound source from the listener, the quieter the sound will be.

0 Likes

#28

Yes, but if lowering the rate makes them sound the same then you know the Hz difference may be the cause. I looked at the files and didn’t see anything else which may cause it.

0 Likes

#29

I was able to compile the extension for HTML5, but it’s not producing any sound yet. However, it does the initialization. Further work is needed.

4 Likes

#30

Still working on the HTML5 version. There is sound output, but it’s not positioned or pitched for some reason. Trying to figure this one out.

2 Likes

#31

So the current JavaScript implementation of OpenAL for HTML5 is not stable, it lacks certain features like the doppler effect, pitch modification and changing the speed of sound. On Chrome it crashes with an error “missing function panner.setVelocity”. Different browsers have slightly different underlying audio API.

But sooner or later these issues will be resolved. I believe I can supply my own OpenAL wrapper as a JavaScript library, that would be the next step.

In the meantime, I’ve updated the extension source code on github and you can try HTML5 support for yourself.

Open in Firefox or Safari. https://lerg.github.io/extension-openal/

4 Likes

Save shelter (old school fps) #CoronaDefoldJam
#32

Can anybody please try the extension on Windows? And see if it just works?

0 Likes

#33

I’ve made some minor modifications to make it compile and run on windows.
Pull request on github.

7 Likes

Play url-loaded sound
#34

Yay! Thanks.
Just merged your pull request.

Awesome, now this extension runs on all platforms. But HTML5 version needs work.

0 Likes

#35

Awesome extension, thanks for it. :+1:
I add it to my game and have some questions:
1)When i add my wav files, i get ERROR:openal: Invalid WAV data header. How can i fixed it?
2)In html looks like, sound volume not decresed when i move away from sound source.
3)You have a lot of distance_model. What is diference of them?
4)What is rolloff_factor?

function on_message(self, message_id, message, sender)
    if(message_id==hashes.CONTROLLER_SPAWN_3D_SOUNDS)then
        local sounds=world.map.data.sounds_3d
        pprint(sounds)
        for i,sound in ipairs(sounds) do
            local sound_source = openal.new_source(SOUNDS[sound.sound])
            sound_source.reference_distance=2
            sound_source.rolloff_factor=50
            --sound_source.max_distance=4
            sound_source.x, sound_source.y = sound.x +0.5  , sound.y +0.5
            sound_source.is_looping = true
            sound_source:play()
            sources[i]=sound_source
         end	
    end	
end
6 Likes

#36

HTML has issues, haven’t finished it yet. Distance models calculate how exactly sound becomes quieter with distance. There are formulas in OpenAL reference, but you can pick one that just sounds better for you. “_clamped” means at max_distance the sound is muted.

Rolloff controls how far the sound goes, can’t tell exactly how.

Resave WAV files with Audacity, should help.

5 Likes

#37

What about support of OGG or stream playing for big files (1 minute and longer)?

0 Likes

#38

Streaming requires a bit more complex coding to manage buffers and OGG support need a decoder library integration. Not something that can be implemented easily.

0 Likes

#39

Regarding stereo sound, is there any possibility to create a ‘dead space’ around an object, where both left and right speakers will be playing a looped sound and only will have 3D effects far (for example right speaker is working while far away from the center of the object to the right)? Now, in an example there is a ‘line’ (pos.x) on which I can’t stand with a listener to ‘feel’ like really near to the campfire, but instead, the listener is always on the right or left side of the campfire and the sound is always on the right or left side.

0 Likes

#40

If you play with various settings, should be possible. Can’t tell for sure which ones.

0 Likes

#41

Any plan to integrate the OpenAl extension into the core of Defold? The audio department still feels a bit too basic and could use some love.

1 Like