• 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: kAudioFormatUnsupportedDataFormatError
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: kAudioFormatUnsupportedDataFormatError


  • Subject: Re: kAudioFormatUnsupportedDataFormatError
  • From: Aran Mulholland <email@hidden>
  • Date: Wed, 09 Nov 2011 09:27:37 +1100

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

  • Follow-Ups:
    • Re: kAudioFormatUnsupportedDataFormatError
      • From: tahome izwah <email@hidden>
References: 
 >kAudioFormatUnsupportedDataFormatError (From: Jon August <email@hidden>)
 >Re: kAudioFormatUnsupportedDataFormatError (From: kamaldeep tumkur <email@hidden>)
 >Re: kAudioFormatUnsupportedDataFormatError (From: Jon August <email@hidden>)

  • Prev by Date: Changing audio session and disabling recording when moving to background
  • Next by Date: MIDIObjectGetProperties returning err -50 on virtual MIDI port
  • Previous by thread: Re: kAudioFormatUnsupportedDataFormatError
  • Next by thread: Re: kAudioFormatUnsupportedDataFormatError
  • Index(es):
    • Date
    • Thread