aboutsummaryrefslogtreecommitdiffstats
path: root/ofxMaxim/examples/OSX/ofxMaximExamples007OSX/maxiAtomSynthesis/src/mp.cpp
blob: 57970cf3ef3e0fdb0f83472aeb0d890edd8f7d6a (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
#include "mp.h"

//--------------------------------------------------------------
void mp::setup(){
	ofEnableAlphaBlending();
	ofSetupScreen();
	ofBackground(0, 0, 0);
	ofSetVerticalSync(true);
//	pyd.setup("localhost", 23612);
//	pyd.clear();
	
	
	maxiAtomBook::loadMPTKXmlBook(ofToDataPath("book100.xml"), book);
	sort(book.atoms.begin(), book.atoms.end(), maxiAtom::atomSortPositionAsc);
	atomBuffer.resize(512);
	atomData.resize(book.atoms[0]->length);

	ofxMaxiSettings::setup(44100, 2, 512);
	ofSoundStreamSetup(maxiSettings::channels,0,this, maxiSettings::sampleRate, maxiSettings::bufferSize, 4);/* Call this last ! */
	
//	flArr test;
//	maxiCollider::createGabor(test, maxiMap::linexp(atom->frequency, 0, 0.2, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 40.0);
	
}



//--------------------------------------------------------------
void mp::update(){
	flArr test;
	//generate atoms from mouse position
//	maxiCollider::createGabor(test, maxiMap::linexp((float)mouseX/ofGetWidth(), 0, 1, 100, 10000) * (1.0 + (ofRandomuf() * 0.2)), 
//					   maxiSettings::sampleRate, 
//					   maxiMap::linlin((float)mouseY / ofGetHeight(), 0, 1, 2000, 40000) * (1.0 + (ofRandomuf() * 0.3)), 
//					   ofRandomf() * PI, 0.3, 0.05);
//	atomStream.addAtom(test);

	//play book back one atom at a time
//	static int atomIdx=0;
//	maxiGaborAtom *atom = (maxiGaborAtom*) book.atoms[atomIdx % book.atoms.size()];
//	maxiCollider::createGabor(test, maxiMap::linlin(atom->frequency, 0.0, 1.0, 20, 20000), 44100, atom->length, atom->phase, 0.3, atom->amp / 30.0);
//	atomStream.addAtom(test);	
//	atomIdx++;
//	cout << (atomIdx % book.atoms.size()) << ", " <<  maxiMap::linlin(atom->frequency, 0.0, 1.0, 20, 20000) << ", " << atom->amp << endl;

}

//--------------------------------------------------------------
void mp::draw(){

}

void mp::audioRequested 	(float * output, int bufferSize, int nChannels){
	atomPlayer.play(book, atomStream, output, bufferSize);
	
	memset(&atomBuffer[0], 0, sizeof(float) * bufferSize);
	atomStream.fillNextBuffer(&(atomBuffer[0]), bufferSize);
	for (int i = 0; i < bufferSize; i++){
		output[i*nChannels    ] = output[i*nChannels + 1] = atomBuffer[i]; 
	}
	
}


//--------------------------------------------------------------
void mp::keyPressed(int key){

}

//--------------------------------------------------------------
void mp::keyReleased(int key){

}

//--------------------------------------------------------------
void mp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void mp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void mp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void mp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void mp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void mp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void mp::dragEvent(ofDragInfo dragInfo){ 

}