skyline/app/src/main/cpp/skyline/audio/common.h

63 lines
2.5 KiB
C++

// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#pragma once
#include <oboe/Oboe.h>
#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<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())));
}
}
}