diff --git a/architecture/csvplot.cpp b/architecture/csvplot.cpp index 25ba499d7d..674c41ae35 100644 --- a/architecture/csvplot.cpp +++ b/architecture/csvplot.cpp @@ -138,7 +138,7 @@ int main(int argc, char* argv[]) interface->addOption("-s", &start_at_sample, 0, 0.0, 100000000.0); if (DSP.getNumInputs() > 0) { - fprintf(stderr, "no inputs allowed\n"); + cerr << "no inputs allowed " << endl; exit(1); } diff --git a/architecture/faust/gui/OSCUI.h b/architecture/faust/gui/OSCUI.h index 0964073e2d..985cd8057a 100644 --- a/architecture/faust/gui/OSCUI.h +++ b/architecture/faust/gui/OSCUI.h @@ -80,7 +80,7 @@ class OSCUI : public GUI const char* tr(const char* label) const { static char buffer[1024]; - char * ptr = buffer; int n=1; + char* ptr = buffer; int n = 1; while (*label && (n++ < 1024)) { switch (*label) { case ' ': case ' ': @@ -110,10 +110,14 @@ class OSCUI : public GUI public: - OSCUI(const char* /*applicationname*/, int argc, char* argv[], oscfaust::OSCIO* io = NULL, ErrorCallback errCallback = NULL, void* arg = NULL, bool init = true) : GUI() + OSCUI(const char* /*applicationname*/, int argc, char* argv[], + oscfaust::OSCIO* io = NULL, + ErrorCallback errCallback = NULL, + void* arg = NULL, + bool init = true) : GUI() { fCtrl = new oscfaust::OSCControler(argc, argv, this, &fJSON, io, errCallback, arg, init); - // fCtrl->opengroup(applicationname); + // fCtrl->opengroup(applicationname); } virtual ~OSCUI() { delete fCtrl; } diff --git a/architecture/faust/gui/console.h b/architecture/faust/gui/console.h index 4fbb7eb641..2e045255ce 100644 --- a/architecture/faust/gui/console.h +++ b/architecture/faust/gui/console.h @@ -46,18 +46,18 @@ *******************************************************************************/ #define NO_FILE 0 -#define INPUT_OUTPUT_FILE 1 -#define OUTPUT_FILE 2 - -struct param { - FAUSTFLOAT* fZone; FAUSTFLOAT fMin; FAUSTFLOAT fMax; - param(FAUSTFLOAT* z, FAUSTFLOAT init, FAUSTFLOAT a, FAUSTFLOAT b) : fZone(z), fMin(a), fMax(b) { *z = init; } -}; +#define OUTPUT_FILE 1 +#define INPUT_OUTPUT_FILE 2 class CMDUI : public UI { private: + struct param { + FAUSTFLOAT* fZone; FAUSTFLOAT fMin; FAUSTFLOAT fMax; + param(FAUSTFLOAT* z, FAUSTFLOAT init, FAUSTFLOAT a, FAUSTFLOAT b) : fZone(z), fMin(a), fMax(b) { *z = init; } + }; + int fArgc; char** fArgv; std::vector fFiles; @@ -90,14 +90,12 @@ class CMDUI : public UI case 0 : case 1 : case 2 : - // Skip the begin of the label "--foo-" - // until 3 '-' have been read + // Skip the begin of the label "--foo-" until 3 '-' have been read if (src[i] == '-') { level++; } break; case 3 : - // copy the content, but skip non alphnum - // and content in parenthesis + // copy the content, but skip non alphanum and content in parenthesis switch (src[i]) { case '(' : case '[' : @@ -114,9 +112,7 @@ class CMDUI : public UI break; default : - // here we are inside parenthesis and - // we skip the content until we are back to - // level 3 + // here we are inside parenthesis and we skip the content until we are back to level 3 switch (src[i]) { case '(' : case '[' : @@ -141,12 +137,18 @@ class CMDUI : public UI : UI(), fArgc(argc), fArgv(argv), fIgnoreParam(ignore_param) { fPrefix.push("-"); } virtual ~CMDUI() {} + // Can be used as public method void addOption(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max) { std::string fullname = "-" + simplify(fPrefix.top() + "-" + label); fKeyParam.insert(make_pair(fullname, param(zone, init, min, max))); } + virtual void openTabBox(const char* label) { openAnyBox(label); } + virtual void openHorizontalBox(const char* label) { openAnyBox(label); } + virtual void openVerticalBox(const char* label) { openAnyBox(label); } + virtual void closeBox() { fPrefix.pop(); } + virtual void addButton(const char* label, FAUSTFLOAT* zone) { addOption(label, zone, 0, 0, 1); @@ -181,12 +183,6 @@ class CMDUI : public UI virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {} - virtual void openTabBox(const char* label) { openAnyBox(label); } - virtual void openHorizontalBox(const char* label) { openAnyBox(label); } - virtual void openVerticalBox(const char* label) { openAnyBox(label); } - - virtual void closeBox() { fPrefix.pop(); } - virtual bool run() { char c; @@ -198,17 +194,20 @@ class CMDUI : public UI return true; } - void printhelp_command(int file = NO_FILE) + void printhelp_command(int file_mode = NO_FILE) { - std::cout << fArgv[0] << " "; - for (const auto& i : fKeyParam) { - std::cout << "[ " << i.first << " " << i.second.fMin << ".." << i.second.fMax <<" ] "; - } - std::cout << std::endl; - if (file == INPUT_OUTPUT_FILE) { - std::cout << "infile outfile\n"; - } else if (file == OUTPUT_FILE) { - std::cout << "outfile\n"; + if ((file_mode == OUTPUT_FILE && files() < 1) + || (file_mode == INPUT_OUTPUT_FILE && files() < 2)) { + std::cout << fArgv[0] << " "; + for (const auto& i : fKeyParam) { + std::cout << "[ " << i.first << " " << i.second.fMin << ".." << i.second.fMax <<" ] "; + } + if (file_mode == INPUT_OUTPUT_FILE) { + std::cout << "infile outfile\n"; + } else if (file_mode == OUTPUT_FILE) { + std::cout << "outfile\n"; + } + exit(1); } } @@ -219,9 +218,10 @@ class CMDUI : public UI std::cout << "[ " << i.first << " " << i.second.fMin << ".." << i.second.fMax <<" ] "; } std::cout << std::endl; + exit(1); } - void process_command(int file = NO_FILE) + void process_command(int file_mode = NO_FILE) { std::map::iterator p; for (int i = 1; i < fArgc; i++) { @@ -229,15 +229,13 @@ class CMDUI : public UI if ((strcmp(fArgv[i], "-help") == 0) || (strcmp(fArgv[i], "-h") == 0) || (strcmp(fArgv[i], "--help") == 0)) { - printhelp_command(file); - exit(1); + printhelp_command(file_mode); } p = fKeyParam.find(fArgv[i]); if (p == fKeyParam.end()) { if (!fIgnoreParam) { std::cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n"; - printhelp_command(); - exit(1); + printhelp_command(file_mode); } else { // Argument with a value, so also ignore the value if ((i+1 < fArgc) && (fArgv[i+1][0] != '-')) i++; @@ -262,13 +260,11 @@ class CMDUI : public UI || (strcmp(fArgv[i], "-h") == 0) || (strcmp(fArgv[i], "--help") == 0)) { printhelp_init(); - exit(1); } p = fKeyParam.find(fArgv[i]); if (p == fKeyParam.end()) { std::cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n"; printhelp_init(); - exit(1); } char* end; *(p->second.fZone) = FAUSTFLOAT(std::strtod(fArgv[i+1], &end)); diff --git a/architecture/sndfile.cpp b/architecture/sndfile.cpp index 69de58cff7..ae3b36932d 100644 --- a/architecture/sndfile.cpp +++ b/architecture/sndfile.cpp @@ -84,9 +84,8 @@ using namespace std; /*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/ - -// loptrm : Scan command-line arguments and remove and return long int value when found -long loptrm(int* argcP, char* argv[], const char* longname, const char* shortname, long def) +// loptrm : scan command-line arguments and remove and return long int value when found +static long loptrm(int* argcP, char* argv[], const char* longname, const char* shortname, long def) { int argc = *argcP; for (int i = 2; i < argc; i++) { @@ -107,7 +106,8 @@ mydsp DSP; std::list GUI::fGuiList; ztimedmap GUI::gTimedZoneMap; -#define kFrames 512 +#define kFrames 512 +#define kSampleRate 44100 int main(int argc, char* argv[]) { @@ -123,81 +123,130 @@ int main(int argc, char* argv[]) CMDUI* interface = new CMDUI(argc, argv, true); DSP.buildUserInterface(interface); - if (argc == 1) { - interface->printhelp_command(INPUT_OUTPUT_FILE); - exit(1); - } - interface->process_command(INPUT_OUTPUT_FILE); - - long num_samples = loptrm(&argc, argv, "--continue", "-c", 0); - bool is_rc = loptrm(&argc, argv, "-rc", "-rc", 0); - - SNDFILE* in_sf; - SNDFILE* out_sf; - SF_INFO in_info; - SF_INFO out_info; - - // open input file - in_info.format = 0; - in_info.channels = 0; - in_sf = sf_open(interface->input_file(), SFM_READ, &in_info); - if (in_sf == NULL) { - fprintf(stderr, "*** Input file not found.\n"); - sf_perror(in_sf); - exit(1); - } - - // open output file - out_info = in_info; - out_info.format = in_info.format; - out_info.channels = DSP.getNumOutputs(); - out_sf = sf_open(interface->output_file(), SFM_WRITE, &out_info); - if (out_sf == NULL) { - fprintf(stderr, "*** Cannot write output file.\n"); - sf_perror(out_sf); - exit(1); - } - - // create separator and interleaver - Deinterleaver sep(kFrames, in_info.channels, DSP.getNumInputs()); - Interleaver ilv(kFrames, DSP.getNumOutputs(), DSP.getNumOutputs()); - - // init DSP with SR - DSP.init(in_info.samplerate); - - // Possibly restore saved state - if (is_rc) { - finterface.recallState(rcfilename); - } - // modify the UI values according to the command line options, after init - interface->process_init(); + interface->process_command(FILE_MODE); + interface->printhelp_command(FILE_MODE); - // process all samples - int nbf; - do { - nbf = READ_SAMPLE(in_sf, sep.input(), kFrames); - sep.deinterleave(); - DSP.compute(nbf, sep.outputs(), ilv.inputs()); - ilv.interleave(); - WRITE_SAMPLE(out_sf, ilv.output(), nbf); - } while (nbf == kFrames); - - sf_close(in_sf); - - // compute tail, if any - if (num_samples > 0) { - FAUSTFLOAT* input = (FAUSTFLOAT*)calloc(num_samples * DSP.getNumInputs(), sizeof(FAUSTFLOAT)); - FAUSTFLOAT* inputs[1] = { input }; - Interleaver ailv(num_samples, DSP.getNumOutputs(), DSP.getNumOutputs()); - DSP.compute(num_samples, inputs, ailv.inputs()); - ailv.interleave(); - WRITE_SAMPLE(out_sf, ailv.output(), num_samples); - } + bool is_rc = loptrm(&argc, argv, "-rc", "-rc", 0); - sf_close(out_sf); - if (is_rc) { - finterface.saveState(rcfilename); + if (FILE_MODE == INPUT_OUTPUT_FILE) { + + int num_samples = loptrm(&argc, argv, "--continue", "-c", 0); + + SF_INFO in_info; + memset(&in_info, 0, sizeof(in_info)); + SNDFILE* in_sf = sf_open(interface->input_file(), SFM_READ, &in_info); + if (!in_sf) { + cerr << "ERROR : input file not found" << endl; + sf_perror(in_sf); + exit(1); + } + + SF_INFO out_info = in_info; + out_info.format = in_info.format; + out_info.channels = DSP.getNumOutputs(); + SNDFILE* out_sf = sf_open(interface->output_file(), SFM_WRITE, &out_info); + if (!out_sf) { + cerr << "ERROR : cannot write output file" << endl; + sf_perror(out_sf); + exit(1); + } + + // Init DSP with SR + DSP.init(in_info.samplerate); + + // Possibly restore saved state + if (is_rc) { + finterface.recallState(rcfilename); + } + + // Modify the UI values according to the command line options, after init + interface->process_init(); + + // Create deinterleaver and interleaver + Deinterleaver dilv(kFrames, in_info.channels, DSP.getNumInputs()); + Interleaver ilv(kFrames, DSP.getNumOutputs(), DSP.getNumOutputs()); + + // Process all samples + int nbf; + do { + nbf = READ_SAMPLE(in_sf, dilv.input(), kFrames); + dilv.deinterleave(); + DSP.compute(nbf, dilv.outputs(), ilv.inputs()); + ilv.interleave(); + WRITE_SAMPLE(out_sf, ilv.output(), nbf); + } while (nbf == kFrames); + + sf_close(in_sf); + + // Compute tail, if any + if (num_samples > 0) { + FAUSTFLOAT* input = (FAUSTFLOAT*)calloc(num_samples * DSP.getNumInputs(), sizeof(FAUSTFLOAT)); + FAUSTFLOAT* inputs[1] = { input }; + Interleaver ilv(num_samples, DSP.getNumOutputs(), DSP.getNumOutputs()); + DSP.compute(num_samples, inputs, ilv.inputs()); + ilv.interleave(); + WRITE_SAMPLE(out_sf, ilv.output(), num_samples); + } + + sf_close(out_sf); + + // Possibly save state + if (is_rc) { + finterface.saveState(rcfilename); + } + + } else { + + int num_samples = loptrm(&argc, argv, "--samples", "-s", kSampleRate * 5); + int sample_rate = loptrm(&argc, argv, "--sample-rate", "-sr", kSampleRate); + int bit_depth = loptrm(&argc, argv, "--bith-depth (16|24|32)", "-bd", 16); + int bd = (bit_depth == 16) ? SF_FORMAT_PCM_16 : ((bit_depth == 24) ? SF_FORMAT_PCM_24 : SF_FORMAT_PCM_32); + + SF_INFO out_info = { num_samples, sample_rate, DSP.getNumOutputs(), SF_FORMAT_WAV|bd|SF_ENDIAN_LITTLE, 0, 0}; + SNDFILE* out_sf = sf_open(interface->input_file(), SFM_WRITE, &out_info); + if (!out_sf) { + cerr << "ERROR : cannot write output file" << endl; + sf_perror(out_sf); + exit(1); + } + + // Init DSP with SR + DSP.init(sample_rate); + + // Possibly restore saved state + if (is_rc) { + finterface.recallState(rcfilename); + } + + // Modify the UI values according to the command line options, after init + interface->process_init(); + + // Create interleaver + Interleaver ilv(kFrames, DSP.getNumOutputs(), DSP.getNumOutputs()); + + // Process all samples + int frames = num_samples; + int nbf = 0; + do { + if (frames > kFrames) { + nbf = kFrames; + frames -= kFrames; + } else { + nbf = frames; + frames = 0; + } + DSP.compute(nbf, nullptr, ilv.inputs()); + ilv.interleave(); + WRITE_SAMPLE(out_sf, ilv.output(), nbf); + } while (nbf); + + sf_close(out_sf); + + // Possibly save state + if (is_rc) { + finterface.saveState(rcfilename); + } } } diff --git a/architecture/synthfile.cpp b/architecture/synthfile.cpp deleted file mode 100644 index bc9e276281..0000000000 --- a/architecture/synthfile.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/************************************************************************ - IMPORTANT NOTE : this file contains two clearly delimited sections : - the ARCHITECTURE section (in two parts) and the USER section. Each section - is governed by its own copyright and license. Please check individually - each section for license and copyright information. - *************************************************************************/ - -/******************* BEGIN synthfile.cpp ****************/ -/************************************************************************ - FAUST Architecture File - Copyright (C) 2003-2019 GRAME, Centre National de Creation Musicale - --------------------------------------------------------------------- - This Architecture section is free software; you can redistribute it - and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 3 of - the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; If not, see . - - EXCEPTION : As a special exception, you may create a larger work - that contains this FAUST architecture section and distribute - that work under terms of your choice, so long as this FAUST - architecture section is not modified. - - ************************************************************************ - ************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "faust/dsp/dsp.h" -#include "faust/gui/console.h" -#include "faust/gui/FUI.h" -#include "faust/gui/meta.h" -#include "faust/dsp/dsp-tools.h" -#include "faust/misc.h" - -using namespace std; - -/****************************************************************************** - ******************************************************************************* - - VECTOR INTRINSICS - - ******************************************************************************* - *******************************************************************************/ - -<> - -/********************END ARCHITECTURE SECTION (part 1/2)****************/ - -/**************************BEGIN USER SECTION **************************/ - -<> - -/***************************END USER SECTION ***************************/ - -/*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/ - - -// loptrm : Scan command-line arguments and remove and return long int value when found -long loptrm(int* argcP, char* argv[], const char* longname, const char* shortname, long def) -{ - int argc = *argcP; - for (int i = 2; i < argc; i++) { - if (strcmp(argv[i-1], shortname) == 0 || strcmp(argv[i-1], longname) == 0) { - int optval = atoi(argv[i]); - for (int j = i-1; j < argc-2; j++) { // make it go away for sake of "faust/gui/console.h" - argv[j] = argv[j+2]; - } - *argcP -= 2; - return optval; - } - } - return def; -} - -mydsp DSP; - -std::list GUI::fGuiList; -ztimedmap GUI::gTimedZoneMap; - -#define kFrames 512 -#define kSampleRate 44100 - -int main(int argc, char* argv[]) -{ - char name[256]; - char rcfilename[256]; - char* home = getenv("HOME"); - snprintf(name, 256, "%s", basename(argv[0])); - snprintf(rcfilename, 256, "%s/.%src", home, name); - - // Recall state before handling commands - FUI finterface; - DSP.buildUserInterface(&finterface); - - CMDUI* interface = new CMDUI(argc, argv, true); - DSP.buildUserInterface(interface); - if (argc == 1) { - interface->printhelp_command(OUTPUT_FILE); - exit(1); - } - interface->process_command(OUTPUT_FILE); - - int num_samples = loptrm(&argc, argv, "--samples", "-s", kSampleRate*5); - int sample_rate = loptrm(&argc, argv, "--sample-rate", "-sr", kSampleRate); - int bit_depth = loptrm(&argc, argv, "--bith-depth (16|24|32)", "-bd", 16); - bool is_rc = loptrm(&argc, argv, "-rc", "-rc", 0); - - int bd = (bit_depth == 16) ? SF_FORMAT_PCM_16 : ((bit_depth == 24) ? SF_FORMAT_PCM_24 : SF_FORMAT_PCM_32); - - // open output file - if (interface->files() == 0) { - interface->printhelp_command(OUTPUT_FILE); - exit(1); - } - SF_INFO out_info = { num_samples, sample_rate, DSP.getNumOutputs(), SF_FORMAT_WAV|bd|SF_ENDIAN_LITTLE, 0, 0}; - SNDFILE* out_sf = sf_open(interface->input_file(), SFM_WRITE, &out_info); - if (out_sf == NULL) { - cerr << "ERROR : "; - sf_perror(out_sf); - exit(1); - } - - // create interleaver - Interleaver ilv(kFrames, DSP.getNumOutputs(), DSP.getNumOutputs()); - - // init DSP with SR - DSP.init(sample_rate); - - // Possibly restore saved state - if (is_rc) { - finterface.recallState(rcfilename); - } - - // modify the UI values according to the command line options, after init - interface->process_init(); - - // process all samples - int frames = num_samples; - int nbf = 0; - do { - if (frames > kFrames) { - nbf = kFrames; - frames -= kFrames; - } else { - nbf = frames; - frames = 0; - } - DSP.compute(nbf, 0, ilv.inputs()); - ilv.interleave(); - sf_writef_float(out_sf, ilv.output(), nbf); - } while (nbf); - - sf_close(out_sf); - if (is_rc) { - finterface.saveState(rcfilename); - } -} - -/******************* END synthfile.cpp ****************/ - diff --git a/tools/faust2appls/faust2sndfile b/tools/faust2appls/faust2sndfile index ced5831512..a08edfb06b 100755 --- a/tools/faust2appls/faust2sndfile +++ b/tools/faust2appls/faust2sndfile @@ -14,6 +14,7 @@ CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used ARCHFILE=$FAUSTARCH/sndfile.cpp +FILE_MODE="" #------------------------------------------------------------------- # Set Faust include path @@ -56,9 +57,10 @@ for f in $FILES; do NINPUTS=${LINPUTS//[^0-9]/} if [ $NINPUTS -gt 0 ]; then echo "Will process an input file to produce an output file" - echo "With the compiled program 'foo', you can add [-c samples] for the number of frames to append beyond the input file" - echo "With the compiled program 'foo', you can add [-rc 1] to use the foo.rc file" - ARCHFILE=$FAUSTARCH/sndfile.cpp + echo "With the compiled program 'foo' you can add:" + echo "[-c samples] for the number of frames to append beyond the input file (default: 0)" + echo "[-rc 1] to use the foo.rc file" + FILE_MODE="INPUT_OUTPUT_FILE" else echo "Will generate an output file" echo "With the compiled program 'foo' you can add:" @@ -66,13 +68,13 @@ for f in $FILES; do echo "[-sr ] to setup the output file sample rate (default: 44100)" echo "[-s ] to setup the output file length in frames (default: SR*5)" echo "[-rc 1] to use the foo.rc file" - ARCHFILE=$FAUSTARCH/synthfile.cpp + FILE_MODE="OUTPUT_FILE" fi # compile Faust DSP then create the binary faust -i -a $ARCHFILE $OPTIONS "$f" -o "$f.cpp" || exit ( - $CXX $CXXFLAGS "$f.cpp" `pkg-config --cflags --static --libs sndfile` -o "${f%.dsp}" + $CXX $CXXFLAGS -DFILE_MODE=$FILE_MODE "$f.cpp" `pkg-config --cflags --static --libs sndfile` -o "${f%.dsp}" ) > /dev/null || exit # remove c++ file