the ofApp::setup() method:
-
void ofApp::setup(){
// BGG audio stuff
int sr = 44100;
int nbufs = 2; // you can use more for more processing but latency will suffer
nchans = 2;
framesize = 512;
s_audio_outbuf = (short*)malloc(nchans*framesize*sizeof(short));
// initialize RTcmix
rtcmixmain();
maxmsp_rtsetparams(sr, nchans, framesize, NULL, NULL);
ofSoundStreamSetup(nchans, 0, sr, framesize, nbufs);
ofSoundStreamStart();
// here is where we added our score, from the 'scoralyzer' program.
// we are declaring "thescore" as a character array which will hold the
// RTcmix script
//
// right here we are only doing initialization stuff; it will get called
// once when the app starts and RTcmix has begun running
//
// the "parse_score(thescore, strlen(thescore));" is what send the
// character array "the score" to RTcmix
char *thescore = { " \
bus_config(\"WAVETABLE\", \"aux 0 out\") \
bus_config(\"MOOGVCF\", \"aux 0 in\", \"aux 1-2 out\") \
bus_config(\"PANECHO\", \"aux 1-2 in\", \"out 0-1\") \
wave = maketable(\"wave\", 1000, \"saw\") \
\
ffreq = maketable(\"line\", \"nonorm\", 1000, 0, 7000, 0.5, 100) \
ffmult = 0.7 \
\
PANECHO(0, 0, 999, 1, 0.125, 0.5, 0.05, 1, 0) \
MAXBANG(1.0) \
"};
parse_score(thescore, strlen(thescore));
}
the ofApp::audioRequested() method:
-
void ofApp::audioRequested(float * output, int bufferSize, int nChannels) {
pullTraverse(NULL, s_audio_outbuf);
for (int i = 0; i < framesize*nchans; i++)
output[i] = (float)s_audio_outbuf[i]/32786.0; // transfer to the float *output buf
// this "audioRequested" function gets called everytime a new buffers-worth
// of audio is neede (very often -- the buffers are set at 512 samples by
// default). We use "check_bang()" to see if a 'bang' (via MAXBANG) is
// set. If it is, we fire off a score fragment to keep the notes and
// bangs going.
if (check_bang() == 1) {
char *thescore = { " \
dur = 0.5 \
WAVETABLE(0, dur/2, 10000, 8.00, 0, wave) \
WAVETABLE(0, dur/2, 10000, 8.001, 0, wave) \
\
MOOGVCF(0, 0, dur/2, 1, 0, 0.5, 0, ffreq*ffmult, 0.9) \
\
WAVETABLE(dur/2, dur/2, 10000, 8.00, 0, wave) \
WAVETABLE(dur/2, dur/2, 10000, 8.001, 0, wave) \
\
MOOGVCF(dur/2, 0, dur/2, 1, 0, 0.5, 0, ffreq/2*ffmult, 0.9) \
\
MAXBANG(dur) \
"};
parse_score(thescore, strlen(thescore));
}
char *pbuf = get_print();
char *pbufptr = pbuf;
while (strlen(pbufptr) > 0) {
ofLog() << pbufptr;
pbufptr += (strlen(pbufptr) + 1);
}
reset_print();
}
the ofApp::touchDown() and ofApp::touchMoved() methods:
-
void ofApp::touchDown(ofTouchEventArgs & touch){
// print out our values so we can see them for fun
ofLog(OF_LOG_NOTICE, "the x value: %f, the y value: %f", touch.x, touch.y);
// 'dollar1' gets the x-coordinate of where we touched the screen
float dollar1 = touch.x/300.0;
// we declare the 'tmpscore' array so we can write into it
char tmpscore[1024];
// this will write a very tiny RTcmix score fragment into 'tmpscore':
// "ffmult = XXX" where "XXX" is replaced by the value from 'dollar1'
sprintf(tmpscore, "ffmult = %f", dollar1);
// that's all we need to do to get RTcmix teh new value of 'ffmult'
parse_score(tmpscore, strlen(tmpscore));
}
//--------------------------------------------------------------
void ofApp::touchMoved(ofTouchEventArgs & touch){
// we used "touchMoved" too so that it will pick up values when we drag
// our finger along the screen
ofLog(OF_LOG_NOTICE, "the x value: %f, the y value: %f", touch.x, touch.y);
float dollar1 = touch.x/300.0;
char tmpscore[1024];
sprintf(tmpscore, "ffmult = %f", dollar1);
parse_score(tmpscore, strlen(tmpscore));
}