gboolean
gst_core_audio_io_proc_start (GstCoreAudio * core_audio)
{
  OSStatus status;
  AURenderCallbackStruct input;
  AudioUnitPropertyID callback_type;

  GST_DEBUG_OBJECT (core_audio->osxbuf,
      "osx ring buffer start ioproc: %p device_id %lu",
      core_audio->element->io_proc, (gulong) core_audio->device_id);
  if (!core_audio->io_proc_active) {
    callback_type = core_audio->is_src ?
        kAudioOutputUnitProperty_SetInputCallback :
        kAudioUnitProperty_SetRenderCallback;

    input.inputProc = (AURenderCallback) core_audio->element->io_proc;
    input.inputProcRefCon = core_audio->osxbuf;

    status = AudioUnitSetProperty (core_audio->audiounit, callback_type, kAudioUnitScope_Global, 0,     /* N/A for global */
        &input, sizeof (input));

    if (status) {
      GST_ERROR_OBJECT (core_audio->osxbuf,
          "AudioUnitSetProperty failed: %" GST_FOURCC_FORMAT,
          GST_FOURCC_ARGS (status));
      return FALSE;
    }
    // ### does it make sense to do this notify stuff for input mode?
    status = AudioUnitAddRenderNotify (core_audio->audiounit,
        (AURenderCallback) gst_core_audio_render_notify, core_audio);

    if (status) {
      GST_ERROR_OBJECT (core_audio->osxbuf,
          "AudioUnitAddRenderNotify failed %"
          GST_FOURCC_FORMAT, GST_FOURCC_ARGS (status));
      return FALSE;
    }
    core_audio->io_proc_active = TRUE;
  }

  core_audio->io_proc_needs_deactivation = FALSE;

  status = AudioOutputUnitStart (core_audio->audiounit);
  if (status) {
    GST_ERROR_OBJECT (core_audio->osxbuf, "AudioOutputUnitStart failed: %"
        GST_FOURCC_FORMAT, GST_FOURCC_ARGS (status));
    return FALSE;
  }
  return TRUE;
}
void OutputImplAudioUnit::Track::play() 
{
	AURenderCallbackStruct renderCallback;
	renderCallback.inputProc = &OutputImplAudioUnit::Track::renderCallback;
	renderCallback.inputProcRefCon = (void *)this;
	
	OSStatus err;
	
	err = AudioUnitSetProperty( mOutput->mMixerUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, mInputBus, mOutput->mPlayerDescription, sizeof( AudioStreamBasicDescription ) );
	if( err ) {
		//throw
		std::cout << "Error setting track input bus format on mixer" << std::endl;
	}
	
	err = AudioUnitSetParameter( mOutput->mMixerUnit, kMultiChannelMixerParam_Enable, kAudioUnitScope_Input, mInputBus, 1, 0 );
	if( err ) {
		std::cout << "error enabling input bus" << std::endl;
	}
	
	err = AudioUnitSetParameter( mOutput->mMixerUnit, kMultiChannelMixerParam_Volume, kAudioUnitScope_Input, mInputBus, CINDER_DEFAULT_VOLUME, 0 );
	if( err ) {
		std::cout << "error setting default volume" << std::endl;
	}
	
	mIsPlaying = true;
	
	err = AudioUnitAddRenderNotify( mOutput->mMixerUnit, OutputImplAudioUnit::Track::renderNotifyCallback, (void *)this );
	if( err ) {
		//throw
		std::cout << "Error setting track redner notify callback on mixer" << std::endl;
	}
	
	err = AudioUnitSetProperty( mOutput->mMixerUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, mInputBus, &renderCallback, sizeof(renderCallback) );
	if( err ) {
		//throw
		std::cout << "Error setting track redner callback on mixer" << std::endl;
	}
}
Beispiel #3
0
bool auLoader::initialize()
{
  /** Algorithm: **/
  /** Call the AU's Initialize method **/
  OSStatus err = AudioUnitInitialize(m_plugin);
  if(err != noErr)
  {
    debug(LOG_ERROR, "Could not initialize plugin");
    return false;
  }
  
  /** Set up output buffers **/
  m_buffer_list = (AudioBufferList *)malloc(offsetof(AudioBufferList, mBuffers[MAX_CHANNELS]));
  m_buffer_list->mNumberBuffers = MAX_CHANNELS;
  
  /** Connect input properties **/
  AURenderCallbackStruct callback;
  callback.inputProc = this->inputCallback;
  callback.inputProcRefCon = this;
  
  /** Set up render notifications **/
  err = AudioUnitSetProperty(m_plugin, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
                             0, &callback, sizeof(callback));
  if(err != noErr)
  {
    debug(LOG_WARN, "Could not configure inputs");
  }
  
  err = AudioUnitAddRenderNotify(m_plugin, this->renderNotify, NULL);
  if(err != noErr)
  {
    debug(LOG_ERROR, "Could not set up render notification");
  }
  
  debug(LOG_INFO, "AU initialized");
  return true;
}