46 #include <boost/filesystem.hpp>
47 #include <boost/shared_array.hpp>
56 namespace sound_asset_writer {
59 int32_t convert(T) {
return {}; }
62 inline int32_t convert(int32_t x)
64 int constexpr clip = (1 << 23);
65 return std::max(-clip, std::min(clip, x));
69 inline int32_t convert(
float x)
71 float constexpr clip = 1.0f - (1.0f / (1 << 23));
72 float constexpr scale = (1 << 23);
73 auto const clipped = std::max(-clip, std::min(clip, x));
74 return std::lround(clipped * scale);
102 void write(
float const *
const * data,
int channels,
int frames);
110 void write(int32_t
const *
const * data,
int channels,
int frames);
116 friend struct ::sync_test1;
118 byte_t* frame_buffer_data()
const;
119 int frame_buffer_capacity()
const;
123 do_write(T
const *
const * data,
int data_channels,
int frames)
126 DCP_ASSERT(frames > 0);
128 auto const asset_channels = _asset->
channels();
129 DCP_ASSERT(data_channels <= asset_channels);
135 for (
int i = 0; i < frames; ++i) {
137 auto out = frame_buffer_data() + _frame_buffer_offset;
140 for (
int j = 0; j < asset_channels; ++j) {
142 if (j == 13 &&
_sync) {
144 }
else if (j < data_channels) {
145 s = sound_asset_writer::convert(data[j][i]);
148 *out++ = (s & 0xff00) >> 8;
149 *out++ = (s & 0xff0000) >> 16;
151 _frame_buffer_offset += 3 * asset_channels;
153 DCP_ASSERT(_frame_buffer_offset <= frame_buffer_capacity());
156 if (_frame_buffer_offset == frame_buffer_capacity()) {
157 write_current_frame();
158 _frame_buffer_offset = 0;
159 memset(frame_buffer_data(), 0, frame_buffer_capacity());
164 SoundAssetWriter(
SoundAsset *, boost::filesystem::path, std::vector<dcp::Channel> extra_active_channels,
bool sync,
bool include_mca_subdescriptors);
167 void write_current_frame ();
175 std::shared_ptr<ASDCPState> _state;
178 int _frame_buffer_offset = 0;
180 std::vector<dcp::Channel> _extra_active_channels;
186 bool _include_mca_subdescriptors =
true;
Parent class for classes which can write MXF-based assets.
Create frequency-shift-keyed samples for encoding synchronization signals.
A helper class for writing to SoundAssets.
void write(float const *const *data, int channels, int frames)
std::vector< bool > create_sync_packets()
Representation of a sound asset.
Namespace for everything in libdcp.