[ Video ]
[ About ]
マイク入力でWaveを生成
Wave created from microphone input.
[ Source ]
| 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 | #pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public: 	void setup(); 	void update(); 	void draw(); 	void keyPressed(int key) {}; 	void keyReleased(int key) {}; 	void mouseMoved(int x, int y) {}; 	void mouseDragged(int x, int y, int button) {}; 	void mousePressed(int x, int y, int button) {}; 	void mouseReleased(int x, int y, int button) {}; 	void mouseEntered(int x, int y) {}; 	void mouseExited(int x, int y) {}; 	void windowResized(int w, int h) {}; 	void dragEvent(ofDragInfo dragInfo) {}; 	void gotMessage(ofMessage msg) {}; 	ofSoundStream sound_stream; 	void audioIn(float* input, int bufferSize, int nChannels); 	float vol; 	vector<float> lengths; 	vector<ofColor> colors; }; | 
| 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 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(0); 	ofSetWindowTitle("Insta"); 	ofNoFill(); 	ofSetLineWidth(6); 	ofSetCircleResolution(120); 	sound_stream.setup(this, 0, 1, 44100, 256, 4); } //-------------------------------------------------------------- void ofApp::update() { 	for (int i = 0; i < this->lengths.size(); i++) { 		this->lengths[i] += 2; 	} 	if (this->vol > 0.5) { 		ofColor color; 		color.setHsb(ofGetFrameNum() % 255, 255, 255); 		this->lengths.push_back(0); 		this->colors.push_back(color); 		this->vol = 0; 	} 	for (int i = this->lengths.size() - 1; i >= 0; i--) { 		if (this->lengths[i] > ofGetWidth()) { 			this->lengths.erase(this->lengths.begin() + i); 			this->colors.erase(this->colors.begin() + i); 		} 	} } //-------------------------------------------------------------- void ofApp::draw() { 	for (int i = 0; i < this->lengths.size(); i++) { 		ofSetColor(this->colors[i], 255 - this->lengths[i] / 2); 		ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 2, this->lengths[i]); 	} } //-------------------------------------------------------------- void ofApp::audioIn(float* input, int bufferSize, int nChannels) { 	for (int i = 0; i < bufferSize; i++) { 		this->vol += input[i] * input[i]; 	} } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(720, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |