17-152
Audio Tools
Programmer’s Manual
Example 16-1 PPSM tone playing
/* 100Hz, 1000Hz, 500Hz and 600Hz */
U16 toneData[] = {100, 1000, 500, 600};
/* Play a melody with 4 different tone frequencies, each with 250ms duration */
#ifdef EZ328
AudioPlayTone((P_U16)toneData, 4, TONE_DUR_4HZ, 1);
#else
AudioPlayTone((P_U16)toneData, 4, 250, 1);
#endif
To stop the tone playing, a user can call AudioStopTone(). To check if the Audio
Tools are currently being used, a user can call AudioInUse().
Note: This is impossible to play a tone with value of frequency less than the value
of duration, since the duration of this frequency is longer than the allowed
duration.
17.3
Wave playing (DragonBall-EZ only)
PPSM audio tools can play back a PCM(Pulse Code Modulation) audio wave file
that can be generated by many audio programs. Wave playing can be done by
two PPSM audio tools - AdvAudioPlayWave() and AudioPlayWave().
AdvAudioPlayWave() is provided for users with solid knowledge of PWM who
want to have advanced configuration details over the DragonBall-EZ PWM
module. For most cases, AudioPlayWave should be used.
STATUS
AudioPlayWave
(P_U8 waveData, U32 waveSize, U8 samplingRate)
Example 16-2 PPSM wave playing
/* Some PWM wave data */
U16 waveData[] = {...};
autoRepeat
To indicate if auto-repeat is needed or not
0 - no autorepeat.
1 - autorepeat.
Name
Description
waveData
The pointer to the PCM audio wave signal
waveSize
Total number of data bytes occupied by
the audio signal
samplingRate
The requested sampling rate
SAMPLING_32KHZ
SAMPLING_16KHZ
SAMPLING_11KHZ
SAMPLING_8KHZ
SAMPLING_4KHZ
Name
Description
Personal Portable System Manager
Programmer’s Manual
Audio Tools
17-153
/* Play a melody with 1000 data bytes at 16kHz sampling/reconstruction rate */
AudioPlayWave((P_U8)waveData, 1000, SAMPLING_16KHZ);
STATUS
AdvAudioPlayWave
(P_U8 waveData, U32 waveSize, U8 prescaler, U8
repeat, U8 clksel)
The sampling rate can be calculated by the above input parameters.
SamplingRate
16.58
MHz
(
)
(
=
For more detail information, please refer to the DragonBall-EZ
Example 16-3 PPSM wave playing
/* Play a melody with 1000 data bytes at 16kHz sampling/reconstruction rate */
/* 16kHz = 16.58Mz/(2 x 1 x 2 x 256) */
AdvAudioPlayWave((P_U8)waveData, 1000, 0, 2, 0);
The device driver function _PWMIrptHandler() under IrptDev.c should return
TRUE for proper wave playing with PPSM audio tools. If the user is going to use
his/her own PWM interrupt function and wants to disable PPSM audio wave
playing tools, the _PWMIrptHandler() should return FALSE instead.
An audio stops after it has finished or the user has called AudioStopTone() or
AudioStopWave(). After audio playing stops, an interrupt is sent to the task that
called AudioPlayTone() or AudioPlayWave() to indicate that the audio playing is
finished.
Example 16-4 Stopping an audio play
/* Some PWM wave data */
U16 waveData[] = {...};
/* Play a melody with 1000 data bytes at 16kHz sampling/reconstruction rate */
AudioPlayWave((P_U8)waveData, 1000, SAMPLING_16KHZ);
switch( IrptGetData((P_U32)&id, (P_U32*) &inData, (P_U32) &size) )
{
case IRPT_AUDIO:
Name
Description
waveData
waveSize
prescaler
(see DragonBall-EZ user’s
manual)
repeat(see DragonBall-EZ user’s
manual)
clksel(see DragonBall-EZ user’s
manual)
)
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.