diff options
| author | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2010-10-20 07:39:11 +0000 |
|---|---|---|
| committer | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2010-10-20 07:39:11 +0000 |
| commit | 4b5328f3bae564266411c6de4daaf09f7173aaab (patch) | |
| tree | b2633f86bc8d5155659cc9eae31672ff3958c07e /Demos/Device/ClassDriver/AudioInput/AudioInput.c | |
| parent | dfce01e2309c7e65b7b8f750f332cb2e38d39ac9 (diff) | |
Added default test tone generation mode to the Device mode AudioInput demos.
git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1534 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'Demos/Device/ClassDriver/AudioInput/AudioInput.c')
| -rw-r--r-- | Demos/Device/ClassDriver/AudioInput/AudioInput.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/Demos/Device/ClassDriver/AudioInput/AudioInput.c b/Demos/Device/ClassDriver/AudioInput/AudioInput.c index dc7a076e..54e70f6b 100644 --- a/Demos/Device/ClassDriver/AudioInput/AudioInput.c +++ b/Demos/Device/ClassDriver/AudioInput/AudioInput.c @@ -82,9 +82,10 @@ void SetupHardware(void) /* Hardware Initialization */ LEDs_Init(); - USB_Init(); + Buttons_Init(); ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32); ADC_SetupChannel(MIC_IN_ADC_CHANNEL); + USB_Init(); /* Start the ADC conversion in free running mode */ ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | MIC_IN_ADC_MUX_MASK); @@ -100,15 +101,29 @@ void ProcessNextSample(void) { /* Clear the sample reload timer compare flag, ready for the next interval */ 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); + + 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 #endif - + Audio_Device_WriteSample16(&Microphone_Audio_Interface, AudioSample); } } |
