From 9f668ceed29b1a3b79636a8767dca36c4e1ca307 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 11 Sep 2019 02:40:57 +0200 Subject: AU: fix optional buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec [1] says: "If the mData pointers are null, the audio unit can provide pointers to its own buffers. In this case, the audio unit must keep those buffers valid for the duration of the calling thread’s I/O cycle." A plugin *can* do this, but it does not need to. An extra NULL test is required. furthermore [2] specifies "mDataByteSize - The number of bytes in the buffer pointed at by the mData field." In case the host does not provide any buffers, this is obviously zero. [1] https://developer.apple.com/documentation/audiotoolbox/1438430-audiounitrender?language=objc [2] https://developer.apple.com/documentation/coreaudiotypes/audiobuffer?language=objc --- libs/ardour/audio_unit.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index e1ef883747..46b7c6746d 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -1667,17 +1667,19 @@ AUPlugin::connect_and_run (BufferSet& bufs, for (uint32_t i = 0; i < cnt; ++i) { buffers->mBuffers[i].mNumberChannels = 1; - buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample); - /* setting this to 0 indicates to the AU that it can provide buffers here + /* setting this to 0 indicates to the AU that it *can* provide buffers here * if necessary. if it can process in-place, it will use the buffers provided * as input by ::render_callback() above. * * a non-null values tells the plugin to render into the buffer pointed * at by the value. + * https://developer.apple.com/documentation/audiotoolbox/1438430-audiounitrender?language=objc */ if (inplace) { + buffers->mBuffers[i].mDataByteSize = 0; buffers->mBuffers[i].mData = 0; } else { + buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample); bool valid = false; uint32_t idx = out_map.get (DataType::AUDIO, i + busoff, &valid); if (valid) { @@ -1704,7 +1706,12 @@ AUPlugin::connect_and_run (BufferSet& bufs, for (uint32_t i = 0; i < limit; ++i) { bool valid = false; uint32_t idx = out_map.get (DataType::AUDIO, i + busoff, &valid); - if (!valid) continue; + if (!valid) { + continue; + } + if (buffers->mBuffers[i].mData == 0 || buffers->mBuffers[i].mNumberChannels != 1) { + continue + } used_outputs.set (i + busoff); Sample* expected_buffer_address = bufs.get_audio (idx).data (offset); if (expected_buffer_address != buffers->mBuffers[i].mData) { -- cgit v1.2.3