BSB Developer Docs
Loading...
Searching...
No Matches
audio.h File Reference

APIs for playing audio (e.g. More...

#include <stdbool.h>
#include <core/pubsub.h>

Go to the source code of this file.

Data Structures

struct  AudioEvent
 Audio event structure emitted by the PubSub. More...
 

Macros

#define RECORD_AUDIO   "audio"
 Record key to access the Audio instance.
 

Typedefs

typedef struct Audio Audio
 Audio opaque type declaration.
 

Enumerations

enum  AudioEventType { AudioEventVolumeUpdate , AudioEventPlayEnd }
 The types of events that can occur. More...
 

Functions

FuriPubSub * audio_get_pubsub (Audio *instance)
 Get the PubSub instance for events subscription.
 
bool audio_play_file (Audio *instance, const char *file_name)
 Play an audio file from storage.
 
bool audio_stop (Audio *instance)
 Stop playing current audio from file.
 
void audio_set_volume (Audio *instance, float volume)
 Set the playback volume.
 
float audio_get_volume (Audio *instance)
 Get the playback volume.
 

Detailed Description

APIs for playing audio (e.g.

files from MMC storage).

Enumeration Type Documentation

◆ AudioEventType

The types of events that can occur.

Enumerator
AudioEventVolumeUpdate 

Volume has been changed.

AudioEventPlayEnd 

File ended playing.

Function Documentation

◆ audio_get_pubsub()

FuriPubSub * audio_get_pubsub ( Audio * instance)

Get the PubSub instance for events subscription.

The received events will be of AudioEvent underlying type.

Parameters
[in]instancepointer to the Audio instance
Returns
pointer to the PubSub instance

◆ audio_get_volume()

float audio_get_volume ( Audio * instance)

Get the playback volume.

The volume is in range 0.0 (mute) to 1.0 (full volume).

Parameters
[in]instancepointer to the Audio instance
Returns
volume value (see above range)

◆ audio_play_file()

bool audio_play_file ( Audio * instance,
const char * file_name )

Play an audio file from storage.

The file MUST be in the following format:

  • Header: none
  • Channels: 1
  • Rate: 44100 Hz
  • Bits: 16bit LE

If this function is called when a file is already playing, the new file will start playing immediately without waiting for the playback to end.

Parameters
[in,out]instancepointer to the Audio instance
[in]file_namefull path to the file location on the storage
Returns
true if the file could be played, false otherwise

◆ audio_set_volume()

void audio_set_volume ( Audio * instance,
float volume )

Set the playback volume.

The volume MUST be in range 0.0 (mute) to 1.0 (full volume).

Parameters
[in,out]instancepointer to the Audio instance
[in]volumenew volume value (see above range)

◆ audio_stop()

bool audio_stop ( Audio * instance)

Stop playing current audio from file.

Parameters
[in,out]instancepointer to the Audio instance
Returns
true if the audio is stopping, false if not playing