![]() |
Kinetis SDK v.1.2 Demo Applications User's Guide
Rev. 0
Freescale Semiconductor, Inc.
|
This demo application demonstrates how to use the SAI drivers.
The SAI Demo project is a digital audio demonstration program that uses the KSDK software. It performs audio playback from either a .wav file, stored in Flash, or from the line-in on a TWR-AUDIO-SGTL Tower System module using the KSDK I2S and I2C drivers. On the TWR-K22F120M, TWR-K24F120M, and the TWR-K64F120M Tower System modules, the project also uses the CMSIS-DSP library to perform a Fast Fourier Transform, and return the fundamental frequency of the line-in audio.
This demo supports the following Freescale Freedom development platforms and Tower System modules:
When building the demo with GCC, ensure that the demo and platform library are built with this option:
<code> <br>CHOOSE_FLOAT=HARD_FP<br> </code>
Otherwise, the project does not use the Kinetis device's hardware floating point when using the CMSIS-DSP library.
These Tower System modules are required to run the sai_demo:
For detailed instructions, see a Kinetis SDK User's Guide for your board.
To hear the audio playback, connect a set of headphones to the headphone output on the TWR-AUDIO-SGTL card. For input to the codec, connect an audio source to the Line-In on the TWR-AUDIO-SGTL.
When the demo starts, this message is displayed in the terminal output window:
Audio Demo!
Press spacebar to start demo.
Demo begin...
The user can either play back audio from the line-in source, or play a .wav file stored in the Flash.
The line-in option plays the audio gathered from the codec line-in for approximately 15 seconds.
Select player: 1. Line-In Playback 2. Wav File Playback ->1
If selecting playback from the line-in source, decide whether to perform an FFT analysis to find the fundamental frequency of the audio input. Finding the fundamental frequency is best suited for pure tones played into the line-in of the TWR-AUDIO-SGTL card.
Select filter: 1. FFT - Find Fundamental Frequency 2. None ->1
The user is prompted to select from a list of headphone output levels:
Choose headphone dB level: 1. +3.0 dB 2. 0.0 dB 3. -3.0 dB 4. -6.0 dB 5. -12.0 dB 6. -24.0 dB 7. -48.0 dB ->5 Frequency is 93 Hz
The table shows the terminal display after playback has completed and the FFT option was selected.
These are the options for the .wav file option:
Select player: 1. Line-In Playback 2. Wav File Playback ->2 Select Wav file: 1. Audio Demo ->1 Choose headphone dB level: 1. +3.0 dB 2. 0.0 dB 3. -3.0 dB 4. -6.0 dB 5. -12.0 dB 6. -24.0 dB 7. -48.0 dB ->5
The quality of the .wav file PCM data depends on the demo system and the compiler.
This table shows the audio sample rate, channels and bit depth of the .wav file for the various platforms and compilers.
Hardware System | Sample Rate (kHz) | Bit Depth | Channels | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
IAR | ARM | GNU-GCC | KDS-GCC | IAR | ARM | GNU-GCC | KDS-GCC | IAR | ARM | GNU-GCC | KDS-GCC | |
TWR-K22F120M | 44.1 | 44.1 | 11.025 | 11.025 | 16 | 16 | 16 | 16 | 2 | 2 | 2 | 2 |
TWR-K24F120M | 44.1 | 44.1 | 44.1 | 44.1 | 32 | 32 | 32 | 32 | 2 | 2 | 2 | 2 |
TWR-K60F100M | 44.1 | 44.1 | 44.1 | 44.1 | 32 | 32 | 32 | 32 | 2 | 2 | 2 | 2 |
TWR-K64F120M | 44.1 | 44.1 | 44.1 | 44.1 | 32 | 32 | 32 | 32 | 2 | 2 | 2 | 2 |
TWR-K65F180M | 44.1 | 44.1 | 44.1 | 44.1 | 32 | 32 | 32 | 32 | 2 | 2 | 2 | 2 |
TWR-K21F120M | 44.1 | 44.1 | 11.025 | 11.025 | 16 | 16 | 16 | 16 | 2 | 2 | 2 | 2 |
Quality differences of the .wav playback depend on the size constraints of the target device, the Flash size, and the density of the code generated by the compiler.
Note that all supported platforms play audio from the line-in option with the same quality: 16-bit, 44.1 kHz, 2 channels.
Initializes the I2S, I2C, and TWR-AUDIO-SGTL Tower System module for streaming audio from Line-In.
Initializes the I2S, I2C, and TWR-AUDIO-SGTL Tower System module for playing back WAV file in Flash.
newWav | Pointer to wave file data structure. |
Sets volume from the user input.
handler | pointer to codec handler structure. |
module | name of module on codec to set the volume for. |
volumeCtrl | user input data from terminal menu. |
Plays a stream of audio.
dspType | Used to select one DSP function to perform on the data. |
volumeCtrl | Value used to set decibel level on codec. |
Collects data from WAV file header.
waveFile | Data structure of pcm data array. |
Plays the PCM audio data from the WAV format array.
pcmBuffer | Pointer to data array containing WAV formatted audio data. |
volumeCtrl | Value used to set decibel level on codec. |
Sends audio data to the sound card.
pdataBuffer | Pointer to data array containing WAV formatted audio data. |
length | length of WAV file to send. |
dataFormat | Point to audio_data_format_t for sound card. |
Performs frequency analysis and finds fundamental frequency of the PCM data.
dataFormat | Pointer to audio data format structure. |
buffer | Pointer to data array to store modulated PCM data. |
fftData | Pointer to data array for storing Fast Fourier Transform data. |
fftResult | Point to data array for storing real frequency bins from FFT. |