|
PebbleOS
|
Plays notes, tones, polyphonic tracks and PCM streams on the speaker. More...
Modules | |
| Note synthesis | |
Synthesizes PCM from SpeakerNote sequences. | |
Enumerations | |
| enum | SpeakerPriority { SpeakerPriorityApp = 0 , SpeakerPriorityNotification , SpeakerPriorityCritical } |
| Playback priority; a higher priority preempts a lower one. More... | |
| enum | SpeakerState { SpeakerStateIdle = 0 , SpeakerStatePlaying , SpeakerStateDraining } |
| Playback state. More... | |
| enum | SpeakerSourceType { SpeakerSourceNone = 0 , SpeakerSourceNoteSeq , SpeakerSourceStream , SpeakerSourceTracks , SpeakerSourceTone } |
| Kind of source being played. More... | |
Functions | |
| void | speaker_service_init (void) |
| Initialize the speaker service. | |
| bool | speaker_service_play_note_seq (const SpeakerNote *notes, uint32_t num_notes, SpeakerPriority pri, uint8_t vol) |
| Play a note sequence. | |
| bool | speaker_service_play_tone (uint16_t freq_hz, uint16_t duration_ms, uint8_t waveform, uint8_t velocity, SpeakerPriority pri, uint8_t vol) |
| Play a single tone at an exact frequency. | |
| bool | speaker_service_play_volume_preview (uint8_t vol) |
| Play a short tone at an absolute output volume. | |
| bool | speaker_service_play_tracks (const SpeakerTrack *tracks, uint32_t num_tracks, SpeakerPriority pri, uint8_t vol) |
| Play monophonic tracks in parallel, mixed together. | |
| void | speaker_service_register_finish (PebbleTask task) |
Post a PEBBLE_SPEAKER_EVENT with the finish reason whenever playback ends. | |
| bool | speaker_service_stream_open (SpeakerPriority pri, uint8_t vol, SpeakerPcmFormat fmt) |
| Open a PCM stream for writing. | |
| bool | speaker_service_stream_open_owned (SpeakerPriority pri, uint8_t vol, SpeakerPcmFormat fmt, PebbleTask owner) |
| Open a PCM stream owned by a task. | |
| bool | speaker_service_stream_open_realtime_owned (SpeakerPriority pri, uint8_t vol, SpeakerPcmFormat fmt, PebbleTask owner) |
| Open an owned PCM stream for internal live audio. | |
| uint32_t | speaker_service_stream_write_owned (PebbleTask owner, const void *data, uint32_t num_bytes) |
| Write PCM data to the stream owned by a task. | |
| void | speaker_service_stream_close_owned (PebbleTask owner) |
| Close the stream owned by a task, draining its buffered data. | |
| uint32_t | speaker_service_stream_write (const void *data, uint32_t num_bytes) |
| Write PCM data to the active stream. | |
| void | speaker_service_stream_close (void) |
| Close the active stream. | |
| void | speaker_service_stop (void) |
| Stop any active playback immediately. | |
| void | speaker_service_set_volume (uint8_t vol) |
| Set the playback volume. | |
| void | speaker_service_set_volume_owned (PebbleTask owner, uint8_t vol) |
| Set the playback volume, only if the playback belongs to a task. | |
| SpeakerState | speaker_service_get_state (void) |
| Get the playback state. | |
| void | speaker_service_stop_for_task (PebbleTask task) |
| Stop any playback owned by a task and drop its finish events. | |
| void | speaker_service_set_owner_task (PebbleTask task) |
| Set the task that owns the current playback. | |
| bool | speaker_service_is_muted (void) |
| Check whether the speaker is muted. | |
| void | speaker_service_handle_audio_prefs_changed (void) |
| Notify that the audio preferences (mute or system volume cap) changed. | |
Plays notes, tones, polyphonic tracks and PCM streams on the speaker.
One source plays at a time, mixed to 16 kHz mono and fed to the audio driver from KernelBG. Starting playback preempts the current source when the new priority is higher, or when the current source has finished and only its tail is draining; otherwise the request is rejected. Volumes are 0-100 and are scaled by the user's speaker volume preference; output is silent while the speaker is muted (always, or during Do Not Disturb if so configured). Without CONFIG_SPEAKER every call is a no-op that reports failure.
The note, sample and PCM types are shared with the app SDK.
Streaming PCM:
| enum SpeakerPriority |
| enum SpeakerSourceType |
Kind of source being played.
| Enumerator | |
|---|---|
| SpeakerSourceNone | No source. |
| SpeakerSourceNoteSeq | Note sequence, see speaker_service_play_note_seq(). |
| SpeakerSourceStream | PCM stream, see speaker_service_stream_open(). |
| SpeakerSourceTracks | Polyphonic tracks, see speaker_service_play_tracks(). |
| SpeakerSourceTone | Single tone, see speaker_service_play_tone(). |
| enum SpeakerState |
| SpeakerState speaker_service_get_state | ( | void | ) |
Get the playback state.
| void speaker_service_handle_audio_prefs_changed | ( | void | ) |
Notify that the audio preferences (mute or system volume cap) changed.
The output volume of a playing source is re-applied immediately.
| void speaker_service_init | ( | void | ) |
Initialize the speaker service.
Called once at boot.
| bool speaker_service_is_muted | ( | void | ) |
Check whether the speaker is muted.
| bool speaker_service_play_note_seq | ( | const SpeakerNote * | notes, |
| uint32_t | num_notes, | ||
| SpeakerPriority | pri, | ||
| uint8_t | vol | ||
| ) |
Play a note sequence.
| notes | Notes to play, copied internally. |
| num_notes | Number of entries in notes. |
| pri | Priority. |
| vol | Volume, 0-100. |
| bool speaker_service_play_tone | ( | uint16_t | freq_hz, |
| uint16_t | duration_ms, | ||
| uint8_t | waveform, | ||
| uint8_t | velocity, | ||
| SpeakerPriority | pri, | ||
| uint8_t | vol | ||
| ) |
Play a single tone at an exact frequency.
| freq_hz | Tone frequency in Hz, 0 for silence. |
| duration_ms | Tone duration in milliseconds, must be non-zero. |
| waveform | SpeakerWaveform value. |
| velocity | Amplitude scale 0-127, 0 for full amplitude. |
| pri | Priority. |
| vol | Volume, 0-100. |
| bool speaker_service_play_tracks | ( | const SpeakerTrack * | tracks, |
| uint32_t | num_tracks, | ||
| SpeakerPriority | pri, | ||
| uint8_t | vol | ||
| ) |
Play monophonic tracks in parallel, mixed together.
Track notes, samples and sample data are copied into kernel memory.
| tracks | Tracks to play. |
| num_tracks | Number of tracks, at most SPEAKER_MAX_TRACKS. |
| pri | Priority. |
| vol | Volume, 0-100. |
SPEAKER_MAX_SAMPLE_BYTES_TOTAL), allocation failure, or if blocked by a higher or equal priority source. | bool speaker_service_play_volume_preview | ( | uint8_t | vol | ) |
Play a short tone at an absolute output volume.
Bypasses the user's speaker volume preference, so settings UIs can preview a candidate volume before it is saved. Mute still applies. Plays at SpeakerPriorityApp.
| vol | Absolute output volume, 0-100. |
| void speaker_service_register_finish | ( | PebbleTask | task | ) |
Post a PEBBLE_SPEAKER_EVENT with the finish reason whenever playback ends.
Stays enabled until speaker_service_stop_for_task() is called for task.
| task | Task interested in the events. |
| void speaker_service_set_owner_task | ( | PebbleTask | task | ) |
Set the task that owns the current playback.
| task | Owning task. |
| void speaker_service_set_volume | ( | uint8_t | vol | ) |
Set the playback volume.
| vol | Volume, 0-100. |
| void speaker_service_set_volume_owned | ( | PebbleTask | owner, |
| uint8_t | vol | ||
| ) |
Set the playback volume, only if the playback belongs to a task.
| owner | Owning task, or PebbleTask_Unknown to apply unconditionally. |
| vol | Volume, 0-100. |
| void speaker_service_stop | ( | void | ) |
Stop any active playback immediately.
| void speaker_service_stop_for_task | ( | PebbleTask | task | ) |
Stop any playback owned by a task and drop its finish events.
Called on app exit.
| task | Exiting task. |
| void speaker_service_stream_close | ( | void | ) |
Close the active stream.
Remaining buffered data is drained.
| void speaker_service_stream_close_owned | ( | PebbleTask | owner | ) |
Close the stream owned by a task, draining its buffered data.
| owner | Owning task, or PebbleTask_Unknown to close any stream. |
| bool speaker_service_stream_open | ( | SpeakerPriority | pri, |
| uint8_t | vol, | ||
| SpeakerPcmFormat | fmt | ||
| ) |
Open a PCM stream for writing.
| pri | Priority. |
| vol | Volume, 0-100. |
| fmt | PCM format of the data to be written. |
| bool speaker_service_stream_open_owned | ( | SpeakerPriority | pri, |
| uint8_t | vol, | ||
| SpeakerPcmFormat | fmt, | ||
| PebbleTask | owner | ||
| ) |
Open a PCM stream owned by a task.
Ownership is assigned atomically with the open, so the owner's later writes, closes and volume changes cannot affect a stream that has preempted it.
| pri | Priority. |
| vol | Volume, 0-100. |
| fmt | PCM format of the data to be written. |
| owner | Owning task. |
| bool speaker_service_stream_open_realtime_owned | ( | SpeakerPriority | pri, |
| uint8_t | vol, | ||
| SpeakerPcmFormat | fmt, | ||
| PebbleTask | owner | ||
| ) |
Open an owned PCM stream for internal live audio.
Writes feed complete driver blocks directly on the producer task. Driver callbacks retry on backpressure instead of inserting silence into the PCM queue, and closing always drains.
| pri | Priority. |
| vol | Volume, 0-100. |
| fmt | PCM format of the data to be written. |
| owner | Owning task. |
| uint32_t speaker_service_stream_write | ( | const void * | data, |
| uint32_t | num_bytes | ||
| ) |
Write PCM data to the active stream.
| data | Source buffer. |
| num_bytes | Number of bytes to write; a trailing partial sample is dropped. |
num_bytes when the queue is full. | uint32_t speaker_service_stream_write_owned | ( | PebbleTask | owner, |
| const void * | data, | ||
| uint32_t | num_bytes | ||
| ) |
Write PCM data to the stream owned by a task.
| owner | Owning task, or PebbleTask_Unknown to write to any stream. |
| data | Source buffer. |
| num_bytes | Number of bytes to write; a trailing partial sample is dropped. |