Synthesizes PCM from SpeakerNote sequences.
More...
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.
◆ 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. |
◆ 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_note | MIDI 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_note | MIDI note number. |
| sample_rate | Output 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()
Clean up note sequence state.
- Parameters
-
◆ 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
-
| s | Note sequence state. |
| [out] | out | Output buffer for signed 16-bit PCM samples. |
| max_samples | Maximum number of samples to generate. |
- Returns
- Number of samples written, 0 once the sequence is done.
◆ note_seq_init()
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] | s | State to initialize. |
| notes | Notes to play. Must stay valid until playback ends. |
| count | Number of entries in notes. |
| sample_rate | Output 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
-
| waveform | SpeakerWaveform value; unknown values produce silence. |
| phase_acc | 16.16 fixed-point phase accumulator. |
| phase_inc | Per-sample increment of phase_acc. |
| velocity | Amplitude scale, 1 to 127; 0 means no per-sample scaling (master volume is applied downstream). |
- Returns
- Signed 16-bit sample.