• 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: Gilbert Mackall <email@hidden>
  • Date: Tue, 25 Feb 2003 18:18:53 -0500

Tommy,

Thanks for the help. After a few changes here are the results of opening an AIFF formated file created with QuickTime and the code used to get them.


PATH = /Users/gilbertmackall/Desktop/VAM_greeting.aif
SampleRate 44100.000000
FormatID 1819304813
FormatFlags 14
BytesPerPacket 2
FramesPerPacket 1
BytesPerFrame 2
ChannelsPerFrame 1



- (IBAction)getFile:(id)sender
{

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

AudioStreamBasicDescription basicDescription;

NSArray *fileTypes = [NSArray arrayWithObjects:@"AIFF",@"aif",@"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);
osStatus = AudioFileGetPropertyInfo(fileID, kAudioFilePropertyDataFormat, &theSize, & isWritable);
if( osStatus == noErr )
{
// basicDescription = (AudioStreamBasicDescription * )malloc(sizeof(AudioStreamBasicDescription));
osStatus = AudioFileGetProperty(fileID,kAudioFilePropertyDataFormat,&theSize,&basic Description);
if( osStatus == noErr )
{
printf("SampleRate %f\n",basicDescription.mSampleRate);
printf("FormatID %ld\n",basicDescription.mFormatID);
printf("FormatFlags %ld\n",basicDescription.mFormatFlags);
printf("BytesPerPacket %ld\n",basicDescription.mBytesPerPacket);
printf("FramesPerPacket %ld\n",basicDescription.mFramesPerPacket);
printf("BytesPerFrame %ld\n",basicDescription.mBytesPerFrame);
printf("ChannelsPerFrame %ld\n",basicDescription.mChannelsPerFrame);
}
}
}

On Monday, February 24, 2003, at 11:25 PM, Tommy Braas wrote:

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,basicD escription);

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,basic Description);

}

}
_______________________________________________
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.





Gilbert Mackall
_______________________________________________
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.

References: 
 >Re: Help with AudioFileGetProperty (From: Tommy Braas <email@hidden>)

  • Prev by Date: Re: audio computation and feeder threads
  • Next by Date: Re: audio computation and feeder threads
  • Previous by thread: Re: Help with AudioFileGetProperty
  • Next by thread: Stupid question about cvs and SourceForge.net
  • Index(es):
    • Date
    • Thread