• 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
getting PCM data from an audio file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getting PCM data from an audio file


  • Subject: getting PCM data from an audio file
  • From: "Andrew GFunk" <email@hidden>
  • Date: Sun, 01 Jun 2003 22:41:35 -0700

Hi! I'm trying to use AudioFile.h to get raw PCM data from an AIFF file (so that I can do some DSP stuff on it). I'm trying to use the AudioFileReadPackets() function, but I'm not having any luck. I keep getting what appears to be an empty file from my code. Here's the code:



/* Controller.h */

#import <Cocoa/Cocoa.h>
#import <AudioToolbox/AudioFile.h>

@interface Controller : NSObject
{
}
- (IBAction)writeFile:(id)sender;
@end




/* Controller.m */

#import "Controller.h"

@implementation Controller

- (IBAction)writeFile:(id)sender
{
NSData *data;

AudioStreamBasicDescription srcFmt;
UInt32 propertySize = sizeof(srcFmt);

void *outBuffer = malloc(20000);
UInt32 ioNumBytes = 20000;
AudioFileID originalAudioFile;
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
FSRef fsRef;
FSPathMakeRef ([[thisBundle pathForResource:@"Waiting2" ofType:@"aif"] UTF8String], &fsRef, NULL);
AudioFileOpen(&fsRef, 1, 0, &originalAudioFile);

AudioFileGetProperty(originalAudioFile, kAudioFilePropertyDataFormat,
&propertySize, &srcFmt);
printf("mSampleRate %g\n", srcFmt.mSampleRate);

// I tried calling this too... still the same result
// AudioFileReadBytes(originalAudioFile, TRUE, 0, &ioNumBytes, outBuffer);

AudioFileReadPackets(originalAudioFile, TRUE, &ioNumBytes, NULL, 0, &ioNumBytes, outBuffer);
data = [NSData dataWithBytesNoCopy:outBuffer length:sizeof(outBuffer)];
[data writeToFile:[@"~/Desktop/audio.txt" stringByExpandingTildeInPath] atomically:YES];

NSLog(@"%@", data);
}

@end



What am I doing wrong?


Thanks,

Andrew Garber

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
_______________________________________________
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: getting PCM data from an audio file
      • From: Philippe Wicker <email@hidden>
  • Prev by Date: Griffin iMic issue
  • Next by Date: Re: getting PCM data from an audio file
  • Previous by thread: Griffin iMic issue
  • Next by thread: Re: getting PCM data from an audio file
  • Index(es):
    • Date
    • Thread