Good to know about sound

Share your advanced PureBasic knowledge/code with the community.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Good to know about sound

Post by djes »

As I've spent several hours on this bug, let me share it. On some computers, playing a sound with a frequency > 44100 slows down everything. Don't ask me why ; I don't think it's a PB bug but an hardware problem. :roll:

Fred> it was the reason why the ball slowed down on white tiles ;) I've totally revamped the collision engine only for that, but it was NOT the collision engine! :cry:
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

The rule : always set the sampling freq according to the native sampling freq of your spu (ie : 48khz for a creative soundcard).
Despite this, crappy soundcard drivers can also be the cause ... (ie: hdaudio, ac97 ...)
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Wrong forum. Where's the PureBasic code? This is off-topic.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

KarLKoX wrote:The rule : always set the sampling freq according to the native sampling freq of your spu (ie : 48khz for a creative soundcard).
Despite this, crappy soundcard drivers can also be the cause ... (ie: hdaudio, ac97 ...)

I just wanted to use the same sound with different frequencies... I'll add this on my todo list : testing soundcard capabilities before using it. :)

Pseudo-code to not be "off topic" :twisted:

Code: Select all

;******************************************************************************************************
; Play specified sound specifying parameters
Procedure play_sound(sound.l, pan.l = -1, volume.l = -1, frequency.l = -1)

  If pan <> -1
  	SoundPan( sound, pan )
  EndIf

  If volume <> -1
  	SoundVolume( sound, volume )
  EndIf

  If frequency <> -1
   	SoundFrequency( sound, frequency )
  EndIf

	PlaySound( sound, #PB_Sound_MultiChannel )

EndProcedure

;******************************************************************************************************

InitSprite()
InitSound()

If LoadSound(0, "mysound.wav")
  
  ;OK
  play_sound(0, 0, 100, 44100)
  
  ;On some soundcards, pauses the program for some ms
  play_sound(0, 0, 100, 50000)
  
EndIf

End
Post Reply