Commit cad2f6e2 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Use Error object as result for SFOutputStream open().

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent b046b704
...@@ -1287,9 +1287,10 @@ add_watermark (const string& infile, const string& outfile, const string& bits) ...@@ -1287,9 +1287,10 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{ {
SFOutputStream *sfostream = new SFOutputStream(); SFOutputStream *sfostream = new SFOutputStream();
out_stream.reset (sfostream); out_stream.reset (sfostream);
if (!sfostream->open (outfile, in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames())) Error err = sfostream->open (outfile, in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames());
if (err)
{ {
error ("audiowmark: error writing to %s\n", outfile.c_str()); // FIXME, sfostream->error_blurb()); error ("audiowmark: error writing to %s: %s\n", outfile.c_str(), err.message());
return 1; return 1;
} }
} }
......
...@@ -12,7 +12,7 @@ SFOutputStream::~SFOutputStream() ...@@ -12,7 +12,7 @@ SFOutputStream::~SFOutputStream()
close(); close();
} }
bool Error
SFOutputStream::open (const string& filename, int n_channels, int sample_rate, int bit_depth, size_t n_frames) SFOutputStream::open (const string& filename, int n_channels, int sample_rate, int bit_depth, size_t n_frames)
{ {
assert (m_state == State::NEW); assert (m_state == State::NEW);
...@@ -39,14 +39,14 @@ SFOutputStream::open (const string& filename, int n_channels, int sample_rate, i ...@@ -39,14 +39,14 @@ SFOutputStream::open (const string& filename, int n_channels, int sample_rate, i
int error = sf_error (m_sndfile); int error = sf_error (m_sndfile);
if (error) if (error)
{ {
m_error_blurb = sf_strerror (m_sndfile); string msg = sf_strerror (m_sndfile);
if (m_sndfile) if (m_sndfile)
sf_close (m_sndfile); sf_close (m_sndfile);
return false; return Error (msg);
} }
m_state = State::OPEN; m_state = State::OPEN;
return true; return Error::Code::NONE;
} }
void void
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
class SFOutputStream : public AudioOutputStream class SFOutputStream : public AudioOutputStream
{ {
SNDFILE *m_sndfile = nullptr; SNDFILE *m_sndfile = nullptr;
std::string m_error_blurb;
int m_bit_depth = 0; int m_bit_depth = 0;
int m_sample_rate = 0; int m_sample_rate = 0;
int m_n_channels = 0; int m_n_channels = 0;
...@@ -25,7 +24,7 @@ class SFOutputStream : public AudioOutputStream ...@@ -25,7 +24,7 @@ class SFOutputStream : public AudioOutputStream
public: public:
~SFOutputStream(); ~SFOutputStream();
bool open (const std::string& filename, int n_channels, int sample_rate, int bit_depth, size_t n_frames); Error open (const std::string& filename, int n_channels, int sample_rate, int bit_depth, size_t n_frames);
Error write_frames (const std::vector<float>& frames) override; Error write_frames (const std::vector<float>& frames) override;
void close(); void close();
int bit_depth() const override; int bit_depth() const override;
......
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