mirror of
https://github.com/thestk/stk
synced 2026-01-19 23:51:51 +00:00
Version 3.0
This commit is contained in:
committed by
Stephen Sinclair
parent
7c0ee03d60
commit
868787a5f9
125
effects/Chorus.cpp
Normal file
125
effects/Chorus.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
/******************************************/
|
||||
/* Chorus Effect Applied to Soundfile */
|
||||
/* by Perry Cook, 1996 */
|
||||
/******************************************/
|
||||
|
||||
#include "Chorus.h"
|
||||
|
||||
Chorus :: Chorus(MY_FLOAT baseDelay)
|
||||
{
|
||||
delayLine[0] = new DLineL((long) (baseDelay * 1.414) + 2);
|
||||
delayLine[1] = new DLineL((long) (baseDelay) + 2);
|
||||
delayLine[0]->setDelay(baseDelay);
|
||||
delayLine[1]->setDelay(baseDelay);
|
||||
baseLength = baseDelay;
|
||||
|
||||
// Concatenate the STK RAWWAVE_PATH to the rawwave file
|
||||
char temp[128];
|
||||
strcpy(temp, RAWWAVE_PATH);
|
||||
mods[0] = new RawWvIn(strcat(temp,"rawwaves/sinewave.raw"),"looping");
|
||||
strcpy(temp, RAWWAVE_PATH);
|
||||
mods[1] = new RawWvIn(strcat(temp,"rawwaves/sinewave.raw"),"looping");
|
||||
mods[0]->normalize();
|
||||
mods[1]->normalize();
|
||||
mods[0]->setFreq(0.2);
|
||||
mods[1]->setFreq(0.222222);
|
||||
modDepth = 0.05;
|
||||
effectMix = (MY_FLOAT) 0.5;
|
||||
this->clear();
|
||||
}
|
||||
|
||||
Chorus :: ~Chorus()
|
||||
{
|
||||
delete delayLine[0];
|
||||
delete delayLine[1];
|
||||
delete mods[0];
|
||||
delete mods[1];
|
||||
}
|
||||
|
||||
void Chorus :: clear()
|
||||
{
|
||||
delayLine[0]->clear();
|
||||
delayLine[1]->clear();
|
||||
lastOutL = (MY_FLOAT) 0.0;
|
||||
lastOutR = (MY_FLOAT) 0.0;
|
||||
}
|
||||
|
||||
void Chorus :: setEffectMix(MY_FLOAT mix)
|
||||
{
|
||||
effectMix = mix;
|
||||
}
|
||||
|
||||
void Chorus :: setModDepth(MY_FLOAT depth)
|
||||
{
|
||||
modDepth = depth;
|
||||
}
|
||||
|
||||
void Chorus :: setModFreq(MY_FLOAT freq)
|
||||
{
|
||||
mods[0]->setFreq(freq);
|
||||
mods[1]->setFreq(freq*1.1111);
|
||||
}
|
||||
|
||||
MY_FLOAT Chorus :: lastOutput()
|
||||
{
|
||||
return (lastOutL + lastOutR) * (MY_FLOAT) 0.5;
|
||||
}
|
||||
|
||||
MY_FLOAT Chorus :: lastOutputL()
|
||||
{
|
||||
return lastOutL;
|
||||
}
|
||||
|
||||
MY_FLOAT Chorus :: lastOutputR()
|
||||
{
|
||||
return lastOutR;
|
||||
}
|
||||
|
||||
MY_FLOAT Chorus :: tick(MY_FLOAT input)
|
||||
{
|
||||
delayLine[0]->setDelay(baseLength * 0.707 * (1.0 + mods[0]->tick()));
|
||||
delayLine[1]->setDelay(baseLength * 0.5 * (1.0 - mods[1]->tick()));
|
||||
lastOutL = input * (1.0 - effectMix);
|
||||
lastOutL += effectMix * delayLine[0]->tick(input);
|
||||
lastOutR = input * (1.0 - effectMix);
|
||||
lastOutR += effectMix * delayLine[1]->tick(input);
|
||||
return (lastOutL + lastOutR) * (MY_FLOAT) 0.5;
|
||||
}
|
||||
|
||||
/************** Test Main Program *********************/
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *soundIn,*soundOut;
|
||||
short data;
|
||||
float efMix,maxDel;
|
||||
Chorus *effect;
|
||||
|
||||
if (argc==5) {
|
||||
soundIn = fopen(argv[3],"rb");
|
||||
soundOut = fopen(argv[4],"wb");
|
||||
if (soundIn && soundOut) {
|
||||
efMix = atof(argv[1]);
|
||||
maxDel = atof(argv[2]);
|
||||
effect = new Chorus(maxDel);
|
||||
effect->setEffectMix(efMix);
|
||||
while (fread(&data,2,1,soundIn)) {
|
||||
data = effect->tick(data);
|
||||
fwrite(&data,2,1,soundOut);
|
||||
}
|
||||
delete effect;
|
||||
fclose(soundIn);
|
||||
fclose(soundOut);
|
||||
}
|
||||
else {
|
||||
printf("Can't open one of the files\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("useage: Chorus mix maxDelay soundIn.snd soundOut.snd\n");
|
||||
printf("0.0 <= mix <= 1.0\n");
|
||||
printf("maxDelay is in samples\n");
|
||||
printf("soundfiles are 16 bit linear mono or stereo\n");
|
||||
}
|
||||
}
|
||||
*/
|
||||
37
effects/Chorus.h
Normal file
37
effects/Chorus.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/******************************************/
|
||||
/* Chorus Effect */
|
||||
/* by Perry Cook, 1996 */
|
||||
/******************************************/
|
||||
|
||||
#if !defined(__Chorus_h)
|
||||
#define __Chorus_h
|
||||
|
||||
#include "../STK/Object.h"
|
||||
#include "../STK/DLineL.h"
|
||||
#include "../STK/RawWvIn.h"
|
||||
|
||||
class Chorus : public Object
|
||||
{
|
||||
protected:
|
||||
DLineL *delayLine[2];
|
||||
RawWvIn *mods[2];
|
||||
MY_FLOAT baseLength;
|
||||
MY_FLOAT modDepth;
|
||||
MY_FLOAT lastOutL;
|
||||
MY_FLOAT lastOutR;
|
||||
MY_FLOAT effectMix;
|
||||
public:
|
||||
Chorus(MY_FLOAT baseDelay);
|
||||
~Chorus();
|
||||
void clear();
|
||||
void setModDepth(MY_FLOAT depth);
|
||||
void setModFreq(MY_FLOAT freq);
|
||||
void setEffectMix(MY_FLOAT mix);
|
||||
MY_FLOAT lastOutput();
|
||||
MY_FLOAT lastOutputL();
|
||||
MY_FLOAT lastOutputR();
|
||||
MY_FLOAT tick(MY_FLOAT input);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
0
effects/Debug/.placeholder
Normal file
0
effects/Debug/.placeholder
Normal file
44
effects/Echo.cpp
Normal file
44
effects/Echo.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/******************************************/
|
||||
/* Echo Effect */
|
||||
/* by Perry Cook, 1996 */
|
||||
/******************************************/
|
||||
|
||||
#include "Echo.h"
|
||||
|
||||
Echo :: Echo(MY_FLOAT longestDelay)
|
||||
{
|
||||
length = (long) longestDelay + 2;
|
||||
delayLine = new DLineN(length);
|
||||
effectMix = 0.5;
|
||||
this->clear();
|
||||
this->setDelay(longestDelay);
|
||||
}
|
||||
|
||||
Echo :: ~Echo()
|
||||
{
|
||||
delete delayLine;
|
||||
}
|
||||
|
||||
void Echo :: clear()
|
||||
{
|
||||
delayLine->clear();
|
||||
lastOut = 0.0;
|
||||
}
|
||||
|
||||
void Echo :: setDelay(MY_FLOAT delay)
|
||||
{
|
||||
delayLine->setDelay(delay);
|
||||
}
|
||||
|
||||
void Echo :: setEffectMix(MY_FLOAT mix)
|
||||
{
|
||||
effectMix = mix;
|
||||
}
|
||||
|
||||
MY_FLOAT Echo :: tick(MY_FLOAT input)
|
||||
{
|
||||
lastOut = effectMix * delayLine->tick(input);
|
||||
lastOut += input * (1.0 - effectMix);
|
||||
return lastOut;
|
||||
}
|
||||
|
||||
30
effects/Echo.h
Normal file
30
effects/Echo.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/******************************************/
|
||||
/* Echo Effect Applied to Soundfile */
|
||||
/* by Perry Cook, 1996 */
|
||||
/******************************************/
|
||||
|
||||
#if !defined(__Echo_h)
|
||||
#define __Echo_h
|
||||
|
||||
#include "../STK/Object.h"
|
||||
#include "../STK/DLineN.h"
|
||||
|
||||
class Echo : public Object
|
||||
{
|
||||
protected:
|
||||
DLineN *delayLine;
|
||||
long length;
|
||||
MY_FLOAT lastOut;
|
||||
MY_FLOAT effectMix;
|
||||
public:
|
||||
Echo(MY_FLOAT longestDelay);
|
||||
~Echo();
|
||||
void clear();
|
||||
void setDelay(MY_FLOAT delay);
|
||||
void setEffectMix(MY_FLOAT mix);
|
||||
MY_FLOAT lastOutput();
|
||||
MY_FLOAT tick(MY_FLOAT input);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1
effects/GUIeffects
Executable file
1
effects/GUIeffects
Executable file
@@ -0,0 +1 @@
|
||||
wish < tcl/Effects.tcl | effects -ip
|
||||
60
effects/Makefile
Normal file
60
effects/Makefile
Normal file
@@ -0,0 +1,60 @@
|
||||
# Effects Makefile
|
||||
|
||||
OS = $(shell uname)
|
||||
|
||||
# The following definition indicates the relative location of
|
||||
# the core STK classes.
|
||||
STK_PATH = ../STK/
|
||||
|
||||
O_FILES = Object.o Reverb.o PRCRev.o JCRev.o \
|
||||
NRev.o RTSoundIO.o DLineN.o Filter.o \
|
||||
RTDuplex.o SKINI11.o Envelope.o Echo.o \
|
||||
PitShift.o DLineL.o Chorus.o RawWvIn.o \
|
||||
WvIn.o swapstuf.o threads.o
|
||||
|
||||
|
||||
RM = /bin/rm
|
||||
|
||||
ifeq ($(OS),IRIX) # These are for SGI
|
||||
INSTR = effects
|
||||
CC = CC -O2 -D__OS_IRIX_ # -g -fullwarn -D__SGI_CC__
|
||||
LIBRARY = -L/usr/sgitcl/lib -laudio -lmd -lm
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Linux) # These are for Linux
|
||||
INSTR = effects
|
||||
CC = g++ -O3 -D__OS_Linux_ # -g
|
||||
LIBRARY = -lpthread -lm
|
||||
endif
|
||||
|
||||
%.o : $(STK_PATH)%.cpp
|
||||
$(CC) -c $(<) -o $@
|
||||
|
||||
all: $(INSTR)
|
||||
|
||||
clean :
|
||||
rm *.o
|
||||
rm $(INSTR)
|
||||
|
||||
cleanIns :
|
||||
rm $(INSTR)
|
||||
|
||||
strip :
|
||||
strip $(INSTR)
|
||||
|
||||
effects: effects.cpp $(O_FILES)
|
||||
$(CC) -O3 -o effects effects.cpp $(O_FILES) $(LIBRARY)
|
||||
|
||||
# $(O_FILES) :
|
||||
|
||||
threads.o: threads.cpp
|
||||
$(CC) -c threads.cpp
|
||||
|
||||
Echo.o: Echo.cpp
|
||||
$(CC) -c Echo.cpp
|
||||
|
||||
PitShift.o: PitShift.cpp
|
||||
$(CC) -c PitShift.cpp
|
||||
|
||||
Chorus.o: Chorus.cpp
|
||||
$(CC) -c Chorus.cpp
|
||||
106
effects/PitShift.cpp
Normal file
106
effects/PitShift.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*********************************************/
|
||||
/* PitchShift Effect */
|
||||
/* by Perry Cook, 1996 */
|
||||
/*********************************************/
|
||||
|
||||
#include "PitShift.h"
|
||||
|
||||
PitShift :: PitShift()
|
||||
{
|
||||
delayLine[0] = new DLineL((long) 1024);
|
||||
delayLine[1] = new DLineL((long) 1024);
|
||||
delay[0] = 12;
|
||||
delay[1] = 512;
|
||||
delayLine[0]->setDelay(delay[0]);
|
||||
delayLine[1]->setDelay(delay[1]);
|
||||
effectMix = (MY_FLOAT) 0.5;
|
||||
rate = 1.0;
|
||||
}
|
||||
|
||||
PitShift :: ~PitShift()
|
||||
{
|
||||
delete delayLine[0];
|
||||
delete delayLine[1];
|
||||
}
|
||||
|
||||
void PitShift :: setEffectMix(MY_FLOAT mix)
|
||||
{
|
||||
effectMix = mix;
|
||||
}
|
||||
|
||||
void PitShift :: setShift(MY_FLOAT shift)
|
||||
{
|
||||
if (shift < 1.0) {
|
||||
rate = 1.0 - shift;
|
||||
}
|
||||
else if (shift > 1.0) {
|
||||
rate = 1.0 - shift;
|
||||
}
|
||||
else {
|
||||
rate = 0.0;
|
||||
delay[0] = 512;
|
||||
}
|
||||
}
|
||||
|
||||
MY_FLOAT PitShift :: lastOutput()
|
||||
{
|
||||
return lastOut;
|
||||
}
|
||||
|
||||
MY_FLOAT PitShift :: tick(MY_FLOAT input)
|
||||
{
|
||||
delay[0] = delay[0] + rate;
|
||||
while (delay[0] > 1012) delay[0] -= 1000;
|
||||
while (delay[0] < 12) delay[0] += 1000;
|
||||
delay[1] = delay[0] + 500;
|
||||
while (delay[1] > 1012) delay[1] -= 1000;
|
||||
while (delay[1] < 12) delay[1] += 1000;
|
||||
delayLine[0]->setDelay(delay[0]);
|
||||
delayLine[1]->setDelay(delay[1]);
|
||||
env[1] = fabs(delay[0] - 512) * 0.002;
|
||||
env[0] = 1.0 - env[1];
|
||||
lastOut = env[0] * delayLine[0]->tick(input);
|
||||
lastOut += env[1] * delayLine[1]->tick(input);
|
||||
lastOut *= effectMix;
|
||||
lastOut += (1.0 - effectMix) * input;
|
||||
return lastOut;
|
||||
}
|
||||
|
||||
/************** Test Main Program *********************/
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *soundIn,*soundOut;
|
||||
short data;
|
||||
float efMix,pitchshift;
|
||||
PitShift *effect;
|
||||
|
||||
if (argc==5) {
|
||||
soundIn = fopen(argv[3],"rb");
|
||||
soundOut = fopen(argv[4],"wb");
|
||||
if (soundIn && soundOut) {
|
||||
efMix = atof(argv[1]);
|
||||
pitchshift = atof(argv[2]);
|
||||
effect = new PitShift();
|
||||
effect->setShift(pitchshift);
|
||||
effect->setEffectMix(efMix);
|
||||
while (fread(&data,2,1,soundIn)) {
|
||||
data = effect->tick(data);
|
||||
fwrite(&data,2,1,soundOut);
|
||||
}
|
||||
delete effect;
|
||||
fclose(soundIn);
|
||||
fclose(soundOut);
|
||||
}
|
||||
else {
|
||||
printf("Can't open one of the files\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("useage: pitshift mix shiftRate soundIn.snd soundOut.snd\n");
|
||||
printf("0.0 <= mix <= 1.0\n");
|
||||
printf("maxDelay is in samples\n");
|
||||
printf("soundfiles are 16 bit linear mono or stereo\n");
|
||||
}
|
||||
}
|
||||
*/
|
||||
32
effects/PitShift.h
Normal file
32
effects/PitShift.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*********************************************/
|
||||
/* PitchShift Effect */
|
||||
/* by Perry Cook, 1996 */
|
||||
/*********************************************/
|
||||
|
||||
#if !defined(__PitShift_h)
|
||||
#define __PitShift_h
|
||||
|
||||
#include "../STK/Object.h"
|
||||
#include "../STK/DLineL.h"
|
||||
|
||||
class PitShift : public Object
|
||||
{
|
||||
protected:
|
||||
DLineL *delayLine[2];
|
||||
MY_FLOAT lastOut;
|
||||
MY_FLOAT delay[2];
|
||||
MY_FLOAT env[2];
|
||||
MY_FLOAT effectMix;
|
||||
MY_FLOAT rate;
|
||||
public:
|
||||
PitShift();
|
||||
~PitShift();
|
||||
void clear();
|
||||
void setShift(MY_FLOAT shift);
|
||||
void setEffectMix(MY_FLOAT mix);
|
||||
virtual MY_FLOAT lastOutput();
|
||||
MY_FLOAT tick(MY_FLOAT input);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
16
effects/README-effects.txt
Normal file
16
effects/README-effects.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
STK: A ToolKit of Audio Synthesis Classes and Instruments in C++
|
||||
Version 3.0
|
||||
|
||||
By Perry R. Cook, 1995-99
|
||||
and Gary P. Scavone, 1997-99.
|
||||
|
||||
|
||||
EFFECTS PROJECT:
|
||||
|
||||
This directory contains a program that demonstrates realtime duplex mode (simultaneous audio input and output) operation, as well as several simple delay-line based effects algorithms. Proper duplex mode operation is very hardware dependent. If you have trouble with this application, make sure your soundcard supports the desired sample rates and sample sizes. Under Linux, also make sure that your soundcard is supported by OSS (http://www.opensound.com/).
|
||||
|
||||
NOTES:
|
||||
|
||||
1. This project will not run under WindowsNT or NeXTStep, due to lack of realtime audio input support.
|
||||
|
||||
2. Audio input from either a microphone or line-input device MUST be available to the audio input port when the program is started.
|
||||
0
effects/Release/.placeholder
Normal file
0
effects/Release/.placeholder
Normal file
159
effects/effects.cpp
Normal file
159
effects/effects.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
/************** Test Effects Program *********************/
|
||||
|
||||
#include "../STK/RTSoundIO.h"
|
||||
#include "../STK/RTDuplex.h"
|
||||
#include "../STK/SKINI11.h"
|
||||
#include "../STK/SKINI11.msg"
|
||||
#include "../STK/Envelope.h"
|
||||
#include "../STK/PRCRev.h"
|
||||
#include "../STK/JCRev.h"
|
||||
#include "../STK/NRev.h"
|
||||
#include "Echo.h"
|
||||
#include "PitShift.h"
|
||||
#include "Chorus.h"
|
||||
|
||||
// The input command pipe and socket threads are defined in threads.cpp.
|
||||
#include "threads.h"
|
||||
|
||||
int numStrings = 0;
|
||||
int notDone = 1;
|
||||
char **inputString;
|
||||
|
||||
void errorfun(void) {
|
||||
/* Error function in case of incorrect command-line argument specifications */
|
||||
printf("\nuseage: effects flag \n");
|
||||
printf(" where flag = -ip for realtime SKINI input by pipe\n");
|
||||
printf(" (won't work under Win95/98),\n");
|
||||
printf(" and flag = -is for realtime SKINI input by socket.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void main(int argc,char *argv[])
|
||||
{
|
||||
MY_FLOAT inSample = 0.0;
|
||||
MY_FLOAT lastSample = 0.0;
|
||||
MY_FLOAT byte3;
|
||||
long i, synlength;
|
||||
int type, j, outOne = 0, effect = 0, useSocket = 0;
|
||||
|
||||
if (argc != 2) errorfun();
|
||||
|
||||
if (!strcmp(argv[1],"-is") )
|
||||
useSocket = 1;
|
||||
else if (strcmp(argv[1],"-ip")) {
|
||||
errorfun();
|
||||
}
|
||||
|
||||
RTDuplex *inout = new RTDuplex(SRATE,1);
|
||||
Echo *echo = new Echo(SRATE); // one second delay
|
||||
PitShift *shifter = new PitShift();
|
||||
Chorus *chorus = new Chorus(5000.0);
|
||||
PRCRev *prcrev = new PRCRev(2.0);
|
||||
JCRev *jcrev = new JCRev(2.0);
|
||||
NRev *nrev = new NRev(2.0);
|
||||
SKINI11 *score = new SKINI11();
|
||||
Envelope *envelope = new Envelope;
|
||||
|
||||
// Start the input thread
|
||||
if (useSocket)
|
||||
startSocketThread();
|
||||
else
|
||||
startPipeThread();
|
||||
|
||||
/* Finally ... the runtime loop begins! */
|
||||
notDone = 1;
|
||||
synlength = RT_BUFFER_SIZE;
|
||||
while(notDone || numStrings) {
|
||||
if (numStrings > 1) synlength = (long) RT_BUFFER_SIZE / numStrings;
|
||||
else synlength = RT_BUFFER_SIZE;
|
||||
for ( i=0; i<synlength; i++ ) {
|
||||
if (effect == 0)
|
||||
inSample = inout->tick(envelope->tick() * echo->tick(lastSample));
|
||||
else if (effect == 1)
|
||||
inSample = inout->tick(envelope->tick() * shifter->tick(lastSample));
|
||||
else if (effect == 2)
|
||||
inSample = inout->tick(envelope->tick() * chorus->tick(lastSample));
|
||||
else if (effect == 3)
|
||||
inSample = inout->tick(envelope->tick() * prcrev->tick(lastSample));
|
||||
else if (effect == 4)
|
||||
inSample = inout->tick(envelope->tick() * jcrev->tick(lastSample));
|
||||
else if (effect == 5)
|
||||
inSample = inout->tick(envelope->tick() * nrev->tick(lastSample));
|
||||
lastSample = inSample;
|
||||
}
|
||||
if (numStrings) {
|
||||
score->parseThis(inputString[outOne]);
|
||||
type = score->getType();
|
||||
if (type > 0) {
|
||||
if (type == __SK_NoteOn_ ) {
|
||||
if (( byte3 = score->getByteThree() ) == 0) { // NoteOff
|
||||
envelope->setRate(0.001);
|
||||
envelope->setTarget(0.0);
|
||||
}
|
||||
else { // Really a NoteOn
|
||||
envelope->setRate(0.001);
|
||||
envelope->setTarget(1.0);
|
||||
}
|
||||
}
|
||||
else if (type == __SK_NoteOff_) {
|
||||
envelope->setRate(0.001);
|
||||
envelope->setTarget(0.0);
|
||||
}
|
||||
else if (type == __SK_ControlChange_) {
|
||||
j = (int) score->getByteTwo();
|
||||
byte3 = score->getByteThree();
|
||||
if (j == 20) effect = (int) byte3; // effect change
|
||||
else if (j == 21) { // 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);
|
||||
}
|
||||
else if (j == 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);
|
||||
}
|
||||
else if (j == 23) { // effect1 parameter change
|
||||
chorus->setModDepth(byte3*NORM_7*0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
outOne += 1;
|
||||
if (outOne == MAX_IN_STRINGS) outOne = 0;
|
||||
numStrings--;
|
||||
}
|
||||
}
|
||||
|
||||
envelope->setRate(0.001);
|
||||
envelope->setTarget(0.0);
|
||||
for (i=0;i<SRATE;i++) { /* let the sound settle a bit */
|
||||
if (effect == 0)
|
||||
inSample = inout->tick(envelope->tick() * echo->tick(lastSample));
|
||||
else if (effect == 1)
|
||||
inSample = inout->tick(envelope->tick() * shifter->tick(lastSample));
|
||||
else if (effect == 2)
|
||||
inSample = inout->tick(envelope->tick() * chorus->tick(lastSample));
|
||||
else if (effect == 3)
|
||||
inSample = inout->tick(envelope->tick() * prcrev->tick(lastSample));
|
||||
else if (effect == 4)
|
||||
inSample = inout->tick(envelope->tick() * jcrev->tick(lastSample));
|
||||
else if (effect == 5)
|
||||
inSample = inout->tick(envelope->tick() * nrev->tick(lastSample));
|
||||
lastSample = inSample;
|
||||
}
|
||||
|
||||
delete inout;
|
||||
delete echo;
|
||||
delete shifter;
|
||||
delete chorus;
|
||||
delete prcrev;
|
||||
delete jcrev;
|
||||
delete nrev;
|
||||
delete score;
|
||||
delete envelope;
|
||||
|
||||
printf("effects finished ... goodbye.\n");
|
||||
}
|
||||
243
effects/effects.dsp
Normal file
243
effects/effects.dsp
Normal file
@@ -0,0 +1,243 @@
|
||||
# Microsoft Developer Studio Project File - Name="effects" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=effects - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "effects.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "effects.mak" CFG="effects - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "effects - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "effects - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "effects - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir ""
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__OS_Win_" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib dsound.lib /nologo /subsystem:console /machine:I386
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "effects - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir ""
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__OS_Win_" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "effects - Win32 Release"
|
||||
# Name "effects - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Chorus.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Chorus.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\DLineL.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\DLineL.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\DLineN.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\DLineN.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Echo.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Echo.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\effects.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Envelope.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Envelope.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Filter.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Filter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\JCRev.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\JCRev.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\NRev.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\NRev.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Object.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Object.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PitShift.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PitShift.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\PRCRev.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\PRCRev.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RawWvIn.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RawWvIn.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Reverb.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\Reverb.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RTDuplex.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RTDuplex.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RTSoundIO.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\RTSoundIO.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\SKINI11.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\SKINI11.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\swapstuf.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\swapstuf.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\threads.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\threads.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\WvIn.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Stk\WvIn.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
effects/effects.dsw
Normal file
29
effects/effects.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 5.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "effects"=.\effects.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
BIN
effects/effects.opt
Normal file
BIN
effects/effects.opt
Normal file
Binary file not shown.
80
effects/effects.plg
Normal file
80
effects/effects.plg
Normal file
@@ -0,0 +1,80 @@
|
||||
--------------------Configuration: effects - Win32 Release--------------------
|
||||
Begining build with project "D:\gary\stk\effects\effects.dsp", at root.
|
||||
Active configuration is Win32 (x86) Console Application (based on Win32 (x86) Console Application)
|
||||
|
||||
Project's tools are:
|
||||
"32-bit C/C++ Compiler for 80x86" with flags "/nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__OS_Win_" /Fp"Release/effects.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c "
|
||||
"Win32 Resource Compiler" with flags "/l 0x409 /d "NDEBUG" "
|
||||
"Browser Database Maker" with flags "/nologo /o"effects.bsc" "
|
||||
"COFF Linker for 80x86" with flags "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib dsound.lib /nologo /subsystem:console /incremental:no /pdb:"effects.pdb" /machine:I386 /out:"effects.exe" "
|
||||
"Custom Build" with flags ""
|
||||
"<Component 0xa>" with flags ""
|
||||
|
||||
Creating temp file "C:\WINDOWS\TEMP\RSP1050.TMP" with contents </nologo /MT /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__OS_Win_" /Fp"Release/effects.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
|
||||
"D:\gary\stk\effects\Chorus.cpp"
|
||||
"D:\gary\stk\Stk\DLineL.cpp"
|
||||
"D:\gary\stk\Stk\DLineN.cpp"
|
||||
"D:\gary\stk\effects\Echo.cpp"
|
||||
"D:\gary\stk\effects\effects.cpp"
|
||||
"D:\gary\stk\Stk\Envelope.cpp"
|
||||
"D:\gary\stk\Stk\Filter.cpp"
|
||||
"D:\gary\stk\Stk\JCRev.cpp"
|
||||
"D:\gary\stk\Stk\NRev.cpp"
|
||||
"D:\gary\stk\Stk\Object.cpp"
|
||||
"D:\gary\stk\effects\PitShift.cpp"
|
||||
"D:\gary\stk\Stk\PRCRev.cpp"
|
||||
"D:\gary\stk\Stk\RawWvIn.cpp"
|
||||
"D:\gary\stk\Stk\Reverb.cpp"
|
||||
"D:\gary\stk\Stk\RTDuplex.cpp"
|
||||
"D:\gary\stk\Stk\RTSoundIO.cpp"
|
||||
"D:\gary\stk\Stk\SKINI11.cpp"
|
||||
"D:\gary\stk\Stk\swapstuf.cpp"
|
||||
"D:\gary\stk\Stk\WvIn.cpp"
|
||||
>
|
||||
Creating command line "cl.exe @C:\WINDOWS\TEMP\RSP1050.TMP"
|
||||
Creating temp file "C:\WINDOWS\TEMP\RSP1051.TMP" with contents <kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib dsound.lib /nologo /subsystem:console /incremental:no /pdb:"effects.pdb" /machine:I386 /out:"effects.exe"
|
||||
.\Release\Chorus.obj
|
||||
.\Release\DLineL.obj
|
||||
.\Release\DLineN.obj
|
||||
.\Release\Echo.obj
|
||||
.\Release\effects.obj
|
||||
.\Release\Envelope.obj
|
||||
.\Release\Filter.obj
|
||||
.\Release\JCRev.obj
|
||||
.\Release\NRev.obj
|
||||
.\Release\Object.obj
|
||||
.\Release\PitShift.obj
|
||||
.\Release\PRCRev.obj
|
||||
.\Release\RawWvIn.obj
|
||||
.\Release\Reverb.obj
|
||||
.\Release\RTDuplex.obj
|
||||
.\Release\RTSoundIO.obj
|
||||
.\Release\SKINI11.obj
|
||||
.\Release\swapstuf.obj
|
||||
.\Release\WvIn.obj>
|
||||
Creating command line "link.exe @C:\WINDOWS\TEMP\RSP1051.TMP"
|
||||
Compiling...
|
||||
Chorus.cpp
|
||||
DLineL.cpp
|
||||
DLineN.cpp
|
||||
Echo.cpp
|
||||
effects.cpp
|
||||
Envelope.cpp
|
||||
Filter.cpp
|
||||
JCRev.cpp
|
||||
NRev.cpp
|
||||
Object.cpp
|
||||
PitShift.cpp
|
||||
PRCRev.cpp
|
||||
RawWvIn.cpp
|
||||
Reverb.cpp
|
||||
RTDuplex.cpp
|
||||
RTSoundIO.cpp
|
||||
SKINI11.cpp
|
||||
swapstuf.cpp
|
||||
WvIn.cpp
|
||||
Linking...
|
||||
|
||||
|
||||
|
||||
effects.exe - 0 error(s), 0 warning(s)
|
||||
219
effects/tcl/Effects.tcl
Normal file
219
effects/tcl/Effects.tcl
Normal file
@@ -0,0 +1,219 @@
|
||||
set mixlevel 64.0
|
||||
set effect1 64.0
|
||||
set effect2 64.0
|
||||
set effect 0
|
||||
set outID "stdout"
|
||||
set commtype "stdout"
|
||||
|
||||
# Configure main window
|
||||
wm title . "STK Effects Controller"
|
||||
wm iconname . "Effects"
|
||||
. config -bg black
|
||||
|
||||
# Configure "communications" menu
|
||||
menu .menu -tearoff 0
|
||||
menu .menu.communication -tearoff 0
|
||||
.menu add cascade -label "Communication" -menu .menu.communication \
|
||||
-underline 0
|
||||
.menu.communication add radio -label "Console" -variable commtype \
|
||||
-value "stdout" -command { setComm }
|
||||
.menu.communication add radio -label "Socket" -variable commtype \
|
||||
-value "socket" -command { setComm }
|
||||
. configure -menu .menu
|
||||
|
||||
# Configure title display
|
||||
label .title -text "STK Effects Controller" \
|
||||
-font {Times 14 bold} -background white \
|
||||
-foreground darkred -relief raised
|
||||
|
||||
label .title2 -text "by Gary P. Scavone\n Center for Computer Research in Music & Acoustics (CCRMA) \n Stanford University" \
|
||||
-font {Times 12 bold} -background white \
|
||||
-foreground darkred -relief raised
|
||||
|
||||
pack .title -padx 5 -pady 10
|
||||
pack .title2 -padx 5 -pady 10
|
||||
|
||||
# Configure "note-on" buttons
|
||||
frame .noteOn -bg black
|
||||
|
||||
button .noteOn.on -text NoteOn -bg grey66 -command { noteOn 64.0 64.0 }
|
||||
button .noteOn.off -text NoteOff -bg grey66 -command { noteOff 64.0 127.0 }
|
||||
button .noteOn.exit -text "Exit Program" -bg grey66 -command myExit
|
||||
pack .noteOn.on -side left -padx 5
|
||||
pack .noteOn.off -side left -padx 5 -pady 10
|
||||
pack .noteOn.exit -side left -padx 5 -pady 10
|
||||
|
||||
pack .noteOn
|
||||
|
||||
# Configure sliders
|
||||
frame .left -bg black
|
||||
|
||||
scale .left.effectsmix -from 0 -to 127 -length 400 \
|
||||
-command {printWhatz "ControlChange 0.0 1 " 21} \
|
||||
-orient horizontal -label "Effects Mix" \
|
||||
-tickinterval 32 -showvalue true -bg grey66 \
|
||||
-variable mixlevel
|
||||
|
||||
scale .left.effect1 -from 0 -to 127 -length 400 \
|
||||
-command {printWhatz "ControlChange 0.0 1 " 22} \
|
||||
-orient horizontal -label "Echo Delay" \
|
||||
-tickinterval 32 -showvalue true -bg grey66 \
|
||||
-variable effect1
|
||||
|
||||
scale .left.effect2 -from 0 -to 127 -length 400 \
|
||||
-command {printWhatz "ControlChange 0.0 1 " 23} \
|
||||
-orient horizontal -label "Disabled" \
|
||||
-tickinterval 32 -showvalue true -bg grey66 \
|
||||
-variable effect2
|
||||
|
||||
pack .left.effectsmix -padx 10 -pady 3
|
||||
pack .left.effect1 -padx 10 -pady 3
|
||||
pack .left.effect2 -padx 10 -pady 3
|
||||
|
||||
pack .left -side left
|
||||
|
||||
# Configure effect select buttons
|
||||
frame .effectSelect -bg black
|
||||
pack .effectSelect -side right -padx 5 -pady 5
|
||||
|
||||
radiobutton .effectSelect.echo -text "Echo" -variable effect -relief flat \
|
||||
-value 0 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
radiobutton .effectSelect.shifter -text "Pitch Shift" -variable effect -relief flat \
|
||||
-value 1 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
radiobutton .effectSelect.chorus -text "Chorus" -variable effect -relief flat \
|
||||
-value 2 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
radiobutton .effectSelect.prcrev -text "PRC Reverb" -variable effect -relief flat \
|
||||
-value 3 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
radiobutton .effectSelect.jcrev -text "JC Reverb" -variable effect -relief flat \
|
||||
-value 4 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
radiobutton .effectSelect.nrev -text "NRev Reverb" -variable effect -relief flat \
|
||||
-value 5 -command {changeEffect "ControlChange 0.0 1 " 20 $effect}
|
||||
|
||||
pack .effectSelect.echo -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
pack .effectSelect.shifter -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
pack .effectSelect.chorus -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
pack .effectSelect.prcrev -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
pack .effectSelect.jcrev -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
pack .effectSelect.nrev -pady 2 -padx 5 -side top -anchor w -fill x
|
||||
|
||||
|
||||
proc myExit {} {
|
||||
global outID
|
||||
puts $outID [format "NoteOff 0.0 1 64 127" ]
|
||||
flush $outID
|
||||
puts $outID [format "ExitProgram"]
|
||||
flush $outID
|
||||
close $outID
|
||||
exit
|
||||
}
|
||||
|
||||
proc noteOn {pitchVal pressVal} {
|
||||
global outID
|
||||
puts $outID [format "NoteOn 0.0 1 %f %f" $pitchVal $pressVal]
|
||||
flush $outID
|
||||
}
|
||||
|
||||
proc noteOff {pitchVal pressVal} {
|
||||
global outID
|
||||
puts $outID [format "NoteOff 0.0 1 %f %f" $pitchVal $pressVal]
|
||||
flush $outID
|
||||
}
|
||||
|
||||
proc printWhatz {tag value1 value2 } {
|
||||
global outID
|
||||
puts $outID [format "%s %i %f" $tag $value1 $value2]
|
||||
flush $outID
|
||||
}
|
||||
|
||||
proc changeEffect {tag value1 value2 } {
|
||||
global outID
|
||||
if ($value2==0) {
|
||||
.left.effect1 config -state normal -label "Echo Delay"
|
||||
.left.effect2 config -state disabled -label "Disabled"
|
||||
}
|
||||
if ($value2==1) {
|
||||
.left.effect1 config -state normal -label "Pitch Shift Amount"
|
||||
.left.effect2 config -state disabled -label "Disabled"
|
||||
}
|
||||
if ($value2==2) {
|
||||
.left.effect1 config -state normal -label "Chorus Modulation Frequency"
|
||||
.left.effect2 config -state normal -label "Chorus Modulation Depth"
|
||||
}
|
||||
if {$value2>=3 && $value2<=5} {
|
||||
.left.effect1 config -state disabled -label "Disabled"
|
||||
.left.effect2 config -state disabled -label "Disabled"
|
||||
}
|
||||
puts $outID [format "%s %i %f" $tag $value1 $value2]
|
||||
flush $outID
|
||||
}
|
||||
|
||||
# Bind an X windows "close" event with the Exit routine
|
||||
bind . <Destroy> +myExit
|
||||
|
||||
# Socket connection procedure
|
||||
set d .socketdialog
|
||||
|
||||
proc setComm {} {
|
||||
global outID
|
||||
global commtype
|
||||
global d
|
||||
if {$commtype == "stdout"} {
|
||||
if { [string compare "stdout" $outID] } {
|
||||
set i [tk_dialog .dialog "Break Socket Connection?" {You are about to break an existing socket connection ... is this what you want to do?} "" 0 Cancel OK]
|
||||
switch $i {
|
||||
0 {set commtype "socket"}
|
||||
1 {close $outID
|
||||
set outID "stdout"}
|
||||
}
|
||||
}
|
||||
} elseif { ![string compare "stdout" $outID] } {
|
||||
set sockport 2001
|
||||
set sockhost localhost
|
||||
toplevel $d
|
||||
wm title $d "STK Client Socket Connection"
|
||||
wm resizable $d 0 0
|
||||
grab $d
|
||||
label $d.message -text "Specify a socket host and port number below (if different than the STK defaults shown) and then click the \"Connect\" button to invoke a socket-client connection attempt to the STK socket server." \
|
||||
-background white -font {Helvetica 10 bold} \
|
||||
-wraplength 3i -justify left
|
||||
frame $d.sockhost
|
||||
entry $d.sockhost.entry -width 15
|
||||
label $d.sockhost.text -text "Socket Host:" \
|
||||
-font {Helvetica 10 bold}
|
||||
frame $d.sockport
|
||||
entry $d.sockport.entry -width 15
|
||||
label $d.sockport.text -text "Socket Port:" \
|
||||
-font {Helvetica 10 bold}
|
||||
pack $d.message -side top -padx 5 -pady 10
|
||||
pack $d.sockhost.text -side left -padx 1 -pady 2
|
||||
pack $d.sockhost.entry -side right -padx 5 -pady 2
|
||||
pack $d.sockhost -side top -padx 5 -pady 2
|
||||
pack $d.sockport.text -side left -padx 1 -pady 2
|
||||
pack $d.sockport.entry -side right -padx 5 -pady 2
|
||||
pack $d.sockport -side top -padx 5 -pady 2
|
||||
$d.sockhost.entry insert 0 $sockhost
|
||||
$d.sockport.entry insert 0 $sockport
|
||||
frame $d.buttons
|
||||
button $d.buttons.cancel -text "Cancel" -bg grey66 \
|
||||
-command { set commtype "stdout"
|
||||
set outID "stdout"
|
||||
destroy $d }
|
||||
button $d.buttons.connect -text "Connect" -bg grey66 \
|
||||
-command {
|
||||
set sockhost [$d.sockhost.entry get]
|
||||
set sockport [$d.sockport.entry get]
|
||||
set err [catch {socket $sockhost $sockport} outID]
|
||||
|
||||
if {$err == 0} {
|
||||
destroy $d
|
||||
} else {
|
||||
tk_dialog $d.error "Socket Error" {Error: Unable to make socket connection. Make sure the STK socket server is first running and that the port number is correct.} "" 0 OK
|
||||
} }
|
||||
pack $d.buttons.cancel -side left -padx 5 -pady 10
|
||||
pack $d.buttons.connect -side right -padx 5 -pady 10
|
||||
pack $d.buttons -side bottom -padx 5 -pady 10
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
282
effects/threads.cpp
Normal file
282
effects/threads.cpp
Normal file
@@ -0,0 +1,282 @@
|
||||
// Thread functions for use with syntmono.
|
||||
//
|
||||
// Gary P. Scavone, 1999.
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
#if defined(__STK_REALTIME_)
|
||||
|
||||
#define SERVICE_PORT 2001 // Socket Port ID number
|
||||
|
||||
// Do OS dependent declarations and includes
|
||||
#if defined(__OS_IRIX_)
|
||||
#include <signal.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t string_thread;
|
||||
|
||||
#elif defined(__OS_Linux_)
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pthread_t string_thread;
|
||||
|
||||
#elif defined(__OS_Win_)
|
||||
#include <process.h>
|
||||
#include <winsock.h>
|
||||
|
||||
unsigned long string_thread;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// The thread function definition protocols are slightly
|
||||
// different under Irix, Linux, and Windoze.
|
||||
#if defined(__OS_IRIX_)
|
||||
|
||||
void newStringByPipe(void *)
|
||||
|
||||
#elif defined(__OS_Linux_)
|
||||
|
||||
void *newStringByPipe(void *)
|
||||
|
||||
#elif defined(__OS_Win_)
|
||||
|
||||
void newStringByPipe(void *)
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
extern int numStrings, notDone;
|
||||
extern char **inputString;
|
||||
int i;
|
||||
|
||||
// Malloc inputString.
|
||||
inputString = (char **) malloc(MAX_IN_STRINGS * sizeof(char *));
|
||||
for ( i=0;i<MAX_IN_STRINGS;i++ )
|
||||
inputString[i] = (char *) malloc(STRING_LEN * sizeof(char));
|
||||
|
||||
int inOne = 0;
|
||||
while (notDone) {
|
||||
fgets(inputString[inOne],STRING_LEN,stdin);
|
||||
if (inputString[inOne][2] == 'i' && inputString[inOne][3] == 't'
|
||||
&& inputString[inOne][1] == 'x' && inputString[inOne][0] == 'E') {
|
||||
notDone = 0;
|
||||
}
|
||||
else {
|
||||
numStrings++;
|
||||
if (numStrings > MAX_IN_STRINGS) {
|
||||
fprintf(stderr,"Losing MIDI data ... try increasing MAX_IN_STRINGS.\n");
|
||||
numStrings--;
|
||||
}
|
||||
inOne++;
|
||||
if (inOne == MAX_IN_STRINGS) inOne = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Free inputString.
|
||||
for ( i=0;i<MAX_IN_STRINGS;i++ ) free(inputString[i]);
|
||||
free(inputString);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__OS_IRIX_)
|
||||
|
||||
void newStringBySocket(void *)
|
||||
|
||||
#elif defined(__OS_Linux_)
|
||||
|
||||
void *newStringBySocket(void *)
|
||||
|
||||
#elif defined(__OS_Win_)
|
||||
|
||||
void newStringBySocket(void *)
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
extern int numStrings, notDone;
|
||||
extern char **inputString;
|
||||
|
||||
int inOne = 0, i=0, m=0, n, parsing;
|
||||
int soc_id, accept_id;
|
||||
int maxfd, fd;
|
||||
fd_set mask, rmask;
|
||||
struct sockaddr_in sockname;
|
||||
char socBuf[STRING_LEN];
|
||||
static struct timeval timeout = {0, 1000}; // one millisecond
|
||||
|
||||
// Malloc inputString.
|
||||
inputString = (char **) malloc(MAX_IN_STRINGS * sizeof(char *));
|
||||
for ( i=0;i<MAX_IN_STRINGS;i++ )
|
||||
inputString[i] = (char *) malloc(STRING_LEN * sizeof(char));
|
||||
|
||||
memset(socBuf, 0, sizeof(socBuf));
|
||||
|
||||
#if defined(__OS_Win_) // Stupid Windoze only stuff
|
||||
WSADATA wsaData;
|
||||
WORD wVersionRequested = MAKEWORD(1,1);
|
||||
|
||||
int nRet = WSAStartup(wVersionRequested, &wsaData);
|
||||
if (wsaData.wVersion != wVersionRequested) {
|
||||
fprintf(stderr,"\n Wrong Windoze socket library version!\n");
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the server-side socket
|
||||
soc_id = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
|
||||
if(soc_id < 0) {
|
||||
fprintf(stderr,"Couldn't create socket ... aborting!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sockname.sin_family=AF_INET;
|
||||
sockname.sin_addr.s_addr=INADDR_ANY;
|
||||
sockname.sin_port=htons(SERVICE_PORT);
|
||||
|
||||
/* Bind socket to the appropriate port and interface (INADDR_ANY) */
|
||||
if (bind(soc_id,(struct sockaddr *)&sockname,sizeof(sockname)) < 0) {
|
||||
fprintf(stderr,"Couldn't bind socket ... aborting!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Listen for incoming connections */
|
||||
printf("Listening for socket connections on port %d\n", SERVICE_PORT);
|
||||
if (listen(soc_id,SOMAXCONN) < 0) {
|
||||
fprintf(stderr,"Couldn't set up listen on socket ... aborting!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(soc_id, &mask);
|
||||
maxfd = soc_id;
|
||||
|
||||
while (notDone) {
|
||||
rmask = mask;
|
||||
select(maxfd+1, &rmask, (fd_set *)0, (fd_set *)0, &timeout);
|
||||
if (FD_ISSET(soc_id,&rmask)) { // a new connection is available
|
||||
// Accept and service the incoming connection request
|
||||
accept_id=accept(soc_id,NULL,NULL);
|
||||
if (accept_id < 0) {
|
||||
fprintf(stderr,"Couldn't accept incoming connection on socket ... aborting!\n");
|
||||
exit(0);
|
||||
}
|
||||
printf("New socket connection made ... ready to receive SKINI messages.\n");
|
||||
|
||||
FD_SET(accept_id, &mask);
|
||||
if (accept_id > maxfd) maxfd = accept_id;
|
||||
FD_CLR(soc_id, &rmask);
|
||||
}
|
||||
for (fd=0;fd<=maxfd;fd++) { // look for other sockets with data
|
||||
if (FD_ISSET(fd, &rmask)) { // process the data
|
||||
parsing = 1;
|
||||
while (parsing) {
|
||||
i = recv(fd, socBuf, STRING_LEN,0);
|
||||
if (i==0) {
|
||||
printf("Closing a socket connection.\n");
|
||||
FD_CLR(fd, &mask);
|
||||
#if defined(__OS_Win_)
|
||||
closesocket(fd);
|
||||
#else
|
||||
close(fd);
|
||||
#endif
|
||||
parsing = 0;
|
||||
}
|
||||
n = 0;
|
||||
while (n < i) {
|
||||
inputString[inOne][m++] = socBuf[n];
|
||||
if (socBuf[n++] == '\n') {
|
||||
if (inputString[inOne][2] == 'i' && inputString[inOne][3] == 't'
|
||||
&& inputString[inOne][1] == 'x' && inputString[inOne][0] == 'E') {
|
||||
notDone = 0;
|
||||
n = i;
|
||||
parsing = 0;
|
||||
}
|
||||
else {
|
||||
m = 0;
|
||||
if (n >= i) parsing = 0;
|
||||
numStrings++;
|
||||
if (numStrings > MAX_IN_STRINGS) {
|
||||
fprintf(stderr,"Losing MIDI data ... try increasing MAX_IN_STRINGS.\n");
|
||||
numStrings--;
|
||||
}
|
||||
inOne++;
|
||||
if (inOne == MAX_IN_STRINGS) inOne = 0;
|
||||
memset(inputString[inOne], 0, STRING_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if defined(__OS_Win_) // Stupid Windoze only stuff
|
||||
closesocket(soc_id);
|
||||
WSACleanup();
|
||||
#else
|
||||
shutdown(soc_id,0);
|
||||
#endif
|
||||
|
||||
// Free inputString.
|
||||
for ( i=0;i<MAX_IN_STRINGS;i++ ) free(inputString[i]);
|
||||
free(inputString);
|
||||
|
||||
printf("Socket connection closed.\n");
|
||||
}
|
||||
|
||||
|
||||
void startPipeThread()
|
||||
{
|
||||
#if defined(__OS_IRIX_)
|
||||
string_thread = sproc(newStringByPipe, PR_SALL);
|
||||
if (string_thread == -1) {
|
||||
fprintf(stderr, "unable to create input pipe thread ... aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#elif defined(__OS_Linux_)
|
||||
if (pthread_create(&string_thread, NULL, newStringByPipe, NULL)) {
|
||||
fprintf(stderr, "unable to create input pipe thread ... aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#elif defined(__OS_Win_)
|
||||
string_thread = _beginthread(newStringByPipe, 0, NULL);
|
||||
if (string_thread == -1) {
|
||||
fprintf(stderr, "unable to create input pipe thread ... aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void startSocketThread()
|
||||
{
|
||||
#if defined(__OS_IRIX_)
|
||||
string_thread = sproc(newStringBySocket, PR_SALL);
|
||||
if (string_thread == -1) {
|
||||
fprintf(stderr, "unable to create input socket thread...aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#elif defined(__OS_Linux_)
|
||||
if (pthread_create(&string_thread, NULL, newStringBySocket, NULL)) {
|
||||
fprintf(stderr, "unable to create input socket thread...aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#elif defined(__OS_Win_)
|
||||
string_thread = _beginthread(newStringBySocket, 0, NULL);
|
||||
if (string_thread == -1) {
|
||||
fprintf(stderr, "unable to create input socket thread...aborting.\n");
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
27
effects/threads.h
Normal file
27
effects/threads.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// Thread functions for use with syntmono.
|
||||
//
|
||||
// Gary P. Scavone, 1999.
|
||||
|
||||
#include "../STK/Object.h"
|
||||
|
||||
#define STRING_LEN 60
|
||||
|
||||
#if (defined(__STK_REALTIME_) && defined(__OS_IRIX_) )
|
||||
|
||||
void newStringByPipe(void *);
|
||||
void newStringBySocket(void *);
|
||||
|
||||
#elif (defined(__STK_REALTIME_) && defined(__OS_Linux_) )
|
||||
|
||||
void *newStringByPipe(void *);
|
||||
void *newStringBySocket(void *);
|
||||
|
||||
#elif (defined(__STK_REALTIME_) && defined(__OS_Win_) )
|
||||
|
||||
void newStringByPipe(void *);
|
||||
void newStringBySocket(void *);
|
||||
|
||||
#endif
|
||||
|
||||
void startPipeThread();
|
||||
void startSocketThread();
|
||||
Reference in New Issue
Block a user