aboutsummaryrefslogtreecommitdiff
path: root/buffer_override/bufferoverrideFormalities.cpp
blob: 428a7b5de54c6d0bb932331631af3ab94a49f6e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*------------------- by Marc Poirier  ][  March 2001 -------------------*/

#ifndef __bufferoverride
#include "bufferoverride.hpp"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


//-------------------------------------------------------------------------
// titles of each parameter
/*
	fDivisor		"buffer divisor"
	fBuffer			"forced buffer size"
	fBufferTempoSync	"forced buffer tempo sync"
	fBufferInterrupt	"stuck buffer"
	fDivisorLFOrate		"divisor LFO rate"
	fDivisorLFOdepth	"divisor LFO depth"
	fDivisorLFOshape	"divisor LFO shape"
	fDivisorLFOtempoSync	"divisor LFO tempo sync"
	fBufferLFOrate		"buffer LFO rate"
	fBufferLFOdepth		"buffer LFO depth"
	fBufferLFOshape		"buffer LFO shape"
	fBufferLFOtempoSync	"buffer LFO tempo sync"
	fSmooth			"smooth"
	fDryWetMix		"dry/wet mix"
	fPitchbend		"pitchbend"
	fTempo			"tempo"
*/


//-----------------------------------------------------------------------------
// initializations & such

bufferoverride::bufferoverride(int argc, t_atom *argv) {

	buffer1 = NULL;

	SUPER_MAX_BUFFER = (long) ((44100.0f / MIN_ALLOWABLE_BPS) * 4.0f);

	// allocate memory for these structures
	tempoRateTable	= new TempoRateTable;
	divisorLFO	= new LFO;
	bufferLFO	= new LFO;

	suspend();
	initPresets();

	fTempo = tempoUnscaled(120.0f);
	currentTempoBPS = tempoScaled(fTempo) / 60.0f;

	
	post("_ ____bufferoverride~ --_ - __ _____");

	SAMPLERATE = (int) Samplerate();
//	blocksize = Blocksize(); 
	
/*	fTomsound = (float)GetFloat(argv[0]);	// creation arguments 
	fQuality  = (float)GetFloat(argv[1]);	// [ yet they default to reasonable values ]
	drymix    = (float)GetFloat(argv[2]);
	ireplace  =   (int)GetFloat(argv[3]);*/

	AddInSignal();
	AddInFloat(9);
	AddOutSignal();         // 1 audio out [ == AddOutSignal(1) ]
	
	SetupInOut();           // set up inlets and outlets. 
				// Must get called once!

	// Now we need to bind the handler function to our
	// inlets, 
	
/*	fDivisor		"buffer divisor"
	fBuffer			"forced buffer size"
	fBufferTempoSync	"forced buffer tempo sync"
	fBufferInterrupt	"stuck buffer"
	fDivisorLFOrate		"divisor LFO rate"
	fDivisorLFOdepth	"divisor LFO depth"
	fDivisorLFOshape	"divisor LFO shape"
	fDivisorLFOtempoSync	"divisor LFO tempo sync"
	fBufferLFOrate		"buffer LFO rate"
	fBufferLFOdepth		"buffer LFO depth"
	fBufferLFOshape		"buffer LFO shape"
	fBufferLFOtempoSync	"buffer LFO tempo sync"
	fSmooth			"smooth"
	fDryWetMix		"dry/wet mix"
	fPitchbend		"pitchbend"
	fTempo			"tempo" 
	
*/	
	FLEXT_ADDMETHOD( 1,setDivisor);
	FLEXT_ADDMETHOD( 2,setBuffer);
	FLEXT_ADDMETHOD( 3,setTempo);
	FLEXT_ADDMETHOD( 4,setDivisorLFOrate);
	FLEXT_ADDMETHOD( 5,setDivisorLFOdepth);
	FLEXT_ADDMETHOD( 6,setDivisorLFOshape);
	FLEXT_ADDMETHOD( 7,setBufferLFOrate);
	FLEXT_ADDMETHOD( 8,setBufferLFOdepth);
	FLEXT_ADDMETHOD( 9,setBufferLFOshape);

	post("_ ____ ____ _");

}


// GIMME class:
FLEXT_NEW_TILDE_G("bufferoverride~", bufferoverride)


//-------------------------------------------------------------------------
bufferoverride::~bufferoverride() {

	// deallocate the memory from these arrays
	if (buffer1) delete[] buffer1;
	if (tempoRateTable) delete tempoRateTable;
	if (divisorLFO) delete divisorLFO;
	if (bufferLFO) delete bufferLFO;


}

//-------------------------------------------------------------------------
void bufferoverride::suspend()
{
	// setting the values like this will restart the forced buffer in the next process()
	currentForcedBufferSize = 1;
	writePos = readPos = 1;
	minibufferSize = 1;
	prevMinibufferSize = 0;
	smoothcount = smoothDur = 0;
	sqrtFadeIn = sqrtFadeOut = 1.0f;

	divisorLFO->reset();
	bufferLFO->reset();
}

//-------------------------------------------------------------------------
void bufferoverride::createAudioBuffers() {

	// update the sample rate value
	SAMPLERATE = (float)Samplerate();
	// just in case the host responds with something wacky
	if (SAMPLERATE <= 0.0f)
		SAMPLERATE = 44100.0f;
	long oldMax = SUPER_MAX_BUFFER;
	SUPER_MAX_BUFFER = (long) ((SAMPLERATE / MIN_ALLOWABLE_BPS) * 4.0f);

	// if the sampling rate (& therefore the max buffer size) has changed, 
	// then delete & reallocate the buffers according to the sampling rate
	if (SUPER_MAX_BUFFER != oldMax) 	{
		if (buffer1 != NULL)
			delete[] buffer1;
		buffer1 = NULL;
	}
	
	if (buffer1 == NULL) buffer1 = new float[SUPER_MAX_BUFFER];
}


//-------------------------------------------------------------------------
void bufferoverride::initPresets()
{

	fDivisor = bufferDivisorUnscaled(27.0f);
	fBuffer = forcedBufferSizeUnscaled(81.0f);
	fBufferTempoSync	= 0.0f;
	fBufferInterrupt	= 1.0f;
	fSmooth			= 0.06f;
	fDryWetMix		= 1.0f;
	fTempo			= 0.0f;

	divisorLFO->fRate = paramSteppedUnscaled(6.6f, NUM_TEMPO_RATES);
	divisorLFO->fDepth = 0.333f;
	divisorLFO->fShape = LFOshapeUnscaled(kSineLFO);
	divisorLFO->fTempoSync = 1.0f;
	bufferLFO->fRate = 0.0f;
	bufferLFO->fDepth = 0.06f;
	bufferLFO->fShape = LFOshapeUnscaled(kSawLFO);
	bufferLFO->fTempoSync = 1.0f;
}