Sound Arrays

BlitzPlus Forums/BlitzPlus Programming/Sound Arrays

siread(Posted 2006) [#1]
If I have an array of sounds similar to the following code:
Dim Sounds(3)

Sounds(1) = LoadSound("MySound1.mp3")
Sounds(2) = LoadSound("MySound2.mp3")
Sounds(3) = LoadSound("MySound3.mp3")

[Stuff Happens Here]

FreeSound Sounds(1)
FreeSound Sounds(2)
FreeSound Sounds(3)


Not a lot happens in the [Stuff Happens Here] section but something causes FreeSound to crash the program with: "Invalid Sound Handle". Even if I don't change the sounds, play the sounds or refer to the array at all it still crashes.

Of course, i must be doing something wrong but I can't find it for the life of me. Any ideas?


WolRon(Posted 2006) [#2]
Of course, i must be doing something wrong
Yep, you didn't verify that the sound was actually loaded...
.
.
.
Sounds(3) = LoadSound("MySound3.mp3")
For iter = 1 to 3
  If Sounds(iter) = 0 Then RunTimeError("Error, a required file is missing!")
Next



Grey Alien(Posted 2006) [#3]
sounds likely, also you may well be doing something funny in [stuff happens here].

I've made a file of common reuseable code which includes this:

Function ccLoadSample (ThePath$)
	pointer = LoadSound(ThePath$)
	If Not pointer Then
    	ccRunTimeError ("Error loading sample "+ThePath$)
		End
	Else 
    	Return Pointer	
  	EndIf	
End Function

Pretty much the same as Wolron's. I also do the same for bitmaps and other files.


sswift(Posted 2006) [#4]
Can blitzplus even play mp3 files? I only use ogg. It compresses better than mp3.


Grey Alien(Posted 2006) [#5]
Yeah, I've played mp3 files but every so often 1/20 it would stutter instead of play. Oggs seem fine, I used them instead of mp3 in Xmas Bonus.