summaryrefslogtreecommitdiff
path: root/os2eindopdracht
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-05-30 15:13:18 +0200
committerlonkaars <loek@pipeframe.xyz>2023-05-30 15:13:18 +0200
commite346087f316e112a8af9494be13bfff188f3cc0b (patch)
tree67342a97434bfe8481c305fea6495c7ff1474454 /os2eindopdracht
parentafa02662b185f62644b1e44a55820ded1e703fd2 (diff)
file copy working
Diffstat (limited to 'os2eindopdracht')
-rw-r--r--os2eindopdracht/.gitignore5
-rw-r--r--os2eindopdracht/SampleStream.cpp28
-rw-r--r--os2eindopdracht/SampleStream.h19
-rwxr-xr-xos2eindopdracht/any2s16lepcm3
-rw-r--r--os2eindopdracht/main.cpp15
-rw-r--r--os2eindopdracht/makefile13
-rwxr-xr-xos2eindopdracht/s16lepcm2any3
7 files changed, 86 insertions, 0 deletions
diff --git a/os2eindopdracht/.gitignore b/os2eindopdracht/.gitignore
index f0c9b81..7c39037 100644
--- a/os2eindopdracht/.gitignore
+++ b/os2eindopdracht/.gitignore
@@ -1,2 +1,7 @@
*.o
main
+*.png
+*.pcm
+*.wav
+*.mp3
+*.flac
diff --git a/os2eindopdracht/SampleStream.cpp b/os2eindopdracht/SampleStream.cpp
index e69de29..b9fd542 100644
--- a/os2eindopdracht/SampleStream.cpp
+++ b/os2eindopdracht/SampleStream.cpp
@@ -0,0 +1,28 @@
+#include <algorithm>
+
+#include "SampleStream.h"
+
+using std::string;
+
+SampleStream::SampleStream(string input_stream) {
+ load(input_stream);
+
+ // test direct sample editing:
+ // std::transform(_stream.begin(), _stream.end(), _stream.begin(), [](int16_t s) { return s/2; });
+}
+
+void SampleStream::load(string input) {
+ _stream.clear();
+ for (unsigned long i = 0; i < input.size(); i += 2)
+ _stream.push_back(((input[i] & 0xff) << 0) | ((input[i+1] & 0xff) << 8));
+}
+
+string SampleStream::save() {
+ string out;
+ for (int16_t sample : _stream) {
+ out.push_back((sample >> 0) & 0xff);
+ out.push_back((sample >> 8) & 0xff);
+ }
+ return out;
+}
+
diff --git a/os2eindopdracht/SampleStream.h b/os2eindopdracht/SampleStream.h
index e69de29..94bb941 100644
--- a/os2eindopdracht/SampleStream.h
+++ b/os2eindopdracht/SampleStream.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <string>
+#include <vector>
+
+using std::string;
+using std::vector;
+
+class SampleStream {
+public:
+ SampleStream(string input_stream);
+
+public:
+ void load(string input);
+ string save();
+
+private:
+ vector<int16_t> _stream;
+};
diff --git a/os2eindopdracht/any2s16lepcm b/os2eindopdracht/any2s16lepcm
new file mode 100755
index 0000000..00bf37c
--- /dev/null
+++ b/os2eindopdracht/any2s16lepcm
@@ -0,0 +1,3 @@
+#!/bin/sh
+ffmpeg -y -hide_banner -loglevel warning -i "$1" -ac 1 -f s16le -acodec pcm_s16le "$2"
+
diff --git a/os2eindopdracht/main.cpp b/os2eindopdracht/main.cpp
index 2e96abe..291361e 100644
--- a/os2eindopdracht/main.cpp
+++ b/os2eindopdracht/main.cpp
@@ -1,4 +1,7 @@
#include <cstdio>
+#include <iostream>
+#include <sstream>
+#include <fstream>
#include "Arguments.h"
#include "SampleStream.h"
@@ -7,11 +10,23 @@
int main(int argc, char** argv) {
Arguments args(argc, argv);
+ std::fstream file_input(args.file_input, std::ios::in | std::ios::binary);
+ std::stringstream file_input_content;
+ file_input_content << file_input.rdbuf();
+ file_input.close();
+
+ SampleStream stream(file_input_content.str());
+
printf("max_threads: %i\n", args.max_threads);
printf("gain_bass: %+i\n", args.gain_bass);
printf("gain_treble: %+i\n", args.gain_treble);
printf("input filename: \"%s\"\n", args.file_input.c_str());
printf("output filename: \"%s\"\n", args.file_output.c_str());
+ std::fstream file_output(args.file_output, std::ios::out | std::ios::binary);
+ std::string edited_stream = stream.save();
+ file_output.write(edited_stream.c_str(), edited_stream.size());
+ file_output.close();
+
return 0;
}
diff --git a/os2eindopdracht/makefile b/os2eindopdracht/makefile
index d88ea30..f71ef29 100644
--- a/os2eindopdracht/makefile
+++ b/os2eindopdracht/makefile
@@ -22,3 +22,16 @@ clean:
compile_commands:
compiledb make -Bn
+original.pcm: original.flac
+ ./any2s16lepcm $< $@
+
+edit.pcm: original.pcm ./main
+ ./main $< $@
+
+edit.wav: edit.pcm
+ ./s16lepcm2any $< $@
+
+edit.png: edit.wav
+
+%.png: %.wav
+ sox $< -n spectrogram -o $@
diff --git a/os2eindopdracht/s16lepcm2any b/os2eindopdracht/s16lepcm2any
new file mode 100755
index 0000000..bd62a08
--- /dev/null
+++ b/os2eindopdracht/s16lepcm2any
@@ -0,0 +1,3 @@
+#!/bin/sh
+ffmpeg -y -hide_banner -loglevel warning -ac 1 -f s16le -ar 44.1k -i "$1" "$2"
+