Search
lxdream.org :: lxdream/src/aica/aica.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/aica.c
changeset 82:81a4acf75f10
prev76:e9a0bd313036
next86:f151e63f9754
author nkeynes
date Tue Jan 17 12:54:02 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Add basic attempt at panning + proper volume
file annotate diff log raw
1.1 --- a/src/aica/aica.c Sat Jan 14 12:31:36 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;
.