Skip to content

Commit 6890c13

Browse files
author
mars
committed
volts/octave updates
1 parent dc182e1 commit 6890c13

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

LibSource/VoltsPerOctave.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
#include "ServiceCall.h"
55
#include <stdint.h>
66

7-
VoltsPerOctave::VoltsPerOctave() : tune(0.0) {
7+
VoltsPerOctave::VoltsPerOctave(bool input) : tune(0.0) {
88
int32_t volts_offset = 0, volts_scalar = 0;
99
void* args[] = {
10-
(void*)"VO", (void*)&volts_offset,
11-
(void*)"VS", (void*)&volts_scalar
10+
(void*)(input ? "IO" : "OO"), (void*)&volts_offset,
11+
(void*)(input ? "IS" : "OS"), (void*)&volts_scalar
1212
};
1313
int ret = getProgramVector()->serviceCall(OWL_SERVICE_GET_PARAMETERS, args, 4);
1414
if(ret == OWL_SERVICE_OK){
15-
multiplier = (float)volts_scalar/INT32_MAX;
16-
offset = (float)volts_offset/INT32_MAX;
15+
multiplier = (float)volts_scalar/UINT16_MAX;
16+
offset = (float)volts_offset/UINT16_MAX;
1717
}else{
1818
if(getProgramVector()->hardware_version == OWL_MODULAR_HARDWARE){
19-
multiplier = -4.40f;
20-
offset = -0.0585f;
19+
if(input){
20+
multiplier = -4.29;
21+
offset = -0.06382;
22+
}else{
23+
multiplier = -4.642;
24+
offset = 0.1208;
25+
}
2126
}else{
2227
multiplier = 2.0f;
2328
offset = 0.0f;
@@ -32,7 +37,7 @@ VoltsPerOctave::VoltsPerOctave(float o, float m)
3237
void VoltsPerOctave::getFrequency(FloatArray samples, FloatArray output){
3338
ASSERT(output.getSize() >= samples.getSize(), "Output buffer too short");
3439
// todo: block based implementation
35-
// samples.add(-offset, output);
40+
// samples.subtract(offset, output);
3641
// samples.multiply(multiplier, output);
3742
// for(int i=0; i<samples.getSize(); ++i)
3843
// output[i] = voltsToHertz(output[i]);

LibSource/VoltsPerOctave.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class VoltsPerOctave {
1414
float multiplier;
1515
float tune;
1616
public:
17-
VoltsPerOctave();
17+
VoltsPerOctave(bool input = true);
1818
VoltsPerOctave(float offset, float multiplier);
1919
// Tune the frequency converter to octaves up or down.
2020
// For semitones divide by 12. For cents divide by 1200.
@@ -30,6 +30,12 @@ class VoltsPerOctave {
3030
float voltsToHerz(float volts){
3131
return 440.f * powf(2, volts);
3232
}
33+
float voltsToSample(float volts){
34+
return volts / multiplier + offset;
35+
}
36+
float herzToVolts(float hertz){
37+
return log2f(hertz/440.0f);
38+
}
3339
void getFrequency(FloatArray samples, FloatArray output);
3440
};
3541

0 commit comments

Comments
 (0)