// SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) #pragma once #include #include "circular_buffer.h" namespace skyline { namespace constant { constexpr auto SampleRate = 48000; //!< The common sampling rate to use for audio output constexpr auto ChannelCount = 2; //!< The common amount of channels to use for audio output constexpr auto PcmFormat = oboe::AudioFormat::I16; //!< The common PCM data format to use for audio output constexpr size_t MixBufferSize = 960; //!< The size of the mix buffer by default }; namespace audio { /** * @brief The available PCM stream formats */ enum class AudioFormat : u8 { Invalid = 0, //!< An invalid PCM format 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 }; /** * @brief The state of an audio track */ enum class AudioOutState : u8 { Started = 0, //!< Stream is started and is playing Stopped = 1, //!< Stream is stopped, there are no samples left to play Paused = 2 //!< Stream is paused, some samples may not have been played yet }; /** * @brief This stores information about pushed buffers */ struct BufferIdentifier { u64 tag; //!< The tag of the buffer u64 finalSample; //!< The final sample this buffer will be played in bool released; //!< If the buffer has been released }; /** * @brief This saturates the specified value according to the numeric limits of Out * @tparam Out The return value type and the numeric limit clamp * @tparam Intermediate The intermediate type that is converted to from In before clamping * @tparam In The input value type * @param value The value to saturate * @return The saturated value */ template inline Out Saturate(In value) { return static_cast(std::clamp(static_cast(value), static_cast(std::numeric_limits::min()), static_cast(std::numeric_limits::max()))); } } }