2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2020-01-02 21:19:34 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-16 21:12:17 +01:00
|
|
|
#include <common/settings.h>
|
2020-01-02 21:19:34 +01:00
|
|
|
#include <audio/track.h>
|
|
|
|
|
|
|
|
namespace skyline::audio {
|
|
|
|
/**
|
|
|
|
* @brief The Audio class is used to mix audio from all tracks
|
|
|
|
*/
|
|
|
|
class Audio : public oboe::AudioStreamCallback {
|
|
|
|
private:
|
2020-09-28 12:05:17 +02:00
|
|
|
oboe::AudioStreamBuilder builder;
|
|
|
|
oboe::ManagedStream outputStream;
|
|
|
|
std::vector<std::shared_ptr<AudioTrack>> audioTracks;
|
2020-10-28 17:00:39 +01:00
|
|
|
std::mutex trackLock; //!< Synchronizes modifications to the audio tracks
|
2022-11-16 21:12:17 +01:00
|
|
|
std::shared_ptr<Settings> settings;
|
2020-01-02 21:19:34 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Audio(const DeviceState &state);
|
|
|
|
|
2020-11-03 10:44:09 +01:00
|
|
|
~Audio();
|
|
|
|
|
2021-10-13 19:08:48 +02:00
|
|
|
void Pause() {
|
|
|
|
outputStream->requestPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resume() {
|
|
|
|
outputStream->requestStart();
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:19:34 +01:00
|
|
|
/**
|
|
|
|
* @brief Opens a new track that can be used to play sound
|
|
|
|
* @param channelCount The amount channels that are present in the track
|
|
|
|
* @param sampleRate The sample rate of the track
|
|
|
|
* @param releaseCallback The callback to call when a buffer has been released
|
|
|
|
* @return A shared pointer to a new AudioTrack object
|
|
|
|
*/
|
2020-08-20 20:31:32 +02:00
|
|
|
std::shared_ptr<AudioTrack> OpenTrack(u8 channelCount, u32 sampleRate, const std::function<void()> &releaseCallback);
|
2020-01-02 21:19:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Closes a track and frees its data
|
|
|
|
*/
|
2020-08-20 20:31:32 +02:00
|
|
|
void CloseTrack(std::shared_ptr<AudioTrack> &track);
|
2020-01-02 21:19:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The callback oboe uses to get audio sample data
|
|
|
|
* @param audioStream The audio stream we are being called by
|
|
|
|
* @param audioData The raw audio sample data
|
|
|
|
* @param numFrames The amount of frames the sample data needs to contain
|
|
|
|
*/
|
|
|
|
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames);
|
2020-04-17 23:35:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
2020-01-02 21:19:34 +01:00
|
|
|
};
|
|
|
|
}
|