File: instr.cpp

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (104 lines) | stat: -rw-r--r-- 2,437 bytes parent folder | download | duplicates (17)
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
#include "instr.h"
#include "Instrmnt.h"
#include "Clarinet.h"
#include "Saxofony.h"
#include "Bowed.h"
#include "BandedWG.h"
#include "Mandolin.h" 
#include "Sitar.h"
#include "ModalBar.h"
#include "Flute.h"
#include "stdlib.h"
#include "string.h"

using namespace Nyq;

/* C interface to Instrmnt */

struct instr {
	Instrmnt *instrObjPtr;
};



struct instr *initInstrument(int instr_type, int sample_rate) {
	struct instr *in = (struct instr *) malloc(sizeof(struct instr));
        Stk::setSampleRate(sample_rate);
	switch(instr_type) {
		case CLARINET: 
			in->instrObjPtr = new Clarinet(10.0);
			break;
		case SAXOFONY:
			in->instrObjPtr = new Saxofony(10.0);
			break;
	        case BOWED:
		  in->instrObjPtr = new Bowed(10.0);
		  break;
	        case BANDEDWG:
		  in->instrObjPtr = new BandedWG();
		  break;
		case MANDOLIN:
		  in->instrObjPtr = new Mandolin(10.0);
		  break;
        	case SITAR:
		  in->instrObjPtr = new Sitar(10.0);
		  break;
	        case MODALBAR:
		  in->instrObjPtr = new ModalBar();
		  break;
	        case FLUTE:
		  in->instrObjPtr = new Flute(10.0);
		  break;
		default:
			return NULL;
	}
	return in;
}

int deleteInstrument(struct instr* in) {
	delete(in->instrObjPtr);
	free(in);
	return 0;
}

//! Start a note with the given frequency and amplitude.
int noteOn(struct instr* in, ::MY_FLOAT frequency, ::MY_FLOAT amplitude) {
	in->instrObjPtr->noteOn(frequency, amplitude);
	return 0;
}

//! Stop a note with the given amplitude (speed of decay).
int noteOff(struct instr* in, ::MY_FLOAT amplitude) {
	in->instrObjPtr->noteOff(amplitude);
	return 0;
}

//! Set instrument parameters for a particular frequency.
int setFrequency(struct instr* in, ::MY_FLOAT frequency) {
	in->instrObjPtr->setFrequency(frequency);
	return 0;
}

//! Return the last output value.
/*
MY_FLOAT lastOut(struct instr* in) {
	return in->instrObjPtr->lastOut();
}
*/

//! Compute one output sample.
::MY_FLOAT tick(struct instr* in) {
	return in->instrObjPtr->tick();
}

// DELETED THIS. PJM
//! Computer \e vectorSize outputs and return them in \e vector.
//MY_FLOAT *multTicks(struct instr* in, MY_FLOAT *vector, unsigned int vectorSize) {
//	return in->instrObjPtr->tick(vector, vectorSize);
//}

//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
int controlChange(struct instr* in, int number, ::MY_FLOAT value) {
	in->instrObjPtr->controlChange(number, value);
	return 0;
}