• 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
Float32 PCM to AIFF error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Float32 PCM to AIFF error


  • Subject: Float32 PCM to AIFF error
  • From: sheen mac <email@hidden>
  • Date: Mon, 5 Mar 2007 04:07:24 -0800 (PST)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Float32 PCM to AIFF error
      • From: Richard Dobson <email@hidden>
  • Prev by Date: Question on MTCoreAudio
  • Next by Date: Re: Float32 PCM to AIFF error
  • Previous by thread: Re: Question on MTCoreAudio
  • Next by thread: Re: Float32 PCM to AIFF error
  • Index(es):
    • Date
    • Thread