How to output MP3s to a sound card - linux

I'm trying to write some code in perl (specifically) to output sound (specifically, MP3s) to my sound card. I've not seen any examples of outputting any sound to the soundcard in perl, so examples of that would be helpful.
My question is, how do audio players output sound to the sound card? Do they convert them to WAV on the fly?

SDL::Sound solves this problem for WAV files. There are several packages for converting compressed MP3 files to WAV, such as Audio::MPEG and Audio::ConvTools.

Are you on Linux? If so you can do your logic in Perl and then shell out to some command line player, like mpg123. Not a pure Perl solution, but gets the job done.

Related

File information of .raw audio files using terminal in linux

How to get file information like sampling rate, bit rate etc of .raw audio files using terminal in linux? Soxi works for .wav files but it isn't working for .raw.
If your life depended on discovering an answer you could make some assumption to tease apart the unknowns ... however there is no automated way since the missing header would give you the easy answers ...
The audio analysis tool called audacity allows you to open up a RAW file, make some guesses and play the track
http://www.audacityteam.org
In audacity goto File -> Import -> Raw Data...
Above settings are typical for audio ripped from a CD ... toy with trying stereo vs mono for starters.
Those picklist widgets give you wiggle room to discover the format of your PCM audio given that the source audio is something when properly rendered is recognizable ... would be harder if the actual audio was noise
However if you need a programmatic method then rolling your own solution to ask those same questions which appear in above window is possible ... is that what you need or will audacity work for you ? We can go down the road of writing code to play off the unknowns mentioned in #Frank Lauterwald's comment
To kick start discovering this information programmatically, if the binary raw audio is 16 bit then each audio sample (point on the audio curve) will consume two bytes of your PCM file. For mono audio then the following two bytes would be your next sample, however if its stereo then these two following bytes would be the sample from the other channel. If more than two channels then just repeat. Typical audio is little endian. Sampling rate is important when rendering the audio, not when programmatically parsing raw bytes. One approach would be to create an output file with a WAV header followed by your source PCM data. Populate the header with answers from your guesswork. This way you could listen to this output file to help confirm your guesses.
Here is a sample 500k mono PCM audio file signed 16 bit which can be imported into audacity or used as input to rolling your own identification code
The_Constructus_Corporation_Long_Street-ycexQvMy03k_excerpt_mono.pcm

How to convert a swf to mp4/flv or so with command line?

I'm going to convert a swf to mp4/flv or so with batch line in linux.
I've tried ffmpeg, mencoder or a perl script FLV::info. But all these convert just the video in the swf(maybe encoded by H.263 or so) to a new video, but no movie clips, not mention the ActionScripts.
I find moyea seems to fit my needs(however, I need linux ones), but is there any free ways to do this?
Many thanks.

What is the algorithm to convert an mp3 file to a wav file?

What is the algorithm to convert an mp3 file to a wav file?
It's non-trivial to say the least. You could get an overview of the algorithm here:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.26.5956&rep=rep1&type=pdf
But I would suggest using a library for your programming needs, for example:
http://www.ffmpeg.org/
As for the mp3 file, I can offer you mpg123 .net wrapper that is extremely easy to use - you will get the sample for reading the mp3, extracting PCM information from it (this is main part of WAV file - PCM data for the sound).
Please, go here:
http://sourceforge.net/projects/mpg123net/
and download sample code from here:
http://sourceforge.net/projects/mpg123net/files/
Ping me if you need more info/help on the subject.
As aac files are concerned, there is faad project here:
http://www.audiocoding.com/faad2.html
that enables you to do the same with the aac file. If you need .net wrapper, I'm about to put it on sourceforge also.

Saving V4L2 video camera output

What video format would be the easiest when saving the output of a camera using V4L2 if I capture it in bitmap format? Getting mpeg directly could be, of course, nice, but I can't unfortunately count on that.
I have managed to capture the frames, now I need to somehow view the video. Can I simply convert those frames using some Linux tool or could I save the video easily straight from my app?
To keep things simple (as in a Proof-of-Concept demo), you can go ahead and directly store the YUV frames captured from the device into a file.
There are a bunch of viewers that support playback of single/multiple frame(s) of YUV data from a file.
One such YUV viewer is freecode.com/projects/yay
You could use practically any format/codec if you used mencoder or ffmpeg
Btw, this question really should be on superuser.com
If you are capturing frames already, you could save them to PPM images and then go to JPEG. I did this using v4l2 and ImageMagick. Maybe you could push JPEGs into a Motion JPEG stream. It might not be as high tech as MPEG, but you might get it working quickly. PPM files were a cinch to create. If I remember correctly, the v4l2 example code shows you how to do that part.

Multiple audio streams in a MPEG-4 file

The MPEG-4 file format allows multiple streams to be present in a file.
This is useful for videos containing audio in multiple languages. In the case of such a video, the audio streams are synchronized to the video.
Is it possible to create a MPEG-4 file the contains desynchronized audio streams, i.e. the audio track are played on after another?
I want to design a MPEG-4 file that contains a music album, so it is crucial that the tracks are played one after another by media players such as VLC.
When I use MP4Box (from the GPAC framework) the resulting file is recognised by VLC as having synchronized audio streams. Which box of the MPEG-4 file format is responsible for this? Or how can I tell VLC that these audio streams are not synchronized?
Thanks in advance!
I can think of two ways you could do that, and both would be somewhat problematic.
You could concatenate all the audio streams into one audio track in the MP4 file. This won't be ideal, for some obvious reasons. For one thing, it's not exactly what you were asking for.
You could also just store the tracks as synchronized audio streams, but set the timing information in such a way that the first sample of the second track won't start playing until the first track finished playing, etc.
I'm not aware of any tools that can do this, but the file format will support such a scheme. Since it's an unusual way to store audio in an MP4 file, I would expect players to have problems with this, too.
Concatenating all streams would work and the individual tracks can be addressed by adding chapters. It works at least with VLC.
MP4Box -new -cat track1.m4a -cat track2.m4a -chap chapters.txt album.m4a
The chapters.txt would look something like this:
CHAPTER1=00:00:00.00
CHAPTER1NAME=Track 1
CHAPTER2=00:03:40.00
CHAPTER2NAME=Track 2
But this is only a hack.
The solution I'm looking for should preserve the tracks as individual streams.

Resources