Jamoma API  0.6.0.a19
ttlimiter~.cpp
1 /*
2  * ttlimiter~ Object for Pure Data
3  * Written by Tim Place
4  * Copyright © 2008
5  *
6  */
7 
8 #include "m_pd.h"
9 #include "TTDSP.h"
10 
11 
12 // Types & Structs
13 typedef struct _ttlimiter {
14  t_object obj;
15  t_outlet* outlet; // outlet for status and version messages
16  t_float f; // dummy for signal in first inlet
17  TTAudioObject* limiter; // the Jamoma limiter object
18  TTAudioSignal* audioIn;
19  TTAudioSignal* audioOut;
20 } t_ttlimiter;
21 
22 
23 // Prototypes
24 extern "C" {
25  void ttlimiter_tilde_setup();
26 }
27 
28 void* ttlimiter_new(t_symbol *s, long ac, t_atom *at);
29 void ttlimiter_free(t_ttlimiter *x);
30 void ttlimiter_setpreamp(t_ttlimiter *x, double f);
31 t_int* ttlimiter_perform(t_int *w);
32 void ttlimiter_dsp(t_ttlimiter *x, t_signal **sp);
33 
34 
35 // Statics & Globals
36 static t_class *ttlimiter_class;
37 
38 
39 // Class Definition
40 void ttlimiter_tilde_setup(void)
41 {
42  TTDSPInit();
43 
44  ttlimiter_class = class_new(gensym("ttlimiter~"), (t_newmethod)ttlimiter_new, (t_method)ttlimiter_free,
45  sizeof(t_ttlimiter), 0, A_GIMME, 0);
46 
47  CLASS_MAINSIGNALIN(ttlimiter_class, t_ttlimiter, f);
48  class_addmethod(ttlimiter_class, (t_method)ttlimiter_dsp, gensym("dsp"), A_NULL);
49  class_addmethod(ttlimiter_class, (t_method)ttlimiter_setpreamp, gensym("preamp"), A_FLOAT, 0);
50 
51  class_sethelpsymbol(ttlimiter_class, gensym("help-ttlimiter~.pd"));
52 }
53 
54 
55 // Life Cycle
56 
57 void *ttlimiter_new(t_symbol *s, long ac, t_atom *at)
58 {
59  t_ttlimiter* x = (t_ttlimiter*)pd_new(ttlimiter_class);
60  TTUInt16 numChannels = 1; // Just a mono limiter for now...
61 
62  if(x){
63  outlet_new(&x->obj, gensym("signal")); // Create new signal outlet
64  TTObjectInstantiate(TT("limiter"), &x->limiter, numChannels);
65  TTObjectInstantiate(kTTSym_audiosignal, &x->audioIn, numChannels);
66  TTObjectInstantiate(kTTSym_audiosignal, &x->audioOut, numChannels);
67  }
68  return(x);
69 }
70 
71 
72 void ttlimiter_free(t_ttlimiter *x)
73 {
74  TTObjectRelease(&x->limiter);
75  TTObjectRelease(&x->audioIn);
76  TTObjectRelease(&x->audioOut);
77 }
78 
79 
80 // Methods
81 
82 // Method for Posting Status
83 void ttlimiter_setpreamp(t_ttlimiter *x, double f)
84 {
85  x->limiter->setAttributeValue(TT("Preamp"), f);
86 }
87 
88 
89 // Perform (signal) Method
90 t_int *ttlimiter_perform(t_int *w)
91 {
92  t_ttlimiter* x = (t_ttlimiter*)(w[1]);
93  t_float* in = (t_float*)(w[2]);
94  t_float* out = (t_float*)(w[3]);
95  TTUInt16 vs = x->audioIn->getVectorSizeAsInt();
96 
97  x->audioIn->setVector(0, vs, (t_float*)in);
98  x->limiter->process(x->audioIn, x->audioOut);
99  x->audioOut->getVector(0, vs, (t_float*)out);
100 
101  return (w+5);
102 }
103 
104 
105 // DSP Method
106 void ttlimiter_dsp(t_ttlimiter *x, t_signal **sp)
107 {
108  x->audioIn->setNumChannels(1);
109  x->audioOut->setNumChannels(1);
110  x->audioIn->setVectorSizeWithInt(sp[0]->s_n);
111  x->audioOut->setVectorSizeWithInt(sp[0]->s_n);
112  //audioIn will be set in the perform method
113  x->audioOut->alloc();
114 
115  x->limiter->setAttributeValue(kTTSym_sampleRate, sp[0]->s_sr);
116 
117  dsp_add(ttlimiter_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
118 }
119 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
Wrap audio objects for convenience.
Jamoma DSP Library.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
void TTDSP_EXPORT TTDSPInit(const char *pathToBinaries=NULL)
Initialise the Jamoma DSP library, as well as Jamoma Foundation foundation if needed.
Definition: TTDSP.cpp:30