Search code examples
methodscore-audioobjective-c++

AudioFileGetProperty - no matching function call in .mm source file, but OK in .m?


I've needed to change an obj-C source file from .m to .mm in order to access some c++ classes. As soon as I do so, AudioFileGetProperty() & AudioFileReadPackets() report a "No Matching Function Call" error.

If I move it out of a method and in to a C-style block outside the implementation, or rename to .m, it works.

Why can't I use AudioFileGetProperty() within a method in a .mm File?

- (SInt16*)loadSingleWAVBuffer:(NSString*)inName ofLength:(UInt32*)outLength
{
    AudioFileID audioFileID;
    SInt64  dataSize, packetsRead, numBytesRead, storageSize, packetCount;
    NSString *filePath = [NSString stringWithFormat:@"%@/%@%@%@", [[NSBundle mainBundle] bundlePath], self.lessonName, @"/Phrase Data/", inName];

    CFURLRef myFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filePath, kCFURLPOSIXPathStyle, false);
    OSStatus    err = AudioFileOpenURL(myFileURL, kAudioFileReadPermission, 0, &audioFileID);
    AudioStreamBasicDescription asbd;
    UInt32 propSize = sizeof(asbd);
    AudioFileGetProperty(audioFileID, kAudioFilePropertyDataFormat,&propSize, &asbd);
    dataSize = sizeof packetCount;

    OSStatus result = AudioFileGetProperty(audioFileID, kAudioFilePropertyAudioDataPacketCount, &dataSize, &packetCount);
    packetsRead = packetCount;
    printf("File Opened, packet Count: %lld", packetCount);
    storageSize = 2 * packetCount; 
    SInt16* outBuffer = (SInt16*)malloc( storageSize);

    result = AudioFileReadPackets (audioFileID, false, &numBytesRead, NULL, 0, &packetsRead,  outBuffer);
    *outLength = packetsRead;
    return outBuffer;
}

I'm using the AudioToolbox framework and have included the headers.

#import <AudioToolbox/AudioToolbox.h>

I'm building with iOS 6.1 SDK, targeting iOS 6.0


Solution

  • You have given some of the variables the wrong type, use the following replacements:

    UInt32 dataSize, numBytesRead, packetsRead;
    UInt64 packetCount;
    

    When compiling as .m file it does give you a warning that it is the wrong type (at least with default compiler settings), it just seems that .mm is more strict and therefor gives you an error instead.