Skip to content

Commit 45bb284

Browse files
author
mars
committed
Merge branch 'events'
2 parents 6eb4d76 + dc60a2f commit 45bb284

34 files changed

Lines changed: 778 additions & 601 deletions

LibSource/ComplexFloatArray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void ComplexFloatArray::complexByComplexMultiplication(ComplexFloatArray& operan
7070
ASSERT(size==operand2.getSize(), "Wrong size");
7171
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
7272
#ifdef ARM_CORTEX
73-
arm_cmplx_mult_cmplx_f32 ( (float*)data, (float*)operand2, (float*)result, size );
73+
arm_cmplx_mult_cmplx_f32( (float*)data, (float*)operand2, (float*)result, size );
7474
#else
7575
float *pSrcA=(float*)data;
7676
float *pSrcB=(float*)operand2;

LibSource/ComplexFloatArray.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class ComplexFloatArray {
107107
return data[i].im;
108108
}
109109

110+
void clear(){
111+
setAll(0);
112+
}
113+
110114
/**
111115
The magnitude of an element of the array.
112116
@param i The index of the element

LibSource/FloatArray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void FloatArray::setAll(float value){
299299
}
300300

301301
void FloatArray::add(FloatArray operand2, FloatArray destination){ //allows in-place
302-
ASSERT(operand2.size == size && destination.size==size, "Arrays must be same size");
302+
ASSERT(operand2.size >= size && destination.size<=size, "Arrays must be matching size");
303303
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
304304
#ifdef ARM_CORTEX
305305
/* despite not explicitely documented in the CMSIS documentation,

LibSource/FloatArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class FloatArray {
264264
/**
265265
* Array-scalar multiplication.
266266
* Multiplies the values in the array by **scalar**.
267-
* @param scalar to be subtracted from the array
267+
* @param scalar to be multiplied with the array elements
268268
*/
269269
void multiply(float scalar);
270270

LibSource/PatchParameter.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "PatchParameter.h"
2+
#include "PatchProcessor.h"
3+
#include "SmoothValue.h"
4+
#include "message.h"
5+
6+
PatchProcessor* getInitialisingPatchProcessor();
7+
8+
#define PATCH_PARAMETER_NO_PID -1
9+
10+
template<typename T>
11+
PatchParameter<T>::PatchParameter() : pid(PATCH_PARAMETER_NO_PID){}
12+
13+
// copy ctors: superceded by assignment operators
14+
/* PatchParameter(PatchParameter<T>& other); */
15+
/* PatchParameter(const PatchParameter<T>& other); */
16+
17+
// template<typename T>
18+
// PatchParameter<T>::PatchParameter(PatchParameter<T>& other) :
19+
// pid(other.pid), value(other.value) {
20+
// // copy ctor
21+
// // register for update callback in copy constructor
22+
// if(pid != PATCH_PARAMETER_NO_PID)
23+
// getInitialisingPatchProcessor()->setPatchParameter(pid, this);
24+
// }
25+
26+
// template<typename T>
27+
// PatchParameter<T>::PatchParameter(const PatchParameter<T>& other) :
28+
// pid(other.pid), value(other.value) {
29+
// // copy ctor
30+
// // register for update callback in copy constructor
31+
// if(pid != PATCH_PARAMETER_NO_PID)
32+
// getInitialisingPatchProcessor()->setPatchParameter(pid, this);
33+
// }
34+
35+
template<typename T>
36+
PatchParameter<T>& PatchParameter<T>::operator=(const PatchParameter<T>& other){
37+
pid = other.pid;
38+
value = other.value;
39+
if(pid != PATCH_PARAMETER_NO_PID)
40+
getInitialisingPatchProcessor()->setPatchParameter(pid, this);
41+
return *this;
42+
}
43+
44+
template class PatchParameter<int>;
45+
template class PatchParameter<float>;

LibSource/PatchParameter.h

Lines changed: 14 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,28 @@
11
#ifndef __PatchParameter_h__
22
#define __PatchParameter_h__
33

4-
5-
#include "SmoothValue.h"
6-
4+
template<typename T>
75
class PatchParameter {
8-
public:
9-
virtual void update(uint16_t value){}
10-
};
11-
12-
template<type T, type V>
13-
class GenericParameter : public PatchParameter {
146
private:
15-
PatchParameterId pid;
16-
T min, max;
17-
V value;
7+
int pid;
8+
T value;
189
public:
19-
PatchParameter(){}
20-
PatchParameter(PatchParameterId pid, T min, T max, V initialValue);
21-
// called when requestParameter() returns to patch constructor
22-
PatchParameter(const PatchParameter<T>& other);
23-
void update(uint16_t value);
24-
/*
10+
PatchParameter();
11+
PatchParameter(int parameterId) : pid(parameterId){}
12+
/* assignment operator */
13+
PatchParameter<T>& operator=( const PatchParameter<T>& other );
2514
void update(T newValue){
2615
value = newValue;
27-
} */
28-
operator V(){
16+
}
17+
T getValue(){
2918
return value;
3019
}
31-
};
32-
33-
template<type T, type V>
34-
GenericParameter<T, V> Patch::requestParameter(const char* name, T min, T max, V defaultValue = V()){
35-
int pid = 0;
36-
if(nextPid < 5){
37-
pid = nextPid++;
38-
registerParameter(pid, name);
20+
operator T(){
21+
return getValue();
3922
}
40-
return GenericParameter<T, V>(PatchParameterId(pid), min, max, defaultValue);
41-
}
42-
43-
template<type T>
44-
GenericParameter<T, SmoothValue<T>> Patch::requestParameter(const char* name, T min, T max, T defaultValue, T lambda){
45-
requestParameter(name, min, max, SmoothValue<T>(defaultValue, lambda));
46-
}
47-
48-
// Patch {
49-
// FloatParameter requestParameter(const char* name, float min, float max, float defaultValue);
50-
// SmoothFloatParameter requestParameter(const char* name, float min, float max, float defaultValue, float lambda); // lambda between 0.5 and 0.99 - compensate for rate/blocksize
51-
// IntParameter requestParameter(const char* name, int min, int max, int defaultValue);
52-
// StiffIntParameter requestParameter(const char* name, int min, int max, int defaultValue, float delta); // delta between 0 and 1 for 0 to 4095
53-
// };
54-
55-
// exponentially averaged float parameter with hysteresis:
56-
// won't work!
57-
// StiffSmoothFloatParameter spread; spread = requestParameter("spread", 0.0, 1.0, 0.5, 0.9); // how to set stiff delta?
58-
// should be GenericParameter<float, SmoothValue<StiffFloat>> but whole of stiff gets assigned to value of smooth
59-
// typedef StiffSmoothFloatParameter GenericParameter<float, SmoothValue<StiffFloat>>
60-
61-
// default in patch processor to StiffSmoothIntParameter
62-
63-
typedef IntParameter GenericParameter<int, int>;
64-
typedef StiffIntParameter GenericParameter<int, StiffInt>;
65-
typedef SmoothIntParameter GenericParameter<int, SmoothInt>;
66-
typedef FloatParameter GenericParameter<float, float;
67-
typedef StiffFloatParameter GenericParameter<float, StiffFloat>;
68-
typedef SmoothFloatParameter GenericParameter<float, SmoothFloat>;
69-
//FloatParameter spread = requestParameter("Spread", 0.0, 1.0, 0.5);
70-
//SmoothFloatParameter spread = requestParameter("Spread", 0.0, 1.0, SmoothFloat(0.9, 0.5));
71-
//SmoothFloatParameter spread = requestParameter("Spread", 0.0, 1.0, 0.5, 0.9);
72-
73-
template<type T, type V>
74-
GenericParameter<T,V>::GenericParameter<T,V>(PatchParameterId p, T mn, T mx, T v)
75-
: pid(p), min(mn), max(mx), value(v) {}
76-
77-
template<type T, type V>
78-
GenericParameter(const GenericParameter<T,V>& other){
79-
// register for update callback in copy constructor
80-
if(pid != NO_PID)
81-
getCurrentPatchProcessor()->setPatchParameter(pid, this);
82-
}
83-
84-
template<V>
85-
void GenericParameter<int,V>::update(uint16_t newValue){
86-
value = (newValue*(max-min)+min)/4095;
87-
}
23+
};
8824

89-
template<V>
90-
void GenericParameter<float,V>::update(uint16_t value){
91-
value = newValue/4096.0f;
92-
// should work for <float, float>, <float, SmoothFloat>, and <float, StiffFloat>
93-
}
25+
typedef PatchParameter<float> FloatParameter;
26+
typedef PatchParameter<int> IntParameter;
9427

9528
#endif /* __PatchParameter_h__ */

LibSource/PolyBlepOscillator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
PolyBlepOscillator::PolyBlepOscillator(float sr):
55
multiplier(1.0/sr),
6-
frequency(440.0),
6+
frequency(440.0*multiplier),
77
shape(0.5),
88
pw(0.5) {
99
osc.Init();

LibSource/SmoothValue.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "SmoothValue.h"
2+
#include "basicmaths.h"
3+
4+
template<>
5+
SmoothFloat::SmoothValue()
6+
: lambda(0.9), value(0.0){}
7+
8+
template<>
9+
SmoothFloat::SmoothValue(float l)
10+
: lambda(l), value(0.0){}
11+
12+
template<>
13+
SmoothFloat::SmoothValue(float l, float initialValue)
14+
: lambda(l), value(initialValue){}
15+
16+
template<>
17+
SmoothInt::SmoothValue(int divider) : lambda(divider) {
18+
// lambda = 1 - 1/divider
19+
// divider 4:0.75, 5:0.8, 6:0.833, 7:0.857, 8:0.875, 9:0.888, 10:0.9 et c
20+
}
21+
22+
template<>
23+
SmoothInt::SmoothValue(int divider, int initialValue)
24+
: lambda(divider), value(initialValue) {}
25+
26+
template<>
27+
void SmoothFloat::update(float newValue){
28+
value = value*lambda + newValue*(1.0f - lambda);
29+
}
30+
31+
template<>
32+
void SmoothInt::update(int newValue){
33+
value = (value*lambda + newValue)/(lambda+1);
34+
}
35+
36+
template<>
37+
void SmoothStiffFloat::update(float newValue){
38+
if(abs(value-newValue) >= delta)
39+
value = value*lambda + newValue*(1.0f - lambda);
40+
}
41+
42+
template<>
43+
void SmoothStiffInt::update(int newValue){
44+
if(abs(value-newValue) >= delta)
45+
value = (value*lambda + newValue)/(lambda+1);
46+
}
47+
48+
template<>
49+
float SmoothValue<float>::normal(float lambda, int blocksize){
50+
return lambda*128.0f/blocksize;
51+
}
52+
53+
template<>
54+
int SmoothValue<int>::normal(float lambda, int blocksize){
55+
return (1.0f/(1.0-lambda))*128.0f/blocksize;
56+
}
57+
58+
template<>
59+
float StiffValue<float>::normal(float delta){
60+
return delta;
61+
}
62+
63+
template<>
64+
int StiffValue<int>::normal(float delta){
65+
return delta;
66+
}
67+
68+
template class SmoothValue<int>;
69+
template class SmoothValue<float>;
70+
template class SmoothStiffValue<int>;
71+
template class SmoothStiffValue<float>;

0 commit comments

Comments
 (0)