// ex10.cpp / Music 120 / Lecture 3 // "Pitch-shifts" realtime input and plays through realtime output, // stops when "Enter" is pressed. // // Mac OS X with StkX: // g++ -g -o ex10 ex10.cpp -framework StkX -D__STKX__ // // CCRMA Linux machines: // g++ -g -o ex10 ex10.cpp -I/usr/include/stk -lstk -lasound -ljack // // Usage: ./ex10 effect_mix shift_amount // Example: ./ex10 0.75 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 "PitShift.h" #include "RtAudio.h" #endif int tick_c(char *buffer, int bufferSize, void *dataPointer) { PitShift *pitshift = (PitShift *) dataPointer; StkFloat *samples = (StkFloat *) buffer; for ( int i=0; itick(*samples); return 0; } int main (int argc, char* const argv[]) { // Input arguments as pitch shifter parameters float effectMix = atof( argv[1] ); // Wet/dry ratio (0.0~1.0) float shift = atof( argv[2] ); // Amount of pitch shift Stk::setSampleRate( 44100.0 ); PitShift* pitshift = new PitShift(); // PitShift pitshift->setEffectMix( effectMix ); pitshift->setShift( shift ); RtAudio* dac; 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 *)pitshift); dac->startStream(); char keyhit; std::cout << "\nPlaying ... press [ENTER] to quit.\n"; std::cin.get(keyhit); dac->cancelStreamCallback(); dac->closeStream(); delete dac; delete pitshift; return 0; }