reztronics

Home - Products - News - Services - Music - About Us

 

 


The PCM Codec

Steps:

1.) Include files and configuration.

2.) UserTask and Initialization

3.) Reading and Writing using the PCM Codec

4.)Closing the Codec

Include files and configuration

 

The files 'dsk5416.h' and 'dsk5416_pcm3002.h' need to be included in your code.

The first one contains all the initialization information for the DSK board.  The second contains the information about the PCM Codec.

Int16 *input is a pointer used for reading input from the codec.  Int16 specifies a 16-bit integer.

setup is an instance of the structure type DSK5416_PCM3002_Config which sets configuration values for four parameters used in the codec.
I find it easiest to put in the default values.  

UserTask and Initialization

 

hCodec is an instance of the type DSK5416_PCM3002_CodecHandle.  This is the handle we use to communicate with the Codec.

hCodec = DSK5416_PCM3002_openCodec(0, &setup);
DSK5416_PCM3002_setFreq(hCodec, 8000);

Here we set the Codec Handle equal to the ouput of the openCodec function.  Notice that it uses the structure setup that we previously defined.

In the second line we set the sampling frequency of the Codec to 8000.

Reading and Writing using the PCM Codec

 

while(TRUE)


while (!DSK5416_PCM3002_read16(hCodec, input);
while (!DSK5416_PCM3002_write16(hCodec, output);

Here is an infinite loop the reads input from the input buffer and then writes it to the output buffer.

Closing the Codec

DSK5416_PCM3002_closeCodec(hCodec);

This simple command closes the PCM Codec using its handle.

 

The main function's only purpose is to call DSK5416_init() which is the initialization for the DSK board.

The UserTask function performs all the functionality of this program.

Below is the source code.  Enjoy.

 

/**************   Complete Source Code  *****************/

#include "dsk5416.h"
#include "dsk5416_pcm3002.h"
Int16 *input;

DSK5416_PCM3002_Config setup = {

0x100, // Set-Up Reg 0 - Left channel DAC attenuation
0x1ff, // Set-Up Reg 1 - Right channel DAC attenuation
0x0, // Set-Up Reg 2 - Various ctl e.g. power-down modes
0x0 // Set-Up Reg 3 - Codec data format control
};

/*
* UserTask() - The main user task
*/

void UserTask()
{

DSK5416_PCM3002_CodecHandle hCodec;
int i, j;

Int16 output; 

// Start the codec

hCodec = DSK5416_PCM3002_openCodec(0, &setup);
DSK5416_PCM3002_setFreq(hCodec, 8000);

while(TRUE)


while (!DSK5416_PCM3002_read16(hCodec, input);
while (!DSK5416_PCM3002_write16(hCodec, output);




// Close the codec

DSK5416_PCM3002_closeCodec(hCodec);
}

void main()
{
// Initialize the board support library

DSK5416_init();
}

Products

Home

Send mail to rghassemi@gmail.com with questions or comments about this web site.
Copyright © 2005 Reztronics
Last modified: August 30, 2005