2019-10-26 01:51:40 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
|
2021-03-21 22:39:10 +01:00
|
|
|
namespace tc::audio {
|
2019-10-26 01:51:40 +02:00
|
|
|
#ifdef WIN32
|
2021-03-21 22:39:10 +01:00
|
|
|
#pragma pack(push,1)
|
|
|
|
#define __attribute__packed_1
|
2019-10-26 01:51:40 +02:00
|
|
|
#else
|
2021-03-21 22:39:10 +01:00
|
|
|
#define __attribute__packed_1 __attribute__((packed, aligned(1)))
|
2019-10-26 01:51:40 +02:00
|
|
|
#endif
|
2021-03-21 22:39:10 +01:00
|
|
|
/* Every sample is a float (4byte) */
|
|
|
|
struct __attribute__packed_1 SampleBuffer {
|
|
|
|
static constexpr size_t HEAD_LENGTH = 4;
|
2019-10-26 01:51:40 +02:00
|
|
|
|
2021-03-21 22:39:10 +01:00
|
|
|
uint16_t sample_size;
|
|
|
|
uint16_t sample_index;
|
2019-10-26 01:51:40 +02:00
|
|
|
|
2021-03-21 22:39:10 +01:00
|
|
|
char sample_data[
|
2019-10-26 01:51:40 +02:00
|
|
|
#ifndef WIN32
|
2021-03-21 22:39:10 +01:00
|
|
|
0
|
2019-10-26 01:51:40 +02:00
|
|
|
#else
|
2021-03-21 22:39:10 +01:00
|
|
|
1 /* windows does not allow zero sized arrays */
|
2019-10-26 01:51:40 +02:00
|
|
|
#endif
|
2021-03-21 22:39:10 +01:00
|
|
|
];
|
2019-10-26 01:51:40 +02:00
|
|
|
|
2021-03-21 22:39:10 +01:00
|
|
|
static std::shared_ptr<SampleBuffer> allocate(uint8_t /* channels */, uint16_t /* samples */);
|
|
|
|
};
|
2019-10-26 01:51:40 +02:00
|
|
|
|
|
|
|
#ifndef WIN32
|
2021-03-21 22:39:10 +01:00
|
|
|
static_assert(sizeof(SampleBuffer) == 4, "Invalid SampleBuffer packaging!");
|
2019-10-26 01:51:40 +02:00
|
|
|
#else
|
2021-03-21 22:39:10 +01:00
|
|
|
#pragma pack(pop)
|
|
|
|
static_assert(sizeof(SampleBuffer) == 5, "Invalid SampleBuffer packaging!");
|
2019-10-26 01:51:40 +02:00
|
|
|
#endif
|
|
|
|
}
|