Permalink
Browse files

Import from bzr

  • Loading branch information...
mbrucher committed Dec 14, 2010
0 parents commit 12dd101020b39b55240c437ac1ab5919090392bc
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blocks", "blocks\blocks.vcproj", "{FD22775A-C0EF-4AF3-9D01-C92ABD0427FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD22775A-C0EF-4AF3-9D01-C92ABD0427FF}.Debug|Win32.ActiveCfg = Debug|Win32
{FD22775A-C0EF-4AF3-9D01-C92ABD0427FF}.Debug|Win32.Build.0 = Debug|Win32
{FD22775A-C0EF-4AF3-9D01-C92ABD0427FF}.Release|Win32.ActiveCfg = Release|Win32
{FD22775A-C0EF-4AF3-9D01-C92ABD0427FF}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,7 @@
Import('env')
env.SConscript([
"blocks\SConstruct",
"plugins\SConstruct",
])
@@ -0,0 +1,61 @@
import os
import os.path
import sys
opts = Variables('custom.py')
opts.Add(BoolVariable('debug', 'Set to build for debug', True))
opts.Add(BoolVariable('optimized', 'Set to build for optimization', False))
opts.Add(BoolVariable('profile', 'Set to build for profiling', False))
opts.Add(PathVariable('prefix', 'Sets the path where the programs and libs will be installed', os.getcwd()))
opts.Add('cflags', 'Set the C++ flags', '')
opts.Add('ldflags', 'Set the linker flags', '')
opts.Add('qwinmigrate', 'Set the QWinMigrate path', '.')
opts.Add('tools', 'Set the tool set to use', '')
opts.Add('topdir', 'Set the location of the tool set', '')
opts.Add('vst', 'Set the VST path', '.')
opts.Add('optlevel', 'Optimization level (1, 2 or 3', '1')
env = Environment(options = opts,
BINDIR = "%s/bin" % '$prefix',
INCDIR = "%s/include" % '$prefix',
LIBDIR = "%s/lib" % '$prefix',
tools = ["default", "qt4"],
toolpath = '.',
ENV=os.environ
)
opts.Save('custom.py', env)
env['boost_suffix'] = ''
Export('env')
if env['tools'] != '':
env = SConscript('%s-%s.scons' % (env['tools'], sys.platform))
elif sys.platform == "win32":
env = SConscript('msvc-win32.scons')
elif sys.platform == "linux2":
env = SConscript('gcc-linux2.scons')
env.Tool("nsis", toolpath=["."])
Help(opts.GenerateHelpText(env))
if env['cflags']:
env.Append(CCFLAGS=env['cflags'])
if env['ldflags']:
env.Append(LINKFLAGS=env['ldflags'])
env.Append(CPPPATH=os.getcwd())
env.Append(CPPPATH=env['vst'])
env.Append(CPPPATH=env['qwinmigrate'] + os.sep + 'src')
env.Append(LIBPATH=env['qwinmigrate'] + os.sep + 'lib')
if env['debug']:
env.EnableQt4Modules(['QtCore', 'QtGui', ], debug=True)
env['QWinMigratelib'] = 'QtSolutions_MFCMigrationFramework-2.8d'
else:
env.EnableQt4Modules(['QtCore', 'QtGui', ], debug=False)
env['QWinMigratelib'] = 'QtSolutions_MFCMigrationFramework-2.8'
Export('env')
env.SConscript(['SConscript', ], variant_dir='build')
@@ -0,0 +1,5 @@
Import('env')
libmain = env.Program('blocks', Glob("*.cpp"))
libmain = env.Install('$BINDIR', libmain)
@@ -0,0 +1,24 @@
/**
* \file main.cpp
*/
#include "variable_filter.h"
const unsigned long size = 10000000;
float in[size];
float out[size];
int main(int argc, char** argv)
{
VariableFilter<float> filter;
filter.set_cutoff_frequency(48000);
filter.set_attenuation(1);
filter.set_cutoff_frequency(12000);
in[0] = 1;
filter.process(in, out, size);
return 0;
}
@@ -0,0 +1,81 @@
#!/usr/bin/env python
import numpy as np
class Function(object):
def __init__(self, dt, R, C):
self.A = dt / (2 * C) + R
self.B = dt / (2 * C) - R
def f(self, x):
return np.sign(x) * 1e-12 * (np.exp(np.abs(x) / 26e-3) - 1)
def fprime(self, x):
return 1e-12 * np.exp(np.abs(x) / 26e-3) / 26e-3
def __call__(self, x0, x1, y0, y1):
return self.f(y1) + 1/self.A * (y1 + (x0 - x1 + self.B * self.f(y0) - y0))
def gradient(self, x0, x1, y0, y1):
return self.fprime(y1) + 1/self.A
def optimize(fun, x0, x1, y0):
y1 = y0
yk = y1 - fun(x0, x1, y0, y1) / fun.gradient(x0, x1, y0, y1)
while(abs(y1 - yk) > 0.00001):
y1 = yk
yk = y1 - fun(x0, x1, y0, y1) / fun.gradient(x0, x1, y0, y1)
return y1
def plot_fft(x, fs):
n = len(x)
x = x[-fs:] / (fs / 2)
x_fft = fft.fft(x)[:fs/10]
plt.subplot(211)
plt.semilogy(np.abs(x_fft))
plt.subplot(212)
angle = np.angle(x_fft)
angle[np.abs(x_fft) < 0.001] = 0
plt.plot(angle)
if __name__ == "__main__":
import matplotlib.pyplot as plt
import numpy as np
import scipy.fftpack as fft
import scipy.io.wavfile as wav
fs = 44100
fsin = 200
n_samples = fs + fs/fsin
fun = Function(1./fs, 10000, 22e-9)
x = 20 * np.sin(2 * np.pi * np.arange(n_samples)*fsin/fs)
y = np.zeros(n_samples)
x1 = x[0]
y1 = y[0]
for i in range(1, n_samples):
print i
x0 = x1
x1 = x[i]
y0 = y1
y1 = optimize(fun, x0, x1, y0)
y[i] = y1
plt.plot(x)
plt.plot(y)
plt.figure()
plot_fft(x, fs)
plt.figure()
plot_fft(y, fs)
wav.write("sin.wav", fs, (x / 20 * 2**15).astype(np.int16))
wav.write("sin_overdrive.wav", fs, (y * 2**15).astype(np.int16))
plt.show()
@@ -0,0 +1,113 @@
/**
* \file variable_filter.hpp
*/
#ifndef VARIABLEFILTER
#define VARIABLEFILTER
#include <iostream>
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265
#endif
template<class Data_Type>
class VariableFilter
{
public:
typedef Data_Type DataType;
VariableFilter()
:yh(0), yb(0), yl(0), selected(0), cutoff_frequency(0), attenuation(0)
{
}
void process(const DataType* in, DataType* out, unsigned long nb_samples)
{
for(unsigned long i = 0; i < nb_samples; ++i)
{
yh = in[i] - yl - numerical_attenuation * yb;
yb = numerical_frequency * yh + yb;
yl = numerical_frequency * yb + yl;
if(selected == 0)
{
out[i] = yl;
}
else if(selected == 1)
{
out[i] = yb;
}
else
{
out[i] = yh;
}
}
}
void set_sampling_frequency(DataType sampling_frequency)
{
this->sampling_frequency = sampling_frequency;
compute_factors();
}
DataType get_sampling_frequency() const
{
return sampling_frequency;
}
void set_cutoff_frequency(DataType cutoff_frequency)
{
this->cutoff_frequency = cutoff_frequency;
compute_factors();
}
DataType get_cutoff_frequency() const
{
return cutoff_frequency;
}
void set_attenuation(DataType attenuation)
{
this->attenuation = attenuation;
compute_factors();
}
DataType get_attenuation() const
{
return attenuation;
}
void select(int selected)
{
this->selected = selected;
}
int get_selected() const
{
return selected;
}
protected:
void compute_factors()
{
numerical_frequency = 2 * std::sin(M_PI * cutoff_frequency / sampling_frequency);
numerical_attenuation = 2 * attenuation;
}
private:
DataType cutoff_frequency;
DataType attenuation;
DataType sampling_frequency;
DataType numerical_frequency;
DataType numerical_attenuation;
DataType yh;
DataType yb;
DataType yl;
int selected;
};
#endif
@@ -0,0 +1,24 @@
# Matthieu Brucher
# Last Change : 2008-12-16 21:59
import os.path
import glob
Import('env')
env['boost_suffix'] = ''
for libpath in os.environ['PATH'].split(';'):
if env['debug']:
l = list(glob.glob(libpath + '\\boost_thread-%s*-mt-gd*.dll' % env['boost']))
else:
l = list(glob.glob(libpath + '\\boost_thread-%s*-mt*.dll' % env['boost']))
if len(l) > 0:
env['boost_suffix'] = l[0][len(libpath) + 13:-4]
env.Append(LIBPATH=[libpath])
break
if os.path.exists(libpath + '/boost_thread.dll') and env['boost_suffix'] != '':
env.Append(LIBPATH=[libpath])
break
Return('env')
Oops, something went wrong.

0 comments on commit 12dd101

Please sign in to comment.