PebbleOS
Loading...
Searching...
No Matches
Data Structures | Functions
Note synthesis

Synthesizes PCM from SpeakerNote sequences. More...

Data Structures

struct  NoteSequenceState
 Playback state of a note sequence. More...
 

Functions

void note_seq_init (NoteSequenceState *s, const SpeakerNote *notes, uint32_t count, uint32_t sample_rate)
 Initialize a note sequence player.
 
uint32_t note_seq_fill (NoteSequenceState *s, int16_t *out, uint32_t max_samples)
 Fill an output buffer with synthesized PCM samples.
 
void note_seq_deinit (NoteSequenceState *s)
 Clean up note sequence state.
 
uint32_t note_phase_inc (uint8_t midi_note, uint32_t sample_rate)
 Compute the per-sample phase increment of a MIDI note.
 
int16_t note_synth_sample (uint8_t waveform, uint32_t phase_acc, uint32_t phase_inc, uint8_t velocity)
 Synthesize one PCM sample of a waveform.
 
uint32_t note_midi_freq_x256 (uint8_t midi_note)
 Get the frequency of a MIDI note.
 

Detailed Description

Synthesizes PCM from SpeakerNote sequences.

Also provides the waveform primitives the track player uses for its voices. These are kernel internals, not part of the app SDK.


Data Structure Documentation

◆ NoteSequenceState

struct NoteSequenceState

Playback state of a note sequence.

Data Fields
bool active Whether notes remain to be played.
uint32_t current_note Index of the note being played.
uint8_t current_velocity Velocity of the current note.
uint8_t current_waveform Waveform of the current note, a SpeakerWaveform.
const SpeakerNote * notes Notes being played, not owned.
uint32_t num_notes Number of entries in notes.
uint32_t phase_acc 16.16 fixed-point phase accumulator.
uint32_t phase_inc Per-sample phase increment, 0 for a rest.
uint32_t samples_remaining Samples left in the current note.

Function Documentation

◆ note_midi_freq_x256()

uint32_t note_midi_freq_x256 ( uint8_t  midi_note)

Get the frequency of a MIDI note.

Used by the track player to compute sample playback pitch ratios.

Parameters
midi_noteMIDI note number.
Returns
Frequency in 16.8 fixed-point Hz (i.e. Hz * 256), 0 if out of range.

◆ note_phase_inc()

uint32_t note_phase_inc ( uint8_t  midi_note,
uint32_t  sample_rate 
)

Compute the per-sample phase increment of a MIDI note.

Parameters
midi_noteMIDI note number.
sample_rateOutput sample rate in Hz.
Returns
16.16 fixed-point phase increment per output sample, 0 for a rest (note 0) or out-of-range values.

◆ note_seq_deinit()

void note_seq_deinit ( NoteSequenceState *  s)

Clean up note sequence state.

Parameters
sState to clear.

◆ note_seq_fill()

uint32_t note_seq_fill ( NoteSequenceState *  s,
int16_t *  out,
uint32_t  max_samples 
)

Fill an output buffer with synthesized PCM samples.

Parameters
sNote sequence state.
[out]outOutput buffer for signed 16-bit PCM samples.
max_samplesMaximum number of samples to generate.
Returns
Number of samples written, 0 once the sequence is done.

◆ note_seq_init()

void note_seq_init ( NoteSequenceState *  s,
const SpeakerNote *  notes,
uint32_t  count,
uint32_t  sample_rate 
)

Initialize a note sequence player.

The sample rate is kept in a single global, so all sequences played at once must share it.

Parameters
[out]sState to initialize.
notesNotes to play. Must stay valid until playback ends.
countNumber of entries in notes.
sample_rateOutput sample rate in Hz (e.g. 16000).

◆ note_synth_sample()

int16_t note_synth_sample ( uint8_t  waveform,
uint32_t  phase_acc,
uint32_t  phase_inc,
uint8_t  velocity 
)

Synthesize one PCM sample of a waveform.

Waveforms are normalized to roughly equal loudness. The square wave applies PolyBLEP anti-aliasing at its discontinuities, using phase_inc.

Parameters
waveformSpeakerWaveform value; unknown values produce silence.
phase_acc16.16 fixed-point phase accumulator.
phase_incPer-sample increment of phase_acc.
velocityAmplitude scale, 1 to 127; 0 means no per-sample scaling (master volume is applied downstream).
Returns
Signed 16-bit sample.