summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-03-16 19:51:27 +0100
committerCarl Hetherington <cth@carlh.net>2023-03-16 19:52:06 +0100
commitc1d296b163ddf88a5b387f98e7e77988a242a996 (patch)
tree4edbcca02dd8bfebdd9530eaad7004dfbb79d125 /src
parent53b444191fddd72416647ec9d24aff1e317a1824 (diff)
Specify number of channels in the data passed to SoundAssetWriter, and pad channels that aren't there.
Diffstat (limited to 'src')
-rw-r--r--src/sound_asset_writer.cc15
-rw-r--r--src/sound_asset_writer.h4
2 files changed, 11 insertions, 8 deletions
diff --git a/src/sound_asset_writer.cc b/src/sound_asset_writer.cc
index a0414aba..f789eb3b 100644
--- a/src/sound_asset_writer.cc
+++ b/src/sound_asset_writer.cc
@@ -200,29 +200,30 @@ LIBDCP_ENABLE_WARNINGS
void
-SoundAssetWriter::write (float const * const * data, int frames)
+SoundAssetWriter::write(float const * const * data, int data_channels, int frames)
{
DCP_ASSERT (!_finalized);
DCP_ASSERT (frames > 0);
+ auto const asset_channels = _asset->channels();
+ DCP_ASSERT (data_channels <= asset_channels);
+
static float const clip = 1.0f - (1.0f / pow (2, 23));
if (!_started) {
start ();
}
- int const ch = _asset->channels ();
-
for (int i = 0; i < frames; ++i) {
byte_t* out = _state->frame_buffer.Data() + _frame_buffer_offset;
- /* Write one sample per channel */
- for (int j = 0; j < ch; ++j) {
+ /* Write one sample per asset channel */
+ for (int j = 0; j < asset_channels; ++j) {
int32_t s = 0;
if (j == 13 && _sync) {
s = _fsk.get();
- } else {
+ } else if (j < data_channels) {
/* Convert sample to 24-bit int, clipping if necessary. */
float x = data[j][i];
if (x > clip) {
@@ -236,7 +237,7 @@ SoundAssetWriter::write (float const * const * data, int frames)
*out++ = (s & 0xff00) >> 8;
*out++ = (s & 0xff0000) >> 16;
}
- _frame_buffer_offset += 3 * ch;
+ _frame_buffer_offset += 3 * asset_channels;
DCP_ASSERT (_frame_buffer_offset <= int(_state->frame_buffer.Capacity()));
diff --git a/src/sound_asset_writer.h b/src/sound_asset_writer.h
index 0435b85f..6d8191c7 100644
--- a/src/sound_asset_writer.h
+++ b/src/sound_asset_writer.h
@@ -70,9 +70,11 @@ public:
~SoundAssetWriter();
/** @param data Pointer an array of float pointers, one for each channel.
+ * @param channels Number of channels in data; if this is less than the channels in the asset
+ * the remaining asset channels will be padded with silence.
* @param frames Number of frames i.e. number of floats that are given for each channel.
*/
- void write (float const * const *, int);
+ void write(float const * const * data, int channels, int frames);
bool finalize () override;