Skip to content

Commit

Permalink
* removed usage of c++11 features to make crusty old compilers happy
Browse files Browse the repository at this point in the history
  • Loading branch information
beschulz committed Feb 25, 2015
1 parent 5d863a5 commit 22b676b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $(SRC)/version.hpp: Makefile version.txt

$(BINARY): $(SRC)/*.cpp $(SRC)/*.hpp $(SRC)/version.hpp
mkdir -p `dirname $(BINARY)`
$(CC) -O3 -Wall -Werror -std=c++11 $(SRC)/*.cpp $(INCLUDES) $(LD_PLATFORM_FLAGS) -o $(BINARY)
$(CC) -O3 -Wall -Werror $(SRC)/*.cpp $(INCLUDES) $(LD_PLATFORM_FLAGS) -o $(BINARY)

../examples/%.json : ../example_data/%.wav
$(BINARY) $+ --precision 2 --channels left right mid side min max -o $@
Expand Down
49 changes: 34 additions & 15 deletions src/wav2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ T compute_sample(const std::vector<T>& block, int i, int n_channels, Options::Ch
return T(0);
}


/* functor to filter out invalid channels
* lambdas would be nicer, but hey, it' 2015 :)
* */
struct filter_invalid_channels
{
filter_invalid_channels(const SndfileHandle& wav, std::ostream& output_stream)
:wav(wav), output_stream(output_stream){}

bool operator () (Options::Channel channel)
{
if ((channel == Options::MID ||
channel == Options::SIDE ||
channel == Options::RIGHT||
channel == Options::MIN ||
channel == Options::MAX) &&
wav.channels() == 1
)
{
output_stream << " \"" << channel << "\":[]," << std::endl; // output empty array, so that existing client-code does not break
std::cerr << "Warning: your trying to generate output for channel '" << channel << "', but the input has only one channel. removing requested channel." << std::endl;
return true;
}
return false;
}

private:
const SndfileHandle& wav;
std::ostream& output_stream;
};


/*
compute the waveform of the supplied audio-file and store it into out_image.
*/
Expand Down Expand Up @@ -112,22 +144,9 @@ void compute_waveform(
std::vector<sample_type> block(samples_per_pixel);

// filter out channels, that require more channels than the wav file has
filter_invalid_channels filter(wav, output_stream);
channels.erase(
std::remove_if(channels.begin(), channels.end(), [&wav, &output_stream](Options::Channel channel){
if ((channel == Options::MID ||
channel == Options::SIDE ||
channel == Options::RIGHT||
channel == Options::MIN ||
channel == Options::MAX) &&
wav.channels() == 1
)
{
output_stream << " \"" << channel << "\":[]," << endl; // output empty array, so that existing client-code does not break
std::cerr << "Warning: your trying to generate output for channel '" << channel << "', but the input has only one channel. removing requested channel." << std::endl;
return true;
}
return false;
}),
std::remove_if(channels.begin(), channels.end(), filter),
channels.end()
);

Expand Down

0 comments on commit 22b676b

Please sign in to comment.