openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider

11,071 views
11,338 views

Published on

Published in: Technology, Business
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,071
On SlideShare
0
From Embeds
0
Number of Embeds
651
Actions
Shares
0
Downloads
87
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider

  1. 1. ‣‣ ‣ ‣‣‣ ‣ ‣ ‣
  2. 2. ‣‣‣‣‣
  3. 3. ‣‣‣‣ ‣ ‣ ‣‣‣
  4. 4. ‣‣‣
  5. 5. ‣#pragma once#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); ofSoundPlayer mySound; float * fft; int nBandsToGet;};
  6. 6. ‣#pragma once#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); ofSoundPlayer mySound; float * fft; int nBandsToGet;};
  7. 7. ‣‣#include "testApp.h"void testApp::setup(){! ofSetFrameRate(60); ofSetVerticalSync(true); ofSetCircleResolution(32); ofEnableBlendMode(OF_BLENDMODE_ADD); ofBackground(0, 0, 0); nBandsToGet = 1024; mySound.loadSound("sounds/drumLoop.aif"); mySound.setLoop(true); mySound.play();}void testApp::update(){ ofSoundUpdate(); fft = ofSoundGetSpectrum(nBandsToGet);}
  8. 8. ‣‣#include "testApp.h"void testApp::setup(){! ofSetFrameRate(60); ofSetVerticalSync(true); ofSetCircleResolution(32); ofEnableBlendMode(OF_BLENDMODE_ADD); ofBackground(0, 0, 0); nBandsToGet = 1024; mySound.loadSound("sounds/drumLoop.aif"); mySound.setLoop(true); mySound.play();}void testApp::update(){ ofSoundUpdate(); fft = ofSoundGetSpectrum(nBandsToGet);}
  9. 9. ‣‣#include "testApp.h"void testApp::setup(){! ofSetFrameRate(60); ofSetVerticalSync(true); ofSetCircleResolution(32); ofEnableBlendMode(OF_BLENDMODE_ADD); ofBackground(0, 0, 0); nBandsToGet = 1024; mySound.loadSound("sounds/drumLoop.aif"); mySound.setLoop(true); mySound.play();}void testApp::update(){ ofSoundUpdate(); fft = ofSoundGetSpectrum(nBandsToGet);}
  10. 10. ‣‣#include "testApp.h"void testApp::setup(){! ofSetFrameRate(60); ofSetVerticalSync(true); ofSetCircleResolution(32); ofEnableBlendMode(OF_BLENDMODE_ADD); ofBackground(0, 0, 0); nBandsToGet = 1024; mySound.loadSound("sounds/drumLoop.aif"); mySound.setLoop(true); mySound.play();}void testApp::update(){ ofSoundUpdate(); fft = ofSoundGetSpectrum(nBandsToGet);}
  11. 11. ‣‣#include "testApp.h"void testApp::setup(){! ofSetFrameRate(60); ofSetVerticalSync(true); ofSetCircleResolution(32); ofEnableBlendMode(OF_BLENDMODE_ADD); ofBackground(0, 0, 0); nBandsToGet = 1024; mySound.loadSound("sounds/drumLoop.aif"); mySound.setLoop(true); mySound.play();}void testApp::update(){ ofSoundUpdate(); fft = ofSoundGetSpectrum(nBandsToGet);}
  12. 12. ‣void testApp::draw(){ float width = float(ofGetWidth()) / float(nBandsToGet) / 2.0f; for (int i = 0;i < nBandsToGet; i++){ int b = float(255) / float(nBandsToGet) * i; int g = 31; int r = 255 - b; ofSetColor(r, g, b); ofCircle(ofGetWidth()/2 + width * i, ofGetHeight()/2, fft[i] * 800); ofCircle(ofGetWidth()/2 - width * i, ofGetHeight()/2, fft[i] * 800); }}
  13. 13. ‣void testApp::draw(){ float width = float(ofGetWidth()) / float(nBandsToGet) / 2.0f; for (int i = 0;i < nBandsToGet; i++){ int b = float(255) / float(nBandsToGet) * i; int g = 31; int r = 255 - b; ofSetColor(r, g, b); ofCircle(ofGetWidth()/2 + width * i, ofGetHeight()/2, fft[i] * 800); ofCircle(ofGetWidth()/2 - width * i, ofGetHeight()/2, fft[i] * 800); }}
  14. 14. ‣void testApp::draw(){ float width = float(ofGetWidth()) / float(nBandsToGet) / 2.0f; for (int i = 0;i < nBandsToGet; i++){ int b = float(255) / float(nBandsToGet) * i; int g = 31; int r = 255 - b; ofSetColor(r, g, b); ofCircle(ofGetWidth()/2 + width * i, ofGetHeight()/2, fft[i] * 800); ofCircle(ofGetWidth()/2 - width * i, ofGetHeight()/2, fft[i] * 800); }}
  15. 15. ‣void testApp::draw(){ float width = float(ofGetWidth()) / float(nBandsToGet) / 2.0f; for (int i = 0;i < nBandsToGet; i++){ int b = float(255) / float(nBandsToGet) * i; int g = 31; int r = 255 - b; ofSetColor(r, g, b); ofCircle(ofGetWidth()/2 + width * i, ofGetHeight()/2, fft[i] * 800); ofCircle(ofGetWidth()/2 - width * i, ofGetHeight()/2, fft[i] * 800); }}
  16. 16.
  17. 17. ‣‣‣‣‣‣‣‣
  18. 18. ‣‣‣‣‣
  19. 19. ‣#ifndef _TEST_APP#define _TEST_APP#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); void audioIn(float * input, int bufferSize, int nChannels);! vector <float> left; vector <float> right; vector <float> volHistory;
  20. 20. ‣#ifndef _TEST_APP#define _TEST_APP#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); void audioIn(float * input, int bufferSize, int nChannels);! vector <float> left; vector <float> right; vector <float> volHistory;
  21. 21. ‣void testApp::audioIn(float * input, int bufferSize, int nChannels){!! float curVol = 0.0;! int numCounted = 0;!! for (int i = 0; i < bufferSize; i++){! ! left[i]!! = input[i*2]*0.5;! ! right[i]! = input[i*2+1]*0.5;! ! curVol += left[i] * left[i];! ! curVol += right[i] * right[i];! ! numCounted+=2;! }! curVol /= (float)numCounted;! curVol = sqrt( curVol );!! smoothedVol *= 0.93;! smoothedVol += 0.07 * curVol;! bufferCounter++;!}
  22. 22. ‣void testApp::audioIn(float * input, int bufferSize, int nChannels){!! float curVol = 0.0;! int numCounted = 0;!! for (int i = 0; i < bufferSize; i++){! ! left[i]!! = input[i*2]*0.5;! ! right[i]! = input[i*2+1]*0.5;! ! curVol += left[i] * left[i];! ! curVol += right[i] * right[i];! ! numCounted+=2;! }! curVol /= (float)numCounted;! curVol = sqrt( curVol );!! smoothedVol *= 0.93;! smoothedVol += 0.07 * curVol;! bufferCounter++;!}
  23. 23.
  24. 24. ‣#ifndef _TEST_APP#define _TEST_APP#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); void audioOut(float * input, int bufferSize, int nChannels); ofSoundStream soundStream; float ! pan; int! ! sampleRate; bool ! bNoise; float ! volume; vector <float> lAudio; vector <float> rAudio;};#endif
  25. 25. ‣#ifndef _TEST_APP#define _TEST_APP#include "ofMain.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); void audioOut(float * input, int bufferSize, int nChannels); ofSoundStream soundStream; float ! pan; int! ! sampleRate; bool ! bNoise; float ! volume; vector <float> lAudio; vector <float> rAudio;};#endif
  26. 26. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ float leftScale = 1 - pan; float rightScale = pan; while (phase > TWO_PI){ phase -= TWO_PI; } if ( bNoise == true){ for (int i = 0; i < bufferSize; i++){ lAudio[i] = output[i*nChannels ] = ofRandom(0, 1) * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = ofRandom(0, 1) * volume * rightScale; } } else { phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; for (int i = 0; i < bufferSize; i++){ phase += phaseAdder; float sample = sin(phase); lAudio[i] = output[i*nChannels ] = sample * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = sample * volume * rightScale; } }}
  27. 27. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ float leftScale = 1 - pan; float rightScale = pan; while (phase > TWO_PI){ phase -= TWO_PI; } if ( bNoise == true){ for (int i = 0; i < bufferSize; i++){ lAudio[i] = output[i*nChannels ] = ofRandom(0, 1) * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = ofRandom(0, 1) * volume * rightScale; } } else { phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; for (int i = 0; i < bufferSize; i++){ phase += phaseAdder; float sample = sin(phase); lAudio[i] = output[i*nChannels ] = sample * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = sample * volume * rightScale; } }}
  28. 28. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ float leftScale = 1 - pan; float rightScale = pan; while (phase > TWO_PI){ phase -= TWO_PI; } if ( bNoise == true){ for (int i = 0; i < bufferSize; i++){ lAudio[i] = output[i*nChannels ] = ofRandom(0, 1) * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = ofRandom(0, 1) * volume * rightScale; } } else { phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; for (int i = 0; i < bufferSize; i++){ phase += phaseAdder; float sample = sin(phase); lAudio[i] = output[i*nChannels ] = sample * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = sample * volume * rightScale; } }}
  29. 29. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ float leftScale = 1 - pan; float rightScale = pan; while (phase > TWO_PI){ phase -= TWO_PI; } if ( bNoise == true){ for (int i = 0; i < bufferSize; i++){ lAudio[i] = output[i*nChannels ] = ofRandom(0, 1) * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = ofRandom(0, 1) * volume * rightScale; } } else { phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; for (int i = 0; i < bufferSize; i++){ phase += phaseAdder; float sample = sin(phase); lAudio[i] = output[i*nChannels ] = sample * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = sample * volume * rightScale; } }}
  30. 30. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ float leftScale = 1 - pan; float rightScale = pan; while (phase > TWO_PI){ phase -= TWO_PI; } if ( bNoise == true){ for (int i = 0; i < bufferSize; i++){ lAudio[i] = output[i*nChannels ] = ofRandom(0, 1) * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = ofRandom(0, 1) * volume * rightScale; } } else { phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; for (int i = 0; i < bufferSize; i++){ phase += phaseAdder; float sample = sin(phase); lAudio[i] = output[i*nChannels ] = sample * volume * leftScale; rAudio[i] = output[i*nChannels + 1] = sample * volume * rightScale; } }}
  31. 31.
  32. 32. ‣‣‣‣‣
  33. 33. ‣‣ http://maximilian.strangeloop.co.uk/
  34. 34. ‣‣‣‣‣‣
  35. 35. ‣‣
  36. 36. ‣‣
  37. 37. ‣#pragma once#include "ofMain.h"#include "ofxMaxim.h"class testApp : public ofBaseApp{public: void setup(); void update(); void draw(); void keyPressed(int key); void audioOut(float * input, int bufferSize, int nChannels); void audioIn(float * input, int bufferSize, int nChannels); int initialBufferSize; int sampleRate; int mode; double wave,sample,outputs[2]; ofxMaxiMix mymix; ofxMaxiOsc osc; vector <float> lAudio; vector <float> rAudio;};
  38. 38. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float freq = mouseY; float pan = (float)mouseX / (float)ofGetWidth(); switch (mode) { case 0: wave = osc.sinewave(freq); break; case 1: wave = osc.saw(freq); break; case 2: wave = osc.pulse(freq, 0.99); break; case 3: wave = osc.phasor(freq); break; case 4: wave = osc.triangle(freq); break; case 5: wave = osc.noise(); break; default: wave = osc.sinewave(freq); break; }
  39. 39. ‣ mymix.stereo(wave, outputs, pan); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1]; }!}
  40. 40.
  41. 41. ‣‣
  42. 42. ‣#pragma once#include "ofMain.h"#include "ofxMaxim.h"class testApp : public ofBaseApp{public: ~testApp(); void setup(); void update(); void draw(); void audioOut(float * input, int bufferSize, int nChannels); void audioIn(float * input, int bufferSize, int nChannels);! int initialBufferSize; int sampleRate; double outputs[2]; double wave; ofxMaxiMix mymix; ofxMaxiOsc car; ofxMaxiOsc mod; vector <float> lAudio; vector <float> rAudio;};
  43. 43. ‣#pragma once#include "ofMain.h"#include "ofxMaxim.h"class testApp : public ofBaseApp{public: ~testApp(); void setup(); void update(); void draw(); void audioOut(float * input, int bufferSize, int nChannels); void audioIn(float * input, int bufferSize, int nChannels);! int initialBufferSize; int sampleRate; double outputs[2]; double wave; ofxMaxiMix mymix; ofxMaxiOsc car; ofxMaxiOsc mod; vector <float> lAudio; vector <float> rAudio;};
  44. 44. ‣#pragma once#include "ofMain.h"#include "ofxMaxim.h"class testApp : public ofBaseApp{public: ~testApp(); void setup(); void update(); void draw(); void audioOut(float * input, int bufferSize, int nChannels); void audioIn(float * input, int bufferSize, int nChannels);! int initialBufferSize; int sampleRate; double outputs[2]; double wave; ofxMaxiMix mymix; ofxMaxiOsc car; ofxMaxiOsc mod; vector <float> lAudio; vector <float> rAudio;};
  45. 45. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float index, modFreq; ofMap(modFreq, 0, mouseX, 20, 8000); ofMap(index, 0, mouseY, 1, 2000); wave = car.sinewave(mouseY*mod.sinewave(mouseX/10)+440); mymix.stereo(wave, outputs, 0.5); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1];! }}
  46. 46. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float index, modFreq; ofMap(modFreq, 0, mouseX, 20, 8000); ofMap(index, 0, mouseY, 1, 2000); wave = car.sinewave(mouseY*mod.sinewave(mouseX/10)+440); mymix.stereo(wave, outputs, 0.5); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1];! }}
  47. 47. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float index, modFreq; ofMap(modFreq, 0, mouseX, 20, 8000); ofMap(index, 0, mouseY, 1, 2000); wave = car.sinewave(mouseY*mod.sinewave(mouseX/10)+440); mymix.stereo(wave, outputs, 0.5); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1];! }}
  48. 48. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float index, modFreq; ofMap(modFreq, 0, mouseX, 20, 8000); ofMap(index, 0, mouseY, 1, 2000); wave = car.sinewave(mouseY*mod.sinewave(mouseX/10)+440); mymix.stereo(wave, outputs, 0.5); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1];! }}
  49. 49. ‣void testApp::audioOut(float * output, int bufferSize, int nChannels){ for (int i = 0; i < bufferSize; i++){ float index, modFreq; ofMap(modFreq, 0, mouseX, 20, 8000); ofMap(index, 0, mouseY, 1, 2000); wave = car.sinewave(mouseY*mod.sinewave(mouseX/10)+440); mymix.stereo(wave, outputs, 0.5); lAudio[i] = output[i*nChannels ] = outputs[0]; rAudio[i] = output[i*nChannels + 1] = outputs[1];! }}
  50. 50.
  51. 51. ‣ ‣
  52. 52. ‣ ‣
  53. 53. ‣ ‣ ‣ ‣ ‣
  54. 54. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  55. 55. ‣ ‣ ‣ ‣
  56. 56. ‣ ‣
  57. 57.
  58. 58.
  59. 59.
  60. 60.
  61. 61.
  62. 62. ‣‣
  63. 63.
  64. 64. ‣‣‣
  65. 65. ‣‣‣‣‣‣‣
  66. 66. ‣‣
  67. 67. ‣‣
  68. 68. ‣‣‣‣‣‣
  69. 69. ‣SynthDef("reverb", { arg wet=1.0; var in, fx; in = In.ar(0, 2); fx = in; fx = GVerb.ar(fx, 80); ReplaceOut.ar(0, fx);}).store;SynthDef("baseSound", { arg note=40, amp=0.1, fadein=12.0; var env, out; env = EnvGen.kr(Env.new([0, amp], [fadein])); out = RLPF.ar(LFPulse.ar([note, note+7].midicps, 0.15), SinOsc.kr(0.1, 0, 10, 72).midicps, 0.1, 0.1); Out.ar(0, out*env);}).store;SynthDef("newRing", { arg note=40, amp=0.5, pan = 0.0, decay=4.0; var env1, out1, env2, out2, mix; out1 = RLPF.ar(LFPulse.ar([note, note+7].midicps, 0.15), SinOsc.kr(0.1, 0, 10, 72).midicps, 0.1, 0.1); out2 = SinOsc.ar([(note+48).midicps, (note+55).midicps]); env1 = EnvGen.kr(Env.perc(decay/4.0, decay/4.0*3.0, amp, -4), doneAction: 2); env2 = EnvGen.kr(Env.adsr(0.001, 0.4, 0.0, decay, amp*0.1, -4)); mix = (out1 * env1) + (out2 * env2); mix = CombN.ar(mix, 0.31, 0.31, 2, 0.5, mix); Out.ar(0, mix);}).store;
  70. 70. ‣‣
  71. 71.
  72. 72. ‣‣‣http://goo.gl/9rH4K‣‣‣
  73. 73.

×