![]() |
PicoVGA
1.0-cmake
VGA/TV display on Raspberry Pico
|
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... | |
void PWMSndInit | ( | ) |
Initialize PWM sound output.
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).
snd | Pointer to sound |
len | Length of sound in number of samples |
rep | True to repeat sample |
speed | Relative speed (1=normal) |
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.
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).
speed | Relative speed (1.0 represents the standard playback speed) |
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.
snd | Pointer to sound |
len | Length of sound in number of samples |