better Sound System

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

better Sound System

Post 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!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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_().
Last edited by Trond on Wed Mar 01, 2006 9:52 am, edited 1 time in total.
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post by Kazmirzak »

with which version?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Any version. 3.94. 4.0. 3.72. Whatever!
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post 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!?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

For Windows, you can use the sndPlaySound API command to do it:

Code: Select all

sndPlaySound_(filename$,#SND_ASYNC)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

With DirectX you need one sound buffer for each playing instance of the sound, yes.
Kazmirzak
User
User
Posts: 92
Joined: Fri Jun 18, 2004 5:44 pm
Location: Germany

Post 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...
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Nik, he wants to play the same sound more than once at the same time.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

No, catchsound() will duplicate the buffer. Actually it's a limitation you're right.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Would you please do something about this Fred?
In GameMaker we could set a sound buffer for each file...
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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!
Post Reply