Permalink
Browse files

Merge branch 'master' of github.com:mbrucher/QtVST

  • Loading branch information...
mbrucher committed Mar 17, 2013
2 parents 873629f + e257796 commit 06d3858f3a75b8e720927b7d7c35bd9f1ce357dc
@@ -9,6 +9,9 @@ main_variable_filter = env.Install('$BINDIR', main_variable_filter)
main_simple_eq = env.Program('simple_eq', "main_simple_eq.cpp", LIBS=env['filter'])
main_simple_eq = env.Install('$BINDIR', main_simple_eq)
main_time_varying_filter = env.Program('time_varying_filter', "main_time_varying_filter.cpp", LIBS=env['filter'])
main_time_varying_filter = env.Install('$BINDIR', main_time_varying_filter)
main_simple_overdrive = env.Program('simple_overdrive', "main_simple_overdrive.cpp", LIBS=env['filter'])
main_simple_overdrive = env.Install('$BINDIR', main_simple_overdrive)
@@ -9,9 +9,17 @@
Samples = 400000
FreqMax = 20000
clims = None
def plot_me(signal, i, imax, MySampleRate = SampleRate, NFFT = 8192, noverlap = 1024):
global clims
a = pyplot.subplot(imax, 1, i + 1)
pyplot.specgram(signal, NFFT = NFFT, Fs = MySampleRate, noverlap = noverlap )
(Pxx, freqs, bins, im) = pyplot.specgram(signal, NFFT = NFFT, Fs = MySampleRate, noverlap = noverlap )
if clims is None:
Pxx = 10 * np.log10(Pxx)
clims = Pxx.min(), Pxx.max()
pyplot.clim(*clims)
pyplot.colorbar()
signal = np.fromfile(sys.argv[1])
signal2 = np.fromfile(sys.argv[2])
@@ -0,0 +1,78 @@
/**
* \file main_time_varying_filter.cpp
*/
#include <fstream>
#include <boost/scoped_ptr.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
#include "second_order_filter.h"
#include "time_varying_second_order_filter.h"
const unsigned long size = 2000000;
const unsigned int sample_rate = 96000;
const unsigned int max_frequency = 20000;
double in[size];
double temp[size];
double out[size];
DSP::MonoFilter<double>* create_low_wah()
{
DSP::TimeVaryingSecondOrderFilter<DSP::TimeVaryingBandPassCoefficients<double> >* filter = new DSP::TimeVaryingSecondOrderFilter<DSP::TimeVaryingBandPassCoefficients<double> >;
filter->set_sampling_frequency(sample_rate);
filter->set_cut_frequency_min(100);
filter->set_cut_frequency_max(10000);
filter->set_angle_offset(0);
filter->set_period(sample_rate*4);
filter->set_Q(1);
return filter;
}
DSP::MonoFilter<double>* create_high_wah()
{
DSP::TimeVaryingSecondOrderFilter<DSP::TimeVaryingBandPassCoefficients<double> >* filter = new DSP::TimeVaryingSecondOrderFilter<DSP::TimeVaryingBandPassCoefficients<double> >;
filter->set_sampling_frequency(sample_rate);
filter->set_cut_frequency_min(8000);
filter->set_cut_frequency_max(10000);
filter->set_angle_offset(boost::math::constants::pi<double>() / 2);
filter->set_period(sample_rate*8);
filter->set_Q(1);
return filter;
}
int main(int argc, char** argv)
{
boost::scoped_ptr<DSP::MonoFilter<double> > low_wah_filter(create_low_wah());
boost::scoped_ptr<DSP::MonoFilter<double> > high_wah_filter(create_high_wah());
boost::mt19937 engine(0);
boost::normal_distribution<double> generator;
boost::variate_generator<boost::mt19937, boost::normal_distribution<double> > binded(engine, generator);
for(int i = 0; i < size; ++i)
{
in[i] = binded();
}
low_wah_filter->process(in, out, size);
high_wah_filter->process(in, temp, size);
for(int i = 0; i < size; ++i)
{
out[i] += temp[i];
}
std::ofstream infile("in_time_varying.raw", std::ofstream::binary);
infile.write(reinterpret_cast<const char*>(in), size * sizeof(double));
std::ofstream outfile("out_time_varying.raw", std::ofstream::binary);
outfile.write(reinterpret_cast<const char*>(out), size * sizeof(double));
return 0;
}
@@ -26,7 +26,7 @@ class BandPassCoefficients
void compute_coeffs()
{
DataType c = std::tan(boost::math::constants::pi<DataType>() * bandwidth_frequency / sampling_frequency);
DataType c = std::tan(boost::math::constants::pi<DataType>() * cut_frequency / sampling_frequency);
DataType d = (1 + std::sqrt(2.) * c + c * c);
DataType Q_inv = 1 / Q;
@@ -0,0 +1,140 @@
/**
* \filter time_varying_second_order_filter.h
*/
#ifndef DSP_TIME_VARYING_SECOND_ORDER_FILTER
#define DSP_TIME_VARYING_SECOND_ORDER_FILTER
#include <boost/math/constants/constants.hpp>
#include <boost/scoped_array.hpp>
#include "filter.h"
namespace DSP
{
template<class Data_Type>
class TimeVaryingBandPassCoefficients
{
public:
typedef Data_Type DataType;
private:
DataType sampling_frequency;
DataType cut_frequency_min;
DataType cut_frequency_max;
DataType angle_offset;
DataType Q;
void compute_coeffs()
{
coefficients_in.reset(new DataType[period][3]);
coefficients_out.reset(new DataType[period][2]);
offset = 0;
for(int i = 0; i < period; ++i)
{
DataType c = std::tan(boost::math::constants::pi<DataType>() * (cut_frequency_min + (cut_frequency_max - cut_frequency_min) * (std::cos(angle_offset + i * 2 * boost::math::constants::pi<DataType>() / period) + 1) / 2) / sampling_frequency);
DataType d = (1 + std::sqrt(2.) * c + c * c);
DataType Q_inv = 1 / Q;
coefficients_in[i][2] = Q_inv * c / d;
coefficients_in[i][1] = 0;
coefficients_in[i][0] = -Q_inv * c / d;
coefficients_out[i][1] = - 2 * (c * c - 1) / d;
coefficients_out[i][0] = - (1 - std::sqrt(2.) * c + c * c) / d;
}
}
protected:
boost::scoped_array<DataType[3]> coefficients_in;
boost::scoped_array<DataType[2]> coefficients_out;
int offset;
int period;
public:
void set_sampling_frequency(DataType sampling_frequency)
{
this->sampling_frequency = sampling_frequency;
compute_coeffs();
}
void set_cut_frequency_min(DataType cut_frequency_min)
{
this->cut_frequency_min = cut_frequency_min;
compute_coeffs();
}
void set_cut_frequency_max(DataType cut_frequency_max)
{
this->cut_frequency_max = cut_frequency_max;
compute_coeffs();
}
void set_period(int period)
{
this->period = period;
compute_coeffs();
}
void set_angle_offset(DataType angle_offset)
{
this->angle_offset = angle_offset;
compute_coeffs();
}
void set_Q(DataType Q)
{
this->Q = Q;
compute_coeffs();
}
};
template<class Coefficients>
class TimeVaryingSecondOrderFilter: public Coefficients, public MonoFilter<typename Coefficients::DataType>
{
typedef typename Coefficients::DataType DataType;
DataType buffer_in[2];
DataType buffer_out[2];
using Coefficients::coefficients_in;
using Coefficients::coefficients_out;
using Coefficients::period;
using Coefficients::offset;
public:
TimeVaryingSecondOrderFilter()
:Coefficients()
{
for(int i = 0; i < 2; ++i)
{
buffer_in[i] = 0;
buffer_out[i] = 0;
}
}
DSP_MONOFILTER_DECLARE()
template<class DataTypeIn, class DataTypeOut>
void process(const DataTypeIn* RESTRICT in, DataTypeOut* RESTRICT out, unsigned long size)
{
for(int i = 0; i < size; ++i)
{
out[i] = coefficients_in[offset][2] * in[i] + coefficients_in[offset][1] * buffer_in[1] + coefficients_in[offset][0] * buffer_in[0] + coefficients_out[offset][1] * buffer_out[1] + coefficients_out[offset][0] * buffer_out[0];
buffer_in[0] = buffer_in[1];
buffer_in[1] = in[i];
buffer_out[0] = buffer_out[1];
buffer_out[1] = out[i];
offset++;
if(offset >= period)
{
offset = 0;
}
}
}
};
}
#endif
@@ -0,0 +1 @@
#include "qmfcapp.h"
@@ -0,0 +1 @@
#include "qwinwidget.h"
@@ -0,0 +1,107 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of a Qt Solutions component.
**
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/
// Implementation of the QMfcApp classes
#include "qmfcapp.h"
#include <QtCore/QEventLoop>
#include <QtCore/QAbstractEventDispatcher>
#include <QtGui/QWidget>
#include <qt_windows.h>
HHOOK hhook;
LRESULT CALLBACK QtFilterProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (qApp) {
qApp->sendPostedEvents(0, -1);
}
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
/*!
If there is no global QApplication object (i.e. qApp is null) this
function creates a QApplication instance and returns true;
otherwise it does nothing and returns false.
The application installs an event filter that drives the Qt event
loop while the MFC or Win32 application continues to own the event
loop.
Use this static function if the application event loop code can not be
easily modified, or when developing a plugin or DLL that will be loaded
into an existing Win32 or MFC application. If \a plugin is non-null then
the function loads the respective DLL explicitly to avoid unloading from
memory.
\code
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
QMfcApp::pluginInstance(hInstance);
return TRUE;
}
\endcode
*/
bool pluginInstance(Qt::HANDLE plugin)
{
if (qApp)
return FALSE;
QT_WA({
hhook = SetWindowsHookExW(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
}, {
hhook = SetWindowsHookExA(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
});
int argc = 0;
(void)new QApplication(argc, 0);
if (plugin) {
char filename[256];
if (GetModuleFileNameA((HINSTANCE)plugin, filename, 255))
LoadLibraryA(filename);
}
return TRUE;
}
Oops, something went wrong.

0 comments on commit 06d3858

Please sign in to comment.