summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct3
-rw-r--r--encoder.h12
-rw-r--r--encoders/lame_encoder.cpp26
-rw-r--r--encoders/lame_encoder.h19
4 files changed, 59 insertions, 1 deletions
diff --git a/SConstruct b/SConstruct
index f29694c..75371ae 100644
--- a/SConstruct
+++ b/SConstruct
@@ -6,6 +6,7 @@ conf = Configure(env)
conf.CheckLib('boost_system')
conf.CheckLib('boost_filesystem')
conf.CheckLib('boost_regex')
+conf.CheckLib('mp3lame')
env = conf.Finish()
if GetOption('release'):
@@ -15,6 +16,6 @@ else:
env.ParseConfig('pkg-config --cflags --libs libmpg123')
-env.Program('audistd', Glob('*.cpp') + Glob('decoders/*.cpp'))
+env.Program('audistd', Glob('*.cpp') + Glob('decoders/*.cpp') + Glob('encoders/*.cpp'))
# vim: syn=python
diff --git a/encoder.h b/encoder.h
new file mode 100644
index 0000000..a9a0e5c
--- /dev/null
+++ b/encoder.h
@@ -0,0 +1,12 @@
+#ifndef ENCODER_H
+#define ENCODER_H
+
+#include <boost/cstdint.hpp>
+
+class EncoderBase {
+ public:
+ virtual size_t encode(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0;
+ virtual size_t flush(uint8_t *output, size_t output_size) = 0;
+};
+
+#endif
diff --git a/encoders/lame_encoder.cpp b/encoders/lame_encoder.cpp
new file mode 100644
index 0000000..4cbfc9c
--- /dev/null
+++ b/encoders/lame_encoder.cpp
@@ -0,0 +1,26 @@
+#include "lame_encoder.h"
+
+#include <stdexcept>
+
+EncoderLame::EncoderLame() {
+ gfp = lame_init();
+ int error = lame_init_params(gfp);
+
+ if(error < 0) {
+ throw std::runtime_error("failed to initialize LAME");
+ }
+}
+
+EncoderLame::~EncoderLame() {
+ lame_close(gfp);
+}
+
+size_t EncoderLame::encode(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) {
+ size_t size = lame_encode_buffer_interleaved(gfp, (short*)input, input_size / 4, output, output_size);
+ return size;
+}
+
+size_t EncoderLame::flush(uint8_t *output, size_t output_size) {
+ size_t size = lame_encode_flush(gfp, output, output_size);
+ return size;
+}
diff --git a/encoders/lame_encoder.h b/encoders/lame_encoder.h
new file mode 100644
index 0000000..47f9666
--- /dev/null
+++ b/encoders/lame_encoder.h
@@ -0,0 +1,19 @@
+#ifndef LAME_ENCODER_H
+#define LAME_ENCODER_H
+
+#include "encoder.h"
+
+#include <lame/lame.h>
+
+class EncoderLame : public EncoderBase {
+ private:
+ lame_global_flags *gfp;
+
+ public:
+ EncoderLame();
+ ~EncoderLame();
+ size_t encode(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size);
+ size_t flush(uint8_t *output, size_t output_size);
+};
+
+#endif