[A5RC4] some questions about the audio addon
wiseguy

OK, so I'm working on this alarm app, and having trouble with the audio addon. I installed everything from svn but I can't seem to figure out why I can't create an audio stream from an ogg file.

here is my code so far:

#SelectExpand
1 2#include <stdio.h> 3#include <stdlib.h> 4#include <time.h> 5#include <allegro5/allegro.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <allegro5/allegro_image.h> 8#include <allegro5/allegro_font.h> 9#include <allegro5/allegro_ttf.h> 10#include <allegro5/allegro_audio.h> 11#include <allegro5/allegro_acodec.h> 12 13int main(int argc, char *argv[]) 14{ 15 ALLEGRO_VOICE *voice; 16 ALLEGRO_MIXER *mixer; 17 ALLEGRO_AUDIO_STREAM *stream; 18 ALLEGRO_PATH *alarmSoundPath; 19 ALLEGRO_FONT *font; 20 ALLEGRO_DISPLAY *scr; 21 ALLEGRO_EVENT_QUEUE *eventQueue; 22 ALLEGRO_EVENT retEvent; 23 time_t rawtime; 24 bool exitFlag = false; 25 struct tm *timeinfo; 26 const char *alarmSoundFilename; 27 char testString[2048]; 28 char *workingDirectory; 29 char amPm[10]; 30 bool AMPM = false; // false = am, true = pm 31 int i; 32 int currentHour, currentMinutes, currentSeconds; 33 int alarmHour, alarmMinutes, alarmSeconds; 34 35 al_init(); 36 if (!al_install_mouse()) 37 { 38 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install mouse", NULL, 0); 39 exit(1); 40 } 41 if (!al_install_keyboard()) 42 { 43 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install keyboard", NULL, 0); 44 exit(1); 45 } 46 al_init_font_addon(); 47 if (!al_init_ttf_addon()) 48 { 49 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install ttf", NULL, 0); 50 exit(1); 51 } 52 if (!al_init_image_addon()) 53 { 54 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install image", NULL, 0); 55 exit(1); 56 } 57 if (!al_init_acodec_addon()) 58 { 59 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install acodec", NULL, 0); 60 exit(1); 61 } 62 if (!al_install_audio()) 63 { 64 al_show_native_message_box(NULL, "Error", "Init Error", "Could not install audio", NULL, 0); 65 exit(1); 66 } 67 68 workingDirectory = al_get_current_directory(); 69 if (workingDirectory==NULL) 70 { 71 al_show_native_message_box(NULL, "Error", "Init Error", "Could not get working directory", NULL, 0); 72 exit(1); 73 } 74 75 font = al_load_font("font.ttf", 24, 0); 76 if (font==NULL) 77 { 78 al_show_native_message_box(NULL, "Error", "Init Error", "Could not load font file", NULL, 0); 79 exit(1); 80 } 81 82 al_set_new_display_flags(ALLEGRO_WINDOWED); 83 scr = al_create_display(2*al_get_text_width(font, "00:00:00"), al_get_font_line_height(font)); 84 if (!scr) 85 { 86 al_show_native_message_box(NULL, "Error", "Init Error", "Could not create display", NULL, 0); 87 exit(1); 88 } 89 90 voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); 91 if (!voice) 92 { 93 al_show_native_message_box(NULL, "Error", "Init Error", "Could not create voice", NULL, 0); 94 exit(1); 95 } 96 97 mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); 98 if (!mixer) 99 { 100 al_show_native_message_box(NULL, "Error", "Init Error", "Could not create mixer", NULL, 0); 101 exit(1); 102 } 103 104 if (!al_attach_mixer_to_voice(mixer, voice)) 105 { 106 al_show_native_message_box(NULL, "Error", "Init Error", "Could not attach mixer to voice", NULL, 0); 107 exit(1); 108 } 109 110 if (!al_filename_exists("default.ogg")) 111 { 112 al_show_native_message_box(NULL, "Error", "Init Error", "File does not exist or can't be found", NULL, 0); 113 exit(1); 114 } 115 116 stream = al_load_audio_stream("default.ogg", 4, 2048); 117 if (!stream) 118 { 119 al_show_native_message_box(NULL, "Error", "Init Error", "Could not create stream", NULL, 0); 120 exit(1); 121 } 122 123 eventQueue = al_create_event_queue(); 124 al_register_event_source(eventQueue, al_get_keyboard_event_source()); 125 al_register_event_source(eventQueue, al_get_mouse_event_source()); 126 al_register_event_source(eventQueue, al_get_display_event_source(scr)); 127 al_register_event_source(eventQueue, al_get_audio_stream_event_source(stream)); 128 129 alarmHour = 12; 130 alarmMinutes = 20; 131 alarmSeconds = 0; 132 while (!exitFlag) 133 { 134 while (al_event_queue_is_empty(eventQueue)) 135 { 136 al_clear_to_color(al_map_rgb(0,0,0)); 137 time(&rawtime); 138 timeinfo = localtime(&rawtime); 139 currentHour = timeinfo->tm_hour; 140 if (currentHour>12) 141 { 142 currentHour-=12; 143 strcpy(amPm, "P.M."); 144 AMPM = true; 145 } 146 else 147 { 148 strcpy(amPm, "A.M."); 149 AMPM = false; 150 } 151 currentMinutes = timeinfo->tm_min; 152 currentSeconds = timeinfo->tm_sec; 153 sprintf(testString, "%d:%d:%d %s", currentHour, currentMinutes, currentSeconds, amPm); 154 al_draw_text(font, al_map_rgb(255,0,0), al_get_display_width(scr)/2, 0, ALLEGRO_ALIGN_CENTRE, testString); 155 al_flip_display(); 156 } 157 al_get_next_event(eventQueue, &retEvent); 158 switch (retEvent.type) 159 { 160 case ALLEGRO_EVENT_KEY_CHAR: 161 if (retEvent.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 162 exitFlag = true; 163 break; 164 default: 165 break; 166 } 167 } 168 169 if (font!=NULL) 170 al_destroy_font(font); 171 if (workingDirectory!=NULL) 172 al_free(workingDirectory); 173 return 0; 174}

The file exists so that isn't the problem. Am I doing something wrong here? Should I be using another part of the audio api? The ogg file was created by ripping a song off of a CD and saving it as an OGG file. Could this be because the song settings differ from the mixer settings?

Thanks for any help.

WG

Matthew Leverton

Do you ever attach the audio stream to something (i.e., a mixer)?

By the way, if you don't care much about the settings of mixers and voices, you can do this:

wiseguy

I got it working by converting the ogg file to WAV format.

I did attach it to a mixer but only if the alarm time is greater than or equal to the clock time... As of now, everything is working, but I don't understand why the load stream function failed for an ogg file but not for a wav file. I installed from svn, and it always is a pain but I thought I finally got everything where I needed it.

For what reasons would the load stream function fail? If I just reserve samples, how would I go about loading the entire file from disk before playing?

I'm just glad to finally have audio working at all with A5. Of all the A5 versions I've tried this is the first one that audio has worked period.

WG

Peter Wang

Are the ogg, vorbis and vorbisfile DLLs in your path? The best way to debug these things is to use a debug build of Allegro and check allegro.log

X-G

What operating system is this? Confirm that Allegro really did build with Ogg support. I had significant issues getting that to work on OSX due to what I can only assume is a bug in Allegro's cmake scripts, and for all I know that issue exists on other systems, too.

wiseguy

Are the ogg, vorbis and vorbisfile DLLs in your path? The best way to debug these things is to use a debug build of Allegro and check allegro.log

All of the DLLs were installed as far as I know but I will go back through and double check.

X-G said:

What operating system is this? Confirm that Allegro really did build with Ogg support. I had significant issues getting that to work on OSX due to what I can only assume is a bug in Allegro's cmake scripts, and for all I know that issue exists on other systems, too.

I'm building this on Windows Vista, and have had similar problems on XP as well.

The only files I had trouble with in cmake were the ogg and vorbis files. I had to manually add those 3 files into cmake. For some reason, no matter what I did, cmake would find the include directories but not the library files. But, when I ran the final configure, cmake did the checks to see if ogg and vorbis compiled and that worked fine.

I'll check this out some more and let you guys know how it goes. I was going to post the steps I took to install from SVN on windows on the wiki sometime today as well. This last time went much smoother than before.

X-G

Note that in my case there were no error messages from cmake either. It just silently failed and excluded ogg, while building everything else.

wiseguy

I just checked and the ogg and vorbis dll files WERE copied during install but I'm not seeing the library files. I'm going to try this again after copying those library files.

[Edit]

Ok, still no luck after that try. Obviously A5 built without OGG support. Is there a way to fix the cmake scripts to properly find the libraries? I have all the dependencies in the deps folder. Should I have copied over the library export files along with the .lib files?

[Edit #2]

Ok, the problem has been resolved. What happened was that I had renamed libogg.lib and libvorbis*.lib in the deps folder in hopes of the cmake scripts automatically finding them. Because of that, the program was looking for the wrong dll files. copying over the original .lib and .dll files and relinking fixed everything. Thanks for all the help folks.

WG

Thread #606181. Printed from Allegro.cc