• 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
Simple AudioFile Copy program
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple AudioFile Copy program


  • Subject: Simple AudioFile Copy program
  • From: James Baxter <email@hidden>
  • Date: Sat, 8 Nov 2003 21:12:59 -0800 (PST)

When I run the code below, a new file is created of
only 4KB (should be 1.88 MB).

Also, when I open the new audio file in QT (whether or
not I've called WriteBytes to it), I get an error
about a movie with an incorrect duration.

Any help is greatly appreciated. Feel free to dumb
down responses because I really don't know what I'm
doing.

*************

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool
alloc] init];


//Open Audio File

OSStatus err;

NSString * myFile = [[NSString alloc] init];
myFile = @"/Users/ekstasis/Desktop/Movie
Samples/taken001.aiff";

FSRef fileRef;
err = FSPathMakeRef ([myFile
fileSystemRepresentation],
&fileRef,
NULL);

AudioFileID fileHandle;

err = AudioFileOpen(&fileRef, fsRdPerm, 0,
&fileHandle);

//Get Audio Byte Count

UInt32 theSize;
UInt32 isWritable;
UInt64 bcnt;

err = AudioFileGetPropertyInfo(fileHandle,

kAudioFilePropertyAudioDataByteCount,
&theSize,
&isWritable);

err = AudioFileGetProperty(fileHandle,

kAudioFilePropertyAudioDataByteCount,
&theSize,
&bcnt);

//Get AudioStreamBasicDescription

AudioStreamBasicDescription streamDesc;

err = AudioFileGetPropertyInfo(fileHandle,

kAudioFilePropertyDataFormat,
&theSize,
&isWritable);

err = AudioFileGetProperty(fileHandle,

kAudioFilePropertyDataFormat,
&theSize,
&streamDesc);

//Extract Audio Data

void * myData;

myData = malloc(bcnt);

err = AudioFileReadBytes(fileHandle, 0, 0, (UInt32
*)&bcnt, myData);


//Close Audio File

err = AudioFileClose(fileHandle);

//Create New Audio File


NSString * myNewDir = [[NSString alloc] init];
myNewDir = @"/Users/ekstasis/Desktop/Movie
Samples/";

NSString * myNewFile = [[NSString alloc] init];
myNewFile = @"taken001COPY.aiff";

FSRef newDirRef;
err = FSPathMakeRef ([myNewDir
fileSystemRepresentation],
&newDirRef,
NULL);

FSRef newFileRef;

AudioFileID newFileHandle;

err = AudioFileCreate (&newDirRef,
(CFStringRef)myNewFile,
kAudioFileAIFCType,
&streamDesc,
0,
&newFileRef,
&newFileHandle);



//Write Audio Data

err = AudioFileWriteBytes (newFileHandle,
0,
0,
(UInt32 *)&bcnt,
myData);

//Close New Audio File

err = AudioFileClose(newFileHandle);

[pool release];
return 0;
}

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
_______________________________________________
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: Simple AudioFile Copy program
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: MusicDevice implementation
  • Next by Date: Re: Simple AudioFile Copy program
  • Previous by thread: Re: threading questions
  • Next by thread: Re: Simple AudioFile Copy program
  • Index(es):
    • Date
    • Thread