Hello,

I added variables tot he pipe output command that will be substituted by the
real values of the input stream. I use it to control a filter chain
consisting of SOX, BruteFIR etc. for an active crossover. 

 

These keywords are supported in the pipe command:

 

$bits = bit depth of stream

$channels = number of channels

$samplerate = sample rate

 

Maybe someone can review it and add it to source control.

 

 

Here ist the diff:

 

 

 

@@ -25,6 +25,7 @@

 

#include <string>

#include <stdexcept>

+#include <sstream>

 

#include <stdio.h>

 

@@ -64,12 +65,42 @@

        return new PipeOutput(block);

}

 

-inline void

-PipeOutput::Open(gcc_unused AudioFormat &audio_format)

-{

-       fh = popen(cmd.c_str(), "w");

+static void replaceString(std::string &str, const std::string &from, const
std::string &to) {

+       if(from.empty())

+               return;

+       size_t start_pos = 0;

+       while((start_pos = str.find(from, start_pos)) != std::string::npos)
{

+               str.replace(start_pos, from.length(), to);

+               start_pos += to.length(); // In case 'to' contains 'from',
like replacing 'x' with 'yx'

+       }

+}

+

+inline void PipeOutput::Open(gcc_unused AudioFormat &audio_format) {

+       std::string replacedString = cmd;

+        std::string bits = "16";

+        std::ostringstream channels;

+        std::ostringstream sampleRate;

+

+        switch(audio_format.format)

+        {

+        case SampleFormat::S8: bits = "8"; break;

+        case SampleFormat::S16: bits = "16"; break;

+        case SampleFormat::S24_P32:

+        case SampleFormat::S32: bits = "32"; break;

+        case SampleFormat::FLOAT: bits = "FLOAT_32"; break;

+        case SampleFormat::DSD: bits = "DSD"; break;

+        default: break;

+        }

+        channels << (uint32_t)audio_format.channels;

+        sampleRate << audio_format.sample_rate;

+

+        replaceString(replacedString,"$bits", bits); //format

+        replaceString(replacedString,"$channels", channels.str());
//channels

+        replaceString(replacedString,"$samplerate", sampleRate.str());
//sample rate

+

+       fh = popen(replacedString.c_str(), "w");

        if (fh == nullptr)

-               throw FormatErrno("Error opening pipe \"%s\"", cmd.c_str());

+               throw FormatErrno("Error opening pipe \"%s\"",
replacedString.c_str());

}

_______________________________________________
mpd-devel mailing list
[email protected]
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to