rework AudioUnit variable input port count.

This commit is contained in:
Robin Gareus 2015-09-02 21:05:09 +02:00
parent 2f69ee8ec8
commit c7b64803d9
2 changed files with 34 additions and 7 deletions

View file

@ -203,7 +203,7 @@ class LIBARDOUR_API AUPlugin : public ARDOUR::Plugin
framecnt_t cb_offset; framecnt_t cb_offset;
BufferSet* input_buffers; BufferSet* input_buffers;
framecnt_t frames_processed; framecnt_t frames_processed;
bool _match_ioports; uint32_t audio_input_cnt;
std::vector<AUParameterDescriptor> descriptors; std::vector<AUParameterDescriptor> descriptors;
AUEventListenerRef _parameter_listener; AUEventListenerRef _parameter_listener;

View file

@ -423,7 +423,7 @@ AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAC
, input_offset (0) , input_offset (0)
, input_buffers (0) , input_buffers (0)
, frames_processed (0) , frames_processed (0)
, _match_ioports (false) , audio_input_cnt (0)
, _parameter_listener (0) , _parameter_listener (0)
, _parameter_listener_arg (0) , _parameter_listener_arg (0)
, last_transport_rolling (false) , last_transport_rolling (false)
@ -1014,8 +1014,8 @@ AUPlugin::configure_io (ChanCount in, ChanCount out)
AudioStreamBasicDescription streamFormat; AudioStreamBasicDescription streamFormat;
bool was_initialized = initialized; bool was_initialized = initialized;
int32_t audio_out = out.n_audio(); int32_t audio_out = out.n_audio();
if (_match_ioports) { if (audio_input_cnt > 0) {
in.set (DataType::AUDIO, audio_out); in.set (DataType::AUDIO, audio_input_cnt);
} }
int32_t audio_in = in.n_audio(); int32_t audio_in = in.n_audio();
@ -1143,6 +1143,32 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out)
audio_out = audio_in; audio_out = audio_in;
} }
/* kAudioUnitProperty_SupportedNumChannels
* https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioUnitProgrammingGuide/TheAudioUnit/TheAudioUnit.html#//apple_ref/doc/uid/TP40003278-CH12-SW20
*
* - both fields are -1
* e.g. inChannels = -1 outChannels = -1
* This is the default case. Any number of input and output channels, as long as the numbers match
*
* - one field is -1, the other field is positive
* e.g. inChannels = -1 outChannels = 2
* Any number of input channels, exactly two output channels
*
* - one field is -1, the other field is -2
* e.g. inChannels = -1 outChannels = -2
* Any number of input channels, any number of output channels
*
* - both fields have non-negative values
* e.g. inChannels = 2 outChannels = 6
* Exactly two input channels, exactly six output channels
* e.g. inChannels = 0 outChannels = 2
* No input channels, exactly two output channels (such as for an instrument unit with stereo output)
*
* - both fields have negative values, neither of which is 1 or 2
* e.g. inChannels = -4 outChannels = -8
* Up to four input channels and up to eight output channels
*/
for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) { for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
int32_t possible_in = i->first; int32_t possible_in = i->first;
@ -1314,9 +1340,10 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out)
} }
if (found) { if (found) {
if (possible_in < -2 && possible_in == possible_out) { if (possible_in < -2 && audio_in == 0) {
// input-port count needs to match output-port // input-port count cannot be zero, use as many ports
_match_ioports = true; // as outputs, but at most abs(possible_in)
audio_input_cnt = max (1, min (audio_out, -possible_in));
} }
break; break;
} }