- Con_Printf("CoreAudio: AudioDeviceStart() returned %d\n", status);
- pthread_mutex_destroy(&coreaudio_mutex);
- AudioDeviceRemoveIOProc(outputDeviceID, audioDeviceIOProc);
- return false;
+ // Add the callback function
+ status = AudioDeviceAddIOProc(outputDeviceID, audioDeviceIOProc, NULL);
+ if (!status)
+ {
+ // We haven't sent any sample frames yet
+ coreaudiotime = 0;
+ if (pthread_mutex_init(&coreaudio_mutex, NULL) == 0)
+ {
+ if ((snd_renderbuffer = Snd_CreateRingBuffer(requested, 0, NULL)))
+ {
+ if ((mixbuffer = Mem_Alloc(snd_mempool, CHUNK_SIZE * sizeof(*mixbuffer) * requested->channels)))
+ {
+ // Start sound running
+ status = AudioDeviceStart(outputDeviceID, audioDeviceIOProc);
+ if (!status)
+ {
+ s_isRunning = true;
+ snd_threaded = true;
+ Con_Print(" Initialization successful\n");
+ return true;
+ }
+ else
+ Con_Printf("CoreAudio: AudioDeviceStart() returned %d\n", (int)status);
+ Mem_Free(mixbuffer);
+ mixbuffer = NULL;
+ }
+ else
+ Con_Print("CoreAudio: can't allocate memory for mixbuffer\n");
+ Mem_Free(snd_renderbuffer->ring);
+ Mem_Free(snd_renderbuffer);
+ snd_renderbuffer = NULL;
+ }
+ else
+ Con_Print("CoreAudio: can't allocate memory for ringbuffer\n");
+ pthread_mutex_destroy(&coreaudio_mutex);
+ }
+ else
+ Con_Print("CoreAudio: can't create pthread mutex\n");
+ AudioDeviceRemoveIOProc(outputDeviceID, audioDeviceIOProc);
+ }
+ else
+ Con_Printf("CoreAudio: AudioDeviceAddIOProc() returned %d\n", (int)status);