- Online Community Forums » Allegro Development » [5.0.5] Crash when trying to play the second instance of sound.

This thread is locked; no one can reply to it. rss feed Print
[5.0.5] Crash when trying to play the second instance of sound.
Max Savenkov
Member #4,613
May 2004

I must admit I find Allegro 5 sound interface somewhat confusing. Unlike it's graphic part, it seems somewhat low-level and requires some manual management. And somehow, lacks volume setting for anything, but single sample instance. But maybe I just don't have enough experience with sound APIs. I never tried incorporate sound in my games before. Anyway, I'm trying to write a wrapper for it for my "engine" (it's more of a collection of classes than a real game engine) and I ran into some problems.

Should I be able to attach to one mixer and play two instances of the same ALLEGRO_SAMPLE? When I try to do so, Allegro crashes.

A flattened code for this case looks like this:

1 if ( !al_install_audio() ) 2 return false; 3 4 if ( !al_init_acodec_addon() ) 5 return false; 6 7 m_pMusicVoice = al_create_voice( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 ); 8 m_pMusicMixer = al_create_mixer( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 ); 9 al_attach_mixer_to_voice( m_pMusicMixer, m_pMusicVoice ); 10 11 ALLEGRO_SAMPLE *m_pSample = al_load_sample( "music.ogg" ); 12 13 ALLEGRO_SAMPLE_INSTANCE *m_pInstance1 = al_create_sample_instance( m_pSample ); 14 ALLEGRO_SAMPLE_INSTANCE *m_pInstance2 = al_create_sample_instance( m_pSample ); 15 16 al_attach_sample_instance_to_mixer( m_pInstance1, m_pMusicMixer ); 17 al_attach_sample_instance_to_mixer( m_pInstance2, m_pMusicMixer ); 18 19 al_play_sample_instance( m_pInstance1 ); 20 _sleep( 500 ); 21 al_play_sample_instance( m_pInstance2 ); 22 _sleep( 10000 );

I expect this to either play music with a 500ms echo or assert somewhere inside Allegro with the message that I can't do this. Instead, I get crash at:

         case ALLEGRO_AUDIO_DEPTH_INT16:
            s[i] = buf->s16[(spl->pos>>MIXER_FRAC_SHIFT)*maxc + i];

I was unable to quickly determine which part of expression causes crash. s[i] seems valid.

So, the usual question. What am I doing wrong, or is this a bug in Allegro? I'm using monolith build of Allegro 5.0.5 on Windows 7 64-bit.

Matthew Leverton
Supreme Loser
January 1999

Should I be able to attach to one mixer and play two instances of the same ALLEGRO_SAMPLE?


The simpler API, by the way, looks like:


spl = al_load_sample(file);
al_play_sample(spl, gain, pan, speed, loop, NULL);

which is really no more difficult than Allegro 4.

Max Savenkov
Member #4,613
May 2004

Oh, thanks I misunderstood that part of documentation.

EDIT: That does not explain crash, though, so I would still like to get some response on that. Was I using API in the wrong way?

Also, there is a problem with al_play_sample, because you can't do anything with it after it has been started. It seems strange to me. I have SAMPLE_ID. I can stop it. Shouldn't I be able to adjust its gain, at least? Or is there any architectural problems which prevent me from doing this?

EDIT2: OK, I have found what led to crash. I was loading the same file into two different ALLEGRO_SAMPLEs, then creating an INSTANCE of each and trying to play them. While I still don't understand why should this crash library, now at least I can avoid this crash.

Go to: