Raw audio: Difference between revisions
(Michael Murtaugh moved page Raw audio to Generating audio with python) |
Andre Castro (talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
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 | |||
* [http://ffmpeg.org/ ffmpeg]: " A complete, cross-platform solution to record, convert and stream audio and video." | |||
* [http://sox.sourceforge.net/ 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 | |||
* <code>-acodec pcm_s16le</code>: audio codec is PCM signed 16bit | |||
* <code>-ar 44100</code>: 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 | |||
* <code>-b 16</code> bit-rate | |||
* <code>-c 1</code> number of channels | |||
* <code>-r 44100</code>sampling rate | |||
* <code>-t raw</code>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 | |||
* <code>--endian little</code>: "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" | |||
* <code>-e signed</code> 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 | |||
* <code>-f</code> 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 | |||
*<code>-c</code>: channel number | |||
*<code>-r</code>: 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 <code>-r</code> 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= | |||
* [https://web.archive.org/web/20160525083851/http://www.fmtz.com:80/misc/raw-audio-file-formats Raw Audio File Formats Information] (at the [[Wayback Machine]]) | |||
* [https://www.nesono.com/node/275 SOX Conversions, Raw Files, Splitting And Merging Channels] | |||
* [http://stefaanlippens.net/audio_conversion_cheat_sheet/ Audio Conversion Cheat Sheet] | |||
* [SoX] in the Cookbook |
Latest revision as of 14:26, 29 January 2018
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