Skip to main content
gamedev.net
🔒 Locked

Help on SDL sound

Started by svnstrk 1 reply 1.5k views
Original Post
svnstrk
svnstrk
hi,

Im trying to create a machine gun sound. So I have a gunshot.wav (about 1 second) that contains the gun sound and the echo. now since its a machine gun, i want to repeat the gunshot.wav every 0.5 second so the echo only heard at the last shot.

I've tried it with SDL but its not working. So I use one channel only (for test):


void SoundManager::playSound(int index) {
if (index != 0) {
return;
}

Mix_HaltChannel(0);
Mix_PlayChannel(0, mixChunkArr[index], 0);

}


each time the machine gun fire (2 shot per second) it call the playSound method, sending the same mixChunk index and playing at the same channel 0. But apparently this is not working properly. The sound only played when the previous song is finished. So its like hearing 1 shot per second machine gun rather than 2 shot per second.

How can I do this in SDL? Thanks in advance
Justindano
Justindano
You should probably give a try to

Mix_PlayChannelTimed(0, mixChunkArr[index], 0, int milliseconds);

Try and see if it works, Not sure.
svnstrk
svnstrk
nope its not working.

anyone?

also i can't seem to post on libsdl forum. i already registered and activate my account, but i can't post anything. Anyone here on libsdl forum? How can I contact the admin?


thanks in advance

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.