• 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: Getting raw audio data from an AIFF file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Getting raw audio data from an AIFF file


  • Subject: RE: Getting raw audio data from an AIFF file
  • From: Peter <email@hidden>
  • Date: Mon, 17 Feb 2003 13:48:46 -0600

Brian,

I had the C string terminating character in mind; thanks for explicitly going
through it. I first learned C++, so I have to learn and deal with C as I go.

Thanks a lot for the strncmp example; I had forgotten about it. (I'll
remember strncpy to protect against buffer overflow exploits, though.)

Your walkthrough makes perfect sense. Thanks a lot for your help.

Peter


>===== Original Message From Brian Willoughby <email@hidden> =====
>Peter,
>
>[ I want to skip all headers after the FORM chunk is read and go to
>[ the SSND chunk so I can start playing the audio. While my chunkID
>[ is 'SSND' (a four char array), I print it out and get
>[ 'SSND\277\260' instead. Why would there be more than the four
>[ chars printing out? This is a problem because my chunk skipping
>[ routine doesn't know when to stop. You can see that I stop now
>[ by doing four char comparisons.
>
>In the C language, strings must be terminated by a '\0' character. The chunk
>type names in AIFF/AIFC are not C strings. Also, you must take care when
>declaring "char field[4]" that there is a '\0' character somewhere within
those
>four bytes, or else the standard C string routines will run forever through
>memory until they come across a zero byte somewhere. Debuggers sometimes
>affect the stack contents, which is where automatic variables are stored,
which
>explains why you get different behavior when running vs. when debugging.
>
>There are many possible solutions to this, but considering your existing
code,
>I would suggest the following:
>
> fread( &form.groupID, sizeof(form.groupID), 1, soundFile );
> printf( "group ID:'%c%c%c%c'\n", form.groupID[0], form.groupID[1],
>form.groupID[2], form.groupID[3] );
> // comparison operators work for integers but not strings
> if ( strncmp( form.groupID, "FORM", sizeof(form.groupID) ) ) {
> printf( "File is not a IFF file.\n" ); fflush( stdout );
> return 1;
> }
>
>Sometimes you will be lucky and there might be a zero after those four
>characters - or, only non-visible characters - but you should not write code
>without protecting against the fact that a zero might not be there. If you
>notice above, I even changed the printf to print four characters. The '%s'
>format also expected a zero-terminated string, so take care.
>
>Your comparison of individual characters for SSND is acceptable. In fact,
you
>really were just lucky that it is not required for the earlier chunks, too.
I
>happen to think that the strncmp() is a little more readable, but the steps
>involved take about the same amount of time.
>
>I hope the above makes sense. You should be able to extrapolate the example
>to every place where you are printing or comparing a chunk type name.
>
>Brian Willoughby
>Sound Consultin
_______________________________________________
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.

  • Prev by Date: Re: Getting raw audio data from an AIFF file
  • Next by Date: Re: Getting raw audio data from an AIFF file
  • Previous by thread: Re: Getting raw audio data from an AIFF file
  • Next by thread: Re: AUCarbonView - 16-bit controls
  • Index(es):
    • Date
    • Thread