Files
tomato/src/frame_streams/audio_stream2.hpp
Green Sky 811a673b0d
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android-23]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android-23]) (push) Has been cancelled
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android-23]) (push) Has been cancelled
ContinuousDelivery / windows (windows-2022, ) (push) Has been cancelled
ContinuousDelivery / windows (windows-2022, asan) (push) Has been cancelled
ContinuousDelivery / dumpsyms (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
ContinuousIntegration / on ubuntu-24.04-arm (push) Has been cancelled
ContinuousIntegration / asan on ubuntu-24.04-arm (push) Has been cancelled
ContinuousIntegration / on ubuntu-latest (push) Has been cancelled
ContinuousIntegration / asan on ubuntu-latest (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android-23]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android-23]) (push) Has been cancelled
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android-23]) (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
correctly move buffer
other fixes
2025-12-19 16:06:50 +01:00

68 lines
1.6 KiB
C++

#pragma once
#include "./frame_stream2.hpp"
#include <solanaceae/util/span.hpp>
#include <cstdint>
#include <variant>
#include <vector>
// raw audio
// channels make samples interleaved,
// planar channels are not supported
// s16 only stopgap audio frame (simplified)
struct AudioFrame2 {
// samples per second
uint32_t sample_rate {48'000};
// only >0 is valid
size_t channels {0};
std::variant<
std::vector<int16_t>, // S16, platform endianess
Span<int16_t> // non owning variant, for direct consumption
> buffer;
AudioFrame2(void) = default;
AudioFrame2(const AudioFrame2&) = default;
AudioFrame2(AudioFrame2&& other) :
sample_rate(other.sample_rate),
channels(other.channels),
buffer(std::move(other.buffer))
{}
AudioFrame2(uint32_t sample_rate_, size_t channels_, const std::variant<std::vector<int16_t>, Span<int16_t>>& buffer_) :
sample_rate(sample_rate_),
channels(channels_),
buffer(buffer_)
{}
AudioFrame2(uint32_t sample_rate_, size_t channels_, std::variant<std::vector<int16_t>, Span<int16_t>>&& buffer_) :
sample_rate(sample_rate_),
channels(channels_),
buffer(std::move(buffer_))
{}
// helpers
Span<int16_t> getSpan(void) const {
if (std::holds_alternative<std::vector<int16_t>>(buffer)) {
return Span<int16_t>{std::get<std::vector<int16_t>>(buffer)};
} else {
return std::get<Span<int16_t>>(buffer);
}
return {};
}
};
template<>
constexpr bool frameHasBytes<AudioFrame2>(void) {
return true;
}
template<>
inline uint64_t frameGetBytes(const AudioFrame2& frame) {
return frame.getSpan().size * sizeof(int16_t);
}
using AudioFrame2Stream2I = FrameStream2I<AudioFrame2>;