diff options
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/audio.c b/src/audio.c index 45efa47..f21bc9f 100644 --- a/src/audio.c +++ b/src/audio.c @@ -59,6 +59,11 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { clip_count++; } stream[j] = 32767; + } else if ( test < -32767 ) { + if ( stream[j] != -32767 ) { + clip_count++; + } + stream[j] = -32767; } else { stream[j] += samp * a->sounds[i].volume; } @@ -75,9 +80,6 @@ static void audio_mix(void *data, Uint8 *stream8, int len) { break; } } - //if ( (i==0) && !(ppp++ % 10000) ) { - // printf("%li / %li (%.2f%%)\n", a->sounds[i].dpos, a->sounds[i].dlen, (double)a->sounds[i].dpos*100.0/a->sounds[i].dlen); - //} } @@ -219,13 +221,15 @@ static void *audio_play_vorbis(void *add_void) { goto out; } decode_done = 0; - decode_samples_done = 0; + decode_samples_done = 0; /* Number of samples from the Vorbis file (i.e. BEFORE CONVERSION) */ a->sounds[idx].decode_pos = 0; /* Position (in sounds[idx].data) at which to write the next block */ while ( !decode_done ) { - long decode_block_samples; + long decode_block_samples; /* Number of samples BEFORE CONVERSION */ long decode_block_length; int w; + int i; + Sint16 *cvtbuf16; /* Decide how much data to shovel this time */ decode_block_samples = 10*vi->rate; /* 10 seconds in samples */ @@ -259,8 +263,11 @@ static void *audio_play_vorbis(void *add_void) { if ( !a->sounds[idx].playing ) { a->sounds[idx].data = malloc(len*vi->channels*2); } - memcpy(a->sounds[idx].data+a->sounds[idx].decode_pos, cvt.buf, cvt.len_cvt); - a->sounds[idx].decode_pos += cvt.len_cvt / 2; + cvtbuf16 = (Sint16 *)cvt.buf; + for ( i=0; i<decode_block_samples*2; i++ ) { + a->sounds[idx].data[i+a->sounds[idx].decode_pos] = cvtbuf16[i]; + } + a->sounds[idx].decode_pos += decode_block_samples*2; /* It's safe to start playing at this point */ if ( !a->sounds[idx].playing ) { @@ -270,16 +277,17 @@ static void *audio_play_vorbis(void *add_void) { a->sounds[idx].volume = add->volume; a->sounds[idx].playing = 1; /* Must be done last - tell the mixer thread it can use this */ } - - if ( a->debug ) printf("AU: Channel %i: Decoded %li samples this time. " + if ( a->debug ) printf("AU: Channel %i: decode_pos=%i, dpos=%li. " "I am now %.1f seconds ahead of the playing position.\n", - idx, decode_block_samples, ((double)a->sounds[idx].decode_pos-(2*a->sounds[idx].dpos))/(44100*2*2)); + idx, a->sounds[idx].decode_pos, a->sounds[idx].dpos, + ((double)a->sounds[idx].decode_pos-a->sounds[idx].dpos)/(44100*2)); /* Sleep for eight seconds while periodically checking for shutdown */ for ( w=0; w<80; w++ ) { if ( a->shutdown ) { ov_clear(&vf); free(data); + printf("AU: Channel %i: Dispatch thread aborting.\n", idx); goto out; } usleep(100000); /* 0.1 seconds */ @@ -451,7 +459,7 @@ AudioContext *audio_setup(int debug, int no_music) { } if ( !no_music ) { - audio_play(a, "kraftwerk", 0.5, 1); + audio_play(a, "music", 0.5, 1); } else { if ( a->debug ) printf("AU: Music disabled.\n"); } |