我所拥有的例程是关于警报声的和实时录音回放的。
以下是警报声代码:
//发出报警声
while(1)
{
for(temp=30000;temp>0;temp-=100)
{
for(i=0;i<2;i++)
{
y=200;
Mydelay(temp);
McbspaRegs.DXR1.all = y;// 输出左声道数据
McbspaRegs.DXR2.all = y;// 输出右声道数据
y=100;
Mydelay(temp);
McbspaRegs.DXR1.all = y;// 输出左声道数据
McbspaRegs.DXR2.all = y;// 输出右声道数据
}
}
}
延时的目的是调整音调,也就是频率。y是电压值,也就是音量。那么如何播放一个单一频率的正弦波呢?
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 table[SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};
void tone(Uint32 sf, Int16 playtime, Int16 gDAC, Uint16 gADC, Int16 *sinetable)
{
Int16 sec, msec;
Int16 sample, len;
USBSTK5505_init( );
CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A20_MODE, MODE1);
USBSTK5505_GPIO_init();
USBSTK5505_GPIO_setDirection(GPIO26, GPIO_OUT);
USBSTK5505_GPIO_setOutput( GPIO26, 1 );
USBSTK5505_I2C_init( );
Init_AIC3204(sf, gDAC, gADC);
USBSTK5505_I2S_init();
switch (sf)
{
case 8000:
len = 8;
break;
case 12000:
len = 12;
break;
case 16000:
len = 16;
break;
case 24000:
len = 24;
break;
case 48000:
default:
len = 48;
break;
}
for ( sec = 0 ; sec < playtime ; sec++ )
{
for ( msec = 0 ; msec < 1000 ; msec++ )
{
for ( sample = 0 ; sample < len ; sample++ )
{
USBSTK5505_I2S_writeLeft( sinetable[sample]);
USBSTK5505_I2S_writeRight(sinetable[sample]);
}
}
}
#if 0
USBSTK5505_I2S_close(); // Disable I2S
AIC3204_rset( 1, 1 ); // Reset codec
USBSTK5505_GPIO_setOutput( GPIO26, 0 ); // Disable AIC3204
#endif
}
这个是正弦波数据和C550eZdsp和AIC3204的播放正弦波的代码。为什么在此代码中可以不用设置延迟来播放数据?还有在 for ( sample = 0 ; sample < len ; sample++ )这个第三层的嵌套循环下,如何确保每执行一次是1ms?