Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Wavegain an album from STDIN? (Read 5630 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Wavegain an album from STDIN?

I've got a bit of a weird desire this time

What I want to be able to do is wavegain an album's worth of tracks, but all without creating temporary files.  Let me explain...

I have some source files, possibly in a variety of formats.  I convert them all to wav, and run wavegain in album mode to calculate track and album gain values.  I then delete the temporary files.

I'd like to be able to avoid the temporary files.  Either by using stdin, and somehow including a "new track starts now" flag between the tracks, or perhaps by having wavegain be able to take a list of commands to run to receive the track data on stdin.

Any thoughts if this is possible?

X

Wavegain an album from STDIN?

Reply #1
Calculating ReplayGain requires all of the wav file's audio.  Applying ReplayGain requires the calculated gain values and all of the wav file's audio.  So since you'll need two passes of that audio data, that means either a temporary file on disk, storing it all in memory, or piping the data twice.

Wavegain an album from STDIN?

Reply #2
Calculating ReplayGain requires all of the wav file's audio.  Applying ReplayGain requires the calculated gain values and all of the wav file's audio.  So since you'll need two passes of that audio data, that means either a temporary file on disk, storing it all in memory, or piping the data twice.


I'm only interested in calculating gain, not applying it, so I only need a single pass of audio.  Any ideas anyone?


Wavegain an album from STDIN?

Reply #4
I'm only interested in calculating gain, not applying it, so I only need a single pass of audio.  Any ideas anyone?

In my "mk_mp3 shell script" I'm using wavegain like this:
Code: [Select]
ALBUM_GAIN=`wavegain -x -a "${_cd}"/ 2>/dev/null`



That looks good, but isn't that working on .wav files?  My issue is that I will have the audio coming from the result of several different conversion tools potentially.

Wavegain an album from STDIN?

Reply #5
Can't test it right now, but eventually you can let wavegain read from stdin, '-' as input file.
What you need is, command line decoders, that decode your files to stdout, ie "flac -d -c test.flac | wavegain -c -"

Wavegain an album from STDIN?

Reply #6
Can't test it right now, but eventually you can let wavegain read from stdin, '-' as input file.
What you need is, command line decoders, that decode your files to stdout, ie "flac -d -c test.flac | wavegain -c -"


Yes, that works great for a single track at a time.  My problem is I want to album gain several tracks from stdin, and I don't seem to be able to work out a way to do that.

Thanks,
x

Wavegain an album from STDIN?

Reply #7
I've got a bit of a weird desire this time :)

What I want to be able to do is wavegain an album's worth of tracks, but all without creating temporary files.  Let me explain...

I have some source files, possibly in a variety of formats.  I convert them all to wav, and run wavegain in album mode to calculate track and album gain values.  I then delete the temporary files.

I'd like to be able to avoid the temporary files.  Either by using stdin, and somehow including a "new track starts now" flag between the tracks, or perhaps by having wavegain be able to take a list of commands to run to receive the track data on stdin.

Any thoughts if this is possible?

X


I've solved this myself now.  I finally managed to get wavegain to build on mingw on windows, and then I made a couple of changes.
1. I turned off ENABLE_RECURSIVE in config.h - it didn't work with my change, and I never use that anyway
2. I changed wavegain.c get_gain function, from
[font= "Courier New"]
   if(!strcmp(filename, "-")) {
      infile = stdin;
      settings->apply_gain = 0;
      wg_opts->std_in = 1;
#ifdef _WIN32
      _setmode( _fileno(stdin), _O_BINARY );
#endif
   }
   else
      infile = fopen(filename, "rb");

[/font]
to
[font= "Courier New"]
   if(!strcmp(filename, "-")) {
      infile = stdin;
      settings->apply_gain = 0;
      wg_opts->std_in = 1;
#ifdef _WIN32
      _setmode( _fileno(stdin), _O_BINARY );
#endif
   }
    else if (filename[0] == '^') {
        r = strrchr(filename + 1, '^');
        if ® { r[0] = '\0'; };
        fprintf(stderr, "Running \"%s\"\n", filename + 1);
        infile = popen(filename + 1, "rb");
        if ® { r[0] = '\\'; };
        settings->apply_gain = 0;
        wg_opts->std_in = 1;
    }
   else
      infile = fopen(filename, "rb");
[/font]

This allows you to specify multiple filenames on the command-line, which are actually commands to run to get the audio data, for example:
wavegain -a "^flac -d -c foo.flac" "^lame --decode bar.mp3 -"

The messing around with r is so that you can specify a fake filename for the input command, which gets reported if you use -e.  I needed this.  It works like:
wavegain -a "^flac -d -c foo.flac^foo.wav" "^lame --decode bar.mp3 -^bar.wav"

I hope this is useful to someone else!

X

Wavegain an album from STDIN?

Reply #8
wavegain -a "^flac -d -c foo.flac^foo.wav" "^lame --decode bar.mp3 -^bar.wav"

You may have considered using "r128gain" (http://r128gain.sourceforge.net/):

Code: [Select]
r128gain --rg foo.flac bar.mp3

"r128gain" comes with the ReplayGain algorithm taken 1:1 from "wavegain" encapsulated in "libreplaygain.dll" (win32) or "libreplaygain.so" (linux).

"r128gain" automatically uses the decoders from FFmpeg (http://ffmpeg.org/) for each supported format/codec (that's almost all).

In order to enable MP3 in "r128gain" you have to upgrade the FFmpeg DLLs from the sub-directory "r128gain-tools" with their counterparts taken from the latest build from Zeranoe: http://ffmpeg.zeranoe.com/builds/win32/shared/.

Wavegain an album from STDIN?

Reply #9
wavegain -a "^flac -d -c foo.flac^foo.wav" "^lame --decode bar.mp3 -^bar.wav"

You may have considered using "r128gain" (http://r128gain.sourceforge.net/):


Interesting.  Does it have the ability to only take as input a section of audio from one of the source files?  My particular use case involves extracting individual tracks from single-file wavpack albums using getaudio

Wavegain an album from STDIN?

Reply #10
Does it have the ability to only take as input a section of audio from one of the source files?  My particular use case involves extracting individual tracks from single-file wavpack albums using getaudio

I'm not certain what you mean. Are you talking about "a CUESHEET field in the APEv2 tag" as described in the wavpack documentation (http://www.wavpack.com/wavpack_doc.html)?

Wavegain an album from STDIN?

Reply #11
Does it have the ability to only take as input a section of audio from one of the source files?  My particular use case involves extracting individual tracks from single-file wavpack albums using getaudio

I'm not certain what you mean. Are you talking about "a CUESHEET field in the APEv2 tag" as described in the wavpack documentation (http://www.wavpack.com/wavpack_doc.html)?


Not quite - I have an external list of sections of a wavpack file (and/or other formats) that I want gain.  There's a tool called getaudio (dunno where I got it from) that allows use like:
getaudio --begin 02:31:15 --end 04:01:00 inputfile.wv
Those begin/end times did originally come from a cuesheet, but aren't in that format any more.


Wavegain an album from STDIN?

Reply #12
I have an external list of sections of a wavpack file (and/or other formats) that I want gain.  There's a tool called getaudio (dunno where I got it from) that allows use like:
getaudio --begin 02:31:15 --end 04:01:00 inputfile.wv
Those begin/end times did originally come from a cuesheet, but aren't in that format any more.

Unfortunately "r128gain" currently doesn't support something like this.