Commit 94024db7 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Read input via AudioInputStream base class.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 22267ef1
......@@ -10,12 +10,14 @@ public:
virtual int bit_depth() const = 0;
virtual int sample_rate() const = 0;
virtual size_t n_frames() const = 0;
virtual int n_channels() const = 0;
virtual ~AudioStream();
};
class AudioInputStream : public AudioStream
{
public:
virtual Error read_frames (std::vector<float>& samples, size_t count) = 0;
};
......
......@@ -1095,13 +1095,17 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
auto bitvec_a = randomize_bit_order (conv_encode (ConvBlockType::a, bitvec), /* encode */ true);
auto bitvec_b = randomize_bit_order (conv_encode (ConvBlockType::b, bitvec), /* encode */ true);
auto in_stream = std::make_unique<SFInputStream> (); // FIXME: need virtual constructor
Error err = in_stream->open (infile);
if (err)
{
fprintf (stderr, "audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1;
}
std::unique_ptr<AudioInputStream> in_stream; // FIXME: virtual constructor
{
SFInputStream *sistream = new SFInputStream ();
in_stream.reset (sistream);
Error err = sistream->open (infile);
if (err)
{
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();
info ("Time: %d:%02d\n", orig_seconds / 60, orig_seconds % 60);
info ("Sample Rate: %d\n", in_stream->sample_rate());
......@@ -1113,7 +1117,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
StdoutWavOutputStream *swstream = new StdoutWavOutputStream();
out_stream.reset (swstream);
err = swstream->open (in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames());
Error err = swstream->open (in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames());
if (err)
{
error ("audiowmark: error writing to -: %s\n", err.message());
......
......@@ -99,6 +99,12 @@ SFOutputStream::sample_rate() const
return m_sample_rate;
}
int
SFOutputStream::n_channels() const
{
return m_n_channels;
}
size_t
SFOutputStream::n_frames() const
{
......
......@@ -31,6 +31,7 @@ public:
void close();
int bit_depth() const override;
int sample_rate() const override;
int n_channels() const override;
size_t n_frames() const override;
};
......
......@@ -24,6 +24,12 @@ StdoutWavOutputStream::bit_depth() const
return m_bit_depth;
}
int
StdoutWavOutputStream::n_channels() const
{
return m_n_channels;
}
static void
header_append_str (vector<unsigned char>& bytes, const string& str)
{
......
......@@ -10,6 +10,7 @@ class StdoutWavOutputStream : public AudioOutputStream
std::string m_error_blurb;
int m_bit_depth = 0;
int m_sample_rate = 0;
int m_n_channels = 0;
size_t m_n_frames = 0;
size_t m_close_padding = 0;
......@@ -28,6 +29,7 @@ public:
void close();
int sample_rate() const override;
int bit_depth() const override;
int n_channels() const override;
size_t n_frames() const override
{
return m_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