void AudioDestinationMac::start() { OSStatus result = AudioOutputUnitStart(m_outputUnit); if (!result) m_isPlaying = true; // LabSound result = AudioOutputUnitStart(m_input->m_inputUnit); }
static void ca_start_capture(ALCdevice *device) { ca_data *data = (ca_data*)device->ExtraData; OSStatus err = AudioOutputUnitStart(data->audioUnit); if(err != noErr) ERR("AudioOutputUnitStart failed\n"); }
Error AudioDriverIphone::init() { active = false; channels = 2; AudioStreamBasicDescription strdesc; strdesc.mFormatID = kAudioFormatLinearPCM; strdesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; strdesc.mChannelsPerFrame = channels; strdesc.mSampleRate = 44100; strdesc.mFramesPerPacket = 1; strdesc.mBitsPerChannel = 16; strdesc.mBytesPerFrame = strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; strdesc.mBytesPerPacket = strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; OSStatus result = noErr; AURenderCallbackStruct callback; AudioComponentDescription desc; AudioComponent comp = NULL; const AudioUnitElement output_bus = 0; const AudioUnitElement bus = output_bus; const AudioUnitScope scope = kAudioUnitScope_Input; zeromem(&desc, sizeof(desc)); desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_RemoteIO; /* !!! FIXME: ? */ comp = AudioComponentFindNext(NULL, &desc); desc.componentManufacturer = kAudioUnitManufacturer_Apple; result = AudioComponentInstanceNew(comp, &audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); ERR_FAIL_COND_V(comp == NULL, FAILED); result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, scope, bus, &strdesc, sizeof(strdesc)); ERR_FAIL_COND_V(result != noErr, FAILED); zeromem(&callback, sizeof(AURenderCallbackStruct)); callback.inputProc = &AudioDriverIphone::output_callback; callback.inputProcRefCon = this; result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, scope, bus, &callback, sizeof(callback)); ERR_FAIL_COND_V(result != noErr, FAILED); result = AudioUnitInitialize(audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); result = AudioOutputUnitStart(audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); const int samples = 1024; samples_in = memnew_arr(int32_t, samples); // whatever buffer_frames = samples / channels; return FAILED; };
/* interruption listeners */ void audio_unit_interruption_listener(void *closure, UInt32 inInterruptionState) { OSStatus err = 0; aubio_audio_unit_t *o = (aubio_audio_unit_t *) closure; AudioUnit this_unit = o->audio_unit; if (inInterruptionState == kAudioSessionEndInterruption) { AUBIO_WRN("audio_unit: session interruption ended\n"); err = AudioSessionSetActive(true); if (err) { AUBIO_ERR("audio_unit: could not make session active after interruption (%d)\n", (int)err); goto fail; } err = AudioOutputUnitStart(this_unit); if (err) { AUBIO_ERR("audio_unit: failed starting unit (%d)\n", (int)err); goto fail; } } if (inInterruptionState == kAudioSessionBeginInterruption) { AUBIO_WRN("audio_unit: session interruption started\n"); err = AudioOutputUnitStop(this_unit); if (err) { AUBIO_ERR("audio_unit: could not stop unit at interruption (%d)\n", (int)err); goto fail; } err = AudioSessionSetActive(false); if (err) { AUBIO_ERR("audio_unit: could not make session inactive after interruption (%d)\n", (int)err); goto fail; } } fail: return; }
void AudioDestinationMac::start() { OSStatus result = AudioOutputUnitStart(m_outputUnit); if (!result) setIsPlaying(true); }
int main (int argc, const char * argv[]) { MyAUGraphPlayer player = {0}; // create the input unit CreateInputUnit(&player); // build a graph with output unit CreateMyAUGraph(&player); #ifdef PART_II // configure the speech synthesizer PrepareSpeechAU(&player); #endif // start playing CheckError (AudioOutputUnitStart(player.inputUnit), "AudioOutputUnitStart failed"); CheckError(AUGraphStart(player.graph), "AUGraphStart failed"); // and wait printf("Capturing, press <return> to stop:\n"); getchar(); cleanup: AUGraphStop (player.graph); AUGraphUninitialize (player.graph); AUGraphClose(player.graph); }
int CoreAudioDrv_PCM_BeginPlayback(char *BufferStart, int BufferSize, int NumDivisions, void ( *CallBackFunc )( void ) ) { if (!Initialised) { ErrorCode = CAErr_Uninitialised; return CAErr_Error; } if (Playing) { CoreAudioDrv_PCM_StopPlayback(); } MixBuffer = BufferStart; MixBufferSize = BufferSize; MixBufferCount = NumDivisions; MixBufferCurrent = 0; MixBufferUsed = 0; MixCallBack = CallBackFunc; // prime the buffer MixCallBack(); AudioOutputUnitStart(output_audio_unit); Playing = 1; return CAErr_Ok; }
int sa_stream_resume(sa_stream_t *s) { if (s == NULL || s->output_unit == NULL) { return SA_ERROR_NO_INIT; } pthread_mutex_lock(&s->mutex); /* * The audio device resets its mSampleTime counter after pausing, * so we need to clear our tracking value to keep that in sync. */ s->total_bytes_played += s->bytes_played; s->bytes_played = 0; pthread_mutex_unlock(&s->mutex); /* * Don't hold the mutex when starting the audio device, because it is * possible to deadlock with this thread holding mutex then waiting on an * internal Core Audio lock, and with the callback thread holding the Core * Audio lock and waiting on the mutex. */ if (AudioOutputUnitStart(s->output_unit) != 0) { return SA_ERROR_SYSTEM; } s->playing = TRUE; return SA_SUCCESS; }
static int audiounits_start(void *usr) { au_instance_t *ap = (au_instance_t*) usr; OSStatus err; if (ap->kind == AI_RECORDER) { #if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5) err = AudioDeviceStart(ap->inDev, ap->inIOProcID); #else err = AudioDeviceStart(ap->inDev, inputRenderProc); #endif if (err) Rf_error("unable to start recording (%08x)", err); } else { AURenderCallbackStruct renderCallback = { outputRenderProc, usr }; ap->done = NO; /* set format */ ap->fmtOut.mSampleRate = ap->sample_rate; err = AudioUnitSetProperty(ap->outUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &ap->fmtOut, sizeof(ap->fmtOut)); if (err) Rf_error("unable to set output audio format (%08x)", err); /* set callback */ err = AudioUnitSetProperty(ap->outUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(renderCallback)); if (err) Rf_error("unable to register audio callback (%08x)", err); /* start audio */ err = AudioOutputUnitStart(ap->outUnit); if (err) Rf_error("unable to start playback (%08x)", err); } return 1; }
static int write_coreaudio(audio_output_t *ao, unsigned char *buf, int len) { mpg123_coreaudio_t* ca = (mpg123_coreaudio_t*)ao->userptr; int written; /* If there is no room, then sleep for half the length of the FIFO */ while (sfifo_space( &ca->fifo ) < len ) { usleep( (FIFO_DURATION/2) * 1000000 ); } /* Store converted audio in ring buffer */ written = sfifo_write( &ca->fifo, (char*)buf, len); if (written != len) { warning( "Failed to write audio to ring buffer" ); return -1; } /* Start playback now that we have something to play */ if(!ca->play) { if(AudioOutputUnitStart(ca->outputUnit)) { error("AudioOutputUnitStart failed"); return(-1); } ca->play = 1; } return len; }
static void ca_start_w(CAData *d){ OSStatus err= noErr; if (d->write_started==FALSE){ AudioStreamBasicDescription inASBD; int i; i = ca_open_w(d); if (i<0) return; inASBD = d->caOutASBD; inASBD.mSampleRate = d->rate; inASBD.mFormatID = kAudioFormatLinearPCM; inASBD.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; if (htonl(0x1234) == 0x1234) inASBD.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; inASBD.mChannelsPerFrame = d->stereo ? 2 : 1; inASBD.mBytesPerPacket = (d->bits / 8) * inASBD.mChannelsPerFrame; inASBD.mBytesPerFrame = (d->bits / 8) * inASBD.mChannelsPerFrame; inASBD.mFramesPerPacket = 1; inASBD.mBitsPerChannel = d->bits; err = AudioConverterNew( &inASBD, &d->caOutASBD, &d->caOutConverter); if(err != noErr) ms_error("AudioConverterNew %x %d", err, inASBD.mBytesPerFrame); else CAShow(d->caOutConverter); if (inASBD.mChannelsPerFrame == 1 && d->caOutASBD.mChannelsPerFrame == 2) { if (d->caOutConverter) { // This should be as large as the number of output channels, // each element specifies which input channel's data is routed to that output channel SInt32 channelMap[] = { 0, 0 }; err = AudioConverterSetProperty(d->caOutConverter, kAudioConverterChannelMap, 2*sizeof(SInt32), channelMap); } } memset((char*)&d->caOutRenderCallback, 0, sizeof(AURenderCallbackStruct)); d->caOutRenderCallback.inputProc = writeRenderProc; d->caOutRenderCallback.inputProcRefCon = d; err = AudioUnitSetProperty (d->caOutAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &d->caOutRenderCallback, sizeof(AURenderCallbackStruct)); if(err != noErr) ms_error("AudioUnitSetProperty %x", err); if(err == noErr) { if(AudioOutputUnitStart(d->caOutAudioUnit) == noErr) d->write_started=TRUE; } } }
static bool coreaudio_start(void *data) { coreaudio_t *dev = (coreaudio_t*)data; if (!dev) return false; dev->is_paused = (AudioOutputUnitStart(dev->dev) == noErr) ? false : true; return dev->is_paused ? false : true; }
void AudioLoopImplCocoa::start() { if (initialized) { OSStatus err = AudioOutputUnitStart(audioUnit); if (err) printf("AudioOutputUnitStart ERROR: %d\n", (int)err); } }
// ---------------------------------------------------------- bool ofxAudioUnitInput::start() // ---------------------------------------------------------- { if(!_impl->isReady) _impl->isReady = configureInputDevice(); if(!_impl->isReady) return false; OFXAU_RET_BOOL(AudioOutputUnitStart(*_unit), "starting hardware input unit"); }
/* * Start Audio. * When you're ready to start your audio flowing, call this beast of a function. */ int MUEAudioIO::startIO() { OSStatus err = AudioOutputUnitStart(rioUnit); if(err) printf("MUEAudioIO::startIO: Couldn't start audio unit\n"); return 0; }
int ao_plugin_play(ao_device *device, const char *output_samples, uint_32 num_bytes) { ao_macosx_internal *internal = (ao_macosx_internal *) device->internal; int err; unsigned int bytesToCopy; unsigned int firstEmptyByteOffset, emptyByteCount; while (num_bytes) { // Get a consistent set of data about the available space in the queue, // figure out the maximum number of bytes we can copy in this chunk, // and claim that amount of space pthread_mutex_lock(&mutex); // Wait until there is some empty space in the queue emptyByteCount = internal->bufferByteCount - internal->validByteCount; while (emptyByteCount == 0) { if(!internal->started){ err = AudioOutputUnitStart(internal->outputAudioUnit); adebug("Starting audio output unit\n"); if(err){ pthread_mutex_unlock(&mutex); aerror("Failed to start audio output => %d\n",(int)err); return 0; } internal->started = true; } err = pthread_cond_wait(&cond, &mutex); if (err) adebug("pthread_cond_wait() => %d\n",err); emptyByteCount = internal->bufferByteCount - internal->validByteCount; } // Compute the offset to the first empty byte and the maximum number of // bytes we can copy given the fact that the empty space might wrap // around the end of the queue. firstEmptyByteOffset = (internal->firstValidByteOffset + internal->validByteCount) % internal->bufferByteCount; if (firstEmptyByteOffset + emptyByteCount > internal->bufferByteCount) bytesToCopy = MIN(num_bytes, internal->bufferByteCount - firstEmptyByteOffset); else bytesToCopy = MIN(num_bytes, emptyByteCount); // Copy the bytes and get ready for the next chunk, if any memcpy(internal->buffer + firstEmptyByteOffset, output_samples, bytesToCopy); num_bytes -= bytesToCopy; output_samples += bytesToCopy; internal->validByteCount += bytesToCopy; pthread_mutex_unlock(&mutex); } return 1; }
static void resume_coreaudio(audio_output_t *ao) { mpg123_coreaudio_t* ca = (mpg123_coreaudio_t*)ao->userptr; if (!ca->play) { AudioOutputUnitStart(ca->outputUnit); ca->play = 1; } }
Error AudioDriverCoreAudio::capture_start() { OSStatus result = AudioOutputUnitStart(input_unit); if (result != noErr) { ERR_PRINTS("AudioOutputUnitStart failed, code: " + itos(result)); } return OK; }
void CoreAudioOutput::start() { this->clearBuffer(); OSSpinLockLock(this->_spinlockAU); AudioUnitReset(this->_au, kAudioUnitScope_Global, 0); AudioOutputUnitStart(this->_au); OSSpinLockUnlock(this->_spinlockAU); }
static int audiounit_stream_start(cubeb_stream * stm) { OSStatus r; r = AudioOutputUnitStart(stm->unit); assert(r == 0); stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STARTED); return CUBEB_OK; }
// ---------------------------------------------------------- bool ofxAudioUnitOutput::start(int deviceID) // ---------------------------------------------------------- { cout<<"ofxAudioUnitOutput::start() "<<deviceID<<endl; if(!_isReady) _isReady = configureOutputDevice(deviceID); if(!_isReady) return false; OFXAU_RET_BOOL(AudioOutputUnitStart(*_unit), "starting output unit"); }
bool CCoreAudioUnit::Start() { if (!m_audioUnit) return false; AudioOutputUnitStart(m_audioUnit); return true; }
void AudioDriverCoreAudio::start() { if (!active) { OSStatus result = AudioOutputUnitStart(audio_unit); if (result != noErr) { ERR_PRINT(("AudioOutputUnitStart failed, code: " + itos(result)).utf8().get_data()); } else { active = true; } } };
int CoreAudioDriver::connect() { OSStatus err; err = AudioOutputUnitStart( m_outputUnit ); if ( err != noErr ) { ERRORLOG( "Could not start AudioUnit" ); } m_bIsRunning = true; return 0; }
static int coreaudio_unpause(void) { trace("coreaudio_unpause\n"); OSStatus err = AudioOutputUnitStart (output_unit); if (err) { trace ("AudioOutputUnitStart= %s\n", GetMacOSStatusErrorString(err)); return -1; } state = OUTPUT_STATE_PLAYING; return 0; }
void AudioDestinationIOS::start() { LOG(Media, "AudioDestinationIOS::start"); if (!m_mediaSession->clientWillBeginPlayback()) { LOG(Media, " returning because of interruption"); return; } OSStatus result = AudioOutputUnitStart(m_outputUnit); if (!result) m_isPlaying = true; }
sint_t aubio_audio_unit_start(aubio_audio_unit_t *o) { OSStatus err = 0; if (o->verbose) { // print some info about the current settings aubio_audio_unit_get_info (o); } /* time to start the unit */ err = AudioOutputUnitStart (o->audio_unit); if (err) { AUBIO_ERR("audio_unit: could not start unit (%d)\n", (int)err); } return err; }
void InputImplAudioUnit::start() { if( mIsCapturing ) return; setup(); OSStatus err = AudioOutputUnitStart( mInputUnit ); if( err != noErr ) { std::cout << "Error starting input unit" << std::endl; throw; } mIsCapturing = true; }
static ALCboolean ca_start_playback(ALCdevice *device) { ca_data *data = (ca_data*)device->ExtraData; OSStatus err; err = AudioOutputUnitStart(data->audioUnit); if(err != noErr) { ERR("AudioOutputUnitStart failed\n"); return ALC_FALSE; } return ALC_TRUE; }
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; }