Recommended for most users. Handles Core0→Core1 communication automatically.
void PlayTone(int frequency, int duration, uint8_t volume = 80);Play a simple tone.
Parameters:
frequency- Frequency in Hzduration- Duration in millisecondsvolume- Volume 0-100 (default: 80)
Example:
PlayTone(440, 200); // Play A4 for 200msvoid PlayMelody(const Note* notes, uint8_t numNotes,
WaveType wave = WAVE_SQUARE, uint8_t volume = 80);Play a sequence of notes.
Parameters:
notes- Array of Note structuresnumNotes- Number of notes in arraywave- Waveform type (default: WAVE_SQUARE)volume- Volume 0-100 (default: 80)
Example:
const Note melody[] = {{440, 200}, {523, 200}};
PlayMelody(melody, 2, WAVE_SINE, 70);void SendAudioCommand(AudioCommandType cmdType, uint8_t soundID = 0,
uint8_t volume = 80, ...);Send command to Core1 audio engine.
Common commands:
CMD_PLAY_SOUND- Play sound from tableCMD_STOP_ALL- Stop all channelsCMD_SET_MASTER_VOLUME- Change master volume
Example:
SendAudioCommand(CMD_PLAY_SOUND, SND_EXPLOSION, 90);void StopAllSounds();Stop all active audio channels.
void SetMasterVolume(uint8_t volume);Set master volume (0-100).
void PicoSound_AudioCore_Setup1();Initialize audio engine on Core1. Call once in setup1().
void PicoSound_AudioCore_Loop1();Audio mixer loop. Call continuously in loop1().
Advanced users only. Direct access to audio engine.
bool playSound(uint8_t soundID, uint8_t volume);Play sound from PICOSOUND_TABLE.
bool playCustomTone(float frequency, uint16_t duration,
WaveType waveType, uint16_t amplitude, uint8_t volume);Generate tone with custom parameters.
bool playMelody(const Note* notes, uint8_t numNotes,
WaveType waveType, uint8_t volume);Play note sequence.
void stopAll();Stop all channels.
void setMasterVolume(uint8_t volume);Set master volume.
typedef struct {
uint16_t frequency; // Hz (0 = rest)
uint16_t duration; // milliseconds
} Note;typedef enum {
WAVE_NONE,
WAVE_SINE,
WAVE_SQUARE,
WAVE_SAWTOOTH,
WAVE_TRIANGLE,
WAVE_NOISE,
WAVE_WAV,
WAVE_EXPLOSION
} WaveType;typedef enum {
CMD_NONE,
CMD_PLAY_SOUND,
CMD_PLAY_CUSTOM,
CMD_PLAY_SWEEP,
CMD_PLAY_MELODY_CUSTOM,
CMD_STOP_ALL,
CMD_SET_MASTER_VOLUME
} AudioCommandType;Sounds are defined in picosound_user_cfg.h:
inline const SoundDefinition PICOSOUND_TABLE[] = {
// Synthesized tone
{WAVE_SQUARE, 440, 0, 200, 12000, 80,
nullptr, 0, false, nullptr, false},
// WAV from LittleFS
{WAVE_WAV, 0, 0, 0, 0, 70,
nullptr, 0, true, "/sound.wav", true},
// WAV from PROGMEM
{WAVE_WAV, 0, 0, 0, 0, 80,
sample_data, sample_length, false, nullptr, false},
};Parameters:
- Waveform type
- Start frequency (Hz, 0 for WAV)
- End frequency (Hz, for sweeps)
- Duration (ms, 0 for WAV)
- Amplitude (max absolute value for a synthesized waveform: 32767)
- Default volume (0-100 percentage)
- WAV data pointer (or nullptr for synthesized waveforms)
- WAV data length (or 0 for synthesized waveforms)
- Loop flag for WAV and melody sounds
- Filesystem path (or nullptr)
- Use filesystem flag