Raw audio

From ActiveArchives
Jump to: navigation, search

Most audio formats (like WAV, MP3, or OGG/Vorbis) are "self-describing". In other words the file includes the information necessary to play the file (such as sample rate, bit depth, number of channels). This meta-data is typically stored inside a initial package of data called a header. Working with "raw audio data" (without a header or other metadata) is in certain circumstances necessary or useful. For instance some audio recorders may produce raw audio and it's convenient to make such a file self-contained for easy playback. An example is the VirtualRecorder app for Android phones which produces "PCM" files which are in fact just raw / headerless audio data (PCM simply stands for pulse-code modulation, another term for the simplest means of representing audio digitally as a stream of numbers representing amplitude or loudness data over time).

Raw audio data manipulations with sox.


Playing raw data

play --type raw --rate 44100 --bits 16 --channels 2 --encoding signed-integer data.raw

Converting raw data to a self-describing format (such as wav)

sox --type raw --rate 44100 --bits 16 --channels 2 --encoding signed-integer data.raw audio.wav

Converting self-describing formats (like wav) to raw

sox audio.wav --rate 44100 --bits 16 --channels 2 --encoding signed-integer data.raw

Applications of using raw

Appending audio using a raw temp file

if [ -f tmp.raw ]; then rm tmp.raw; fi;
for i
  sox input.wav --rate 44100 --bits 16 --channels 1 -t raw - >> tmp.raw
sox --rate 44100 --bits 16 --channels 1 --encoding signed-integer tmp.raw output.wav
rm tmp.raw
Personal tools