X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=snd_coreaudio.c;h=246cff1d5f1a51e18c1569bc3088024954c8442e;hb=8d8fea1106dfc80248ccf0c7a4e8ad99dc5f6d97;hp=669b82f180adb9ae9257f6ecd195653552124664;hpb=eacf9e2321a57816ae32e33a7f9b014af53d4997;p=xonotic%2Fdarkplaces.git diff --git a/snd_coreaudio.c b/snd_coreaudio.c index 669b82f1..246cff1d 100644 --- a/snd_coreaudio.c +++ b/snd_coreaudio.c @@ -57,7 +57,7 @@ static OSStatus audioDeviceIOProc(AudioDeviceID inDevice, outBuffer = (float*)outOutputData->mBuffers[0].mData; factor = snd_renderbuffer->format.channels * snd_renderbuffer->format.width; frameCount = 0; - + // Lock the snd_renderbuffer if (SndSys_LockRenderBuffer()) { @@ -82,7 +82,7 @@ static OSStatus audioDeviceIOProc(AudioDeviceID inDevice, samples = (const short*)(&snd_renderbuffer->ring[startOffset * factor]); for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) outBuffer[sampleIndex] = samples[sampleIndex] * scale; - + outBuffer = &outBuffer[sampleCount]; sampleCount = frameCount * snd_renderbuffer->format.channels - sampleCount; samples = (const short*)(&snd_renderbuffer->ring[0]); @@ -107,9 +107,10 @@ static OSStatus audioDeviceIOProc(AudioDeviceID inDevice, if (frameCount < submissionChunk) { unsigned int missingFrames; - + missingFrames = submissionChunk - frameCount; - Con_DPrintf("audioDeviceIOProc: %u sample frames missing\n", missingFrames); + if (developer.integer >= 1000 && vid_activewindow) + Con_Printf("audioDeviceIOProc: %u sample frames missing\n", missingFrames); memset(&outBuffer[frameCount * snd_renderbuffer->format.channels], 0, missingFrames * sizeof(outBuffer[0])); } @@ -136,20 +137,18 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) return true; Con_Printf("Initializing CoreAudio...\n"); - - // We only accept 16-bit samples for the moment - if (requested->width != 2) + + if(requested->width != 2) { - // Suggest a 16-bit format instead - if (suggested != NULL) + // we can only do 16bit per sample for now + if(suggested != NULL) { - memcpy (suggested, requested, sizeof (suggested)); + memcpy (suggested, requested, sizeof (*suggested)); suggested->width = 2; } - return false; } - + // Get the output device propertySize = sizeof(outputDeviceID); status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &propertySize, &outputDeviceID); @@ -199,6 +198,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) Con_Printf("CoreAudio: AudioDeviceGetProperty() returned %d when getting kAudioDevicePropertyStreamFormat\n", status); return false; } + Con_DPrint (" Hardware format:\n"); Con_DPrintf(" %5d mSampleRate\n", (unsigned int)streamDesc.mSampleRate); Con_DPrintf(" %c%c%c%c mFormatID\n", @@ -212,6 +212,18 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) Con_DPrintf(" %5d mChannelsPerFrame\n", streamDesc.mChannelsPerFrame); Con_DPrintf(" %5d mBitsPerChannel\n", streamDesc.mBitsPerChannel); + // Suggest proper settings if they differ + if (requested->channels != streamDesc.mChannelsPerFrame || requested->speed != streamDesc.mSampleRate) + { + if (suggested != NULL) + { + memcpy (suggested, requested, sizeof (*suggested)); + suggested->channels = streamDesc.mChannelsPerFrame; + suggested->speed = streamDesc.mSampleRate; + } + return false; + } + if(streamDesc.mFormatID != kAudioFormatLinearPCM) { Con_Print("CoreAudio: Default audio device doesn't support linear PCM!\n"); @@ -275,7 +287,7 @@ void SndSys_Shutdown(void) return; } s_isRunning = false; - + pthread_mutex_destroy(&coreaudio_mutex); status = AudioDeviceRemoveIOProc(outputDeviceID, audioDeviceIOProc);