| 1 | [[PageOutline]] |
| 2 | |
| 3 | [=#audio] |
| 4 | = Audio = |
| 5 | This page will attempt to give examples of audio-based GStreamer pipelines using GStreamer-1.0, with 'enhanced' encoders and decoders from the gstreamer-imx set of plugins. Note that 'enhanced' just means that the software algorithms are especially tuned for the imx6 family. |
| 6 | |
| 7 | To see GStreamer-0.10 (deprecated) examples, please refer to [http://trac.gateworks.com/wiki/Yocto/gstreamer/audio?version=2 this older revision page]. |
| 8 | |
| 9 | For a description of Audio devices see: |
| 10 | * [wiki:ventana/audio Ventana Audio devices] |
| 11 | |
| 12 | |
| 13 | [=#gstreamer-alsa] |
| 14 | == GStreamer alsasrc and alsasink == |
| 15 | The GStreamer {{{alsasrc}}} and {{{alsasink}}} provide audio capture and playback to Advanced Linux Sound Architecture (ALSA) devices. ALSA is the modern device-driver API for the Linux kernel. |
| 16 | |
| 17 | The Gstreamer alsasrc and alsasink can be passed a {{{device}}} property which can represent either the device name (reported from {{{aplay -L}}} for playback, or {{{arecord -L}}} for record) (ie {{{sysdefault:CARD=sgtl5000audio}}}) or the hw:x,y notation (ie {{{hw:0,0}}} for first device, first subdevice) |
| 18 | |
| 19 | If not specified via the {{{device}}} property, the device used for alsasrc and alsasink will depend on {{{/etc/asound.conf}}} and/or {{{~/.asoundrc}}}. |
| 20 | |
| 21 | Playback and Capture also depends on your ALSA mixer ({{{amixer}}}) settings. See [wiki:ventana/audio#Mixermuxgainvolume mixer settings] for more info. |
| 22 | |
| 23 | |
| 24 | [=#audio-output] |
| 25 | == Audio Output == |
| 26 | Generally, a 'sink' plugin is one that will take an audio stream and send it to an audio device. Please refer to [http://trac.gateworks.com/wiki/ventana/audio this audio] page for more details on audio devices on the ventana platform. |
| 27 | |
| 28 | A list of output sinks on the imx6: |
| 29 | * alsasink (recommended) |
| 30 | * autoaudiosink |
| 31 | * fakesink |
| 32 | * filesink |
| 33 | |
| 34 | |
| 35 | === alsasink === |
| 36 | This audio sink is our recommended audio sink. It can accept the following formats via {{{audio/x-raw}}}: S8, U8, S16LE, S16BE, U16LE, U16BE, S24_32LE, S24_32BE, U24_32LE, U24_32BE, S32LE, S32BE, U32LE, U32BE, S24LE, S24BE, U24LE, U24BE, S20LE, S20BE, U20LE, U20BE, S18LE, S18BE, U18LE, U18BE, F32LE, F32BE, F64LE, F64BE |
| 37 | |
| 38 | |
| 39 | === fakesink === |
| 40 | This is a very useful debugging sink. It takes whatever data is given to it and drops them. This might help debugging pipelines if problems ever arise. |
| 41 | |
| 42 | |
| 43 | === filesink === |
| 44 | This sink is very useful when a user wants to record and save audio to a file. |
| 45 | |
| 46 | |
| 47 | === autoaudiosink === |
| 48 | This GStreamer sink is not really an 'audio' sink in the traditional sense. Similar to {{{playbin}}} and {{{decodebin}}}, this element selects what it thinks is the best available audio sink and uses it. Generally not recommended. |
| 49 | |
| 50 | |
| 51 | === Examples === |
| 52 | The GStreamer {{{alsasink}}} element will playback a 1KHz tone to any Advanced Linux Sound Architecture (ALSA) device driver: |
| 53 | {{{#!bash |
| 54 | gst-launch-1.0 audiotestsrc ! alsasink device="hw:0,0" |
| 55 | }}} |
| 56 | * see [wiki:ventana/audio#devices here] for details on specifying audio input and output devices |
| 57 | |
| 58 | |
| 59 | [=#audio-input] |
| 60 | == Audio Input == |
| 61 | An input source is anything coming from a capture device on the SBC, e.g. HDMI audio in/analog audio in. Please refer to [http://trac.gateworks.com/wiki/ventana/audio this audio] page for more details on audio devices on the ventana platform. |
| 62 | |
| 63 | A list of input sources on the imx6: |
| 64 | * alsasrc (recommended) |
| 65 | * autoaudiosrc |
| 66 | * audiotestsrc |
| 67 | * filesrc |
| 68 | |
| 69 | |
| 70 | === alsasrc === |
| 71 | This is the recommended audio capture source when capturing audio onto the SBC. This plugin can output the following source types in {{{audio/x-raw}}}: S8, U8, S16LE, S16BE, U16LE, U16BE, S24_32LE, S24_32BE, U24_32LE, U24_32BE, S32LE, S32BE, U32LE, U32BE, S24LE, S24BE, U24LE, U24BE, S20LE, S20BE, U20LE, U20BE, S18LE, S18BE, U18LE, U18BE, F32LE, F32BE, F64LE, F64BE |
| 72 | |
| 73 | |
| 74 | === autoaudiosrc === |
| 75 | This GStreamer source is not really an 'audio' source in the traditional sense. Similar to {{{playbin}}} and {{{decodebin}}}, this element selects what it thinks is the best available audio source and uses it. Generally not recommended. |
| 76 | |
| 77 | |
| 78 | === audiotestsrc === |
| 79 | This is a very useful plugin for testing. It can output 16-64bit {{{audio/x-raw}}}: S16LE, S32LE, F32LE, F64LE |
| 80 | |
| 81 | This can output audio signals from {{{sine}}} to {{{violet-noise}}}. |
| 82 | |
| 83 | |
| 84 | === filesrc === |
| 85 | This source is very useful when a user wants to playback audio from a file. |
| 86 | |
| 87 | |
| 88 | === Examples === |
| 89 | The GStreamer {{{alsasrc}}} element will capture audio from any Advanced Linux Sound Architecture (ALSA) device driver: |
| 90 | {{{#!bash |
| 91 | gst-launch-1.0 alsasrc device="hw:0,0" ! "audio/x-raw,rate=32000,channels=2,depth=16" ! \ |
| 92 | audioconvert ! avimux ! filesink location=./audio.avi |
| 93 | }}} |
| 94 | * see [wiki:ventana/audio#devices here] for details on specifying audio input and output devices |
| 95 | |
| 96 | |
| 97 | [=#audio-encoding] |
| 98 | == Encoding == |
| 99 | Encoding is the term used to capture audio and encode it to a new format type. |
| 100 | |
| 101 | A list of audio encoders on the imx6 platform: |
| 102 | * {{{gstreamer-imx}}} specific |
| 103 | * imxmp3audioenc |
| 104 | * Other GStreamer encoders |
| 105 | * vorbisenc |
| 106 | * mulawenc |
| 107 | * wavenc |
| 108 | * alawenc |
| 109 | * flacenc |
| 110 | * lamemp3enc |
| 111 | |
| 112 | There are many more. You can search for your specified one by running a similar search: {{{gst-inspect-1.0 | grep enc}}}. |
| 113 | |
| 114 | |
| 115 | === imxmp3audioenc === |
| 116 | This encoder can encode {{{audio/x-raw}}} S16LE to {{{audio/mpeg}}}. |
| 117 | |
| 118 | |
| 119 | === vorbisenc === |
| 120 | This encoder can encode {{{audio/x-raw}}} F32LE to {{{audio/x-vorbis}}}. |
| 121 | |
| 122 | |
| 123 | === mulawenc === |
| 124 | This encoder can encode {{{audio/x-raw}}} S16LE to {{{audio/x-mulaw}}}. |
| 125 | |
| 126 | |
| 127 | === wavenc === |
| 128 | This encoder can encode {{{audio/x-raw}}} S32LE, S24LE, S16LE, U8, F32LE, F64LE, {{{audio/x-alaw}}}, and {{{audio/x-mulaw}}} to {{{audio/x-wav}}}. |
| 129 | |
| 130 | |
| 131 | === alawenc === |
| 132 | This encoder can encode {{{audio/x-raw}}} S16LE to {{{audio/x-alaw}}}. |
| 133 | |
| 134 | |
| 135 | === flacenc === |
| 136 | This encoder can encode {{{audio/x-raw}}} S24LE, S24_32LE, S16LE, S8 to {{{audio/x-flac}}}. |
| 137 | |
| 138 | |
| 139 | === lamemp3enc === |
| 140 | This encoder can encode {{{audio/x-raw}}} S16LE to {{{audio/mpeg}}}. |
| 141 | |
| 142 | |
| 143 | === Examples === |
| 144 | This will take in an audio source from the mic and save it as an mp3. |
| 145 | {{{#!bash |
| 146 | gst-launch-1.0 alsasrc device="hw:0,0" ! audioconvert ! imxmp3audioenc ! filesink location=/tmp/mic.mp3 |
| 147 | }}} |
| 148 | * Note the audioconvert element is used to convert audio samplerate / bitwidth / format (via software algorithms) as needed between two elements. |
| 149 | |
| 150 | |
| 151 | [=#audio-decoding] |
| 152 | == Decoding == |
| 153 | Decoding is the term used to decode an encoded audio stream to a raw audio stream. |
| 154 | |
| 155 | A list of audio encoders on the imx6 platform: |
| 156 | * {{{gstreamer-imx}}} specific |
| 157 | * imxuniaudiodec |
| 158 | * Other GStreamer encoders |
| 159 | * vorbisdec |
| 160 | * ivorbisdec |
| 161 | * a52dec |
| 162 | * mulawdec |
| 163 | * alawdec |
| 164 | * flacdec |
| 165 | |
| 166 | |
| 167 | === imxuniaudiodec === |
| 168 | This decoder can decode {{{audio/mpeg}}} to {{{audio/x-raw}}} S32LE, S24LE, S16LE, S8. |
| 169 | |
| 170 | |
| 171 | === vorbisdec === |
| 172 | This decoder can decode {{{audio/x-vorbis}}} to {{{audio/x-raw}}} F32LE. |
| 173 | |
| 174 | |
| 175 | === ivorbisdec === |
| 176 | This decoder can decode {{{audio/x-vorbis}}} to {{{audio/x-raw}}} S16LE. |
| 177 | |
| 178 | |
| 179 | === a52dec === |
| 180 | This decoder can decode {{{audio/x-ac3}}}, {{{audio/ac3}}}, and {{{audio/x-private1-ac3}}} to {{{audio/x-raw}}} F32LE. |
| 181 | |
| 182 | |
| 183 | === mulawdec === |
| 184 | This decoder can decode {{{audio/x-mulaw}}} to {{{audio/x-raw}}} S16LE. |
| 185 | |
| 186 | |
| 187 | === alawdec === |
| 188 | This decoder can decode {{{audio/x-alaw}}} to {{{audio/x-raw}}} S16LE. |
| 189 | |
| 190 | |
| 191 | === flacdec === |
| 192 | This decoder can decode {{{audio/x-flac}}} to {{{audio/x-raw}}} S8, S16LE, S24_32LE, S32LE. |
| 193 | |
| 194 | |
| 195 | === Examples === |
| 196 | We can decode the MP3 audio saved previously and playback to the default audio device with the following: |
| 197 | {{{#!bash |
| 198 | gst-launch-1.0 filesrc location=/tmp/mic.mp3 ! mpegaudioparse ! imxuniaudiodec ! alsasink |
| 199 | }}} |
| 200 | |
| 201 | |
| 202 | [=#audio-format] |
| 203 | == Audio Format Conversion == |
| 204 | In specify the details of the audio format, you use a GStreamer {{{capsfilter}}} and to convert it from one format to another you use the GStreamer {{{audioconvert}}} element. |
| 205 | {{{#!bash |
| 206 | gst-launch-1.0 alsasrc device="hw:0,0" ! "audio/x-raw,rate=32000,channels=2,depth=16" ! \ |
| 207 | audioconvert ! avimux ! filesink location=./audio.avi |
| 208 | }}} |
| 209 | |
| 210 | |
| 211 | [=#audio-loopback] |
| 212 | == Audio loopback (Useful for testing audio input and output) == |
| 213 | A simple aduio loopback test can take audio input from an input device and output it to an output device. |
| 214 | |
| 215 | loopback audio from the first audio card: |
| 216 | {{{#!bash |
| 217 | gst-launch-1.0 alsasrc device="hw:0,0" ! alsasink device="hw:0,0" |
| 218 | }}} |
| 219 | |
| 220 | To send audio from the sgtl5000 (analog input) to the imxhdmisoc (HDMI output): |
| 221 | * using device/function numbers (ie from {{{aplay -l}}}): |
| 222 | {{{#!bash |
| 223 | gst-launch-1.0 alsasrc device="hw:0,0" ! alsasink device="hw:2,0" |
| 224 | }}} |
| 225 | * or, using names (ie from {{{aplay -L}}}): |
| 226 | {{{#!bash |
| 227 | gst-launch-1.0 alsasrc device="sysdefault:CARD=sgtl5000audio" ! \ |
| 228 | alsasink device="sysdefault:CARD=imxhdmisoc" |
| 229 | }}} |
| 230 | |
| 231 | To send audio from the tda1997x HDMI receiver (digital input) to the imxhdmisoc (digital output): |
| 232 | {{{#!bash |
| 233 | gst-launch-1.0 alsasrc device="sysdefault:CARD=tda1997xaudio" ! \ |
| 234 | "audio/x-raw,rate=44100" ! alsasink device="sysdefault:CARD=imxhdmisoc" |
| 235 | }}} |
| 236 | * Note here we need to specify the audio sample-rate as it can vary per input stream (and gstreamer does not validate the rate). This rate must match the source stream samplrate which can be found via sysfs {{{/sys/bus/i2c/drivers/tda1997x/2-0048/audmode}}}. If your output device requires a different sample-rate than the source input device, you need to perform a sample-rate conversion. |