-
-
Save anonymous/14782d0237a0e39db310 to your computer and use it in GitHub Desktop.
relevant parts of soundStream problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
ofBackground(255,255,255); | |
w = 320; | |
h = 240; | |
movie.initGrabber(w, h, true); | |
//reserve memory for cv images | |
rgb.allocate(w, h); | |
hsb.allocate(w, h); | |
hue.allocate(w, h); | |
sat.allocate(w, h); | |
bri.allocate(w, h); | |
filtered.allocate(w, h); | |
colour.setHue(0); | |
int bufferSize = 512; | |
sampleRate = 44100; | |
phase = 0; | |
phaseAdder = 0.0f; | |
phaseAdderTarget = 0.0f; | |
volume = 0.1f; | |
lAudio.assign(bufferSize, 0.0); | |
rAudio.assign(bufferSize, 0.0); | |
soundStream.setup(this, 2, 0, sampleRate, bufferSize, 4); | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
movie.update(); | |
if (movie.isFrameNew()) { | |
//copy webcam pixels to rgb image | |
rgb.setFromPixels(movie.getPixels(), w, h); | |
//mirror horizontal | |
rgb.mirror(false, true); | |
//duplicate rgb | |
hsb = rgb; | |
//convert to hsb | |
hsb.convertRgbToHsv(); | |
//store the three channels as grayscale images | |
hsb.convertToGrayscalePlanarImages(hue, sat, bri); | |
int takePixel = 1284; | |
for(int j=0; j < 24; j++) | |
{ | |
for(int i=0; i < 32; i++) | |
{ | |
findBri[i][j] = bri.getPixels()[takePixel]; | |
takePixel += 10; | |
} | |
takePixel += 1280; | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::audioOut(float * output, int bufferSize, int nChannels){ | |
//pan = 0.5f; | |
for(int n = 0; n < 1; n++) | |
{ | |
pan = (n+1)/24; | |
for(int p = 0; p < 1; p++) | |
{ | |
pitch = 50*(p+1); | |
phaseAdderTarget = (pitch / (float) sampleRate) * TWO_PI; | |
volume = findBri[p][n]/255; | |
float leftScale = 1 - pan; | |
float rightScale = pan; | |
// sin (n) seems to have trouble when n is very large, so we | |
// keep phase in the range of 0-TWO_PI like this: | |
while (phase > TWO_PI){ | |
phase -= TWO_PI; | |
} | |
phaseAdder = 0.95f * phaseAdder + 0.05f * phaseAdderTarget; | |
for (int i = 0; i < bufferSize; i++){ | |
phase += phaseAdder; | |
float sample = sin(phase)+phase; | |
lAudio[i] = output[i*nChannels ] = sample * volume * 0.5 * leftScale; | |
rAudio[i] = output[i*nChannels + 1] = sample * volume * 0.5 * rightScale; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment