diff --git a/src/dmxPersonality.h b/src/dmxPersonality.h index a9977d8..b083ae6 100644 --- a/src/dmxPersonality.h +++ b/src/dmxPersonality.h @@ -1,19 +1,19 @@ #ifndef DMXPERSONALITY_H #define DMXPERSONALITY_H -#define VOLUME_COARSE 3 -#define PAN 6 #define DMX_FOLDER 0 #define DMX_FILE 1 -#define PLAYBACK 8 #define VOLUME_FINE 2 -#define ENTRY_POINT_COARSE 5 +#define VOLUME_COARSE 3 #define ENTRY_POINT_FINE 4 +#define ENTRY_POINT_COARSE 5 +#define PAN 6 #define PITCH 7 -#define VOL1 9 -#define VOL2 10 -#define LOW_FREQ 11 -#define LOW_Q 12 +#define PLAYBACK 8 +#define HP_FREQ 9 +#define LOW_FREQ 10 +#define LOW_Q 11 +#define LOW_GAIN 12 #define MIDLOW_FREQ 13 #define MIDLOW_Q 14 #define MIDLOW_GAIN 15 @@ -22,7 +22,9 @@ #define MIDHIGH_GAIN 18 #define HIGH_FREQ 19 #define HIGH_Q 20 - -#define LAYER_CHANNELS 21 +#define HIGH_GAIN 21 +#define SEND1 22 +#define SEND2 23 +#define LAYER_CHANNELS 24 #endif // DMXPERSONALITY_H diff --git a/src/libremediaserver-audio.cpp b/src/libremediaserver-audio.cpp index d516e6c..07ab9a8 100644 --- a/src/libremediaserver-audio.cpp +++ b/src/libremediaserver-audio.cpp @@ -140,9 +140,8 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value) m_played.append(m_ola->getValue(layer, DMX_FILE)); } #endif - } else if (channel >= LOW_FREQ) { + } else if (channel >= HP_FREQ && channel <= HIGH_GAIN) { m_mae.filterParamChanged(layer, m_dmxSettings.at(layer).audioDevice, channel, value); - } } #ifndef NOGUI diff --git a/src/miniaudioengine.cpp b/src/miniaudioengine.cpp index 01e274a..9dbd3c8 100644 --- a/src/miniaudioengine.cpp +++ b/src/miniaudioengine.cpp @@ -1,10 +1,8 @@ #include "miniaudioengine.h" #include "dmxPersonality.h" -#define LPF_BIAS 0.9f -#define FILTER_ORDER 2 -#define LPF_CUTOFF_FACTOR 2 -#define HPF_CUTOFF_FACTOR 20 +#define BIAS 0.99f +#define FILTER_ORDER 3 MiniAudioEngine::MiniAudioEngine() {} @@ -26,9 +24,11 @@ void MiniAudioEngine::stopEngine() for (uint i = 0; i < m_devicesSelected; i++) { for (uint j = 0; j < m_layersQty; j++) { ma_hpf_node_uninit(&m_filterBank[i][j].hpf, NULL); - ma_lpf_node_uninit(&m_filterBank[i][j].lpf, NULL); + ma_loshelf_node_uninit(&m_filterBank[i][j].loshelf, NULL); ma_peak_node_uninit(&m_filterBank[i][j].mLow, NULL); ma_peak_node_uninit(&m_filterBank[i][j].mHigh, NULL); + ma_hishelf_node_uninit(&m_filterBank[i][j].hishelf, NULL); + ma_splitter_node_uninit(&m_filterBank[i][j].output, NULL); } ma_engine_uninit(&m_engine[i]); ma_device_uninit(&m_device[i]); @@ -57,7 +57,6 @@ bool MiniAudioEngine::startEngine(uint layers) return true; } -// lpf -> hpf -> mLow -> mHigh -> engine ma_result MiniAudioEngine::createFilterBank(int id, uint layer) { ma_result result; @@ -66,52 +65,76 @@ ma_result MiniAudioEngine::createFilterBank(int id, uint layer) ma_node *endpoint = ma_engine_get_endpoint(&m_engine[id]); filterBank *fb = &m_filterBank[id][layer]; - ma_lpf_node_config lpfConfig = ma_lpf_node_config_init(CHANNELS, SAMPLE_RATE, SAMPLE_RATE / LPF_CUTOFF_FACTOR, FILTER_ORDER); - fb->lpfConfig = ma_lpf_config_init(FORMAT, CHANNELS, SAMPLE_RATE, SAMPLE_RATE / LPF_CUTOFF_FACTOR, FILTER_ORDER); - result = ma_lpf_node_init(ng, &lpfConfig, NULL, &fb->lpf); - if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to initialize low pass filter node." << endl; - return result; - } - ma_hpf_node_config hpfConfig = ma_hpf_node_config_init(CHANNELS, SAMPLE_RATE, HPF_CUTOFF_FACTOR, FILTER_ORDER); - fb->hpfConfig = ma_hpf_config_init(FORMAT, CHANNELS, SAMPLE_RATE, HPF_CUTOFF_FACTOR, FILTER_ORDER); - result = ma_hpf_node_init(ng, &hpfConfig, NULL, &fb->hpf); + fb->hpfConfig = ma_hpf_node_config_init(CHANNELS, SAMPLE_RATE, 16, FILTER_ORDER); + result = ma_hpf_node_init(ng, &fb->hpfConfig, NULL, &fb->hpf); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to initialize high pass filter node." << endl; return result; } - ma_peak_node_config mLowConfig = ma_peak_node_config_init(CHANNELS, SAMPLE_RATE, 1.0, 5.0, 300); // double gainDB, double q, double frequency); - fb->mLowConfig = ma_peak2_config_init(FORMAT, CHANNELS, SAMPLE_RATE, 100.0, 50.0, 1000); - result = ma_peak_node_init(ng, &mLowConfig, NULL, &fb->mLow); + + fb->loshelfConfig = ma_loshelf_node_config_init(CHANNELS, SAMPLE_RATE, 0.0f, 1.0f, 30); + result = ma_loshelf_node_init(ng, &fb->loshelfConfig, NULL, &fb->loshelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to initialize low pass filter node." << endl; + return result; + } + + fb->mLowConfig = ma_peak_node_config_init(CHANNELS, SAMPLE_RATE, 0.0, 4.0, 200); // double gainDB, double q, double frequency); + result = ma_peak_node_init(ng, &fb->mLowConfig, NULL, &fb->mLow); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to initialize peak low filter node." << endl; return result; } - ma_peak_node_config mHighConfig = ma_peak_node_config_init(CHANNELS, SAMPLE_RATE, 0.0, 0.0, 1000); // double gainDB, double q, double frequency); - fb->mHighConfig = ma_peak2_config_init(FORMAT, CHANNELS, SAMPLE_RATE, 0.0, 0.0, 220); - result = ma_peak_node_init(ng, &mHighConfig, NULL, &fb->mHigh); + + fb->mHighConfig = ma_peak_node_config_init(CHANNELS, SAMPLE_RATE, 0.0, 0.0, 600); // double gainDB, double q, double frequency); + result = ma_peak_node_init(ng, &fb->mHighConfig, NULL, &fb->mHigh); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to initialize peak high filter node." << endl; return result; } - result = ma_node_attach_output_bus(&fb->lpf, 0, &fb->hpf, 0); + + fb->hishelfConfig = ma_hishelf_node_config_init(CHANNELS, SAMPLE_RATE, 0.0f, 1.0f, 20000); + result = ma_hishelf_node_init(ng, &fb->hishelfConfig, NULL, &fb->hishelf); if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to attach low pass filter node." << endl; + cout << "ERROR " << result << ": Failed to initialize hi shelf filter node." << endl; return result; } - result = ma_node_attach_output_bus(&fb->hpf, 0, &fb->mLow, 0); + + ma_splitter_node_config splitterConfig = ma_splitter_node_config_init(CHANNELS); + result = ma_splitter_node_init(ng, &splitterConfig, NULL, &fb->output); if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to attach Mid Low pass filter node." << endl; + cout << "ERROR " << result << ": Failed to initialize output node." << endl; + return result; + } + + result = ma_node_attach_output_bus(&fb->hpf, 0, &fb->loshelf, 0); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to attach high pass pass filter node." << endl; + return result; + } + result = ma_node_attach_output_bus(&fb->loshelf, 0, &fb->mLow, 0); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to attach low shelf filter node." << endl; return result; } result = ma_node_attach_output_bus(&fb->mLow, 0, &fb->mHigh, 0); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to attach low peaks filter node." << endl; + return result; + } + result = ma_node_attach_output_bus(&fb->mHigh, 0, &fb->hishelf, 0); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to attach high peaks filter node." << endl; return result; } - result = ma_node_attach_output_bus(&fb->mHigh, 0, endpoint, 0); + result = ma_node_attach_output_bus(&fb->hishelf, 0, &fb->output, 0); if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to attach high peaks filter node." << endl; + cout << "ERROR " << result << ": Failed to attach high shelf filter node." << endl; + return result; + } + result = ma_node_attach_output_bus(&fb->output, 0, endpoint, 0); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to attach output node to engine." << endl; return result; } return result; @@ -233,7 +256,7 @@ ma_result MiniAudioEngine::loadMedia(int layer, char *file, uint audioDevice) cout << "Error " << result << ": Failed to load file " << file << endl; return result; } - result = ma_node_attach_output_bus(&m_currentSound[layer], 0, &m_filterBank[audioDevice][layer].lpf, 0); + result = ma_node_attach_output_bus(&m_currentSound[layer], 0, &m_filterBank[audioDevice][layer].hpf, 0); if (result != MA_SUCCESS) { cout << "Error " << result << ": Failed to attach output bus " << audioDevice << endl; //return result; @@ -406,64 +429,97 @@ ma_result MiniAudioEngine::filterParamChanged(int layer, int audioDevice, int ch filterBank *fb = &m_filterBank[audioDevice][layer]; - if (channel == LOW_FREQ) { - fb->hpfConfig.cutoffFrequency = (value * 2) + 20; - result = ma_hpf_node_reinit(&fb->hpfConfig, &fb->hpf); + if (channel == HP_FREQ) { + fb->hpfConfig.hpf.cutoffFrequency = double((value * 1.31) + 16.0f); // 16 - 350 + result = ma_hpf_node_reinit(&fb->hpfConfig.hpf, &fb->hpf); if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to set frecuency Low filter node." << endl; + cout << "ERROR " << result << ": Failed to set frecuency high pass filter node." << endl; return result; } - } else if (channel == HIGH_FREQ) { - fb->lpfConfig.cutoffFrequency = 22000 - (value * 80); - result = ma_lpf_node_reinit(&fb->lpfConfig, &fb->lpf); + } else if (channel == LOW_FREQ) { + fb->loshelfConfig.loshelf.frequency = 30 + (value * 1.647); // 30 - 450 + result = ma_loshelf_node_reinit(&fb->loshelfConfig.loshelf, &fb->loshelf); if (result != MA_SUCCESS) { - cout << "ERROR " << result << ": Failed to set frecuency High filter node." << endl; + cout << "ERROR " << result << ": Failed to set frecuency low shelf filter node." << endl; + return result; + } + } else if (channel == LOW_Q) { + fb->loshelfConfig.loshelf.shelfSlope = (double)(value / 32.0f) + 0.1f; // 0.1 - 8 + result = ma_loshelf_node_reinit(&fb->loshelfConfig.loshelf, &fb->loshelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed set Q low shelf filter node." << endl; + return result; + } + } else if (channel == LOW_GAIN) { + fb->loshelfConfig.loshelf.gainDB = (double)(value / 21.25f) - 6.023528412f; + result = ma_loshelf_node_reinit(&fb->loshelfConfig.loshelf, &fb->loshelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed set gain low shelf filter node." << endl; return result; } } else if (channel == MIDLOW_FREQ) { - fb->mLowConfig.frequency = 60 + (value * 4); - result = ma_peak_node_reinit(&fb->mLowConfig, &fb->mLow); + fb->mLowConfig.peak.frequency = 200 + (value * 9.019607843); // 200 - 450 + result = ma_peak_node_reinit(&fb->mLowConfig.peak, &fb->mLow); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set frecuency Mid Low pass filter node." << endl; return result; } - cout << "frec " << fb->mLowConfig.frequency << endl; } else if (channel == MIDLOW_Q) { - fb->mLowConfig.q = (double)( value / 32.0f) + 0.50; - result = ma_peak_node_reinit(&fb->mLowConfig, &fb->mLow); + fb->mLowConfig.peak.q = (double)( value / 64.0f) + 0.10; // 0.1 - 4 + result = ma_peak_node_reinit(&fb->mLowConfig.peak, &fb->mLow); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set Q Mid Low filter node." << endl; return result; } - cout << "Q " << fb->mLowConfig.q << endl; } else if (channel == MIDLOW_GAIN) { - fb->mLowConfig.gainDB = (double)(value / 8.0f) - 16.0f; - result = ma_peak_node_reinit(&fb->mLowConfig, &fb->mLow); + fb->mLowConfig.peak.gainDB = (double)(value / 7.0833333333333f) - 18.0f; + result = ma_peak_node_reinit(&fb->mLowConfig.peak, &fb->mLow); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set gain Mid Low filter node." << endl; return result; } } else if (channel == MIDHIGH_FREQ) { - fb->mHighConfig.frequency = 400 + (value * 32); - result = ma_peak_node_reinit(&fb->mHighConfig, &fb->mHigh); + fb->mHighConfig.peak.frequency = 600 + (value * 25.09803922); // 600 - 7000 + result = ma_peak_node_reinit(&fb->mHighConfig.peak, &fb->mHigh); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set frecuency Mid High filter node." << endl; return result; } } else if (channel == MIDHIGH_Q) { - fb->mHighConfig.q = (double)( value / 32.0f) + 0.50; - result = ma_peak_node_reinit(&fb->mHighConfig, &fb->mHigh); + fb->mHighConfig.peak.q = (double)( value / 64.0f) + 0.10; // 0.1 - 4 + result = ma_peak_node_reinit(&fb->mHighConfig.peak, &fb->mHigh); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set Q Mid High filter node." << endl; return result; } } else if (channel == MIDHIGH_GAIN) { - fb->mHighConfig.gainDB = (double)(value / 8.0f) - 16.0f; - result = ma_peak_node_reinit(&fb->mHighConfig, &fb->mHigh); + fb->mHighConfig.peak.gainDB = (double)(value / 7.0833333333333f) - 18.0f; + result = ma_peak_node_reinit(&fb->mHighConfig.peak, &fb->mHigh); if (result != MA_SUCCESS) { cout << "ERROR " << result << ": Failed to set gain Mid High filter node." << endl; return result; } + } else if (channel == HIGH_FREQ) { + fb->hishelfConfig.hishelf.frequency = 1500 + (value * 56.8627451); // 1500 - 16000 + result = ma_hishelf_node_reinit(&fb->hishelfConfig.hishelf, &fb->hishelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed to frecuency high shelf filter node." << endl; + return result; + } + } else if (channel == HIGH_Q) { + fb->hishelfConfig.hishelf.shelfSlope = (double)( value / 32.0f) + 0.1f; + result = ma_hishelf_node_reinit(&fb->hishelfConfig.hishelf, &fb->hishelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed set Q high shelf filter node." << endl; + return result; + } + } else if (channel == HIGH_GAIN) { + fb->hishelfConfig.hishelf.gainDB = (double)(value / 21.25) - 6.023528412f; + result = ma_hishelf_node_reinit(&fb->hishelfConfig.hishelf, &fb->hishelf); + if (result != MA_SUCCESS) { + cout << "ERROR " << result << ": Failed set gain high shelf filter node." << endl; + return result; + } } return (result); } diff --git a/src/miniaudioengine.h b/src/miniaudioengine.h index d5d798b..332c1bf 100644 --- a/src/miniaudioengine.h +++ b/src/miniaudioengine.h @@ -20,14 +20,16 @@ using namespace std; typedef struct { ma_hpf_node hpf; - ma_hpf_config hpfConfig; - ma_lpf_node lpf; - ma_lpf_config lpfConfig; + ma_hpf_node_config hpfConfig; + ma_loshelf_node loshelf; + ma_loshelf_node_config loshelfConfig; ma_peak_node mLow; - ma_peak_config mLowConfig; + ma_peak_node_config mLowConfig; ma_peak_node mHigh; - ma_notch_node notch; - ma_peak_config mHighConfig; + ma_peak_node_config mHighConfig; + ma_hishelf_node hishelf; + ma_hishelf_node_config hishelfConfig; + ma_splitter_node output; } filterBank;