[SOLVED] Question on the output of audio decoding programs.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Question on the output of audio decoding programs.
Hi all,
I've noticed that a lot of audio decoding command-line programs (such as flac, mpg123 or ffmpeg) have the possibility to "print" the decoded sound to stdout. What is the format of this output and where can I find more information about it?
I think that depends on the particular decoder you're using. And when you decode something or convert it, such as MP4 to MP3, then the "output" is MP3. Be that binary or Ascii it doesn't matter. "Seeing" it on stdout may be useless. For one, it'll just zip by, especially if it's large. Better to redirect via > to a file. That may be the intention, something like "convert input.mp4 > output.mp3"
Thanks for answer,
Actually I need that stdout output because a program need it...
I think that is better explain what I'm trying to achieve.
There is this program, pifm, that turns a Raspberry PI board in a FM transmitter: it normally broadcasts wav files but it can also "read" audio from stdin. Now I want to write a program that, thanks to a ncurses GUI, let me do some basic operations like broadcasting the DJ's voice while a song starts in the background. In order to do that I need to know how to overlap the voice with the music and print the result to stdout...
I'm almost a newbie so don't kill me if I don't know what fifo is... Do you mean first-in first-out structures? And if that so, how can I use them in this case?
Last edited by giuliom_95; 10-06-2015 at 03:51 PM.
Reason: Typo
Can you make an example on usage of mkfifo and fifo commands?
However, I'm planning to call pifm with something like:
Code:
$ ./radiogui | sudo ./pifm - 98 96000
and radiogui is a C-written program which prints continuously to stdout the outputs of commands like "flac -dc music/01.flac", "mpg123 -s music/02.mp3" or "arecord -d0 -c2 -f S16_LE -r 96000 -twav -D copy", depending on the user input.
Now, I want to enhance this program by adding the possibility to print the overlapped output of two commands (probably flac and arecord) while turning down the volume of one of these two streams (if we can call them this way).
Ok I've found the solution. I can simply arithmetically add one output to one other in order to broadcast from two files and I can turn down the volume by subtracting an integer to the output. Here's an example code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] ) {
FILE *fp1, *fp2;
fp1 = popen("/usr/bin/flac -dc 1.flac", "r");
fp2 = popen("/usr/bin/mpg123 -s 2.mp3", "r");
if( fp1 == NULL || fp2 == NULL ) {
printf("Failed to run command\n" );
exit(1);
}
//Reads the output until one of two streams ends.
while( feof( fp1 ) == 0 || feof( fp2 ) == 0 ) {
//"Prints" the flac almost silenced and the mp3 at full volume.
printf("c", ( fgetc( fp1 ) - 30 ) + fgetc( fp2 ));
}
pclose(fp1);
pclose(fp2);
return 0;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.