From 7f6ea5e614268ff3fe605d88b6f6517ff4b41160 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 30 Aug 2014 23:42:49 +0200 Subject: [PATCH] Verarbeitungsmechanismus mit Laden/Schreiben und Kontextbehandlung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit implementiert und getestet Ein Kontext-Puffer wird mitgeführt, so daß stets eine bestimmte Anzahl an Kontext-Samples mit verfügbar ist. Puffer-Steuerung erfolgt pro Kanal, so daß auch variierende Dateilängen korrekt gehandhabt werden; die Verarbeitung bricht aber insgesamt innerhalb einer Pufferlänge ab, wenn die kürzesten Samples fertig bearbeitet sind. die eigentliche Korrektur ist noch nicht implementiert; im Test, nach dem Beheben der Implementierungs-Fehler, waren die bearbeiteten Samples schließlich Bit für Bit identisch mit dem Original. --- sauSynKlick/Makefile | 1 + sauSynKlick/SynKlick.cc | 70 +++++++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/sauSynKlick/Makefile b/sauSynKlick/Makefile index ef72ea9..586b376 100644 --- a/sauSynKlick/Makefile +++ b/sauSynKlick/Makefile @@ -30,6 +30,7 @@ SynKlick: SynKlick.cc all: SynKlick clean: + -rm -f SynKlick -rm -f `find . -name "*.o"` -rm -f `find .. -name "*~"` -rm -f *.bak core score.srt diff --git a/sauSynKlick/SynKlick.cc b/sauSynKlick/SynKlick.cc index 22ebbd1..6348ae5 100644 --- a/sauSynKlick/SynKlick.cc +++ b/sauSynKlick/SynKlick.cc @@ -43,7 +43,16 @@ name_without_path (string rawName) { auto pos = rawName.rfind('/'); return (pos == string::npos)? rawName - : rawName.substr(pos); + : rawName.substr(pos+1); +} + +void +reduceBufferPos (size_t & pos, size_t elementsToRemove) +{ + if (pos < elementsToRemove) + pos = 0; + else + pos -= elementsToRemove; } @@ -66,11 +75,13 @@ class Channel info_out_; float buff_[CHUNK_SIZE]; - size_t workPos=0, - loadPos=0; + size_t numSamples_ = 0; + size_t workPos_ = 0; public: + static bool hitEnd; + void open (string name, string target) { @@ -81,6 +92,9 @@ class Channel in_ = sf_open (name.c_str(), SFM_READ, &info_in_); if (!in_) error ("could not open "+name+" -- " + sf_strerror (NULL)); + if (1 != info_in_.channels) + error ("only Mono streams supported -- but '"+name_ + +"' was found to have "+std::to_string(info_in_.channels)+" channels."); info_out_.format = info_in_.format; info_out_.channels = info_in_.channels; @@ -93,10 +107,11 @@ class Channel ~Channel() { - sf_close (in_); - if (!sf_close (out_)) - cerr << "WARNING: problems while closing target '" << name_without_path(name_) - << "' -- " << sf_strerror(out_) << "\n"; + if (in_) sf_close (in_); + if (out_) + if (0 != sf_close (out_)) + cerr << "WARNING: problems while closing target '" << name_without_path(name_) + << "' -- " << sf_strerror(out_) << "\n"; in_ = out_ = nullptr; } @@ -105,18 +120,41 @@ class Channel void fillBuffer() { - error("TODO"); + assert(numSamples_ < CHUNK_SIZE); + float* startPos = buff_ + numSamples_; + size_t samplesToRead = CHUNK_SIZE - numSamples_; + numSamples_ = sf_read_float(in_, startPos, samplesToRead); + if (numSamples_ < samplesToRead) + hitEnd = true; // causes the processing to end with this chunk. + + numSamples_ += (startPos - buff_); + assert(workPos_ <= numSamples_); } void writeBuffer() { - error("TODO"); + size_t samplesToWrite = numSamples_ - (hitEnd? 0 : 2*CONTEXT); + size_t actuallyWritten = sf_write_float(out_, buff_, samplesToWrite); + if (actuallyWritten < samplesToWrite) + cerr << "Alarm: only "< streams(0); -bool hitEnd = false; +bool Channel::hitEnd = false; void @@ -195,7 +239,7 @@ closeStreams() void process() { - while (!hitEnd) + while (!Channel::hitEnd) { for (Channel& channel : streams) channel.fillBuffer();