| 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 Modulator User Guide
SAI Modulator

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

### SAI MODULATOR User Guide

Play PCM audio data from the WAV format array.

# Getting started

## 1. Hardware settings

SAI_Modulator program requires the following 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 "Press spacebar to start demo" to the terminal. Then press space key to continue. Communication Interface Settings:

  - TWR-K64F120M(OpenSDA) UART1 TX: PC3 RX: PC4.

    ## 3. Run the program

  If a serial terminal echo inputs normally,

      Audio Modulator Demo!

      Press spacebar to start demo.

Use headphones connected to the TWR-SGTL's HEADSET socket and press the spacebar in the terminal window.

    Demo begin...

It plays a C major arpeggio and prints out a menu in the terminal window.

    Select note to play:
        1. C4
        2. D4
        3. E4
        4. F4
        5. G4
        6. A4
        7. B4
        8. C5
    ->

Enter the number that corresponds to the note you wish to hear and a duration menu appears.

    Select note duration:
        1. 200ms
        2. 100ms
        3. 50ms
    ->

Default duration of the notes in FLASH is 200 ms; Select the number that corresponds with the duration of the note you want. Then, a modulation type menu is printed in the terminal window.

    Select note modulation:
        1. none
        2. Square
        3. Saw
        4. Triangle
    ->

Select the type of waveform you wish to modulate the pure tone to. If a non-pure tone is selected, the processing message appears.

    Processing...

Followed by the completed message.

    Completed!

At this point, you hear the note with the desired characteristics played through the headphone jack of the TWR-AUDIO-SGTL board.

# Key Functions

## 1. play_wav

audio_status_t play_wav(uint32_t *pcmBuffer, uint8_t divider);

Parameters

  pcmBuffer | Pointer to a data array containing WAV formatted audio data.
  divider | Integer to divide PCM data length to adjust the audio sample duration.

Returns
  status_t Return kStatus_Success if function completed successfully; return kStatusFail if function failed.

## 2. play_mod_wav

audio_status_t play_mod_wav(uint16_t *pcmBuffer, uint16_t *modPointer, float32_t *fftData, float32_t *fftResult, uint8_t divider, uint8_t modulation, uint32_t srcSizeBytes, uint32_t sampleSize);Play modulated PCM audio data from a WAV format array.

Parameters

  pcmBuffer | Pointer to a data array containing the WAV formatted audio data.
  modBuffer | Pointer to a data array to store the modulated PCM data.
  fftData | Pointer to a data array for storing the Fast Fourier Transform data.
  fftResult | Point to a data array for storing real frequency bins from FFT.
  divider | Integer to divide PCM data length to adjust an audio sample duration.
  modulation | Constant representing type of waveform achieve from modulation.
  srcSizeBytes | Size of the WAV format array being processed.
  sampleSize | Size of a sample for FFT (each sample is 16-bit integer from the PCM data).

Returns
  status_t Return kStatus_Success if function completed successfully; return kStatusFail if function failed.

## 3. mod_wav_data

float32_t mod_wav_data(uint16_t *pcmBuffer, uint16_t *modBuffer, float32_t *fftData, float32_t *fftResult, uint16_t startIndex, uint32_t sampleSize, uint8_t modType);Find fundamental frequency of the PCM data in a WAV format array.

Parameters

  pcmBuffer | Pointer to a data array containing the WAV formatted audio data.
  modBuffer | Pointer to a data array to store the modulated PCM data.
  fftData | Pointer to a data array for storing the Fast Fourier Transform data.
  fftResult | Point to a data array for storing real frequency bins from FFT.
  startIndex | Starting index of array to get the PCM data.
  sampleSize | Size of a sample for FFT (each sample is 16-bit integer from PCM data).
  modType | Constant representing type of waveform achieve from modulation.

Returns
  float32_t Returns fundamental frequency in Hz.