WIP Aufruf und Öffnen der Dateien
This commit is contained in:
parent
0d4a659070
commit
a327e90ed1
2 changed files with 145 additions and 7 deletions
|
|
@ -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++
|
||||
|
|
|
|||
|
|
@ -1,7 +1,145 @@
|
|||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
/*
|
||||
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 <sndfile.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
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 <INPUTFILE> [<INPUTFILE2> ...] <TARGETDIR>"
|
||||
<< "\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 <TARGETDIR>\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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue