Page 1 of 2

better Sound System

Posted: Wed Mar 01, 2006 9:40 am
by Kazmirzak
Hy,

why is PureBasic so bad with sounds? You can only play one sound at a time!?

I would like to see a *real* sound system be integrated - maybe via openGL or DirectX or whatever. Even MCI would be a step forward!

Posted: Wed Mar 01, 2006 9:45 am
by Trond
You can play 10000 sounds at the same time if you've got enough hardware support.

Edit: The currect sound system uses DirectX. And OpenGL doens't have a sound system. And MCI is fully supported through API commands like mciSendString_().

Posted: Wed Mar 01, 2006 9:52 am
by Kazmirzak
with which version?

Posted: Wed Mar 01, 2006 9:54 am
by Trond
Any version. 3.94. 4.0. 3.72. Whatever!

Posted: Wed Mar 01, 2006 10:11 am
by Kazmirzak
ok, let me specify:

I just found out you can play more than one sound by doing multiple loadings.

But is doesn't work like this:

Code: Select all

sound=LoadSound(-1,"sound.wav")
Playsound(sound)
delay(100)
Playsound(sound)
delay(100)
Playsound(sound)
You should hear an echo effect but purebasic just stops the previous sound before playing the next. Do I have to load a sound 20 times to be able to do a tunnelecho effect? That doesn't seem very memory-saving!?

Posted: Wed Mar 01, 2006 10:18 am
by PB
For Windows, you can use the sndPlaySound API command to do it:

Code: Select all

sndPlaySound_(filename$,#SND_ASYNC)

Posted: Wed Mar 01, 2006 10:18 am
by Trond
With DirectX you need one sound buffer for each playing instance of the sound, yes.

Posted: Wed Mar 01, 2006 10:34 am
by Kazmirzak
No, sndPlaySound does only play one sound at a time (although asyncronious), I just checked out. Additionally this is bad for large files because you can't preload a sound with this command.

@Trond: This can't be true, because BlitzBasic uses DirectX7 and can play one loaded sound multiple times. It is based on channels -> each playing of a sound opens a new channel which can be paused, stopped etc...

channel1=Playsound(sound1)
delay(100)
channel2=Playsound(sound1)
delay(100)
stopchannel(channel2)

this way you have perfect control on sounds, can play them as often as you want, and all this is DX based... I would just like to do this in Pure too as I'm migrating to Pure...

Posted: Wed Mar 01, 2006 11:35 am
by PB
> sndPlaySound does only play one sound at a time

Oops, you're right. :oops: It seemed logical that the async state would allow more than one.

Posted: Wed Mar 01, 2006 12:53 pm
by Nik
The manual says:
PlaySound(#Sound [, Mode])

Description

Start to play the specified sound. 'Mode' is optional and can take the following value:

0: Play the sound only once (Default value when 'Mode' is ommitted)
1: Play the sound continuously (loop). Not available under Linux!

Then you have:
SoundFrequency()
SoundPan()
SoundVolume()
StopSound()

To influence the sound (even while it is playing)
You cann use :UseOGGSoundDecoder()
to play ogg sounds and the music library for mp3 files + you have the API so where is the problem

Posted: Wed Mar 01, 2006 1:38 pm
by Trond
Nik, he wants to play the same sound more than once at the same time.

Posted: Wed Mar 01, 2006 2:01 pm
by netmaestro
I think you can achieve your objective by:

Code: Select all

Enumeration 
  #firstinstance_MySound 
  #secondinstance_MySound 
  #thirdinstance_MySound 
EndEnumeration 

InitSound()
OpenWindow(0,0,0,320,240,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"")

CatchSound(#firstinstance_MySound, ?MySound) 
CatchSound(#secondinstance_MySound, ?MySound) 
CatchSound(#thirdinstance_MySound, ?MySound) 

PlaySound(#firstinstance_MySound) 
Delay(500) 
PlaySound(#secondinstance_Mysound) 
Delay(500) 
PlaySound(#thirdinstance_Mysound) 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
  
DataSection 
  MySound: IncludeBinary "MySound.wav" 
EndDataSection 
CatchSound() just points to the one soundfile, so this shouldn't add size to the exe or memory footprint. It just creates a separate channel for each instance.
I didn't test but it looks good to me. As long as they are different #sounds they should play concurrently.
[edit] OK I tested it. It works.

Posted: Wed Mar 01, 2006 3:50 pm
by Fred
No, catchsound() will duplicate the buffer. Actually it's a limitation you're right.

Posted: Wed Mar 01, 2006 4:52 pm
by Joakim Christiansen
Would you please do something about this Fred?
In GameMaker we could set a sound buffer for each file...

Posted: Wed Mar 01, 2006 7:38 pm
by dracflamloc
All comparisons to other tools and languages aside, this would be a nice feature. I've run into this issue a couple times making games. It can be worked around but at the cost of quite a bit of memory.

Also fred, please add looping to linux!