From a327e90ed14b8db059de54082666f9adba750c69 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 30 Aug 2014 03:27:40 +0200 Subject: [PATCH] =?UTF-8?q?WIP=20Aufruf=20und=20=C3=96ffnen=20der=20Dateie?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sauSynKlick/Makefile | 4 +- sauSynKlick/SynKlick.cc | 148 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 145 insertions(+), 7 deletions(-) diff --git a/sauSynKlick/Makefile b/sauSynKlick/Makefile index 866c8b3..1354534 100644 --- a/sauSynKlick/Makefile +++ b/sauSynKlick/Makefile @@ -12,9 +12,9 @@ #INCLUDES = -I$(XXX_H) INCLUDES = -LIBRARIES = -lm +LIBRARIES = -lm -lsndfile CFLAGS = $(INCLUDES) -O2 -fPIC -CXXFLAGS = $(CFLAGS) +CXXFLAGS = $(CFLAGS) -std=gnu++11 PROGRAMS = SynKlick CC = clang CXX = clang++ diff --git a/sauSynKlick/SynKlick.cc b/sauSynKlick/SynKlick.cc index 4888c46..7022fdb 100644 --- a/sauSynKlick/SynKlick.cc +++ b/sauSynKlick/SynKlick.cc @@ -1,7 +1,145 @@ -#include -#include +/* + SynKlick - repair synchronous drop-outs in raw sound recording -int main(void) { - std::cout << "Hurgha\n"; - return EXIT_SUCCESS; + (C) Ichthyostega (Hermann Vosseler), 2014 + +All code in this package is provided "as is" and WITHOUT ANY WARRANTY. +It may be copied and used under the terms and conditions of the +GNU PUBLIC LICENCE (GPL) Version 2 and above. + +*********************************************************************/ + +#include +#include + +#include +#include +#include +#include + +using std::string; +using std::cout; +using std::cerr; + +const size_t BUFF_SIZE = 44100; +const size_t CONTEXT = 1; + + +/* ==== Helpers ==== */ + +void +error (string msg) +{ + cerr << "processing FAILED: " + << msg << "\n\n"; + exit(EXIT_FAILURE); +} + +string +name_without_path (string rawName) +{ + error("TODO"); +} + + + + +/* ==== Abstraction: single channel to be processed ==== */ + +struct Channel + { + string name; + SNDFILE *in = nullptr, + *out = nullptr; + SF_INFO info_in, + info_out; + + float buff[BUFF_SIZE+CONTEXT]; + + + void + open (string name, string target) + { + this->name = name; + target += name_without_path(name); + + info_in.format = 0; + in = sf_open (name.c_str(), SFM_READ, &info_in); + if (!in) + error ("could not open "+name+" -- " + sf_strerror (NULL)); + + info_out.format = info_in.format; + info_out.channels = info_in.channels; + info_out.samplerate = info_in.samplerate; + out = sf_open(target.c_str(), SFM_WRITE, &info_out); + if (!out) + error ("unable to create target "+target+" -- " + sf_strerror (NULL)); + } + + + ~Channel() + { + sf_close (in); + if (!sf_close (out)) + cerr << "WARNING: problems while closing target '" << name_without_path(name) + << "' -- " << sf_strerror(out) << "\n"; + + in = out = nullptr; + } + }; + + + + + + +/* ==== high-level operation ==== */ + +int num_sources = 0; +Channel* channel = nullptr; + + +void +openStreams (char* name[], string targetDir) +{ + assert (!channel); + assert (num_sources); + channel = new Channel[num_sources]; + + assert (targetDir.length()); + if (targetDir[targetDir.length()-1] != '/') + targetDir += '/'; + + for (uint i=0; i < num_sources; ++i) + channel[i].open (name[i], targetDir); +} + +void +closeStreams() +{ + delete[] channel; +} + + +int +main (int argc, char* argv[]) { + if (argc < 3 || string("-h") == argv[1]) + { + cerr << "SynKlick [ ...] " + << "\n\nRepair a very special kind of defects in sound recordings:" + << "\nsynchronous drop-outs in a set of input sound files." + << "\nA fixed copy of each file will be written to \n\n"; + + return EXIT_FAILURE; + } + num_sources = argc - 2; + string targetDir = argv[argc-1]; + + openStreams (&argv[1], targetDir); + + closeStreams(); + cout << "\nSUCCESS\n" + << num_sources << " files read and processed --> " + << targetDir << "\n\n"; + return EXIT_SUCCESS; }