Raw audio
RAW Audio is an audio file format for storing uncompressed audio in raw form. Comparable to WAV or AIFF in size, RAW Audio file does not include any header information (sampling rate, bit depth, endian, or number of channels)
convert an mp3 to raw
Using
- ffmpeg: " A complete, cross-platform solution to record, convert and stream audio and video."
- Sox: the Swiss Army knife of sound processing programs
Find out the properties of the audio file with ffmpeg
ffmpeg -i file.mp3 sox -V file.wav
Sox has no handler for mp3 formate, hence you have need to convert from mp3 to wav, ffmpeg does it quickly and well
ffmpeg -i file.mp3 -acodec pcm_s16le -ar 44100 file.wav
-acodec pcm_s16le
: audio codec is PCM signed 16bit-ar 44100
: audio rate 44.1kHz
Sox: display information on the wav file
sox -V file.wav
Sox: convert the wav file to raw
sox file.wav -b 16 -c 1 -r 44100 -t raw file.raw
-b 16
bit-rate-c 1
number of channels-r 44100
sampling rate-t raw
target raw
play (sox): play back the raw file at same bit-rate and sample-rate
play -b 16 --endian little -e signed -r 44100 -c 1 Zong3.raw
--endian little
: "specify whether the byte-order of the audio data is, respectively, `little endian'... Endianness applies only to data encoded as floating-point, or as signed or unsigned integers of 16 or more bits. It is often necessary to specify one of these options for headerless files"-e signed
encoding. Signed is commonly used with a 16 or 24 -bit encoding size.
Same thing but with aplay:
aplay -f S16_LE -c 1 -r 44100 Zong3.raw
-f
sample forma+bit rate+endian:- 8bit: S8 U8
- 16bit: S16_LE S16_BE U16_LE U16_BE
- 24bit: S24_LE S24_BE U24_LE U24_BE
- 32bit: S32_LE S32_BE U32_LE U32_BE
-c
: channel number-r
: sample rate. 4000 Hz is the minimum allowed by aplay. 44100Hz is the default sample rate for CDs
convert image to raw audio
copy the image to another file, with the extension raw
cp img.png img.raw
play: use sox previously use command to play that audio
play -b 16 --endian big -e signed -r 44100 -c 1 img.raw
- lowering the sampling rate
-r
will slow-down the playback
Save the result of playing the raw file into audio file with a head (wav)
sox -r 44100 -b 16 -c 1 -e signed img.raw img.wav
Notice that the same audio parameters need to be declared: sample-rate, bit-rate, channel number, encoding
play: without having to declare any parameters
play img.wav
Links
- Raw Audio File Formats Information (at the Wayback Machine)
- SOX Conversions, Raw Files, Splitting And Merging Channels
- Audio Conversion Cheat Sheet
- [SoX] in the Cookbook