Ki开发板用的是TMS320C5517
这是一段1KHz的正弦波音频信号,播放的时候声音太大,怎么调节音量大小,可不可以不减小幅值在程序里调。Gi有个问题就是C5517有两片AIC3204,可不可以在两个模块同时播放同一段声音
#include"stdio.h"
#include "evm5517.h"
extern
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);#define Xmit 0x20
/*
*
* aic3204_tone_headphone( )
* Output a 1 kHz tone through the STEREO OUT jack
*
*/
Int16 aic3204_tone_headphone( )
{
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 sinetable[48] = {
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
};
Int16 j, i = 0;
Int16 sample;
/* Configure AIC3204 */
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 1, 0x01 ); // Reset codec
AIC3204_rset( 0, 0x01 ); // Point to page 1
AIC3204_rset( 1, 0x08 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 0x00 ); // Enable Analog Blocks
/* PLL and Clocks config and Power Up */
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 27, 0x00 ); // BCLK and WCLK is set as i/p to AIC3204(Slave)
AIC3204_rset( 4, 0x07 ); // PLL setting: PLLCLK <- BCLK and CODEC_CLKIN <-PLL CLK
AIC3204_rset( 6, 0x08 ); // PLL setting: J
AIC3204_rset( 7, 0 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0 ); // PLL setting: LO_BYTE(D)
/* For 48 KHz sampling */
AIC3204_rset( 5, 0x92 ); // PLL setting: Power up PLL, P=1 and R=2
AIC3204_rset( 13, 0x00 ); // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain
AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
EVM5517_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 52, 0x0C ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 55, 0x0C ); // IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 54, 0x03 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 57, 0xC0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 59, 0x00 ); // MIC_PGA_L unmute
AIC3204_rset( 60, 0x00 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 81, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 82, 0x00 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0x00 );
EVM5517_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0015;
I2S0_ICMR = 0x0028; // Enable interrupts
I2S0_CR = 0x8012; // 16-bit word, Master, enable I2S
/* Play Tone */
for
( i = 0 ; i < 5 ; i++ )
{
for
( j = 0 ; j < 1000 ; j++ )
{
for
( sample = 0 ; sample < 48 ; sample++ )
{
I2S0_W0_MSW_W = (sinetable[sample]/5) ; // Send left sample
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = (sinetable[sample]/5) ; // Send right sample
I2S0_W1_LSW_W = 0;
while
((Xmit & I2S0_IR) == 0); // Wait for interrupt
}
}
}
/* Disble I2S */
I2S0_CR = 0x00;
return
0;}
Kailyn Chen:
具体可以参考这篇应用手册有关volume调节寄存器中gain level 设置www.ti.com/.../slaa557.pdf