mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
A2B: Add initial WAV streaming support
This commit is contained in:
@@ -5,26 +5,26 @@
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
|
||||
|
||||
#define A2BMESSAGE_UPSTREAM 1
|
||||
#define A2BMESSAGE_DOWNSTREAM 0
|
||||
|
||||
#define A2BPCM_SAMPLE_SIZE 4
|
||||
|
||||
#define A2BPCM_L16 16
|
||||
#define A2BPCM_L24 24
|
||||
|
||||
#define A2BPCM_SAMPLERATE_44100 44100
|
||||
#define A2BPCM_SAMPLERATE_48000 48000
|
||||
|
||||
namespace icsneo
|
||||
{
|
||||
namespace icsneo {
|
||||
|
||||
typedef uint32_t A2BPCMSample;
|
||||
typedef std::vector<A2BPCMSample> ChannelBuffer;
|
||||
|
||||
class A2BMessage : public Frame
|
||||
{
|
||||
class A2BMessage : public Frame {
|
||||
public:
|
||||
enum class A2BDirection : uint8_t
|
||||
{
|
||||
enum class A2BDirection : uint8_t {
|
||||
DownStream = 0,
|
||||
UpStream = 1
|
||||
};
|
||||
@@ -40,86 +40,78 @@ public:
|
||||
upstream.resize(numChannels);
|
||||
}
|
||||
|
||||
void addSample(A2BPCMSample &&sample, A2BDirection dir, uint8_t channel)
|
||||
{
|
||||
if(dir == A2BDirection::DownStream)
|
||||
{
|
||||
void addSample(A2BPCMSample &&sample, A2BDirection dir, uint8_t channel) {
|
||||
if(dir == A2BDirection::DownStream) {
|
||||
downstream[channel].push_back(std::move(sample));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
upstream[channel].push_back(std::move(sample));
|
||||
}
|
||||
totalSamples++;
|
||||
}
|
||||
|
||||
const A2BPCMSample *getSamples(A2BDirection dir, uint8_t channel) const
|
||||
{
|
||||
if(channel >= getNumChannels())
|
||||
{
|
||||
const A2BPCMSample* getSamples(A2BDirection dir, uint8_t channel) const {
|
||||
if(channel >= getNumChannels()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(dir == A2BDirection::DownStream)
|
||||
{
|
||||
if(dir == A2BDirection::DownStream) {
|
||||
return downstream[channel].data();
|
||||
}
|
||||
return upstream[channel].data();
|
||||
}
|
||||
|
||||
std::optional<A2BPCMSample> getSample(A2BDirection dir, uint8_t channel, uint32_t sampleIndex) const
|
||||
{
|
||||
const A2BPCMSample *samples = getSamples(dir, channel);
|
||||
std::optional<A2BPCMSample> getSample(A2BDirection dir, uint8_t channel, uint32_t sampleIndex) const {
|
||||
const A2BPCMSample* samples = getSamples(dir, channel);
|
||||
auto numSamplesInChannel = getNumSamplesInChannel(dir, channel);
|
||||
|
||||
if(
|
||||
samples == nullptr ||
|
||||
sampleIndex >= numSamplesInChannel.value_or(0)
|
||||
)
|
||||
{
|
||||
) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return samples[sampleIndex];
|
||||
}
|
||||
|
||||
std::optional<std::size_t> getNumSamplesInChannel(A2BDirection dir, uint8_t channel) const
|
||||
{
|
||||
if(channel >= getNumChannels())
|
||||
{
|
||||
std::optional<size_t> getNumSamplesInChannel(A2BDirection dir, uint8_t channel) const {
|
||||
if(channel >= getNumChannels()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if(dir == A2BDirection::DownStream)
|
||||
{
|
||||
if(dir == A2BDirection::DownStream) {
|
||||
return downstream[channel].size();
|
||||
}
|
||||
|
||||
return upstream[channel].size();
|
||||
}
|
||||
|
||||
size_t getNumSamples() const
|
||||
{
|
||||
const std::vector<ChannelBuffer>& getDownstream() const {
|
||||
return downstream;
|
||||
}
|
||||
|
||||
const std::vector<ChannelBuffer>& getUpstream() const {
|
||||
return upstream;
|
||||
}
|
||||
|
||||
size_t getNumSamples() const {
|
||||
return totalSamples;
|
||||
}
|
||||
|
||||
uint8_t getNumChannels() const
|
||||
{
|
||||
uint8_t getNumChannels() const {
|
||||
return static_cast<uint8_t>(downstream.size());
|
||||
}
|
||||
|
||||
uint8_t getBitDepth() const
|
||||
{
|
||||
uint8_t getBitDepth() const {
|
||||
return mBitDepth;
|
||||
}
|
||||
|
||||
uint8_t getBytesPerSample() const
|
||||
{
|
||||
uint8_t getBytesPerSample() const {
|
||||
return mBytesPerSample;
|
||||
}
|
||||
|
||||
bool isMonitor() const
|
||||
{
|
||||
bool isMonitor() const {
|
||||
return mMonitor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user