I didn't want to clutter up ValleyBell's topic too much, so I decided to start a new topic. This relates to the problem LOst was talking about. I'm using Allegro v4.4. DIGI_AUTODETECT works fine. DIGI_DIRECTX(0) does not. The DirectX option has heavy audio distortion. A quick audio analysis reveals why it sounds bad. Here's what "silence" looks like: So everything that plays will get played on top of that. Can anyone explain this? Code (Text): #include <allegro.h> AUDIOSTREAM *stream; short *allegroStream; volatile int timer = 0; volatile int timerChanged = 0; void TimerUpdate(void); const int testFrequency = 48000; void TimerUpdate(void) { timer++; timerChanged = 1; } END_OF_FUNCTION(TimerUpdate); int main() { allegro_init(); install_keyboard(); install_timer(); //install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); install_sound(DIGI_DIRECTX(0), MIDI_AUTODETECT, NULL); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 240, 0, 0); LOCK_VARIABLE(timer); LOCK_FUNCTION(TimerUpdate); install_int_ex(&TimerUpdate, BPS_TO_TIMER(60)); stream = play_audio_stream(testFrequency/60, 16, 1, testFrequency, 255, 128); while(!key[KEY_ESC]) { while(timerChanged == 0); timerChanged = 0; allegroStream = (short*)get_audio_stream_buffer(stream); if(allegroStream){ for(int I = 0 ; I < (testFrequency/60)*2 ; I++) { allegroStream[I] = 0; } free_audio_stream_buffer(stream); } } remove_timer(); stop_audio_stream(stream); return 0; } END_OF_MAIN();
It seems that there is a problem with the timer function. When the timer says that 1/60 seconds have passed, DirectX is still playing the same chunk as the time you called free_audio_stream_buffer() . Thus probably get_audio_stream_buffer return NULL, if(allegroStream) fails, and you wait another 1/60 seconds till you try again. To solve it you probably need to either a) double the frequency of the timer to 120 BPS b) or move the line timerChanged=0; inside if(allegroStream) { stuff //here? } and increase the timer again, to 70 or more c) make a separate thread so it doesn't cpu hog the gameplay stuff Hope this helps.