diff options
-rw-r--r-- | os2eindopdracht/FilterWorker.cpp | 30 | ||||
-rw-r--r-- | os2eindopdracht/FilterWorker.h | 5 | ||||
-rw-r--r-- | os2eindopdracht/SampleBlock.cpp | 6 | ||||
-rw-r--r-- | os2eindopdracht/SampleBlock.h | 13 | ||||
-rw-r--r-- | os2eindopdracht/SampleStream.cpp | 14 | ||||
-rw-r--r-- | os2eindopdracht/SampleStream.h | 3 | ||||
-rw-r--r-- | os2eindopdracht/main.cpp | 46 | ||||
-rw-r--r-- | os2eindopdracht/makefile | 2 |
8 files changed, 88 insertions, 31 deletions
diff --git a/os2eindopdracht/FilterWorker.cpp b/os2eindopdracht/FilterWorker.cpp index e69de29..7d2f315 100644 --- a/os2eindopdracht/FilterWorker.cpp +++ b/os2eindopdracht/FilterWorker.cpp @@ -0,0 +1,30 @@ + +/* + 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; + } + 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; + } +*/ diff --git a/os2eindopdracht/FilterWorker.h b/os2eindopdracht/FilterWorker.h index e69de29..e1e84b5 100644 --- a/os2eindopdracht/FilterWorker.h +++ b/os2eindopdracht/FilterWorker.h @@ -0,0 +1,5 @@ +#pragma once + +class FilterWorker { + +}; diff --git a/os2eindopdracht/SampleBlock.cpp b/os2eindopdracht/SampleBlock.cpp index e69de29..4d4fc16 100644 --- a/os2eindopdracht/SampleBlock.cpp +++ b/os2eindopdracht/SampleBlock.cpp @@ -0,0 +1,6 @@ +#include "SampleBlock.h" + +SampleBlock::SampleBlock(vector<int16_t>::iterator begin, vector<int16_t>::iterator end) { + this->begin = begin; + this->end = end; +} diff --git a/os2eindopdracht/SampleBlock.h b/os2eindopdracht/SampleBlock.h index e69de29..57dbabf 100644 --- a/os2eindopdracht/SampleBlock.h +++ b/os2eindopdracht/SampleBlock.h @@ -0,0 +1,13 @@ +#pragma once + +#include <cstdint> +#include <vector> + +using std::vector; + +class SampleBlock { +public: + SampleBlock(vector<int16_t>::iterator begin, vector<int16_t>::iterator end); + vector<int16_t>::iterator begin; + vector<int16_t>::iterator end; +}; diff --git a/os2eindopdracht/SampleStream.cpp b/os2eindopdracht/SampleStream.cpp index b9fd542..ca60281 100644 --- a/os2eindopdracht/SampleStream.cpp +++ b/os2eindopdracht/SampleStream.cpp @@ -1,8 +1,10 @@ #include <algorithm> #include "SampleStream.h" +#include "SampleBlock.h" using std::string; +using std::min; SampleStream::SampleStream(string input_stream) { load(input_stream); @@ -26,3 +28,15 @@ string SampleStream::save() { return out; } +vector<SampleBlock> SampleStream::split(unsigned long 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); + out.push_back(block); + } + return out; +} + diff --git a/os2eindopdracht/SampleStream.h b/os2eindopdracht/SampleStream.h index a9b8536..917a60e 100644 --- a/os2eindopdracht/SampleStream.h +++ b/os2eindopdracht/SampleStream.h @@ -3,6 +3,8 @@ #include <string> #include <vector> +#include "SampleBlock.h" + using std::string; using std::vector; @@ -13,6 +15,7 @@ public: public: void load(string input); string save(); + vector<SampleBlock> split(unsigned long block_size); public: vector<int16_t> _stream; diff --git a/os2eindopdracht/main.cpp b/os2eindopdracht/main.cpp index 534bf0c..ae042c5 100644 --- a/os2eindopdracht/main.cpp +++ b/os2eindopdracht/main.cpp @@ -2,11 +2,17 @@ #include <iostream> #include <sstream> #include <fstream> +#include <vector> #include "Arguments.h" #include "SampleStream.h" +#include "SampleBlock.h" #include "FilterWorker.h" +using std::vector; + +#define SAMPLE_BLOCK_SIZE 1024 + int main(int argc, char** argv) { Arguments args(argc, argv); @@ -15,38 +21,18 @@ int main(int argc, char** argv) { file_input_content << file_input.rdbuf(); file_input.close(); - SampleStream stream(file_input_content.str()); - - 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; - } - 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; - } + SampleStream input(file_input_content.str()); + vector<SampleBlock> input_blocks = input.split(SAMPLE_BLOCK_SIZE); + + 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); + // } std::fstream file_output(args.file_output, std::ios::out | std::ios::binary); - std::string edited_stream = stream.save(); + std::string edited_stream = output.save(); file_output.write(edited_stream.c_str(), edited_stream.size()); file_output.close(); diff --git a/os2eindopdracht/makefile b/os2eindopdracht/makefile index 41fd730..f71ef29 100644 --- a/os2eindopdracht/makefile +++ b/os2eindopdracht/makefile @@ -26,7 +26,7 @@ original.pcm: original.flac ./any2s16lepcm $< $@ edit.pcm: original.pcm ./main - ./main $< $@ -b1 -t-19 + ./main $< $@ edit.wav: edit.pcm ./s16lepcm2any $< $@ |