July 09, 2020, 10:11:19 AM

Author Topic: Sounds with Openb3dmax  (Read 228 times)

Offline matty47

  • Jr. Member
  • **
  • Posts: 2
Sounds with Openb3dmax
« on: May 26, 2020, 04:22:39 AM »
I'm on a MacBook.
the following code works
Code: [Select]
'playsound.bmx
Global run:TSound
Global chan:TChannel=AllocChannel()

run=LoadSound("water.wav",SOUND_LOOP)
PlaySound(run,chan)
SetChannelVolume(chan,0.5)

Graphics 640,480
Repeat

If KeyDown(KEY_ESCAPE)=True
End
EndIf

Flip
Forever

However when I try to add the Openb3dmax framework the sound fails to load - returns null. So this this code fails
Code: [Select]
'playsound.bmx
Framework Openb3dmax.B3dglgraphics
Import brl.audio

Global run:TSound
Global chan:TChannel=AllocChannel()

run=LoadSound("water.wav",SOUND_LOOP)
PlaySound(run,chan)
SetChannelVolume(chan,0.5)

Graphics 640,480
Repeat

If KeyDown(KEY_ESCAPE)=True
End
EndIf

Flip
Forever
Anyone know what I am doing wrong?
I tried adding Openb3dmax.audio but this did not work either.
Thanks in advance

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 77
Re: Sounds with Openb3dmax
« Reply #1 on: June 03, 2020, 05:23:36 PM »
I am not familiar with Mac at all, but for the sake of elimination have you tried with a different WAV ?

One that is natively played on the Mac?

The reason I suggest this is because it may be PCM encoded or a bit-depth that is incompatible for the MacBook soundchip.

_________________________
EDIT __

Sorry I misread the initial post, I was assuming you hada a similar code that worked on Windows but not on MacOS

Offline Derron

  • Hero Member
  • *****
  • Posts: 3034
Re: Sounds with Openb3dmax
« Reply #2 on: June 03, 2020, 06:01:21 PM »
When using the framework command you need to ensure to load all required "drivers".

There is
Brl.PNGLoader - if you want to load PNG files.
Brl.JPGLoader - to load JP(E)G files
... and ... *drum roll*
Brl.WAVLoader - to load WAV files


So right below your framework command, try to import the wavLoader:
Code: [Select]
'playsound.bmx
Framework Openb3dmax.B3dglgraphics
Import brl.audio
Import brl.wavloader '<--- eg. here

Global run:TSound
Global chan:TChannel=AllocChannel()
...


Using the "framework" command is a bit more advanced - there was some tool ("FA Assistant" or so - which scanned what modules you used and created the import statements for you) to do this but most oft the time you will do it on your own (as your project grows and you add functionality). This means the more you get used to it, the easier it comes. You just stepped into a little trap by copy pasting some example code not explaining this advanced stuff.

bye
Ron

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 465
Re: Sounds with Openb3dmax
« Reply #3 on: June 04, 2020, 01:22:55 PM »
Derron is right, you're not importing a module, you can use Import Openb3dmax.B3dglgraphics and then it will work, Framework is for when you want to reduce your app file size by only importing what you need, the compiler doesn't help you with this so you basically have to figure it out yourself.

Openb3dmax imports all images loaders by default but not audio drivers because it's platform dependent, in Windows you import Brl.DirectSoundAudio but in Mac/Linux you use Brl.FreeAudioAudio, the audio loaders are cross-platform so import Brl.WavLoader and/or Brl.OggLoader, then there's Brl.OpenAlAudio which is a cross-platform audio driver, if you're using this you need to make sure you change the default audio driver with SetAudioDriver or there will be no sound.

Also, the sound module's name is Openb3dmax.Audio3d as it's for 3d sound, it is actually the only Openb3dmax module you have to import, see Openb3dmax.docs sound for example. Here's you example working with Framework.

Code: [Select]
'playsound.bmx

Framework Openb3dmax.B3dglgraphics

' import BRL sound
?Not Win32
Import Brl.FreeAudioAudio
?Win32
Import Brl.DirectSoundAudio
?
Import Brl.WavLoader
Import Brl.OggLoader

' show available audio drivers
Local Drives:String[] = AudioDrivers()
For Local Drive:String = EachIn Drives
Print Drive
Next

Global run:TSound
Global chan:TChannel=AllocChannel()

run=LoadSound("media/sample.wav",SOUND_LOOP)
PlaySound(run,chan)
SetChannelVolume(chan,0.5)

Graphics3D 640,480,0,2

Repeat

If KeyDown(KEY_ESCAPE)=True
End
EndIf

Flip
Forever
Code: [Select]
'playsoundal.bmx

Framework Openb3dmax.B3dglgraphics

' import BRL sound
Import Brl.OpenAlAudio
?Not Win32
Import "-ldl" ' Linux fix
?
Import Brl.WavLoader
Import Brl.OggLoader

' show available audio drivers
Local Drives:String[] = AudioDrivers()
For Local Drive:String = EachIn Drives
Print Drive
Next

' change sound driver
If AudioDriverExists("OpenAL") Then SetAudioDriver("OpenAL")

Global run:TSound
Global chan:TChannel=AllocChannel()

run=LoadSound("media/sample.wav",SOUND_LOOP)
PlaySound(run,chan)
SetChannelVolume(chan,0.5)

Graphics3D 640,480,0,2

Repeat

If KeyDown(KEY_ESCAPE)=True
End
EndIf

Flip
Forever

PS: there's a bug in the OpenAL modules where in Linux you get the error: undefined reference to symbol 'dlsym' which is resolved by putting Import "-ldl" in Pub.Openal or Brl.Openalaudio. I haven't tested on Mac.

Offline matty47

  • Jr. Member
  • **
  • Posts: 2
Re: Sounds with Openb3dmax
« Reply #4 on: June 04, 2020, 11:55:04 PM »
Thanks all for the great advice. ;D

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal