Version 3.1

This commit is contained in:
Gary Scavone
2013-09-25 14:44:17 +02:00
committed by Stephen Sinclair
parent 868787a5f9
commit 4b6500d3de
140 changed files with 5171 additions and 632 deletions

View File

@@ -17,7 +17,7 @@ char **inputString;
#include "threads.h"
/* Error function in case of incorrect command-line argument specifications */
void errorf(char *func) {
void usage(char *func) {
printf("\nuseage: %s Instr flag\n",func);
printf(" where Instr = TwoOsc (only one available for now)\n");
printf(" and flag = -ip for realtime SKINI input by pipe\n");
@@ -26,19 +26,19 @@ void errorf(char *func) {
exit(0);
}
void main(int argc,char *argv[])
int main(int argc,char *argv[])
{
long i, j, synlength, useSocket = 0;
int type, rtInput = 0;
int type;
int outOne = 0;
MY_FLOAT settleTime = 0.5; /* in seconds */
MY_FLOAT temp, byte3, lastPitch;
if (argc == 3) {
if (strcmp(argv[1],"TwoOsc")) errorf(argv[0]);
if (strcmp(argv[1],"TwoOsc")) usage(argv[0]);
if (!strcmp(argv[2],"-is")) useSocket = 1;
else if (strcmp(argv[2],"-ip")) errorf(argv[0]);
} else errorf(argv[0]);
else if (strcmp(argv[2],"-ip")) usage(argv[0]);
} else usage(argv[0]);
TwoOsc *instrument = new TwoOsc;
WvOut *output = new RTWvOut(SRATE,1);
@@ -63,38 +63,40 @@ void main(int argc,char *argv[])
if (numStrings) {
score->parseThis(inputString[outOne]);
type = score->getType();
if (type > 0) {
if (type == __SK_NoteOn_ ) {
if (type > 0) {
switch(type) {
case __SK_NoteOn_:
// check to see if velocity is zero ... really a NoteOff
if (( byte3 = score->getByteThree() ) == 0)
instrument->noteOff(byte3*NORM_7);
else {
instrument->noteOff(0.0);
else { // really a NoteOn
j = (int) score->getByteTwo();
temp = __MIDI_To_Pitch[j];
lastPitch = temp;
instrument->noteOn(temp,byte3*NORM_7);
lastPitch = __MIDI_To_Pitch[j];
instrument->noteOn(lastPitch,byte3*NORM_7);
}
}
else if (type == __SK_NoteOff_) {
byte3 = score->getByteThree();
instrument->noteOff(byte3*NORM_7);
}
else if (type == __SK_ControlChange_) {
j = (int) score->getByteTwo();
byte3 = score->getByteThree();
instrument->controlChange(j,byte3);
}
else if (type == __SK_AfterTouch_) {
j = (int) score->getByteTwo();
instrument->controlChange(128,j);
}
else if (type == __SK_PitchBend_) {
break;
case __SK_NoteOff_:
instrument->noteOff(NORM_7*score->getByteThree());
break;
case __SK_ControlChange_:
instrument->controlChange((int)score->getByteTwo(),
score->getByteThree());
break;
case __SK_AfterTouch_:
instrument->controlChange(128,score->getByteTwo());
break;
case __SK_PitchBend_:
temp = score->getByteTwo();
j = (int) temp;
temp -= j;
temp -= j; // floating-point remainder
lastPitch = __MIDI_To_Pitch[j] * pow(2.0,temp / 12.0) ;
instrument->setFreq(1, lastPitch); /* change osc1 pitch for now */
}
else if (type == __SK_ProgramChange_) {
break;
}
}
outOne += 1;
@@ -102,6 +104,7 @@ void main(int argc,char *argv[])
numStrings--;
}
}
for (i=0;i<settleTime*SRATE;i++) { /* let the sound settle a little */
output->tick(instrument->tick());
}
@@ -111,4 +114,5 @@ void main(int argc,char *argv[])
delete instrument;
printf("MUS151 finished.\n");
return 0;
}

View File

@@ -26,7 +26,7 @@ RM = /bin/rm
ifeq ($(OS),IRIX) # These are for SGI
INSTR = MUS151
CC = CC -O2 -D__OS_IRIX_ # -g -fullwarn -D__SGI_CC__
LIBRARY = -L/usr/sgitcl/lib -laudio -lmd -lm
LIBRARY = -L/usr/sgitcl/lib -laudio -lm -lpthread
endif
ifeq ($(OS),Linux) # These are for Linux

View File

@@ -102,7 +102,7 @@ bind . <Destroy> +myExit
proc myExit {} {
global outID
puts $outID [format "NoteOff 0.0 1 64 127" ]
puts $outID [format "NoteOff 0.0 1 64.0 127.0" ]
flush $outID
puts $outID [format "ExitProgram"]
flush $outID

View File

@@ -1,26 +1,28 @@
// Thread functions for use with syntmono.
//
// Gary P. Scavone, 1999.
// No mutexes are currently being used when accessing
// the global variables shared between these threads
// and the main() routine. In a single processor
// environment, no problems have resulted from such data
// sharing. However, if STK is to be run on a true parallel
// processing platform, it is likely that mutexes will be
// necessary. While the mutex calls are simple to code, I
// am trying to keep the code as generic as possible. A
// quick investigation of threads under Windoze indicates
// that mutex functionality is not available, at least with
// the standard libraries.
//
// Gary P. Scavone, 2000.
#include "threads.h"
#if defined(__STK_REALTIME_)
#define SERVICE_PORT 2001 // Socket Port ID number
// Default STK socket port ID number
#define SERVICE_PORT 2001
// 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_)
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -39,13 +41,10 @@ unsigned long string_thread;
#endif
// The thread function definition protocols are slightly
// different under Irix, Linux, and Windoze.
#if defined(__OS_IRIX_)
// The thread function protocols are slightly different
// under Windoze ... but of course!
void newStringByPipe(void *)
#elif defined(__OS_Linux_)
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
void *newStringByPipe(void *)
@@ -86,14 +85,15 @@ void newStringByPipe(void *)
// Free inputString.
for ( i=0;i<MAX_IN_STRINGS;i++ ) free(inputString[i]);
free(inputString);
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
pthread_exit(NULL);
return NULL;
#elif defined(__OS_Win_)
_endthread();
#endif
}
#if defined(__OS_IRIX_)
void newStringBySocket(void *)
#elif defined(__OS_Linux_)
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
void *newStringBySocket(void *)
@@ -113,7 +113,7 @@ void newStringBySocket(void *)
fd_set mask, rmask;
struct sockaddr_in sockname;
char socBuf[STRING_LEN];
static struct timeval timeout = {0, 1000}; // one millisecond
static struct timeval timeout = {0, 10000}; // ten millisecond
// Malloc inputString.
inputString = (char **) malloc(MAX_IN_STRINGS * sizeof(char *));
@@ -163,6 +163,9 @@ void newStringBySocket(void *)
while (notDone) {
rmask = mask;
// Need to reset the timeout values because of linux "select" implementation
timeout.tv_sec = 0;
timeout.tv_usec = 10000; // 0.01 seconds
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
@@ -232,18 +235,18 @@ void newStringBySocket(void *)
free(inputString);
printf("Socket connection closed.\n");
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
pthread_exit(NULL);
return NULL;
#elif defined(__OS_Win_)
_endthread();
#endif
}
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 (defined(__OS_IRIX_) || defined(__OS_Linux_))
if (pthread_create(&string_thread, NULL, newStringByPipe, NULL)) {
fprintf(stderr, "unable to create input pipe thread ... aborting.\n");
exit(0);
@@ -259,13 +262,7 @@ void startPipeThread()
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 (defined(__OS_IRIX_) || defined(__OS_Linux_))
if (pthread_create(&string_thread, NULL, newStringBySocket, NULL)) {
fprintf(stderr, "unable to create input socket thread...aborting.\n");
exit(0);

View File

@@ -6,12 +6,15 @@
#define STRING_LEN 60
/*
#if (defined(__STK_REALTIME_) && defined(__OS_IRIX_) )
void newStringByPipe(void *);
void newStringBySocket(void *);
#elif (defined(__STK_REALTIME_) && defined(__OS_Linux_) )
*/
#if (defined(__STK_REALTIME_) && (defined(__OS_IRIX_) || defined(__OS_Linux_)))
void *newStringByPipe(void *);
void *newStringBySocket(void *);