Re: kAudioFormatUnsupportedDataFormatError
Re: kAudioFormatUnsupportedDataFormatError
- Subject: Re: kAudioFormatUnsupportedDataFormatError
- From: tahome izwah <email@hidden>
- Date: Fri, 11 Nov 2011 07:46:01 +0100
Or use the EAFRead/EAFWrite wrapper classes from the DiracLE project:
http://dirac.dspdimension.com
Usually a good starting point even if you don't need time
stretching/pitch shifting
--th
2011/11/8 Aran Mulholland <email@hidden>:
> Example of setting up recording for AAC or WAV on iOS
> http://pastie.org/2833326
>
>
> On Wed, Nov 9, 2011 at 7:52 AM, Jon August <email@hidden> wrote:
>>
>> That was it.
>> Not sure how I would have figured that out myself.
>> Thanks very much!
>>
>>
>>
>> On Nov 8, 2011, at 3:13 PM, kamaldeep tumkur wrote:
>>
>> Try with:
>> asbd.mFormatFlags = kAudioFormatFlagIsBigEndian |
>> kAudioFormatFlagIsSignedInteger;
>>
>> It's usually the ASBD with these kind of things, in my short time with
>> CoreAudio.
>>
>>
>> On Tue, Nov 8, 2011 at 8:53 AM, Jon August <email@hidden> wrote:
>>>
>>> Hi,
>>> Just joined this list and can't find a way to search archives, so I
>>> apologize if this is a common question.
>>> I'm working through some example code in Core Audio and I'm
>>> getting kAudioFormatUnsupportedDataFormatError when I try to write an AIFF
>>> file or MP3 file. Everything works if I use CAF. Am I missing a framework?
>>> Code below.
>>> Thanks,
>>> -Jon
>>>
>>> //
>>> // main.m
>>> // CAToneFileGenerator
>>> #import <Foundation/Foundation.h>
>>> #import <AudioToolbox/AudioToolbox.h>
>>> #define SAMPLE_RATE 44100
>>> // 1
>>> #define DURATION 5.0
>>> // 2
>>> #define FILENAME_FORMAT @"%0.3f-square.aif"
>>> // 3
>>> int main (int argc, const char * argv[])
>>> {
>>> @autoreleasepool {
>>> if (argc < 2) {
>>> printf ("Usage: CAToneFileGenerator n\n(where n is tone in
>>> Hz)");
>>> return -1;
>>> }
>>> double hz = atof(argv[1]);
>>> assert (hz > 0);
>>> NSLog (@"generating %f hz tone", hz);
>>> NSString *fileName = [NSString stringWithFormat:FILENAME_FORMAT,
>>> hz];
>>> NSString *filePath = [[[NSFileManager defaultManager]
>>> currentDirectoryPath]
>>> stringByAppendingPathComponent: fileName];
>>> NSURL *fileURL = [NSURL fileURLWithPath: filePath];
>>>
>>>
>>> AudioStreamBasicDescription asbd;
>>> memset(&asbd, 0, sizeof(asbd));
>>> asbd.mSampleRate = SAMPLE_RATE;
>>> asbd.mFormatID = kAudioFormatLinearPCM;
>>> asbd.mFormatFlags = kAudioFormatFlagIsBigEndian;
>>> asbd.mBitsPerChannel = 16;
>>> asbd.mChannelsPerFrame = 1;
>>> asbd.mFramesPerPacket = 1;
>>> asbd.mBytesPerFrame = 2;
>>> asbd.mBytesPerPacket = 2;
>>>
>>> AudioFileID audioFile;
>>> OSStatus audioErr = noErr;
>>> // ## FAILS HERE ##
>>> audioErr = AudioFileCreateWithURL((CFURLRef)fileURL,
>>> kAudioFileAIFFType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
>>> // ## FAILS HERE ##
>>> assert(audioErr == noErr);
>>>
>>> // Start writing samples
>>> long maxSampleCount = SAMPLE_RATE * DURATION;
>>> long sampleCount = 0;
>>> UInt32 bytesToWrite = 2;
>>> double wavelengthInSamples = SAMPLE_RATE / hz;
>>> while (sampleCount < maxSampleCount) {
>>> for (int i=0; i<wavelengthInSamples; i++) {
>>> SInt16 sample;
>>> if (i < wavelengthInSamples/2) {
>>> sample = CFSwapInt16HostToBig(SHRT_MAX);
>>> } else {
>>> sample = CFSwapInt16HostToBig(SHRT_MIN);
>>> }
>>> audioErr = AudioFileWriteBytes(audioFile, false,
>>> sampleCount*2, &bytesToWrite, &sample);
>>> assert(audioErr == noErr);
>>> sampleCount++;
>>> }
>>> }
>>> audioErr = AudioFileClose(audioFile);
>>> assert(audioErr == noErr);
>>> NSLog(@"wrote %ld samples", sampleCount);
>>> }
>>> return 0;
>>> }
>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Coreaudio-api mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>>
>>> This email sent to email@hidden
>>>
>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Coreaudio-api mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>>
>> This email sent to email@hidden
>>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden