Skip to content

Commit 13a5fd1

Browse files
author
mars
committed
Merge branch 'master' of github.com:pingdynasty/OwlProgram
Conflicts: common.mk
2 parents c6c3294 + e531f99 commit 13a5fd1

37 files changed

Lines changed: 836 additions & 648 deletions

HeavySource/HvMessage.c

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
HvMessage *msg_init(HvMessage *m, hv_size_t numElements, hv_uint32_t timestamp) {
2121
m->timestamp = timestamp;
2222
m->numElements = (hv_uint16_t) numElements;
23-
m->numBytes = (hv_uint16_t) msg_getByteSize(numElements);
23+
m->numBytes = (hv_uint16_t) msg_getCoreSize(numElements);
2424
return m;
2525
}
2626

@@ -43,7 +43,7 @@ HvMessage *msg_initWithBang(HvMessage *m, hv_uint32_t timestamp) {
4343
HvMessage *msg_initWithSymbol(HvMessage *m, hv_uint32_t timestamp, char *s) {
4444
m->timestamp = timestamp;
4545
m->numElements = 1;
46-
m->numBytes = sizeof(HvMessage);
46+
m->numBytes = sizeof(HvMessage) + (hv_uint16_t) hv_strlen(s);
4747
msg_setSymbol(m, 0, s);
4848
return m;
4949
}
@@ -56,51 +56,18 @@ HvMessage *msg_initWithHash(HvMessage *m, hv_uint32_t timestamp, hv_uint32_t h)
5656
return m;
5757
}
5858

59-
HvMessage *msg_initV(HvMessage *const m, const hv_uint32_t timestamp, const char *format, ...) {
60-
va_list ap;
61-
va_start(ap, format);
62-
63-
const int numElem = (int) hv_strlen(format);
64-
msg_init(m, numElem, timestamp);
65-
for (int i = 0; i < numElem; i++) {
66-
switch (format[i]) {
67-
case 'b': msg_setBang(m,i); break;
68-
case 'f': msg_setFloat(m, i, (float) va_arg(ap, double)); break;
69-
case 's': msg_setSymbol(m, i, (char *) va_arg(ap, char *)); break;
70-
case 'h': // hash not supported
71-
default: break;
72-
}
73-
}
74-
va_end(ap);
75-
76-
return m;
77-
}
78-
79-
hv_size_t msg_getNumHeapBytes(const HvMessage *m) {
80-
// get the size of all symbol elements
81-
hv_size_t rsizeofsym = 0;
82-
for (int i = 0; i < msg_getNumElements(m); ++i) {
83-
if (msg_isSymbol(m,i)) {
84-
rsizeofsym += (hv_size_t) hv_strlen(msg_getSymbol(m,i)) + 1; // +1 to allow for trailing '\0'
85-
}
86-
}
87-
88-
// the total byte size on the heap
89-
return (msg_getByteSize(msg_getNumElements(m)) + rsizeofsym);
90-
}
91-
9259
void msg_copyToBuffer(const HvMessage *m, char *buffer, hv_size_t len) {
9360
HvMessage *r = (HvMessage *) buffer;
9461

62+
hv_size_t len_r = msg_getCoreSize(msg_getNumElements(m));
63+
9564
// assert that the message is not already larger than the length of the buffer
96-
hv_assert(msg_getNumBytes(m) <= len);
65+
hv_assert(len_r <= len);
9766

9867
// copy the basic message to the buffer
99-
hv_memcpy(r, m, msg_getNumBytes(m));
68+
hv_memcpy(r, m, len_r);
10069

101-
hv_size_t len_r = msg_getNumBytes(m);
102-
103-
char *p = buffer + msg_getByteSize(msg_getNumElements(m)); // points to the end of the base message
70+
char *p = buffer + len_r; // points to the end of the base message
10471
for (int i = 0; i < msg_getNumElements(m); ++i) {
10572
if (msg_isSymbol(m,i)) {
10673
const hv_size_t symLen = (hv_size_t) hv_strlen(msg_getSymbol(m,i)) + 1; // include the trailing null char
@@ -117,7 +84,7 @@ void msg_copyToBuffer(const HvMessage *m, char *buffer, hv_size_t len) {
11784

11885
// the message is serialised such that all symbol elements are placed in order at the end of the buffer
11986
HvMessage *msg_copy(const HvMessage *m) {
120-
const hv_size_t heapSize = msg_getNumHeapBytes(m);
87+
const hv_uint32_t heapSize = msg_getSize(m);
12188
char *r = (char *) hv_malloc(heapSize);
12289
hv_assert(r != NULL);
12390
msg_copyToBuffer(m, r, heapSize);
@@ -184,6 +151,7 @@ hv_uint32_t msg_symbolToHash(const char *s) {
184151
static const hv_int32_t r = 24;
185152

186153
if (s == NULL) return 0;
154+
187155
hv_uint32_t len = (hv_uint32_t) hv_strlen(s);
188156
hv_uint32_t x = len; // seed (0) ^ len
189157

HeavySource/HvUtils.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ static inline hv_size_t __hv_utils_max_ui(hv_size_t x, hv_size_t y) { return (x
207207
static inline hv_size_t __hv_utils_min_ui(hv_size_t x, hv_size_t y) { return (x < y) ? x : y; }
208208
static inline hv_int32_t __hv_utils_max_i(hv_int32_t x, hv_int32_t y) { return (x > y) ? x : y; }
209209
static inline hv_int32_t __hv_utils_min_i(hv_int32_t x, hv_int32_t y) { return (x < y) ? x : y; }
210+
210211
#define hv_max_ui(a, b) __hv_utils_max_ui(a, b)
211212
#define hv_min_ui(a, b) __hv_utils_min_ui(a, b)
212213
#define hv_max_i(a, b) __hv_utils_max_i(a, b)
@@ -238,7 +239,12 @@ static inline hv_int32_t __hv_utils_min_i(hv_int32_t x, hv_int32_t y) { return (
238239
#define hv_exp_f(a) expf(a)
239240
#define hv_abs_f(a) fabsf(a)
240241
#define hv_log_f(a) logf(a)
241-
#define hv_log2_f(a) log2f(a)
242+
#if HV_ANDROID
243+
// NOTE(mhroth): for whatever silly reason, log2f is not defined!
244+
#define hv_log2_f(a) (1.44269504088896f*logf(a))
245+
#else
246+
#define hv_log2_f(a) log2f(a)
247+
#endif // HV_ANDROID
242248
#define hv_log10_f(a) log10f(a)
243249
#define hv_ceil_f(a) ceilf(a)
244250
#define hv_floor_f(a) floorf(a)
@@ -260,4 +266,31 @@ static inline hv_int32_t __hv_utils_min_i(hv_int32_t x, hv_int32_t y) { return (
260266
#endif
261267
#define hv_min_max_log2(a) __hv_utils_min_max_log2(a)
262268

269+
// Atomics
270+
#if HV_WIN
271+
#include <Windows.h>
272+
#define hv_atomic_bool volatile LONG
273+
#define HV_SPINLOCK_ACQUIRE(_x) \
274+
while (InterlockedCompareExchange(&_x, true, false)) { }
275+
#define HV_SPINLOCK_RELEASE(_x) (_x = false)
276+
#elif defined(__has_include)
277+
#if __has_include(<stdatomic.h>)
278+
#include <stdatomic.h>
279+
#define hv_atomic_bool volatile atomic_bool
280+
#define HV_SPINLOCK_ACQUIRE(_x) \
281+
bool expected = false; \
282+
while (!atomic_compare_exchange_strong(&_x, &expected, true)) { expected = false; }
283+
#define HV_SPINLOCK_RELEASE(_x) atomic_store(&_x, false)
284+
#else
285+
#define hv_atomic_bool volatile bool
286+
#define HV_SPINLOCK_ACQUIRE(_x) _x = true;
287+
#define HV_SPINLOCK_RELEASE(_x) _x = false;
288+
#endif
289+
#else
290+
#define hv_atomic_bool volatile bool
291+
#define HV_SPINLOCK_ACQUIRE(_x) _x = true;
292+
#define HV_SPINLOCK_RELEASE(_x) _x = false;
293+
#endif
294+
295+
263296
#endif // _HEAVY_UTILS_H_

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();

0 commit comments

Comments
 (0)