Homebrew [Q] How to play more than one sound at the same time?

LeifEricson

Coming Soon™
OP
Member
Joined
Jun 22, 2012
Messages
234
Trophies
0
Age
27
Location
New York, USA
Website
www.youtube.com
XP
534
Country
United States
I'm writing a new app and I'm trying to get sound effects to play over my music. However, whenever I call csndPlaySound more than once, even after playing two sounds on separate channels, the second sound always plays instead of the first sound.

Is there some sort of flag or something that I'm missing that will allow me to play multiple sounds at once?
 

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
You're probably doing something wrong. There are 24 channels usable by CSND. Just keep cycling through them. Something like this:

Code:
void Sound::play()
{
    if (!m_buffer || m_buffer->getSampleCount() == 0)
        return;

    // 24 possible CSND channels to cycle through (0-7) reserved for DSP
    static int channel;
    channel++;
    channel %= 24;

    u32 flags = SOUND_FORMAT_16BIT;
    if (m_loop)
        flags |= SOUND_REPEAT;
    u32 size = sizeof(Int16) * m_buffer->getSampleCount();
    GSPGPU_FlushDataCache(NULL, (u8*)m_buffer->getSamples(), size);
    csndPlaySound(channel+8, flags, m_buffer->getSampleRate(), 1.0, 0.0, (u32*)m_buffer->getSamples(), (u32*)m_buffer->getSamples(), size);
}
 
Last edited by TheCruel,
  • Like
Reactions: marc00077

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Sonic Angel Knight @ Sonic Angel Knight: I thought it was duck season, not... king kong season....