Page 1 of 1

Playing .wav file

Posted: Mon Feb 20, 2006 6:37 pm
by MikeB

Code: Select all

If InitSound()
	ls = LoadSound(1,"C:\Documents and Settings\All Users\Documents\My Music\xxxx.wav")
	If ls <> 0
		Debug IsSound(1)
		;SoundVolume(1,100)
		;SoundFrequency(1,20000)
		PlaySound(1)
		Delay(30000)
	EndIf
EndIf
The above code works for all the .wav files that I have in the directory, except for one. I have tried varying the volume and sound setting to see if it can make anything happen, but all I ever get is a click and then nothing. The file plays with no problem with Windows Media Player and Creative Wave Studio, I have even loaded it into Wave Studio and re-saved it to see if that helps, but it still won't play. The properties says it has a bit rate of 352kbps, 16 bit sample size, 1 channel mono, 22 kHz sample rate and PCM format. It is a large sample at 2,161,210 bytes, but I have another at 7,251,492 bytes that plays with no problem, so it's not that.
Any ideas?

Posted: Mon Feb 20, 2006 6:57 pm
by josku_x
I think it's because other formats.. THey can all be PCM, but one of them may be RIFF or something else. It can also be that PureBasic's sound library can't play the file.

Try to play the file with this code: (I made this with hurry!)

Code: Select all

Procedure.s GetShortFileName(LongFileName$)
 Static ShortPathName$, RetVal, iLen
 ShortPathName$ = Space(256)
 iLen = Len(ShortPathName$)
 RetVal = GetShortPathName_(LongFileName$, ShortPathName$, iLen)
 ShortFileName$ = Left(ShortPathName$, RetVal)
ProcedureReturn ShortFileName$
EndProcedure
Procedure MCI_OpenWaveFile(Alias$, FileName$)
 ShortName$=GetShortFileName(FileName$)
 Command=mciSendString_("open "+Chr(34)+FileName$+Chr(34)+" type waveaudio alias "+Alias$, 0, 0, 0)
If Command=0
 ProcedureReturn #True
Else
 ProcedureReturn #False
EndIf
EndProcedure
Procedure MCI_Close(Alias$)
ProcedureReturn mciSendString_("close " + Alias$, 0, 0, 0)
EndProcedure
Procedure MCI_Play(Alias$, Loop)
If Loop>=1
 Command=mciSendString_("play "+Alias$+" repeat", 0, 0, 0)
ElseIf Loop<=0
 Command=mciSendString_("play "+Alias$, 0, 0, 0)
EndIf
ProcedureReturn Command
EndProcedure

Sound$=OpenFileRequester("","","Wave|*.wav",0)

MCI_OpenWaveFile("MySound", Sound$)
MCI_Play("MySound", 1)
 MessageRequester("Mini-Media PLayer", "Currently playing: "+GetFilePart(Sound$))
MCI_Close("MySound") ; Never forget to close the file or the computer will hang.

Posted: Mon Feb 20, 2006 9:10 pm
by MikeB
Thanks for the try josku_x, but I'm afraid that there must be an error somewhere as I have copied and pasted your code and it opens the FileRequester and then the MessageRequester shows the filename, but nothing plays no matter which .wav file I have selected.

Posted: Mon Feb 20, 2006 9:14 pm
by Roger
I needed some extra sound functionality too (check if a sound was playing or not) and found this on the german boards:

http://forums.purebasic.com/german/viewtopic.php?t=1820

The guy who wrote that post has made a number of procedures you can use to get more information about your sound files...

Posted: Tue Feb 21, 2006 12:12 am
by MikeB
It looks as though there is something about this wave file that PB does not like, as the bit from the German forum plays everything else, but not the file in question, which is incidentally the definition of the "Pan Galactic Gargleblaster" from "Hitch-hikers Guide to the Galaxy". Anyway I am grateful for the link as it is a good way to get a program to pause while the sound is playing when you don't know the length of the file.

Posted: Tue Feb 21, 2006 4:53 am
by Hatonastick
I had a similar problem occur when I tried to play a sound that was less than 1k in size. :) However in that case it seemed to be a problem with the library as I added some blank space to take it to over 1k, saved exact same file type and it worked fine. I get the feeling the PureBASIC sound library does some odd things.