开发者

Which audio file format is easiest to manipulate?

开发者 https://www.devze.com 2023-02-09 20:59 出处:网络
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.

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 开发者_JAVA百科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!


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


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号