From 471e91867e5911094c349b78eaf7f8b6263720e3 Mon Sep 17 00:00:00 2001 From: jakubfiala Date: Sun, 28 Dec 2014 13:56:12 +0100 Subject: added maxiBark --- ofxMaxim/ofxMaxim/install.xml | 2 + ofxMaxim/ofxMaxim/libs/maxiBark.cpp | 10 +++ ofxMaxim/ofxMaxim/libs/maxiBark.h | 133 ++++++++++++++++++++++++++++++++++++ ofxMaxim/ofxMaxim/src/ofxMaxim.h | 1 + 4 files changed, 146 insertions(+) create mode 100644 ofxMaxim/ofxMaxim/libs/maxiBark.cpp create mode 100644 ofxMaxim/ofxMaxim/libs/maxiBark.h (limited to 'ofxMaxim') diff --git a/ofxMaxim/ofxMaxim/install.xml b/ofxMaxim/ofxMaxim/install.xml index 58923be..e42de73 100644 --- a/ofxMaxim/ofxMaxim/install.xml +++ b/ofxMaxim/ofxMaxim/install.xml @@ -21,6 +21,8 @@ ../../../addons/ofxMaxim/libs/fft.cpp ../../../addons/ofxMaxim/libs/fftOctaveAnalyzer.h ../../../addons/ofxMaxim/libs/fftOctaveAnalyzer.cpp + ../../../addons/ofxMaxim/libs/maxiBark.cpp + ../../../addons/ofxMaxim/libs/maxiBark.h ../../../addons/ofxMaxim/libs/maximilian.h ../../../addons/ofxMaxim/libs/maximilian.cpp diff --git a/ofxMaxim/ofxMaxim/libs/maxiBark.cpp b/ofxMaxim/ofxMaxim/libs/maxiBark.cpp new file mode 100644 index 0000000..634a779 --- /dev/null +++ b/ofxMaxim/ofxMaxim/libs/maxiBark.cpp @@ -0,0 +1,10 @@ +/* + * maxiBark.cpp + * Bark scale loudness + * + * Created by Jakub on 01/12/2014. + * Copyright 2014 Goldsmiths Creative Computing. All rights reserved. + * + */ + +#include "maxiBark.h" diff --git a/ofxMaxim/ofxMaxim/libs/maxiBark.h b/ofxMaxim/ofxMaxim/libs/maxiBark.h new file mode 100644 index 0000000..dbb4a86 --- /dev/null +++ b/ofxMaxim/ofxMaxim/libs/maxiBark.h @@ -0,0 +1,133 @@ +/* + * maxiBark.cpp + * Bark scale loudness + * + * Created by Jakub on 01/12/2014. + * Copyright 2014 Goldsmiths Creative Computing. All rights reserved. + * + */ + +#pragma once +#pragma pack(16) + +#include "maxiFFT.h" +#include +#include +//#include +#include +#ifdef __APPLE_CC__ +#include +#endif + +using namespace std; + +//convert to Bark scale (Zwicker, 1961) +inline double hzToBark(double hz) { + return 13.0*atan(hz/1315.8) + 3.5*atan(pow((hz/7518.0),2)); +} + +inline double binToHz(unsigned int bin, unsigned int sR, unsigned int bS) { + return bin*sR/bS; +} + +template + +class maxiBarkScaleAnalyser { +public: + int NUM_BARK_BANDS; + + void setup(unsigned int sR, unsigned int bS) { + this->sampleRate = sR; + this->bufferSize = bS; + specSize = bS/2; + NUM_BARK_BANDS = 24; + for (int i=0; i currentBandEnd) { + bbLimits[currentBand] = i; + currentBand++; + currentBandEnd = currentBand*barkScale[specSize-1]/NUM_BARK_BANDS; + } + } + + bbLimits[NUM_BARK_BANDS] = specSize-1; + }; + + double* specificLoudness(float* normalisedSpectrum) { + for (int i = 0; i < NUM_BARK_BANDS; i++){ + double sum = 0; + for (int j = bbLimits[i] ; j < bbLimits[i+1] ; j++) { + + sum += normalisedSpectrum[j]; + } + specific[i] = pow(sum,0.23); + } + + return specific; + }; + + double* relativeLoudness(float* normalisedSpectrum) { + for (int i = 0; i < NUM_BARK_BANDS; i++){ + double sum = 0; + for (int j = bbLimits[i] ; j < bbLimits[i+1] ; j++) { + + sum += normalisedSpectrum[j]; + } + specific[i] = pow(sum,0.23); + } + + double max = 0; + for (int i = 0; i < NUM_BARK_BANDS; i++){ + if (specific[i] > max) max = specific[i]; + } + + for (int i = 0; i < NUM_BARK_BANDS; i++){ + relative[i] = specific[i]/max; + } + + return relative; + }; + + double* totalLoudness(float* normalisedSpectrum) { + for (int i = 0; i < NUM_BARK_BANDS; i++){ + double sum = 0; + for (int j = bbLimits[i] ; j < bbLimits[i+1] ; j++) { + + sum += normalisedSpectrum[j]; + } + specific[i] = pow(sum,0.23); + } + + total[0] = 0; + + for (int i = 0; i < 24; i++){ + total[0] += specific[i]; + } + + return total; + }; + +private: + int bbLimits[24]; + unsigned int sampleRate, bufferSize, specSize; + double barkScale[2048]; + double specific[24]; + double relative[24]; + double total[1]; + +}; + +typedef maxiBarkScaleAnalyser maxiBark; + + + + + + diff --git a/ofxMaxim/ofxMaxim/src/ofxMaxim.h b/ofxMaxim/ofxMaxim/src/ofxMaxim.h index b197723..e902f14 100644 --- a/ofxMaxim/ofxMaxim/src/ofxMaxim.h +++ b/ofxMaxim/ofxMaxim/src/ofxMaxim.h @@ -37,6 +37,7 @@ #include "maxiFFT.h" #include "maxiGrains.h" #include "maxiMFCC.h" +#include "maxiBark.h" typedef maxiMix ofxMaxiMix; -- cgit v1.3