Re: [hatari-devel] Falcon left-right sound swapper bug? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Falcon left-right sound swapper bug?
- From: David Savinkoff <dsavnkff@xxxxxxxxx>
- Date: Mon, 21 Apr 2014 00:26:38 -0600 (MDT)
- Thread-index: 6Ku/Z/0tbZMTjynw0kJ8w3n1WzutdKMSlDKhzzBms1M=
- Thread-topic: Falcon left-right sound swapper bug?
Hi,
This patch adds a ring buffer for the microphone. Apply this patch
(mic.patch) after (fifo.patch). Note that this patch compiles, but is
untested because I don't know how to test the microphone. Please
test it for me.
Thank you for the feedback. I'll improve the patch and add anti-aliasing
over the next few days. I will remove the zeros from the patch and
replace with filtered samples.
David Savinkoff
--- hatari/src/falcon/crossbar.c 2014-04-20 23:06:52.000000000 -0700
+++ hatari/src/falcon/crossbar.c 2014-04-20 23:07:55.000000000 -0700
@@ -261,8 +261,6 @@
Uint32 dmaRecord_CurrentFrameStart; /* current DmaPlay Frame end ($ff890f $ff8911 $ff8913) */
Uint32 dmaRecord_CurrentFrameCount; /* current DmaRecord Frame start ($ff8903 $ff8905 $ff8907) */
Uint32 dmaRecord_CurrentFrameEnd; /* current DmaRecord Frame end ($ff890f $ff8911 $ff8913) */
- Uint32 adc2dac_readBufferPosition; /* read position for direct adc->dac transfer */
- Sint64 adc2dac_readBufferPosition_float; /* float value of read position for direct adc->dac transfer index */
Uint32 save_special_transfer; /* Used in a special undocumented transfer mode (dsp sent is not in handshake mode and dsp receive is in handshake mode) */
};
@@ -294,6 +292,7 @@
static struct dma_s dmaRecord;
static struct codec_s dac;
static struct codec_s adc;
+static struct codec_s mic;
static struct dsp_s dspXmit;
static struct dsp_s dspReceive;
@@ -337,6 +336,13 @@
adc.writePosition = 0;
adc.FIFO_NbBytes = 0;
+ /* Microphone inits */
+ memset(mic.buffer_left, 0, sizeof(mic.buffer_left));
+ memset(mic.buffer_right, 0, sizeof(mic.buffer_right));
+ mic.readPosition = 0;
+ mic.writePosition = 0;
+ mic.FIFO_NbBytes = 0;
+
/* DSP inits */
dspXmit.wordCount = 0;
@@ -366,8 +372,6 @@
crossbar.gainSettingRight = 3276;
crossbar.attenuationSettingLeft = 65535;
crossbar.attenuationSettingRight = 65535;
- crossbar.adc2dac_readBufferPosition = 0;
- crossbar.adc2dac_readBufferPosition_float = 0;
/* Start 25 Mhz and 32 Mhz Clocks */
Crossbar_Recalculate_Clocks_Cycles();
@@ -1716,6 +1720,21 @@
adc.readPosition = adc.writePosition;
}
}
+
+ bufferIndex = 0;
+ for (i = 0; i < microBuffer_size; i++) {
+ mic.buffer_left[mic.writePosition] = micro_bufferL[bufferIndex];
+ mic.buffer_right[mic.writePosition] = micro_bufferR[bufferIndex];
+
+ bufferIndex++;
+
+ mic.writePosition = (mic.writePosition + 1) % DACBUFFER_SIZE;
+
+ if (++mic.FIFO_NbBytes > DACBUFFER_SIZE) {
+ mic.FIFO_NbBytes = DACBUFFER_SIZE;
+ mic.readPosition = mic.writePosition;
+ }
+ }
}
/**
@@ -1805,20 +1824,6 @@
unsigned n = 0;
Sint16 adc_leftData, adc_rightData, dac_LeftData, dac_RightData;
- if (crossbar.isDacMuted) {
- /* Output sound = 0 */
- for (i = 0; i < nSamplesToGenerate; i++) {
- nBufIdx = (nMixBufIdx + i) % MIXBUFFER_SIZE;
- MixBuffer[nBufIdx][0] = 0;
- MixBuffer[nBufIdx][1] = 0;
- }
-
- /* Counters are refreshed for when DAC becomes unmuted */
- dac.readPosition = dac.writePosition;
- crossbar.adc2dac_readBufferPosition = adc.writePosition;
- return;
- }
-
for (i = 0; i < nSamplesToGenerate; i++)
{
nBufIdx = (nMixBufIdx + i) % MIXBUFFER_SIZE;
@@ -1830,23 +1835,30 @@
dac.buffer_right[dac.writePosition] = 0;
}
+ if (--mic.FIFO_NbBytes < 0) {
+ mic.FIFO_NbBytes = 0;
+ mic.writePosition = mic.readPosition;
+ mic.buffer_left[mic.writePosition] = 0;
+ mic.buffer_right[mic.writePosition] = 0;
+ }
+
/* ADC mixing (PSG sound or microphone sound for left and right channels) */
switch (crossbar.codecAdcInput) {
case 0:
default: /* Just here to remove compiler's warnings */
/* Microphone sound for left and right channels */
- adc_leftData = adc.buffer_left[crossbar.adc2dac_readBufferPosition];
- adc_rightData = adc.buffer_right[crossbar.adc2dac_readBufferPosition];
+ adc_leftData = mic.buffer_left[mic.readPosition];
+ adc_rightData = mic.buffer_right[mic.readPosition];
break;
case 1:
/* Microphone sound for left channel, PSG sound for right channel */
- adc_leftData = adc.buffer_left[crossbar.adc2dac_readBufferPosition];
+ adc_leftData = mic.buffer_left[mic.readPosition];
adc_rightData = MixBuffer[nBufIdx][1];
break;
case 2:
/* PSG sound for left channel, microphone sound for right channel */
adc_leftData = MixBuffer[nBufIdx][0];
- adc_rightData = adc.buffer_right[crossbar.adc2dac_readBufferPosition];
+ adc_rightData = mic.buffer_right[mic.readPosition];
break;
case 3:
/* PSG sound for left and right channels */
@@ -1891,10 +1903,12 @@
dac.readPosition = (dac.readPosition + n) % DACBUFFER_SIZE;
dac.readPosition_float &= 0xffffffff; /* only keep the fractional part */
- /* Upgrade adc->dac's buffer read pointer */
- crossbar.adc2dac_readBufferPosition_float += crossbar.frequence_ratio;
- n = crossbar.adc2dac_readBufferPosition_float >> 32; /* number of samples to skip */
- crossbar.adc2dac_readBufferPosition = (crossbar.adc2dac_readBufferPosition + n) % DACBUFFER_SIZE;
- crossbar.adc2dac_readBufferPosition_float &= 0xffffffff; /* only keep the fractional part */
+ /* Upgrade microphone buffer read pointer */
+ mic.readPosition = ++mic.readPosition % DACBUFFER_SIZE;
+
+ if (crossbar.isDacMuted) {
+ MixBuffer[nBufIdx][0] = 0;
+ MixBuffer[nBufIdx][1] = 0;
+ }
}
}