From: Henrik S. <hb...@ks...> - 2001-11-10 16:52:24
|
Init stream, having a 44 byte WAV header and skipping it : #define BUFFER_SIZE 131072 sfp = fopen("your wav file","rb"); fseek(sfp,0,SEEK_END); /* Get size of raw data we want to feed */ ssize = ftell(sfp) - 44; rewind(sfp); /* skip the header */ fseek(sfp,44,SEEK_SET); scnt = 0; theme = play_audio_stream(BUFFER_SIZE/2,16,FALSE,22050,128,128); Note that the first paramter to play_audio_stream() is just half of the buffer size we want to feed as it is counted in samples, 2 byte = 1 sample for 16 bit. This was my biggest mistake and caused the pauses. In the loop : void StreamAudio(void) { int i,cnt; unsigned char *buff; unsigned short *buff2; buff = get_audio_stream_buffer(theme); if ( buff != NULL ) { /* Play it again, Sam */ if ( scnt >= ssize ) { rewind(sfp); fseek(sfp,44,SEEK_SET); scnt = 0; } cnt = fread(buff,1,BUFFER_SIZE,sfp); scnt += cnt; buff2 = (unsigned short *)buff; for (i = 0; i < (cnt / 2); i++) { *buff2 ^= 0x8000; buff2++; } free_audio_stream_buffer(theme); } } My last problem is a knack sound at the end of the file when repeating it. ----- Original Message ----- From: "Owen Rudge" <ow...@os...> To: <al...@ca...> Sent: Saturday, November 10, 2001 2:12 PM Subject: [AL] Playing WAV files in audiostreams > Hi, > > I've been following the "allegro, windows and sound" thread closely, and was > wondering: can someone post some code that will play 16-bit WAV files > without the "pauses" in between actual audio? I can't convert the WAV to raw > format or anything else - it must be WAV. 8-bit files play fine, but 16-bit > doesn't. > > If you want, I can post my code (3.19kb in total). > > Thanks, > > Owen Rudge > http://www.owenrudge.co.uk/ > > MSN Messenger: or...@fr... > ICQ: 125455765 > |