diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-11-15 17:05:52 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-11-15 17:05:52 +0100 |
commit | 5f0efb26389f5610876d59b80d6ad6ca72cbce85 (patch) | |
tree | 77d951923ff0f3fffd3e459f19dd74fda6443ae8 /src | |
parent | e8f702516079ea4b5803adcb888150d3d7a760d4 (diff) |
Move zita-resampler inside wrapper.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 42 | ||||
-rw-r--r-- | src/drumgizmo.cc | 22 | ||||
-rw-r--r-- | src/drumgizmo.h | 5 | ||||
-rw-r--r-- | src/zrwrapper.cc | 150 | ||||
-rw-r--r-- | src/zrwrapper.h | 76 |
5 files changed, 270 insertions, 25 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 72eafdd..551c711 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,18 +1,35 @@ -noinst_LTLIBRARIES = libdg.la +noinst_LTLIBRARIES = libdg.la libzr.la libpugi.la +# libzita-resampler + +libzr_la_CPPFLAGS = \ + -ffast-math -D_USE_MATH_DEFINES -Wno-unused-private-field $(PTHREAD_CFLAGS) + +libzr_la_LIBADD = \ + $(PTHREAD_LIBS) + +libzr_la_SOURCES = \ + zrwrapper.cc \ + $(top_srcdir)/zita-resampler/libs/resampler.cc \ + $(top_srcdir)/zita-resampler/libs/resampler-table.cc + +# pugixml + +libpugi_la_CPPFLAGS = +libpugi_la_LIBADD = +libpugi_la_SOURCES = \ + $(top_srcdir)/pugixml/src/pugixml.cpp + +# libdg libdg_la_CPPFLAGS = \ -I$(top_srcdir)/hugin -I$(top_srcdir)/pugixml/src \ - $(SSEFLAGS) -D_USE_MATH_DEFINES -Wno-unused-private-field \ - -I$(top_srcdir)/zita-resampler/libs $(SNDFILE_CFLAGS) $(PTHREAD_CFLAGS) + $(SSEFLAGS) -I$(top_srcdir)/zita-resampler/libs + $(SNDFILE_CFLAGS) $(PTHREAD_CFLAGS) libdg_la_LIBADD = \ - $(SNDFILE_LIBS) $(PTHREAD_LIBS) + $(SNDFILE_LIBS) $(PTHREAD_LIBS) libzr.la libpugi.la -# If you add a file here, remember to add it to plugin/Makefile.mingw32.in -nodist_libdg_la_SOURCES = \ - $(top_srcdir)/pugixml/src/pugixml.cpp \ - $(top_srcdir)/zita-resampler/libs/resampler.cc \ - $(top_srcdir)/zita-resampler/libs/resampler-table.cc \ +libdg_la_SOURCES = \ audiocachefile.cc \ audiocache.cc \ audiocacheeventhandler.cc \ @@ -48,7 +65,9 @@ nodist_libdg_la_SOURCES = \ versionstr.cc EXTRA_DIST = \ - $(nodist_libdg_la_SOURCES) \ + $(libzr_la_SOURCES) \ + $(libpugi_la_SOURCES) \ + $(libdg_la_SOURCES) \ DGDOM.h \ atomic.h \ audio.h \ @@ -98,4 +117,5 @@ EXTRA_DIST = \ syncedsettings.h \ thread.h \ velocityfilter.h \ - versionstr.h + versionstr.h \ + zrwrapper.h diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index bec3e0f..65af878 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -211,10 +211,10 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) internal = true; } - zita[c].out_data = buf; - zita[c].out_count = nsamples; + zita[c].set_out_data(buf); + zita[c].set_out_count(nsamples); - if(zita[c].inp_count > 0) + if(zita[c].get_inp_count() > 0) { // Samples left from last iteration, process that one first zita[c].process(); @@ -222,12 +222,12 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) std::memset(resampler_input_buffer[c].get(), 0, MAX_RESAMPLER_BUFFER_SIZE); - zita[c].inp_data = resampler_input_buffer[c].get(); + zita[c].set_inp_data(resampler_input_buffer[c].get()); std::size_t sample_count = - std::ceil((nsamples - (nsamples - zita[c].out_count)) * ratio); - getSamples(c, kitpos, zita[c].inp_data, sample_count); + std::ceil((nsamples - (nsamples - zita[c].get_out_count())) * ratio); + getSamples(c, kitpos, zita[c].get_inp_data(), sample_count); - zita[c].inp_count = sample_count; + zita[c].set_inp_count(sample_count); zita[c].process(); if(!internal) { @@ -455,13 +455,13 @@ void DrumGizmo::setSamplerate(float samplerate) // Prefill auto null_size = zita[c].inpsize() - 1;// / 2 - 1; - zita[c].inp_data = nullptr; - zita[c].inp_count = null_size; + zita[c].set_inp_data(nullptr); + zita[c].set_inp_count(null_size); constexpr auto sz = 4096 * 16; sample_t s[sz]; - zita[c].out_data = s; - zita[c].out_count = sz; + zita[c].set_out_data(s); + zita[c].set_out_count(sz); zita[c].process(); } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 9d2e661..8a423d1 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -33,8 +33,6 @@ #include <array> #include <memory> -#include <zita-resampler/resampler.h> - #include "audiooutputengine.h" #include "audioinputengine.h" #include "events.h" @@ -44,6 +42,7 @@ #include "audiocache.h" #include "settings.h" #include "inputprocessor.h" +#include "zrwrapper.h" #define REFSFILE "refs.conf" @@ -102,7 +101,7 @@ protected: SettingsGetter settings_getter; Random rand; - std::array<Resampler, NUM_CHANNELS> zita; + std::array<ZRWrapper, NUM_CHANNELS> zita; std::array<std::unique_ptr<sample_t>, NUM_CHANNELS> resampler_input_buffer; double ratio = 1.0; diff --git a/src/zrwrapper.cc b/src/zrwrapper.cc new file mode 100644 index 0000000..29559fc --- /dev/null +++ b/src/zrwrapper.cc @@ -0,0 +1,150 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * zrwrapper.cc + * + * Fri Nov 15 15:06:51 CET 2019 + * Copyright 2019 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "zrwrapper.h" + +#include <zita-resampler/resampler.h> + +#include "cpp11fix.h" + +ZRWrapper::ZRWrapper() + : resampler(std::make_unique<Resampler>()) +{ +} + +ZRWrapper::~ZRWrapper() = default; + +int ZRWrapper::setup(unsigned int fs_inp, + unsigned int fs_out, + unsigned int nchan, + unsigned int hlen) +{ + return resampler->setup(fs_inp, fs_out, nchan, hlen); +} + +int ZRWrapper::setup(unsigned int fs_inp, + unsigned int fs_out, + unsigned int nchan, + unsigned int hlen, + double frel) +{ + return resampler->setup(fs_inp, fs_out, nchan, hlen, frel); +} + +void ZRWrapper::clear() +{ + resampler->clear(); +} + +int ZRWrapper::reset() +{ + return resampler->reset(); +} + +int ZRWrapper::nchan() const +{ + return resampler->nchan(); +} + +int ZRWrapper::filtlen() const +{ + return resampler->filtlen(); +} + +int ZRWrapper::inpsize() const +{ + return resampler->inpsize(); +} + +double ZRWrapper::inpdist() const +{ + return resampler->inpdist(); +} + +int ZRWrapper::process() +{ + return resampler->process(); +} + +unsigned int ZRWrapper::get_inp_count() +{ + return resampler->inp_count; +} + +void ZRWrapper::set_inp_count(unsigned int inp_count) +{ + resampler->inp_count = inp_count; +} + +unsigned int ZRWrapper::get_out_count() +{ + return resampler->out_count; +} + +void ZRWrapper::set_out_count(unsigned int out_count) +{ + resampler->out_count = out_count; +} + +float *ZRWrapper::get_inp_data() +{ + return resampler->inp_data; +} + +void ZRWrapper::set_inp_data(float *inp_data) +{ + resampler->inp_data = inp_data; +} + +float *ZRWrapper::get_out_data() +{ + return resampler->out_data; +} + +void ZRWrapper::set_out_data(float *out_data) +{ + resampler->out_data = out_data; +} + +void *ZRWrapper::get_inp_list() +{ + return resampler->inp_list; +} + +void ZRWrapper::set_inp_list(void *inp_list) +{ + resampler->inp_list = inp_list; +} + +void *ZRWrapper::get_out_list() +{ + return resampler->out_list; +} + +void ZRWrapper::set_out_list(void *out_list) +{ + resampler->out_list = out_list; +} diff --git a/src/zrwrapper.h b/src/zrwrapper.h new file mode 100644 index 0000000..6299a31 --- /dev/null +++ b/src/zrwrapper.h @@ -0,0 +1,76 @@ +/* -*- Mode: c++ -*- */ +/*************************************************************************** + * zrwrapper.h + * + * Fri Nov 15 15:06:51 CET 2019 + * Copyright 2019 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#pragma once + +#include <memory> + +class ZRWrapper +{ +public: + ZRWrapper(); + ~ZRWrapper(); + + int setup(unsigned int fs_inp, + unsigned int fs_out, + unsigned int nchan, + unsigned int hlen); + + int setup(unsigned int fs_inp, + unsigned int fs_out, + unsigned int nchan, + unsigned int hlen, + double frel); + + void clear(); + int reset(); + int nchan() const; + int filtlen() const; + int inpsize() const; + double inpdist() const; + int process(); + + unsigned int get_inp_count(); + void set_inp_count(unsigned int inp_count); + + unsigned int get_out_count(); + void set_out_count(unsigned int out_count); + + float *get_inp_data(); + void set_inp_data(float *inp_data); + + float *get_out_data(); + void set_out_data(float *out_data); + + void *get_inp_list(); + void set_inp_list(void *inp_list); + + void *get_out_list(); + void set_out_list(void *out_list); + +private: + std::unique_ptr<class Resampler> resampler; +}; |