LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 10-06-2015, 11:10 AM   #1
giuliom_95
Member
 
Registered: Feb 2013
Distribution: Fedora
Posts: 47

Rep: Reputation: Disabled
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?
 
Old 10-06-2015, 02:43 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,915
Blog Entries: 13

Rep: Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948
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"
 
Old 10-06-2015, 03:53 PM   #3
giuliom_95
Member
 
Registered: Feb 2013
Distribution: Fedora
Posts: 47

Original Poster
Rep: Reputation: Disabled
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...
 
Old 10-06-2015, 04:22 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
i didnt know pifm could read from a stdin.

maybe using fifo's will help ?
 
Old 10-06-2015, 04:51 PM   #5
giuliom_95
Member
 
Registered: Feb 2013
Distribution: Fedora
Posts: 47

Original Poster
Rep: Reputation: Disabled
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 04:51 PM. Reason: Typo
 
Old 10-06-2015, 06:56 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
yes. using the mkfifo command you can set one program to write to a file and another to read from it at the same time.

i am curious, how you are calling pifm from within your script.
 
Old 10-07-2015, 04:40 AM   #7
giuliom_95
Member
 
Registered: Feb 2013
Distribution: Fedora
Posts: 47

Original Poster
Rep: Reputation: Disabled
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).
 
Old 10-07-2015, 05:27 AM   #8
giuliom_95
Member
 
Registered: Feb 2013
Distribution: Fedora
Posts: 47

Original Poster
Rep: Reputation: Disabled
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;
}
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decoding An audio coming live continuesly Jeetendra Programming 5 10-17-2013 11:26 AM
Help decoding tcpdump output crosstalk Linux - Networking 3 09-14-2010 12:05 PM
ffmpeg not decoding AC3 audio jroyce Linux - Software 3 11-23-2007 10:32 AM
error while decoding audio k3b linx win Linux - Software 6 06-10-2005 08:32 PM
Totem wont allow other programs to make audio output 43r05p4c3 Linux - Software 8 04-08-2005 08:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration