mirror of
https://github.com/thestk/stk
synced 2026-04-21 15:06:55 +00:00
Version 4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
3f126af4e5
commit
81475b04c5
@@ -1,8 +1,8 @@
|
||||
/************** Effects Program *********************/
|
||||
|
||||
#include "RtDuplex.h"
|
||||
#include "SKINI11.h"
|
||||
#include "SKINI11.msg"
|
||||
#include "SKINI.h"
|
||||
#include "SKINI.msg"
|
||||
#include "Envelope.h"
|
||||
#include "PRCRev.h"
|
||||
#include "JCRev.h"
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "Chorus.h"
|
||||
|
||||
// The input control handler.
|
||||
#include "Controller.h"
|
||||
#include "Messager.h"
|
||||
|
||||
void usage(void) {
|
||||
/* Error function in case of incorrect command-line argument specifications */
|
||||
@@ -25,17 +25,9 @@ void usage(void) {
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
MY_FLOAT inSample = 0.0;
|
||||
MY_FLOAT lastSample = 0.0;
|
||||
MY_FLOAT byte2, byte3;
|
||||
long i, nTicks;
|
||||
int type, effect = 0;
|
||||
int controlMask = 0;
|
||||
bool done;
|
||||
Controller *controller;
|
||||
|
||||
if (argc != 2) usage();
|
||||
|
||||
int controlMask = 0;
|
||||
if (!strcmp(argv[1],"-is") )
|
||||
controlMask |= STK_SOCKET;
|
||||
else if (!strcmp(argv[1],"-ip") )
|
||||
@@ -43,36 +35,51 @@ int main(int argc,char *argv[])
|
||||
else
|
||||
usage();
|
||||
|
||||
// If you want to change the default sample rate (set in Stk.h), do
|
||||
// it before instantiating any objects!!
|
||||
Stk::setSampleRate(22050.0);
|
||||
|
||||
bool done;
|
||||
int effect = 0;
|
||||
MY_FLOAT lastSample, inSample;
|
||||
Envelope *envelope = new Envelope;
|
||||
PRCRev *prcrev = new PRCRev(2.0);
|
||||
JCRev *jcrev = new JCRev(2.0);
|
||||
NRev *nrev = new NRev(2.0);
|
||||
Echo *echo = new Echo(SRATE); // one second delay
|
||||
Echo *echo = new Echo( (long) Stk::sampleRate() ); // one second delay
|
||||
PitShift *shifter = new PitShift();
|
||||
Chorus *chorus = new Chorus(5000.0);
|
||||
SKINI11 *score = new SKINI11();
|
||||
RtDuplex *inout;
|
||||
SKINI *score = new SKINI();
|
||||
Messager *messager = 0;
|
||||
RtDuplex *inout = 0;
|
||||
|
||||
try {
|
||||
inout = new RtDuplex(1, SRATE);
|
||||
// Change the nBuffers parameter to a smaller number to get better input/output latency.
|
||||
inout = new RtDuplex(1, Stk::sampleRate(), 0, RT_BUFFER_SIZE, 10);
|
||||
|
||||
// Instantiate the input message controller.
|
||||
controller = new Controller( controlMask );
|
||||
messager = new Messager( controlMask );
|
||||
}
|
||||
catch (StkError& m) {
|
||||
m.printMessage();
|
||||
exit(0);
|
||||
catch (StkError &) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// The runtime loop begins here:
|
||||
long i, nTicks;
|
||||
int type;
|
||||
lastSample = 0.0;
|
||||
inSample = 0.0;
|
||||
MY_FLOAT byte2, byte3;
|
||||
done = FALSE;
|
||||
while (!done) {
|
||||
|
||||
nTicks = controller->getNextMessage();
|
||||
|
||||
if (nTicks == -1)
|
||||
// Look for new messages and return a delta time (in samples).
|
||||
type = messager->nextMessage();
|
||||
if (type < 0)
|
||||
done = TRUE;
|
||||
|
||||
nTicks = messager->getDelta();
|
||||
|
||||
for (i=0; i<nTicks; i++) {
|
||||
if (effect == 0)
|
||||
inSample = inout->tick(envelope->tick() * echo->tick(lastSample));
|
||||
@@ -89,12 +96,11 @@ int main(int argc,char *argv[])
|
||||
lastSample = inSample;
|
||||
}
|
||||
|
||||
type = controller->getType();
|
||||
if (type > 0) {
|
||||
// parse the input control message
|
||||
|
||||
byte2 = controller->getByte2();
|
||||
byte3 = controller->getByte3();
|
||||
byte2 = messager->getByteTwo();
|
||||
byte3 = messager->getByteThree();
|
||||
|
||||
switch(type) {
|
||||
|
||||
@@ -117,20 +123,20 @@ int main(int argc,char *argv[])
|
||||
case __SK_ControlChange_:
|
||||
if (byte2 == 20) effect = (int) byte3; // effect change
|
||||
else if (byte2 == 44) { // effects mix
|
||||
echo->setEffectMix(byte3*NORM_7);
|
||||
shifter->setEffectMix(byte3*NORM_7);
|
||||
chorus->setEffectMix(byte3*NORM_7);
|
||||
prcrev->setEffectMix(byte3*NORM_7);
|
||||
jcrev->setEffectMix(byte3*NORM_7);
|
||||
nrev->setEffectMix(byte3*NORM_7);
|
||||
echo->setEffectMix(byte3*ONE_OVER_128);
|
||||
shifter->setEffectMix(byte3*ONE_OVER_128);
|
||||
chorus->setEffectMix(byte3*ONE_OVER_128);
|
||||
prcrev->setEffectMix(byte3*ONE_OVER_128);
|
||||
jcrev->setEffectMix(byte3*ONE_OVER_128);
|
||||
nrev->setEffectMix(byte3*ONE_OVER_128);
|
||||
}
|
||||
else if (byte2 == 22) { // effect1 parameter change
|
||||
echo->setDelay(byte3*NORM_7*SRATE*0.95 + 2);
|
||||
shifter->setShift(byte3*NORM_7*3 + 0.25);
|
||||
chorus->setModFreq(byte3*NORM_7);
|
||||
echo->setDelay(byte3*ONE_OVER_128*Stk::sampleRate()*0.95);
|
||||
shifter->setShift(byte3*ONE_OVER_128*3 + 0.25);
|
||||
chorus->setModFrequency(byte3*ONE_OVER_128);
|
||||
}
|
||||
else if (byte2 == 23) { // effect1 parameter change
|
||||
chorus->setModDepth(byte3*NORM_7*0.2);
|
||||
chorus->setModDepth(byte3*ONE_OVER_128*0.2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -139,7 +145,8 @@ int main(int argc,char *argv[])
|
||||
|
||||
envelope->setRate(0.001);
|
||||
envelope->setTarget(0.0);
|
||||
for (i=0;i<SRATE;i++) { /* let the sound settle a bit */
|
||||
nTicks = (long) Stk::sampleRate();
|
||||
for (i=0; i<nTicks; i++) { // let the sound settle a bit
|
||||
if (effect == 0)
|
||||
inSample = inout->tick(envelope->tick() * echo->tick(lastSample));
|
||||
else if (effect == 1)
|
||||
@@ -155,7 +162,6 @@ int main(int argc,char *argv[])
|
||||
lastSample = inSample;
|
||||
}
|
||||
|
||||
delete inout;
|
||||
delete echo;
|
||||
delete shifter;
|
||||
delete chorus;
|
||||
@@ -164,7 +170,10 @@ int main(int argc,char *argv[])
|
||||
delete nrev;
|
||||
delete score;
|
||||
delete envelope;
|
||||
delete controller;
|
||||
|
||||
cleanup:
|
||||
delete messager;
|
||||
delete inout;
|
||||
|
||||
printf("effects finished ... goodbye.\n");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user