Optimize Audio by using Circular Buffers, Handle Device Disconnection and Fix Some Bugs

This optimizes a lot of audio by using a circular buffer rather than queues. In addition to handling device disconnection using oboe callbacks and fix bugs in regards to audio saturation.
This commit is contained in:
◱ PixelyIon
2020-04-18 03:05:31 +05:30
committed by ◱ PixelyIon
parent 4e4ed5aac0
commit fb1a158e8f
8 changed files with 270 additions and 97 deletions

View File

@ -17,17 +17,14 @@ namespace skyline::audio {
class Audio : public oboe::AudioStreamCallback {
private:
const DeviceState &state; //!< The state of the device
oboe::AudioStreamBuilder builder; //!< The audio stream builder, used to open
oboe::ManagedStream outputStream; //!< The output oboe audio stream
std::vector<std::shared_ptr<audio::AudioTrack>> audioTracks; //!< Vector containing a pointer of every open audio track
std::vector<std::shared_ptr<audio::AudioTrack>> audioTracks; //!< A vector of shared_ptr to every open audio track
Mutex trackMutex; //!< This mutex is used to ensure that audioTracks isn't modified while it is being used
public:
Audio(const DeviceState &state);
/**
* @brief The destructor for the audio class
*/
~Audio();
/**
* @brief Opens a new track that can be used to play sound
* @param channelCount The amount channels that are present in the track
@ -50,5 +47,12 @@ namespace skyline::audio {
* @param numFrames The amount of frames the sample data needs to contain
*/
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames);
/**
* @brief The callback oboe uses to notify the application about stream closure
* @param audioStream The audio stream we are being called by
* @param error The error due to which the stream is being closed
*/
void onErrorAfterClose(oboe::AudioStream *audioStream, oboe::Result error);
};
}