Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Cannot create an ALLEGRO_VOICE object in Allegro5

Credits go to Edgar Reynaldo and Elias for helping out!
This thread is locked; no one can reply to it. rss feed Print
Cannot create an ALLEGRO_VOICE object in Allegro5
AgentBaron
Member #16,630
January 2017

I'm working on a game for Allegro 5 and I'm trying to get an ALLEGRO_VOICE object created:
m_voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);

The program will not make this, and Visual Studio likes to place it in memory address 0x00000000.

What I'm trying to do is create looping game music that will repeat itself after finishing an initial warm-up part. I do not know a good name for this kind of looping music. I suppose like this song.

Any alternative suggestions for how to accomplish this are welcome.

Elias
Member #358
May 2000

If you don't need a voice, just use the default mixer instead. Look for example here: https://github.com/liballeg/allegro5/blob/master/examples/ex_saw.c

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Member #8,592
May 2007
avatar

al_create_voice only fails when this fails :

al_create_voice said:

kcm_voice.c#SelectExpand
90 if (_al_kcm_driver->allocate_voice(voice) != 0) { 91 al_destroy_mutex(voice->mutex); 92 al_destroy_cond(voice->cond); 93 al_free(voice); 94 return NULL; 95 }

allocate_voice is a function pointer in the ALLEGRO_AUDIO_DRIVER structure. Its value depends on which audio driver you're using. Debug this in GDB and set a breakpoint in al_create_voice. Print out the value of _al_kcm_driver->allocate_voice to see which function it is calling. Then debug that function and so on. I can't do this right now because I'm not at home and I don't have easy access to GDB.

Short answer : It depends on which driver you're using.

AgentBaron
Member #16,630
January 2017

Thanks for the suggestions. I was able to use the default mixer without creating a voice, though for some reason trying to make a custom mixer results in pure and utter silence.

Since this is a project for school, I do not have the luxury of taking the time to troubleshoot as Edgar Reynaldo suggested. However, I will definitely look into this once my semester is over and post here any findings.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Thanks for the suggestions. I was able to use the default mixer without creating a voice, though for some reason trying to make a custom mixer results in pure and utter silence.

Did you remember to attach the mixer you created to the default voice?

AgentBaron
Member #16,630
January 2017

I actually did not attach anything to a default voice. I don't even see anything pooping up in my autocomplete. Is this a feature in Allegro 5.2.2? I am presently using a slightly out of date version.

I was able to get the sound working by attaching the samples to a default mixer, though. Is there a reason why a default mixer would give sound while a custom mixer gives silence?

Edgar Reynaldo
Member #8,592
May 2007
avatar

There is only one voice in allegro 5. If you don't attach your mixer to it, there will be no output from it. The voice is basically the hardware and outputs the sound. When you call al_reserve_samples, a default voice and mixer are created for you. Otherwise you have to create your own, which you've had problems with IIRC.

Elias
Member #358
May 2000

The default mixer is already attached to the default voice. So if you do nothing sound already will work. ALLEGRO_VOICE is only needed in very special situations - in fact could probably say it is a mis-feature we only still have for historic reasons.

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Member #8,592
May 2007
avatar

Go to: