/*auStart-------------------------------------------------*/ BOOL auPlay(Audio* self) { if(!self->isPlaying) { #ifdef __APPLE__ int i; for(i=0; i<AU_NUM_AUDIO_BUFFERS; i++) { if(self->isOutput) auAudioOutputCallback(self, self->queue, self->buffers[i]); else AudioQueueEnqueueBuffer(self->queue, self->buffers[i],0, NULL); } OSStatus error = AudioQueueStart(self->queue, NULL); if(error) fprintf(stderr, "Audio.c: unable to start queue\n"); #elif defined __linux__ int error = pthread_create(&(self->thread), NULL, auAudioCallback, self); if(error != 0) perror("Audio.c: error creating Audio thread"); #endif else self->isPlaying = YES; } return self->isPlaying; }
void seekToPacket(uint64_t packet) { AudioQueueStop(aqData.mQueue, true); aqData.mCurrentPacket = rand()%1000; primeBuffer(); AudioQueueStart(aqData.mQueue, NULL); }
void CL_SoundOutput_MacOSX::mixer_thread_starting() { audio_format.mSampleRate = frequency; audio_format.mFormatID = kAudioFormatLinearPCM; audio_format.mFormatFlags = kAudioFormatFlagsCanonical; audio_format.mBytesPerPacket = 2 * sizeof(short); audio_format.mFramesPerPacket = 1; audio_format.mBytesPerFrame = 2 * sizeof(short); audio_format.mChannelsPerFrame = 2; audio_format.mBitsPerChannel = sizeof(short) * 8; audio_format.mReserved = 0; OSStatus result = AudioQueueNewOutput(&audio_format, &CL_SoundOutput_MacOSX::static_audio_queue_callback, this, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &audio_queue); if (result != 0) throw CL_Exception("AudioQueueNewOutput failed"); for (int i = 0; i < fragment_buffer_count; i++) { result = AudioQueueAllocateBuffer(audio_queue, fragment_size * sizeof(short) * 2, &audio_buffers[i]); if (result != 0) throw CL_Exception("AudioQueueAllocateBuffer failed"); audio_queue_callback(audio_queue, audio_buffers[i]); } result = AudioQueueStart(audio_queue, 0); if (result != 0) throw CL_Exception("AudioQueueStart failed"); }
void Moose::Sound::CMusicClip::Play() { if ( IsPaused()) { m_bPaused = false; pthread_mutex_lock(&m_pData->mutex); AudioQueueStart(m_pData->audioQueue, NULL); pthread_mutex_unlock(&m_pData->mutex); } else { if ( IsRunning()) Stop(); if ( m_bHasThread ) { void *status; pthread_join(m_thread, &status); m_bHasThread = false; } OSStatus err = pthread_create( &m_thread, NULL, audio_decode_play_proc, this); if ( err ) { g_Error << "Could not create thread for music clip, error: " << err << endl; } } }
bool QueueAudioData::start() { printf("QueueAudioData::start()\n"); AudioQueueStart(audioQueue, 0); running = true; return true; }
void play() { int i; AudioStreamBasicDescription format; AudioQueueRef queue; AudioQueueBufferRef buffers[NUM_BUFFERS]; format.mSampleRate = SAMPLE_RATE; format.mFormatID = kAudioFormatLinearPCM; format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; format.mBitsPerChannel = 8*sizeof(SAMPLE_TYPE); format.mChannelsPerFrame = NUM_CHANNELS; format.mBytesPerFrame = sizeof(SAMPLE_TYPE)*NUM_CHANNELS; format.mFramesPerPacket = 1; format.mBytesPerPacket = format.mBytesPerFrame*format.mFramesPerPacket; format.mReserved = 0; AudioQueueNewOutput(&format, callback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &queue); for (i = 0; i < NUM_BUFFERS; i++) { AudioQueueAllocateBuffer(queue, BUFFER_SIZE, &buffers[i]); buffers[i]->mAudioDataByteSize = BUFFER_SIZE; callback(NULL, queue, buffers[i]); } AudioQueueStart(queue, NULL); CFRunLoopRun(); }
void play() { OSStatus status; aqData.mIsRunning = true; // 1 aqData.mCurrentPacket = 0; // 1 primeBuffer(); Float32 gain = 1.0; // 1 // Optionally, allow user to override gain setting here status = AudioQueueSetParameter ( // 2 aqData.mQueue, // 3 kAudioQueueParam_Volume, // 4 gain // 5 ); checkStatus(status); status = AudioQueueStart ( // 2 aqData.mQueue, // 3 NULL // 4 ); checkStatus(status); }
void IPhoneSoundDevice::Enable(bool fEnable) { base::CritScope cs(&m_crit); if (fEnable) { if (!m_fEnable) { memset(m_achnl, 0, sizeof(m_achnl)); m_tSilence = 0; m_fEnable = true; for (int i = 0; i < kcBuffers; i++) { InitAudioBuffer(m_apaqb[i]); } AudioQueuePrime(m_haq, 0, NULL); AudioQueueStart(m_haq, NULL); SetSoundServiceDevice(this); } } else { if (m_fEnable) { m_fEnable = false; memset(m_achnl, 0, sizeof(m_achnl)); m_tSilence = 0; AudioQueueStop(m_haq, false); SetSoundServiceDevice(NULL); } } }
int32_t setup_queue( ALACMagicCookie cookie, PlayerInfo *playerInfo, uint32_t buffer_size, uint32_t num_buffers, uint32_t num_packets ) { // Create Audio Queue for ALAC AudioStreamBasicDescription inFormat = {0}; inFormat.mSampleRate = ntohl(cookie.sampleRate); inFormat.mFormatID = kAudioFormatAppleLossless; inFormat.mFormatFlags = 0; // ALAC uses no flags inFormat.mBytesPerPacket = 0; // Variable size (must use AudioStreamPacketDescription) inFormat.mFramesPerPacket = ntohl(cookie.frameLength); inFormat.mBytesPerFrame = 0; // Compressed inFormat.mChannelsPerFrame = 2; // Stero TODO: get from fmtp? inFormat.mBitsPerChannel = 0; // Compressed inFormat.mReserved = 0; OSStatus err = AudioQueueNewOutput( &inFormat, c_callback, playerInfo, // User data NULL, // Run on audio queue's thread NULL, // Callback run loop's mode 0, // Reserved &playerInfo->queue); if (err) return err; // Need to set the magic cookie too (tail fmtp) err = AudioQueueSetProperty(playerInfo->queue, kAudioQueueProperty_MagicCookie, &cookie, sizeof(ALACMagicCookie)); if (err) return err; // Create input buffers, and enqueue using callback for (int i = 0; i < num_buffers; i++) { AudioQueueBufferRef buffer; err = AudioQueueAllocateBufferWithPacketDescriptions( playerInfo->queue, buffer_size, num_packets, &buffer); if (err) return err; c_callback(playerInfo, playerInfo->queue, buffer); } // Volume full err = AudioQueueSetParameter(playerInfo->queue, kAudioQueueParam_Volume, 1.0); if (err) return err; // Prime err = AudioQueuePrime(playerInfo->queue, 0, NULL); if (err) return err; // Start err = AudioQueueStart(playerInfo->queue, NULL); if (err) return err; return 0; }
static int Open ( vlc_object_t *p_this ) { audio_output_t *p_aout = (audio_output_t *)p_this; struct aout_sys_t *p_sys = malloc(sizeof(aout_sys_t)); p_aout->sys = p_sys; OSStatus status = 0; // Setup the audio device. AudioStreamBasicDescription deviceFormat; deviceFormat.mSampleRate = 44100; deviceFormat.mFormatID = kAudioFormatLinearPCM; deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; // Signed integer, little endian deviceFormat.mBytesPerPacket = 4; deviceFormat.mFramesPerPacket = 1; deviceFormat.mBytesPerFrame = 4; deviceFormat.mChannelsPerFrame = 2; deviceFormat.mBitsPerChannel = 16; deviceFormat.mReserved = 0; // Create a new output AudioQueue for the device. status = AudioQueueNewOutput(&deviceFormat, // Format AudioQueueCallback, // Callback p_aout, // User data, passed to the callback CFRunLoopGetMain(), // RunLoop kCFRunLoopDefaultMode, // RunLoop mode 0, // Flags ; must be zero (per documentation)... &(p_sys->audioQueue)); // Output // This will be used for boosting the audio without the need of a mixer (floating-point conversion is expensive on ARM) // AudioQueueSetParameter(p_sys->audioQueue, kAudioQueueParam_Volume, 12.0); // Defaults to 1.0 msg_Dbg(p_aout, "New AudioQueue output created (status = %i)", status); // Allocate buffers for the AudioQueue, and pre-fill them. for (int i = 0; i < NUMBER_OF_BUFFERS; ++i) { AudioQueueBufferRef buffer = NULL; status = AudioQueueAllocateBuffer(p_sys->audioQueue, FRAME_SIZE * 4, &buffer); AudioQueueCallback(NULL, p_sys->audioQueue, buffer); } /* Volume is entirely done in software. */ aout_SoftVolumeInit( p_aout ); p_aout->format.i_format = VLC_CODEC_S16L; p_aout->format.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; p_aout->format.i_rate = 44100; aout_PacketInit(p_aout, &p_sys->packet, FRAME_SIZE); p_aout->pf_play = aout_PacketPlay; p_aout->pf_pause = aout_PacketPause; p_aout->pf_flush = aout_PacketFlush; msg_Dbg(p_aout, "Starting AudioQueue (status = %i)", status); status = AudioQueueStart(p_sys->audioQueue, NULL); return VLC_SUCCESS; }
int app_OpenSound(int samples_per_sync, int sample_rate) { Float64 sampleRate = 44100.0; int i; LOGDEBUG("app_SoundOpen()"); app_MuteSound(); if(preferences.muted) { return 0; } soundInit = 0; in.mDataFormat.mSampleRate = sampleRate; in.mDataFormat.mFormatID = kAudioFormatLinearPCM; in.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; in.mDataFormat.mBytesPerPacket = 4; in.mDataFormat.mFramesPerPacket = 1; in.mDataFormat.mBytesPerFrame = 2; in.mDataFormat.mChannelsPerFrame = 2; in.mDataFormat.mBitsPerChannel = 16; /* Pre-buffer before we turn on audio */ UInt32 err; err = AudioQueueNewOutput(&in.mDataFormat, AQBufferCallback, &in, NULL, kCFRunLoopCommonModes, 0, &in.queue); if (err) { LOGDEBUG("AudioQueueNewOutput err %d\n", err); } in.frameCount = 512 * 1; //512; //(1024 * (16)) / 4; UInt32 bufferBytes = in.frameCount * in.mDataFormat.mBytesPerFrame; for (i=0; i<AUDIO_BUFFERS; i++) { err = AudioQueueAllocateBuffer(in.queue, bufferBytes, &in.mBuffers[i]); if (err) { LOGDEBUG("AudioQueueAllocateBuffer[%d] err %d\n",i, err); } /* "Prime" by calling the callback once per buffer */ AQBufferCallback (&in, in.queue, in.mBuffers[i]); } soundInit = 1; LOGDEBUG("app_QueueSample.AudioQueueStart"); err = AudioQueueStart(in.queue, NULL); return 0; }
OSStatus Start() { OSStatus result = AudioQueuePrime(mQueue, 1, NULL); if (result) { printf("Error priming queue"); return result; } return AudioQueueStart(mQueue, NULL); }
OSStatus StartQueueIfNeeded(struct audioPlayer* player) { OSStatus err = noErr; if (!player->started) { // start the queue if it has not been started already err = AudioQueueStart(player->audioQueue, NULL); if (err) { PRINTERROR("AudioQueueStart"); player->failed = true; return err; } player->started = true; } return err; }
void audio_start(audio_player_t *player) { state_t *state = (state_t *) player->internal_state; if (noErr != AudioQueueStart(state->queue, NULL)) puts("AudioQueueStart failed"); state->playing = true; if (state->running) { if (player->on_start) { player->on_start(player); } } }
OSStatus StartQueueIfNeeded(MyData* myData) { OSStatus err = noErr; if (!myData->started) { // start the queue if it has not been started already err = AudioQueueStart(myData->audioQueue, NULL); if (err) { PRINTERROR("AudioQueueStart"); myData->failed = true; return err; } myData->started = true; printf("started\n"); } return err; }
void Audio_Queue::pause() { if (m_state == RUNNING) { if (AudioQueuePause(m_outAQ) != 0) { AQ_TRACE("Audio_Queue::pause(): AudioQueuePause failed!\n"); } setState(PAUSED); } else if (m_state == PAUSED) { AudioQueueStart(m_outAQ, NULL); setState(RUNNING); } }
void CAudioQueueManager::resume() { if (_isRunning) return; if (!_isInitialized) { _autoStart = true; return; } AudioQueueStart(_queue, NULL); _isRunning = true; }
long AudioStreamDecoder::EnqueueBuffer() { bool locked = false; if (mFinished) return 0; long err = AudioQueueEnqueueBuffer(mQueue, *mCurrentBuffer, 0, NULL); BAIL_IF(err, "AudioQueueEnqueueBuffer returned %ld\n", err); if (++mCurrentBuffer == mBuffers + kBufferCount) mCurrentBuffer = mBuffers; if (!mStarted && !mFinished) { mStarted = true; err = AudioQueueStart(mQueue, NULL); BAIL_IF(err, "AudioQueueStart returned %ld\n", err); } err = pthread_mutex_lock(&mMutex); BAIL_IF(err, "pthread_mutex_lock returned %ld\n", err); locked = true; while ((*mCurrentBuffer)->mUserData && !mFinished) { err = pthread_cond_wait(&mCond, &mMutex); BAIL_IF(err, "pthread_cond_wait returned %ld\n", err); } (*mCurrentBuffer)->mUserData = this; (*mCurrentBuffer)->mAudioDataByteSize = 0; (*mCurrentBuffer)->mPacketDescriptionCount = 0; bail: long err2; if (locked) { err2 = pthread_mutex_unlock(&mMutex); CARP_IF(err2, "pthread_mutex_unlock returned %ld\n", err2); } if (err && mStarted) { err2 = SetFinished(); CARP_IF(err2, "SetFinished returned %ld\n", err2); } return err; }
void Audio_Queue::startQueueIfNeeded() { if (!m_audioQueueStarted) { // start the queue if it has not been started already OSStatus err = AudioQueueStart(m_outAQ, NULL); if (!err) { m_audioQueueStarted = true; m_lastError = noErr; } else { m_lastError = err; } } }
/** * Entry point for the thread. */ int AudioOutputDeviceCoreAudio::Main() { dmsg(1,("CoreAudio thread started\n")); OSStatus res; if(aqPlayerState.mQueue == NULL) { /* * Need to be run from this thread because of CFRunLoopGetCurrent() * which returns the CFRunLoop object for the current thread. */ try { CreateAndStartAudioQueue(); } catch(Exception e) { std::cerr << "Failed to star audio queue: " + e.Message() << std::endl; return 0; } } destroyMutex.Lock(); do { if(atomic_read(&pausedNew) != pausedOld) { pausedOld = atomic_read(&pausedNew); if(pausedOld) { res = AudioQueuePause(aqPlayerState.mQueue); if(res) std::cerr << "AudioQueuePause: Error " << res << std::endl; } else { res = AudioQueuePrime(aqPlayerState.mQueue, 0, NULL); if(res) std::cerr << "AudioQueuePrime: Error " << res << std::endl; res = AudioQueueStart(aqPlayerState.mQueue, NULL); if(res) std::cerr << "AudioQueueStart: Error " << res << std::endl; } } if(atomic_read(&restartQueue)) { DestroyAudioQueue(); try { CreateAndStartAudioQueue(); } catch(Exception e) { destroyMutex.Unlock(); throw e; } atomic_set(&restartQueue, 0); dmsg(1,("Audio queue restarted")); } CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.2, false); } while (atomic_read(&(aqPlayerState.mIsRunning))); destroyMutex.Unlock(); dmsg(2,("CoreAudio thread stopped\n")); pthread_exit(NULL); return 0; }
void CAudioQueueManager::setupQueue() { OSStatus res = AudioQueueNewOutput(&_dataFormat, HandleOutputBuffer, this, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &_queue); for (int i = 0; i < kNumberBuffers; i++) { res = AudioQueueAllocateBuffer(_queue, _bytesPerFrame, &_buffers[i]); HandleOutputBuffer(this, _queue, _buffers[i]); } if (_autoStart) { _isRunning = true; res = AudioQueueStart(_queue, NULL); } _isInitialized = true; }
static void aq_put(MSFilter * f, mblk_t * m) { AQData *d = (AQData *) f->data; ms_mutex_lock(&d->mutex); ms_bufferizer_put(d->bufferizer, m); ms_mutex_unlock(&d->mutex); int len = (d->writeBufferByteSize * d->writeAudioFormat.mSampleRate / 1) / d->devicewriteFormat.mSampleRate / d->devicewriteFormat.mChannelsPerFrame; if (d->write_started == FALSE && d->bufferizer->size >= len) { AudioQueueBufferRef curbuf = d->writeBuffers[d->curWriteBuffer]; #if 0 OSStatus err; UInt32 bsize = d->writeBufferByteSize; uint8_t *pData = ms_malloc(len); ms_bufferizer_read(d->bufferizer, pData, len); err = AudioConverterConvertBuffer(d->writeAudioConverter, len, pData, &bsize, curbuf->mAudioData); if (err != noErr) { ms_error("writeCallback: AudioConverterConvertBuffer %d", err); } ms_free(pData); if (bsize != d->writeBufferByteSize) ms_warning("d->writeBufferByteSize = %i len = %i bsize = %i", d->writeBufferByteSize, len, bsize); #else ms_bufferizer_read(d->bufferizer, curbuf->mAudioData, len); #endif curbuf->mAudioDataByteSize = d->writeBufferByteSize; putWriteAQ(d, d->curWriteBuffer); ++d->curWriteBuffer; } if (d->write_started == FALSE && d->curWriteBuffer == kNumberAudioOutDataBuffers - 1) { OSStatus err; err = AudioQueueStart(d->writeQueue, NULL // start time. NULL means ASAP. ); if (err != noErr) { ms_error("AudioQueueStart -write- %d", err); } d->write_started = TRUE; } }
/** @internal @This creates a new audioqueue * @param upipe description structure of the pipe * @param flow description structure of the flow * @return an error code */ static int upipe_osx_audioqueue_sink_set_flow_def(struct upipe *upipe, struct uref *flow) { OSStatus status; uint64_t sample_rate = 0; /* hush gcc */ uint8_t channels = 0; uint8_t sample_size = 0; struct AudioStreamBasicDescription fmt; struct upipe_osx_audioqueue_sink *osx_audioqueue = upipe_osx_audioqueue_sink_from_upipe(upipe); if (unlikely(osx_audioqueue->queue)) { upipe_osx_audioqueue_sink_remove(upipe); } /* retrieve flow format information */ uref_sound_flow_get_rate(flow, &sample_rate); uref_sound_flow_get_sample_size(flow, &sample_size); uref_sound_flow_get_channels(flow, &channels); /* build format description */ memset(&fmt, 0, sizeof(struct AudioStreamBasicDescription)); fmt.mSampleRate = sample_rate; fmt.mFormatID = kAudioFormatLinearPCM; fmt.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; fmt.mFramesPerPacket = 1; fmt.mChannelsPerFrame = channels; fmt.mBytesPerPacket = fmt.mBytesPerFrame = sample_size * channels; fmt.mBitsPerChannel = sample_size * 8; /* create queue */ status = AudioQueueNewOutput(&fmt, upipe_osx_audioqueue_sink_cb, upipe, NULL, kCFRunLoopCommonModes, 0, &osx_audioqueue->queue); if (unlikely(status == kAudioFormatUnsupportedDataFormatError)) { upipe_warn(upipe, "unsupported data format"); return UBASE_ERR_EXTERNAL; } /* change volume */ AudioQueueSetParameter(osx_audioqueue->queue, kAudioQueueParam_Volume, osx_audioqueue->volume); /* start queue ! */ AudioQueueStart(osx_audioqueue->queue, NULL); upipe_notice_va(upipe, "audioqueue started (%uHz, %hhuch, %db)", sample_rate, channels, sample_size*8); return UBASE_ERR_NONE; }
int playbuffer(void *pcmbuffer, unsigned long len) { AQCallbackStruct aqc; UInt32 err, bufferSize; int i; aqc.mDataFormat.mSampleRate = SAMPLE_RATE; aqc.mDataFormat.mFormatID = kAudioFormatLinearPCM; aqc.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; aqc.mDataFormat.mBytesPerPacket = 4; aqc.mDataFormat.mFramesPerPacket = 1; aqc.mDataFormat.mBytesPerFrame = 4; aqc.mDataFormat.mChannelsPerFrame = 2; aqc.mDataFormat.mBitsPerChannel = 16; aqc.frameCount = FRAME_COUNT; aqc.sampleLen = len / BYTES_PER_SAMPLE; aqc.playPtr = 0; aqc.pcmBuffer = (sampleFrame *)pcmbuffer; err = AudioQueueNewOutput(&aqc.mDataFormat, AQBufferCallback, &aqc, NULL, kCFRunLoopCommonModes, 0, &aqc.queue); if (err) return err; aqc.frameCount = FRAME_COUNT; bufferSize = aqc.frameCount * aqc.mDataFormat.mBytesPerFrame; for (i=0; i<AUDIO_BUFFERS; i++) { err = AudioQueueAllocateBuffer(aqc.queue, bufferSize, &aqc.mBuffers[i]); if (err) return err; AQBufferCallback(&aqc, aqc.queue, aqc.mBuffers[i]); } err = AudioQueueStart(aqc.queue, NULL); if (err) return err; struct timeval tv = {1.0, 0}; while(aqc.playPtr < aqc.sampleLen) { select(0, NULL, NULL, NULL, &tv); } sleep(1); return 0; }
OSStatus DZAudioQueuePlayer::start() { if (this->_queue == NULL || this->_status == DZAudioQueuePlayerStatus_NotReady || this->_status == DZAudioQueuePlayerStatus_Error) { return dzDebug(!noErr, "Audio queue cannot start because it is not ready."); } dzDebug(AudioQueueSetParameter(this->_queue, kAudioQueueParam_Volume, 1.0), "Fail to set audio queue property: Volumn."); OSStatus ret = dzDebug(AudioQueueStart(this->_queue, NULL), "Fail to start audio queue."); if (ret == noErr) { this->_status = DZAudioQueuePlayerStatus_Running; } return ret; }
int app_OpenSound(int buffersize) { Float64 sampleRate = 22050.0; int i; UInt32 bufferBytes; soundBufferSize = buffersize; app_MuteSound(); soundInit = 0; in.mDataFormat.mSampleRate = sampleRate; in.mDataFormat.mFormatID = kAudioFormatLinearPCM; in.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; in.mDataFormat.mBytesPerPacket = 4; in.mDataFormat.mFramesPerPacket = isStereo ? 1 : 2; in.mDataFormat.mBytesPerFrame = isStereo ? 4 : 2; in.mDataFormat.mChannelsPerFrame = isStereo ? 2 : 1; in.mDataFormat.mBitsPerChannel = 16; /* Pre-buffer before we turn on audio */ UInt32 err; err = AudioQueueNewOutput(&in.mDataFormat, AQBufferCallback, NULL, NULL, kCFRunLoopCommonModes, 0, &in.queue); bufferBytes = AUDIO_BUFFER_SIZE; for (i=0; i<AUDIO_BUFFERS; i++) { err = AudioQueueAllocateBuffer(in.queue, bufferBytes, &in.mBuffers[i]); /* "Prime" by calling the callback once per buffer */ //AQBufferCallback (&in, in.queue, in.mBuffers[i]); in.mBuffers[i]->mAudioDataByteSize = AUDIO_BUFFER_SIZE; //samples_per_frame * 2; //inData->mDataFormat.mBytesPerFrame; //(inData->frameCount * 4 < (sndOutLen) ? inData->frameCount * 4 : (sndOutLen)); AudioQueueEnqueueBuffer(in.queue, in.mBuffers[i], 0, NULL); } soundInit = 1; err = AudioQueueStart(in.queue, NULL); return 0; }
int SIOpenSound(int buffersize) { SI_SoundIsInit = 0; SI_AudioOffset = 0; if(SI_AQCallbackStruct.queue != 0) AudioQueueDispose(SI_AQCallbackStruct.queue, true); SI_AQCallbackCount = 0; memset(&SI_AQCallbackStruct, 0, sizeof(AQCallbackStruct)); Float64 sampleRate = 22050.0; sampleRate = Settings.SoundPlaybackRate; SI_SoundBufferSizeBytes = buffersize; SI_AQCallbackStruct.mDataFormat.mSampleRate = sampleRate; SI_AQCallbackStruct.mDataFormat.mFormatID = kAudioFormatLinearPCM; SI_AQCallbackStruct.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; SI_AQCallbackStruct.mDataFormat.mBytesPerPacket = 4; SI_AQCallbackStruct.mDataFormat.mFramesPerPacket = SI_IsStereo ? 1 : 2; SI_AQCallbackStruct.mDataFormat.mBytesPerFrame = SI_IsStereo ? 4 : 2; SI_AQCallbackStruct.mDataFormat.mChannelsPerFrame = SI_IsStereo ? 2 : 1; SI_AQCallbackStruct.mDataFormat.mBitsPerChannel = Settings.SixteenBitSound ? 16: 8; /* Pre-buffer before we turn on audio */ UInt32 err; err = AudioQueueNewOutput(&SI_AQCallbackStruct.mDataFormat, AQBufferCallback, NULL, NULL, kCFRunLoopCommonModes, 0, &SI_AQCallbackStruct.queue); for(int i=0; i<SI_AUDIO_BUFFER_COUNT; i++) { err = AudioQueueAllocateBuffer(SI_AQCallbackStruct.queue, SI_SoundBufferSizeBytes, &SI_AQCallbackStruct.mBuffers[i]); memset(SI_AQCallbackStruct.mBuffers[i]->mAudioData, 0, SI_SoundBufferSizeBytes); SI_AQCallbackStruct.mBuffers[i]->mAudioDataByteSize = SI_SoundBufferSizeBytes; //samples_per_frame * 2; //inData->mDataFormat.mBytesPerFrame; //(inData->frameCount * 4 < (sndOutLen) ? inData->frameCount * 4 : (sndOutLen)); AudioQueueEnqueueBuffer(SI_AQCallbackStruct.queue, SI_AQCallbackStruct.mBuffers[i], 0, NULL); } SI_SoundIsInit = 1; err = AudioQueueStart(SI_AQCallbackStruct.queue, NULL); return 0; }
void Audio_Queue::start() { // start the queue if it has not been started already if (m_audioQueueStarted) { return; } OSStatus err = AudioQueueStart(m_outAQ, NULL); if (!err) { m_audioQueueStarted = true; m_lastError = noErr; } else { AQ_TRACE("%s: AudioQueueStart failed!\n", __PRETTY_FUNCTION__); m_lastError = err; } }
void GbApuEmulator::beginApuPlayback() { // Reset the APU and Buffer // gbAPU->reset(false,0); gbAPU->reset(); blipBuffer->clear(true); // Prime the playback buffer for (int i = 0; i < NUM_BUFFERS; ++i) { HandleOutputBuffer(gbAPUState, gbAPUState->queue, gbAPUState->buffers[i]); } AudioQueuePrime(gbAPUState->queue, 0, NULL); gbAPUState->isRunning = true; AudioQueueStart(gbAPUState->queue, NULL); }
void SoundRecorder::start(void) { /* Do nothing if already started: */ if(active) return; /* Reset the packet counter: */ numRecordedPackets=0; /* Set the audio file's magic cookie: */ setAudioFileMagicCookie(); /* Start recording: */ if(AudioQueueStart(queue,0)==noErr) active=true; else Misc::throwStdErr("SoundRecorder::start: Unable to start recording"); }