summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-03 14:54:21 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-03 14:54:21 +0200
commit33fcc80be5e6d7c755a8bcc285854e872787ff38 (patch)
treeb094eaded5d42bfd2258ecaba84f838bcd37893e
parentbe7c24ad3e39c2a84c5bf9b264c5c89c811b8162 (diff)
filtering working on chunks
-rw-r--r--os2eindopdracht/FilterWorker.cpp59
-rw-r--r--os2eindopdracht/FilterWorker.h9
-rw-r--r--os2eindopdracht/SampleBlock.cpp5
-rw-r--r--os2eindopdracht/SampleBlock.h4
-rw-r--r--os2eindopdracht/SampleStream.cpp14
-rw-r--r--os2eindopdracht/SampleStream.h2
-rw-r--r--os2eindopdracht/main.cpp6
-rw-r--r--os2eindopdracht/makefile2
8 files changed, 59 insertions, 42 deletions
diff --git a/os2eindopdracht/FilterWorker.cpp b/os2eindopdracht/FilterWorker.cpp
index 7d2f315..495d3d1 100644
--- a/os2eindopdracht/FilterWorker.cpp
+++ b/os2eindopdracht/FilterWorker.cpp
@@ -1,30 +1,35 @@
+#include "FilterWorker.h"
+#include "SampleBlock.h"
-/*
- std::vector<int16_t> original;
- original = std::vector<int16_t>(stream._stream);
- for (unsigned long i = 0; i < original.size(); i++) {
- double x_pp = i < 2 ? 0 : original[i-2];
- double x_p = i < 1 ? 0 : original[i-1];
- double x_ = i < 0 ? 0 : original[i-0];
- double y_pp = i < 2 ? 0 : stream._stream[i-2];
- double y_p = i < 1 ? 0 : stream._stream[i-1];
- stream._stream[i] = args.bass.b0 * x_ +
- args.bass.b1 * x_p +
- args.bass.b2 * x_pp +
- args.bass.a1 * y_p +
- args.bass.a2 * y_pp;
+FilterWorker::FilterWorker(SampleBlock& input, SampleBlock& output) {
+ _input = &input;
+ _output = &output;
+}
+
+void FilterWorker::filter(Coefficients bass, Coefficients treble) {
+ for (size_t i = 0; i < _output->size; i++) {
+ double x_pp = i < 2 ? 0 : *(_input->begin + i - 2);
+ double x_p = i < 1 ? 0 : *(_input->begin + i - 1);
+ double x_ = i < 0 ? 0 : *(_input->begin + i - 0);
+ double y_pp = i < 2 ? 0 : *(_output->begin + i - 2);
+ double y_p = i < 1 ? 0 : *(_output->begin + i - 1);
+ *(_output->begin + i) = bass.b0 * x_ +
+ bass.b1 * x_p +
+ bass.b2 * x_pp +
+ bass.a1 * y_p +
+ bass.a2 * y_pp;
}
- original = std::vector<int16_t>(stream._stream);
- for (unsigned long i = 0; i < original.size(); i++) {
- double x_pp = i < 2 ? 0 : original[i-2];
- double x_p = i < 1 ? 0 : original[i-1];
- double x_ = i < 0 ? 0 : original[i-0];
- double y_pp = i < 2 ? 0 : stream._stream[i-2];
- double y_p = i < 1 ? 0 : stream._stream[i-1];
- stream._stream[i] = args.treble.b0 * x_ +
- args.treble.b1 * x_p +
- args.treble.b2 * x_pp +
- args.treble.a1 * y_p +
- args.treble.a2 * y_pp;
+ for (size_t i = 0; i < _output->size; i++) {
+ double x_pp = i < 2 ? 0 : *(_input->begin + i - 2);
+ double x_p = i < 1 ? 0 : *(_input->begin + i - 1);
+ double x_ = i < 0 ? 0 : *(_input->begin + i - 0);
+ double y_pp = i < 2 ? 0 : *(_output->begin + i - 2);
+ double y_p = i < 1 ? 0 : *(_output->begin + i - 1);
+ *(_output->begin + i) = treble.b0 * x_ +
+ treble.b1 * x_p +
+ treble.b2 * x_pp +
+ treble.a1 * y_p +
+ treble.a2 * y_pp;
}
-*/
+}
+
diff --git a/os2eindopdracht/FilterWorker.h b/os2eindopdracht/FilterWorker.h
index e1e84b5..2883d8b 100644
--- a/os2eindopdracht/FilterWorker.h
+++ b/os2eindopdracht/FilterWorker.h
@@ -1,5 +1,14 @@
#pragma once
+#include "SampleBlock.h"
+#include "Arguments.h"
+
class FilterWorker {
+public:
+ FilterWorker(SampleBlock& input, SampleBlock& output);
+ void filter(Coefficients bass, Coefficients treble);
+private:
+ SampleBlock* _input;
+ SampleBlock* _output;
};
diff --git a/os2eindopdracht/SampleBlock.cpp b/os2eindopdracht/SampleBlock.cpp
index 4d4fc16..a1288a6 100644
--- a/os2eindopdracht/SampleBlock.cpp
+++ b/os2eindopdracht/SampleBlock.cpp
@@ -1,6 +1,7 @@
#include "SampleBlock.h"
-SampleBlock::SampleBlock(vector<int16_t>::iterator begin, vector<int16_t>::iterator end) {
+SampleBlock::SampleBlock(vector<int16_t>::iterator begin, size_t size) {
this->begin = begin;
- this->end = end;
+ this->end = begin + size;
+ this->size = size;
}
diff --git a/os2eindopdracht/SampleBlock.h b/os2eindopdracht/SampleBlock.h
index 57dbabf..cb1f84a 100644
--- a/os2eindopdracht/SampleBlock.h
+++ b/os2eindopdracht/SampleBlock.h
@@ -1,5 +1,6 @@
#pragma once
+#include <cstdlib>
#include <cstdint>
#include <vector>
@@ -7,7 +8,8 @@ using std::vector;
class SampleBlock {
public:
- SampleBlock(vector<int16_t>::iterator begin, vector<int16_t>::iterator end);
+ SampleBlock(vector<int16_t>::iterator begin, size_t size);
vector<int16_t>::iterator begin;
vector<int16_t>::iterator end;
+ size_t size;
};
diff --git a/os2eindopdracht/SampleStream.cpp b/os2eindopdracht/SampleStream.cpp
index ca60281..3727e52 100644
--- a/os2eindopdracht/SampleStream.cpp
+++ b/os2eindopdracht/SampleStream.cpp
@@ -15,7 +15,7 @@ SampleStream::SampleStream(string input_stream) {
void SampleStream::load(string input) {
_stream.clear();
- for (unsigned long i = 0; i < input.size(); i += 2)
+ for (size_t i = 0; i < input.size(); i += 2)
_stream.push_back(((input[i] & 0xff) << 0) | ((input[i+1] & 0xff) << 8));
}
@@ -28,13 +28,13 @@ string SampleStream::save() {
return out;
}
-vector<SampleBlock> SampleStream::split(unsigned long block_size) {
+vector<SampleBlock> SampleStream::split(size_t block_size) {
vector<SampleBlock> out;
- unsigned long stream_size = _stream.size();
- for (unsigned long i = 0; i < stream_size; i += block_size) {
- unsigned long begin_offset = i;
- unsigned long end_offset = min(i + block_size, stream_size);
- SampleBlock block(_stream.begin() + begin_offset, _stream.begin() + end_offset);
+ size_t stream_size = _stream.size();
+ for (size_t i = 0; i < stream_size; i += block_size) {
+ size_t begin_offset = i;
+ size_t end_offset = min(i + block_size, stream_size);
+ SampleBlock block(_stream.begin() + begin_offset, end_offset - begin_offset);
out.push_back(block);
}
return out;
diff --git a/os2eindopdracht/SampleStream.h b/os2eindopdracht/SampleStream.h
index 917a60e..4c8b5c3 100644
--- a/os2eindopdracht/SampleStream.h
+++ b/os2eindopdracht/SampleStream.h
@@ -15,7 +15,7 @@ public:
public:
void load(string input);
string save();
- vector<SampleBlock> split(unsigned long block_size);
+ vector<SampleBlock> split(size_t block_size);
public:
vector<int16_t> _stream;
diff --git a/os2eindopdracht/main.cpp b/os2eindopdracht/main.cpp
index ae042c5..6d8ddd5 100644
--- a/os2eindopdracht/main.cpp
+++ b/os2eindopdracht/main.cpp
@@ -27,9 +27,9 @@ int main(int argc, char** argv) {
SampleStream output(file_input_content.str());
vector<SampleBlock> output_blocks = output.split(SAMPLE_BLOCK_SIZE);
- // for (unsigned int i = 0; i < input_blocks.size(); i++) {
- // FilterWorker(input_blocks[i], output_blocks[i]).filter(args.bass, args.treble);
- // }
+ for (size_t i = 0; i < input_blocks.size(); i++) {
+ FilterWorker(input_blocks[i], output_blocks[i]).filter(args.bass, args.treble);
+ }
std::fstream file_output(args.file_output, std::ios::out | std::ios::binary);
std::string edited_stream = output.save();
diff --git a/os2eindopdracht/makefile b/os2eindopdracht/makefile
index f71ef29..3d8f260 100644
--- a/os2eindopdracht/makefile
+++ b/os2eindopdracht/makefile
@@ -26,7 +26,7 @@ original.pcm: original.flac
./any2s16lepcm $< $@
edit.pcm: original.pcm ./main
- ./main $< $@
+ ./main $< $@ -b-4 -t-18
edit.wav: edit.pcm
./s16lepcm2any $< $@