DSP5509项目之用FFT识别钢琴音调(4)之麦克风输入

1. 麦克风输入需要修改的内容,之前的版本是LINE IN的输入。实现功能,检测麦克风的输入,并且同时在耳机里面播放。

#include <csl.h>
#include <csl_i2c.h>
#include <stdio.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>

#include "myapp.h"
#include "csedu.h"
#include "scancode.h"
#include <math.h>

#define CODEC_ADDR 0x1A

/*锁相环的设置*/
PLL_Config  myConfig      = {
  0,    //IAI: the PLL locks using the same process that was underway
                //before the idle mode was entered
  1,    //IOB: If the PLL indicates a break in the phase lock,
                //it switches to its bypass mode and restarts the PLL phase-locking
                //sequence
  12,    //PLL multiply value; multiply 24 times
  1             //Divide by 2 PLL divide value; it can be either PLL divide value
                //(when PLL is enabled), or Bypass-mode divide value
                //(PLL in bypass mode, if PLL multiply value is set to 1)
};

//FFT相关的代码
#define PI 3.1415926
#define SAMPLENUMBER 128

void InitForFFT();
void MakeWave();

int INPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
float fWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER],w[SAMPLENUMBER];
float sin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];
MCBSP_Config Mcbsptest;

/*McBSP set,we use mcbsp1 to send and recieve the data between DSP and AIC23*/
MCBSP_Config Mcbsp1Config = {
  MCBSP_SPCR1_RMK(
    MCBSP_SPCR1_DLB_OFF,                   /* DLB    = 0,禁止自闭环方式 */
    MCBSP_SPCR1_RJUST_LZF,                 /* RJUST  = 2 */
    MCBSP_SPCR1_CLKSTP_DISABLE,            /* CLKSTP = 0 */
    MCBSP_SPCR1_DXENA_ON,                  /* DXENA  = 1 */
    0,                                     /* ABIS   = 0 */
    MCBSP_SPCR1_RINTM_RRDY,                /* RINTM  = 0 */
    0,                                     /* RSYNCER = 0 */
    MCBSP_SPCR1_RRST_DISABLE               /* RRST   = 0 */
   ),
    MCBSP_SPCR2_RMK(
    MCBSP_SPCR2_FREE_NO,                   /* FREE   = 0 */
    MCBSP_SPCR2_SOFT_NO,                   /* SOFT   = 0 */
    MCBSP_SPCR2_FRST_FSG,                  /* FRST   = 0 */
    MCBSP_SPCR2_GRST_CLKG,                 /* GRST   = 0 */
    MCBSP_SPCR2_XINTM_XRDY,                /* XINTM  = 0 */
    0,                                     /* XSYNCER = N/A */
    MCBSP_SPCR2_XRST_DISABLE               /* XRST   = 0 */
   ),
   /*单数据相,接受数据长度为16位,每相2个数据*/
  MCBSP_RCR1_RMK(
      MCBSP_RCR1_RFRLEN1_OF(1),              /* RFRLEN1 = 1 */
      MCBSP_RCR1_RWDLEN1_16BIT               /* RWDLEN1 = 2 */
  ),
  MCBSP_RCR2_RMK(
    MCBSP_RCR2_RPHASE_SINGLE,              /* RPHASE  = 0 */
    MCBSP_RCR2_RFRLEN2_OF(0),              /* RFRLEN2 = 0 */
    MCBSP_RCR2_RWDLEN2_8BIT,               /* RWDLEN2 = 0 */
    MCBSP_RCR2_RCOMPAND_MSB,               /* RCOMPAND = 0 */
    MCBSP_RCR2_RFIG_YES,                   /* RFIG    = 0 */
    MCBSP_RCR2_RDATDLY_1BIT                /* RDATDLY = 1 */
    ),
   MCBSP_XCR1_RMK(
    MCBSP_XCR1_XFRLEN1_OF(1),              /* XFRLEN1 = 1 */
    MCBSP_XCR1_XWDLEN1_16BIT               /* XWDLEN1 = 2 */

 ),
 MCBSP_XCR2_RMK(
    MCBSP_XCR2_XPHASE_SINGLE,              /* XPHASE  = 0 */
    MCBSP_XCR2_XFRLEN2_OF(0),              /* XFRLEN2 = 0 */
    MCBSP_XCR2_XWDLEN2_8BIT,               /* XWDLEN2 = 0 */
    MCBSP_XCR2_XCOMPAND_MSB,               /* XCOMPAND = 0 */
    MCBSP_XCR2_XFIG_YES,                   /* XFIG    = 0 */
    MCBSP_XCR2_XDATDLY_1BIT                /* XDATDLY = 1 */
  ),
 MCBSP_SRGR1_DEFAULT,
 MCBSP_SRGR2_DEFAULT,
 MCBSP_MCR1_DEFAULT,
 MCBSP_MCR2_DEFAULT,
 MCBSP_PCR_RMK(
   MCBSP_PCR_IDLEEN_RESET,                 /* IDLEEN   = 0   */
   MCBSP_PCR_XIOEN_SP,                     /* XIOEN    = 0   */
   MCBSP_PCR_RIOEN_SP,                     /* RIOEN    = 0   */
   MCBSP_PCR_FSXM_EXTERNAL,                /* FSXM     = 0   */
   MCBSP_PCR_FSRM_EXTERNAL,                /* FSRM     = 0   */
   0,                                      /* DXSTAT = N/A   */
   MCBSP_PCR_CLKXM_INPUT,                  /* CLKXM    = 0   */
   MCBSP_PCR_CLKRM_INPUT,                  /* CLKRM    = 0   */
   MCBSP_PCR_SCLKME_NO,                    /* SCLKME   = 0   */
   MCBSP_PCR_FSXP_ACTIVEHIGH,              /* FSXP     = 0   */
   MCBSP_PCR_FSRP_ACTIVEHIGH,              /* FSRP     = 1   */
   MCBSP_PCR_CLKXP_FALLING,                /* CLKXP    = 1   */
   MCBSP_PCR_CLKRP_RISING                  /* CLKRP    = 1   */
 ),
 MCBSP_RCERA_DEFAULT,
 MCBSP_RCERB_DEFAULT,
 MCBSP_RCERC_DEFAULT,
 MCBSP_RCERD_DEFAULT,
 MCBSP_RCERE_DEFAULT,
 MCBSP_RCERF_DEFAULT,
 MCBSP_RCERG_DEFAULT,
 MCBSP_RCERH_DEFAULT,
 MCBSP_XCERA_DEFAULT,
 MCBSP_XCERB_DEFAULT,
 MCBSP_XCERC_DEFAULT,
 MCBSP_XCERD_DEFAULT,
 MCBSP_XCERE_DEFAULT,
 MCBSP_XCERF_DEFAULT,
 MCBSP_XCERG_DEFAULT,
 MCBSP_XCERH_DEFAULT
};
/* This next struct shows how to use the I2C API */
/* Create and initialize an I2C initialization structure */
I2C_Setup I2Cinit = {
        0,              /* 7 bit address mode */
        0,         /* own address - don‘t care if master */
        84,            /* clkout value (Mhz)  */
        50,            /* a number between 10 and 400*/
        0,              /* number of bits/byte to be received or transmitted (8)*/
        0,              /* DLB mode on*/
        1               /* FREE mode of operation on*/
};

I2C_Config testI2C;

/*数字音频接口格式设置
AIC23为主模式,数据为DSP模式,数据长度16位*/
//Uint16 digital_audio_inteface_format[2]={0x0e,0x53};
Uint16 digital_audio_inteface_format[2]={0x0e,0x43};
/*AIC23的波特率设置,采样率为44.1K*/
Uint16 sample_rate_control[2] = {0x10,0x23};
/*AIC23寄存器复位*/
Uint16 reset[2] ={0x1e,0x00};
/*AIC23节电方式设置,所有部分均所与工作状态*/
//Uint16 power_down_control[2] ={0x0c,0x03};
Uint16 power_down_control[2] ={0x0c,0x00};
/*AIC23模拟音频的控制
//DAC使能,ADC输入选择为Line*/
//Uint16 analog_aduio_path_control[2] ={0x08,0x10};

//DAC使能,ADC输入选择为麦克风*/
Uint16 analog_aduio_path_control[2] ={0x08,0x17};

/*AIC23数字音频通路的控制*/
Uint16 digital_audio_path_control[2] ={0x0a,0x05};
/*AIC23数字接口的使能*/
Uint16 digital_interface_activation[2] ={0x12,0x01};

/*AIC23左通路音频调节*/
Uint16 left_line_input_volume_control[2] ={0x00,0x17};
/*AIC23右通路音频调节*/
Uint16 right_line_input_volume_control[2] ={0x02,0x17};

///*AIC23左通路音频调节*/
//Uint16 left_mic_input_volume_control[2] ={0x04,0x79};
///*AIC23右通路音频调节*/
//Uint16 right_mic_input_volume_control[2] ={0x06,0x79};

/*AIC23耳机左通路音频调节*/
//Uint16 left_headphone_volume_control[2] ={0x04,0xFF};
///*AIC23耳机右通路音频调节*/
//Uint16 right_headphone_volume_control[2] = {0x06,0xFF};

Uint16 left_headphone_volume_control[2] ={0x04,0x79};
/*AIC23耳机右通路音频调节*/
Uint16 right_headphone_volume_control[2] = {0x06,0x79};
/*定义McBSP的句柄*/
MCBSP_Handle hMcbsp;

Uint16 i2c_status;
Uint16 i,temp;

void delay(Uint32 k)
{
   while(k--);
}

void main(void)
{

    Uint16 aic23data = 0;
    i2c_status = 1;
    /* Initialize CSL library - This is REQUIRED !!! */
    /*初始化CSL库*/
    CSL_init();

    /*设置系统的运行速度为140MHz*/
    PLL_config(&myConfig);

    /* Initialize I2C, using parameters in init structure */
    /*初始化I2C的格式*/

//    I2C_config(&Config);
//    I2C_start();

//    I2C_getConfig(&Config1);
    /*I2C is undet reset*/
    I2C_RSET(I2CMDR,0);
    /*设置预分频寄存器,I2C的mode clock is 10MHz*/
    delay(100);
    I2C_RSET(I2CSAR,0x001A);
    I2C_RSET(I2CMDR,0x0620);

    I2C_setup(&I2Cinit);
      /*设置I2C的Mater clock*/
    I2C_RSET(I2CCLKL,100);
    I2C_RSET(I2CCLKH,100);

    I2C_getConfig(&testI2C);

    /*初始化McBSP0*/
    hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);
    /*设置McBSP0*/
    MCBSP_config(hMcbsp,&Mcbsp1Config);
    /*启动McBSP0*/
    MCBSP_start(hMcbsp,
                MCBSP_RCV_START | MCBSP_XMIT_START,
                0);

    MCBSP_getConfig(hMcbsp,&Mcbsptest);

    /*reset AIC23*/
    i2c_status = I2C_write( reset,          //pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    delay(1000);
    /*设置AIC23各部分均工作*/
    i2c_status = I2C_write( power_down_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    /*设置AIC23的数字接口*/
    i2c_status = I2C_write( digital_audio_inteface_format,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                               );
     /*设置AIC23模拟通路*/
    i2c_status = I2C_write( analog_aduio_path_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    /*设置数字通路*/
    i2c_status = I2C_write( digital_audio_path_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                              );
    /*设置AIC23的采样率*/
    i2c_status = I2C_write( sample_rate_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    /*设置耳机音量*/
    i2c_status = I2C_write( left_headphone_volume_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    i2c_status = I2C_write( right_headphone_volume_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    /*设置Line输入的音量*/
    i2c_status = I2C_write( left_line_input_volume_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );
    i2c_status = I2C_write( right_line_input_volume_control,//pointer to data array
                            2,                //length of data to be transmitted
                            1,                //master or slaver
                            CODEC_ADDR,        //slave address to transmit to
                            1,                //transfer mode of operation
                            30000            //time out for bus busy
                            );

    /*启动AIC23*/
    i2c_status = I2C_write( digital_interface_activation,//pointer to data array
               2,                //length of data to be transmitted
               1,                //master or slaver
               CODEC_ADDR,        //slave address to transmit to
               1,                //transfer mode of operation
               30000            //time out for bus busy
               );

    /*回放音频*/
    //每次读取256个字符,然后进行解析
    //现在需要解决的问题是,1. 确定多久采样一次。2. 滤波的问题
    //3. 从Line in输入改成麦克风

    //进行FFT的初始化
    InitForFFT();

    while(TRUE)
    {
        while(!MCBSP_rrdy(hMcbsp)){};
        aic23data = MCBSP_read16(hMcbsp);
                MCBSP_write16(hMcbsp,aic23data);

    }
}

2. 上面调试的问题关键在于是TLV320AIC23的寄存器

原文地址:https://www.cnblogs.com/429512065qhq/p/9574365.html

时间: 2024-11-03 02:46:41

DSP5509项目之用FFT识别钢琴音调(4)之麦克风输入的相关文章

DSP5509项目之用FFT识别钢琴音调(5)之开始傅里叶变换

1. 首先电脑上下载一个模拟钢琴的软件 2. 研究下钢琴的声音范围27HZ到4000HZ,那么采样频率需要是信号的两倍频率以上,所以建议采样频率是16KHZ. 原文地址:https://www.cnblogs.com/429512065qhq/p/9581618.html

DSP5509项目之用FFT识别钢琴音调(3)之ccs v6环境变量的配置

1. 添加头文件路径,没搞明白"${C5500_CSL_CG_ROOT}/include"里面的C5500_CSL_CG_ROOT是在哪里定义的? 2. 打开CCS的窗口,优选项配置 3. 勾选上,查看系统的变量 4. 自己添加变量 原文地址:https://www.cnblogs.com/429512065qhq/p/9557220.html

项目一:人脸识别(1)

1.简介: /********************************************************************** 最近开始人脸识别的个人项目练习,其实该项目中所谓的识别仅仅只是检测,我们先从最简单 的调用opencv训练好的分类器和函数,虽然只是调用,我觉得这是接触人脸识别的必经之路,只有自己亲自动手做了,虽然在重复造轮子,但只有自己亲自动手造出来的轮子,才能内化 为自己的东西. 平台:ubuntu16.04+opencv3.2 ************

[blog 项目实战派]钢管识别项目2

钢管识别项目2 零.相关说明: 首先进行一下相关说明.在"jsxyhelu.cnblogs.com/项目实战派"栏目里面出现的需求.图片和其他资源,都是我在浏览威客网站.论坛等网站的时候通过正规渠道获得的真实需求.个人觉得比较感兴趣,但是由于时间或者工作的冲突自己没有去接这些项目.但是由于这些需求都很有实现价值,所以过了一段时间,仍然拿出来练一练手,并且实现了核心模块.希望能够给浏览者一些启发.如果你认为这些图片和资源放在这里不合适,请及时联系我([email protected]),

[blog 项目实战派]钢管识别项目1

钢管识别项目1 零.相关说明: 首先进行一下相关说明.在"jsxyhelu.cnblogs.com/项目实战派"栏目里面出现的需求.图片和其他资源,都是我在浏览威客网站.论坛等网站的时候通过正规渠道获得的真实需求.个人觉得比较感兴趣,但是由于时间或者工作的冲突自己没有去接这些项目.但是由于这些需求都很有实现价值,所以过了一段时间,仍然拿出来练一练手,并且实现了核心模块.希望能够给浏览者一些启发.如果你认为这些图片和资源放在这里不合适,请及时联系我([email protected]),

[blog 项目实战派]压板识别项目分析

压板识别项目 零.相关说明: 首先进行一下相关说明.在"jsxyhelu.cnblogs.com/项目实战派"栏目里面出现的需求.图片和其他资源,都是我在浏览威客网站.论坛等网站的时候通过正规渠道获得的真实需求.个人觉得比较感兴趣,但是由于时间或者工作的冲突自己没有去接这些项目.但是由于这些需求都很有实现价值,所以过了一段时间,仍然拿出来练一练手,并且实现了核心模块.希望能够给浏览者一些启发.如果你认为这些图片和资源放在这里不合适,请及时联系我([email protected]),我

项目一:麻将牌识别

因其安装环境的限制,从摄像头采集到的图像只能是部分图: 然后按照其硬件规律,拼接成一张完整的牌面: 然后放到分到做好的分类器里面训练,再识别: 结语:识别程序做成SDK的形式,后来发现由于没有考虑到多线程的问题,导致后期程序修改比较麻烦:由于图片比较小,所以,这个拼图加识别速度足够快,在处理图像采集之后就完成了拼图与识别工作,完全不影响其它数据传输工作.识别率方面,万字识别率较低,这是今后要改进的地方.

机器学习进阶-项目实战-信用卡数字识别 1.cv2.findContour(找出轮廓) 2.cv2.boudingRect(轮廓外接矩阵位置) 3.cv2.threshold(图片二值化操作) 4.cv2.MORPH_TOPHAT(礼帽运算突出线条) 5.cv2.MORPH_CLOSE(闭运算图片内部膨胀) 6. cv2.resize(改变图像大小) 7.cv2.putText(在图片上放上文本)

7. cv2.putText(img, text, loc, text_font, font_scale, color, linestick) # 参数说明:img表示输入图片,text表示需要填写的文本str格式,loc表示文本在图中的位置,font_size可以使用cv2.FONT_HERSHEY_SIMPLEX, font_scale表示文本的规格,color表示文本颜色,linestick表示线条大小 信用卡数字识别: 信用卡      数字模板涉及到的内容:主要是采用模板匹配的思想 思

阅读项目:通过机器学习识别手写数字

地址:https://github.com/JosephPai/KaggleSolution/tree/master/DigitRec 数据集:https://www.kaggle.com/c/digit-recognizer/data import pandas as pd import matplotlib.pyplot as plt, matplotlib.image as mpimg from sklearn.model_selection import train_test_split