From 1c8e6a8344830f60d7858903fb6dac142520661d Mon Sep 17 00:00:00 2001 From: Benjamin Schulz Date: Wed, 25 Feb 2015 21:16:57 +0100 Subject: [PATCH] * outputting empty son-array, if the requested channel cannot be generated (because there are not enough channels). This is done, so that client-side javascript code does not break. --- examples/test1.json | 5 +++++ src/wav2json.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/test1.json b/examples/test1.json index cee59e6..8d015e7 100644 --- a/examples/test1.json +++ b/examples/test1.json @@ -1,5 +1,10 @@ { "_generator":"wav2json version 0.4 on Darwin (http://goo.gl/af7wg)", + "right":[], + "mid":[], + "side":[], + "min":[], + "max":[], "left": [0,0.5,0.87,1,0.87,0.5,0,0.5,0.87,0,0.87,0.5], "duration":0.000250 } diff --git a/src/wav2json.cpp b/src/wav2json.cpp index 33c1d6f..39c9211 100644 --- a/src/wav2json.cpp +++ b/src/wav2json.cpp @@ -113,7 +113,7 @@ void compute_waveform( // filter out channels, that require more channels than the wav file has channels.erase( - std::remove_if(channels.begin(), channels.end(), [&wav](Options::Channel channel){ + std::remove_if(channels.begin(), channels.end(), [&wav, &output_stream](Options::Channel channel){ if ((channel == Options::MID || channel == Options::SIDE || channel == Options::RIGHT|| @@ -122,6 +122,7 @@ void compute_waveform( 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; }