Search
lxdream.org :: lxdream :: r82:81a4acf75f10
lxdream 0.9.1
released Jun 29
Download Now
changeset82:81a4acf75f10
parent81:1c1d53584da4
child83:72c4fbd60965
authornkeynes
dateTue Jan 17 12:54:02 2006 +0000 (14 years ago)
Add basic attempt at panning + proper volume
src/aica/aica.c
src/aica/audio.c
src/aica/audio.h
1.1 --- a/src/aica/aica.c Tue Jan 17 12:53:39 2006 +0000
1.2 +++ b/src/aica/aica.c Tue Jan 17 12:54:02 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: aica.c,v 1.14 2006-01-14 12:31:36 nkeynes Exp $
1.6 + * $Id: aica.c,v 1.15 2006-01-17 12:54:02 nkeynes Exp $
1.7 *
1.8 * This is the core sound system (ie the bit which does the actual work)
1.9 *
1.10 @@ -227,18 +227,42 @@
1.11 {
1.12 uint32_t exponent = (freq & 0x3800) >> 11;
1.13 uint32_t mantissa = freq & 0x03FF;
1.14 + uint32_t rate;
1.15 if( freq & 0x4000 ) {
1.16 /* neg exponent - rate < 44100 */
1.17 exponent = 8 - exponent;
1.18 - return (44100 >> exponent) +
1.19 + rate = (44100 >> exponent) +
1.20 ((44100 * mantissa) >> (10+exponent));
1.21 } else {
1.22 /* pos exponent - rate > 44100 */
1.23 - return (44100 << exponent) +
1.24 + rate = (44100 << exponent) +
1.25 ((44100 * mantissa) >> (10-exponent));
1.26 }
1.27 + return rate;
1.28 }
1.29
1.30 +/**
1.31 + * Derived directly from Dan Potter's log table
1.32 + */
1.33 +uint8_t aica_volume_table[256] = {
1.34 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1.35 + 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4,
1.36 + 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9,
1.37 + 9, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16,
1.38 + 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 25,
1.39 + 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36,
1.40 + 37, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49,
1.41 + 50, 51, 52, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
1.42 + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 81,
1.43 + 82, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 100,
1.44 + 102, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 121,
1.45 + 123, 124, 126, 127, 128, 130, 131, 133, 134, 136, 137, 139, 140, 142, 143, 145,
1.46 + 146, 148, 149, 151, 152, 154, 155, 157, 159, 160, 162, 163, 165, 167, 168, 170,
1.47 + 171, 173, 175, 176, 178, 180, 181, 183, 185, 187, 188, 190, 192, 194, 195, 197,
1.48 + 199, 201, 202, 204, 206, 208, 210, 211, 213, 215, 217, 219, 221, 223, 224, 226,
1.49 + 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 253, 254, 255 };
1.50 +
1.51 +
1.52 void aica_write_channel( int channelNo, uint32_t reg, uint32_t val )
1.53 {
1.54 val &= 0x0000FFFF;
1.55 @@ -293,9 +317,13 @@
1.56 case 0x1C: /* ??? */
1.57 case 0x20: /* ??? */
1.58 case 0x24: /* Volume? /pan */
1.59 + val = val & 0x1F;
1.60 + if( val <= 0x0F )
1.61 + val = 0x0F - val; /* Convert to smooth pan over 0..31 */
1.62 + channel->pan = val;
1.63 break;
1.64 case 0x28: /* Volume */
1.65 - channel->vol_left = channel->vol_right = val & 0xFF;
1.66 + channel->vol = aica_volume_table[val & 0xFF];
1.67 break;
1.68 default: /* ??? */
1.69 break;
2.1 --- a/src/aica/audio.c Tue Jan 17 12:53:39 2006 +0000
2.2 +++ b/src/aica/audio.c Tue Jan 17 12:54:02 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: audio.c,v 1.3 2006-01-16 11:23:05 nkeynes Exp $
2.6 + * $Id: audio.c,v 1.4 2006-01-17 12:54:02 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 100
2.15 +#define MS_PER_BUFFER 1000
2.16
2.17 #define BUFFER_EMPTY 0
2.18 #define BUFFER_WRITING 1
2.19 @@ -186,12 +186,14 @@
2.20 audio_channel_t channel = &audio.channels[i];
2.21 if( channel->active ) {
2.22 int32_t sample;
2.23 + int vol_left = (channel->vol * (32 - channel->pan)) >> 5;
2.24 + int vol_right = (channel->vol * (channel->pan + 1)) >> 5;
2.25 switch( channel->sample_format ) {
2.26 case AUDIO_FMT_16BIT:
2.27 for( j=0; j<num_samples; j++ ) {
2.28 sample = *(int16_t *)(arm_mem + channel->posn + channel->start);
2.29 - result_buf[j][0] += sample * channel->vol_left;
2.30 - result_buf[j][1] += sample * channel->vol_right;
2.31 + result_buf[j][0] += sample * vol_left;
2.32 + result_buf[j][1] += sample * vol_right;
2.33
2.34 channel->posn_left += channel->sample_rate;
2.35 while( channel->posn_left > audio.output_rate ) {
2.36 @@ -213,8 +215,8 @@
2.37 case AUDIO_FMT_8BIT:
2.38 for( j=0; j<num_samples; j++ ) {
2.39 sample = (*(int8_t *)(arm_mem + channel->posn + channel->start)) << 8;
2.40 - result_buf[j][0] += sample * channel->vol_left;
2.41 - result_buf[j][1] += sample * channel->vol_right;
2.42 + result_buf[j][0] += sample * vol_left;
2.43 + result_buf[j][1] += sample * vol_right;
2.44
2.45 channel->posn_left += channel->sample_rate;
2.46 while( channel->posn_left > audio.output_rate ) {
2.47 @@ -236,8 +238,8 @@
2.48 case AUDIO_FMT_ADPCM:
2.49 for( j=0; j<num_samples; j++ ) {
2.50 sample = (int16_t)channel->adpcm_predict;
2.51 - result_buf[j][0] += sample * channel->vol_left;
2.52 - result_buf[j][1] += sample * channel->vol_right;
2.53 + result_buf[j][0] += sample * vol_left;
2.54 + result_buf[j][1] += sample * vol_right;
2.55 channel->posn_left += channel->sample_rate;
2.56 while( channel->posn_left > audio.output_rate ) {
2.57 channel->posn_left -= audio.output_rate;
2.58 @@ -273,8 +275,8 @@
2.59 audio_buffer_t buf = audio.output_buffers[audio.write_buffer];
2.60 uint16_t *data = (uint16_t *)&buf->data[buf->posn];
2.61 for( j=0; j < num_samples; j++ ) {
2.62 - *data++ = (int16_t)(result_buf[j][0] >> 8);
2.63 - *data++ = (int16_t)(result_buf[j][1] >> 8);
2.64 + *data++ = (int16_t)(result_buf[j][0] >> 6);
2.65 + *data++ = (int16_t)(result_buf[j][1] >> 6);
2.66 buf->posn += 4;
2.67 if( buf->posn == buf->length ) {
2.68 audio_next_write_buffer();
3.1 --- a/src/aica/audio.h Tue Jan 17 12:53:39 2006 +0000
3.2 +++ b/src/aica/audio.h Tue Jan 17 12:54:02 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: audio.h,v 1.3 2006-01-12 12:38:59 nkeynes Exp $
3.6 + * $Id: audio.h,v 1.4 2006-01-17 12:54:02 nkeynes Exp $
3.7 *
3.8 * Audio engine, ie the part that does the actual work.
3.9 *
3.10 @@ -42,8 +42,8 @@
3.11 uint32_t end;
3.12 gboolean loop;
3.13 uint32_t loop_start;
3.14 - int vol_left; /* 0..255 */
3.15 - int vol_right; /* 0..255 */
3.16 + int vol; /* 0..255 */
3.17 + int pan; /* 0 (left) .. 31 (right) */
3.18 uint32_t sample_rate;
3.19 int sample_format;
3.20 /* Envelope etc stuff */
.