Commit b0b7371e authored by Stefan Westerfeld's avatar Stefan Westerfeld

Use Error objects in WavData::save().

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 9324da9b
......@@ -1967,9 +1967,10 @@ gentest (const string& infile, const string& outfile)
out_signal.push_back (in_signal[i + offset]);
}
WavData out_wav_data (out_signal, wav_data.n_channels(), wav_data.sample_rate(), wav_data.bit_depth());
if (!out_wav_data.save (outfile))
err = out_wav_data.save (outfile);
if (err)
{
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), out_wav_data.error_blurb());
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1;
}
return 0;
......@@ -1994,9 +1995,10 @@ cut_start (const string& infile, const string& outfile, const string& start_str)
out_signal.push_back (in_signal[i]);
WavData out_wav_data (out_signal, wav_data.n_channels(), wav_data.sample_rate(), wav_data.bit_depth());
if (!out_wav_data.save (outfile))
err = out_wav_data.save (outfile);
if (err)
{
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), out_wav_data.error_blurb());
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1;
}
return 0;
......@@ -2038,9 +2040,10 @@ test_subtract (const string& infile1, const string& infile2, const string& outfi
out_signal.push_back (in1_signal[i] - in2_signal[i]);
WavData out_wav_data (out_signal, in1_data.n_channels(), in1_data.sample_rate(), in1_data.bit_depth());
if (!out_wav_data.save (outfile))
err = out_wav_data.save (outfile);
if (err)
{
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), out_wav_data.error_blurb());
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1;
}
return 0;
......
......@@ -8,7 +8,6 @@
#include <memory>
#include <math.h>
#include <sndfile.h>
using std::string;
using std::vector;
......@@ -66,7 +65,7 @@ WavData::load (const string& filename)
return Error::Code::NONE;
}
bool
Error
WavData::save (const string& filename)
{
std::unique_ptr<AudioOutputStream> out_stream; // FIXME: virtual constructor
......@@ -75,18 +74,13 @@ WavData::save (const string& filename)
out_stream.reset (sostream);
Error err = sostream->open (filename, m_n_channels, m_sample_rate, m_bit_depth, m_samples.size() / m_n_channels);
if (err)
{
m_error_blurb = err.message();
return false;
}
return err;
err = sostream->write_frames (m_samples);
if (err)
{
m_error_blurb = err.message();
return false;
}
return true;
return err;
return Error::Code::NONE;
}
int
......@@ -106,9 +100,3 @@ WavData::set_samples (const vector<float>& samples)
{
m_samples = samples;
}
const char *
WavData::error_blurb() const
{
return m_error_blurb.c_str();
}
......@@ -12,18 +12,16 @@ class WavData
int m_sample_rate = 0;
int m_n_channels = 0;
int m_bit_depth = 0;
std::string m_error_blurb;
public:
WavData();
WavData (const std::vector<float>& samples, int n_channels, int sample_rate, int bit_depth);
Error load (const std::string& filename);
bool save (const std::string& filename);
Error save (const std::string& filename);
int sample_rate() const;
int bit_depth() const;
const char *error_blurb() const;
int
n_channels() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment