Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Float32 PCM to AIFF error



Hi All,

I tried to convert FLoat32 PCM to AIFF based on http://05.code-hosting.com/MAC_Programming/1432108-Generating-tones---coreAudio-.
But I didn't get a sound.I enclosed the code here.

Kindly help me.

Thanks in Advance,
Sheen

struct Simple_AIFF_File {
    /* form chunk */
    unsigned int formid;
    int formchunksize;
    unsigned int formtype;
   
    /* comm chunk */
    unsigned int commid;
    int commchunksize;
    short numchannels;
    unsigned int numsampleframes;
    short samplesize;
    extended80 samplerate;
   
    /* ssnd chunk */
    unsigned int ssndid;
    int ssndchunksize;
    unsigned int offset;
    unsigned int blocksize;
    Float32 sounddata[];
} __attribute__ ((__packed__));


unsigned long GenerateRandomNumber()
{
    randSeed = (randSeed * 196314165) + 907633515;
    return randSeed;
}

@implementation AiffController

- (IBAction)pressPlay:(id)sender
{
    double frequency =(double)0.05;
   
    const unsigned int sampleRate = 44100;
    const unsigned int channels = 1;
    const unsigned int bytesPerFrame = channels * sizeof(Float32);
    const unsigned int seconds = 4;
   
    const unsigned int dataSize = seconds * sampleRate * channels *
        bytesPerFrame;
    const unsigned int totalSize = dataSize + sizeof(struct Simple_AIFF_File);
   
    unsigned int i;
   
    struct Simple_AIFF_File* aiff = malloc(totalSize);
       
   
    aiff->formid = 'FORM';
    aiff->formchunksize = totalSize - offsetof(struct Simple_AIFF_File,
                                               formtype);
    aiff->formtype = 'AIFF';
   
    aiff->commid = 'COMM';
    aiff->commchunksize = 18;
    aiff->numchannels = 1;
    aiff->numsampleframes = seconds * sampleRate;
    aiff->samplesize = 32;
   
    double sampleRateDouble = (double)sampleRate;
    dtox80(&sampleRateDouble, &aiff->samplerate);
   
    aiff->ssndid = 'SSND';
    aiff->ssndchunksize = dataSize + 8;
    aiff->offset = 0;
    aiff->blocksize = 0;
   
    Float32 sample;
   
    for (i=0; i < seconds * sampleRate * channels; i++) {
        sample = ((long)GenerateRandomNumber()) * (float)(1.0f / 0x7FFFFFFF) *0.80;
        aiff->sounddata[i] = sample;
       
    }
   
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    NSData* data = "" alloc] initWithBytesNoCopy:aiff length:totalSize];
   
    NSSound* sound = [[NSSound alloc] initWithData:data];
    [data release];
   
    [sound play];
    sleep(seconds);
   
    [sound release];
    [pool release];
   
}


Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/coreaudio-api/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.