diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-03-29 11:01:21 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-31 17:35:47 +0200 |
commit | 94d33d51ee136d88a2d81bfce47efd2836e845d0 (patch) | |
tree | 9a27e8ac61cf3872386f9d4d154cfb1dfd2b0b0c /src | |
parent | 13b5fabc8c3722e7e30b22d50f44e2a3bba3ef11 (diff) |
Refactored class BeatMapper
Diffstat (limited to 'src')
-rw-r--r-- | src/beatmapper.cc | 76 | ||||
-rw-r--r-- | src/beatmapper.h | 22 |
2 files changed, 53 insertions, 45 deletions
diff --git a/src/beatmapper.cc b/src/beatmapper.cc index 78441cb..b61f0b5 100644 --- a/src/beatmapper.cc +++ b/src/beatmapper.cc @@ -30,48 +30,58 @@ #define DEF 2.0 -BeatMapper::BeatMapper(Instrument *instrument) +BeatMapper::BeatMapper(const Instrument& instrument) + : instrument{instrument} + , hist{} + , C{1.3} + , mindist{4} + , last{mindist} { - this->instrument = instrument; - for(size_t i = 0; i < HISTORY_SIZE; i++) hist[i] = DEF; - C = 1.3; - mindist = 4; - last = mindist; + for(size_t i = 0; i < HISTORY_SIZE; ++i) + { + hist[i] = DEF; + } } - -Sample *BeatMapper::map(jack_nframes_t nframes) +Sample* BeatMapper::map(jack_nframes_t nframes) { - return NULL; - Sample *sample = NULL; - - jack_default_audio_sample_t *buffer; - buffer = (jack_default_audio_sample_t *)jack_port_get_buffer(instrument->port, nframes); - - float e = 0.0; - for(size_t i = 0; i < nframes; i++) { - e += buffer[i] * buffer[i]; - } + return nullptr; + + // moved the following to comment by glocke since return makes this + // unreachable + /* + Sample *sample = nullptr; + + jack_default_audio_sample_t *buffer; + buffer = (jack_default_audio_sample_t + *)jack_port_get_buffer(instrument->port, nframes); + + float e = 0.0; + for(size_t i = 0; i < nframes; i++) { + e += buffer[i] * buffer[i]; + } - float E = 0.0; - for(size_t i = 0; i < HISTORY_SIZE; i++) E += hist[i] / (float)HISTORY_SIZE; - if(E == 0) E = DEF; // We do not have a connection + float E = 0.0; + for(size_t i = 0; i < HISTORY_SIZE; i++) E += hist[i] / (float)HISTORY_SIZE; + if(E == 0) E = DEF; // We do not have a connection - // printf("last: %d, E: %f, e: %f - threshold: %f\n", last, E, e, 1.3 * E); + // printf("last: %d, E: %f, e: %f - threshold: %f\n", last, E, e, 1.3 * + E); - // Shift history and save new value - for(size_t i = 0; i < HISTORY_SIZE - 1; i++) hist[i] = hist[i+1]; - hist[HISTORY_SIZE - 1] = e>DEF?e:DEF; + // Shift history and save new value + for(size_t i = 0; i < HISTORY_SIZE - 1; i++) hist[i] = hist[i+1]; + hist[HISTORY_SIZE - 1] = e>DEF?e:DEF; - if(instrument->name == "hihat" && e > 0) printf("e: %f\n", e); + if(instrument->name == "hihat" && e > 0) printf("e: %f\n", e); - if(e > C * E && last > mindist) { - Velocity *v = instrument->getVelocity(127); - if(v) sample = v->getSample(); - } + if(e > C * E && last > mindist) { + Velocity *v = instrument->getVelocity(127); + if(v) sample = v->getSample(); + } - last++; - if(sample) last = 0; + last++; + if(sample) last = 0; - return sample; + return sample; + */ } diff --git a/src/beatmapper.h b/src/beatmapper.h index fde1988..405b3d6 100644 --- a/src/beatmapper.h +++ b/src/beatmapper.h @@ -24,8 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_BEATMAPPER_H__ -#define __DRUMGIZMO_BEATMAPPER_H__ +#pragma once #include <jack/jack.h> @@ -36,19 +35,18 @@ #define HISTORY_SIZE 200 -class BeatMapper { +class BeatMapper +{ public: - BeatMapper(Instrument *instrument); + BeatMapper(const Instrument& instrument); - Sample *map(jack_nframes_t nframes); + Sample* map(jack_nframes_t nframes); private: - Instrument *instrument; - float hist[HISTORY_SIZE]; - float C; + const Instrument& instrument; + float hist[HISTORY_SIZE]; + float C; - size_t mindist; - size_t last; + size_t mindist; + size_t last; }; - -#endif/*__DRUMGIZMO_BEATMAPPER_H__*/ |