Commit 88c5fbba authored by Stefan Westerfeld's avatar Stefan Westerfeld

Move shared class AudioBuffer to its own header.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent a79f608e
......@@ -5,7 +5,8 @@ COMMON_SRC = utils.hh utils.cc convcode.hh convcode.cc random.hh random.cc wavda
audiostream.cc audiostream.hh sfinputstream.cc sfinputstream.hh stdoutwavoutputstream.cc stdoutwavoutputstream.hh \
sfoutputstream.cc sfoutputstream.hh rawinputstream.cc rawinputstream.hh rawoutputstream.cc rawoutputstream.hh \
rawconverter.cc rawconverter.hh mp3inputstream.cc mp3inputstream.hh wmcommon.cc wmcommon.hh fft.cc fft.hh \
limiter.cc limiter.hh shortcode.cc shortcode.hh mpegts.cc mpegts.hh hlsoutputstream.cc hlsoutputstream.hh
limiter.cc limiter.hh shortcode.cc shortcode.hh mpegts.cc mpegts.hh hlsoutputstream.cc hlsoutputstream.hh \
audiobuffer.hh
COMMON_LIBS = $(SNDFILE_LIBS) $(FFTW_LIBS) $(LIBGCRYPT_LIBS) $(LIBMPG123_LIBS) $(FFMPEG_LIBS)
audiowmark_SOURCES = audiowmark.cc wmget.cc wmadd.cc $(COMMON_SRC)
......
/*
* Copyright (C) 2018-2020 Stefan Westerfeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUDIOWMARK_AUDIO_BUFFER_HH
#define AUDIOWMARK_AUDIO_BUFFER_HH
#include <assert.h>
class AudioBuffer
{
const int n_channels = 0;
std::vector<float> buffer;
public:
AudioBuffer (int n_channels) :
n_channels (n_channels)
{
}
void
write_frames (const std::vector<float>& samples)
{
buffer.insert (buffer.end(), samples.begin(), samples.end());
}
std::vector<float>
read_frames (size_t frames)
{
assert (frames * n_channels <= buffer.size());
const auto begin = buffer.begin();
const auto end = begin + frames * n_channels;
std::vector<float> result (begin, end);
buffer.erase (begin, end);
return result;
}
size_t
can_read_frames() const
{
return buffer.size() / n_channels;
}
};
#endif /* AUDIOWMARK_AUDIO_BUFFER_HH */
......@@ -19,6 +19,7 @@
#define AUDIOWMARK_HLS_OUTPUT_STREAM_HH
#include "audiostream.hh"
#include "audiobuffer.hh"
#include <assert.h>
......@@ -32,39 +33,6 @@ extern "C" {
#define av_err2str(errnum) av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
}
/* FIXME: fix duplication with wmadd.cc */
class AudioBuffer
{
const int n_channels = 0;
std::vector<float> buffer;
public:
AudioBuffer (int n_channels) :
n_channels (n_channels)
{
}
void
write_frames (const std::vector<float>& samples)
{
buffer.insert (buffer.end(), samples.begin(), samples.end());
}
std::vector<float>
read_frames (size_t frames)
{
assert (frames * n_channels <= buffer.size());
const auto begin = buffer.begin();
const auto end = begin + frames * n_channels;
std::vector<float> result (begin, end);
buffer.erase (begin, end);
return result;
}
size_t
can_read_frames() const
{
return buffer.size() / n_channels;
}
};
class HLSOutputStream : public AudioOutputStream {
AVStream *m_st = nullptr;
AVCodecContext *m_enc = nullptr;
......
......@@ -31,6 +31,7 @@
#include "rawoutputstream.hh"
#include "stdoutwavoutputstream.hh"
#include "shortcode.hh"
#include "audiobuffer.hh"
using std::string;
using std::vector;
......@@ -344,38 +345,6 @@ public:
}
};
class AudioBuffer
{
const int n_channels = 0;
vector<float> buffer;
public:
AudioBuffer (int n_channels) :
n_channels (n_channels)
{
}
void
write_frames (const vector<float>& samples)
{
buffer.insert (buffer.end(), samples.begin(), samples.end());
}
vector<float>
read_frames (size_t frames)
{
assert (frames * n_channels <= buffer.size());
const auto begin = buffer.begin();
const auto end = begin + frames * n_channels;
vector<float> result (begin, end);
buffer.erase (begin, end);
return result;
}
size_t
can_read_frames() const
{
return buffer.size() / n_channels;
}
};
class ResamplerImpl
{
public:
......
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