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
|
|
|
|
|
|
|
|
#include <oboe/Oboe.h>
|
2020-11-03 10:44:09 +01:00
|
|
|
#include <common.h>
|
2020-01-02 21:19:34 +01:00
|
|
|
|
2020-03-25 18:59:37 +01:00
|
|
|
namespace skyline {
|
|
|
|
namespace constant {
|
2020-08-21 15:28:47 +02:00
|
|
|
constexpr u16 SampleRate{48000}; //!< The common sampling rate to use for audio output
|
2022-01-22 22:42:38 +01:00
|
|
|
constexpr u8 StereoChannelCount{2}; //!< Channels to use for stereo audio output
|
|
|
|
constexpr u8 SurroundChannelCount{6}; //!< Channels to use for surround audio output (downsampled by backend)
|
|
|
|
constexpr u16 MixBufferSize{960}; //!< Default size of the audren mix buffer
|
|
|
|
constexpr auto PcmFormat{oboe::AudioFormat::I16}; //!< PCM data format to use for audio output
|
2021-02-06 13:36:58 +01:00
|
|
|
}
|
2020-01-02 21:19:34 +01:00
|
|
|
|
2020-03-25 18:59:37 +01:00
|
|
|
namespace audio {
|
2020-04-17 23:23:38 +02:00
|
|
|
enum class AudioFormat : u8 {
|
2020-03-25 18:59:37 +01:00
|
|
|
Invalid = 0, //!< An invalid PCM format
|
2020-09-28 12:05:17 +02:00
|
|
|
Int8 = 1, //!< 8 bit integer PCM
|
|
|
|
Int16 = 2, //!< 16 bit integer PCM
|
|
|
|
Int24 = 3, //!< 24 bit integer PCM
|
|
|
|
Int32 = 4, //!< 32 bit integer PCM
|
|
|
|
Float = 5, //!< Floating point PCM
|
|
|
|
ADPCM = 6, //!< Adaptive differential PCM
|
2020-03-25 18:59:37 +01:00
|
|
|
};
|
2020-01-02 21:19:34 +01:00
|
|
|
|
2020-03-25 18:59:37 +01:00
|
|
|
enum class AudioOutState : u8 {
|
|
|
|
Started = 0, //!< Stream is started and is playing
|
|
|
|
Stopped = 1, //!< Stream is stopped, there are no samples left to play
|
2020-09-28 12:05:17 +02:00
|
|
|
Paused = 2, //!< Stream is paused, some samples may not have been played yet
|
2020-03-25 18:59:37 +01:00
|
|
|
};
|
2020-01-02 21:19:34 +01:00
|
|
|
|
2020-03-25 18:59:37 +01:00
|
|
|
struct BufferIdentifier {
|
2020-08-21 15:28:47 +02:00
|
|
|
u64 tag;
|
|
|
|
u64 finalSample; //!< The final sample this buffer will be played in, after that the buffer can be safely released
|
|
|
|
bool released; //!< If the buffer has been released (fully played back)
|
2020-03-25 18:59:37 +01:00
|
|
|
};
|
2020-04-17 23:35:31 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-28 12:05:17 +02:00
|
|
|
* @brief Saturates the specified value according to the numeric limits of Out
|
2020-04-17 23:35:31 +02:00
|
|
|
* @tparam Out The return value type and the numeric limit clamp
|
|
|
|
* @tparam Intermediate The intermediate type that is converted to from In before clamping
|
|
|
|
*/
|
|
|
|
template<typename Out, typename Intermediate, typename In>
|
|
|
|
inline Out Saturate(In value) {
|
|
|
|
return static_cast<Out>(std::clamp(static_cast<Intermediate>(value), static_cast<Intermediate>(std::numeric_limits<Out>::min()), static_cast<Intermediate>(std::numeric_limits<Out>::max())));
|
|
|
|
}
|
2020-03-25 18:59:37 +01:00
|
|
|
}
|
2020-01-02 21:19:34 +01:00
|
|
|
}
|