Search
lxdream.org :: lxdream/src/aica/audio.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/audio.c
changeset 434:8af49a412d92
prev431:248dd77a9e44
next463:0655796f9bb5
author nkeynes
date Tue Oct 09 11:37:36 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix ADPCM (to some degree at least)
Fix key-on/off (triggers all channels at once)
file annotate diff log raw
1.1 --- a/src/aica/audio.c Tue Oct 09 08:12:29 2007 +0000
1.2 +++ b/src/aica/audio.c Tue Oct 09 11:37:36 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: audio.c,v 1.8 2007-10-09 08:11:51 nkeynes Exp $
1.6 + * $Id: audio.c,v 1.9 2007-10-09 11:37:36 nkeynes Exp $
1.7 *
1.8 * Audio mixer core. Combines all the active streams into a single sound
1.9 * buffer for output.
1.10 @@ -25,7 +25,7 @@
1.11 #include <string.h>
1.12
1.13 #define NUM_BUFFERS 3
1.14 -#define MS_PER_BUFFER 50
1.15 +#define MS_PER_BUFFER 100
1.16
1.17 #define BUFFER_EMPTY 0
1.18 #define BUFFER_WRITING 1
1.19 @@ -198,7 +198,7 @@
1.20 switch( channel->sample_format ) {
1.21 case AUDIO_FMT_16BIT:
1.22 for( j=0; j<num_samples; j++ ) {
1.23 - sample = *(int16_t *)(arm_mem + channel->posn + channel->start);
1.24 + sample = ((int16_t *)(arm_mem + channel->start))[channel->posn];
1.25 result_buf[j][0] += sample * vol_left;
1.26 result_buf[j][1] += sample * vol_right;
1.27
1.28 @@ -221,7 +221,7 @@
1.29 break;
1.30 case AUDIO_FMT_8BIT:
1.31 for( j=0; j<num_samples; j++ ) {
1.32 - sample = (*(int8_t *)(arm_mem + channel->posn + channel->start)) << 8;
1.33 + sample = ((int8_t *)(arm_mem + channel->start))[channel->posn] << 8;
1.34 result_buf[j][0] += sample * vol_left;
1.35 result_buf[j][1] += sample * vol_right;
1.36
1.37 @@ -250,22 +250,23 @@
1.38 channel->posn_left += channel->sample_rate;
1.39 while( channel->posn_left > audio.output_rate ) {
1.40 channel->posn_left -= audio.output_rate;
1.41 - if( channel->adpcm_nibble == 0 ) {
1.42 - uint8_t data = *(uint8_t *)(arm_mem + channel->posn + channel->start);
1.43 - adpcm_yamaha_decode_nibble( channel, (data >> 4) & 0x0F );
1.44 - channel->adpcm_nibble = 1;
1.45 - } else {
1.46 - channel->posn++;
1.47 - if( channel->posn == channel->end ) {
1.48 - if( channel->loop )
1.49 - channel->posn = channel->loop_start;
1.50 - else
1.51 - audio_stop_channel(i);
1.52 + channel->posn++;
1.53 + if( channel->posn == channel->end ) {
1.54 + if( channel->loop ) {
1.55 + channel->posn = channel->loop_start;
1.56 + channel->adpcm_predict = 0;
1.57 + channel->adpcm_step = 0;
1.58 + } else {
1.59 + audio_stop_channel(i);
1.60 + j = num_samples;
1.61 break;
1.62 }
1.63 - uint8_t data = *(uint8_t *)(arm_mem + channel->posn + channel->start);
1.64 + }
1.65 + uint8_t data = ((uint8_t *)(arm_mem + channel->start))[channel->posn>>1];
1.66 + if( channel->posn&1 ) {
1.67 + adpcm_yamaha_decode_nibble( channel, (data >> 4) & 0x0F );
1.68 + } else {
1.69 adpcm_yamaha_decode_nibble( channel, data & 0x0F );
1.70 - channel->adpcm_nibble = 0;
1.71 }
1.72 }
1.73 }
1.74 @@ -314,6 +315,17 @@
1.75 return &audio.channels[channel];
1.76 }
1.77
1.78 +void audio_start_stop_channel( int channel, gboolean start )
1.79 +{
1.80 + if( audio.channels[channel].active ) {
1.81 + if( !start ) {
1.82 + audio_stop_channel(channel);
1.83 + }
1.84 + } else if( start ) {
1.85 + audio_start_channel(channel);
1.86 + }
1.87 +}
1.88 +
1.89 void audio_stop_channel( int channel )
1.90 {
1.91 audio.channels[channel].active = FALSE;
1.92 @@ -324,8 +336,11 @@
1.93 {
1.94 audio.channels[channel].posn = 0;
1.95 audio.channels[channel].posn_left = 0;
1.96 - audio.channels[channel].adpcm_nibble = 0;
1.97 - audio.channels[channel].adpcm_step = 0;
1.98 - audio.channels[channel].adpcm_predict = 0;
1.99 audio.channels[channel].active = TRUE;
1.100 + if( audio.channels[channel].sample_format == AUDIO_FMT_ADPCM ) {
1.101 + audio.channels[channel].adpcm_step = 0;
1.102 + audio.channels[channel].adpcm_predict = 0;
1.103 + uint8_t data = ((uint8_t *)(arm_mem + audio.channels[channel].start))[0];
1.104 + adpcm_yamaha_decode_nibble( &audio.channels[channel], data & 0x0F );
1.105 + }
1.106 }
.