Migrate to VoidLibrary (toolchain + API groundwork)
This commit is contained in:
1 parent
5e1e3d66c4
commit
e17cfed56f
38 files changed
+3077
-2505
No files matched your search
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include <MemoryPool.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
enum class AudioFormat : uint8_t {
|
||||
Unknown = 0,
|
||||
MP3,
|
||||
AAC,
|
||||
Opus,
|
||||
Vorbis,
|
||||
FLAC,
|
||||
WAV
|
||||
};
|
||||
|
||||
enum class AudioQuality : uint8_t {
|
||||
Low = 0, // 64-96 kbps
|
||||
Medium, // 128-160 kbps
|
||||
High, // 192-256 kbps
|
||||
VeryHigh, // 320 kbps
|
||||
Lossless // FLAC or equivalent
|
||||
};
|
||||
|
||||
// Hardware acceleration types
|
||||
enum class HwAccelType : uint8_t {
|
||||
None = 0,
|
||||
CUDA, // NVIDIA CUDA
|
||||
VAAPI, // Video Acceleration API (Linux)
|
||||
DXVA2, // DirectX Video Acceleration 2 (Windows)
|
||||
D3D11VA, // Direct3D 11 Video Acceleration
|
||||
VideoToolbox, // Apple VideoToolbox
|
||||
Vulkan // Vulkan Video
|
||||
};
|
||||
|
||||
struct AudioFrame {
|
||||
std::vector<uint8_t> data;
|
||||
std::chrono::milliseconds pts;
|
||||
std::chrono::milliseconds duration;
|
||||
bool isKeyFrame;
|
||||
};
|
||||
|
||||
struct AudioStreamInfo {
|
||||
AudioFormat format;
|
||||
uint32_t sampleRate;
|
||||
uint32_t channels;
|
||||
uint32_t bitrate;
|
||||
std::chrono::milliseconds duration;
|
||||
std::optional<AudioQuality> quality;
|
||||
bool hwAccelerated = false;
|
||||
HwAccelType hwAccelType = HwAccelType::None;
|
||||
};
|
||||
|
||||
// Zero-copy decoded audio using pooled memory (int16 for direct playback)
|
||||
struct DecodedAudio {
|
||||
// Use pooled buffer instead of std::vector for zero-copy
|
||||
// Now using int16_t for direct TeamSpeak compatibility (no float
|
||||
// conversion)
|
||||
std::vector<int16_t> samples;
|
||||
|
||||
// Non-owning view into the data
|
||||
Int16AudioView view;
|
||||
|
||||
uint32_t sampleRate;
|
||||
uint32_t channels;
|
||||
std::chrono::milliseconds timestamp;
|
||||
|
||||
// Backwards compatibility - returns the samples
|
||||
[[nodiscard]] std::vector<int16_t> getSamples() const
|
||||
{
|
||||
return samples;
|
||||
}
|
||||
|
||||
// Check if valid
|
||||
[[nodiscard]] bool isValid() const { return !samples.empty(); }
|
||||
|
||||
// Apply volume in-place (int16 version)
|
||||
void applyVolume(float volume)
|
||||
{
|
||||
if (samples.empty()) {
|
||||
return;
|
||||
}
|
||||
int32_t volInt = static_cast<int32_t>(volume * 32768);
|
||||
for (auto& sample : samples) {
|
||||
int32_t scaled =
|
||||
(static_cast<int32_t>(sample) * volInt) / 32768;
|
||||
sample =
|
||||
static_cast<int16_t>(std::clamp(scaled, -32768, 32767));
|
||||
}
|
||||
// Update view to point to new data
|
||||
view = Int16AudioView(samples.data(), samples.size(), channels);
|
||||
}
|
||||
};
|
||||
|
||||
// Hardware acceleration configuration
|
||||
struct HwAccelConfig {
|
||||
HwAccelType type = HwAccelType::None;
|
||||
int deviceIndex = -1; // -1 for auto-select
|
||||
std::optional<std::string> deviceName;
|
||||
|
||||
[[nodiscard]] bool isEnabled() const
|
||||
{
|
||||
return type != HwAccelType::None;
|
||||
}
|
||||
};
|
||||
|
||||
// Audio processing options
|
||||
struct AudioProcessOptions {
|
||||
float volume = 1.0f;
|
||||
bool normalize = false;
|
||||
bool highPassFilter = false; // Remove DC offset
|
||||
float highPassFreq = 20.0f; // Hz
|
||||
bool limiter = false; // Prevent clipping
|
||||
float limiterThreshold = 0.95f;
|
||||
};
|
||||
|
||||
using AudioBuffer = std::vector<uint8_t>;
|
||||
using AudioFramePtr = std::shared_ptr<AudioFrame>;
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user