0

I am attempting to use MusicSequence to control an instance of AUSampler targeting iOS5.1

The project has references to CoreAudio and AudioToolbox the project compiles and runs, but errors on the call to MusicDeviceMIDIEvent with Bad Access Xcode, 'unknown function' AppCode.

I see that the API has changed and that MusicDeviceMIDIEvent now exists in MusicDevice.h in the AudioUnit framework.

If I try to add a reference to AudioUnit.framework which I understand contains the function I get 'framework not found AudioUnit' and the project fails to build.

Other questions on SE suggest that I should be using CoreAudio and AudioToolbox over AudioUnit.

In addition I can see that the sample code 'LoadPresetDemo' functions without the AudioUnit framework, but I can't see why.

Any advice or pointers would be very much appreciated.

1 Answers1

1

To work with the MusicPlayer API you only need to add the AudioToolBox framework to your project and then import the AudioToolbox.h in your project:

#import <AudioToolbox/AudioToolbox.h>

If you look at that file you will see that it #includes all the necessary bits for working with AUGraphs etc. If you need to do something additional, like recording or access to the AUGraph output then you will need to import additional frameworks.

I posted a demo project for someone else which uses the MusicPlayer API - you may find that of use.

Update:

AudioToolbox is sort of a convenience "Swiss Army Knife for Audio" type thing. If you look in AudioToolbox.h it is linking to MusicPlayer.h and that is linking to some Core Audio + Audio Unit stuff. MusicDeviceMIDIEvent is defined in MusicPlayer.h so if you have included the AudioToolBox Framework in your build settings,

I have the "LoadPresetDemo" example here. For audio it only contains the AudioToolbox and the AVFoundation. As a reality check I removed the AVFoundation link, compiled and fixed the errors which resulted - which all pertain to setting up an Audio Session and output sample rate, etc. then I compiled and ran it in the Simulator and it runs fine. I think Apple included all of that to demo how to handle an audio app entering and leaving the background (see endInterruptionWithFlags method).

Anyway... If you have linked to the AudioToolBox and imported AudioToolbox.h then I have no idea what is going wrong ... ;-)

#define AUDIO_TOOLBOX_VERSION 1060

#include <Availability.h>
#include <TargetConditionals.h>
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
    #include <AudioToolbox/AudioFile.h>
    #include <AudioToolbox/AudioFileStream.h>
    #include <AudioToolbox/AudioFormat.h>
    #include <AudioToolbox/AudioQueue.h>
    #include <AudioToolbox/AudioServices.h>
    #include <AudioToolbox/AUGraph.h>
    #include <AudioToolbox/AudioConverter.h>
    #include <AudioToolbox/ExtendedAudioFile.h>
    #include <AudioToolbox/MusicPlayer.h>
    #include <AudioToolbox/CAFFile.h>
    #if !TARGET_OS_IPHONE
        #include <AudioToolbox/AudioFileComponent.h>
        #include <AudioToolbox/AudioUnitUtilities.h>
        #include <AudioToolbox/AUMIDIController.h>
        #include <AudioToolbox/CoreAudioClock.h>
    #endif
#else
    #include <AudioConverter.h>
    #include <AudioFile.h>
    #include <AudioFileComponent.h>
    #include <AudioFileStream.h>
    #include <AudioFormat.h>
    #include <AudioQueue.h>
    #include <AudioUnitUtilities.h>
    #include <AUGraph.h>
    #include <AUMIDIController.h>
    #include <CAFFile.h>
    #include <CoreAudioClock.h>
    #include <ExtendedAudioFile.h>
    #include <MusicPlayer.h>
    #include <AudioServices.h>
#endif

// MusicPlayer.h
#include <Availability.h>
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
    #include <CoreAudio/CoreAudioTypes.h>
    #include <AudioUnit/AUComponent.h>
#else
    #include <CoreAudioTypes.h>
    #include <AUComponent.h>
#endif
spring
  • 18,009
  • 15
  • 80
  • 160
  • Thanks for your time, & the code is def useful but my question is about the func MusicDeviceMIDIEvent as shown in this apple [example](https://developer.apple.com/library/ios/#samplecode/LoadPresetDemo/Introduction/Intro.html). It seems like it should require AudioUnit.fmwk, as this is where the documentation leads me but the above code does not reference it (and works correctly!). Despite this, in my clone of the above code my app fails at run time on the call to MusicDeviceMIDIEvent with both Xcode, Appcode suggesting it is missing.Thanks for the alt approach, still interested in question – disappearance Aug 12 '12 at 12:58
  • Oh, and it seems I can't upvote your answer just yet as I haven't the reputation, but I do appreciate your alternate approach. Thanks again. – disappearance Aug 12 '12 at 12:59
  • Added an update. @ voting - no problem. You can check the checkmark if this answers your question (aka "accepting an answer"). Spent a lot of time/pain getting into the Core Audio stuff - there aren't great docs out there. One book, if you are planning on working with Core Audio is "Learning Core Audio: A Hands-On Guide to Audio Programming for Mac and iOS" - not as in-depth as I would have liked but still worthwhile. – spring Aug 12 '12 at 14:09
  • Ok, thanks for the update and the additional information. With the above insight, I agree, I probably have something else causing my pain, project/ide setting perhaps. I have the CoreAudio book. Any other book I might say I'd read, but with this I'd just say I've done a 'first pass' ;) Thanks again. – disappearance Aug 12 '12 at 14:51