- UID
- 1029342
- 性别
- 男
|
这段代码实现了录制一段2声道、44.1KHz音频数据的功能。参数buffer指明这个录制的音频数据存放的位置。和播放的代码比较起来L3总线的操作多了几条命令:
01 void record(unsigned char *buffer)
02 {
03 int count,i,flag = 1;
04 int temp;
05
06 GPBDAT = (GPBDAT & (~(L3M | L3C | L3D))) | (L3M | L3C);
07 WriteL3(0x14 + 2,1);
08 WriteL3(0x60,0);
09
10 WriteL3(0x14 + 2,1);
11 WriteL3(0x10,0);
12
13 WriteL3(0x14 + 2,1);
14 WriteL3(0xc1,0);
15
16 WriteL3(0x14 + 2,1);
17 //1,1,1,0,0,0,11——DAC输出增益选择为6db(OGS),ADC输入增益选择为6db(IGS),ADC极性不翻转,DAC极性不翻转,
18 //倍速回放关闭,ADC启动DAC启动(启动了DAC后,自己说话就能在耳机中听到)
19 WriteL3(0xe3,0);
20
21 WriteL3(0x14 + 0,1);
22 //01,1110,11——低音增强设置FLAT为0db,MIN为18db,MAX为24db
23 WriteL3(0x7b,0);
24
25 //11000,1,0,0——扩展地址0x4
26 WriteL3(0xc4,0);
27 //111,1,0,0,0,0——对应的扩展数据0x10开启AGC(MIC敏感度增益控制设置)
28 WriteL3(0xf0,0);
29
30 //11000,0,0,0——扩展地址0x0
31 WriteL3(0xc0,0);
32 //111,0,0,0,0,0——对应的扩展数据0x0混频增益控制通道1的MA设置为0
33 WriteL3(0xe0,0);
34
35 //11000,0,0,1——扩展地址0x1
36 WriteL3(0xc1,0);
37 //111,0,0,0,0,0——对应的扩展数据0x0混频增益控制通道2的MB设置为0
38 WriteL3(0xe0,0);
39
40 //11000,0,1,0——扩展地址0x2
41 WriteL3(0xc2,0);
42 ///111,1,1,0,0,1——对应的扩展数据0x19MIC敏感(MIC放大增益)为27db,混频模式为(输入通道1选择(同时输入通道2被关闭))
43 WriteL3(0xf9,0);
44
45 IISPSR = PRESCANLER_A(2) | PRESCANLER_B(2);
46 IISCON = TX_CH_IDLE_CMD | IIS_PRESCALER;
47 IISMOD = TX_RX_MODE(RX_MODE)| S_DATA_BIT(BIT16) | \
48 MA_CLOCK(FS384) | S_CLOCK(FS32);
49 IISFCON = RX_FIFO_AC(NORMAL) | RX_FIFO_EN;
50
51 count = 0;
52
53 IISCON |= 0x01;
54
55 while(flag)
56 {
57 if(0 == (IISCON & (1 << 6)))
58 {
59 for(i = 0;i < 32;i++)
60 {
61 temp = IISFIFO;
62 buffer[count + 2 * i + (flag - 1) * 6400] = (unsigned char)(temp & 0xff);
63 buffer[count + 2 * i + 1 + (flag - 1) * 6400] = (unsigned char)(temp >> 8);
64 }
65 count += 64;
66 if(count >= 6400)
67 {
68 count = 0;
69 flag++;
70 }
71 }
72 if(400 == flag)
73 flag = 0;
74 }
75 IISCON = 0x00;
76 }
总的来说,上面的两个功能和串口实验中没有开启中断的时候的构造相似。都是在一个循环内检测一个标识位,检测到FIFO准备好后就进入循环读取/写数据。 |
|