PicoVGA  1.0-cmake
VGA/TV display on Raspberry Pico
PWM Audio

Description

The PicoVGA library includes support for audio output using PWM modulation. By default, the audio output is done on the GPIO19 port - defined in the pwmsnd.h file. The port can be connected to directly (e.g. headphones) or better via a simple RC filter with low pass. Audio output using PWM modulation has the advantage that 1 output pin is sufficient and the output circuitry is very simple. The disadvantages are the noise of the sound modulation frequency and the low bit depth of the sound (8 bit depth is used). Higher depth is not possible because of the limited processor frequency. This output is sufficient for most common, undemanding applications (such as retro games). For higher sound quality, another method must be used.

Functions

void PWMSndInit ()
 Initialize PWM sound output. More...
 
void PlaySound (const u8 *snd, int len, Bool rep=False, float speed=1.0f)
 Output PWM sound. More...
 
void StopSound ()
 stop playing sound More...
 
void SpeedSound (float speed)
 Update sound speed. More...
 
Bool PlayingSound ()
 Check if playing sound.
 
void SetNextSound (const u8 *snd, int len)
 Set the next sound to play. More...
 

Function Documentation

◆ PWMSndInit()

void PWMSndInit ( )

Initialize PWM sound output.

Note
If the system clock changes, you must reinitialize the audio output settings by calling this function again.

◆ PlaySound()

void PlaySound ( const u8 *  snd,
int  len,
Bool  rep = False,
float  speed = 1.0f 
)

Output PWM sound.

The audio must be in uncompressed PCM format, mono, 8 bits, frequency 22050 Hz. The parameters can be used to specify whether the sound will be repeated and the relative speed at which it will be played (the 'speed' parameter can be used to speed up or slow down the sound).

Parameters
sndPointer to sound
lenLength of sound in number of samples
repTrue to repeat sample
speedRelative speed (1=normal)

◆ StopSound()

void StopSound ( )

stop playing sound

The output to the output pin will continue to be output (it will appear as a low noise), but the value of zero 128 will be used.

◆ SpeedSound()

void SpeedSound ( float  speed)

Update sound speed.

Used when repeatedly playing a sound to change the pitch (e.g. the sound of a car engine).

Parameters
speedRelative speed (1.0 represents the standard playback speed)

◆ SetNextSound()

void SetNextSound ( const u8 *  snd,
int  len 
)

Set the next sound to play.

Used for repeated sounds to finish playing the current sound and continue with the next sound.

Parameters
sndPointer to sound
lenLength of sound in number of samples