18 #include "TTFoundationAPI.h"
21 #ifdef TT_PLATFORM_WIN
22 template <
typename T> T asinh(T value)
26 returned = log(value + sqrt(value * value + 1));
28 returned = -log(-value + sqrt(value * value + 1));
37 #define thisTTClass BarkUnit
38 #define thisTTClassName "unit.bark"
39 #define thisTTClassTags "dataspace.unit, time, pitch, frequency"
45 BarkUnit::~BarkUnit(){;}
49 output = 1.0 / (600 * sinh(
TTFloat64(input) / 6));
55 output = (6 * asinh(1.0 / (
TTFloat64(input) * 600.0)));
60 #undef thisTTClassName
61 #undef thisTTClassTags
70 #define thisTTClass BpmUnit
71 #define thisTTClassName "unit.bpm"
72 #define thisTTClassTags "dataspace.unit, time"
79 BpmUnit::~BpmUnit(){;}
95 #undef thisTTClassName
96 #undef thisTTClassTags
103 #define thisTTClass CentUnit
104 #define thisTTClassName "unit.cent"
105 #define thisTTClassTags "dataspace.unit, time"
111 CentUnit::~CentUnit(){;}
115 output = 1. / (440.0 * pow(2.0, (
TTFloat64(input)-6900.0) / 1200.0 ));
121 output = 6900.0 + 1200.0 * log(1./(440.0*
TTFloat64(input)))/log(2.0);
126 #undef thisTTClassName
127 #undef thisTTClassTags
134 #define thisTTClass FrequencyUnit
135 #define thisTTClassName "unit.rate"
136 #define thisTTClassTags "dataspace.unit, time"
143 FrequencyUnit::~FrequencyUnit(){;}
159 #undef thisTTClassName
160 #undef thisTTClassTags
167 #define thisTTClass MelUnit
168 #define thisTTClassName "unit.mel"
169 #define thisTTClassTags "dataspace.unit, time"
175 MelUnit::~MelUnit(){;}
179 output = 1.0 / (700.0 *(pow(10,(
TTFloat64(input)/2595.0))-1.0));
185 output = 2595.0 * log10(1+1.0/(
TTFloat64(input)*700.0));
190 #undef thisTTClassName
191 #undef thisTTClassTags
198 #define thisTTClass MidiPitchUnit
199 #define thisTTClassName "unit.midi"
200 #define thisTTClassTags "dataspace.unit, time"
206 MidiPitchUnit::~MidiPitchUnit(){;}
210 output = 1. / (440.0 * pow(2.0, (
TTFloat64(input)-69.0) / 12.0 ));
219 output = 69.0 - 12.0 * log(440.0*
TTFloat64(input))/log(2.0);
223 #undef thisTTClassName
224 #undef thisTTClassTags
231 #define thisTTClass MillisecondUnit
232 #define thisTTClassName "unit.ms"
233 #define thisTTClassTags "dataspace.unit, time"
240 MillisecondUnit::~MillisecondUnit(){;}
255 #undef thisTTClassName
256 #undef thisTTClassTags
263 #define thisTTClass SampleUnit
264 #define thisTTClassName "unit.sample"
265 #define thisTTClassTags "dataspace.unit, time"
273 SampleUnit::~SampleUnit()
281 double sampleRate = globalSampleRate;
291 double sampleRate = globalSampleRate;
298 #undef thisTTClassName
299 #undef thisTTClassTags
306 #define thisTTClass SecondUnit
307 #define thisTTClassName "unit.second"
308 #define thisTTClassTags "dataspace.unit, time"
315 SecondUnit::~SecondUnit(){;}
329 #undef thisTTClassName
330 #undef thisTTClassTags
337 #define thisTTClass SpeedUnit
338 #define thisTTClassName "unit.speed"
339 #define thisTTClassTags "dataspace.unit, time"
345 SpeedUnit::~SpeedUnit(){;}
361 output = pow(2.0, 69./12.) / (440.0*
TTFloat64(input));
379 output = pow(2.0, 69./12.) / (440.0*
TTFloat64(input));
384 #undef thisTTClassName
385 #undef thisTTClassTags
392 #define thisTTClass TimeDataspace
393 #define thisTTClassName "dataspace.time"
394 #define thisTTClassTags "foundationDataspaceLib, dataspace, time"
401 registerUnit(
TT(
"unit.bark"),
TT(
"bark"));
402 registerUnit(
TT(
"unit.bpm"),
TT(
"bpm"));
403 registerUnit(
TT(
"unit.cent"),
TT(
"cents"));
404 registerUnit(
TT(
"unit.mel"),
TT(
"mel"));
405 registerUnit(
TT(
"unit.midi"),
TT(
"midinote"));
406 registerUnit(
TT(
"unit.ms"),
TT(
"ms"));
407 registerUnit(
TT(
"unit.ms"),
TT(
"millisecond"));
408 registerUnit(
TT(
"unit.rate"),
TT(
"fps"));
409 registerUnit(
TT(
"unit.rate"),
TT(
"Hz"));
410 registerUnit(
TT(
"unit.rate"),
TT(
"hz"));
411 registerUnit(
TT(
"unit.rate"),
TT(
"Hertz"));
412 registerUnit(
TT(
"unit.sample"),
TT(
"sample"));
413 registerUnit(
TT(
"unit.second"),
TT(
"s"));
414 registerUnit(
TT(
"unit.second"),
TT(
"second"));
415 registerUnit(
TT(
"unit.speed"),
TT(
"speed"));
419 neutralUnit =
TT(
"second");
423 setInputUnit(neutralUnit);
424 setOutputUnit(neutralUnit);
428 TimeDataspace::~TimeDataspace()
435 #undef thisTTClassName
436 #undef thisTTClassTags
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from radians to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to seconds.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from milliseconds to neutral unit.
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from MIDI pitch to neutral unit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Hz to neutral unit.
The TimeDataspace converts between different measurement untis describing time intervals and frequenc...
TTErr getAttributeValue(const TTSymbol name, TTValue &value)
Get an attribute value for an object.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to MIDI pitch.
double TTFloat64
64 bit floating point number
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from samples to neutral unit.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Bpm to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to number of samples.
Specification for the base class of each DataspaceUnit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Mel to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Hz.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Mel.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to milliseconds.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to cents.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from speed to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to speed.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from seconds to neutral unit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Bark.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Bpm.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Bark to neutral unit.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]