History

fix macos compile errors - modernize audio api

Conrad Jones committed 7 years ago

Commit a2eb2811 parent 47bba232 files · +30 −16Browse files

Unified · Split

2 files
  1. CMakeLists.txt +3 −0
  2. examples/audio_out.c +27 −16
CMakeLists.txt+3−0
@@ -122,6 +122,9 @@ foreach(exampleSrc ${EXAMPLE_SRCS}) · 121 unmodified lines
122122 if(WIN32)
123123 target_link_libraries(${exampleName} PUBLIC winmm)
124124 endif()
125+ if (APPLE)
126+ target_link_libraries (${exampleName} PUBLIC "-framework CoreAudio")
127+ endif()
125128 endforeach(exampleSrc)
126129
127130 set(prefix ${CMAKE_INSTALL_PREFIX})
examples/audio_out.c+27−16
@@ -427,7 +427,6 @@ opensoundsys_close (AUDIO_OUT *audio_out) · 426 unmodified lines
427427
428428 #if (defined (__MACH__) && defined (__APPLE__)) /* MacOSX */
429429
430−#include <Carbon.h>
431430 #include <CoreAudio/AudioHardware.h>
432431
433432 #define MACOSX_MAGIC MAKE_MAGIC ('M', 'a', 'c', ' ', 'O', 'S', ' ', 'X')
@@ -447,6 +446,9 @@ typedef struct · 13 unmodified lines
447446 get_audio_callback_t callback ;
448447
449448 void *callback_data ;
449+
450+ AudioDeviceIOProcID ioprocid;
451+
450452 } MACOSX_AUDIO_OUT ;
451453
452454 static AUDIO_OUT *macosx_open (int channels, int samplerate) ;
@@ -463,7 +465,8 @@ static AUDIO_OUT * · 10 unmodified lines
463465 macosx_open (int channels, int samplerate)
464466 { MACOSX_AUDIO_OUT *macosx_out ;
465467 OSStatus err ;
466− size_t count ;
468+ UInt32 count ;
469+ AudioObjectPropertyAddress propertyAddress ;
467470
468471 if ((macosx_out = calloc (1, sizeof (MACOSX_AUDIO_OUT))) == NULL)
469472 { perror ("macosx_open : malloc ") ;
@@ -477,38 +480,45 @@ macosx_open (int channels, int samplerate) · 7 unmodified lines
477480 macosx_out->device = kAudioDeviceUnknown ;
478481
479482 /* get the default output device for the HAL */
483+ propertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
484+ propertyAddress.mScope = kAudioDevicePropertyScopeOutput;
485+ propertyAddress.mElement = kAudioObjectPropertyElementMaster;
486+
480487 count = sizeof (AudioDeviceID) ;
481− if ((err = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice,
482− &count, (void *) &(macosx_out->device))) != noErr)
483− { printf ("AudioHardwareGetProperty failed.\n") ;
488+ if ((err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL,
489+ &count, &(macosx_out->device))) != noErr)
490+ { printf ("AudioObjectGetPropertyData (kAudioHardwarePropertyDefaultOutputDevice) failed.\n") ;
484491 free (macosx_out) ;
485492 return NULL ;
486493 } ;
487494
488495 /* get the buffersize that the default device uses for IO */
489496 count = sizeof (UInt32) ;
490− if ((err = AudioDeviceGetProperty (macosx_out->device, 0, false, kAudioDevicePropertyBufferSize,
497+ propertyAddress.mSelector = kAudioDevicePropertyBufferSize ;
498+ if ((err = AudioObjectGetPropertyData (macosx_out->device, &propertyAddress, 0, NULL,
491499 &count, &(macosx_out->buffer_size))) != noErr)
492− { printf ("AudioDeviceGetProperty (AudioDeviceGetProperty) failed.\n") ;
500+ { printf ("AudioObjectGetPropertyData (kAudioDevicePropertyBufferSize) (AudioDeviceGetProperty) failed.\n") ;
493501 free (macosx_out) ;
494502 return NULL ;
495503 } ;
496504
497505 /* get a description of the data format used by the default device */
498506 count = sizeof (AudioStreamBasicDescription) ;
499− if ((err = AudioDeviceGetProperty (macosx_out->device, 0, false, kAudioDevicePropertyStreamFormat,
507+ propertyAddress.mSelector = kAudioDevicePropertyStreamFormat ;
508+ if ((err = AudioObjectGetPropertyData (macosx_out->device, &propertyAddress, 0, NULL,
500509 &count, &(macosx_out->format))) != noErr)
501− { printf ("AudioDeviceGetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
510+ { printf ("AudioObjectGetPropertyData (kAudioDevicePropertyStreamFormat) failed.\n") ;
502511 free (macosx_out) ;
503512 return NULL ;
504513 } ;
505514
506515 macosx_out->format.mSampleRate = samplerate ;
507516 macosx_out->format.mChannelsPerFrame = channels ;
508−
509− if ((err = AudioDeviceSetProperty (macosx_out->device, NULL, 0, false, kAudioDevicePropertyStreamFormat,
510− sizeof (AudioStreamBasicDescription), &(macosx_out->format))) != noErr)
511− { printf ("AudioDeviceSetProperty (kAudioDevicePropertyStreamFormat) failed.\n") ;
517+ propertyAddress.mSelector = kAudioDevicePropertyStreamFormat ;
518+ count = sizeof (AudioStreamBasicDescription) ;
519+ if ((err = AudioObjectGetPropertyData (macosx_out->device, &propertyAddress, 0, NULL,
520+ &count, &(macosx_out->format))) != noErr)
521+ { printf ("AudioObjectGetPropertyData (kAudioDevicePropertyStreamFormat) failed.\n") ;
512522 free (macosx_out) ;
513523 return NULL ;
514524 } ;
@@ -522,8 +532,8 @@ macosx_open (int channels, int samplerate) · 7 unmodified lines
522532 macosx_out->done_playing = 0 ;
523533
524534 /* Fire off the device. */
525− if ((err = AudioDeviceAddIOProc (macosx_out->device, macosx_audio_out_callback,
526− (void *) macosx_out)) != noErr)
535+ if ((err = AudioDeviceCreateIOProcID (macosx_out->device, macosx_audio_out_callback,
536+ (void *) macosx_out, &macosx_out->ioprocid)) != noErr)
527537 { printf ("AudioDeviceAddIOProc failed.\n") ;
528538 free (macosx_out) ;
529539 return NULL ;
@@ -582,7 +592,8 @@ macosx_close (AUDIO_OUT *audio_out) · 52 unmodified lines
582592 return ;
583593 } ;
584594
585− err = AudioDeviceRemoveIOProc (macosx_out->device, macosx_audio_out_callback) ;
595+ err = AudioDeviceDestroyIOProcID(macosx_out->device,
596+ macosx_out->ioprocid);
586597 if (err != noErr)
587598 { printf ("AudioDeviceRemoveIOProc failed.\n") ;
588599 return ;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t