void MainAudio::timerEvent(QTimerEvent *) { memset(mixbuf, 0, mixlen); size_t frames = NativeMix((short *)mixbuf, AUDIO_BUFFERS*AUDIO_SAMPLES); if (frames > 0) feed->write(mixbuf, sizeof(short) * AUDIO_CHANNELS * frames); }
OSStatus iOSCoreAudioCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { // see if we have any sound to play UInt32 frames = (inNumberFrames > STREAM_MAX_FRAME_COUNT ? STREAM_MAX_FRAME_COUNT : inNumberFrames); UInt32 framesReady = NativeMix(stream, frames); if (framesReady == 0) { // oops, we don't currently have any sound, so return silence *ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence; return noErr; } // grab the output buffer and copy data into it AudioSampleType *output = (AudioSampleType *)ioData->mBuffers[0].mData; UInt32 bytesReady = framesReady * sizeof(short) * 2; memcpy(output, stream, bytesReady); // make sure and tell it how much audio data is there ioData->mBuffers[0].mDataByteSize = bytesReady; return noErr; }
void* RunAudio() { while(true) { if (!paused) { memset(mixbuf, 0, mixlen); NativeMix((short *)mixbuf, mixlen / 4); fd_set rfds, wfds; int nflds; if (!paused && (FD_ISSET(snd_pcm_file_descriptor(pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds))) { snd_pcm_plugin_write(pcm_handle, mixbuf, mixlen); } FD_ZERO(&rfds); FD_ZERO(&wfds); FD_SET(snd_mixer_file_descriptor(mixer_handle), &rfds); FD_SET(snd_pcm_file_descriptor(pcm_handle, SND_PCM_CHANNEL_PLAYBACK), &wfds); nflds = std::max(snd_mixer_file_descriptor(mixer_handle), snd_pcm_file_descriptor(pcm_handle, SND_PCM_CHANNEL_PLAYBACK)); select (nflds+1, &rfds, &wfds, NULL, NULL); } else delay((AUDIO_SAMPLES*1000)/AUDIO_FREQ); } }
// This path is not used if OpenSL ES is available. extern "C" jint Java_com_henrikrydgard_libnative_NativeApp_audioRender(JNIEnv* env, jclass clazz, jshortArray array) { // The audio thread can pretty safely enable Flush-to-Zero mode on the FPU. EnableFZ(); int buf_size = env->GetArrayLength(array); if (buf_size) { short *data = env->GetShortArrayElements(array, 0); int samples = buf_size / 2; samples = NativeMix(data, samples); if (samples != 0) { env->ReleaseShortArrayElements(array, data, 0); return samples * 2; } else { env->ReleaseShortArrayElements(array, data, JNI_ABORT); return 0; } } return 0; }
extern void mixaudio(void *userdata, Uint8 *stream, int len) { NativeMix((short *)stream, len / 4); }