topical media & game development
lib-of-vs-apps-examples-audioInputExample-src-testApp.cpp / cpp
include <testApp.h>
include <stdio.h>
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(255,255,255);
// 0 output channels,
// 2 input channels
// 22050 samples per second
// 256 samples per buffer
// 4 num buffers (latency)
ofSoundStreamSetup(0,2,this, 44100, 256, 4);
left = new float[256];
right = new float[256];
bufferCounter = 0;
drawCounter = 0;
}
//--------------------------------------------------------------
void testApp::draw(){
// draw the left:
ofSetColor(0x333333);
ofRect(100,100,256,200);
ofSetColor(0xFFFFFF);
for (int i = 0; i < 256; i++){
ofLine(100+i,200,100+i,200+left[i]*100.0f);
}
// draw the right:
ofSetColor(0x333333);
ofRect(600,100,256,200);
ofSetColor(0xFFFFFF);
for (int i = 0; i < 256; i++){
ofLine(600+i,200,600+i,200+right[i]*100.0f);
}
ofSetColor(0x333333);
drawCounter++;
char reportString[255];
sprintf(reportString, "buffers received: \%i\ndraw routines called: \%i\n", bufferCounter,drawCounter);
ofDrawBitmapString(reportString,80,380);
}
static float adder = 0;
//--------------------------------------------------------------
void testApp::audioReceived (float * input, int bufferSize, int nChannels){
// samples are "interleaved"
for (int i = 0; i < bufferSize; i++){
left[i] = input[i*2];
right[i] = input[i*2+1];
}
bufferCounter++;
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::resized(int w, int h){
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.