| Kinetis SDK Demo Applications User Guide 1.0.0-beta Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- Demos

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAI Play Sound User Guide
SAI Play Sound

User guide on how to use this demo. More...

### SAI Play Sound User Guide

# Getting started

## 1. Hardware settings

SAI_PlaySound program needs this hardware:

- TWR-K64F120M
- TWR-ELEV
- TWR-SGTL

## 2. Download program

- Download the program to the target board.
- Connect a USB cable to the PC host and open a serial terminal at 115200 baud, 8-bits no parity, 1 stop bit.
- When successfully connected, the program sends the welcome information to the terminal. Communication Interface Settings:
  - TWR-K64F120M(OpenSDA) UART1 TX: PC3 RX: PC4.

## 3. Run the program

If a serial terminal echo inputs normally, use headphones connected to the TWR-SGTL's HEADSET socket and type "play" on the terminal. It plays a short audio clip.

# Select different format of wave file

To change the format of a wave data source, change the include file located in main.c.
// Windows PCM wave data singed 16 bit, sample rate:44.1KHZ, stereo
#include "PCM_S16B_44100_2C.h"

All available wave files are:

- PCM_S16B_11025_2C.h
- PCM_S16B_44100_1C.h
- PCM_S16B_44100_2C.h
- PCM_S32B_44100_2C.h

Note
  1. SGTL5000 cannot support 8-bit waveform data.
  2. Wave data source header files are generated by any "BIN to C" tools. They are available on the Internet.

# Add your own audio clip

## 1. Convert your audio file into the Windows PCM wave file format.

Note
  The wave file should be less than 500 KB provided the internal flash is used as memory media.

## 2. Write call back function "AppGetData"

### (1) Function "PLAYSOUND_Play"

Function "PLAYSOUND_Play" transfers wave data into the codec. The entire wave data does not have to be loaded into memory.
Function prototype:
status_t PLAYSOUND_Play(APP_GET_DATA_FUNC fpAppGetData);

### (2) Prototype of "GetData" function

uint32_t AppGetDataCallBack(uint32_t NumBytesReq, uint8_t **ppData, uint32_t offest)

### (3) Description of "GetData" function

The function returns the number of requested bytes. The maximum number of bytes is NumBytesReq.

### (4) Example

The following code excerpt shows how to use the function:
uint32_t AppGetDataCallBack(uint32_t NumBytesReq, uint8_t **ppData, uint32_t offest)
{
uint32_t NumBytesRead = 0;
// Check if NumBytesReq is allowed for your data buffer size.
... /* TBD */
// set the data pointer to your memory devices buffer.
... /* TBD */
// return how many bytes we can get, return value should equal or less then NumBytesReq.
... /* TBD */
}

> Note: sgtl5000 only supports 16bit, 20bit, 24bit and 32bit. Note: 20bit and 24 bit need to do some special operations in application, current application now do not support this. Note: Sgtl5000 only supports 8k, 11.025k, 12k, 16k, 22.05k, 24k, 32k, 44.1k, 48k and 96k sample rate.