// ex9.cpp / Music 120 / Lecture 3 // Applies chorus effect to realtime input and plays through realtime output, // stops when "Enter" is pressed. // // Mac OS X with StkX: // g++ -g -o ex9 ex9.cpp -framework StkX -D__STKX__ // // CCRMA Linux machines: // g++ -g -o ex9 ex9.cpp -I/usr/include/stk -lstk -lasound -ljack // // Usage: ./ex9 effect_mix mod_depth mod_frequency // Example: ./ex9 0.75 0.1 2.0 // // Created by Woon Seung Yeo on 10/9/06. // Based on the callback sample code by Gary Scavone and Perry Cook. // Copyright 2006 CCRMA, Stanford University. All rights reserved. #include #ifdef __STKX__ #include #else #include "Chorus.h" #include "RtAudio.h" #endif int tick_c(char *buffer, int bufferSize, void *dataPointer) { // Pointer to "Chorus" from main Chorus *chorus = (Chorus *) dataPointer; StkFloat *samples = (StkFloat *) buffer; // Passes RT input through "chorus" to RT output for ( int i=0; itick(*samples); return 0; } int main (int argc, char* const argv[]) { // Input arguments as chorus parameters float effectMix = atof( argv[1] ); // Wet/dry ratio (0.0~1.0) float modDepth = atof( argv[2] ); // Modulation depth (0.0~1.0) float modFrequency = atof( argv[3] ); // Modulation frequency [Hz] Stk::setSampleRate( 44100.0 ); Chorus* chorus = new Chorus(); // Chorus chorus->setEffectMix(effectMix); // Wet/dry ratio chorus->setModDepth(modDepth); // Mod. depth chorus->setModFrequency(modFrequency); // Mod. freq. RtAudio* dac; // RtAudio: realtime audio I/O RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32; int bufferSize = RT_BUFFER_SIZE; dac = new RtAudio(0, 1, 0, 1, format, (int)Stk::sampleRate(), &bufferSize, 0); dac->setStreamCallback(&tick_c, (void *)chorus); dac->startStream(); char keyhit; std::cout << "\nPlaying ... press [ENTER] to quit.\n"; std::cin.get(keyhit); dac->cancelStreamCallback(); dac->closeStream(); delete dac; delete chorus; return 0; }