aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/LowLevel/AudioInput/AudioInput.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-10-20 07:39:11 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-10-20 07:39:11 +0000
commitbd337aced3b1888373030878bf1a49367bc37ab5 (patch)
treeb2633f86bc8d5155659cc9eae31672ff3958c07e /Demos/Device/LowLevel/AudioInput/AudioInput.c
parent06f222b3ed6f612f4ac1b21566547797d4db8013 (diff)
downloadlufa-bd337aced3b1888373030878bf1a49367bc37ab5.tar.gz
lufa-bd337aced3b1888373030878bf1a49367bc37ab5.tar.bz2
lufa-bd337aced3b1888373030878bf1a49367bc37ab5.zip
Added default test tone generation mode to the Device mode AudioInput demos.
Diffstat (limited to 'Demos/Device/LowLevel/AudioInput/AudioInput.c')
-rw-r--r--Demos/Device/LowLevel/AudioInput/AudioInput.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/Demos/Device/LowLevel/AudioInput/AudioInput.c b/Demos/Device/LowLevel/AudioInput/AudioInput.c
index a984a2ab8..e681f3bd1 100644
--- a/Demos/Device/LowLevel/AudioInput/AudioInput.c
+++ b/Demos/Device/LowLevel/AudioInput/AudioInput.c
@@ -68,6 +68,7 @@ void SetupHardware(void)
/* Hardware Initialization */
LEDs_Init();
+ Buttons_Init();
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
ADC_SetupChannel(MIC_IN_ADC_CHANNEL);
USB_Init();
@@ -164,13 +165,27 @@ void USB_Audio_Task(void)
/* Clear the sample reload timer */
TIFR0 |= (1 << OCF0A);
- /* Audio sample is ADC value scaled to fit the entire range */
- int16_t AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
-
- #if defined(MICROPHONE_BIASED_TO_HALF_RAIL)
- /* Microphone is biased to half rail voltage, subtract the bias from the sample value */
- AudioSample -= (SAMPLE_MAX_RANGE / 2);
- #endif
+ int16_t AudioSample;
+
+ #if defined(USE_TEST_TONE)
+ static uint8_t SquareWaveSampleCount;
+ static int16_t CurrentWaveValue;
+
+ /* In test tone mode, generate a square wave at 1/256 of the sample rate */
+ if (SquareWaveSampleCount++ == 0xFF)
+ CurrentWaveValue ^= 0x8000;
+
+ /* Only generate audio if the board button is being pressed */
+ AudioSample = (Buttons_GetStatus() & BUTTONS_BUTTON1) ? CurrentWaveValue : 0;
+ #else
+ /* Audio sample is ADC value scaled to fit the entire range */
+ AudioSample = ((SAMPLE_MAX_RANGE / ADC_MAX_RANGE) * ADC_GetResult());
+
+ #if defined(MICROPHONE_BIASED_TO_HALF_RAIL)
+ /* Microphone is biased to half rail voltage, subtract the bias from the sample value */
+ AudioSample -= (SAMPLE_MAX_RANGE / 2);
+ #endif
+ #end if
/* Write the sample to the buffer */
Endpoint_Write_Word_LE(AudioSample);