--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ FILE........: iir_tuner.h
+ AUTHOR......: David Rowe
+ DATE CREATED: 20 Feb 2015
+
+ Header file for IIR tuner function.
+
+\*---------------------------------------------------------------------------*/
+
+/*
+ Copyright (C) 2015 David Rowe
+
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License version 2.1, as
+ published by the Free Software Foundation. This program is
+ distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __IIR_TUNER__
+#define __IIR_TUNER__
+
+#define IIR_TUNER_DEC_50_10_FILT_MEM 100
+
+void iir_tuner(float dec_50[], unsigned short adc_buf[]);
+void iir_tuner_dec_50_to_10(float dec_10[], float dec_50[], int n);
+
+#endif
#include "stm32f4_adc_tuner.h"\r
#include "iir_tuner.h"\r
#include "sm1000_leds_switches.h"\r
+#include "../src/codec2_fm.h"\r
+#include "stm32f4xx.h"\r
\r
#define REC_TIME_SECS 10\r
#define FS 50000\r
-#define N 10000\r
+#define N 5000\r
\r
extern int adc_overflow1;\r
\r
int main(void) {\r
float tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+N/2];\r
- float dec_10[(N/2)/5];\r
- short dec_10_short[(N/2)/5];\r
- int bufs, i, j, fifo_sz;\r
+ float fm_out[N/2];\r
+ //float dec_10[(N/2)/5];\r
+ short dec_10_short[(N/2)];\r
+ int bufs, i, j, k, fifo_sz, bn;\r
FILE *ftuner;\r
+ struct FM *fm;\r
\r
ftuner = fopen("tuner.raw", "wb");\r
if (ftuner == NULL) {\r
adc_open(fifo_sz);\r
sm1000_leds_switches_init();\r
\r
- for(i=0; i<bufs; i++) {\r
+ fm = fm_create(N/2);\r
+ fm->Fs = 44400.0;\r
+ fm->fm_max = 3000.0;\r
+ fm->fd = 5000.0;\r
+ fm->fc = fm->Fs/4;\r
\r
+ i = 0; bn = 0;\r
+ while(1) {\r
/* wait for buffer of Fs=50kHz tuner output samples */\r
\r
while(adc1_read((short *)&tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM], N) == -1);\r
/* The semi-hosting system can only handle Fs=16kHz and below so resample down\r
to Fs=10 kHz and convert to shorts */\r
\r
- //for(j=0; j<N/2; j++)\r
- // tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 45.0;\r
+ #ifdef SSB\r
iir_tuner_dec_50_to_10(dec_10, &tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM], N/2);\r
for(j=0; j<IIR_TUNER_DEC_50_10_FILT_MEM; j++)\r
tuner_out[j] = tuner_out[j+N/2];\r
for(j=0; j<(N/2)/5; j++)\r
dec_10_short[j] = dec_10[j]/ADC_TUNER_M;\r
-\r
- fwrite(dec_10_short, sizeof(short), (N/2)/5, ftuner);\r
- printf("%d %d\n", i, adc_overflow1);\r
+ #else\r
+ GPIOE->ODR |= (1 << 3);\r
+ /*\r
+ for(j=0; j<N/2; j++)\r
+ tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 0;\r
+ for(j=1; j<N/2; j+=4)\r
+ tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = 100;\r
+ for(j=3; j<N/2; j+=4)\r
+ tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j] = -100;\r
+ */\r
+ fm_demod(fm, fm_out, &tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM]);\r
+ GPIOE->ODR &= ~(1 << 3);\r
+\r
+ for(j=0,k=0; j<N/2; j+=5,k++)\r
+ dec_10_short[k+bn] = 16384*fm_out[j];\r
+ bn += (N/2)/5;\r
+ #endif\r
+\r
+ if ((bn == N/2) && (i < bufs)) {\r
+ //for(j=0; j<N/2; j++)\r
+ // dec_10_short[j] = tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+j];\r
+ fwrite(dec_10_short, sizeof(short), (N/2), ftuner);\r
+ bn = 0;\r
+ i += 5;\r
+ //fwrite(dec_10_short, sizeof(short), (N/2)/5, ftuner);\r
+ //printf("%d %d\n", i, adc_overflow1);\r
+ }\r
+ if (i == bufs) {\r
+ printf("finished! %d\n", adc_overflow1);\r
+ fclose(ftuner);\r
+ i++;\r
+ }\r
}\r
-\r
- printf("finished! %d\n", adc_overflow1);\r
- fclose(ftuner);\r
-\r
- while(1); /* keep ISR running */\r
}\r
\r