Linux: how to dump audio output PCM bit stream like tcpdump - linux

I am trying to do some audio debugging on my Linux system.
I learned how to record the sound of the current playing media but how can I get the PCM data without DAC/ADC?
I mean, just like wireshark or tcpdump tool, is there some sort of alsadump that I can make use of?
I want to do bit-exact comparison of the output PCM data to make sure the audio processing algorithm (which is an executable binary) worked correctly.
Thanks a lot.

Related

Capturing PCM audio data stream into file, and playing stream via ffmpeg, how?

Would like to do following four things (separately), and need a bit of help understanding how to approach this,
Dump audio data (from a serial-over-USB port), encoded as PCM, 16-bit, 8kHz, little-endian, into a file (plain binary data dump, not into any container format). Can this approach be used:
$ cat /dev/ttyUSB0 > somefile.dat
Can I do a ^C to close the file writing, while the dumping is in progress, as per the above command ?
Stream audio data (same as above described kind), directly into ffmpeg for it to play out ? Like this:
$ cat /dev/ttyUSB0 | ffmpeg
or, do I have to specify the device port as a "-source" ? If so, I couldn't figure out the format.
Note that, I've tried this,
$ cat /dev/urandom | aplay
which works as expected, by playing out white-noise..., but trying the following doesn't help:
$ cat /dev/ttyUSB1 | aplay -f S16_LE
Even though, opening /dev/ttyUSB1 using picocom # 115200bps, 8-bit, no parity, I do see gibbrish, indicating presence of audio data, exactly when I expect.
Use the audio data dumped into the file, use as a source in ffmpeg ? If so how, because so far I get the impression that ffmpeg can read a file in standard containers.
Use pre-recorded audio captured in any format (perhaps .mp3 or .wav) to be streamed by ffmpeg, into /dev/ttyUSB0 device. Should I be using this as a "-sink" parameter, or pipe into it or redirect into it ? Also, is it possible that in 2 terminal windows, I use ffmpeg to capture and transmit audio data from/into same device /dev/ttyUSB0, simultaneously ?
My knowledge of digital audio recording/processing formats, codecs is somewhat limited, so not sure if what I am trying to do qualifies as working with 'raw' audio or not ?
If ffmpeg is unable to do what I am hoping to achieve, could gstreamer be the solution ?
PS> If anyone thinks that the answer could be improved, please feel free to suggest specific points. Would be happy to add any detail requested, provided I have the information.

How to read video file using v4l2

I want to read a video file using v4l2, say an AVI file. And read it frame by frame.
As far as I can tell I need to use the read() function. But how isn't very clear to me. There are also hardly any examples available. So maybe a simple example on how to do this would help.
This is not what the Video4Linux2 (V4L2) API is for. It is not designed for reading multimedia files from disk, decoding them and playing them. Rather, it is designed to interface to assorted multimedia input devices (like webcams, microphones, TV tuners, and video capture devices), capture A/V data, and play it.
Take it from the V4L2 API introduction:
Video For Linux Two is [...] a kernel interface for analog radio and
video capture and output drivers.
For reading an AVI file and decoding/playing it (programmatically) on Linux, look into FFmpeg or GStreamer.

How to capture voice PCM data over a serial port and process?

I have a telephony modem (SIM5320EVB) which gives voice data on ttyUSB0 as PCM with 1600 bytes each 100ms.Iam able to see the data on minicom. How to capture the PCM data in linux (i use ubuntu)and hear it live on the fly or atleast save and play the data? Is there any application available or API? If the approach atleast is suggested I will try developing one..
cat /dev/ttyUSB0 > my_cap_file
# make some noise for 5s for example, then hit ^C
then get Audacity and try to open your file with it, trying different input formats. You should be able to hear the sound you produced if you will guess the right format.
Install sox for the play command and use: play -r 8000 -c 1 -t raw -e signed-integer -b 16 /dev/ttyUSB0. That is: bit rate 8KHz, 1 channel (mono), raw data (PCM), format is signed integer 16 bits wide, and data can be read from ttyUSB0.
That requires sox to be able to play audio on your system; I've had success with pulseaudio for the underlying sound system.
You may need to modify the buffer size for play. By default, it buffers data which creates a small but very noticeable delay.

How to retrieve H263/H264 data from a pcap file.

I have tried tools like videosnarf that takes a pcap file as input and creates a raw .h264 file , which could be later encoded with ffmpeg , and finally can be played with vlc player. But videosnarf can only handle h264 data.
I'm not able to find a similar tool that can dump h263 data from a pcap file. I tried to decode h263 stream from wireshark but I have had no luck so far.
I can program in perl/python but I don't know what exact steps to follow to retrieve h263 raw data from a pcap file as I haven't played with pcap capture files before.
sjd,
You can try setting up a sniffer using Twisted Python library (Twisted) this would allow you to capture the raw data coming in over your network as long as you can tell Twisted what port to listen to (or listen all), and where to dump the file to, etc and then do something with that new file (like send it into ffmpeg to test saving to .mov).
You would have to generate the .sdp file for ffmpeg, so unless you automate that step of the process, it is really annoying. I am currently working on the automation portion but am struggling just as much.
I'm using EventMachine for Ruby with FFMPEG, and .sdp from SIP.
Hope this helps a little.

Convert raw PCM stream to wavs (cli)

I need a program that I can pipe a raw PCM stream into, and will send wav files to stdout.
Since the input is a stream, I can't just add headers to it, but I can for every x seconds (For example, program reads ten seconds of the stream, and outputs a ten second long wav file, reads the next ten seconds, outputs a wav file, and so on).
Is there a program that can do this? It needs to run on Linux.
Check out sox, the Swiss Army knife of sound processing.
This is a dead simple program to write, in fact, if you can guarantee exactly the same number of bytes of PCM data in each wave file, you can just pre-create a standard wave file header for that amount of PCM data and then just cat wavehdr + chunk-of-streamdata
mplayer is quite good for this kind of tasks. It comes with two interface, mencoder and mplayer. mencoder as all the command line switch you want to transform raw pcm into various sound format.
It also come with a very long man page that explains all the options quite well.

Resources