Search
lxdream.org :: lxdream :: r434:8af49a412d92
lxdream 0.9.1
released Jun 29
Download Now
changeset434:8af49a412d92
parent433:a4f61551d79d
child435:7a5d71e8560b
authornkeynes
dateTue Oct 09 11:37:36 2007 +0000 (12 years ago)
Fix ADPCM (to some degree at least)
Fix key-on/off (triggers all channels at once)
src/aica/aica.c
src/aica/audio.c
src/aica/audio.h
1.1 --- a/src/aica/aica.c Tue Oct 09 08:48:28 2007 +0000
1.2 +++ b/src/aica/aica.c Tue Oct 09 11:37:36 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: aica.c,v 1.22 2007-10-09 08:11:51 nkeynes Exp $
1.6 + * $Id: aica.c,v 1.23 2007-10-09 11:37:36 nkeynes Exp $
1.7 *
1.8 * This is the core sound system (ie the bit which does the actual work)
1.9 *
1.10 @@ -289,6 +289,19 @@
1.11 return rate;
1.12 }
1.13
1.14 +void aica_start_stop_channels()
1.15 +{
1.16 + int i;
1.17 + for( i=0; i<32; i++ ) {
1.18 + uint32_t val = MMIO_READ( AICA0, i<<7 );
1.19 + audio_start_stop_channel(i, val&0x4000);
1.20 + }
1.21 + for( ; i<64; i++ ) {
1.22 + uint32_t val = MMIO_READ( AICA1, (i-32)<<7 );
1.23 + audio_start_stop_channel(i, val&0x4000);
1.24 + }
1.25 +}
1.26 +
1.27 /**
1.28 * Derived directly from Dan Potter's log table
1.29 */
1.30 @@ -334,16 +347,8 @@
1.31 channel->sample_format = AUDIO_FMT_ADPCM;
1.32 break;
1.33 }
1.34 - switch( (val >> 14) & 0x03 ) {
1.35 - case 2:
1.36 - audio_stop_channel( channelNo );
1.37 - break;
1.38 - case 3:
1.39 - audio_start_channel( channelNo );
1.40 - break;
1.41 - default:
1.42 - break;
1.43 - /* Hrmm... */
1.44 + if( val & 0x8000 ) {
1.45 + aica_start_stop_channels();
1.46 }
1.47 break;
1.48 case 0x04: /* Low 16 address bits */
2.1 --- a/src/aica/audio.c Tue Oct 09 08:48:28 2007 +0000
2.2 +++ b/src/aica/audio.c Tue Oct 09 11:37:36 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: audio.c,v 1.8 2007-10-09 08:11:51 nkeynes Exp $
2.6 + * $Id: audio.c,v 1.9 2007-10-09 11:37:36 nkeynes Exp $
2.7 *
2.8 * Audio mixer core. Combines all the active streams into a single sound
2.9 * buffer for output.
2.10 @@ -25,7 +25,7 @@
2.11 #include <string.h>
2.12
2.13 #define NUM_BUFFERS 3
2.14 -#define MS_PER_BUFFER 50
2.15 +#define MS_PER_BUFFER 100
2.16
2.17 #define BUFFER_EMPTY 0
2.18 #define BUFFER_WRITING 1
2.19 @@ -198,7 +198,7 @@
2.20 switch( channel->sample_format ) {
2.21 case AUDIO_FMT_16BIT:
2.22 for( j=0; j<num_samples; j++ ) {
2.23 - sample = *(int16_t *)(arm_mem + channel->posn + channel->start);
2.24 + sample = ((int16_t *)(arm_mem + channel->start))[channel->posn];
2.25 result_buf[j][0] += sample * vol_left;
2.26 result_buf[j][1] += sample * vol_right;
2.27
2.28 @@ -221,7 +221,7 @@
2.29 break;
2.30 case AUDIO_FMT_8BIT:
2.31 for( j=0; j<num_samples; j++ ) {
2.32 - sample = (*(int8_t *)(arm_mem + channel->posn + channel->start)) << 8;
2.33 + sample = ((int8_t *)(arm_mem + channel->start))[channel->posn] << 8;
2.34 result_buf[j][0] += sample * vol_left;
2.35 result_buf[j][1] += sample * vol_right;
2.36
2.37 @@ -250,22 +250,23 @@
2.38 channel->posn_left += channel->sample_rate;
2.39 while( channel->posn_left > audio.output_rate ) {
2.40 channel->posn_left -= audio.output_rate;
2.41 - if( channel->adpcm_nibble == 0 ) {
2.42 - uint8_t data = *(uint8_t *)(arm_mem + channel->posn + channel->start);
2.43 - adpcm_yamaha_decode_nibble( channel, (data >> 4) & 0x0F );
2.44 - channel->adpcm_nibble = 1;
2.45 - } else {
2.46 - channel->posn++;
2.47 - if( channel->posn == channel->end ) {
2.48 - if( channel->loop )
2.49 - channel->posn = channel->loop_start;
2.50 - else
2.51 - audio_stop_channel(i);
2.52 + channel->posn++;
2.53 + if( channel->posn == channel->end ) {
2.54 + if( channel->loop ) {
2.55 + channel->posn = channel->loop_start;
2.56 + channel->adpcm_predict = 0;
2.57 + channel->adpcm_step = 0;
2.58 + } else {
2.59 + audio_stop_channel(i);
2.60 + j = num_samples;
2.61 break;
2.62 }
2.63 - uint8_t data = *(uint8_t *)(arm_mem + channel->posn + channel->start);
2.64 + }
2.65 + uint8_t data = ((uint8_t *)(arm_mem + channel->start))[channel->posn>>1];
2.66 + if( channel->posn&1 ) {
2.67 + adpcm_yamaha_decode_nibble( channel, (data >> 4) & 0x0F );
2.68 + } else {
2.69 adpcm_yamaha_decode_nibble( channel, data & 0x0F );
2.70 - channel->adpcm_nibble = 0;
2.71 }
2.72 }
2.73 }
2.74 @@ -314,6 +315,17 @@
2.75 return &audio.channels[channel];
2.76 }
2.77
2.78 +void audio_start_stop_channel( int channel, gboolean start )
2.79 +{
2.80 + if( audio.channels[channel].active ) {
2.81 + if( !start ) {
2.82 + audio_stop_channel(channel);
2.83 + }
2.84 + } else if( start ) {
2.85 + audio_start_channel(channel);
2.86 + }
2.87 +}
2.88 +
2.89 void audio_stop_channel( int channel )
2.90 {
2.91 audio.channels[channel].active = FALSE;
2.92 @@ -324,8 +336,11 @@
2.93 {
2.94 audio.channels[channel].posn = 0;
2.95 audio.channels[channel].posn_left = 0;
2.96 - audio.channels[channel].adpcm_nibble = 0;
2.97 - audio.channels[channel].adpcm_step = 0;
2.98 - audio.channels[channel].adpcm_predict = 0;
2.99 audio.channels[channel].active = TRUE;
2.100 + if( audio.channels[channel].sample_format == AUDIO_FMT_ADPCM ) {
2.101 + audio.channels[channel].adpcm_step = 0;
2.102 + audio.channels[channel].adpcm_predict = 0;
2.103 + uint8_t data = ((uint8_t *)(arm_mem + audio.channels[channel].start))[0];
2.104 + adpcm_yamaha_decode_nibble( &audio.channels[channel], data & 0x0F );
2.105 + }
2.106 }
3.1 --- a/src/aica/audio.h Tue Oct 09 08:48:28 2007 +0000
3.2 +++ b/src/aica/audio.h Tue Oct 09 11:37:36 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: audio.h,v 1.7 2006-03-16 12:41:59 nkeynes Exp $
3.6 + * $Id: audio.h,v 1.8 2007-10-09 11:37:36 nkeynes Exp $
3.7 *
3.8 * Audio engine, ie the part that does the actual work.
3.9 *
3.10 @@ -37,7 +37,7 @@
3.11
3.12 typedef struct audio_channel {
3.13 gboolean active;
3.14 - uint32_t posn;
3.15 + uint32_t posn; /* current sample #, 0 = first sample */
3.16 uint32_t posn_left;
3.17 uint32_t start;
3.18 uint32_t end;
3.19 @@ -49,7 +49,6 @@
3.20 int sample_format;
3.21 /* Envelope etc stuff */
3.22 /* ADPCM */
3.23 - int adpcm_nibble; /* 0 = low nibble, 1 = high nibble */
3.24 int adpcm_step;
3.25 int adpcm_predict;
3.26 } *audio_channel_t;
3.27 @@ -102,6 +101,7 @@
3.28 */
3.29 audio_channel_t audio_get_channel( int channel );
3.30
3.31 +void audio_start_stop_channel( int channel, gboolean start );
3.32 void audio_start_channel( int channel );
3.33 void audio_stop_channel( int channel );
3.34
.