460 likes | 658 Views
“Improved Audio Template”. Texas Instruments University Programme Teaching Materials. Improved Audio Template. Introduction. The code in MyFirstProject had: Fixed sampling rate of 48000 samples per second Suitable for line inputs (CD, iPod) only
E N D
“Improved Audio Template” Texas Instruments University Programme Teaching Materials
Introduction • The code in MyFirstProject had: • Fixed sampling rate of 48000 samples per second • Suitable for line inputs (CD, iPod) only • Not suitable for microphones and electric guitars.
Objectives • To design an Improved Audio Template with: • Sampling rate adjustable between 8000 samples per second and 48000 samples per second • Adjustable gain suitable for: • line inputs (CD player, MP3 etc). • microphones • electric guitars.
What you will Learn • How to read TI datasheets and use the values to configure registers. • How to change the sampling rate and audio gain of the coder-decoder (CODEC) • How to use decibels.
USB Stick Codec Codec 12 MHz Crystal
Setting up the Codec • The TMS320C5505 USB Stick uses a TLV320AIC3204 Codec (coder-decoder). • The information required to configure this device is contained in TI datasheet SLOS602A.
Codec Adjustments • The following can be adjusted on the codec: • Sampling rate • Input ADC gain • Output DAC gain.
Phase Locked Loop (PLL) Setup • Table 5-25 PLL gives example configurations. • This is the really useful part of the document!
Registers • All the fields PLLP, PLLR etc refer to specific registers inside the Codec. • This phase lock loop (PLL) has: • a fixed oscillator on the outside (12 MHz) • lower speed operation on the inside (e.g. 48 kHz).
Clock Distribution Tree • The clock signals form a tree.
PLL Loop Clock Setups • The Phase Locked Loop frequency is calculated as follows:
Master Clock (MCLK) • The TMS320C5505 USB Stick uses a 32768 Hz crystal for the Master Clock (MCLK). • The setup for 100 MHz is given in red.
Setting the ADC Gain • Microphones and guitars have low electrical output. • Additional gain is required for these devices.
Setting the ADC Gain • The ADC gain is controlled by Register 59 and Register 60:
Range of Gain Values • The TLV320AIC3204 supports gains between 0 dB and 47.5 dB. • In practical terms, intervals of 1 dB are perfectly adequate. • This also solves the problem of expressing 0.5 dB using fixed-point maths.
Gain in Decibels • The gain is expressed in terms of decibels (dB). • A decibel is a ratio.
Useful Decibels • The following are decibel values and their ratio equivalents: • 0 dB => 1:1 • 6 dB => 2:1 • 20 dB => 10:1 • 40 dB => 100:1 • 60 dB => 1000:1
New Function • The following C code function has been added to AIC3204_init.c set_sampling_frequency_and_gain(); • This function takes two parameters: • unsigned long SamplingFrequency; // Sampling frequency Hz • unsigned int ADCgain; // Gain in dB
Sampling Frequencies • The sampling frequency can be any of the following: 48000 24000 16000 12000 9600 8000 6857 • The default is 48000 Hz.
ADC Gain • The ADCgain takes a value between 0 and 48. • 0 => 0 dB e.g. line input • 30 => 30 dB e.g. microphone input • 48 => 48 dB e.g. low output microphone input.
Electret Microphone • The TMS320C5505 USB Stick supports electret microphones. • It is necessary to turn on the MICBIAS power supply • Add the following line to aic3204_init.c: AIC3204_rset(51, 0x40); // Enable MICBIAS
Configuration Example • To configure the codec with: • Sampling frequency 48000 Hz • Gain 0dB • Use following #defines in main.c: #define SAMPLES_PER_SECOND 48000 #define GAIN_IN_dB 0
New Timed Steps • The TMS320C5505 has no switches, so Step changes once every 20 seconds and flashes the XF LED.
Installing the Application • Use the code given in Application 2 Improved Audio Template • Follow the steps previously given in Chapter 1 to set up the new project.
Line Setup TMS320C5505 USB Stick USB to PC CD Player or MP3 Player Headphones
Console for Line Setup • Sampling frequency and Gain are shown in the Console window.
Microphone Setup TMS320C5505 USB to PC Microphone Headphones
Microphone Setup in main.c • Change lines containing SAMPLES_PER_SECOND and GAIN_IN_dB as shown below:
Console for Microphone Setup • New Sampling frequency and Gain are shown in the Console window.
Change Sampling Frequency • Try different values of sampling frequency by changing the number in both main.c and LEDflasher.c: #define SAMPLES_PER_SECOND 24000L
Change Gain • Try different values of gain by changing the number in main.c: #define GAIN_IN_dB 25
Programming Challenge • Add code for Step 4 in main.c
Using TI Datasheets • The datasheet for the TLV320AIC3204 Codec has the TI literature number SLOS62A. • The last letter A is the revision number, which may change. • Therefore, when searching for the latest version of the above document on the TI website, just enter SLOS62.
References • TLV320AIC3204 Stereo Codec Data Sheet SLOS62.