37 lines
902 B
C
Raw Normal View History

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