Commit 06885ac8 authored by Claes Sjofors's avatar Claes Sjofors

Xtt audio bugfix

parent 6cf1f297
...@@ -42,7 +42,7 @@ typedef struct { ...@@ -42,7 +42,7 @@ typedef struct {
long dataSize; long dataSize;
} wav_sFormat; } wav_sFormat;
static int debug = 0; static int debug = 1;
int XttAudio::number_of=0; int XttAudio::number_of=0;
int XttAudio::audio_ok=0; int XttAudio::audio_ok=0;
...@@ -224,6 +224,7 @@ int XttAudio::beep( pwr_tAttrRef *arp) ...@@ -224,6 +224,7 @@ int XttAudio::beep( pwr_tAttrRef *arp)
} }
} }
} }
size = 2 * int(sound.Length * srate);
} }
else if ( strstr( sound.Source, ".wav") != 0) { else if ( strstr( sound.Source, ".wav") != 0) {
// Wave file // Wave file
...@@ -249,6 +250,9 @@ int XttAudio::beep( pwr_tAttrRef *arp) ...@@ -249,6 +250,9 @@ int XttAudio::beep( pwr_tAttrRef *arp)
return XNAV__WAVEFORMAT; return XNAV__WAVEFORMAT;
} }
if ( debug)
printf( "Wavefile BitPerSample %d Channels %d\n", chunk.wBitsPerSample, chunk.wChannels);
if ( chunk.dataSize == 0 || chunk.dataSize > 10000000) if ( chunk.dataSize == 0 || chunk.dataSize > 10000000)
return XNAV__FILECORRUPT; return XNAV__FILECORRUPT;
if ( chunk.wBitsPerSample == 8) { if ( chunk.wBitsPerSample == 8) {
...@@ -267,6 +271,7 @@ int XttAudio::beep( pwr_tAttrRef *arp) ...@@ -267,6 +271,7 @@ int XttAudio::beep( pwr_tAttrRef *arp)
for ( int i = 0; i < chunk.dataSize; i++) { for ( int i = 0; i < chunk.dataSize; i++) {
buffer[2*i] = buffer[2*i+1] = 255 * ((short) buf8[i] - 127); buffer[2*i] = buffer[2*i+1] = 255 * ((short) buf8[i] - 127);
} }
size = chunk.dataSize;
} }
else { else {
// wChannels == 2 // wChannels == 2
...@@ -278,6 +283,7 @@ int XttAudio::beep( pwr_tAttrRef *arp) ...@@ -278,6 +283,7 @@ int XttAudio::beep( pwr_tAttrRef *arp)
for ( int i = 0; i < chunk.dataSize; i++) { for ( int i = 0; i < chunk.dataSize; i++) {
buffer[i] = 255 * ((short)buf8[i] - 127); buffer[i] = 255 * ((short)buf8[i] - 127);
} }
size = chunk.dataSize / 2;
} }
free( buf8); free( buf8);
} }
...@@ -300,16 +306,18 @@ int XttAudio::beep( pwr_tAttrRef *arp) ...@@ -300,16 +306,18 @@ int XttAudio::beep( pwr_tAttrRef *arp)
buffer[2*i] = buffer[2*i+1] = buf16[i]; buffer[2*i] = buffer[2*i+1] = buf16[i];
} }
free( buf16); free( buf16);
size = chunk.dataSize;
} }
else { else {
// wChannels == 2 // wChannels == 2
size = chunk.dataSize / 2; size = chunk.dataSize;
size = ((size - 1) / (hw_buff_size) + 1) * hw_buff_size; size = ((size - 1) / (hw_buff_size) + 1) * hw_buff_size;
buffer = (short *) calloc( sizeof(short), size); buffer = (short *) calloc( sizeof(short), size);
if ( !buffer) return XNAV__NOMEMORY; if ( !buffer) return XNAV__NOMEMORY;
sts = fread( buffer, chunk.dataSize, 1, fp); sts = fread( buffer, chunk.dataSize, 1, fp);
fclose( fp); fclose( fp);
size = chunk.dataSize/2;
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment