AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AOpusSoundPipe.h
    1#pragma once
    2
    3#include "AUI/Audio/ISoundPipe.h"
    4#include "AUI/IO/ADynamicPipe.h"
    5
    6typedef struct OpusDecoder OpusDecoder;
    7
   13public:
   14    static constexpr uint32_t SAMPLE_RATE = 48000;
   15    static constexpr AChannelFormat CHANNEL_COUNT = AChannelFormat::STEREO;
   16    static constexpr ASampleFormat SAMPLE_FORMAT = ASampleFormat::I16;
   17
   18    ~AOpusSoundPipe() override;
   19
   20    void write(const char *src, size_t size) override;
   21
   22    size_t read(char* dst, size_t size) override;
   23
   24    AAudioFormat info() override;
   25
   26    [[nodiscard]]
   27    bool isLastWriteSuccessful() const {
   28        return mLastWriteSuccessful;
   29    }
   30
   31private:
   32    static constexpr size_t HEADER_SIZE = 19;
   33    static constexpr size_t MAX_UNPACKED_SIZE = 11520;
   34
   35    struct OpusHead {
   36        char signature[8];
   37        uint8_t version;
   38        uint8_t outputChannelCount;
   39        uint16_t preSkip; //TODO implement preskipping first samples
   40        uint32_t inputSampleRate;
   41        int16_t outputGain;
   42        int8_t channelMap;
   43        char _pad[1];
   44    };
   45
   46    static_assert(sizeof(OpusHead) == 20);
   47
   48
   49    ADynamicPipe mDecodedSamples;
   50    bool mHeaderHasRead = false;
   51    bool mLastWriteSuccessful = true;
   52
   53    OpusHead mHeader;
   54    OpusDecoder* mDecoder;
   55    char mSampleBuffer[MAX_UNPACKED_SIZE];
   56    size_t mPreSkipped = 0;
   57    AMutex mSync;
   58};
Sound pipe for OPUS format, decodes OPUS packets.
Definition AOpusSoundPipe.h:12
size_t read(char *dst, size_t size) override
Reads up to size bytes from stream. Blocking (waiting for new data) is allowed.
void write(const char *src, size_t size) override
Writes exact size bytes to stream. Blocking (waiting for write all data) is allowed.
AAudioFormat info() override
Get general info about sound stream.
ISoundPipe accepts sound data and outputs sound samples, useful for decoded audio passed in packets.
Definition ISoundPipe.h:10
ASampleFormat
Sample formats supported for mixing.
Definition ASampleFormat.h:12
@ I16
Signed 16-bit integer.
Definition ASampleFormat.h:16
Audio format descriptor.
Definition AAudioFormat.h:13