News:

Function Finder  Find all the functions within source code files

Main Menu

Sound Question

Started by Big C., June 18, 2006, 10:59:50 AM

Previous topic - Next topic

Big C.

Hello,

I need a proposal for solution.

I have only one Soundfile which I would like to assign to 4 objects. Actually I would become that as follows does..
PlayBASIC Code: [Select]
Type TSound
SoundId
EndType

id = 1

Dim MySound(4) As TSound

sID = LoadNewSound("phaser.wav")

For i = 1 To 4
MySound(i).SoundId = sID
SoundFreq MySound(i).SoundId, RNDRange(22000, 44000)
Next i

Repeat

Cls 0

If id = 5
id = 1
EndIf

If GetSoundPlaying(MySound(id).SoundId) = 0
PlaySound MySound(id).SoundId
EndIf

Wait 150

Text 100, 50, "Sound playing Nr. " + Str$(id)

id = id + 1

Sync

Until EscKey()

End



If the first Soundfile of an object is played just, a second Soundfile can be played indeed simultaneously, however the Sound does not come before then if the first file was once completely played. That is, the Soundfiles become synchronous and in asynchronous mode not played.

I had had to rewrite therefore the code..
PlayBASIC Code: [Select]
Type TSound
SoundId
EndType

id = 1

Dim MySound(4) As TSound

For i = 1 To 4
MySound(i).SoundId = LoadNewSound("phaser.wav")
SoundFreq MySound(i).SoundId, RNDRange(22000, 44000)
Next i

Repeat

Cls 0

If id = 5
id = 1
EndIf

If GetSoundPlaying(MySound(id).SoundId) = 0
PlaySound MySound(id).SoundId
EndIf

Wait 150

Text 100, 50, "Sound playing Nr. " + Str$(id)

id = id + 1

Sync

Until EscKey()

End




Here the Soundfile was loaded into the memory 4 times and assigned to every individual object => asynchronous play

And now my question:

Is there a solution, as I can assign only one Soundfile several objects and can play every object independently of each other?

I ask because I want to increase the object number dynamically but I want to assign one loaded soundfile to Object numbers I have.

I hope you understand me.

Thx for your ideas/helps in advanced

Big C.

P.S. Download is broken so please use an own soundfile to test and modify the above code yourself

Big C.


eatfishy

I'm not sure about that...but I  can't get .mp3 to works...even thou I got .wav and .wma working fine Is this a bug or am I am stupid?

Big C.

#3
Hi eatfishy,

I wrap up some code for you... try this...

PlayBASIC Code: [Select]
MyMP3File$ = ".mp3" ; here your MP3-File
MyOGGFile$ = ".ogg";here your OGG-File

sID_MP3 = LoadNewSound(MyMP3File$)

PlaySound sID_MP3

Print "Playing " + MyMP3File$ + " as sound..."

Sync

WaitKey

WaitNoKey

StopSound sID_MP3

sID_OGG = LoadNewSound(MyOGGFile$)

PlaySound sID_OGG

Print "Playing " + MyOGGFile$ + " as sound..."

Sync

WaitKey

WaitNoKey

StopSound sID_OGG

DeleteAllSounds

sID_MP3_2 = LoadNewMusic(MyMP3File$)

PlayMusic sID_MP3_2

Print "Playing " + MyMP3File$ + " as music..."

Sync

WaitKey

WaitNoKey

StopMusic sID_MP3_2

sID_OGG_2 = LoadNewMusic(MyOGGFile$)

PlayMusic sID_OGG_2

Print "Playing " + MyOGGFile$ + " as music..."

Sync

WaitKey

StopMusic sID_OGG_2

DeleteAllMusics

End