OSK5912 Tone Example
The tone example is a slightly more complicated program that directs the AIC23 & McBSP to generate a 1 KHz sine wave through the headphone jack.
Perform the following steps to run the tone example:
Plug in headphone/speaker
Plug a pair of headphones or speakers into the OSK5912’s headphone jack( P5 )
Load Project
Open the tone.pjt Code Composer project using Project -> Open and selecting tone.pjt. It is in the directory:
c:\ti\boards\osk5912\examples\tone
 Click Image to Enlarge
Load Program
Load the tone.out executable file. Select File -> Load Program. It will open a file browser dialog. Select the tone.out file in the tone\Debug directory in the file browser and hit "Open" to load the executable file.
Run Program
Select the Debug -> Run option under the Debug menu. You will hear a 1KHz tone.
After 5 seconds the sound will stop.
When you are satisfied that the program is indeed running correctly, stop the program by selecting Debug -> Halt.
The array sinetable[ ] contains a pre-generated sine wave using signed 16-bit data that matches the AIC23. The data covers exactly one period and the amplitude matches the full range of the codec.
Int16 sine_wave_table_size = 48;
/* Pre-generated sine wave data, 16-bit signed samples */
Unt16 sinetable[ ] = {
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
};
The main loop of the code writes each data point in the sine wave table out to the codec using the AIC23 codec package of the BSL. Each write function sends a single 16 bit sample to the codec. In this case the same data is sent out twice, once to the left channel and once to the right channel. The codec is configured to accept data at a rate of 48,000 stereo samples per second. Since the sine table is 48 entries long, the resulting output wave will be a 1 KHz sine wave with the same output on both the left and right channels.
/* Generate a 1 KHz sine wave for 5 seconds */
for ( msec = 0 ; msec < 5000 ; msec++ )
{
for ( sample = 0; sample < sine_wave_table_size; sample++ )
{
/* Send a sample tp the left channel */
while ( ! OSK5912_AIC23_write16(hCodec, sinetable[sample]) );
/* Send a sample tp the right channel */
while ( ! OSK5912_AIC23_write16(hCodec, sinetable[sample]) );
}
}
The McBSP is used to transmit data to the codec at a much slower rate than the DSP can process data. It accepts data 32 bits at a time and shifts them out slowly one at a time. The write function returns a 1 if the write is completed successfully or a 0 if the serial channel is busy. The while( ) loop around the writes waits while the serial port is busy so program can be synchronized to the data rate of the codec.
The 32 bit data consists of two 16-bit samples, each corresponding to one of the two audio channels. The left data sits in the top half of the 32-bit word while the right data sits in the bottom half . Each sample is a signed 16-bit value.
The following two commands are used to initialize and shut down the codec and are found at the beginning and end of all programs that use BSL codec module. The OSK5912_openCodec( ) command returns a handle that is passed each of the other codec functions.
/* Start the codec */
hCodec = OSK5912_AIC23_openCodec( 0, &config );
/* Close the codec */
OSK5912_AIC23_closeCodec( hCodec );
|