views:

299

answers:

2

The question may sound stupid, but the thing is this: I am learning how to use a Audio Queue, and the example I've taken (aqtest) has been a nice guide for me until I recently found out that aqtest is not for iPhone. (stupid me) I served around the Internet and found out that there is no FSRef for iPhone.

If possible, I want to find a way to work around FSRef thinggie. So here comes the question: can I use something else instead of FSRef that exists on the iPhone SDK? Or am I missing something?

A: 

FSRefs are not available on the phone at all. FSRefs are a way of reprsenting a file reference, for most purposes the preferred replacement for the is an NSURL with a file: scheme.

Having said that, there definitely is a SpeakHere example for the iPhone, it does not use FSRefs.

As for aqtest, I assume the code you are having issues with is:

FSRef fsref;    
XThrowIfError(FSPathMakeRef(filePath, &fsref, NULL), "Input file not found");

XThrowIfError(AudioFileOpen(&fsref, fsRdPerm, 0, &myInfo.mAudioFile), "AudioFileOpen failed");

Like I said, FSRef is no longer the preferred way to handle file refs, and is not available on the phone, NSURL is. So change over to the URL based version:

NSString *pathString = [NSString stringWithCString: filePath];
if (!pathString) { printf("can't parse file path\n"); return; }

NSURL *url = [NSURL fileURLWithPath:pathString];
if (! url) { printf("can't make file url\n"); return; }

XThrowIfError(AudioFileOpenURL (url, kAudioFileReadPermission, 0/*inFileTypeHint*/, &myInfo.mAudioFil), "can't open file");

That should work on the phone, of course a lot of aqtest itself won't work on the phone, running commandline tools on the device is not supported after all.

Louis Gerbarg
Actually I was running away from SpeakHere example because it confuses me. aqtest makes me understand a lot of things clearer when I read through it with the apple document about audio queue. For SpeakHere though, I'm not sure what goes where. I don't even know where to start looking in order to understand how it works.
A: 

Have you looked at the code in aqplay.cpp? It's in some sample code I grabbed from
Core Audio -> SimpleSDK -> AudioQueueTools.

It's uses a CFURLRef to open its AudioFileID.

Most of that code looks like it should compile for the iPhone.

Rhythmic Fistman