🌐 English

    Audio Device API#

    Header File#

    OasisMedia.h

    Functions#

    int32_t createAudioDevice ( key_value_map_t & parameters )
    OasisMedia.h
    Initializes an audio device.
    Parameters
    parameters  The key-value map required for audio device initialization.
    Return Value
    • 0: Success
    • -1: Failure

    The key-value map that can be passed as a parameter to the oasis::createAudioDevice function is as follows:

    Key
    Default
    M
    Description
    types
    Specifies the role of the audio device. It can be set to one of the following values: sink, source, or sink,source. sink indicates output (speaker), and source indicates input (microphone).
    path
    Specifies the audio device path. You can use a hardware device path in the format of hw:<card>,<device> (e.g., hw:0,0) or an ALSA device name such as default. This can be verified using commands like aplay -l, aplay -L, arecord -l, or arecord -L.
    always-on
    0
     
    Specifies whether to keep the audio device always running. If set to "1", the audio device remains open even when there are no active users.
    aec-disabled
    1
     
    Specifies whether Acoustic Echo Cancellation (AEC) is operational. By default, AEC is disabled.
    denoise-enabled
    0
     
    Specifies whether noise reduction is operational. By default, noise reduction is disabled. When AEC is enabled, the noise reduction feature is also activated.
    snd-input-channels
    1
     
    Specifies the number of input/output channels.
    snd-input-sample-size
    16
     
    Specifies the sample size (in bits).
    snd-input-sampling-rate
    8000
     
    Specifies the sampling rate (in Hz). You must specify a value supported by the hardware device.
    snd-input-sampling-duration-msec
    40
     
    Specifies the sampling buffer size in time units (milliseconds). This setting may vary along with the sampling rate depending on the hardware audio device.
    int32_t restartAudioDevice ( const char * device_path , int32_t direction = SND_DIR_BOTH )
    OasisMedia.h
    Restarts an audio device.
    Parameters
    device_path  The audio device path specified in createAudioDevice.
    direction  Specifies the type of audio device to restart. It can be set to one of the following values: SND_DIR_OUT, SND_DIR_IN, or SND_DIR_BOTH.
    Return Value
    • 0: Success
    • -1: Failure

    direction is defined in OasisMedia.h with the following values:

    enum {
        SND_DIR_OUT = 1, //speaker
        SND_DIR_IN = 2,  //mic
        SND_DIR_BOTH = 3 //speaker+mic
    };
    
    OasisMedia.h
    Removes all audio devices.

    Examples#

    The following is an example of creating an audio device after calling oasis::initialize:

    #if 0
    #define SND_PATH "default"
    #else
    #define SND_PATH "hw:0,0"
    #endif
    
    oasis::key_value_map_t parameters;
    
    parameters["types"]="sink";
    parameters["path"]=SND_PATH;
    parameters["always-on"]="0";
    parameters["aec-disabled"]="1";
    parameters["snd-input-channels"]="2";
    parameters["snd-input-sample-size"]="16";
    parameters["snd-input-sampling-duration-msec"]="40";
    parameters["snd-input-sampling-rate"]="48000";
    
    oasis::createAudioDevice(parameters);