Commit 0a2c6006 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Use new style errors for new streams.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 57ce3979
......@@ -1096,9 +1096,10 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
auto bitvec_b = randomize_bit_order (conv_encode (ConvBlockType::b, bitvec), /* encode */ true);
auto in_stream = std::make_unique<SFInputStream> (); // FIXME: need virtual constructor
if (!in_stream->open (infile))
Error err = in_stream->open (infile);
if (err)
{
fprintf (stderr, "audiowmark: error opening %s: %s\n", infile.c_str(), in_stream->error_blurb());
fprintf (stderr, "audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1;
}
int orig_seconds = in_stream->n_frames() / in_stream->sample_rate();
......@@ -1112,9 +1113,10 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
StdoutWavOutputStream *swstream = new StdoutWavOutputStream();
out_stream.reset (swstream);
if (!swstream->open (in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames()))
err = swstream->open (in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames());
if (err)
{
fprintf (stderr, "audiowmark: error writing to -\n"); //%s: %s\n", outfile.c_str(), out_wav_data.error_blurb()); FIXME
error ("audiowmark: error writing to -: %s\n", err.message());
return 1;
}
}
......
......@@ -10,7 +10,7 @@ SFInputStream::~SFInputStream()
close();
}
bool
Error
SFInputStream::open (const string& filename)
{
assert (m_state == State::NEW);
......@@ -22,13 +22,13 @@ SFInputStream::open (const string& filename)
int error = sf_error (m_sndfile);
if (error)
{
m_error_blurb = sf_strerror (m_sndfile);
Error err (sf_strerror (m_sndfile));
if (m_sndfile)
{
m_sndfile = nullptr;
sf_close (m_sndfile);
}
return false;
return err;
}
m_n_channels = sfinfo.channels;
......@@ -64,7 +64,7 @@ SFInputStream::open (const string& filename)
}
m_state = State::OPEN;
return true;
return Error::Code::NONE;
}
int
......
......@@ -10,7 +10,6 @@
class SFInputStream : public AudioInputStream
{
SNDFILE *m_sndfile = nullptr;
std::string m_error_blurb;
int m_n_channels = 0;
int m_n_values = 0;
int m_bit_depth = 0;
......@@ -26,7 +25,7 @@ class SFInputStream : public AudioInputStream
public:
~SFInputStream();
bool open (const std::string& filename);
Error open (const std::string& filename);
Error read_frames (std::vector<float>& samples, size_t count);
void close();
......@@ -47,10 +46,6 @@ public:
{
return m_n_values / m_n_channels;
}
const char *error_blurb() const
{
return m_error_blurb.c_str();
}
};
#endif /* AUDIOWMARK_SF_INPUT_STREAM_HH */
......@@ -47,15 +47,14 @@ header_append_u16 (vector<unsigned char>& bytes, uint16_t u)
bytes.push_back (u >> 8);
}
bool
Error
StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, size_t n_frames)
{
assert (m_state == State::NEW);
if (bit_depth != 16 && bit_depth != 24)
{
m_error_blurb = "StdoutWavOutputStream::open: unsupported bit depth";
return false;
return Error ("StdoutWavOutputStream::open: unsupported bit depth");
}
vector<unsigned char> header_bytes;
......@@ -88,7 +87,7 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz
m_n_frames = n_frames;
m_state = State::OPEN;
return true;
return Error::Code::NONE;
}
template<int BIT_DEPTH> void
......
......@@ -23,7 +23,7 @@ class StdoutWavOutputStream : public AudioOutputStream
public:
~StdoutWavOutputStream();
bool open (int n_channels, int sample_rate, int bit_depth, size_t n_frames);
Error open (int n_channels, int sample_rate, int bit_depth, size_t n_frames);
Error write_frames (const std::vector<float>& frames) override;
void close();
int sample_rate() const override;
......
......@@ -18,9 +18,10 @@ main (int argc, char **argv)
StdoutWavOutputStream out;
std::string filename = (argc >= 2) ? argv[1] : "-";
if (!in.open (filename.c_str()))
Error err = in.open (filename.c_str());
if (err)
{
fprintf (stderr, "teststream: open input failed: %s\n", in.error_blurb());
fprintf (stderr, "teststream: open input failed: %s\n", err.message());
return 1;
}
if (!out.open (in.n_channels(), in.sample_rate(), 16, in.n_frames()))
......
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