• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with AudioFileGetProperty
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with AudioFileGetProperty


  • Subject: Re: Help with AudioFileGetProperty
  • From: Tommy Braas <email@hidden>
  • Date: Mon, 24 Feb 2003 20:25:37 -0800

Gilbert,

Void pointers is the C way of achieving a generic way of sending untyped data. Any pointer can be a void pointer. There shouldn't be a need to cast something to a void pointer, there is, however, a need to cast a pointer from a void pointer to some other kind of pointer.

The simplest way of changing your code would be to change the following lines;

AudioFileOpen(fileRef, fsRdPerm, 0, fileID);
AudioFileGetProperty(fileID,kAudioFilePropertyDataFormat,theSize,basicDe scription);

to

// the fourth parameter needs to be a pointer, prepend ampersand to any datatype to make it a pointer to that type
AudioFileOpen(fileRef, fsRdPerm, 0, &fileID);

// the fourth parameter needs to be a pointer, prepend ampersand to any datatype to make it a pointer to that type
AudioFileGetProperty(fileID, kAudioFilePropertyDataFormat, theSize, &basicDescription);

The reason why that should work, without retrieving the size properly first, is that the AudioStreamBasicDescription is fixed in size. Any property that has a variable size should be retrieved using the steps outlined below.

The way the various get property methods are supposed to be used, as far as I know, is that first you query the API to get the size of the data, then you get the data.

So, you would do the following in the general case (which covers ALL values and types for the property data returned by a query);

UInt32 theSize;
void *theData;
UInt32 isWritable;

OSStatus osStatus = noErr;
osStatus = AudioFileGetPropertyInfo(inAudioFile, inPropertyID, &theSize, &writable);
if( osStatus == noErr )
{
// allocate enough space to hold the data
theData = malloc( theSize * sizeof(char));
osStatus = AudioFileGetProperty(inAudioFile, inPropertyID, &theSize, theData);

if( osStatus == noErr )
{
// the data is valid
// do something with the data
// cast 'theData' to the type that was returned by the property, and access its fields
}
}

Some properties are writable using the AudioFileSetProperty(...), and the 'writable' variable will be true (1) if the specific property is writable.

I would change your code to the following;

- (IBAction)getFile:(id)sender
{

int result;
NSString *path;
FSRef *fileRef;
AudioFileID fileID;
UInt32 theSize;
UInt32 isWritable;
AudioStreamBasicDescription *basicDescription;
OSStatus osStatus = noErr;

NSArray *fileTypes = [NSArray arrayWithObjects:@"AIFF",@"AIFC",@"WAVE",@"wav",nil];

NSOpenPanel *oPanel = [NSOpenPanel openPanel];

[oPanel setAllowsMultipleSelection:NO];
result = [oPanel runModalForTypes:fileTypes];

if (result == NSOKButton)
{
NSArray *filesToOpen = [oPanel filenames];
path = [filesToOpen objectAtIndex:0];

NSLog(@"%@ \n", path);

FSPathMakeRef([path fileSystemRepresentation], fileRef, NULL);
AudioFileOpen(fileRef, fsRdPerm, 0, &fileID);
osStatus = AudioFileGetPropertyInfo(fileID, kAudioFilePropertyDataFormat, &theSize, & isWritable);
if( osStatus == noErr )
{
basicDescription = (AudioStreamBasicDescription * )malloc(sizeof(AudioStreamBasicDescription));
osStatus = AudioFileGetProperty(fileID, kAudioFilePropertyDataFormat, &theSize, basicDescription);
if( osStatus == noErr )
{
// your data should be contained and accessible through 'basicDescription' here
}
}
}
}

I hope this helps you out!

Best regards,

Tommy Braas
deep sea software


On Monday, Feb 24, 2003, at 18:48 US/Pacific, Gilbert Mackall wrote:

I am having a problem in understanding how the AudioFileGetProperty function is passed a pointer for the AudioStreamBasicDescription of the file I have selected. Below is the section of code I am having problems with. In reading AudioFile.h it states:

AudioFileGetProperty( AudioFileID inAudioFile,
AudioFilePropertyID inPropertyID,
UInt32 *ioDataSize,
void *outPropertyData);


My problem seems to be that I am not understanding, how to pass a void pointer.


- (IBAction)getFile:(id)sender
{

int result;
NSString *path;
FSRef *fileRef;
AudioFileID fileID;
UInt32 *theSize;
AudioStreamBasicDescription basicDescription;

NSArray *fileTypes = [NSArray arrayWithObjects:@"AIFF",@"AIFC",@"WAVE",@"wav",nil];

NSOpenPanel *oPanel = [NSOpenPanel openPanel];

[oPanel setAllowsMultipleSelection:NO];
result = [oPanel runModalForTypes:fileTypes];

if (result == NSOKButton)
{
NSArray *filesToOpen = [oPanel filenames];
path = [filesToOpen objectAtIndex:0];

printf("%s \n",[path cString]);

FSPathMakeRef([path fileSystemRepresentation],fileRef,NULL);
AudioFileOpen(fileRef, fsRdPerm, 0, fileID);
AudioFileGetProperty(fileID,kAudioFilePropertyDataFormat,theSize,basicD escription);

}

}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Help with AudioFileGetProperty
      • From: Gilbert Mackall <email@hidden>
    • Re: Help with AudioFileGetProperty
      • From: Gilbert Mackall <email@hidden>
References: 
 >Help with AudioFileGetProperty (From: Gilbert Mackall <email@hidden>)

  • Prev by Date: Help with AudioFileGetProperty
  • Next by Date: Re: Idle processing
  • Previous by thread: Help with AudioFileGetProperty
  • Next by thread: Re: Help with AudioFileGetProperty
  • Index(es):
    • Date
    • Thread