From be7c24ad3e39c2a84c5bf9b264c5c89c811b8162 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 3 Jun 2023 14:10:26 +0200 Subject: split stream into sample blocks --- os2eindopdracht/FilterWorker.cpp | 30 ++++++++++++++++++++++++++ os2eindopdracht/FilterWorker.h | 5 +++++ os2eindopdracht/SampleBlock.cpp | 6 ++++++ os2eindopdracht/SampleBlock.h | 13 ++++++++++++ os2eindopdracht/SampleStream.cpp | 14 ++++++++++++ os2eindopdracht/SampleStream.h | 3 +++ os2eindopdracht/main.cpp | 46 ++++++++++++++-------------------------- os2eindopdracht/makefile | 2 +- 8 files changed, 88 insertions(+), 31 deletions(-) (limited to 'os2eindopdracht') 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 original; + original = std::vector(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(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::iterator begin, vector::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 +#include + +using std::vector; + +class SampleBlock { +public: + SampleBlock(vector::iterator begin, vector::iterator end); + vector::iterator begin; + vector::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 #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 SampleStream::split(unsigned long block_size) { + vector 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 #include +#include "SampleBlock.h" + using std::string; using std::vector; @@ -13,6 +15,7 @@ public: public: void load(string input); string save(); + vector split(unsigned long block_size); public: vector _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 #include #include +#include #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 original; - original = std::vector(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(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 input_blocks = input.split(SAMPLE_BLOCK_SIZE); + + SampleStream output(file_input_content.str()); + vector 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 $< $@ -- cgit v1.2.3