Home
Name Modified Size InfoDownloads / Week
readme.md 2020-12-23 4.4 kB
audiogram-c_0.2.tar.xz 2020-12-23 6.0 kB
owl_iso1.mp4 2020-12-11 497.3 kB
Totals: 3 Items   507.6 kB 0

Second version, fixed a couple bugs.

New discovery: if you use mpg123 with a -w argument you can convert MP3 files to WAV files. And --stereo will convert mono to stereo. Check the mpg123 man page. I fed a 1940 Bing Crosby recording through it successfully, started with an mp3. It doesn't handle input on stdin yet so you can't use it in a pipeline.


First: apt-get install libturbojpeg0 libturbojpeg0-dev ffmpeg

Then type make where the source and Makefile are.

Once everything's set up, type ./ag <filename>. If you've copied it to your executable path you don't need the ./ anymore.

The purpose of this program is to make video files from audio files because most social media platforms won't let you post audio since there are many MP3 files which are bootleg. I added a visual of a cursor moving across a waveform like in Audacity to make it slightly more interesting.

WAV files can be about as complex as TIFFs, this only deals with limited types: 16 bit signed integer data type, 2 channels, PCM data. The files this was written for were 44100 sample rate, but that should be flexible. I may eventually enhance it, maybe even link in a library to make it handle MP3 files and add a GTK GUI but don't hold your breath. It does what I wrote it for.

If you just read in a WAV file and plot it you get an envelope since you aren't seeing 44100 lines per second, you see the outline. It's much like looking at amplitude modulation (AM) on a radio signal. That's scaled to fit the "canvas" of the mp4 output file. From the WAV file header the program picks out the size of the PCM data and the sample rate in bytes/sec, from that it calculates the duration.

There's no graphics library involved, it works like framebuffer graphics. You allocate (and zero) memory of an amount that's (width * height * 3) bytes. There's a virtual/imaginary X and Y. The memory offset within the chunk you alllocated is (width * 3 * Y) + (3 * X). The 3 is because this is 24-bit color with 3 bytes per pixel. The first byte you write at each address becomes red, the next green, the last blue. The next pixel starts 3 bytes later. You should be able to change the definitions for height, width, frame rate and colors without breaking anything.

Duration in seconds * frame rate gives the number of still images needed. Each starts as a copy of the image with the waveforms, then gets a cursor line drawn on it. If you divide the width by the number of frames that gives the number of pixels to move the cursor per frame.

This uses the turbo jpeg library to compress each image in memory into a jpeg file, which are named with leading zeroes to stay in the correct order. ffmpeg is then called to change the sequence of images plus the orignal audio file into a video file. The images and directory they were in are deleted at the end. The ".wav" is taken off the original filename, replaced with ".mp4", and that becomes the name of the output file. In the directory with the image files a temporary bash script is written which drives ffmpeg.

That's the way it should work. It was written under Debian Linux with bash, although I left it out of the script. sh, tcsh, etc. may work. I don't think I used any Linuxisms, I used to be an OpenBSD guy. You absolutely need TurboJPEG with headers and libraries, or replace buf2jpg. ffmpeg is unique, but based on mencoder which worked about the same as far as this is concerned. GCC can be replaced with clang's cc in the Makefile. Type make to compile, then copy ag someplace in your path like /usr/local/bin.

The program spits out a few mostly diagnostic messages which you can ignore. If something goes wrong so you want to look at them scroll up, use shift-PgUp in Linux. Or redirect them to a file like: ./ag myfile.wav &> mylog.txt Most are left over from when I was writing it and not that useful, but there are error messages like if it couldn't find a file. ffmpeg also spits out a bunch. To get an idea of ffmpeg's progress watch the time= column, which is file (recording) time. And remember, the source code is always the ultimate documentation for most software.

With ffmpeg comes ffplay, which is kind of a reference player that does video and audio files, try ffplay -h. There's a man page but that didn't come with the deb, try the web.

Source: readme.md, updated 2020-12-23