Jamoma API  0.6.0.a19
TTZerocross.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspAnalysisLib
4  *
5  * @brief Jamoma DSP zero-crossing detector and counter.
6  *
7  * @details
8  *
9  * @authors Tim Place, Trond Lossius
10  *
11  * @copyright Copyright © 2008, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTZerocross.h"
18 
19 #define thisTTClass TTZerocross
20 #define thisTTClassName "zerocross"
21 #define thisTTClassTags "dspAnalysisLib, audio, analysis, frequency"
22 
23 
24 TT_AUDIO_CONSTRUCTOR
25 {
26  TTChannelCount initialMaxNumChannels = arguments;
27 
28  // Attributes
30 
31  // Messages
32  addMessage(Clear);
33  addUpdates(MaxNumChannels);
34 
35  // Set Defaults
36  setAttributeValue(TT("MaxNumChannels"), initialMaxNumChannels);
37  setAttributeValue(TT("Size"), 2000);
38  setProcessMethod(processAudio);
39  Clear();
40 }
41 
42 
43 TTZerocross::~TTZerocross()
44 {
45  ;
46 }
47 
48 
50 {
51  return Clear();
52 }
53 
54 
56 {
57  lastSampleWasOverZero = false;
58  counter = 0;
59  finalCount = 0;
60  analysisLocation = 0;
61  return kTTErrNone;
62 }
63 
64 
66 {
67  mSize = value;
68  rSize = 1.0 / mSize;
69  return kTTErrNone;
70 }
71 
72 
73 // TODO: this unit requires 1 input and 2 outputs -- it does not yet configure itself for other arrangements!
75 {
76  TTAudioSignal& in = inputs->getSignal(0);
77  TTAudioSignal& out = outputs->getSignal(0);
78  TTUInt16 vs = in.getVectorSizeAsInt();
79  TTSampleValue* inSample;
80  TTSampleValue* out1Sample;
81  TTSampleValue* out2Sample;
82  TTBoolean thisSampleIsOverZero;
83  TTBoolean zeroxOccured;
84 
85  inSample = in.mSampleVectors[0];
86  out1Sample = out.mSampleVectors[0];
87  out2Sample = out.mSampleVectors[1];
88 
89  while (vs--) {
90  thisSampleIsOverZero = (0 < (*inSample++));
91  zeroxOccured = lastSampleWasOverZero != thisSampleIsOverZero;
92  lastSampleWasOverZero = thisSampleIsOverZero;
93 
94  counter += zeroxOccured;
96 
97  if (analysisLocation >= mSize) {
98  //finalCount = ((sr * counter) * rSize) * srInv;
99  finalCount = counter * rSize; //that's the same that the line above
100  analysisLocation = 0;
101  counter = 0;
102  }
103 
104  *out1Sample++ = finalCount;
105  *out2Sample++ = zeroxOccured;
106  }
107 
108  return kTTErrNone;
109 }
110 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTUInt32 counter
counts zero-crossings
Definition: TTZerocross.h:35
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Audio processing method.
Definition: TTZerocross.cpp:74
TTErr setSize(const TTValue &value)
Set the size attribute.
Definition: TTZerocross.cpp:65
TTUInt32 analysisLocation
keep track of how many samples so far
Definition: TTZerocross.h:37
TTBoolean lastSampleWasOverZero
was the last sample over zero?
Definition: TTZerocross.h:34
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
This method gets called when the inherited maxNumChannels attribute is changed.
Definition: TTZerocross.cpp:49
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTErr Clear()
Reset the history used in the analysis.
Definition: TTZerocross.cpp:55
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
Jamoma DSP zero-crossing detector and counter.
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTFloat64 rSize
reciprocal of the size attribute
Definition: TTZerocross.h:33
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
A simple container for an array of TTAudioSignal pointers.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
TTUInt32 mSize
Attribute: size of the analysis buffer.
Definition: TTZerocross.h:32
32-bit unsigned integer, range is 0 through 4,294,967,295.
Definition: TTBase.h:278
No Error.
Definition: TTBase.h:343
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44