kopia lustrzana https://github.com/OpenRTX/OpenRTX
Re-implemented microphone testsuite using audio input stream
rodzic
943838c263
commit
5abb5263db
|
@ -1,5 +1,5 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
|
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||||
* Niccolò Izzo IU2KIN, *
|
* Niccolò Izzo IU2KIN, *
|
||||||
* Frederik Saraci IU2NRO, *
|
* Frederik Saraci IU2NRO, *
|
||||||
* Silvano Seva IU2KWO *
|
* Silvano Seva IU2KWO *
|
||||||
|
@ -21,129 +21,47 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <interfaces/delays.h>
|
#include <interfaces/delays.h>
|
||||||
#include <interfaces/gpio.h>
|
#include <interfaces/audio.h>
|
||||||
#include <hwconfig.h>
|
#include <interfaces/audio_path.h>
|
||||||
|
#include <interfaces/audio_stream.h>
|
||||||
/*
|
#include <interfaces/platform.h>
|
||||||
* Uncomment this directive to sample audio coming from RTX stage instead of the
|
#include <dsp.h>
|
||||||
* one from microphone.
|
|
||||||
*/
|
|
||||||
// #define SAMPLE_RTX_AUDIO
|
|
||||||
|
|
||||||
static const char hexdigits[]="0123456789abcdef";
|
|
||||||
void printUnsignedInt(uint16_t x)
|
|
||||||
{
|
|
||||||
char result[]="....\r";
|
|
||||||
for(int i=3;i>=0;i--)
|
|
||||||
{
|
|
||||||
result[i]=hexdigits[x & 0xf];
|
|
||||||
x>>=4;
|
|
||||||
}
|
|
||||||
puts(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// platform_init();
|
platform_init();
|
||||||
|
|
||||||
static const size_t numSamples = 45*1024; // 80kB
|
static const size_t numSamples = 45*1024; // 90kB
|
||||||
uint16_t *sampleBuf = ((uint16_t *) malloc(numSamples * sizeof(uint16_t)));
|
stream_sample_t *sampleBuf = ((stream_sample_t *) malloc(numSamples *
|
||||||
|
sizeof(stream_sample_t)));
|
||||||
|
|
||||||
gpio_setMode(GREEN_LED, OUTPUT);
|
audio_enableMic();
|
||||||
gpio_setMode(RED_LED, OUTPUT);
|
streamId id = inputStream_start(SOURCE_MIC, PRIO_TX, sampleBuf, numSamples,
|
||||||
gpio_setMode(MIC_PWR, OUTPUT);
|
BUF_LINEAR, 8000);
|
||||||
gpio_setPin(MIC_PWR);
|
|
||||||
|
|
||||||
#ifdef SAMPLE_RTX_AUDIO
|
sleepFor(3u, 0u);
|
||||||
gpio_setMode(GPIOC, 13, INPUT_ANALOG);
|
platform_ledOn(GREEN);
|
||||||
#else
|
|
||||||
gpio_setMode(AIN_MIC, INPUT_ANALOG);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Enable pull-up resistor on PA3 (AIN_MIC)
|
dataBlock_t audio = inputStream_getData(id);
|
||||||
GPIOA->PUPDR |= 1 << 6; */
|
|
||||||
|
|
||||||
delayMs(3000);
|
platform_ledOff(GREEN);
|
||||||
|
platform_ledOn(RED);
|
||||||
|
sleepFor(10u, 0u);
|
||||||
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
// Pre-processing gain
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
for(size_t i = 0; i < audio.len; i++) audio.data[i] <<= 3;
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
|
|
||||||
__DSB();
|
|
||||||
|
|
||||||
/*
|
// DC removal
|
||||||
* TIM2 for conversion triggering via TIM2_TRGO, that is counter reload.
|
dsp_dcRemoval(audio.data, audio.len);
|
||||||
* AP1 frequency is 42MHz but timer runs at 84MHz, configure for 8kHz interrupt rate.
|
|
||||||
*/
|
|
||||||
TIM2->PSC = 83; /* Tick rate 1MHz */
|
|
||||||
TIM2->ARR = 124; /* Overflow rate 8kHz */
|
|
||||||
TIM2->CNT = 0;
|
|
||||||
TIM2->EGR = TIM_EGR_UG;
|
|
||||||
TIM2->CR2 = TIM_CR2_MMS_1;
|
|
||||||
TIM2->CR1 = TIM_CR1_CEN;
|
|
||||||
|
|
||||||
/* DMA2 Stream 0 configuration:
|
// Post-processing gain
|
||||||
* - channel 0: ADC1
|
for(size_t i = 0; i < audio.len; i++) audio.data[i] *= 10;
|
||||||
* - low priority
|
|
||||||
* - half-word transfer, both memory and peripheral
|
|
||||||
* - increment memory
|
|
||||||
* - peripheral-to-memory transfer
|
|
||||||
* - no interrupts
|
|
||||||
*/
|
|
||||||
DMA2_Stream0->PAR = ((uint32_t) &(ADC1->DR));
|
|
||||||
DMA2_Stream0->M0AR = ((uint32_t) sampleBuf);
|
|
||||||
DMA2_Stream0->NDTR = numSamples;
|
|
||||||
DMA2_Stream0->CR = DMA_SxCR_MSIZE_0 /* Memory size: 16 bit */
|
|
||||||
| DMA_SxCR_PSIZE_0 /* Peripheral size: 16 bit */
|
|
||||||
| DMA_SxCR_PL_0 /* Medium priority */
|
|
||||||
| DMA_SxCR_MINC /* Increment memory */
|
|
||||||
| DMA_SxCR_EN;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ADC clock is APB2 frequency divided by 8, giving 10.5MHz.
|
|
||||||
* A conversion takes 12 cycles.
|
|
||||||
*/
|
|
||||||
ADC->CCR |= ADC_CCR_ADCPRE;
|
|
||||||
ADC1->SMPR2 = ADC_SMPR2_SMP0
|
|
||||||
| ADC_SMPR2_SMP1
|
|
||||||
| ADC_SMPR2_SMP3
|
|
||||||
| ADC_SMPR2_SMP8;
|
|
||||||
|
|
||||||
ADC1->SQR1 = 0; /* One channel to be converted */
|
uint16_t *ptr = ((uint16_t *) audio.data);
|
||||||
|
for(size_t i = 0; i < audio.len; i++)
|
||||||
#ifdef SAMPLE_RTX_AUDIO
|
|
||||||
ADC1->SQR3 = 13; /* CH13, audio from RTX on PC13 */
|
|
||||||
#else
|
|
||||||
ADC1->SQR3 = 3; /* CH3, vox level on PA3 */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* No overrun interrupt, 12-bit resolution, no analog watchdog, no
|
|
||||||
* discontinuous mode, enable scan mode, no end of conversion interrupts,
|
|
||||||
* enable continuous conversion (free-running).
|
|
||||||
*/
|
|
||||||
ADC1->CR1 |= ADC_CR1_DISCEN;
|
|
||||||
ADC1->CR2 |= ADC_CR2_EXTEN_0 /* Trigger on rising edge */
|
|
||||||
| ADC_CR2_EXTSEL_1
|
|
||||||
| ADC_CR2_EXTSEL_2 /* 0b0110 TIM2_TRGO trig. source */
|
|
||||||
| ADC_CR2_DDS /* Enable DMA data transfer */
|
|
||||||
| ADC_CR2_DMA
|
|
||||||
| ADC_CR2_ALIGN
|
|
||||||
| ADC_CR2_ADON; /* Enable ADC */
|
|
||||||
|
|
||||||
while((DMA2_Stream0->CR & DMA_SxCR_EN) == 1)
|
|
||||||
{
|
{
|
||||||
gpio_togglePin(GREEN_LED);
|
iprintf("%04x ", ptr[i]);
|
||||||
delayMs(250);
|
|
||||||
}
|
|
||||||
|
|
||||||
gpio_clearPin(GREEN_LED);
|
|
||||||
gpio_setPin(RED_LED);
|
|
||||||
|
|
||||||
delayMs(10000);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < numSamples; i++)
|
|
||||||
{
|
|
||||||
printUnsignedInt(sampleBuf[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) ;
|
while(1) ;
|
||||||
|
|
Ładowanie…
Reference in New Issue