4

Hello nice computer persons,

Per to a question I had earlier concerning accessing the samples in an audio file, I now realize that the Core Audio Format may not be the way to go.

Especially since on page 15 of the spec it mentions something about the use of C being a 'notational convenience' i.e. you can't just crack it open with some c functions and do what you want with it.

That said, if I want to open an audio file and then run some C, C++ or Objective-C code on it to play around with the sample values, which format would be best to do this on: WAV? AIFF? other?

Please keep in mind I would like this to be able to run on iOS.

Thanks!

Community
  • 1
  • 1
Eric Brotto
  • 53,471
  • 32
  • 129
  • 174
  • note that a CAF file with uncompressed LinearPCM (as in table 2-2 of the spec) is virtually identical to uncompressed WAV and should be just as easy to edit. – AShelly Feb 08 '11 at 19:27
  • @AShelly. Interesting. Could I get your opinion on the comment about the presentation being 'a notational convenience' (page 15 of the box. in the spec). Would be glad to hear what you think :) – Eric Brotto Feb 08 '11 at 20:45
  • 1
    I believe it is saying that you can't just do a binary read of the file directly into the structures the document describes. There are things like padding and variable size fields, which require the file to be parsed. My point is that once you get to the DATA chunk in either format, what you have is raw PCM, which is the easiest format to edit. – AShelly Feb 14 '11 at 18:06

5 Answers5

9

Uncompressed WAV files. They consist of a header followed by the raw samples.

Niki Yoshiuchi
  • 16,883
  • 1
  • 35
  • 44
5

I once manipulated WAV via C++ and it was pretty easy. I used this spec to write my code: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ With this document and a little understanding of digital audio you can easily manipulate WAV files.

Raphael
  • 7,972
  • 14
  • 62
  • 83
2

Uncompressed WAV is the defacto standard for audio editing. You can use various libraries to manipulate them easily. If you simply want completely raw samples without even the WAV header go with PCM however you will have to know your sample rate, frequency, etc ahead of time as you won't have that info that would normally be in the WAV header all you get is the uncompressed samples.

AJG85
  • 15,849
  • 13
  • 42
  • 50
  • My frequency, sample rate, etc. will never change, so yes I do need just raw samples. Could you specify what you mean by 'go with PCM'? – Eric Brotto Feb 08 '11 at 20:49
  • 2
    PCM (Pulse-code modulation) is a raw uncompressed audio format ... programs such as Adobe Audition and other audio editing, sampling, mastering will recognize PCM file extension as such. Specifically I used PCM when working with text-to-speech synthesis in telecom previously. Basically it's a WAV file without the header. – AJG85 Feb 08 '11 at 22:14
1

The simplest uncompressed WAV file format just has a 44 byte header (which tells you the sample rate, number of bits per sample, and whether the data is stereo pairs or mono), followed directly by an array of raw PCM (usually) short integers.

On a little-endian CPU (such as Intel or most ARM), you can map this file format directly into a C array of 16-bit shorts, and just index into it with an appropriate offset from the header.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

Uncompressed WAV will be the simplest to deal with, as you don't have to deal with decoding them before manipulation, so you probably want to start with that until you are sure of your manipulation routines/code.

However, unless you plan on only having a few spot effects or a rather large resultant bundle it might be better, in the long run, to look at something like IMA ADPCM. The decoding algorithms are out there (check out http://wiki.multimedia.cx/index.php?title=IMA_ADPCM for more on that), relatively simple to implement and it will allow you to fit more sounds in your product.

Laughing_Jack
  • 1,603
  • 15
  • 14