This file is indexed.

/usr/share/faust/octave.cpp is in faust-common 0.9.95~repack1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/* octave.cpp
   Copyright (C) 2009 by Bjoern Anton Erlach. */

// OCTAVE architecture file for faust.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307 USA
//-------------------------------------------------------------------

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <oct.h>


using namespace std;

// TODO: find out what to do with this Meta thing
struct Meta : map<const char*, const char*>
{
    void declare (const char* key, const char* value) { (*this)[key]=value; }
};



// abs is now predefined
//template<typename T> T abs (T a)			{ return (a<T(0)) ? -a : a; }


inline int		lsr (int x, int n)			{ return int(((unsigned int)x) >> n); }

/******************************************************************************
*******************************************************************************

							       VECTOR INTRINSICS

*******************************************************************************
*******************************************************************************/

//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }


<<includeIntrinsic>>

/******************************************************************************
*******************************************************************************

			ABSTRACT USER INTERFACE

*******************************************************************************
*******************************************************************************/


class UI
{
	bool	fStopped;
public:

	UI() : fStopped(false) {}
	virtual ~UI() {}

	// -- active widgets

	virtual void addButton(const char* label, float* zone) = 0;
	virtual void addToggleButton(const char* label, float* zone) = 0;
	virtual void addCheckButton(const char* label, float* zone) = 0;
	virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
	virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
	virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;

	// -- passive widgets

	virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
	virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;

	// -- frames and labels

	virtual void openFrameBox(const char* label) = 0;
	virtual void openTabBox(const char* label) = 0;
	virtual void openHorizontalBox(const char* label) = 0;
	virtual void openVerticalBox(const char* label) = 0;
	virtual void closeBox() = 0;

	virtual void show() = 0;
	virtual void run() = 0;

	void stop()		{ fStopped = true; }
	bool stopped() 	{ return fStopped; }

    virtual void declare(float* zone, const char* key, const char* value) {}
};


struct param {
	string fName; float *fVals; float* fZone; float fMin; float fMax;
	param(string name, float* z, float init, float a, float b) : fName(name), fVals(NULL), fZone(z), fMin(a), fMax(b) { *z = init; }
};


class FNUI : public UI
{
	vector<param>	fParam;
	int numOptions;


public:
	FNUI() : UI() { numOptions=0; }
	virtual ~FNUI() {}


	void addOption(const char* label, float* zone, float init, float min, float max)
	{
	  string fullname = label;
	  fParam.push_back(param(fullname, zone, init, min, max));
	  numOptions++;
	}

	virtual vector<param> getOpts () { return fParam; }

	virtual void addButton(const char* label, float* zone)
	{
		addOption(label,zone,0,0,1);
	}

	virtual int getNumOptions() { return numOptions; }

	virtual void addToggleButton(const char* label, float* zone)
	{
		addOption(label,zone,0,0,1);
	}

	virtual void addCheckButton(const char* label, float* zone)
	{
		addOption(label,zone,0,0,1);
	}

	virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step)
	{
		addOption(label,zone,init,min,max);
	}

	virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step)
	{
		addOption(label,zone,init,min,max);
	}

	virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step)
	{
		addOption(label,zone,init,min,max);
	}

	// -- passive widgets

	virtual void addNumDisplay(const char* label, float* zone, int precision) {}
	virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {}
	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {}
	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) {}


	virtual void openFrameBox(const char* label)		{ }
	virtual void openTabBox(const char* label)              { }
	virtual void openHorizontalBox(const char* label)	{ }
	virtual void openVerticalBox(const char* label)		{ }

	//virtual void openFrameBox(const char* label)		{ openAnyBox(label); }
	//virtual void openTabBox(const char* label)              { openAnyBox(label); }
	//virtual void openHorizontalBox(const char* label)	{ openAnyBox(label); }
	//virtual void openVerticalBox(const char* label)		{ openAnyBox(label); }

	//virtual void closeBox() { fPrefix.pop(); }
	virtual void closeBox() { }
	virtual void run() 	{}
	virtual void show() 	{}

};



/******************************************************************************
*******************************************************************************

			    FAUST DSP

*******************************************************************************
*******************************************************************************/



//----------------------------------------------------------------
//  abstract definition of a signal processor
//----------------------------------------------------------------

class dsp {
 protected:
	int fSamplingFreq;
 public:
	dsp() {}
	virtual ~dsp() {}

	virtual int getNumInputs() 						= 0;
	virtual int getNumOutputs() 					= 0;
	virtual void buildUserInterface(UI* interface) 	= 0;
	virtual void init(int samplingRate) 			= 0;
 	virtual void compute(int len, float** inputs, float** outputs) 	= 0;
};


//----------------------------------------------------------------------------
//  FAUST generated signal processor
//----------------------------------------------------------------------------


<<includeclass>>


//----------------------------------------------------------------------------
//  Octave interface
//----------------------------------------------------------------------------

// Prefered way to allocate memory
#define ALLOC(x) alloca(x)
#define FREE(x) ((void)0)
// if ALLOCA is not available use MALLOC
//#define ALLOC(x) malloc(x)
//#define FREE(x) free(x)

#define QUOTEME(x) #x

#define DEFAULT_SAMPLERATE 44100
#define DEFAULT_BLOCKSIZE 64

// linear interpolation for vector valued control inputs
void
interpolate_ctrlin (float *vals, NDArray in, int n)
{
  int nin = in.length();
  double ratio = (double)(n-1)/(double)(nin-1);
  int irat = (int) ratio;
  double frat = ratio - (double) irat;
  double rest = 0;
  int i = 0;
  float x;

  for (int j=0; j<(nin-1); j++) {
	  float del;
	  int seglength = irat;
	  rest += frat;
	  if (rest >= 1.0) {
		  seglength ++;
		  rest -= 1.0;
	  }
	  del = (in(j+1) - in(j)) / (float) seglength;
	  x = in(j);
	  for (int k=0; k<seglength; k++) {
		  vals[i++] = x;
		  x += del;
	  }
  }
  for (; i<n; i++) {
	  vals[i] = in(nin-1);
  }
}



DEFUN_DLD (FAUST_FUNC_NAME, args, nargout,
	   "type " QUOTEME(FAUST_FUNC_NAME) "() to see the arguments.\n")
{
  int nargin = args.length();
  int numIn;
  int numOut;
  int numOpts;
  int maxInputLength = 0;
  mydsp DSP;
  int ngivenctrls;
  float **finputs;
  float **foutputs;
  float **controlinputs;
  int ctrllength;
  int ctrlargoff;
  int allscalarctrls = 1;
  // TODO: float **controloutputs;
  int i;
  vector<param> opts;
  int bsize;
  int srate;
  octave_value_list retval;
  octave_value tmp;

  FNUI* interface = new FNUI();
  DSP.buildUserInterface(interface);

  // check if global variable FAUST_BLOCKSIZE is set.
  tmp = get_global_value ("FAUST_BLOCKSIZE", true);
  if (tmp.is_defined ())
	  bsize = (int) tmp.scalar_value();
  else {
	  bsize = DEFAULT_BLOCKSIZE;
  }

  // check if global variable FAUST_SAMPLERATE is set.
  tmp = get_global_value ("FAUST_SAMPLERATE", true);
  if (tmp.is_defined ())
	  srate = (int) tmp.scalar_value();
  else {
	  srate = DEFAULT_SAMPLERATE;
  }

  DSP.init(srate);
  opts = interface->getOpts();

  numIn = DSP.getNumInputs();
  numOut = DSP.getNumOutputs();
  numOpts = interface->getNumOptions();

  // print a usage message in case the function is called with too few arguments
  if (nargin < numIn || nargin == 0) {
	  if (numOut>1) {
		  octave_stdout << "[out1";
		  for (i=2; i<=numOut; i++)
			  octave_stdout << ",out" << i;
		  octave_stdout << "] = " << QUOTEME(FAUST_FUNC_NAME) << "(";
	  } else {
		  octave_stdout << "out = " << QUOTEME(FAUST_FUNC_NAME) << "(";
	  }
	  if (numIn == 0)
		  octave_stdout << "numsamps";
	  else
		  octave_stdout << "in1";
	  for (i=2; i<=numIn; i++)
		  octave_stdout << ", in" << i;
	  for (i=0; i<numOpts; i++)
		  octave_stdout << ", " << opts[i].fName;
	  octave_stdout << ")\n";
	  delete interface;
	  return retval;
 }

  // If we have inputs we use the length of the longest input vector
  // as length of the output to be produced.
  // If we don't have inputs, the first argument specifies the number of
  // samples to be produced.
  if (numIn == 0) {
	  maxInputLength = args(0).scalar_value();
	  ctrlargoff = 1;
  } else {
	  ctrlargoff = numIn;
	  for (i=0; i<numIn; i++) {
		  octave_idx_type nr = args(i).matrix_value().rows();
		  octave_idx_type nc = args(i).matrix_value().columns();
		  if (nr == 1) {
			  if (nc > maxInputLength)
				  maxInputLength = nc;
		  } else if (nc == 1) {
			  if (nr > maxInputLength)
				  maxInputLength = nr;
		  } else {
			  maxInputLength = nc;
			  octave_stdout << "Argument " << i << " has wrong dimensions " << nr << "x" << nc << "\n";
		  }
	  }
  }


  ctrllength = (maxInputLength+bsize-1)/bsize;

  // check for arguments that should serve as control inputs
  for (i=ctrlargoff; i<nargin; i++) {
	  if ((i-ctrlargoff) < numOpts) {
		  NDArray v = args(i).array_value();
		  if (v.length() > 1) {
			  allscalarctrls = 0;
			  opts[i-ctrlargoff].fVals = (float*) ALLOC(sizeof(float)*ctrllength);
			  interpolate_ctrlin(opts[i-ctrlargoff].fVals, v, ctrllength);
			  *opts[i-ctrlargoff].fZone = (float) v(0);
		  } else {
			  *opts[i-ctrlargoff].fZone = (float) args(i).scalar_value();
		  }
	  }
  }

  for (i=0; i<numOpts; i++) {
	  octave_stdout << "Parameter " << opts[i].fName << ": " << *opts[i].fZone << "\n";
  }

  finputs = (float**) ALLOC(sizeof(float*) * numIn);
  foutputs = (float**) ALLOC(sizeof(float*) * numOut);

  // Copy the matrix and convert to floats - This is a real slowdown!
  for (i=0; i<numIn; i++) {
	  Matrix m = args(i).matrix_value();
	  float *p;
	  finputs[i] = (float*) ALLOC(maxInputLength * sizeof(float));
	  memset(finputs[i], 0, sizeof(float)*maxInputLength);
	  p = finputs[i];
	  if (m.rows() > m.columns()) {
		  for (int j=0; j<m.rows(); j++) {
			  *p++ = (float) m(j,0);
		  }
	  } else {
		  for (int j=0; j<m.columns(); j++) {
			  *p++ = (float) m(0,j);
		  }
	  }
  }

  // allocate output vectors
  for (i=0; i<numOut; i++) {
	  foutputs[i] = (float*) ALLOC(maxInputLength * sizeof(float));
	  memset(foutputs[i], 0, sizeof(float)*maxInputLength);
  }

  if (allscalarctrls) {
	  DSP.compute(maxInputLength, finputs, foutputs);
  } else {
	  int nleft = maxInputLength;
	  int k = 0;
	  float **fins;
	  float **fouts;
	  fins = (float**) ALLOC(sizeof(float*) * numIn);
	  fouts = (float**) ALLOC(sizeof(float*) * numOut);
	  memcpy(fins, finputs, sizeof(float*)*numIn);
	  memcpy(fouts, foutputs, sizeof(float*)*numOut);
	  while (nleft > 0) {
		  int n = min(bsize, nleft);
		  for (i=0; i<numOpts; i++) {
			  if (opts[i].fVals) {
				  *opts[i].fZone = opts[i].fVals[k];
			  }
		  }
		  DSP.compute(n, fins, fouts);
		  nleft -= n;
		  k++;
		  for (i=0; i<numIn; i++)
			  fins[i] += n;
		  for (i=0; i<numOut; i++)
			  fouts[i] += n;
	  }
	  FREE(fins);
	  FREE(fouts);
  }

  // copy the output from the float arrays (and free all tmp memory if malloc is used)
  for (i=0; i<numOut; i++) {
	  Matrix output = Matrix(1, maxInputLength);
	  for (int j=0; j<maxInputLength; j++)
		  output(0, j) = (double) foutputs[i][j];
	  FREE(foutputs[i]);
	  retval(i) = output;
  }
  for (i=0; i<numOpts; i++) {
	  if (opts[i].fVals) {
		  FREE(opts[i].fVals);
	  }
  }
  for (i=0; i<numIn; i++) {
	  FREE(finputs[i]);
  }
  FREE(foutputs);
  FREE(finputs);

  delete interface;
  return retval;
}