diff --git a/lib-src/libnyquist/hurd-nyquist.patch b/lib-src/libnyquist/hurd-nyquist.patch deleted file mode 100644 index 9bafe9c5f..000000000 --- a/lib-src/libnyquist/hurd-nyquist.patch +++ /dev/null @@ -1,102 +0,0 @@ -Index: nyquist/cmt/midifns.c -=================================================================== -RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/cmt/midifns.c,v -retrieving revision 1.1 -diff -u -r1.1 midifns.c ---- nyquist/cmt/midifns.c 29 Jan 2009 18:04:20 -0000 1.1 -+++ nyquist/cmt/midifns.c 8 Dec 2009 01:19:17 -0000 -@@ -24,6 +24,7 @@ - #include "switches.h" - - #ifdef UNIX -+#include - #include - #ifndef OPEN_MAX - /* this is here for compiling the UNIX version under AIX. This is a BSDism */ -@@ -376,6 +377,7 @@ - struct timeval unix_timeout; - struct timeval *waitspec = NULL; - fd_set readfds; -+ struct rlimit file_limit; - - FD_ZERO(&readfds); - FD_SET(MI_CONNECTION(midiconn), &readfds); -@@ -387,7 +389,8 @@ - unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000; - waitspec = &unix_timeout; - } -- select(NOFILE+1, &readfds, 0, 0, waitspec); -+ getrlimit(RLIMIT_NOFILE, &file_limit); -+ select(file_limit.rlim_max+1, &readfds, 0, 0, waitspec); - return; - } - #else /* !UNIX_ITC */ -@@ -424,6 +427,7 @@ - { - struct timeval unix_timeout; - struct timeval *waitspec = NULL; -+ struct rlimit file_limit; - - if (timeout >= 0) { - timeout -= gettime(); /* convert to millisecond delay */ -@@ -431,7 +435,8 @@ - /* remainder become microsecs: */ - unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000; - waitspec = &unix_timeout; -- select(NOFILE+1, 0, 0, 0, waitspec); -+ getrlimit(RLIMIT_NOFILE, &file_limit); -+ select(file_limit.rlim_max+1, 0, 0, 0, waitspec); - } else { - int c = getc(stdin); - ungetc(c, stdin); -@@ -445,6 +450,7 @@ - struct timeval unix_timeout; - struct timeval *waitspec = NULL; - int readfds = 1 << IOinputfd; -+ struct rlimit file_limit; - - if (timeout >= 0) { - timeout -= gettime(); /* convert to millisecond delay */ -@@ -453,7 +459,8 @@ - unix_timeout.tv_usec = (timeout - (unix_timeout.tv_sec * 1000)) * 1000; - waitspec = &unix_timeout; - } -- select(NOFILE+1, &readfds, 0, 0, waitspec); -+ getrlimit(RLIMIT_NOFILE, &file_limit); -+ select(file_limit.rlim_max+1, &readfds, 0, 0, waitspec); - return; - } - #endif /* BUFFERED_SYNCHRONOUS_INPUT */ -Index: nyquist/cmt/userio.c -=================================================================== -RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/cmt/userio.c,v -retrieving revision 1.1 -diff -u -r1.1 userio.c ---- nyquist/cmt/userio.c 29 Jan 2009 18:04:21 -0000 1.1 -+++ nyquist/cmt/userio.c 8 Dec 2009 01:19:17 -0000 -@@ -133,6 +133,7 @@ - - #ifdef UNIX - #include -+#include - #include "cmtio.h" - #ifdef _IBMR2 - #define NBBY 8 -@@ -1205,6 +1206,7 @@ - #endif /* !UNIX_MACH */ - #endif - char c; -+ struct rlimit file_limit; - - if (abort_flag == ABORT_LEVEL) return ABORT_CHAR; - if (abort_flag == BREAK_LEVEL) return BREAK_CHAR; -@@ -1233,7 +1235,8 @@ - FD_ZERO(&readfds); - FD_SET(IOinputfd, &readfds); - gflush(); -- select(NOFILE+1, &readfds, 0, 0, NULL); -+ getrlimit(RLIMIT_NOFILE, &file_limit); -+ select(file_limit.rlim_max+1, &readfds, 0, 0, NULL); - #endif /* !UNIX_MACH */ - #endif /* ifdef UNIX */ - } diff --git a/lib-src/libnyquist/kFreeBSD-nyquist.patch b/lib-src/libnyquist/kFreeBSD-nyquist.patch deleted file mode 100644 index 5d2e38bba..000000000 --- a/lib-src/libnyquist/kFreeBSD-nyquist.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- audacity-1.3.8.orig/lib-src/libnyquist/nyquist/sys/unix/switches.h -+++ audacity-1.3.8/lib-src/libnyquist/nyquist/sys/unix/switches.h -@@ -76,7 +76,7 @@ - #define CPU_IS_BIG_ENDIAN 1 - #endif - #else -- #ifdef __linux__ -+ #if defined(__linux__) || defined(__GLIBC__) - #include - #if __BYTE_ORDER == __LITTLE_ENDIAN - /* Target processor is little endian. */ -only in patch2: -unchanged: ---- audacity-1.3.8.orig/lib-src/libnyquist/nyquist/xlisp/xlisp.h -+++ audacity-1.3.8/lib-src/libnyquist/nyquist/xlisp/xlisp.h -@@ -143,7 +143,7 @@ - #endif - - /* Linux on Pentium */ --#ifdef __linux__ -+#if defined(__linux__) || defined(__GLIBC__) - #include - #if __BYTE_ORDER == __LITTLE_ENDIAN - #define XL_LITTLE_ENDIAN diff --git a/lib-src/libnyquist/nyquist/Readme.txt b/lib-src/libnyquist/nyquist/Readme.txt index 93a728418..f5feba403 100644 --- a/lib-src/libnyquist/nyquist/Readme.txt +++ b/lib-src/libnyquist/nyquist/Readme.txt @@ -1,22 +1,62 @@ -README file for Nyquist Version 3.03 -24 Feb 2009 +README file for Nyquist Version 3.09 +28 Dec 2014 Roger B. Dannenberg LICENSE: see license.txt -WEB SITE: http://www.cs.cmu.edu/~rbd/nyquist.html +WEB SITE: http://www.cs.cmu.edu/~music/nyquist INSTALLING NYQUIST ==================== -Please see Section 1.1, Page 1, of the Nyquist Manual +You can download pre-compiled versions for Windows and OS X. -If you use Windows 95 or Windows NT, this release was -compiled with Visual C++ 6.0. +You can compile Nyquist from sources for Windows, OS X, linux, and +other versions of Unix. For details, see one of these files: + - sys/win/README.txt + - sys/mac/README.txt + - sys/unix/README.txt -For Mac OS X command line users, there is an executable -Nyquist program: NyquistIDE.app/Contents/Resources/Java/ny IMPLEMENTATION STATUS ===================== + +Version 3.09 provides: + Various bug fixes + OS X version is significantly faster + Security features added to limit CPU, memory, file access (default + is still unrestricted; this feature is to protect servers) + +Version 3.08 provides: + NyquistIDE opens documentation properly on default browser + NyquistIDE forcefully terminates nyquist process on exit if needed + bug fix for mixed sample rate signal handling, affects many primitives + timed-seq and score-play avoid stack overflow on finely spaced events + sampler() primitive does error checking to avoid infinite loop + +Version 3.07 provides: + Bug fixes in NyquistIDE Envelope Editor + NyquistIDE installs symbolic links to lib and demos + directories from nyquist directory (where documentation + is kept) so these folders are not hidden in the app bundle. + Bug fix in quantize and snd-quantize functions. + +Version 3.06 provides: + 64-bit architecture support + Access to OGG and FLAC file formats + Updates for MSVC++2010, VS2012, XCode 4.5 + This is a deadline-driven release. Expect an update soon. + +Version 3.05 provides: + New "UPIC Editor" window in NyquistIDE + Fix to escape backslashes in default windows directory + Fix to other problems with Preferences + Arpeggiator example in nyquist/demos + +Version 3.04 provides: + Updates to libraries, including liblo and PortAudio + Documentation uses both syntax SAL and Lisp syntax + Some STK instruments have been added + Build files modified to make 32-bit code even on 64-bit + architectures (Nyquist only runs in 32-bit mode) Version 3.03 provides: Bug fix to Markov pattern generator (see make-markov). Update to current (24-feb-09) liblo library. @@ -215,20 +255,3 @@ todo - list of things to do (this may not be in the release) tran - descriptor (.alg) files for machine-translated Nyquist code xlisp - sources for Xlisp (these are linked into Nyquist) -THE RUNTIME ONLY RELEASE -======================== -The runtime-only release contains everything related to running -Nyquist, but no source code. The files in this release are: - Readme.txt (this file) - nyquist.exe (located in the runtime directory) - runtime (directory) - lib (directory) - demos (directory) - test (directory) - -BUILDING UNDER LINUX -==================== -in the nyquist directory: -> ln -s sys/unix/linux/Makefile -> make - diff --git a/lib-src/libnyquist/nyquist/cmt/cmdline.c b/lib-src/libnyquist/nyquist/cmt/cmdline.c index 0882bd6aa..2c7d38394 100644 --- a/lib-src/libnyquist/nyquist/cmt/cmdline.c +++ b/lib-src/libnyquist/nyquist/cmt/cmdline.c @@ -89,6 +89,13 @@ #include "ctype.h" #include "string.h" +/* this should really be defined in security.h, but it is in xlisp.h. + * I don't want to add an xlisp dependency here, nor do I want to + * create security.h since that's not how xlisp does things. + * The C++ linker will type check so this is at least type safe. + */ +int ok_to_open(const char *filename, const char *mode); + #define syntax_max 10 /* allow for 10 syntax strings */ private char *syntax[syntax_max]; private int n_syntax = 0; /* number of strings so far */ @@ -440,9 +447,11 @@ private void indirect_command(filename, oldarg0) char *filename; char *oldarg0; { - FILE *argfile = fopen(filename, "r"); + FILE *argfile = NULL; + if (ok_to_open(filename, "r")) + argfile = fopen(filename, "r"); if (!argfile) { - argv = (char **) malloc(sizeof(char *)); + argv = (char **) malloc(sizeof(char *)); argv[0] = oldarg0; argc = 1; } else { diff --git a/lib-src/libnyquist/nyquist/cmt/midifile.h b/lib-src/libnyquist/nyquist/cmt/midifile.h index f81f1e122..a759d768c 100644 --- a/lib-src/libnyquist/nyquist/cmt/midifile.h +++ b/lib-src/libnyquist/nyquist/cmt/midifile.h @@ -1,27 +1,27 @@ -extern void midifile(); -extern int (*Mf_getc)(); -extern void (*Mf_header)(); -extern void (*Mf_starttrack)(); -extern void (*Mf_endtrack)(); -extern void (*Mf_on)(); -extern void (*Mf_off)(); -extern void (*Mf_pressure)(); -extern void (*Mf_controller)(); -extern void (*Mf_pitchbend)(); -extern void (*Mf_program)(); -extern void (*Mf_chanpressure)(); -extern void (*Mf_sysex)(); -extern void (*Mf_metamisc)(); -extern void (*Mf_sqspecific)(); -extern void (*Mf_seqnum)(); -extern void (*Mf_text)(); -extern void (*Mf_eot)(); -extern void (*Mf_timesig)(); -extern void (*Mf_smpte)(); -extern void (*Mf_tempo)(); -extern void (*Mf_keysig)(); -extern void (*Mf_arbitrary)(); -extern void (*Mf_error)(); +extern void midifile(void); +extern int (*Mf_getc)(void); +extern void (*Mf_header)(int,int,int); +extern void (*Mf_starttrack)(void); +extern void (*Mf_endtrack)(void); +extern void (*Mf_on)(int,int,int); +extern void (*Mf_off)(int,int,int); +extern void (*Mf_pressure)(int,int,int); +extern void (*Mf_controller)(int,int,int); +extern void (*Mf_pitchbend)(int,int,int); +extern void (*Mf_program)(int,int); +extern void (*Mf_chanpressure)(int,int); +extern void (*Mf_sysex)(int,char*); +extern void (*Mf_metamisc)(int,int,char*); +extern void (*Mf_sqspecific)(int,char*); +extern void (*Mf_seqnum)(int); +extern void (*Mf_text)(int,int,char*); +extern void (*Mf_eot)(void); +extern void (*Mf_timesig)(int,int,int,int); +extern void (*Mf_smpte)(int,int,int,int,int); +extern void (*Mf_tempo)(int); +extern void (*Mf_keysig)(int,int); +extern void (*Mf_arbitrary)(int,char*); +extern void (*Mf_error)(char *); extern long Mf_currtime; extern int Mf_nomerge; extern int Mf_skipinit; diff --git a/lib-src/libnyquist/nyquist/cmt/record.c b/lib-src/libnyquist/nyquist/cmt/record.c index 44f2373a9..07cb18f9c 100644 --- a/lib-src/libnyquist/nyquist/cmt/record.c +++ b/lib-src/libnyquist/nyquist/cmt/record.c @@ -600,7 +600,20 @@ boolean rec_init(boolean bender) /* it would be silly to record with only room enough for 10 notes! */ } - +#ifdef NEED_REC_EVENT +/* +This function was part of the CMU MIDI Toolkit. It provided a constant time +fast way to record midi data into a buffer. After recording, the buffered +data could be transferred into an Adagio score structure, which involved +linked list allocation and insertion that might have caused performance +problems. This code uses the high-order bit of longs to distinguish timestamps +from data (MIDI messages), but the code seems to assume little endian, and +I'm not sure how it worked on both Intel and 68000 processors. Rather than +look more closely or fix it, I'm commenting it out because Nyquist does not +have any MIDI I/O capability and does not need the function. It is here for +completeness, since this is probably the only archived version of the CMU +MIDI Toolkit. */ + /**************************************************************************** * rec_event * Inputs: @@ -636,3 +649,5 @@ overflow: gprintf(ERROR, "No more memory.\n"); return FALSE; } + +#endif \ No newline at end of file diff --git a/lib-src/libnyquist/nyquist/cmt/seq.c b/lib-src/libnyquist/nyquist/cmt/seq.c index 07cf567ba..de54e4746 100644 --- a/lib-src/libnyquist/nyquist/cmt/seq.c +++ b/lib-src/libnyquist/nyquist/cmt/seq.c @@ -35,14 +35,15 @@ boolean clock_running = FALSE; /* TRUE if clock is running */ boolean external_midi_clock = FALSE; boolean suppress_midi_clock = FALSE; -private void insert_event(); -private void process_event(); +private void insert_event(seq_type, register event_type); +private void process_event(seq_type); -private char *chunk_alloc(); -private void clock_tick(); +private char *chunk_alloc(seq_type seq, int size); +private void clock_tick(seq_type seq, time_type fraction); private void ramp_event(seq_type seq, event_type event, unsigned int value, unsigned int to_value, int increment, time_type step, int n); -/*private*/ void send_macro(); +/*private*/ void send_macro(register unsigned char *ptr, int voice, + short parameter[], int parm_num, int value, int nline); /* chunk_alloc -- allocate data for a sequence */ /* @@ -103,9 +104,7 @@ chunk_type chunk_create(boolean first_flag) /* clock_tick -- advance the clock and send a tick */ /**/ -private void clock_tick(seq, fraction) - seq_type seq; - time_type fraction; +private void clock_tick(seq_type seq, time_type fraction) { int delay; fraction += clock_ticksize; @@ -121,8 +120,7 @@ private void clock_tick(seq, fraction) } } -private void cycle(seq) - seq_type seq; +private void cycle(seq_type seq) { seq_reset(seq); seq_play(seq); @@ -828,11 +826,7 @@ void seq_at_end(seq, fn) /* seq_cause_noteoff_meth -- turn off a note in the future */ /**/ -void seq_cause_noteoff_meth(seq, delay, voice, pitch) - seq_type seq; - time_type delay; - int voice; - int pitch; +void seq_cause_noteoff_meth(seq_type seq, time_type delay, int voice, int pitch) { if (seq->note_enable) { pitch += seq->transpose; @@ -1021,10 +1015,7 @@ void seq_midi_touch_meth(seq_type seq, int voice, int value) /* seq_noteoff_meth -- turn a seq note off */ /**/ -void seq_noteoff_meth(seq, voice, pitch) - seq_type seq; - int voice; - int pitch; +void seq_noteoff_meth(seq_type seq, int voice, int pitch) { midi_note(voice, pitch, 0); /*gprintf(TRANS, "_e");*/ @@ -1034,9 +1025,7 @@ void seq_noteoff_meth(seq, voice, pitch) /* seq_noteon_meth -- play a note with transformations */ /**/ -void seq_noteon_meth(seq, chan, pitch, vel) - seq_type seq; - int chan, pitch, vel; +void seq_noteon_meth(seq_type seq, int chan, int pitch, int vel) { if (seq->note_enable) { pitch += seq->transpose; @@ -1100,8 +1089,7 @@ void seq_play(seq) /* seq_reset_meth -- reset a sequence to start back at the first event */ /**/ -void seq_reset_meth(seq) - seq_type seq; +void seq_reset_meth(seq_type seq) { timebase_type old_timebase = timebase; diff --git a/lib-src/libnyquist/nyquist/cmt/seq.h b/lib-src/libnyquist/nyquist/cmt/seq.h index 2bfac2656..4177d2c86 100644 --- a/lib-src/libnyquist/nyquist/cmt/seq.h +++ b/lib-src/libnyquist/nyquist/cmt/seq.h @@ -168,15 +168,15 @@ typedef struct chunk_struct { typedef struct seq_struct { - void (*cause_noteoff_fn)(); - void (*midi_bend_fn)(); - void (*midi_ctrl_fn)(); - void (*midi_program_fn)(); - void (*midi_touch_fn)(); - void (*noteoff_fn)(); - void (*noteon_fn)(); - void (*free_fn)(); - void (*reset_fn)(); + void (*cause_noteoff_fn)(struct seq_struct *, time_type, int, int); + void (*midi_bend_fn)(struct seq_struct * seq, int voice, int value); + void (*midi_ctrl_fn)(struct seq_struct * seq, int voice, int ctrl, int value); + void (*midi_program_fn)(struct seq_struct * seq, int voice, int prog); + void (*midi_touch_fn)(struct seq_struct * seq, int voice, int value); + void (*noteoff_fn)(struct seq_struct * seq, int voice, int pitch); + void (*noteon_fn)(struct seq_struct * seq, int chan, int pitch, int vel); + void (*free_fn)(struct seq_struct * seq); + void (*reset_fn)(struct seq_struct * seq); void (*stopfunc)(struct seq_struct *); chunk_type chunklist; /* event_type eventlist; diff --git a/lib-src/libnyquist/nyquist/cmt/seqmwrite.c b/lib-src/libnyquist/nyquist/cmt/seqmwrite.c index 8afd7ad5d..2288ab293 100644 --- a/lib-src/libnyquist/nyquist/cmt/seqmwrite.c +++ b/lib-src/libnyquist/nyquist/cmt/seqmwrite.c @@ -167,9 +167,6 @@ private void smfw_dotrack(seq) unsigned long chunk_size; if (seq->runflag) { - if ((seq->timebase->virt_base == 0) && - (seq->timebase->rate == STOPRATE)) - /*we just set these last time through... do nothing*/; seq_stop(seq); } timebase_use(seq->timebase); @@ -541,8 +538,9 @@ void seq_write_smf(seq, outfile) event = seq_events(smfw_seq.seq); - /*search for clock events up till start of score*/ - while(event->ntime <= 0){ + /* search for clock events up till start of score */ + /* careful: there may be no events at all */ + while(event && event->ntime <= 0){ if(debug) gprintf(TRANS, "event (time:%ld)\n", event->ntime); if(vc_ctrl(event->nvoice) == ESC_CTRL && event->value == CLOCK_VALUE) { if(debug) gprintf(TRANS, "clock %lu at 0\n", event->u.clock.ticksize); @@ -570,55 +568,61 @@ void seq_write_smf(seq, outfile) putc(0x02, smfw_seq.outfile);/*division resolution of 600*/ putc(0x58, smfw_seq.outfile); - for(i = 0; i < 17; i++){/*for each track..*/ - if(((seq_used_mask(smfw_seq.seq) >> (i - 1)) & 0x1) || (i == 0)){ - if(debug) gprintf(TRANS, "write track %d \n", i); - track_count++; - clock_ticksize = starting_ticksize; - last_tick_size = starting_ticksize; - putc(0x4D, smfw_seq.outfile);/*track header: MTrk*/ - putc(0x54, smfw_seq.outfile); - putc(0x72, smfw_seq.outfile); - putc(0x6B, smfw_seq.outfile); + for (i = 0; i < 17; i++) { /* for each track... */ + if (((seq_used_mask(smfw_seq.seq) >> (i - 1)) & 0x1) || (i == 0)) { + if (debug) gprintf(TRANS, "write track %d \n", i); + track_count++; + clock_ticksize = starting_ticksize; + last_tick_size = starting_ticksize; + putc(0x4D, smfw_seq.outfile);/*track header: MTrk*/ + putc(0x54, smfw_seq.outfile); + putc(0x72, smfw_seq.outfile); + putc(0x6B, smfw_seq.outfile); - chunk_size_marker = ftell(smfw_seq.outfile);/*size of chunk will be written later*/ - putc(0x00, smfw_seq.outfile); /*will be filled by chunk_size_marker*/ - putc(0x00, smfw_seq.outfile); - putc(0x00, smfw_seq.outfile); - putc(0x00, smfw_seq.outfile); - - if(i == 0) { /*tempo and time signature track*/ - putc(0x00, smfw_seq.outfile);/* default time sig stuff*/ - putc(0xFF, smfw_seq.outfile); - putc(0x58, smfw_seq.outfile); - putc(0x04, smfw_seq.outfile); - putc(0x04, smfw_seq.outfile); - putc(0x02, smfw_seq.outfile); - putc(0x18, smfw_seq.outfile); - putc(0x08, smfw_seq.outfile); + chunk_size_marker = ftell(smfw_seq.outfile); + /* size of chunk will be written later */ + /* will be filled by chunk_size_marker */ putc(0x00, smfw_seq.outfile); + putc(0x00, smfw_seq.outfile); + putc(0x00, smfw_seq.outfile); + putc(0x00, smfw_seq.outfile); + + if (i == 0) { /* tempo and time signature track */ + putc(0x00, smfw_seq.outfile);/* default time sig stuff*/ + putc(0xFF, smfw_seq.outfile); + putc(0x58, smfw_seq.outfile); + putc(0x04, smfw_seq.outfile); + putc(0x04, smfw_seq.outfile); + putc(0x02, smfw_seq.outfile); + putc(0x18, smfw_seq.outfile); + putc(0x08, smfw_seq.outfile); + putc(0x00, smfw_seq.outfile); - putc(0xFF, smfw_seq.outfile);/*TEMPO: inserted here in case default is used*/ - putc(0x51, smfw_seq.outfile); - putc(0x03, smfw_seq.outfile); - /* ticksize is in ms<<16, so to get milliseconds per tick, it's - ticksize / 65536. To get beat durations, multiply by 24 to get - ticksize * 24 / 65536. To get microseconds, multiply by 1000: - ticksize * 24000 / 65536. Divide both constants by 64 to get - ticksize * 375 / 1024 = microseconds per quarter note. - */ - put_tick_size = scale(clock_ticksize, 375L, 1024L); - putc((int) ((put_tick_size >> 16) & 0xFF), smfw_seq.outfile); - putc((int) ((put_tick_size >> 8) & 0xFF), smfw_seq.outfile); - putc((int) (put_tick_size & 0xFF), smfw_seq.outfile); + /* TEMPO: inserted here in case default is used */ + putc(0xFF, smfw_seq.outfile); + putc(0x51, smfw_seq.outfile); + putc(0x03, smfw_seq.outfile); + /* ticksize is in ms<<16, so to get milliseconds per tick, it's + ticksize / 65536. To get beat durations, multiply by 24 + to get ticksize * 24 / 65536. To get microseconds, + multiply by 1000: ticksize * 24000 / 65536. Divide both + constants by 64 to get ticksize * 375 / 1024 = + microseconds per quarter note. + */ + put_tick_size = scale(clock_ticksize, 375L, 1024L); + putc((int) ((put_tick_size >> 16) & 0xFF), smfw_seq.outfile); + putc((int) ((put_tick_size >> 8) & 0xFF), smfw_seq.outfile); + putc((int) (put_tick_size & 0xFF), smfw_seq.outfile); + } + smfw_seq.track = i; + smfw_dotrack(smfw_seq.seq); } - smfw_seq.track = i; - smfw_dotrack(smfw_seq.seq); - } } - if(seti_counter) gprintf(TRANS, "%d SETI events IGNORED!\n", seti_counter); + if (seti_counter) + gprintf(TRANS, "%d SETI events IGNORED!\n", seti_counter); seq_stop(smfw_seq.seq); - fseek(smfw_seq.outfile, track_count_marker, 0);/*go back and insert number of tracks*/ + /* go back and insert number of tracks */ + fseek(smfw_seq.outfile, track_count_marker, 0); putc(0xFF & track_count, smfw_seq.outfile); fclose(smfw_seq.outfile); } diff --git a/lib-src/libnyquist/nyquist/cmt/swlogic.h b/lib-src/libnyquist/nyquist/cmt/swlogic.h index e09bd6c73..88807305b 100644 --- a/lib-src/libnyquist/nyquist/cmt/swlogic.h +++ b/lib-src/libnyquist/nyquist/cmt/swlogic.h @@ -139,7 +139,7 @@ #ifndef NYQUIST #define MIDIMGR #endif -#define USE_VSPRINTF +#define HAVE_VSNPRINTF 1 #endif #ifdef BORLAND @@ -161,12 +161,12 @@ #define ITC #endif -/* USE_VSPRINTF says vsprintf() is defined */ +/* HAVE_VSNPRINTF says vsnprintf() is defined */ #ifdef ITC -#define USE_VSPRINTF +#define HAVE_VSNPRINTF 1 #endif #ifdef AZTEC -#define USE_VSPRINTF +#define HAVE_VSNPRINTF 1 #endif diff --git a/lib-src/libnyquist/nyquist/cmt/userio.c b/lib-src/libnyquist/nyquist/cmt/userio.c index e8d4fdb36..f442376c5 100644 --- a/lib-src/libnyquist/nyquist/cmt/userio.c +++ b/lib-src/libnyquist/nyquist/cmt/userio.c @@ -537,8 +537,14 @@ FILE *fileopen(deflt, extension, mode, prompt) strcpy(extname, fileopen_name); strcat(extname, "."); strcat(extname, extension); - fp = fopen(fileopen_name, mode); - fpext = fopen(extname, mode); + fp = NULL; + fpext = NULL; + if (ok_to_open(fileopen_name, mode)) { + fp = fopen(fileopen_name, mode); + } + if (ok_to_open(extname, mode)) { + fpext = fopen(extname, mode); + } if (fp != NULL && fpext != NULL) { gprintf(TRANS, "warning: both %s and %s exist. %s will be used.\n", @@ -566,7 +572,9 @@ FILE *fileopen(deflt, extension, mode, prompt) && added_extension #endif ) { - fp = fopen(fileopen_name, "r"); + fp = NULL; + if (ok_to_open(fileopen_name, "r")) + fp = fopen(fileopen_name, "r"); if (fp != NULL) { char question[100]; fclose(fp); @@ -579,7 +587,9 @@ FILE *fileopen(deflt, extension, mode, prompt) } } } - fp = fopen(fileopen_name, mode); + fp = NULL; + if (ok_to_open(fileopen_name, mode)) + fp = fopen(fileopen_name, mode); if (fp == NULL) problem = "Couldn't create %s.\n"; } tryagain: @@ -592,7 +602,6 @@ FILE *fileopen(deflt, extension, mode, prompt) return fp; } - #ifdef MACINTOSH static int GetReadFileName(name) @@ -786,7 +795,7 @@ void readln(fp) * Note that to handle the variable argument list, a number of different * approaches are implemented. The first part of the implementation selects * one of 4 ways to build temp1, a formatted string. The 4 ways arise from -* use or non-use of vsprintf, and use or non-use of ... in the arg list. +* use or non-use of vsnprintf, and use or non-use of ... in the arg list. * After building temp1, non-Amiga systems write to stdout or stderr, * whereas AMIGA writes to a special console. Why? Because the Amiga * needs a new console so we can set up a signal upon character typein. @@ -794,10 +803,10 @@ void readln(fp) #ifndef gprintf #define GPRINTF_MESSAGE_LEN 512 -#ifdef USE_VSPRINTF +#ifdef HAVE_VSNPRINTF #ifdef DOTS_FOR_ARGS -/* define with ... in arg list and use vsprintf to get temp1 */ +/* define with ... in arg list and use vsnprintf to get temp1 */ public void gprintf(long where, char *format, ...) { char temp1[GPRINTF_MESSAGE_LEN]; @@ -807,12 +816,12 @@ public void gprintf(long where, char *format, ...) va_list ap; va_start(ap, format); - vsprintf(temp1, format, ap); + vsnprintf(temp1, GPRINTF_MESSAGE_LEN, format, ap); va_end(ap); #else /* !DOTS_FOR_ARGS */ -/* define with va_alist and use vsprintf to get temp1 */ +/* define with va_alist and use vsnprintf to get temp1 */ public void gprintf(where, format, va_alist) long where; char *format; @@ -823,19 +832,19 @@ va_dcl /* this is a syntax error - if you don't have to remove this, */ /* then this whole section of code is unnecessary. */ va_start(pvar); - vsprintf(temp1, format, pvar); + vsnprintf(temp1, GPRINTF_MESSAGE_LEN, format, pvar); va_end(pvar); #endif /* DOTS_FOR_ARGS */ -#else /* !USE_VSPRINTF */ +#else /* !HAVE_VSNPRINTF */ #define MAX_GPRINTF_ARGS 10 typedef struct gp_args_struct { long arg[MAX_GPRINTF_ARGS]; } gp_args_node; #ifdef DOTS_FOR_ARGS -/* use ... but not vsprintf */ +/* use ... but not vsnprintf */ public void gprintf(long where, char *format, ...) { char temp1[GPRINTF_MESSAGE_LEN]; @@ -848,7 +857,7 @@ public void gprintf(long where, char *format, ...) args = va_arg(ap, gp_args_node); va_end(ap); #else /* !DOTS_FOR_ARGS */ -/* don't use ... and don't use vsprintf */ +/* don't use ... and don't use vsnprintf */ public void gprintf(where, format, args) long where; char *format; @@ -860,9 +869,9 @@ public void gprintf(where, format, args) #endif /* AMIGA*/ #endif /* DOTS_FOR_ARGS */ - sprintf(temp1, format, args); + snprintf(temp1, GPRINTF_MESSAGE_LEN, format, args); -#endif /* USE_VSPRINTF */ +#endif /* HAVE_VSNPRINTF */ /* * Now we've got formatted output in temp1. Write it out. diff --git a/lib-src/libnyquist/nyquist/ffts/src/fftlib.c b/lib-src/libnyquist/nyquist/ffts/src/fftlib.c index d832f8957..b310d00f1 100644 --- a/lib-src/libnyquist/nyquist/ffts/src/fftlib.c +++ b/lib-src/libnyquist/nyquist/ffts/src/fftlib.c @@ -1,6 +1,8 @@ /******************************************************************* lower level fft stuff including routines called in fftext.c and fft2d.c *******************************************************************/ +/* inline declarations modified by RBD for C99 compiler */ + #include "fftlib.h" #include #define MCACHE (11-(sizeof(float)/8)) // fft's with M bigger than this bust primary cache @@ -61,8 +63,8 @@ for (i1 = 0; i1 < Nroot_1; i1++){ parts of ffts1 *************************************************/ -inline void bitrevR2(float *ioptr, long M, short *BRLow); -inline void bitrevR2(float *ioptr, long M, short *BRLow){ +//inline void bitrevR2(float *ioptr, long M, short *BRLow); +static inline void bitrevR2(float *ioptr, long M, short *BRLow){ /*** bit reverse and first radix 2 stage of forward or inverse fft ***/ float f0r; float f0i; @@ -198,8 +200,8 @@ for (; ioptr < iolimit; ioptr += POW2(M/2+1)){ }; } -inline void fft2pt(float *ioptr); -inline void fft2pt(float *ioptr){ +//inline void fft2pt(float *ioptr); +static inline void fft2pt(float *ioptr){ /*** RADIX 2 fft ***/ float f0r, f0i, f1r, f1i; float t0r, t0i; @@ -229,8 +231,8 @@ ioptr[3] = f1i; } -inline void fft4pt(float *ioptr); -inline void fft4pt(float *ioptr){ +//inline void fft4pt(float *ioptr); +static inline void fft4pt(float *ioptr){ /*** RADIX 4 fft ***/ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; float t0r, t0i, t1r, t1i; @@ -284,8 +286,8 @@ ioptr[6] = f3r; ioptr[7] = f3i; } -inline void fft8pt(float *ioptr); -inline void fft8pt(float *ioptr){ +//inline void fft8pt(float *ioptr); +static inline void fft8pt(float *ioptr){ /*** RADIX 8 fft ***/ float w0r = 1.0/MYROOT2; /* cos(pi/4) */ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; @@ -403,8 +405,8 @@ ioptr[14] = f6r; ioptr[15] = f6i; } -inline void bfR2(float *ioptr, long M, long NDiffU); -inline void bfR2(float *ioptr, long M, long NDiffU){ +//inline void bfR2(float *ioptr, long M, long NDiffU); +static inline void bfR2(float *ioptr, long M, long NDiffU){ /*** 2nd radix 2 stage ***/ unsigned long pos; unsigned long posi; @@ -512,8 +514,8 @@ for (SameUCnt = NSameU; SameUCnt > 0 ; SameUCnt--){ } } -inline void bfR4(float *ioptr, long M, long NDiffU); -inline void bfR4(float *ioptr, long M, long NDiffU){ +//inline void bfR4(float *ioptr, long M, long NDiffU); +static inline void bfR4(float *ioptr, long M, long NDiffU){ /*** 1 radix 4 stage ***/ unsigned long pos; unsigned long posi; @@ -721,8 +723,8 @@ f4i = f4i * Two - f6i; } -inline void bfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt); -inline void bfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt){ +// inline void bfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt); +static inline void bfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt){ /*** RADIX 8 Stages ***/ unsigned long pos; unsigned long posi; @@ -1125,8 +1127,8 @@ default: parts of iffts1 *************************************************/ -inline void scbitrevR2(float *ioptr, long M, short *BRLow, float scale); -inline void scbitrevR2(float *ioptr, long M, short *BRLow, float scale){ +// inline void scbitrevR2(float *ioptr, long M, short *BRLow, float scale); +static inline void scbitrevR2(float *ioptr, long M, short *BRLow, float scale){ /*** scaled bit reverse and first radix 2 stage forward or inverse fft ***/ float f0r; float f0i; @@ -1262,8 +1264,8 @@ for (; ioptr < iolimit; ioptr += POW2(M/2+1)){ }; } -inline void ifft2pt(float *ioptr, float scale); -inline void ifft2pt(float *ioptr, float scale){ +//inline void ifft2pt(float *ioptr, float scale); +static inline void ifft2pt(float *ioptr, float scale){ /*** RADIX 2 ifft ***/ float f0r, f0i, f1r, f1i; float t0r, t0i; @@ -1292,8 +1294,8 @@ ioptr[2] = scale*f1r; ioptr[3] = scale*f1i; } -inline void ifft4pt(float *ioptr, float scale); -inline void ifft4pt(float *ioptr, float scale){ +// inline void ifft4pt(float *ioptr, float scale); +static inline void ifft4pt(float *ioptr, float scale){ /*** RADIX 4 ifft ***/ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; float t0r, t0i, t1r, t1i; @@ -1347,8 +1349,8 @@ ioptr[6] = scale*f3r; ioptr[7] = scale*f3i; } -inline void ifft8pt(float *ioptr, float scale); -inline void ifft8pt(float *ioptr, float scale){ +//inline void ifft8pt(float *ioptr, float scale); +static inline void ifft8pt(float *ioptr, float scale){ /*** RADIX 8 ifft ***/ float w0r = 1.0/MYROOT2; /* cos(pi/4) */ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; @@ -1467,8 +1469,8 @@ ioptr[14] = scale*f6r; ioptr[15] = scale*f6i; } -inline void ibfR2(float *ioptr, long M, long NDiffU); -inline void ibfR2(float *ioptr, long M, long NDiffU){ +//inline void ibfR2(float *ioptr, long M, long NDiffU); +static inline void ibfR2(float *ioptr, long M, long NDiffU){ /*** 2nd radix 2 stage ***/ unsigned long pos; unsigned long posi; @@ -1576,8 +1578,8 @@ for (SameUCnt = NSameU; SameUCnt > 0 ; SameUCnt--){ } } -inline void ibfR4(float *ioptr, long M, long NDiffU); -inline void ibfR4(float *ioptr, long M, long NDiffU){ +//inline void ibfR4(float *ioptr, long M, long NDiffU); +static inline void ibfR4(float *ioptr, long M, long NDiffU){ /*** 1 radix 4 stage ***/ unsigned long pos; unsigned long posi; @@ -1785,8 +1787,8 @@ f4i = f4i * Two - f6i; } -inline void ibfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt); -inline void ibfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt){ +//inline void ibfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt); +static inline void ibfstages(float *ioptr, long M, float *Utbl, long Ustride, long NDiffU, long StageCnt){ /*** RADIX 8 Stages ***/ unsigned long pos; unsigned long posi; @@ -2193,8 +2195,8 @@ default: parts of rffts1 *************************************************/ -inline void rfft1pt(float *ioptr); -inline void rfft1pt(float *ioptr){ +//inline void rfft1pt(float *ioptr); +static inline void rfft1pt(float *ioptr){ /*** RADIX 2 rfft ***/ float f0r, f0i; float t0r, t0i; @@ -2212,8 +2214,8 @@ ioptr[0] = t0r; ioptr[1] = t0i; } -inline void rfft2pt(float *ioptr); -inline void rfft2pt(float *ioptr){ +//inline void rfft2pt(float *ioptr); +static inline void rfft2pt(float *ioptr){ /*** RADIX 4 rfft ***/ float f0r, f0i, f1r, f1i; float t0r, t0i; @@ -2245,8 +2247,8 @@ ioptr[2] = f1r; ioptr[3] = f1i; } -inline void rfft4pt(float *ioptr); -inline void rfft4pt(float *ioptr){ +//inline void rfft4pt(float *ioptr); +static inline void rfft4pt(float *ioptr){ /*** RADIX 8 rfft ***/ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; float t0r, t0i, t1r, t1i; @@ -2318,8 +2320,8 @@ ioptr[6] = scale*f3r; ioptr[7] = scale*f3i; } -inline void rfft8pt(float *ioptr); -inline void rfft8pt(float *ioptr){ +//inline void rfft8pt(float *ioptr); +static inline void rfft8pt(float *ioptr){ /*** RADIX 16 rfft ***/ float w0r = 1.0/MYROOT2; /* cos(pi/4) */ float w1r = MYCOSPID8; /* cos(pi/8) */ @@ -2477,8 +2479,8 @@ ioptr[14] = scale*f6r; ioptr[15] = scale*f6i; } -inline void frstage(float *ioptr, long M, float *Utbl); -inline void frstage(float *ioptr, long M, float *Utbl){ +//inline void frstage(float *ioptr, long M, float *Utbl); +static inline void frstage(float *ioptr, long M, float *Utbl){ /* Finish RFFT */ unsigned long pos; @@ -2687,8 +2689,8 @@ default: parts of riffts1 *************************************************/ -inline void rifft1pt(float *ioptr, float scale); -inline void rifft1pt(float *ioptr, float scale){ +//inline void rifft1pt(float *ioptr, float scale); +static inline void rifft1pt(float *ioptr, float scale){ /*** RADIX 2 rifft ***/ float f0r, f0i; float t0r, t0i; @@ -2706,8 +2708,8 @@ ioptr[0] = scale*t0r; ioptr[1] = scale*t0i; } -inline void rifft2pt(float *ioptr, float scale); -inline void rifft2pt(float *ioptr, float scale){ +//inline void rifft2pt(float *ioptr, float scale); +static inline void rifft2pt(float *ioptr, float scale){ /*** RADIX 4 rifft ***/ float f0r, f0i, f1r, f1i; float t0r, t0i; @@ -2740,8 +2742,8 @@ ioptr[2] = scale*f1r; ioptr[3] = scale*f1i; } -inline void rifft4pt(float *ioptr, float scale); -inline void rifft4pt(float *ioptr, float scale){ +//inline void rifft4pt(float *ioptr, float scale); +static inline void rifft4pt(float *ioptr, float scale){ /*** RADIX 8 rifft ***/ float f0r, f0i, f1r, f1i, f2r, f2i, f3r, f3i; float t0r, t0i, t1r, t1i; @@ -2811,8 +2813,8 @@ ioptr[6] = scale*f3r; ioptr[7] = scale*f3i; } -inline void rifft8pt(float *ioptr, float scale); -inline void rifft8pt(float *ioptr, float scale){ +//inline void rifft8pt(float *ioptr, float scale); +static inline void rifft8pt(float *ioptr, float scale){ /*** RADIX 16 rifft ***/ float w0r = 1.0/MYROOT2; /* cos(pi/4) */ float w1r = MYCOSPID8; /* cos(pi/8) */ @@ -2968,8 +2970,8 @@ ioptr[14] = scale*f6r; ioptr[15] = scale*f6i; } -inline void ifrstage(float *ioptr, long M, float *Utbl); -inline void ifrstage(float *ioptr, long M, float *Utbl){ +//inline void ifrstage(float *ioptr, long M, float *Utbl); +static inline void ifrstage(float *ioptr, long M, float *Utbl){ /* Start RIFFT */ unsigned long pos; diff --git a/lib-src/libnyquist/nyquist/nyqsrc/add.c b/lib-src/libnyquist/nyquist/nyqsrc/add.c index 267be4862..ec5b31333 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/add.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/add.c @@ -59,17 +59,9 @@ factor, ADD will create a rescaling of the operand. /* #define GC_DEBUG 1 */ -void add_s1_s2_nn_fetch(add_susp_type, snd_list_type); -void add_s1_nn_fetch(add_susp_type, snd_list_type); -void add_s2_nn_fetch(add_susp_type, snd_list_type); -void add_zero_fill_nn_fetch(add_susp_type, snd_list_type); -void add_free(); - - -void add_s1_s2_nn_fetch(susp, snd_list) - register add_susp_type susp; - snd_list_type snd_list; +void add_s1_s2_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + add_susp_type susp = (add_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -126,7 +118,7 @@ A if (susp->terminate_bits & 2) { * if a sound has terminated) */ A nyquist_printf( - "add[%p,%p] (s1_s2_nn) %p: logically_stopped %d, logical_stop_cnt %d, s1 logical_stop_cnt %d, s2 logical_stop_cnt %d \n", + "add[%p,%p] (s1_s2_nn) %p: logically_stopped %d, logical_stop_cnt %d, s1 logical_stop_cnt %ld, s2 logical_stop_cnt %ld \n", susp->s1, susp->s2, susp, susp->logically_stopped, (int) susp->susp.log_stop_cnt, susp->s1->logical_stop_cnt, @@ -173,7 +165,7 @@ A nyquist_printf("add[%p,%p] (s1_s2_nn) %p starting inner loop, n %d\n", out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ /* scale? */ -A nyquist_printf("add_s1_s2_nn: %g + %g\n", *s1_ptr_reg, *s2_ptr_reg); +/*A nyquist_printf("add_s1_s2_nn: %g + %g\n", *s1_ptr_reg, *s2_ptr_reg); */ *out_ptr_reg++ = *(s1_ptr_reg++) + *(s2_ptr_reg++); } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000 */ @@ -238,7 +230,7 @@ D nyquist_printf("add_s1_s2_nn_fetch: add_s2_nn_fetch installed\n"); if (cnt == 0) { D nyquist_printf("add[%p,%p]: calling add_s2_nn_fetch\n", susp->s1, susp->s2); - add_s2_nn_fetch(susp, snd_list); + add_s2_nn_fetch(a_susp, snd_list); } } else if (susp->terminate_bits & 2) { @@ -251,7 +243,7 @@ D stdputstr("add_s1_s2_nn_fetch: add_s1_nn_fetch installed\n"); if (cnt == 0) { D nyquist_printf("add[%p,%p]: calling add_s1_nn_fetch\n", susp->s1, susp->s2); - add_s1_nn_fetch(susp, snd_list); + add_s1_nn_fetch(a_susp, snd_list); } } @@ -267,10 +259,9 @@ D nyquist_printf("add[%p,%p]: calling add_s1_nn_fetch\n", * They should probably be made into one routine, but for now, * any changes to one should be made to the other. */ -void add_s1_nn_fetch(susp, snd_list) - register add_susp_type susp; - snd_list_type snd_list; +void add_s1_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + add_susp_type susp = (add_susp_type) a_susp; /* expansion of add_s_nn_fetch(snd_list,s1,s2,1); follows: */ int togo, s2_start=0; int n; @@ -314,7 +305,7 @@ B if (togo == 0) stdputstr("togo is zero at checkpoint 2\n"); susp->s1 = NULL; susp->susp.fetch = add_s2_nn_fetch; D stdputstr("add_s_nn_fetch: other installed, calling now...\n"); - add_s2_nn_fetch(susp, snd_list); + add_s2_nn_fetch(a_susp, snd_list); } else if (susp->s2 && susp->susp.current < s2_start) { /* s2 not started and s1 stops */ /* go to zero-fill state */ @@ -322,7 +313,7 @@ D stdputstr("add_s_nn_fetch: other installed, calling now...\n"); susp->s1 = NULL; susp->susp.fetch = add_zero_fill_nn_fetch; B stdputstr("add_s_nn_fetch: zero_fill installed\n"); - add_zero_fill_nn_fetch(susp, snd_list); + add_zero_fill_nn_fetch(a_susp, snd_list); } else if (susp->s2) { D stdputstr("add_s_nn_fetch: unexpected condition\n"); EXIT(1); @@ -391,7 +382,7 @@ B if (togo == 0) stdputstr("togo is zero at checkpoint 4\n"); snd_list->block_len = togo; /* if other is terminated and sound_types match, collapse */ - /* NOTE: in order to collapse, we need s2 to be generating + /* NOTE: in order to collapse, we need s1 to be generating * blocks and linking them onto a sound list. This is true * when the get_next fn is SND_get_next. (A counterexample is * SND_get_zeros, which returns zero blocks but does not link @@ -493,10 +484,9 @@ D { } -void add_s2_nn_fetch(susp, snd_list) - register add_susp_type susp; - snd_list_type snd_list; +void add_s2_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + add_susp_type susp = (add_susp_type) a_susp; int togo, s1_start=0; int n; sample_block_type out; @@ -537,7 +527,7 @@ D nyquist_printf("add_s2_nn_fetch(susp %p, snd_list %p)\n", susp->s2 = NULL; susp->susp.fetch = add_s1_nn_fetch; D stdputstr("add_s_nn_fetch: other installed, calling now...\n"); - add_s1_nn_fetch(susp, snd_list); + add_s1_nn_fetch(a_susp, snd_list); } else if (susp->s1 && susp->susp.current < s1_start) { /* s1 not started and s2 stops */ /* go to zero-fill state */ @@ -545,7 +535,7 @@ D stdputstr("add_s_nn_fetch: other installed, calling now...\n"); susp->s2 = NULL; susp->susp.fetch = add_zero_fill_nn_fetch; D stdputstr("add_s_nn_fetch: zero_fill installed\n"); - add_zero_fill_nn_fetch(susp, snd_list); + add_zero_fill_nn_fetch(a_susp, snd_list); } else if (susp->s1) { D stdputstr("add_s_nn_fetch: unexpected condition\n"); EXIT(1); @@ -565,13 +555,12 @@ D nyquist_printf("add_s_nn_fetch: special return, susp %p\n", susp); /* check if we've seen the logical stop from s2. If so then log_stop_cnt is max of s1 and s2 stop times */ (susp->logical_stop_bits & 2)) { - /* (some compilers don't like statements before declarations) -D nyquist_printf("add_s2_nn_fetch: susp->susp.log_stop_cnt %d\n", + int to_stop; +D nyquist_printf("add_s2_nn_fetch: susp->susp.log_stop_cnt %ld\n", susp->susp.log_stop_cnt); -D nyquist_printf("add_s2_nn_fetch: susp->susp.current %d\n", +D nyquist_printf("add_s2_nn_fetch: susp->susp.current %ld\n", susp->susp.current); - */ - int to_stop = susp->susp.log_stop_cnt - susp->susp.current; + to_stop = susp->susp.log_stop_cnt - susp->susp.current; // to_stop can be less than zero if we've been adding in sounds with // t0 less than the time when the sound is added. E.g. if the user // wants a sequence of two sounds that start at 0, the second sound @@ -636,7 +625,7 @@ D nyquist_printf("add[%p,%p] (s%d_nn) %p shared block %p zero_block %p\n",susp-> snd_list->block_len = togo; /* if other is terminated and sound_types match, collapse */ - /* NOTE: in order to collapse, we need s1 to be generating + /* NOTE: in order to collapse, we need s2 to be generating * blocks and linking them onto a sound list. This is true * when the get_next fn is SND_get_next. (A counterexample is * SND_get_zeros, which returns zero blocks but does not link @@ -650,9 +639,9 @@ D nyquist_printf("add[%p,%p] (s%d_nn) %p shared block %p zero_block %p\n",susp-> susp->s2->get_next == SND_get_next && susp->s2->logical_stop_cnt == UNKNOWN) { snd_list_type addend_list; -D nyquist_printf("add[%p,%p]: collapsing! LSC %d\n", +D nyquist_printf("add[%p,%p]: collapsing! LSC %d\n", susp->s2, susp->s1, (int)susp->s2->logical_stop_cnt); -D sound_print_tree(susp->s2); +D sound_print_tree(susp->s2); /* will "current" values match? */ /* test for logical stop */ if (susp->logically_stopped) { @@ -667,6 +656,9 @@ D sound_print_tree(susp->s2); snd_list_unref(snd_list->u.next); snd_list->u.next = addend_list; return; + } else { +D nyquist_printf("s1 == NULL, but no collapse, lsc %ld\n", + susp->s2->logical_stop_cnt); } } else { /* @@ -746,10 +738,9 @@ D stdputstr("add_s_nn_fetch: susp->logically_stopped\n"); -void add_zero_fill_nn_fetch(susp, snd_list) - register add_susp_type susp; - snd_list_type snd_list; +void add_zero_fill_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + add_susp_type susp = (add_susp_type) a_susp; int togo, s_start=0; #ifdef GC_DEBUG @@ -790,16 +781,18 @@ D stdputstr("add_zero_fill_nn_fetch: add_s2_nn_fetch installed\n"); } /* add_zero_fill_nn_fetch */ -void add_free(add_susp_type susp) +void add_free(snd_susp_type a_susp) { + add_susp_type susp = (add_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->s2); ffree_generic(susp, sizeof(add_susp_node), "add_free"); } -void add_mark(add_susp_type susp) +void add_mark(snd_susp_type a_susp) { + add_susp_type susp = (add_susp_type) a_susp; /* nyquist_printf("add_mark(%p)\n", susp);*/ /* nyquist_printf("marking s1@%p in add@%p\n", susp->s1, susp);*/ sound_xlmark(susp->s1); @@ -809,8 +802,9 @@ void add_mark(add_susp_type susp) } -void add_print_tree(add_susp_type susp, int n) +void add_print_tree(snd_susp_type a_susp, int n) { + add_susp_type susp = (add_susp_type) a_susp; indent(n); nyquist_printf("logically_stopped %d logical_stop_bits %d terminate_bits %d\n", susp->logically_stopped, susp->logical_stop_bits, susp->terminate_bits); @@ -826,9 +820,7 @@ void add_print_tree(add_susp_type susp, int n) } -sound_type snd_make_add(s1, s2) - sound_type s1; - sound_type s2; +sound_type snd_make_add(sound_type s1, sound_type s2) { register add_susp_type susp; rate_type sr = MAX(s1->sr, s2->sr); @@ -906,13 +898,10 @@ D stdputstr("snd_make_add: add_s1_s2_nn_fetch installed\n"); } -sound_type snd_add(s1, s2, t0) - sound_type s1; - sound_type s2; - time_type t0; +sound_type snd_add(sound_type s1, sound_type s2) { sound_type s1_copy = sound_copy(s1); sound_type s2_copy = sound_copy(s2); /* nyquist_printf("snd_add %p %p copied to %p %p\n", s1, s2, s1_copy, s2_copy); */ - return snd_make_add(s1_copy, s2_copy, t0); + return snd_make_add(s1_copy, s2_copy); } diff --git a/lib-src/libnyquist/nyquist/nyqsrc/add.h b/lib-src/libnyquist/nyquist/nyqsrc/add.h index e1835ac83..673796051 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/add.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/add.h @@ -30,15 +30,15 @@ typedef struct add_susp_struct { long s1_prepend; /* offset to susp.current */ } add_susp_node, *add_susp_type; -sound_type snd_make_add(); -sound_type snd_add(); +sound_type snd_make_add(sound_type s1, sound_type s2); +sound_type snd_add(sound_type s1, sound_type s2); /* LISP: (SND-ADD SOUND SOUND) */ /* we export these for seq.c and multiseq.c */ -void add_zero_fill_nn_fetch(add_susp_type susp, snd_list_type snd_list); -void add_s1_s2_nn_fetch(add_susp_type susp, snd_list_type snd_list); -void add_s2_nn_fetch(add_susp_type susp, snd_list_type snd_list); -void add_s1_nn_fetch(add_susp_type susp, snd_list_type snd_list); -void add_mark(add_susp_type susp); -void add_print_tree(add_susp_type susp, int n); -void add_free(add_susp_type susp); +void add_zero_fill_nn_fetch(snd_susp_type, snd_list_type); +void add_s1_s2_nn_fetch(snd_susp_type, snd_list_type); +void add_s1_nn_fetch(snd_susp_type, snd_list_type); +void add_s2_nn_fetch(snd_susp_type, snd_list_type); +void add_mark(snd_susp_type susp); +void add_print_tree(snd_susp_type susp, int n); +void add_free(snd_susp_type susp); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/avg.c b/lib-src/libnyquist/nyquist/nyqsrc/avg.c index be1b574d1..a6b308ce3 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/avg.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/avg.c @@ -73,8 +73,9 @@ sample_type peak_block(avg_susp_type susp) } -void avg_s_fetch(avg_susp_type susp, snd_list_type snd_list) +void avg_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + avg_susp_type susp = (avg_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo = 0; int n; @@ -164,10 +165,9 @@ void avg_s_fetch(avg_susp_type susp, snd_list_type snd_list) } /* avg_s_fetch */ -void avg_toss_fetch(susp, snd_list) - avg_susp_type susp; - snd_list_type snd_list; +void avg_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + avg_susp_type susp = (avg_susp_type) a_susp; long final_count = MIN(susp->susp.current + max_sample_block_len, susp->susp.toss_cnt); time_type final_time = susp->susp.t0 + final_count / susp->susp.sr; @@ -193,22 +193,25 @@ void avg_toss_fetch(susp, snd_list) } -void avg_mark(avg_susp_type susp) +void avg_mark(snd_susp_type a_susp) { + avg_susp_type susp = (avg_susp_type) a_susp; sound_xlmark(susp->s); } -void avg_free(avg_susp_type susp) +void avg_free(snd_susp_type a_susp) { + avg_susp_type susp = (avg_susp_type) a_susp; sound_unref(susp->s); free(susp->buffer); ffree_generic(susp, sizeof(avg_susp_node), "avg_free"); } -void avg_print_tree(avg_susp_type susp, int n) +void avg_print_tree(snd_susp_type a_susp, int n) { + avg_susp_type susp = (avg_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/compose.c b/lib-src/libnyquist/nyquist/nyqsrc/compose.c index a15fe3439..564116bf5 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/compose.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/compose.c @@ -36,8 +36,9 @@ typedef struct compose_susp_struct { /* compose_fetch -- computes f(g(t)) */ /**/ -void compose_fetch(register compose_susp_type susp, snd_list_type snd_list) +void compose_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + compose_susp_type susp = (compose_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo = 0; int n; @@ -173,10 +174,9 @@ f_out_of_samples: } /* compose_fetch */ -void compose_toss_fetch(susp, snd_list) - register compose_susp_type susp; - snd_list_type snd_list; +void compose_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + compose_susp_type susp = (compose_susp_type) a_susp; long final_count = MIN(susp->susp.current + max_sample_block_len, susp->susp.toss_cnt); time_type final_time = susp->susp.t0 + final_count / susp->susp.sr; @@ -210,23 +210,26 @@ void compose_toss_fetch(susp, snd_list) } -void compose_mark(compose_susp_type susp) +void compose_mark(snd_susp_type a_susp) { + compose_susp_type susp = (compose_susp_type) a_susp; sound_xlmark(susp->f); sound_xlmark(susp->g); } -void compose_free(compose_susp_type susp) +void compose_free(snd_susp_type a_susp) { + compose_susp_type susp = (compose_susp_type) a_susp; sound_unref(susp->f); sound_unref(susp->g); ffree_generic(susp, sizeof(compose_susp_node), "compose_free"); } -void compose_print_tree(compose_susp_type susp, int n) +void compose_print_tree(snd_susp_type a_susp, int n) { + compose_susp_type susp = (compose_susp_type) a_susp; indent(n); stdputstr("f:"); sound_print_tree_1(susp->f, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/convolve.c b/lib-src/libnyquist/nyquist/nyqsrc/convolve.c index e234171c9..fc287d2c0 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/convolve.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/convolve.c @@ -6,6 +6,34 @@ * of the first parameter. */ +/* Original convolve.c modified to do fast convolution. Here are some + * notes: + * The first arg is arbitrary length. The second arg is the impulse + * response, which is converted into a table. Tables have limited maximum + * size, which is good because we're going to use a single FFT for the + * whole impulse response. + * + * The fast convolution works like this: + * inputs are x_snd and h_snd. + * Make h_snd into a table ht of size N, where N is a power of 2. + * Copy ht with zero fill into H of size 2N. + * Compute FFT of H in place. + * Iterate: + * Copy N samples of x_snd into X and zero fill to size 2N. + * Compute FFT of X in place. + * Multiply X by H (result goes into X). + * Compute IFFT of X in place + * Add X to R. + * Now N samples of R can be output. + * Copy 2nd half of R to first half and zero the 2nd half. + * (this is actually done first, and the first time does + * nothing because R is initially filled with zeros) + * + * Length of output is length of x input + length of h + */ + +#define _USE_MATH_DEFINES 1 /* for Visual C++ to get M_LN2 */ +#include #include "stdio.h" #ifndef mips #include "stdlib.h" @@ -15,6 +43,8 @@ #include "falloc.h" #include "cext.h" +#include "fftlib.h" +#include "fftext.h" #include "convolve.h" void convolve_free(); @@ -28,13 +58,13 @@ typedef struct convolve_susp_struct { long x_snd_cnt; sample_block_values_type x_snd_ptr; - table_type table; - sample_type *h_buf; - double length_of_h; - long h_len; - long x_buf_len; - sample_type *x_buffer_pointer; - sample_type *x_buffer_current; + sample_type *H; // the FFT of h_snd + int h_len; // true length of H + int N; // length of block, FFTs are of size 2*N + int M; // log2 of 2*N, the FFT size + sample_type *X; + sample_type *R; // result buffer where output is summed + sample_type *R_current; } convolve_susp_node, *convolve_susp_type; @@ -52,8 +82,9 @@ void h_reverse(sample_type *h, long len) } -void convolve_s_fetch(register convolve_susp_type susp, snd_list_type snd_list) +void convolve_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + convolve_susp_type susp = (convolve_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -62,152 +93,118 @@ void convolve_s_fetch(register convolve_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; - register sample_type * h_buf_reg; - register long h_len_reg; - register long x_buf_len_reg; - register sample_type * x_buffer_pointer_reg; - register sample_type * x_buffer_current_reg; - register sample_type x_snd_scale_reg = susp->x_snd->scale; - register sample_block_values_type x_snd_ptr_reg; + sample_type *R = susp->R; + sample_type *R_current; + int N = susp->N; falloc_sample_block(out, "convolve_s_fetch"); out_ptr = out->samples; snd_list->block = out; while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the x_snd input sample block: */ - /* based on susp_check_term_log_samples, but offset by h_len */ - - /* THIS IS EXPANDED BELOW - * susp_check_term_log_samples(x_snd, x_snd_ptr, x_snd_cnt); - */ - if (susp->x_snd_cnt == 0) { - susp_get_samples(x_snd, x_snd_ptr, x_snd_cnt); - - /* THIS IS EXPANDED BELOW - *logical_stop_test(x_snd, susp->x_snd_cnt); - */ - if (susp->x_snd->logical_stop_cnt == - susp->x_snd->current - susp->x_snd_cnt) { - min_cnt(&susp->susp.log_stop_cnt, susp->x_snd, - (snd_susp_type) susp, susp->x_snd_cnt); - } - - /* THIS IS EXPANDED BELOW - * terminate_test(x_snd_ptr, x_snd, susp->x_snd_cnt); - */ - if (susp->x_snd_ptr == zero_block->samples) { - /* ### modify this to terminate at an offset of (susp->h_len) */ - /* Note: in the min_cnt function, susp->x_snd_cnt is *subtracted* - * from susp->x_snd->current to form the terminate time, so to - * increase the time, we need to *subtract* susp->h_len, which - * due to the double negative, *adds* susp->h_len to the ultimate - * terminate time calculation. + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + /* if we need output samples, generate them here */ + if (susp->R_current >= R + N) { + /* Copy N samples of x_snd into X and zero fill to size 2N */ + int i = 0; + sample_type *X = susp->X; + sample_type *H = susp->H; + int to_copy; + while (i < N) { + if (susp->x_snd_cnt == 0) { + susp_get_samples(x_snd, x_snd_ptr, x_snd_cnt); + if (susp->x_snd->logical_stop_cnt == + susp->x_snd->current - susp->x_snd_cnt) { + min_cnt(&susp->susp.log_stop_cnt, susp->x_snd, + (snd_susp_type) susp, susp->x_snd_cnt); + } + } + if (susp->x_snd_ptr == zero_block->samples) { + min_cnt(&susp->terminate_cnt, susp->x_snd, + (snd_susp_type) susp, susp->x_snd_cnt); + /* extend the output to include impulse response */ + susp->terminate_cnt += susp->h_len; + } + /* copy no more than the remaining space and no more than + * the amount remaining in the block */ - min_cnt(&susp->terminate_cnt, susp->x_snd, - (snd_susp_type) susp, susp->x_snd_cnt - susp->h_len); - } - } - - - togo = min(togo, susp->x_snd_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - h_buf_reg = susp->h_buf; - h_len_reg = susp->h_len; - x_buf_len_reg = susp->x_buf_len; - x_buffer_pointer_reg = susp->x_buffer_pointer; - x_buffer_current_reg = susp->x_buffer_current; - x_snd_ptr_reg = susp->x_snd_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - long i; double sum; - /* see if we've reached end of x_buffer */ - if ((x_buffer_pointer_reg + x_buf_len_reg) <= (x_buffer_current_reg + h_len_reg)) { - /* shift x_buffer from current back to base */ - for (i = 1; i < h_len_reg; i++) { - x_buffer_pointer_reg[i-1] = x_buffer_current_reg[i]; - } - /* this will be incremented back to x_buffer_pointer_reg below */ - x_buffer_current_reg = x_buffer_pointer_reg - 1; + to_copy = min(N - i, susp->x_snd_cnt); + memcpy(X + i, susp->x_snd_ptr, + to_copy * sizeof(*susp->x_snd_ptr)); + susp->x_snd_ptr += to_copy; + susp->x_snd_cnt -= to_copy; + i += to_copy; } - - x_buffer_current_reg++; - - x_buffer_current_reg[h_len_reg - 1] = (x_snd_scale_reg * *x_snd_ptr_reg++); - - sum = 0.0; - for (i = 0; i < h_len_reg; i++) { - sum += x_buffer_current_reg[i] * h_buf_reg[i]; + /* zero fill to size 2N */ + memset(X + N, 0, N * sizeof(X[0])); + /* Compute FFT of X in place */ + fftInit(susp->M); + rffts(X, susp->M, 1); + /* Multiply X by H (result goes into X) */ + rspectprod(X, H, X, N * 2); + /* Compute IFFT of X in place */ + riffts(X, susp->M, 1); + /* Shift R, zero fill, add X, all in one loop */ + for (i = 0; i < N; i++) { + R[i] = R[i + N] + X[i]; + R[i + N] = X[i + N]; } + /* now N samples of R can be output */ + susp->R_current = R; + } + /* compute togo, the number of samples to "compute" */ + /* can't use more than what's left in R. R_current is + the next sample of R, so what's left is N - (R - R_current) */ + R_current = susp->R_current; + togo = min(togo, N - (R_current - R)); - *out_ptr_reg++ = (sample_type) sum; - } while (--n); /* inner loop */ + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } - susp->x_buffer_pointer = x_buffer_pointer_reg; - susp->x_buffer_current = x_buffer_current_reg; - /* using x_snd_ptr_reg is a bad idea on RS/6000: */ - susp->x_snd_ptr += togo; - out_ptr += togo; - susp_took(x_snd_cnt, togo); - cnt += togo; + /* don't run past logical stop time */ + if (!susp->logically_stopped && + susp->susp.log_stop_cnt != UNKNOWN && + susp->susp.log_stop_cnt <= susp->susp.current + cnt + togo) { + togo = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } + + n = togo; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = (sample_type) *R_current++; + } while (--n); /* inner loop */ + + /* using R_current is a bad idea on RS/6000: */ + susp->R_current += togo; + out_ptr += togo; + cnt += togo; } /* outer loop */ /* test for termination */ if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); + snd_list_terminate(snd_list); } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; + snd_list->block_len = cnt; + susp->susp.current += cnt; } /* test for logical stop */ if (susp->logically_stopped) { - snd_list->logically_stopped = true; + snd_list->logically_stopped = true; } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; + susp->logically_stopped = true; } } /* convolve_s_fetch */ -void convolve_toss_fetch(susp, snd_list) - register convolve_susp_type susp; - snd_list_type snd_list; +void convolve_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + convolve_susp_type susp = (convolve_susp_type) susp; time_type final_time = susp->susp.t0; long n; @@ -218,36 +215,40 @@ void convolve_toss_fetch(susp, snd_list) /* convert to normal processing when we hit final_count */ /* we want each signal positioned at final_time */ n = round((final_time - susp->x_snd->t0) * susp->x_snd->sr - - (susp->x_snd->current - susp->x_snd_cnt)); + (susp->x_snd->current - susp->x_snd_cnt)); susp->x_snd_ptr += n; susp_took(x_snd_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void convolve_mark(convolve_susp_type susp) +void convolve_mark(snd_susp_type a_susp) { + convolve_susp_type susp = (convolve_susp_type) a_susp; sound_xlmark(susp->x_snd); } -void convolve_free(convolve_susp_type susp) +void convolve_free(snd_susp_type a_susp) { - table_unref(susp->table); - free(susp->x_buffer_pointer); sound_unref(susp->x_snd); + convolve_susp_type susp = (convolve_susp_type) a_susp; + free(susp->R); + free(susp->X); + free(susp->H); + sound_unref(susp->x_snd); ffree_generic(susp, sizeof(convolve_susp_node), "convolve_free"); } -void convolve_print_tree(convolve_susp_type susp, int n) +void convolve_print_tree(snd_susp_type a_susp, int n) { + convolve_susp_type susp = (convolve_susp_type) a_susp; indent(n); stdputstr("x_snd:"); sound_print_tree_1(susp->x_snd, n); } - sound_type snd_make_convolve(sound_type x_snd, sound_type h_snd) { register convolve_susp_type susp; @@ -255,16 +256,38 @@ sound_type snd_make_convolve(sound_type x_snd, sound_type h_snd) time_type t0 = x_snd->t0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + table_type table; + double log_len; falloc_generic(susp, convolve_susp_node, "snd_make_convolve"); - susp->table = sound_to_table(h_snd); - susp->h_buf = susp->table->samples; - susp->length_of_h = susp->table->length; - susp->h_len = (long) susp->length_of_h; - h_reverse(susp->h_buf, susp->h_len); - susp->x_buf_len = 2 * susp->h_len; - susp->x_buffer_pointer = calloc((2 * (susp->h_len)), sizeof(float)); - susp->x_buffer_current = susp->x_buffer_pointer; - susp->susp.fetch = convolve_s_fetch; + table = sound_to_table(h_snd); + susp->h_len = table->length; + log_len = log(table->length) / M_LN2; /* compute log-base-2(length) */ + susp->M = (int) log_len; + if (susp->M != log_len) susp->M++; /* round up */ + susp->N = 1 << susp->M; /* size of data blocks */ + susp->M++; /* M = log2(2 * N) */ + susp->H = (sample_type *) calloc(2 * susp->N, sizeof(susp->H[0])); + if (!susp->H) { + xlabort("memory allocation failure in convolve"); + } + memcpy(susp->H, table->samples, sizeof(susp->H[0]) * susp->N); + table_unref(table); /* don't need table now */ + /* remaining N samples are already zero-filled */ + if (fftInit(susp->M)) { + free(susp->H); + xlabort("fft initialization error in convolve"); + } + rffts(susp->H, susp->M, 1); + susp->X = (sample_type *) calloc(2 * susp->N, sizeof(susp->X[0])); + susp->R = (sample_type *) calloc(2 * susp->N, sizeof(susp->R[0])); + if (!susp->X || !susp->R) { + free(susp->H); + if (susp->X) free(susp->X); + if (susp->R) free(susp->R); + xlabort("memory allocation failed in convolve"); + } + susp->R_current = susp->R + susp->N; + susp->susp.fetch = &convolve_s_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < x_snd->t0) sound_prepend_zeros(x_snd, t0); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/downsample.c b/lib-src/libnyquist/nyquist/nyqsrc/downsample.c index a796ee5e3..261332983 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/downsample.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/downsample.c @@ -17,7 +17,7 @@ #include "cext.h" #include "downsample.h" -void down_free(); +void down_free(snd_susp_type a_susp); typedef struct down_susp_struct { @@ -40,12 +40,11 @@ typedef struct down_susp_struct { } down_susp_node, *down_susp_type; -void down_n_fetch(susp, snd_list) - register down_susp_type susp; - snd_list_type snd_list; +void down_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + down_susp_type susp = (down_susp_type) a_susp; int cnt = 0; /* how many samples computed */ - int togo = 0; + int togo; int n; sample_block_type out; register sample_block_values_type out_ptr; @@ -76,7 +75,25 @@ void down_n_fetch(susp, snd_list) /* don't run past logical stop time */ if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - if (to_stop < togo && ((togo = to_stop) == 0)) break; + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } } n = togo; @@ -109,12 +126,11 @@ void down_n_fetch(susp, snd_list) } /* down_n_fetch */ -void down_s_fetch(susp, snd_list) - register down_susp_type susp; - snd_list_type snd_list; +void down_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + down_susp_type susp = (down_susp_type) a_susp; int cnt = 0; /* how many samples computed */ - int togo = 0; + int togo; int n; sample_block_type out; register sample_block_values_type out_ptr; @@ -132,6 +148,10 @@ void down_s_fetch(susp, snd_list) /* don't overflow the output sample block: */ togo = max_sample_block_len - cnt; + /* don't run past the s input sample block: */ + susp_check_term_log_samples(s, s_ptr, s_cnt); + togo = min(togo, susp->s_cnt); + /* don't run past terminate time */ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { @@ -142,8 +162,26 @@ void down_s_fetch(susp, snd_list) /* don't run past logical stop time */ if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - if (to_stop < togo && ((togo = to_stop) == 0)) break; - } + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } n = togo; s_ptr_reg = susp->s_ptr; @@ -152,7 +190,8 @@ void down_s_fetch(susp, snd_list) *out_ptr_reg++ = (s_scale_reg * *s_ptr_reg++); } while (--n); /* inner loop */ - susp->s_ptr = s_ptr_reg; + /* using s_ptr_reg is a bad idea on RS/6000: */ + susp->s_ptr += togo; out_ptr += togo; cnt += togo; } /* outer loop */ @@ -173,23 +212,21 @@ void down_s_fetch(susp, snd_list) } /* down_s_fetch */ -void down_i_fetch(susp, snd_list) - register down_susp_type susp; - snd_list_type snd_list; +void down_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + down_susp_type susp = (down_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type s_x2_sample; - int togo = 0; + int togo; int n; sample_block_type out; register sample_block_values_type out_ptr; register sample_block_values_type out_ptr_reg; - register sample_type s_pHaSe_iNcR_rEg = (sample_type) susp->s_pHaSe_iNcR; + register double s_pHaSe_iNcR_rEg = susp->s_pHaSe_iNcR; register double s_pHaSe_ReG; register sample_type s_x1_sample_reg; - falloc_sample_block(out, "down_i_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -222,11 +259,26 @@ void down_i_fetch(susp, snd_list) /* don't run past logical stop time */ if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - if (to_stop < togo && ((togo = to_stop) <= 0)) { - togo = 0; - break; - } - } + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } n = togo; s_pHaSe_ReG = susp->s_pHaSe; @@ -263,7 +315,7 @@ void down_i_fetch(susp, snd_list) s_x2_sample * s_pHaSe_ReG); s_pHaSe_ReG += s_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ -breakout: + breakout: togo -= n; susp->s_pHaSe = s_pHaSe_ReG; susp->s_x1_sample = s_x1_sample_reg; @@ -287,10 +339,9 @@ breakout: } /* down_i_fetch */ -void down_toss_fetch(snd_list) - snd_list_type snd_list; +void down_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - register down_susp_type susp = (down_susp_type) snd_list->u.susp; + down_susp_type susp = (down_susp_type) a_susp; long final_count = MIN(susp->susp.current + max_sample_block_len, susp->susp.toss_cnt); time_type final_time = susp->susp.t0 + final_count / susp->susp.sr; @@ -316,30 +367,31 @@ void down_toss_fetch(snd_list) } -void down_mark(down_susp_type susp) +void down_mark(snd_susp_type a_susp) { + down_susp_type susp = (down_susp_type) a_susp; sound_xlmark(susp->s); } -void down_free(down_susp_type susp) +void down_free(snd_susp_type a_susp) { + down_susp_type susp = (down_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(down_susp_node), "down_free"); } -void down_print_tree(down_susp_type susp, int n) +void down_print_tree(snd_susp_type a_susp, int n) { + down_susp_type susp = (down_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); } -sound_type snd_make_down(sr, s) - rate_type sr; - sound_type s; +sound_type snd_make_down(rate_type sr, sound_type s) { register down_susp_type susp; /* sr specified as input parameter */ @@ -365,13 +417,12 @@ sound_type snd_make_down(sr, s) /* handle unequal start times, if any */ if (t0 < s->t0) sound_prepend_zeros(s, t0); /* minimum start time over all inputs: */ - t0_min = MIN(s->t0, t0); + t0_min = min(s->t0, t0); /* how many samples to toss before t0: */ - susp->susp.toss_cnt = ROUND((t0 - t0_min) * sr); + susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { susp->susp.keep_fetch = susp->susp.fetch; susp->susp.fetch = down_toss_fetch; - t0 = t0_min; } /* initialize susp state */ @@ -395,9 +446,7 @@ sound_type snd_make_down(sr, s) } -sound_type snd_down(sr, s) - rate_type sr; - sound_type s; +sound_type snd_down(rate_type sr, sound_type s) { sound_type s_copy = sound_copy(s); return snd_make_down(sr, s_copy); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/fft.c b/lib-src/libnyquist/nyquist/nyqsrc/fft.c index 95095acf6..6f8b8fb42 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/fft.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/fft.c @@ -93,11 +93,13 @@ LVAL snd_fft(sound_type s, long len, long step, LVAL winval) float *temp_fft; float *window; LVAL result; + float *float_base; if (len < 1) xlfail("len < 1"); if (!s->extra) { /* this is the first call, so fix up s */ sound_type w = NULL; + long bytes = sizeof(long) * OFFSET + sizeof(float) * 3 * len; if (winval) { if (soundp(winval)) { w = getsound(winval); @@ -106,10 +108,9 @@ LVAL snd_fft(sound_type s, long len, long step, LVAL winval) } } /* note: any storage required by fft must be allocated here in a - * contiguous block of memory who's size is given by the first long + * contiguous block of memory whose size is given by the first long * in the block. Here, there are 4 more longs after the size, and - * then room for 3*len floats (assumes that floats and longs take - * equal space). + * then room for 3*len floats * * The reason for 3*len floats is to provide space for: * the samples to be transformed (len) @@ -122,12 +123,15 @@ LVAL snd_fft(sound_type s, long len, long step, LVAL winval) * structure (this could be added in sound.c, however, if it's * really necessary). */ - s->extra = (long *) malloc(sizeof(long) * (3 * len + OFFSET)); - s->extra[0] = sizeof(long) * (3 * len + OFFSET); + + s->extra = (long *) malloc(bytes); + s->extra[0] = bytes; s->CNT = s->INDEX = s->FILLCNT = 0; s->TERMCNT = -1; maxlen = len; - window = (float *) &(s->extra[OFFSET + 2 * len]); + // float_base is where the floats start, after the longs + float_base = (float *) &(s->extra[OFFSET]); + window = float_base + 2 * len; /* fill the window from w */ if (!w) { for (i = 0; i < len; i++) *window++ = 1.0F; @@ -135,12 +139,14 @@ LVAL snd_fft(sound_type s, long len, long step, LVAL winval) n_samples_from_sound(w, len, window); } } else { - maxlen = ((s->extra[0] / sizeof(long)) - OFFSET) / 3; + maxlen = (s->extra[0] - sizeof(long) * OFFSET) / (sizeof(float) * 3); if (maxlen != len) xlfail("len changed from initial value"); + float_base = (float *) &(s->extra[OFFSET]); } - samples = (float *) &(s->extra[OFFSET]); - temp_fft = samples + len; - window = temp_fft + len; + samples = float_base; + temp_fft = float_base + len; + // this code computes window location + window = float_base + 2 * len; /* step 1: refill buffer with samples */ fillptr = s->FILLCNT; while (fillptr < maxlen) { @@ -178,6 +184,9 @@ LVAL snd_fft(sound_type s, long len, long step, LVAL winval) } /* perform the fft: */ m = round(log(len) / M_LN2); /* compute log-base-2(len) */ + if (1 << m != len) { + xlfail("FFT len is not a power of two"); + } if (!fftInit(m)) rffts(temp_fft, m, 1); else xlfail("FFT initialization error"); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/fftw.h b/lib-src/libnyquist/nyquist/nyqsrc/fftw.h index a5acc907f..1ba148a09 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/fftw.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/fftw.h @@ -19,7 +19,7 @@ */ /* fftw.h -- system-wide definitions */ -/* $Id: fftw.h,v 1.2 2009-03-05 16:34:00 llucius Exp $ */ +/* $Id: fftw.h,v 1.1.1.1 2004/11/10 16:07:38 rbd Exp $ */ #ifndef FFTW_H #define FFTW_H diff --git a/lib-src/libnyquist/nyquist/nyqsrc/inverse.c b/lib-src/libnyquist/nyquist/nyqsrc/inverse.c index 1dd757cd5..a1a3a7213 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/inverse.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/inverse.c @@ -34,8 +34,9 @@ typedef struct inverse_susp_struct { boolean started; } inverse_susp_node, *inverse_susp_type; -void inverse_fetch(register inverse_susp_type susp, snd_list_type snd_list) +void inverse_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + inverse_susp_type susp = (inverse_susp_type) a_susp; int cnt = 0; /* how many samples read from s */ int out_cnt = 0; /* how many samples output */ int togo = 0; /* how many more to read from s in inner loop */ @@ -128,10 +129,9 @@ void inverse_fetch(register inverse_susp_type susp, snd_list_type snd_list) } /* inverse_fetch */ -void inverse_toss_fetch(susp, snd_list) - register inverse_susp_type susp; - snd_list_type snd_list; +void inverse_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + inverse_susp_type susp = (inverse_susp_type) a_susp; long final_count = MIN(susp->susp.current + max_sample_block_len, susp->susp.toss_cnt); time_type final_time = susp->susp.t0 + final_count / susp->susp.sr; @@ -157,21 +157,24 @@ void inverse_toss_fetch(susp, snd_list) } -void inverse_mark(inverse_susp_type susp) +void inverse_mark(snd_susp_type a_susp) { + inverse_susp_type susp = (inverse_susp_type) a_susp; sound_xlmark(susp->s); } -void inverse_free(inverse_susp_type susp) +void inverse_free(snd_susp_type a_susp) { + inverse_susp_type susp = (inverse_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(inverse_susp_node), "inverse_free"); } -void inverse_print_tree(inverse_susp_type susp, int n) +void inverse_print_tree(snd_susp_type a_susp, int n) { + inverse_susp_type susp = (inverse_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/multiread.c b/lib-src/libnyquist/nyquist/nyqsrc/multiread.c index 9c34be38a..d42a404fd 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/multiread.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/multiread.c @@ -44,10 +44,9 @@ * deallocated, because it can only be referenced through the * snd_list nodes to which there are backpointers. */ -void multiread_fetch(susp, snd_list) - register read_susp_type susp; - snd_list_type snd_list; +void multiread_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + read_susp_type susp = (read_susp_type) a_susp; int i, j; int frames_read = 0; /* total frames read in this call to fetch */ int n; @@ -252,8 +251,9 @@ void multiread_fetch(susp, snd_list) } /* multiread__fetch */ -void multiread_free(read_susp_type susp) +void multiread_free(snd_susp_type a_susp) { + read_susp_type susp = (read_susp_type) a_susp; int j; boolean active = false; /* stdputstr("multiread_free: "); */ diff --git a/lib-src/libnyquist/nyquist/nyqsrc/multiread.h b/lib-src/libnyquist/nyquist/nyqsrc/multiread.h index 7bd1b1795..9de2b1f1b 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/multiread.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/multiread.h @@ -1,3 +1,3 @@ LVAL multiread_create(read_susp_type susp); -void multiread_fetch(read_susp_type susp, snd_list_type snd_list); -void multiread_free(read_susp_type susp); +void multiread_fetch(snd_susp_type a_susp, snd_list_type snd_list); +void multiread_free(snd_susp_type a_susp); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/multiseq.c b/lib-src/libnyquist/nyquist/nyqsrc/multiseq.c index 367b5f65e..daef12de2 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/multiseq.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/multiseq.c @@ -136,9 +136,9 @@ known", I mean somewhere in the block referenced by ->s1_ptr and ->s1_cnt. /* extern LVAL s_stdout; */ void multiseq_convert(multiseq_type ms); -void multiseq_free(add_susp_type susp); +void multiseq_free(snd_susp_type a_susp); sample_block_type multiseq_get_next(sound_type snd, long * cnt); -void multiseq_print_tree(add_susp_type susp, int n); +void multiseq_print_tree(snd_susp_type a_susp, int n); #define susp_cnt_time(ssp, ms, cnt) (ssp->susp.t0 - ms->t0 + (cnt)/ssp->s1->sr) @@ -390,7 +390,7 @@ D nyquist_printf("susp %p using add_s1_s2_nn_fetch\n", susp); */ snd_list->u.next = snd_list_create(&(susp->susp)); snd_list->block = internal_zero_block; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))((snd_susp_type) susp, snd_list); } /* now free the multiseq struct */ @@ -420,10 +420,9 @@ D nyquist_printf("susp %p using add_s1_s2_nn_fetch\n", susp); * must check the pointers and substitute internal_zero_block to * avoid premature termination. */ -void multiseq_fetch(susp, snd_list) - register add_susp_type susp; - snd_list_type snd_list; +void multiseq_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + add_susp_type susp = (add_susp_type) a_susp; time_type block_end_time; /* undo the preallocation of a snd_list_node */ @@ -483,8 +482,9 @@ D nyquist_printf("block_end_time of %p: %g\n", susp, block_end_time); /* multiseq_mark -- mark routine for multiseq susps */ /**/ -void multiseq_mark(add_susp_type susp) +void multiseq_mark(snd_susp_type a_susp) { + add_susp_type susp = (add_susp_type) a_susp; int i; multiseq_type ms = susp->multiseq; D nyquist_printf("multiseq_mark(%p)\n", susp); @@ -607,8 +607,9 @@ D nyquist_printf("ms->t0 == %g\n", ms->t0); /* note: snd_multiseq is a noop, just call snd_make_multiseq */ -void multiseq_free(add_susp_type susp) +void multiseq_free(snd_susp_type a_susp) { + add_susp_type susp = (add_susp_type) a_susp; int i; multiseq_type ms = susp->multiseq; boolean dead = true; @@ -642,8 +643,9 @@ D nyquist_printf("susp %p freed, ms@%p->chans[%d] = NULL\n", } -void multiseq_print_tree(add_susp_type susp, int n) +void multiseq_print_tree(snd_susp_type a_susp, int n) { + add_susp_type susp = (add_susp_type) a_susp; int i; indent(n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.c b/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.c index 49cc0ae06..f3b949f10 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.c @@ -27,7 +27,8 @@ #include "xlisp.h" #include "sound.h" /* to get nosc_enabled */ #include "lo/lo.h" -#include "sliders.h" +#include "nyq-osc-server.h" +#include "sndsliders.h" static lo_server the_server = NULL; static int lo_fd; @@ -63,14 +64,16 @@ static int wii_orientation_handler(const char *path, const char *types, int nosc_init() { - the_server = lo_server_new("7770", error); - /* add method that will match the path /slider, with two numbers, coerced - * to int and float */ - lo_server_add_method(the_server, "/slider", "if", slider_handler, NULL); - lo_server_add_method(the_server, "/wii/orientation", "ff", - wii_orientation_handler, NULL); - lo_fd = lo_server_get_socket_fd(the_server); - nosc_enabled = true; + if (!SAFE_NYQUIST) { + the_server = lo_server_new("7770", error); + /* add method that will match the path /slider, with two numbers, coerced + * to int and float */ + lo_server_add_method(the_server, "/slider", "if", slider_handler, NULL); + lo_server_add_method(the_server, "/wii/orientation", "ff", + wii_orientation_handler, NULL); + lo_fd = lo_server_get_socket_fd(the_server); + nosc_enabled = true; + } return 0; } @@ -81,6 +84,7 @@ int nosc_poll() struct timeval tv; int retval; + if (SAFE_NYQUIST) return 0; // loop, receiving all pending OSC messages while (true) { FD_ZERO(&rfds); @@ -99,13 +103,16 @@ int nosc_poll() return 0; } } + return 0; } void nosc_finish() { - lo_server_free(the_server); - nosc_enabled = false; + if (!SAFE_NYQUIST) { + lo_server_free(the_server); + nosc_enabled = false; + } } #endif diff --git a/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.h b/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.h index 655c7b5ad..df1dd9f9a 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/nyq-osc-server.h @@ -2,8 +2,9 @@ * nyq-osc-server.h * nyquist * - * Created by Roger Dannenberg on 10/1/06. - * Copyright 2006 __MyCompanyName__. All rights reserved. - * + * Created by Roger Dannenberg */ +int nosc_init(); +int nosc_poll(); +void nosc_finish(); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.c b/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.c new file mode 100644 index 000000000..d4460952b --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.c @@ -0,0 +1,102 @@ +/* phasevocoder.c -- this is a stub showing how you might hook a + phase vocoder into Nyquist using pvshell + */ + +#include "stdio.h" +#ifndef mips +#include "stdlib.h" +#endif +#include "xlisp.h" +#include "sound.h" + +#include "falloc.h" +#include "cext.h" +#include "pvshell.h" + +#include "phasevocoder.h" + +/* use the state[] info for sample interpolation */ +#define X_VALUE state[0] /* a parameter value */ +#define F_COUNT state[1] /* counts samples of f */ +#define G_COUNT state[2] /* counts samples of g */ +#define G_PREV state[3] /* previous value from g */ +#define G_NEXT state[4] /* next (current?) value from g */ +/* invariant: G_NEXT is the G_COUNT'th sample of g */ + +/* pv_fetch -- this is an example, but it doesn't really do + * phase vocoding. Instead, it will just multiply f, g, and x + * + * To make things a bit more interesting, we will assume g has + * an arbitrary sample rate with respect to f, and will interpolate. + * + */ +long pv_fetch(pvshell_type susp, + sample_block_values_type out, long *n) +{ + int i; + for (i = 0; i < *n; i++) { + long new_flags; + sample_type f; + double g; + /* NOTE: in DSP terms, this is poor code because of the + * division operations -- it could be made faster + */ + /* To get a value from g, first compute the time */ + double f_time = susp->F_COUNT / susp->f->sr; + /* Now compute g count that is past the time */ + double g_count = f_time * susp->g->sr; + while (susp->G_COUNT < g_count) { + PVSHELL_TEST_G(susp); /* prepare to get a sample */ + /* ignore flags from g -- we could, if we wanted, + * terminate when either f or g terminated, etc. + */ + susp->G_PREV = susp->G_NEXT; + susp->G_NEXT = PVSHELL_FETCH_G(susp); + susp->G_COUNT++; + } + /* now interpolate to get the value of g at f_time */ + g = susp->G_PREV + (susp->G_NEXT - susp->G_PREV) * + (g_count - (susp->G_COUNT - 1)); + new_flags = PVSHELL_TEST_F(susp); + susp->flags |= new_flags; + if (new_flags) break; + f = PVSHELL_FETCH_F(susp); + susp->F_COUNT++; /* count how many samples we have taken */ + + /* now we have f, g, x */ + *out++ = f * g * susp->X_VALUE; + } + /* i is the number of samples we acutally computed */ + *n = i; + /* if we computed samples, we want to return them before + * returning flags that say we're done or stopped + */ + return (i ? 0 : susp->flags); +} + + +sound_type snd_phasevocoder(sound_type f, sound_type g, double x) +{ + /* we're using 5 doubles of state. The first is a parameter, + * and the rest are initialized to zero except for state[2], + * aka G_COUNT. This is the number of samples we have read + * from G. Since we're interpolating we need a one-sample + * lookahead, and initializing the count to -1 causes an + * extra fetch and hence 1-sample lookahead. This state is copied + * into the pvshell structure, so we don't need to allocate + * a vector on the heap. + */ + double state[5] = {0, 0, -1, 0, 0}; + state[0] = x; + /* If f and g do not start at the same time, we should really + * should do something about it, but we'll just throw an error. + * Be careful to allow small differences (within one sample). + */ + if (fabs(f->t0 - g->t0) * f->sr > 0.5) { + xlfail("phasevocoder inputs must start at the same time"); + } + /* output the same sample rate and start time as f */ + return snd_make_pvshell("snd_phasevocoder", f->sr, f->t0, + &pv_fetch, f, g, + state, sizeof(state) / sizeof(state[0])); +} diff --git a/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.h b/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.h new file mode 100644 index 000000000..8d941b305 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/phasevocoder.h @@ -0,0 +1,6 @@ +/* phasevocoder.h -- this is a stub showing how you might hook a + phase vocoder into Nyquist using pvshell + */ + +sound_type snd_phasevocoder(sound_type f, sound_type g, double x); + /* LISP: (snd-phasevocoder SOUND SOUND ANYNUM) */ diff --git a/lib-src/libnyquist/nyquist/nyqsrc/probe.c b/lib-src/libnyquist/nyquist/nyqsrc/probe.c index 9a04b4a85..635f303b5 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/probe.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/probe.c @@ -3,6 +3,7 @@ #include "stdio.h" #include "string.h" #include "xlisp.h" +#include "sound.h" static FILE* probefile = NULL; static long line_num = 0; diff --git a/lib-src/libnyquist/nyquist/nyqsrc/pvshell.c b/lib-src/libnyquist/nyquist/nyqsrc/pvshell.c new file mode 100644 index 000000000..608f10e44 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/pvshell.c @@ -0,0 +1,206 @@ +// pvshell.c -- This is a skeleton for a Nyquist primitive that +// returns a sound. The sound is obtained by calling a function +// with a request consisting of a location to put samples and +// a count of how many samples are needed. The function returns +// the actual number of samples computed and flags indicating +// if the signal has reached the logical stop or termination. +// In addition, there are interfaces for extracting samples +// from input sounds. +// This code is designed for a time-stretching phase vocoder, +// but could be used for other purposes. It is derived from +// compose.c, which might have been implmented with this +// skeleton had we started out with this abstraction. + +#include "stdio.h" +#ifndef mips +#include "stdlib.h" +#endif +#include "xlisp.h" +#include "sound.h" + +#include "falloc.h" +#include "cext.h" +#include "pvshell.h" +#include "assert.h" + +/* CHANGE LOG + * -------------------------------------------------------------------- + * 28Apr03 dm changes for portability and fix compiler warnings + */ + +void pvshell_free(); + + +typedef struct pvshell_susp_struct { + snd_susp_node susp; + long terminate_cnt; + boolean logically_stopped; + boolean started; + + pvshell_node pvshell; +} pvshell_susp_node, *pvshell_susp_type; + + +/* pvshell_test_f -- get next sample block and check flags + * + * Only call this from PVSHELL_TEST_F macro + */ +long pvshell_test_f(pvshell_type susp) +{ + long flags = 0; + susp_get_samples(f, f_ptr, f_cnt); /* warning: macro references susp */ + if (susp->f->logical_stop_cnt == susp->f->current - susp->f_cnt) { + flags |= PVSHELL_FLAG_LOGICAL_STOP; + } + if (susp->f_ptr == zero_block->samples) { + flags |= PVSHELL_FLAG_TERMINATE; + } + return flags; +} + + +/* pvshell_test_g -- get next sample block and check flags + * + * Only call this from PVSHELL_TEST_G macro + */ +long pvshell_test_g(pvshell_type susp) +{ + long flags = 0; + susp_get_samples(g, g_ptr, g_cnt); /* warning: macro references susp */ + if (susp->g->logical_stop_cnt == susp->g->current - susp->g_cnt) { + flags |= PVSHELL_FLAG_LOGICAL_STOP; + } + if (susp->g_ptr == zero_block->samples) { + flags |= PVSHELL_FLAG_TERMINATE; + } + return flags; +} + + +/* pvshell_fetch -- computes h(f, g, x, y) where f and g are + * sounds, x and y are doubles, and h implemented via a function + * pointer. This could certainly be generalized further, but + * maybe we should take this one step at a time. + */ +void pvshell_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + pvshell_susp_type susp = (pvshell_susp_type) a_susp; + long n, flags; + sample_block_type out; + sample_block_values_type out_ptr; + + falloc_sample_block(out, "pvshell_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* don't run past the f input sample block: */ + /* most fetch routines call susp_check_term_log_samples() here + * but we can't becasue susp_check_term_log_samples() assumes + * that output time progresses at the same rate as input time. + * Here, some time warping might be going on, so this doesn't work. + * It is up to the user to tell us when it is the logical stop + * time and the terminate time. + */ + /* don't run past terminate time */ + // if (susp->terminate_cnt != UNKNOWN && + // susp->terminate_cnt <= susp->susp.current + cnt + togo) { + // togo = susp->terminate_cnt - (susp->susp.current + cnt); + // if (togo == 0) break; + // } + /* don't run past logical stop time */ + // if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + // int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + // if (to_stop < togo && ((togo = to_stop) == 0)) break; + // } + n = max_sample_block_len; // ideally, compute a whole block of samples + + flags = (susp->pvshell.h)(&(susp->pvshell), out_ptr, &n); + + /* test for termination */ + if (flags & PVSHELL_FLAG_TERMINATE) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = n; + susp->susp.current += n; + } + /* test for logical stop */ + if (flags & PVSHELL_FLAG_LOGICAL_STOP || susp->logically_stopped) { + snd_list->logically_stopped = true; + susp->logically_stopped = true; + } +} /* pvshell_fetch */ + + +void pvshell_mark(snd_susp_type a_susp) +{ + pvshell_susp_type susp = (pvshell_susp_type) a_susp; + sound_xlmark(susp->pvshell.f); + sound_xlmark(susp->pvshell.g); +} + + +void pvshell_free(snd_susp_type a_susp) +{ + pvshell_susp_type susp = (pvshell_susp_type) a_susp; + /* note that f or g can be NULL */ + sound_unref(susp->pvshell.f); + sound_unref(susp->pvshell.g); + ffree_generic(susp, sizeof(pvshell_susp_node), "pvshell_free"); +} + + +void pvshell_print_tree(snd_susp_type a_susp, int n) +{ + pvshell_susp_type susp = (pvshell_susp_type) a_susp; + indent(n); + stdputstr("f:"); + sound_print_tree_1(susp->pvshell.f, n); + + indent(n); + stdputstr("g:"); + sound_print_tree_1(susp->pvshell.g, n); +} + + +sound_type snd_make_pvshell(char *name, rate_type sr, time_type t0, + h_fn_type h, sound_type f, sound_type g, + double *state, long n) +{ + register pvshell_susp_type susp; + int i; + + falloc_generic(susp, pvshell_susp_node, "snd_make_pvshell"); + susp->susp.fetch = pvshell_fetch; + susp->terminate_cnt = UNKNOWN; + + /* initialize susp state */ + susp->susp.free = pvshell_free; + susp->susp.sr = sr; + susp->susp.t0 = t0; + susp->susp.mark = pvshell_mark; + susp->susp.print_tree = pvshell_print_tree; + susp->susp.name = name; + susp->logically_stopped = false; + susp->susp.log_stop_cnt = UNKNOWN; + susp->susp.current = 0; + + /* copy the sound so that we have a private "reader" object */ + susp->pvshell.f = (f ? sound_copy(f) : f); + susp->pvshell.f_cnt = 0; + + susp->pvshell.g = (g ? sound_copy(g) : g); + susp->pvshell.g_cnt = 0; + + susp->pvshell.h = h; + + susp->pvshell.flags = 0; /* terminated and logically stopped flags -- these + are for the client of pvshell to use */ + + assert(n <= PVSHELL_STATE_MAX); + for (i = 0; i < n; i++) { + susp->pvshell.state[i] = state[i]; + } + + susp->started = false; + return sound_create((snd_susp_type)susp, t0, sr, 1.0); +} diff --git a/lib-src/libnyquist/nyquist/nyqsrc/pvshell.h b/lib-src/libnyquist/nyquist/nyqsrc/pvshell.h new file mode 100644 index 000000000..95ad05173 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/pvshell.h @@ -0,0 +1,92 @@ +/* pvshell.h -- a generic Nyquist primitive, esp. for phase vocoder */ + +/* how many doubles to provide for miscellaneous state info */ +#define PVSHELL_STATE_MAX 8 + +/* define some bits to return conditions */ +#define PVSHELL_FLAG_TERMINATE 4 +#define PVSHELL_FLAG_LOGICAL_STOP 8 + +/* this function is called to compute samples. It should compute n + * samples (floats == sample_type) and store them at out[i]. + * You can return less than n samples by writing the actual number + * of samples computed into *n. Normally, you return zero. + * To indicate that the time of the FIRST sample is the logical stop + * time, return PVSHELL_FLAG_LOGICAL_STOP. (If the logical stop time + * is not at the first sample, but instead at sample j, then just + * return j samples (from 0 to j-1), save the rest of the samples, + * and the next time, the first sample will correspond to the logical + * stop time, so you can return PVSHELL_FLAG_LOGICAL_STOP. + * To indicate that the sound has terminated, return + * PVSHELL_FLAG_TERMINATE. This should be the only time you return + * zero samples. (As with logical stop time, if you have samples to + * return before termination, then do it, and return + * PVSHELL_FLAG_TERMINATE the next time you are called, at which + * point you've returned all the samples, so you can set *n = 0. + */ +struct pvshell_struct; + +typedef long (*h_fn_type)(struct pvshell_struct *susp, + sample_block_values_type out, long *n); + +typedef struct pvshell_struct { + sound_type f; + long f_cnt; + sample_block_values_type f_ptr; + + sound_type g; + long g_cnt; + sample_block_values_type g_ptr; + + long flags; /* for terminated and logically stopped flags */ + + // state is extra storage for whatever you like + double state[PVSHELL_STATE_MAX]; + + // h is a function that computes sound from f, g, x, y, state + h_fn_type h; +} pvshell_node, *pvshell_type; + + +/* to get samples from f or g, use these macros. For each sample, call + * PVSHELL_TEST_X to get logical stop and terminate flags (but do not + * fetch a sample). Then, if you want, call PVSHELL_FETCH_X to get the + * next sample. You can call PVSHELL_TEST_X multiple times before + * calling PVSHELL_FETCH_X, e.g. you can return exit a loop when you + * see a logical stop flag and later call PVSHELL_TEST_X again. You + * CANNOT call PVSHELL_FETCH_X multiples times without an intervening + * call to PVSHELL_TEST_X. Finally, the logical stop flag is only + * returned once. Normally you should write something like: + * new_flags = PVSHELL_TEST_F(susp); + * susp->flags | = new_flags; // remember flags + * if (new_flags) break; + * in the sample loop so that you will break when you see logical_stop. + * Outside the loop, you can return (*n ? 0 : susp->flags) which will + * return 0 if you computed samples before the logical stop was detected. + * Then the next time you are called, you will return the logical_stop + * flag because you saved it in susp->flags, and the flag applies to the + * *beginning* of the sample block. This code handles terminate too. + */ +long pvshell_test_f(pvshell_type susp); +long pvshell_test_g(pvshell_type susp); +#define PVSHELL_TEST_F(susp) ((susp)->f_cnt == 0 ? pvshell_test_f(susp) : 0) +#define PVSHELL_FETCH_F(susp) ((susp)->f_cnt--, (*(susp)->f_ptr++)) + +#define PVSHELL_TEST_G(susp) ((susp)->g_cnt == 0 ? pvshell_test_g(susp) : 0) +#define PVSHELL_FETCH_G(susp) ((susp)->g_cnt--, (*(susp)->g_ptr++)) + +/* snd_make_pvshell -- create an instance of pvshell. + name -- string name of the operation, for debugging & printing + (name is not copied. It must be a permanent, immutable string.) + sr -- sample rate of output sound + t0 -- start time of output sound + h -- function that computes samples of output + f -- first input sound, e.g. sound to be time-stretched + g -- second input sound, e.g. sound to control varying stretch factor + state -- initial state information needed by h + n -- number of doubles in state (< PVSHELL_STATE_MAX) +*/ +sound_type snd_make_pvshell(char *name, rate_type sr, time_type t0, + h_fn_type h, sound_type f, sound_type g, + double *state, long n); + diff --git a/lib-src/libnyquist/nyquist/nyqsrc/resamp.c b/lib-src/libnyquist/nyquist/nyqsrc/resamp.c index e02e34440..a877d7765 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/resamp.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/resamp.c @@ -156,10 +156,10 @@ static int SrcUD(float X[], float Y[], double factor, double *Time, } -void resample__fetch(register resample_susp_type susp, snd_list_type snd_list) +void resample__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resample_susp_type susp = (resample_susp_type) a_susp; int togo; - int n; int Nout; sample_block_type out; /* note that in this fetch routine, out_ptr is used to remember where @@ -167,9 +167,6 @@ void resample__fetch(register resample_susp_type susp, snd_list_type snd_list) * loop that copies input samples into X, a buffer */ register sample_block_values_type out_ptr; - register sample_block_values_type X_ptr_reg; - - register sample_type *s_ptr_reg; falloc_sample_block(out, "resample__fetch"); out_ptr = out->samples; snd_list->block = out; @@ -268,22 +265,25 @@ samples need to be shifted from the end of X to the beginning. } /* resample__fetch */ -void resample_mark(resample_susp_type susp) +void resample_mark(snd_susp_type a_susp) { + resample_susp_type susp = (resample_susp_type) a_susp; sound_xlmark(susp->s); } -void resample_free(resample_susp_type susp) +void resample_free(snd_susp_type a_susp) { + resample_susp_type susp = (resample_susp_type) a_susp; sound_unref(susp->s); free(susp->X); ffree_generic(susp, sizeof(resample_susp_node), "resample_free"); } -void resample_print_tree(resample_susp_type susp, int n) +void resample_print_tree(snd_susp_type a_susp, int n) { + resample_susp_type susp = (resample_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/resampv.c b/lib-src/libnyquist/nyquist/nyqsrc/resampv.c index 67dcf7b0c..01d88d723 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/resampv.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/resampv.c @@ -142,8 +142,9 @@ static float SrcUD(float X[], double dt, double Time, } -void resamplev__fetch(register resamplev_susp_type susp, snd_list_type snd_list) +void resamplev__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resamplev_susp_type susp = (resamplev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_block_type out; /* note that in this fetch routine, out_ptr is used to remember where @@ -304,15 +305,17 @@ void resampv_refill(resamplev_susp_type susp) { -void resamplev_mark(resamplev_susp_type susp) +void resamplev_mark(snd_susp_type a_susp) { + resamplev_susp_type susp = (resamplev_susp_type) a_susp; sound_xlmark(susp->f); sound_xlmark(susp->g); } -void resamplev_free(resamplev_susp_type susp) +void resamplev_free(snd_susp_type a_susp) { + resamplev_susp_type susp = (resamplev_susp_type) a_susp; sound_unref(susp->f); sound_unref(susp->g); free(susp->X); @@ -320,8 +323,9 @@ void resamplev_free(resamplev_susp_type susp) } -void resamplev_print_tree(resamplev_susp_type susp, int n) +void resamplev_print_tree(snd_susp_type a_susp, int n) { + resamplev_susp_type susp = (resamplev_susp_type) a_susp; indent(n); nyquist_printf("f:"); sound_print_tree_1(susp->f, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/samples.c b/lib-src/libnyquist/nyquist/nyqsrc/samples.c index 4007d5c21..e841f67b3 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/samples.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/samples.c @@ -210,7 +210,10 @@ LVAL snd_fetch_array(sound_type s, long len, long step) long i, maxlen, skip, fillptr; float *samples; LVAL result; - + LVAL rslt_symbol = xlenter("*RSLT*"); + + setvalue(rslt_symbol, NULL); + if (len < 1) xlfail("len < 1"); if (!s->extra) { /* this is the first call, so fix up s */ @@ -232,6 +235,7 @@ LVAL snd_fetch_array(sound_type s, long len, long step) if (s->INDEX == s->CNT) { sound_get_next(s, &(s->CNT)); if (s->SAMPLES == zero_block->samples) { + setvalue(rslt_symbol, cvfixnum(fillptr)); if (s->TERMCNT < 0) s->TERMCNT = fillptr; } s->INDEX = 0; diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.c b/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.c new file mode 100644 index 000000000..178a33fd7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.c @@ -0,0 +1,18 @@ +/* sliderdata.c -- shared data for slider abstraction in nyquist + * + * Roger B. Dannenberg + * Jan 2013 + */ + +#include "sliderdata.h" + +float slider_array[SLIDERS_MAX]; + +void set_slider(int index, float value) +{ + if (index >= 0 && index < SLIDERS_MAX) { + slider_array[index] = value; + } +} + + diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.h b/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.h new file mode 100644 index 000000000..93f0f851c --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/sliderdata.h @@ -0,0 +1,12 @@ +/* sliderdata.h -- shared data for slider abstraction in nyquist + * + * Roger B. Dannenberg + * Jan 2013 + */ + +/* define the shared data */ +#define SLIDERS_MAX 1024 +extern float slider_array[SLIDERS_MAX]; + +/* access from the GUI to shared data */ +void set_slider(int index, float value); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sliders.h b/lib-src/libnyquist/nyquist/nyqsrc/sliders.h deleted file mode 100644 index 6628990ca..000000000 --- a/lib-src/libnyquist/nyquist/nyqsrc/sliders.h +++ /dev/null @@ -1,11 +0,0 @@ -/* sliders.h -- support for graphical sliders in Nyquist IDE */ - -/* probably these 3 should be elsewhere */ -int nosc_init(); -int nosc_poll(); -void nosc_finish(); - -#define SLIDERS_MAX 1024 -extern float slider_array[SLIDERS_MAX]; -void set_slider(int index, float value); - diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfmt.h b/lib-src/libnyquist/nyquist/nyqsrc/sndfmt.h index 24340054f..3f8f235da 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfmt.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfmt.h @@ -54,7 +54,9 @@ error here /* LISP-SRC: (setf snd-head-CAF 19) */ #define SND_HEAD_RAW 20 /* LISP-SRC: (setf snd-head-raw 20) */ -#define SND_NUM_HEADS 21 +#define SND_HEAD_OGG 21 +/* LISP-SRC: (setf snd-head-OGG 21) */ +#define SND_NUM_HEADS 22 /* bitfields for soundheaders */ #define SND_HEAD_CHANNELS (1<<0) @@ -103,7 +105,9 @@ error here /* microsoft ADPCM */ #define SND_MODE_MSADPCM 11 /* LISP-SRC: (setf snd-mode-msadpcm 11) */ -#define SND_NUM_MODES 12 +#define SND_MODE_VORBIS 12 +/* LISP-SRC: (setf snd-mode-vorbis 11) */ +#define SND_NUM_MODES 13 #define SND_LOOP_NONE 0 diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfn.cl b/lib-src/libnyquist/nyquist/nyqsrc/sndfn.cl index f10526790..6976bae37 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfn.cl +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfn.cl @@ -1,27 +1,54 @@ -nyqsrc/sndfnint sndfile.h nyqsrc/sndfmt.h nyqsrc/sound.h nyqsrc/add.h - nyqsrc/avg.h nyqsrc/compose.h nyqsrc/convolve.h nyqsrc/downsample.h - tran/fmfb.h tran/fmfbv.h - nyqsrc/fft.h nyqsrc/inverse.h nyqsrc/multiseq.h nyqsrc/resamp.h - nyqsrc/resampv.h nyqsrc/samples.h nyqsrc/sndmax.h nyqsrc/sndread.h - nyqsrc/sndseq.h nyqsrc/sndsliders.h nyqsrc/sndwrite.h nyqsrc/yin.h - nyqsrc/trigger.h nyqsrc/lpanal.h tran/abs.h - tran/allpoles.h tran/alpass.h tran/alpasscv.h tran/alpassvv.h - tran/amosc.h tran/areson.h tran/aresonvc.h tran/aresoncv.h - tran/aresonvv.h tran/atone.h tran/atonev.h tran/biquadfilt.h - tran/buzz.h tran/chase.h tran/clip.h tran/congen.h - tran/const.h tran/coterm.h tran/delaycc.h tran/delaycv.h - tran/eqbandvvv.h tran/exp.h tran/follow.h tran/fmosc.h - tran/fromobject.h tran/fromarraystream.h tran/gate.h tran/ifft.h - tran/instrclar.h tran/instrclarall.h tran/instrclarfreq.h tran/instrsax.h - tran/instrsaxall.h tran/instrsaxfreq.h tran/integrate.h tran/log.h - tran/lpreson.h tran/maxv.h tran/offset.h tran/oneshot.h - tran/osc.h tran/partial.h tran/pluck.h tran/prod.h - tran/pwl.h tran/quantize.h tran/recip.h tran/reson.h - tran/resonvc.h tran/resoncv.h tran/resonvv.h tran/sampler.h - tran/scale.h tran/shape.h tran/sine.h tran/siosc.h - tran/slope.h tran/sqrt.h tran/tapf.h tran/tapv.h - tran/tone.h tran/tonev.h tran/upsample.h tran/white.h - tran/stkrev.h tran/stkpitshift.h tran/stkchorus.h tran/instrbow.h - tran/instrbowedfreq.h tran/instrbanded.h tran/instrmandolin.h tran/instrsitar.h - tran/instrmodalbar.h tran/instrflute.h tran/instrflutefreq.h tran/instrfluteall.h +nyqsrc/sndfnint nylsf/sndfile.h nyqsrc/sndfmt.h + nyqsrc/sound.h nyqsrc/add.h + nyqsrc/avg.h nyqsrc/compose.h + nyqsrc/convolve.h nyqsrc/downsample.h + nyqsrc/fft.h nyqsrc/inverse.h + nyqsrc/multiseq.h nyqsrc/resamp.h + nyqsrc/resampv.h nyqsrc/samples.h + nyqsrc/sndmax.h nyqsrc/sndread.h + nyqsrc/sndseq.h nyqsrc/sndsliders.h + nyqsrc/sndwrite.h nyqsrc/yin.h + nyqsrc/nyq-osc-server.h nyqsrc/trigger.h + nyqsrc/lpanal.h nyqsrc/phasevocoder.h + nyqsrc/pvshell.h + tran/abs.h tran/allpoles.h + tran/alpass.h tran/alpasscv.h + tran/alpassvv.h tran/amosc.h + tran/areson.h tran/aresonvc.h + tran/aresoncv.h tran/aresonvv.h + tran/atone.h tran/atonev.h + tran/biquadfilt.h tran/buzz.h + tran/chase.h tran/clip.h + tran/congen.h tran/const.h + tran/coterm.h tran/delaycc.h + tran/delaycv.h tran/eqbandvvv.h + tran/exp.h tran/follow.h + tran/fmosc.h tran/fromobject.h + tran/fromarraystream.h tran/gate.h + tran/ifft.h tran/instrclar.h + tran/instrclarall.h tran/instrclarfreq.h + tran/instrsax.h tran/instrsaxall.h + tran/instrsaxfreq.h tran/integrate.h + tran/log.h tran/lpreson.h + tran/maxv.h tran/offset.h + tran/oneshot.h tran/osc.h + tran/partial.h tran/pluck.h + tran/prod.h tran/pwl.h + tran/quantize.h tran/recip.h + tran/reson.h tran/resonvc.h + tran/resoncv.h tran/resonvv.h + tran/sampler.h tran/scale.h + tran/shape.h tran/sine.h + tran/siosc.h tran/slope.h + tran/sqrt.h tran/tapf.h + tran/tapv.h tran/tone.h + tran/tonev.h tran/upsample.h + tran/white.h tran/stkrev.h + tran/stkpitshift.h tran/stkchorus.h + tran/instrbow.h tran/instrbowedfreq.h + tran/instrbanded.h tran/instrmandolin.h + tran/instrsitar.h tran/instrmodalbar.h + tran/instrflute.h tran/instrflutefreq.h + tran/instrfluteall.h tran/fmfb.h + tran/fmfbv.h diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfn.wcl b/lib-src/libnyquist/nyquist/nyqsrc/sndfn.wcl index cf589f8f7..6b7d44588 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfn.wcl +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfn.wcl @@ -1,26 +1,54 @@ -nyqsrc\sndfnint ~sndfile.h ~sndfmt.h nyqsrc\sound.h nyqsrc\add.h - nyqsrc\avg.h nyqsrc\compose.h nyqsrc\convolve.h nyqsrc\downsample.h - nyqsrc\fft.h nyqsrc\inverse.h nyqsrc\multiseq.h nyqsrc\resamp.h - nyqsrc\resampv.h nyqsrc\samples.h nyqsrc\sndmax.h nyqsrc\sndread.h - nyqsrc\sndseq.h nyqsrc\sndsliders.h nyqsrc\sndwrite.h nyqsrc\yin.h - nyqsrc\trigger.h nyqsrc\lpanal.h ~nyqsrc\sndheader.h tran\abs.h - tran\allpoles.h tran\alpass.h tran\alpasscv.h tran\alpassvv.h - tran\amosc.h tran\areson.h tran\aresonvc.h tran\aresoncv.h - tran\aresonvv.h tran\atone.h tran\atonev.h tran\biquad.h - tran\buzz.h tran\chase.h tran\clip.h tran\congen.h - tran\const.h tran\coterm.h tran\delaycc.h tran\delaycv.h - tran\eqbandvvv.h tran\exp.h tran\follow.h tran\fmosc.h - tran\fromobject.h tran\fromarraystream.h tran\gate.h tran\ifft.h - tran\instrclar.h tran\instrclarall.h tran\instrclarfreq.h tran\instrsax.h - tran\instrsaxall.h tran\instrsaxfreq.h tran\integrate.h tran\log.h - tran\lpreson.h tran\maxv.h tran\offset.h tran\oneshot.h - tran\osc.h tran\partial.h tran\pluck.h tran\prod.h - tran\pwl.h tran\quantize.h tran\recip.h tran\reson.h - tran\resonvc.h tran\resoncv.h tran\resonvv.h tran\sampler.h - tran\scale.h tran\shape.h tran\sine.h tran\siosc.h - tran\slope.h tran\sqrt.h tran\tapf.h tran\tapv.h - tran\tone.h tran\tonev.h tran\upsample.h tran\white.h - tran\stkrev.h tran\stkpitshift.h tran\stkchorus.h tran\instrbow.h - tran\instrbowedfreq.h tran\instrbanded.h tran\instrmandolin.h tran\instrsitar.h - tran\instrmodalbar.h tran\instrflute.h tran\instrflutefreq.h tran\instrfluteall.h +nyqsrc\sndfnint snd\snd.h + nyqsrc\sound.h nyqsrc\add.h + nyqsrc\avg.h nyqsrc\compose.h + nyqsrc\convolve.h nyqsrc\downsample.h + nyqsrc\fft.h nyqsrc\inverse.h + nyqsrc\multiseq.h nyqsrc\resamp.h + nyqsrc\resampv.h nyqsrc\samples.h + nyqsrc\sndmax.h nyqsrc\sndread.h + nyqsrc\sndseq.h nyqsrc\sndsliders.h + nyqsrc\sndwrite.h nyqsrc\yin.h + nyqsrc\nyq-osc-server.h nyqsrc\trigger.h + nyqsrc\lpanal.h nyqsrc\phasevocoder.h + nyqsrc\pvshell.h ~nyqsrc\sndheader.h + tran\abs.h tran\allpoles.h + tran\alpass.h tran\alpasscv.h + tran\alpassvv.h tran\amosc.h + tran\areson.h tran\aresonvc.h + tran\aresoncv.h tran\aresonvv.h + tran\atone.h tran\atonev.h + tran\biquadfilt.h tran\buzz.h + tran\chase.h tran\clip.h + tran\congen.h tran\const.h + tran\coterm.h tran\delaycc.h + tran\delaycv.h tran\eqbandvvv.h + tran\exp.h tran\follow.h + tran\fmosc.h tran\fromobject.h + tran\fromarraystream.h tran\gate.h + tran\ifft.h tran\instrclar.h + tran\instrclarall.h tran\instrclarfreq.h + tran\instrsax.h tran\instrsaxall.h + tran\instrsaxfreq.h tran\integrate.h + tran\log.h tran\lpreson.h + tran\maxv.h tran\offset.h + tran\oneshot.h tran\osc.h + tran\partial.h tran\pluck.h + tran\prod.h tran\pwl.h + tran\quantize.h tran\recip.h + tran\reson.h tran\resonvc.h + tran\resoncv.h tran\resonvv.h + tran\sampler.h tran\scale.h + tran\shape.h tran\sine.h + tran\siosc.h tran\slope.h + tran\sqrt.h tran\tapf.h + tran\tapv.h tran\tone.h + tran\tonev.h tran\upsample.h + tran\white.h tran\stkrev.h + tran\stkpitshift.h tran\stkchorus.h + tran\instrbow.h tran\instrbowedfreq.h + tran\instrbanded.h tran\instrmandolin.h + tran\instrsitar.h tran\instrmodalbar.h + tran\instrflute.h tran\instrflutefreq.h + tran\instrfluteall.h tran\fmfb.h + tran\fmfbv.h diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.c b/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.c index bc6b1df49..8abcb63c9 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.c @@ -4,9 +4,11 @@ * nyqsrc/downsample.h, nyqsrc/fft.h, nyqsrc/inverse.h, * nyqsrc/multiseq.h, nyqsrc/resamp.h, nyqsrc/resampv.h, * nyqsrc/samples.h, nyqsrc/sndmax.h, nyqsrc/sndread.h, - * nyqsrc/sndseq.h, nyqsrc/sndsliders.h, nyqsrc/sndwrite.h, - * nyqsrc/yin.h, nyqsrc/nyq-osc-server.h, nyqsrc/trigger.h, - * nyqsrc/lpanal.h, tran/abs.h, tran/allpoles.h, + * nyqsrc/sndseq.h, nyqsrc/sndsliders.h, + * nyqsrc/sliderdata.h, nyqsrc/sndwritepa.h, nyqsrc/yin.h, + * nyqsrc/nyq-osc-server.h, nyqsrc/trigger.h, + * nyqsrc/lpanal.h, nyqsrc/phasevocoder.h, + * nyqsrc/pvshell.h, tran/abs.h, tran/allpoles.h, * tran/alpass.h, tran/alpasscv.h, tran/alpassvv.h, * tran/amosc.h, tran/areson.h, tran/aresonvc.h, * tran/aresoncv.h, tran/aresonvv.h, tran/atone.h, @@ -33,7 +35,8 @@ * tran/instrbanded.h, tran/instrmandolin.h, * tran/instrsitar.h, tran/instrmodalbar.h, * tran/instrflute.h, tran/instrflutefreq.h, - * tran/instrfluteall.h, tran/fmfb.h, tran/fmfbv.h */ + * tran/instrfluteall.h, tran/fmfb.h, tran/fmfbv.h, + * nyqsrc/sndwrite.h */ #ifndef mips #include "stdlib.h" @@ -698,63 +701,9 @@ LVAL xlc_snd_slider(void) } -#include "sndwrite.h" - -/* xlc_snd_save -- interface to C routine sound_save */ -/**/ -LVAL xlc_snd_save(void) -{ - LVAL arg1 = xlgetarg(); - long arg2 = getfixnum(xlgafixnum()); - unsigned char * arg3 = getstring(xlgastring()); - long arg4 = getfixnum(xlgafixnum()); - long arg5 = getfixnum(xlgafixnum()); - long arg6 = getfixnum(xlgafixnum()); - long arg7 = getfixnum(xlgafixnum()); - double arg8 = 0.0; - long arg9 = 0; - double arg10 = 0.0; - LVAL arg11 = xlgetarg(); - double result; - - xllastarg(); - result = sound_save(arg1, arg2, arg3, arg4, arg5, arg6, arg7, &arg8, &arg9, &arg10, arg11); - { LVAL *next = &getvalue(RSLT_sym); - *next = cons(NIL, NIL); - car(*next) = cvflonum(arg8); next = &cdr(*next); - *next = cons(NIL, NIL); - car(*next) = cvfixnum(arg9); next = &cdr(*next); - *next = cons(NIL, NIL); - car(*next) = cvflonum(arg10); - } - return cvflonum(result); -} - - -/* xlc_snd_overwrite -- interface to C routine sound_overwrite */ -/**/ -LVAL xlc_snd_overwrite(void) -{ - LVAL arg1 = xlgetarg(); - long arg2 = getfixnum(xlgafixnum()); - unsigned char * arg3 = getstring(xlgastring()); - double arg4 = testarg2(xlgaanynum()); - long arg5 = getfixnum(xlgafixnum()); - long arg6 = getfixnum(xlgafixnum()); - long arg7 = getfixnum(xlgafixnum()); - long arg8 = getfixnum(xlgafixnum()); - double arg9 = 0.0; - double result; - - xllastarg(); - result = sound_overwrite(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, &arg9); - { LVAL *next = &getvalue(RSLT_sym); - *next = cons(NIL, NIL); - car(*next) = cvflonum(arg9); - } - return cvflonum(result); -} +#include "sliderdata.h" +#include "sndwritepa.h" #include "yin.h" @@ -808,6 +757,25 @@ LVAL xlc_snd_lpanal(void) } +#include "phasevocoder.h" + +/* xlc_snd_phasevocoder -- interface to C routine snd_phasevocoder */ +/**/ +LVAL xlc_snd_phasevocoder(void) +{ + sound_type arg1 = getsound(xlgasound()); + sound_type arg2 = getsound(xlgasound()); + double arg3 = testarg2(xlgaanynum()); + sound_type result; + + xllastarg(); + result = snd_phasevocoder(arg1, arg2, arg3); + return cvsound(result); +} + + +#include "pvshell.h" + #include "abs.h" /* xlc_snd_abs -- interface to C routine snd_abs */ @@ -1959,11 +1927,10 @@ LVAL xlc_snd_stkrev(void) sound_type arg2 = getsound(xlgasound()); double arg3 = testarg2(xlgaanynum()); double arg4 = testarg2(xlgaanynum()); - double arg5 = testarg2(xlgaanynum()); sound_type result; xllastarg(); - result = snd_stkrev(arg1, arg2, arg3, arg4, arg5); + result = snd_stkrev(arg1, arg2, arg3, arg4); return cvsound(result); } @@ -1977,11 +1944,10 @@ LVAL xlc_snd_stkpitshift(void) sound_type arg1 = getsound(xlgasound()); double arg2 = testarg2(xlgaanynum()); double arg3 = testarg2(xlgaanynum()); - double arg4 = testarg2(xlgaanynum()); sound_type result; xllastarg(); - result = snd_stkpitshift(arg1, arg2, arg3, arg4); + result = snd_stkpitshift(arg1, arg2, arg3); return cvsound(result); } @@ -1997,11 +1963,10 @@ LVAL xlc_snd_stkchorus(void) double arg3 = testarg2(xlgaanynum()); double arg4 = testarg2(xlgaanynum()); double arg5 = testarg2(xlgaanynum()); - double arg6 = testarg2(xlgaanynum()); sound_type result; xllastarg(); - result = snd_stkchorus(arg1, arg2, arg3, arg4, arg5, arg6); + result = snd_stkchorus(arg1, arg2, arg3, arg4, arg5); return cvsound(result); } @@ -2210,3 +2175,61 @@ LVAL xlc_snd_fmfbv(void) } +#include "sndwrite.h" + +/* xlc_snd_save -- interface to C routine sound_save */ +/**/ +LVAL xlc_snd_save(void) +{ + LVAL arg1 = xlgetarg(); + long arg2 = getfixnum(xlgafixnum()); + unsigned char * arg3 = getstring(xlgastring()); + long arg4 = getfixnum(xlgafixnum()); + long arg5 = getfixnum(xlgafixnum()); + long arg6 = getfixnum(xlgafixnum()); + long arg7 = getfixnum(xlgafixnum()); + double arg8 = 0.0; + long arg9 = 0; + double arg10 = 0.0; + LVAL arg11 = xlgetarg(); + double result; + + xllastarg(); + result = sound_save(arg1, arg2, arg3, arg4, arg5, arg6, arg7, &arg8, &arg9, &arg10, arg11); + { LVAL *next = &getvalue(RSLT_sym); + *next = cons(NIL, NIL); + car(*next) = cvflonum(arg8); next = &cdr(*next); + *next = cons(NIL, NIL); + car(*next) = cvfixnum(arg9); next = &cdr(*next); + *next = cons(NIL, NIL); + car(*next) = cvflonum(arg10); + } + return cvflonum(result); +} + + +/* xlc_snd_overwrite -- interface to C routine sound_overwrite */ +/**/ +LVAL xlc_snd_overwrite(void) +{ + LVAL arg1 = xlgetarg(); + long arg2 = getfixnum(xlgafixnum()); + unsigned char * arg3 = getstring(xlgastring()); + double arg4 = testarg2(xlgaanynum()); + long arg5 = getfixnum(xlgafixnum()); + long arg6 = getfixnum(xlgafixnum()); + long arg7 = getfixnum(xlgafixnum()); + long arg8 = getfixnum(xlgafixnum()); + double arg9 = 0.0; + double result; + + xllastarg(); + result = sound_overwrite(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, &arg9); + { LVAL *next = &getvalue(RSLT_sym); + *next = cons(NIL, NIL); + car(*next) = cvflonum(arg9); + } + return cvflonum(result); +} + + diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.lsp b/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.lsp index 83c897cde..3194cedb9 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.lsp +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.lsp @@ -40,6 +40,8 @@ (setf snd-head-raw 20) + (setf snd-head-OGG 21) + (setf snd-head-channels 1) (setf snd-head-mode 2) @@ -78,6 +80,8 @@ (setf snd-mode-msadpcm 11) + (setf snd-mode-vorbis 11) + (SETF MAX-STOP-TIME 10E20) (SETF MIN-START-TIME -10E20) diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfnintdefs.h b/lib-src/libnyquist/nyquist/nyqsrc/sndfnintdefs.h index 007527e71..0119c12b1 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfnintdefs.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfnintdefs.h @@ -40,11 +40,10 @@ extern LVAL xlc_snd_max(void); extern LVAL xlc_snd_read(void); extern LVAL xlc_snd_seq(void); extern LVAL xlc_snd_slider(void); -extern LVAL xlc_snd_save(void); -extern LVAL xlc_snd_overwrite(void); extern LVAL xlc_snd_yin(void); extern LVAL xlc_snd_trigger(void); extern LVAL xlc_snd_lpanal(void); +extern LVAL xlc_snd_phasevocoder(void); extern LVAL xlc_snd_abs(void); extern LVAL xlc_snd_allpoles(void); extern LVAL xlc_snd_alpass(void); @@ -124,3 +123,5 @@ extern LVAL xlc_snd_flute_freq(void); extern LVAL xlc_snd_flute_all(void); extern LVAL xlc_snd_fmfb(void); extern LVAL xlc_snd_fmfbv(void); +extern LVAL xlc_snd_save(void); +extern LVAL xlc_snd_overwrite(void); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndfnintptrs.h b/lib-src/libnyquist/nyquist/nyqsrc/sndfnintptrs.h index 81b966f1e..76d5aaa16 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndfnintptrs.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndfnintptrs.h @@ -40,11 +40,10 @@ { "SND-READ", S, xlc_snd_read}, { "SND-SEQ", S, xlc_snd_seq}, { "SND-SLIDER", S, xlc_snd_slider}, - { "SND-SAVE", S, xlc_snd_save}, - { "SND-OVERWRITE", S, xlc_snd_overwrite}, { "SND-YIN", S, xlc_snd_yin}, { "SND-TRIGGER", S, xlc_snd_trigger}, { "SND-LPANAL", S, xlc_snd_lpanal}, + { "SND-PHASEVOCODER", S, xlc_snd_phasevocoder}, { "SND-ABS", S, xlc_snd_abs}, { "SND-ALLPOLES", S, xlc_snd_allpoles}, { "SND-ALPASS", S, xlc_snd_alpass}, @@ -124,3 +123,5 @@ { "SND-FLUTE_ALL", S, xlc_snd_flute_all}, { "SND-FMFB", S, xlc_snd_fmfb}, { "SND-FMFBV", S, xlc_snd_fmfbv}, + { "SND-SAVE", S, xlc_snd_save}, + { "SND-OVERWRITE", S, xlc_snd_overwrite}, diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndread.c b/lib-src/libnyquist/nyquist/nyqsrc/sndread.c index 5087abbc4..d4986c532 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndread.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndread.c @@ -19,11 +19,11 @@ #include "io.h" #else #include -#endif +#endif /* WINDOWS */ #define L_SET SEEK_SET #define L_INCR SEEK_CUR #define PROTECTION -#endif +#endif /* UNIX */ #ifndef mips #include "stdlib.h" #endif @@ -86,15 +86,16 @@ void read__fetch(susp, snd_list) } /* read__fetch */ -void read_free(read_susp_type susp) +void read_free(snd_susp_type a_susp) { + read_susp_type susp = (read_susp_type) a_susp; sf_close(susp->sndfile); sndread_file_open_count--; ffree_generic(susp, sizeof(read_susp_node), "read_free"); } -void read_print_tree(read_susp_type susp, int n) +void read_print_tree(snd_susp_type a_susp, int n) { } @@ -169,12 +170,15 @@ LVAL snd_make_read( susp->sf_info.format |= format; } - susp->sndfile = sf_open((const char *) filename, SFM_READ, - &(susp->sf_info)); + susp->sndfile = NULL; + if (ok_to_open((const char *) filename, "rb")) + susp->sndfile = sf_open((const char *) filename, SFM_READ, + &(susp->sf_info)); if (!susp->sndfile) { char error[240]; - sprintf(error, "SND-READ: Cannot open file '%s'", filename); + sprintf(error, "SND-READ: Cannot open file '%s' because of %s", filename, + sf_strerror(susp->sndfile)); xlfail(error); } if (susp->sf_info.channels < 1) { @@ -239,6 +243,7 @@ LVAL snd_make_read( case SF_FORMAT_SD2: *format = SND_HEAD_SD2; break; case SF_FORMAT_FLAC: *format = SND_HEAD_FLAC; break; case SF_FORMAT_CAF: *format = SND_HEAD_CAF; break; + case SF_FORMAT_OGG: *format = SND_HEAD_OGG; break; default: *format = SND_HEAD_NONE; break; } *channels = susp->sf_info.channels; diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndseq.c b/lib-src/libnyquist/nyquist/nyqsrc/sndseq.c index edeb8b29d..21fefb40b 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndseq.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndseq.c @@ -59,16 +59,15 @@ typedef struct sndseq_susp_struct { } sndseq_susp_node, *sndseq_susp_type; -void sndseq_fetch(sndseq_susp_type, snd_list_type); +void sndseq_fetch(snd_susp_type a_susp, snd_list_type snd_list); void sndseq_zero_fill_fetch(sndseq_susp_type, snd_list_type); -void sndseq_free(); +void sndseq_free(snd_susp_type susp); extern LVAL s_stdout; -void sndseq_mark(sndseq_susp_type susp) +void sndseq_mark(snd_susp_type a_susp) { -/* nyquist_printf("sndseq_mark(%x)\n", susp);*/ -/* nyquist_printf("marking s1@%x in sndseq@%x\n", susp->s1, susp); */ + sndseq_susp_type susp = (sndseq_susp_type) a_susp; sound_xlmark(susp->s1); if (susp->closure) mark(susp->closure); } @@ -77,10 +76,9 @@ void sndseq_mark(sndseq_susp_type susp) /* sndseq_fetch returns blocks of s1 until the logical stop time of s1 */ /**/ -void sndseq_fetch(susp, snd_list) - register sndseq_susp_type susp; - snd_list_type snd_list; +void sndseq_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sndseq_susp_type susp = (sndseq_susp_type) a_susp; int togo; int n; sample_block_type out; @@ -173,7 +171,7 @@ D stdputstr("using add_s1_nn_fetch\n"); susp->output_per_s2 = susp->susp.sr / susp->s2->sr; D stdputstr("in sndseq: calling add's fetch\n"); - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); D stdputstr("in sndseq: returned from add's fetch\n"); /* gc();*/ xlpop(); @@ -262,16 +260,17 @@ D stdputstr("in sndseq: returned from add's fetch\n"); } /* sndseq_fetch */ -void sndseq_free(sndseq_susp_type susp) +void sndseq_free(snd_susp_type a_susp) { - sound_unref(susp->s1); + sndseq_susp_type susp = (sndseq_susp_type) a_susp; sound_unref(susp->s2); ffree_generic(susp, sizeof(sndseq_susp_node), "sndseq_free"); } -void sndseq_print_tree(sndseq_susp_type susp, int n) +void sndseq_print_tree(snd_susp_type a_susp, int n) { + sndseq_susp_type susp = (sndseq_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sliders.c b/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.c similarity index 89% rename from lib-src/libnyquist/nyquist/nyqsrc/sliders.c rename to lib-src/libnyquist/nyquist/nyqsrc/sndsliders.c index 9e0713216..7fd9ac662 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sliders.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.c @@ -7,20 +7,10 @@ #include "falloc.h" #include "cext.h" -#include "sliders.h" +#include "nyq-osc-server.h" +#include "sliderdata.h" #include "sndsliders.h" -float slider_array[SLIDERS_MAX]; - - -void set_slider(int index, float value) -{ - if (index >= 0 && index < SLIDERS_MAX) { - slider_array[index] = value; - } -} - - LVAL xslider_read(void) { LVAL arg = xlgafixnum(); @@ -34,7 +24,11 @@ LVAL xslider_read(void) LVAL xosc_enable(void) { - LVAL arg = xlgetarg(); +/* only need arg if OSC is defined, otherwise compiler complains */ +#ifdef OSC + LVAL arg = +#endif + xlgetarg(); xllastarg(); #ifdef OSC if (nosc_enabled == !null(arg)) { @@ -63,8 +57,9 @@ typedef struct slider_susp_struct { } slider_susp_node, *slider_susp_type; -void slider__fetch(register slider_susp_type susp, snd_list_type snd_list) +void slider__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + slider_susp_type susp = (slider_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -116,13 +111,14 @@ void slider__fetch(register slider_susp_type susp, snd_list_type snd_list) } /* slider__fetch */ -void slider_free(slider_susp_type susp) +void slider_free(snd_susp_type a_susp) { + slider_susp_type susp = (slider_susp_type) a_susp; ffree_generic(susp, sizeof(slider_susp_node), "slider_free"); } -void slider_print_tree(slider_susp_type susp, int n) +void slider_print_tree(snd_susp_type susp, int n) { } diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.h b/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.h index ade86ba0f..ae96523a2 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndsliders.h @@ -1,5 +1,10 @@ /* sndsliders.h -- support for graphical sliders in Nyquist IDE */ +/* Roger Dannenberg + * Jan 2013 + */ + +/* access from Nyquist unit generators to shared data */ sound_type snd_make_slider(int index, time_type t0, rate_type sr, time_type d); sound_type snd_slider(int index, time_type t0, rate_type sr, time_type d); /* LISP: (SND-SLIDER FIXNUM ANYNUM ANYNUM ANYNUM) */ diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.c b/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.c index a0591cc2a..cfd317d33 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.c @@ -1,4 +1,4 @@ -/* sndwrite.c -- write sounds to files */ + /* sndwrite.c -- write sounds to files */ #include "stdlib.h" #include "switches.h" @@ -93,12 +93,8 @@ max_sample = -s; \ } - -/* jlh Changed these to the <> format, so it will be sought for in the - include path */ -#include -/* #include "exitpa.h" jlh obsolete? or windows only? PortAudio 2007 - has no such thing. Is it PA 19 or PA 2.0??? */ +// should be looking for local portaudio +#include "portaudio.h" long flush_count = 0; /* how many samples to write to finish */ @@ -138,8 +134,9 @@ static int portaudio_error(PaError err, char *problem) { char msgbuffer[256]; if (err != paNoError) { - sprintf(msgbuffer, "%s, error %ld, %s.", problem, err, - Pa_GetErrorText(err)); + snprintf(msgbuffer, sizeof(msgbuffer), + "%s, error %d, %s.", problem, (int) err, + Pa_GetErrorText(err)); xlerrprint("warning", NULL, msgbuffer, s_unbound); return true; } @@ -242,7 +239,8 @@ long lookup_format(long format, long mode, long bits, long swap) case SND_HEAD_SD2: sf_format = SF_FORMAT_SD2; break; case SND_HEAD_FLAC: sf_format = SF_FORMAT_FLAC; break; case SND_HEAD_CAF: sf_format = SF_FORMAT_CAF; break; - case SND_HEAD_RAW: + case SND_HEAD_OGG: sf_format = SF_FORMAT_OGG; mode = SND_MODE_VORBIS; break; /* ZEYU */ + case SND_HEAD_RAW: sf_format = SF_FORMAT_RAW; #ifdef XL_BIG_ENDIAN sf_format |= (swap ? SF_ENDIAN_LITTLE : SF_ENDIAN_BIG); @@ -267,7 +265,7 @@ long lookup_format(long format, long mode, long bits, long swap) "using PCM instead\n"); } /* no break here, fall through to SND_MODE_PCM... */ default: - nyquist_printf("s-save: unrecognized mode (%d), using PCM\n", + nyquist_printf("s-save: unrecognized mode (%ld), using PCM\n", mode); /* no break, fall through as SND_MODE_PCM */ case SND_MODE_PCM: @@ -278,7 +276,7 @@ long lookup_format(long format, long mode, long bits, long swap) else { sf_mode = SF_FORMAT_PCM_16; nyquist_printf( - "s-save: bad bits parameter (%d), using 16-bit PCM\n", + "s-save: bad bits parameter (%ld), using 16-bit PCM\n", bits); } break; @@ -287,7 +285,7 @@ long lookup_format(long format, long mode, long bits, long swap) case SND_MODE_FLOAT: sf_mode = SF_FORMAT_FLOAT; break; case SND_MODE_DOUBLE: sf_mode = SF_FORMAT_DOUBLE; break; case SND_MODE_UNKNOWN: sf_mode = SF_FORMAT_PCM_16; break; - case SND_MODE_GSM610: sf_mode = SF_FORMAT_GSM610; break; + case SND_MODE_GSM610: sf_mode = SF_FORMAT_GSM610; break; case SND_MODE_DWVW: if (bits <= 12) sf_mode = SF_FORMAT_DWVW_12; else if (bits <= 16) sf_mode = SF_FORMAT_DWVW_16; @@ -300,11 +298,12 @@ long lookup_format(long format, long mode, long bits, long swap) else { sf_mode = SF_FORMAT_DPCM_16; nyquist_printf( - "s-save: bad bits parameter (%d), using 16-bit DPCM\n", + "s-save: bad bits parameter (%ld), using 16-bit DPCM\n", bits); } break; case SND_MODE_MSADPCM: sf_mode = SF_FORMAT_MS_ADPCM; break; + case SND_MODE_VORBIS: sf_mode = SF_FORMAT_VORBIS; break; } return sf_format | sf_mode; } @@ -330,6 +329,7 @@ double sound_save( SNDFILE *sndfile = NULL; SF_INFO sf_info; PaStream *audio_stream = NULL; + if (SAFE_NYQUIST) play = FALSE; gc(); @@ -356,7 +356,9 @@ double sound_save( * write the file if (filename[0]) */ if (filename[0]) { - sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); + sndfile = NULL; + if (ok_to_open((char *) filename, "wb")) + sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); if (sndfile) { /* use proper scale factor: 8000 vs 7FFF */ sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE); @@ -381,10 +383,19 @@ double sound_save( sf_info.samplerate = ROUND((getsound(result))->sr); *sr = sf_info.samplerate; if (filename[0]) { - sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); - if (sndfile) { - /* use proper scale factor: 8000 vs 7FFF */ - sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE); + sndfile = NULL; + if (ok_to_open((char *) filename, "wb")) { + sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info); + if (sndfile) { + /* use proper scale factor: 8000 vs 7FFF */ + sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE); + } else { + char error[240]; + sprintf(error, "snd_save -- %s", sf_error_number(sf_error(sndfile))); + xlabort(error); + } + } else { + xlabort("snd_save -- write not permitted by -W option"); } } if (play) @@ -432,10 +443,12 @@ SNDFILE *open_for_write(unsigned char *filename, long direction, } else { sf_info->format = 0; } - sndfile = sf_open((const char *) filename, direction, sf_info); + sndfile = NULL; + if (ok_to_open((char *) filename, "w")) + sndfile = sf_open((const char *) filename, direction, sf_info); if (!sndfile) { - sprintf(error, "snd_overwrite: cannot open file %s", filename); + snprintf(error, sizeof(error), "snd_overwrite: cannot open file %s", filename); xlabort(error); } /* use proper scale factor: 8000 vs 7FFF */ @@ -444,12 +457,12 @@ SNDFILE *open_for_write(unsigned char *filename, long direction, frames = round(offset * sf_info->samplerate); rslt = sf_seek(sndfile, frames, SEEK_SET); if (rslt < 0) { - sprintf(error, "snd_overwrite: cannot seek to frame %lld of %s", + snprintf(error, sizeof(error), "snd_overwrite: cannot seek to frame %lld of %s", frames, filename); xlabort(error); } if (sf_info->channels != channels) { - sprintf(error, "%s%ld%s%ld%s", + snprintf(error, sizeof(error), "%s%d%s%d%s", "snd_overwrite: number of channels in sound (", channels, ") does not match\n number of channels in file (", @@ -459,7 +472,7 @@ SNDFILE *open_for_write(unsigned char *filename, long direction, } if (sf_info->samplerate != srate) { - sprintf(error, "%s%g%s%ld%s", + snprintf(error, sizeof(error), "%s%ld%s%d%s", "snd_overwrite: sample rate in sound (", srate, ") does not match\n sample rate in file (", @@ -496,7 +509,9 @@ double sound_overwrite( long flags; */ // first check if sound file exists, do not create new file - FILE *file = fopen((char *) filename, "rb"); + FILE *file = NULL; + if (ok_to_open((char *) filename, "rb")) + file = fopen((char *) filename, "rb"); // if not then fail if (!file) { *duration = 0; @@ -513,6 +528,7 @@ double sound_overwrite( float *buf; // buffer for samples read in from sound file /* make sure all elements are of type a_sound */ long i = getsize(result); + long channels = i; while (i > 0) { i--; if (!exttypep(getelement(result, i), a_sound)) { @@ -520,7 +536,7 @@ double sound_overwrite( result); } } - sndfile = open_for_write(filename, SFM_RDWR, format, &sf_info, i, + sndfile = open_for_write(filename, SFM_RDWR, format, &sf_info, channels, ROUND(getsound(getelement(result, 0))->sr), offset_secs, &buf); @@ -569,7 +585,6 @@ sample_type sound_save_sound(LVAL s_as_lval, long n, SF_INFO *sf_info, sample_type threshold = 0.0F; /* jlh cvtfn_type cvtfn; */ *ntotal = 0; - /* if snd_expr was simply a symbol, then s now points to a shared sound_node. If we read samples from it, then the sound bound to the symbol will be destroyed, so @@ -746,7 +761,7 @@ D nyquist_printf("save scale factor %ld = %g\n", i, state[i].scale); for (i = 0; i < chans; i++) { if (state[i].cnt == 0) { if (sndwrite_trace) { - nyquist_printf("CALLING SOUND_GET_NEXT ON CHANNEL %ld (%x)\n", + nyquist_printf("CALLING SOUND_GET_NEXT ON CHANNEL %ld (%lx)\n", i, (unsigned long) state[i].sound); /* jlh 64 bit issue */ sound_print_tree(state[i].sound); } diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.h b/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.h new file mode 100644 index 000000000..495bde303 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.h @@ -0,0 +1,10 @@ +// sndwritepa.h -- headers for sndwritepa.c +// +// Roger Dannenberg +// Jan 2013 +// +// Since sndwritepa.c is a PortAudio based implementation of the sndwrite.h +// interface, we just include sndwrite.h (By doing this, we regularize the +// system so that there is a .h file corresponding to each .c file.) + +#include "sndwrite.h" diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sound.c b/lib-src/libnyquist/nyquist/nyqsrc/sound.c index 9892d10da..35de780f4 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sound.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sound.c @@ -73,6 +73,16 @@ double snd_set_latency(double latency) } +long check_terminate_cnt(long tc) +{ + if (tc < 0) { + xlfail("duration is less than 0 samples"); + tc = 0; /* this should not be reached */ + } + return tc; +} + + /* xlbadsr - report a "bad combination of sample rates" error */ LVAL snd_badsr(void) { @@ -1572,12 +1582,19 @@ double hz_to_step(double hz) } -double step_to_hz(steps) - double steps; +double step_to_hz(double steps) { return exp(steps * p1 + p2); } +#ifdef WIN32 +#define RECIP_LOG_2 1.44269504088895364453 + +double log2(double x) +{ + return log(x) * RECIP_LOG_2; +} +#endif /* * from old stuff... @@ -1616,9 +1633,9 @@ static unsigned char *sound_xlrestore(FILE *fp) /* sound_xlmark -- mark LVAL nodes reachable from this sound */ /**/ -void sound_xlmark(s) -sound_type s; +void sound_xlmark(void *a_sound) { + sound_type s = (sound_type) a_sound; snd_list_type snd_list; long counter = 0; #ifdef TRACESNDGC diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sound.h b/lib-src/libnyquist/nyquist/nyqsrc/sound.h index 9cdd95ae6..20fe993de 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sound.h +++ b/lib-src/libnyquist/nyquist/nyqsrc/sound.h @@ -53,6 +53,14 @@ extern int nosc_enabled; /* enable polling for OSC messages */ #define INTERP_ss 5 #define INTERP_si 6 #define INTERP_sr 7 +#define INTERP_in 8 +#define INTERP_is 9 +#define INTERP_ii 10 +#define INTERP_ir 11 +#define INTERP_rn 12 +#define INTERP_rs 13 +#define INTERP_ri 14 +#define INTERP_rr 15 #define INTERP_nnn 0 #define INTERP_nns 1 @@ -87,6 +95,39 @@ extern int nosc_enabled; /* enable polling for OSC messages */ #define INTERP_sri 30 #define INTERP_srr 31 +#define INTERP_inn 32 +#define INTERP_ins 33 +#define INTERP_ini 34 +#define INTERP_inr 35 +#define INTERP_isn 36 +#define INTERP_iss 37 +#define INTERP_isi 38 +#define INTERP_isr 39 +#define INTERP_iin 40 +#define INTERP_iis 41 +#define INTERP_iii 42 +#define INTERP_iir 43 +#define INTERP_irn 44 +#define INTERP_irs 45 +#define INTERP_iri 46 +#define INTERP_irr 47 +#define INTERP_rnn 48 +#define INTERP_rns 49 +#define INTERP_rni 50 +#define INTERP_rnr 51 +#define INTERP_rsn 52 +#define INTERP_rss 53 +#define INTERP_rsi 54 +#define INTERP_rsr 55 +#define INTERP_rin 56 +#define INTERP_ris 57 +#define INTERP_rii 58 +#define INTERP_rir 59 +#define INTERP_rrn 60 +#define INTERP_rrs 61 +#define INTERP_rri 62 +#define INTERP_rrr 63 + #define INTERP_nnnn 0 #define INTERP_nnns 1 #define INTERP_nnsn 4 @@ -95,6 +136,7 @@ extern int nosc_enabled; /* enable polling for OSC messages */ #define INTERP_nsns 17 #define INTERP_nssn 20 #define INTERP_nsss 21 +#define INTERP_nrrr 63 #define INTERP_snnn 64 #define INTERP_snns 65 #define INTERP_snsn 68 @@ -105,11 +147,76 @@ extern int nosc_enabled; /* enable polling for OSC messages */ #define INTERP_ssss 85 #define INTERP_niii 42 #define INTERP_siii 106 -#define INTERP_nrrr 63 #define INTERP_srrr 127 +#define INTERP_iiii 170 +#define INTERP_rrrr 255 -#define INTERP_nnnnnn 0 +#define INTERP_nnnnnn 0 +#define INTERP_nnnnns 1 +#define INTERP_nnnnsn 4 +#define INTERP_nnnnss 5 +#define INTERP_nnnsnn 16 +#define INTERP_nnnsns 17 +#define INTERP_nnnssn 20 +#define INTERP_nnnsss 21 +#define INTERP_nnsnnn 64 +#define INTERP_nnsnns 65 +#define INTERP_nnsnsn 68 +#define INTERP_nnsnss 69 +#define INTERP_nnssnn 80 +#define INTERP_nnssns 81 +#define INTERP_nnsssn 84 +#define INTERP_nnssss 85 +#define INTERP_nsnnnn 256 +#define INTERP_nsnnns 257 +#define INTERP_nsnnsn 260 +#define INTERP_nsnnss 261 +#define INTERP_nsnsnn 272 +#define INTERP_nsnsns 273 +#define INTERP_nsnssn 276 +#define INTERP_nsnsss 277 +#define INTERP_nssnnn 320 +#define INTERP_nssnns 321 +#define INTERP_nssnsn 324 +#define INTERP_nssnss 325 +#define INTERP_nsssnn 336 +#define INTERP_nsssns 337 +#define INTERP_nssssn 340 +#define INTERP_nsssss 341 +#define INTERP_snnnnn 1024 +#define INTERP_snnnns 1025 +#define INTERP_snnnsn 1028 +#define INTERP_snnnss 1029 +#define INTERP_snnsnn 1040 +#define INTERP_snnsns 1041 +#define INTERP_snnssn 1044 +#define INTERP_snnsss 1045 +#define INTERP_snsnnn 1088 +#define INTERP_snsnns 1089 +#define INTERP_snsnsn 1092 +#define INTERP_snsnss 1093 +#define INTERP_snssnn 1104 +#define INTERP_snssns 1105 +#define INTERP_snsssn 1108 +#define INTERP_snssss 1109 +#define INTERP_ssnnnn 1280 +#define INTERP_ssnnns 1281 +#define INTERP_ssnnsn 1284 +#define INTERP_ssnnss 1285 +#define INTERP_ssnsnn 1296 +#define INTERP_ssnsns 1297 +#define INTERP_ssnssn 1300 +#define INTERP_ssnsss 1301 +#define INTERP_sssnnn 1344 +#define INTERP_sssnns 1345 +#define INTERP_sssnsn 1348 +#define INTERP_sssnss 1349 +#define INTERP_ssssnn 1360 +#define INTERP_ssssns 1361 +#define INTERP_sssssn 1364 #define INTERP_ssssss 1365 +#define INTERP_iiiiii 2730 +#define INTERP_rrrrrr 4095 #define INTERP_nnnnnnnn 0 #define INTERP_ssssssss 21845 @@ -119,6 +226,7 @@ extern int nosc_enabled; /* enable polling for OSC messages */ #define INTERP_SHIFT 2 LVAL snd_badsr(void); +long check_terminate_cnt(long tc); typedef double time_type; typedef double rate_type; @@ -141,6 +249,11 @@ typedef double promoted_sample_type; #define max_sample_block_len 1020 /* #define max_sample_block_len 4 */ +/* longest allowed sample is basically 2^31 but a bit lower to + allow for rounding */ +#define MAX_SND_LEN (MAX_STOP - max_sample_block_len * 2) + + /* Defines needed for xlisp */ #define getsound(x) ((sound_type) getinst(x)) #define xlgasound() (testarg(typearg(soundp))) @@ -156,18 +269,21 @@ typedef struct { } sample_block_node, *sample_block_type; +/* forward declaration for circular type dependencies */ +typedef struct snd_list_struct *snd_list_type; + typedef struct snd_susp_struct { - void (*fetch)(); - void (*keep_fetch)(); - void (*free)(); - void (*mark)(); /* marks LVAL nodes for GC */ - void (*print_tree)(); /* debugging */ - char * name; /* string name for debugging */ - long toss_cnt; /* return this many zeros, then compute */ - long current; /* current sample number */ - double sr; /* sample rate */ - time_type t0; /* starting time */ - long log_stop_cnt; /* logical stop count */ + void (*fetch)(struct snd_susp_struct *, snd_list_type snd_list); + void (*keep_fetch)(struct snd_susp_struct *, snd_list_type snd_list); + void (*free)(struct snd_susp_struct *); + void (*mark)(struct snd_susp_struct *); /* marks LVAL nodes for GC */ + void (*print_tree)(struct snd_susp_struct *, int); /* debugging */ + char *name; /* string name for debugging */ + long toss_cnt; /* return this many zeros, then compute */ + long current; /* current sample number */ + double sr; /* sample rate */ + time_type t0; /* starting time */ + long log_stop_cnt; /* logical stop count */ /* other susp dependent stuff will be here... */ } snd_susp_node, *snd_susp_type; @@ -177,11 +293,11 @@ typedef struct snd_list_struct { union { struct snd_list_struct *next; snd_susp_type susp; - } u; - short refcnt; - short block_len; - boolean logically_stopped; -} snd_list_node, *snd_list_type; + } u; + short refcnt; + short block_len; + boolean logically_stopped; +} snd_list_node; /* , *snd_list_type; -- defined above */ extern snd_list_type list_watch; //DBY @@ -200,7 +316,7 @@ typedef struct table_struct { #define UNKNOWN (-10-max_sample_block_len) typedef struct sound_struct { - sample_block_type (*get_next)(/* struct sound_struct *snd, long *cnt */); + sample_block_type (*get_next)(struct sound_struct *snd, long *cnt); time_type time; /* logical starting time */ time_type t0; /* quantized time of first sample */ long stop; /* stop (clipping) sample no. */ @@ -216,7 +332,7 @@ typedef struct sound_struct { long prepend_cnt; /* how many zeros to prepend */ /* function to use as get_next after prepended zeros are generated: */ sample_block_type (*after_prepend) - (/* struct sound_struct * snd, long * cnt */); + (struct sound_struct * snd, long * cnt); table_type table; /* pointer to table-ized version of this sound */ long *extra; /* used for extra state information, first word of extra state should be the length of the extra state @@ -242,14 +358,14 @@ double snd_set_latency(double latency); double compute_phase(double phase, double key, long n, double srate, double new_srate, double freq, double *incr_ptr); -boolean soundp(); +boolean soundp(LVAL); /* LISP: (SOUNDP ANY) */ void snd_list_ref(snd_list_type list); void sound_unref(sound_type snd); void snd_list_unref(snd_list_type list); -LVAL cvsound(); +LVAL cvsound(sound_type); extern LVAL a_sound; sample_block_type SND_get_next(sound_type snd, long * cnt); @@ -257,9 +373,9 @@ sample_block_type SND_get_first(sound_type snd, long * cnt); sample_block_type SND_get_zeros(sound_type snd, long * cnt); sample_block_type SND_flush(sound_type snd, long * cnt); -double hz_to_step(); /* LISP: (HZ-TO-STEP ANYNUM) */ +double hz_to_step(double); /* LISP: (HZ-TO-STEP ANYNUM) */ int interp_style(sound_type s, rate_type sr); -void set_logical_stop_time(); /* LISP: (SND-SET-LOGICAL-STOP SOUND ANYNUM) */ +void set_logical_stop_time(sound_type sound, time_type when); /* LISP: (SND-SET-LOGICAL-STOP SOUND ANYNUM) */ #define xlog(x) log(x) /* LISP: double (LOG FLONUM) */ @@ -307,17 +423,17 @@ long sound_nth_block(sound_type snd, long n); sound_type sound_copy(sound_type snd); /* LISP: (SND-COPY SOUND) */ -void sound_xlmark(sound_type s); +void sound_xlmark(void *a_sound); void sound_print(LVAL snd_expr, long n); /* LISP: (SND-PRINT ANY FIXNUM) */ void sound_play(LVAL snd_expr); /* LISP: (SND-PLAY ANY) */ -void stats(); +void stats(void); /* LISP: (STATS) */ void sound_print_tree(sound_type snd); /* LISP: (SND-PRINT-TREE SOUND) */ -void mark_audio_time(); +void mark_audio_time(void); void sound_print_tree_1(sound_type snd, int n); @@ -338,9 +454,13 @@ sound_type sound_zero(time_type t0, rate_type sr); #define susp_print_tree(s, n) (*((s)->print_tree))(s, n) -double step_to_hz(); +double step_to_hz(double); /* LISP: (STEP-TO-HZ ANYNUM) */ +#ifdef WIN32 +double log2(double x); +#endif WIN32 + /* macros for access to samples within a suspension */ /* NOTE: assume suspension structure is named "susp" */ diff --git a/lib-src/libnyquist/nyquist/nyqsrc/stats.c b/lib-src/libnyquist/nyquist/nyqsrc/stats.c index 7f2161265..e605d7137 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/stats.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/stats.c @@ -12,7 +12,6 @@ #include "sound.h" #include "falloc.h" - void stats() { nyquist_printf("\n\nNyquist statistics:\n\n"); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/trigger.c b/lib-src/libnyquist/nyquist/nyqsrc/trigger.c index f55ba95b3..58a35b6a8 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/trigger.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/trigger.c @@ -80,13 +80,14 @@ typedef struct trigger_susp_struct { } trigger_susp_node, *trigger_susp_type; -void trigger_fetch(trigger_susp_type, snd_list_type); +void trigger_fetch(snd_susp_type, snd_list_type); void trigger_free(); extern LVAL s_stdout; -void trigger_mark(trigger_susp_type susp) +void trigger_mark(snd_susp_type a_susp) { + trigger_susp_type susp = (trigger_susp_type) a_susp; sound_xlmark(susp->s1); if (susp->closure) mark(susp->closure); } @@ -95,8 +96,9 @@ void trigger_mark(trigger_susp_type susp) /* trigger_fetch returns zero blocks until s1 goes from <=0 to >0 */ /**/ -void trigger_fetch(trigger_susp_type susp, snd_list_type snd_list) +void trigger_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + trigger_susp_type susp = (trigger_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -208,7 +210,7 @@ D nyquist_printf("in trigger: after evaluation; " D stdputstr("in trigger: calling add's fetch\n"); /* fetch will get called later .. - (*(susp->susp.fetch))(susp, snd_list); */ + (*(susp->susp.fetch))(a_susp, snd_list); */ D stdputstr("in trigger: returned from add's fetch\n"); xlpop(); @@ -217,8 +219,9 @@ D stdputstr("in trigger: returned from add's fetch\n"); /* but if cnt == 0, then we haven't computed any samples */ /* call on new fetch routine to get some samples */ if (cnt == 0) { - ffree_sample_block(out, "trigger-pre-adder"); // because adder will reallocate - (*susp->susp.fetch)(susp, snd_list); + // because adder will reallocate + ffree_sample_block(out, "trigger-pre-adder"); + (*susp->susp.fetch)(a_susp, snd_list); } return; } else { @@ -244,16 +247,18 @@ D stdputstr("in trigger: returned from add's fetch\n"); } /* trigger_fetch */ -void trigger_free(trigger_susp_type susp) +void trigger_free(snd_susp_type a_susp) { + trigger_susp_type susp = (trigger_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->s2); ffree_generic(susp, sizeof(trigger_susp_node), "trigger_free"); } -void trigger_print_tree(trigger_susp_type susp, int n) +void trigger_print_tree(snd_susp_type a_susp, int n) { + trigger_susp_type susp = (trigger_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); diff --git a/lib-src/libnyquist/nyquist/nyqsrc/yin.c b/lib-src/libnyquist/nyquist/nyqsrc/yin.c index b034c4da4..9796ba228 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/yin.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/yin.c @@ -271,8 +271,9 @@ void yin_compute(yin_susp_type susp, float *pitch, float *harmonicity) * deallocated, because it can only be referenced through the * snd_list nodes to which there are backpointers. */ -void yin_fetch(yin_susp_type susp, snd_list_type snd_list) +void yin_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + yin_susp_type susp = (yin_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -478,14 +479,16 @@ void yin_fetch(yin_susp_type susp, snd_list_type snd_list) } /* yin_fetch */ -void yin_mark(yin_susp_type susp) +void yin_mark(snd_susp_type a_susp) { + yin_susp_type susp = (yin_susp_type) a_susp; sound_xlmark(susp->s); } -void yin_free(yin_susp_type susp) +void yin_free(snd_susp_type a_susp) { + yin_susp_type susp = (yin_susp_type) a_susp; int j; boolean active = false; /* stdputstr("yin_free: "); */ @@ -509,8 +512,9 @@ void yin_free(yin_susp_type susp) } -void yin_print_tree(yin_susp_type susp, int n) +void yin_print_tree(snd_susp_type a_susp, int n) { + yin_susp_type susp = (yin_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); diff --git a/lib-src/libnyquist/nyquist/nyqstk/include/ReedTabl.h b/lib-src/libnyquist/nyquist/nyqstk/include/ReedTabl.h new file mode 100644 index 000000000..e6f97a5d5 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqstk/include/ReedTabl.h @@ -0,0 +1,70 @@ +/***************************************************/ +/*! \class ReedTabl + \brief STK reed table class. + + This class implements a simple one breakpoint, + non-linear reed function, as described by + Smith (1986). This function is based on a + memoryless non-linear spring model of the reed + (the reed mass is ignored) which saturates when + the reed collides with the mouthpiece facing. + + See McIntyre, Schumacher, & Woodhouse (1983), + Smith (1986), Hirschman, Cook, Scavone, and + others for more information. + + by Perry R. Cook and Gary P. Scavone, 1995 - 2002. +*/ +/***************************************************/ + +#if !defined(__REEDTABL_H) +#define __REEDTABL_H + +#include "Stk.h" + +class ReedTabl : public Stk +{ +public: + //! Default constructor. + ReedTabl(); + + //! Class destructor. + ~ReedTabl(); + + //! Set the table offset value. + /*! + The table offset roughly corresponds to the size + of the initial reed tip opening (a greater offset + represents a smaller opening). + */ + void setOffset(MY_FLOAT aValue); + + //! Set the table slope value. + /*! + The table slope roughly corresponds to the reed + stiffness (a greater slope represents a harder + reed). + */ + void setSlope(MY_FLOAT aValue); + + //! Return the last output value. + MY_FLOAT lastOut() const; + + //! Return the function value for \e input. + /*! + The function input represents the differential + pressure across the reeds. + */ + MY_FLOAT tick(MY_FLOAT input); + + //! Take \e vectorSize inputs and return the corresponding function values in \e vector. + MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize); + +protected: + MY_FLOAT offSet; + MY_FLOAT slope; + MY_FLOAT lastOutput; + +}; + +#endif diff --git a/lib-src/libnyquist/nyquist/nyqstk/src/FileRead.cpp b/lib-src/libnyquist/nyquist/nyqstk/src/FileRead.cpp index 79034bee0..37027fd07 100644 --- a/lib-src/libnyquist/nyquist/nyqstk/src/FileRead.cpp +++ b/lib-src/libnyquist/nyquist/nyqstk/src/FileRead.cpp @@ -36,6 +36,15 @@ #include #include #include +#include + +/* this is defined in xlisp.h, but it seems a bad idea + * to create an stk dependency on xlisp, or to add a new + * security.h file to share between xlisp.h and stk + */ +extern "C" { + int ok_to_open(const char *filename, const char *mode); +} using namespace Nyq; @@ -47,7 +56,7 @@ FileRead :: FileRead() FileRead :: FileRead( std::string fileName, bool typeRaw ) : fd_(0) { - open( fileName, typeRaw ); + open( fileName, typeRaw ); } FileRead :: ~FileRead() @@ -75,7 +84,9 @@ void FileRead :: open( std::string fileName, bool typeRaw ) close(); // Try to open the file. - fd_ = fopen( fileName.c_str(), "rb" ); + fd_ = NULL; + if (ok_to_open(fileName.c_str(), "rb")) + fd_ = fopen( fileName.c_str(), "rb" ); if ( !fd_ ) { errorString_ << "FileRead::open: could not open or find file (" << fileName << ")!"; handleError( StkError::FILE_NOT_FOUND ); diff --git a/lib-src/libnyquist/nyquist/nyqstk/src/ReedTabl.cpp b/lib-src/libnyquist/nyquist/nyqstk/src/ReedTabl.cpp new file mode 100644 index 000000000..4ca6d6565 --- /dev/null +++ b/lib-src/libnyquist/nyquist/nyqstk/src/ReedTabl.cpp @@ -0,0 +1,71 @@ +/***************************************************/ +/*! \class ReedTabl + \brief STK reed table class. + + This class implements a simple one breakpoint, + non-linear reed function, as described by + Smith (1986). This function is based on a + memoryless non-linear spring model of the reed + (the reed mass is ignored) which saturates when + the reed collides with the mouthpiece facing. + + See McIntyre, Schumacher, & Woodhouse (1983), + Smith (1986), Hirschman, Cook, Scavone, and + others for more information. + + by Perry R. Cook and Gary P. Scavone, 1995 - 2002. +*/ +/***************************************************/ + +#include "ReedTabl.h" + +ReedTabl :: ReedTabl() +{ + offSet = (MY_FLOAT) 0.6; // Offset is a bias, related to reed rest position. + slope = (MY_FLOAT) -0.8; // Slope corresponds loosely to reed stiffness. +} + +ReedTabl :: ~ReedTabl() +{ + +} + +void ReedTabl :: setOffset(MY_FLOAT aValue) +{ + offSet = aValue; +} + +void ReedTabl :: setSlope(MY_FLOAT aValue) +{ + slope = aValue; +} + +MY_FLOAT ReedTabl :: lastOut() const +{ + return lastOutput; +} + +MY_FLOAT ReedTabl :: tick(MY_FLOAT input) +{ + // The input is differential pressure across the reed. + lastOutput = offSet + (slope * input); + + // If output is > 1, the reed has slammed shut and the + // reflection function value saturates at 1.0. + if (lastOutput > 1.0) lastOutput = (MY_FLOAT) 1.0; + + // This is nearly impossible in a physical system, but + // a reflection function value of -1.0 corresponds to + // an open end (and no discontinuity in bore profile). + if (lastOutput < -1.0) lastOutput = (MY_FLOAT) -1.0; + return lastOutput; +} + +MY_FLOAT *ReedTabl :: tick(MY_FLOAT *vector, unsigned int vectorSize) +{ + for (unsigned int i=0; i +#include +#include +#include "macstuff.h" +#include "MacCommandWin.h" +#include "MacFileUtils.h" +//#include "MiscellaneousUtilities.h" + +#define TEXTREC (*hTERec) // the command +extern TEHandle hTERec; // window text record + + +//========================================================================= +// Handle quit apple event +//========================================================================= + +pascal OSErr AEQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon) +{ + osfinish(); +} + +//========================================================================= +// Handle Open Document apple event by trying to load it. +//========================================================================= +extern xlload (char *, int, int); +extern xlabort(char *); + +pascal OSErr AEOpenFiles(AppleEvent *theAppleEvent, AppleEvent *theReply, + long Refcon) +{ + AEDescList docList; + AEKeyword keywd; + DescType returnedType; + Size actualSize; + long itemsInList; + FSSpec theSpec; + CInfoPBRec pb; + Str255 name; + short i; + + if (AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList) != + noErr) return; + if (AECountItems (&docList, &itemsInList) != noErr) return; + + SetSelection (TEXTREC->teLength, TEXTREC->teLength); + for (i = 1; i <= itemsInList; i++) { + AEGetNthPtr (&docList, i, typeFSS, &keywd, &returnedType, + (Ptr) &theSpec, sizeof(theSpec), &actualSize); + + GetFullPath(&theSpec, name); + P2CStr(name); // was: pstrterm(name); + if (xlload ((char *)name + 1, 1, 0) == 0) xlabort ("load error"); + } + macputs ("> "); + PrepareForInput (); +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.c b/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.c new file mode 100644 index 000000000..c3336aade --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.c @@ -0,0 +1,764 @@ +//============================================================================= +// All command window updates, input, etc happen here -EAD +//============================================================================= +#include +/* #include */ +#include +#include +#include +#include "MacGlobals.h" +#include "macint.h" +#include +#define NIL ((void *) 0) + +//============================================================================= +// local variables +//============================================================================= + +ControlHandle vScroll; +int cursorPos; /* the cursor's position on the line */ +short linesInView; /* how many lines are in the window */ +int cmdStart; /* where (in text record) the current command starts */ +TextStyle textStyle[2]; /* styles: bold for user input, plain for output */ +/* output is buffered */ +Handle hOutputBuffer = NULL; +enum currentStyle { plainStyle, boldStyle } currentStyle; + +static void GoStartOfLine (void); +static void GoEndOfLine (void); +static void GoBackOneWord (void); +static void GoForwardOneWord (void); + +//============================================================================= +// static void DoScrollBar (ControlHandle control, short change) +//============================================================================= +/* keep track of the user as he fiddles with the scroll bar */ +/* This routine is called while the user has the mouse down. */ +/* It makes sure the thumb isn't dragged out-of-bounds. */ +//============================================================================= + +static void DoScrollBar (ControlHandle control, short change) { + short value = GetControlValue (control), max = GetControlMaximum (control); + long newval = value + change; /* this is a long in case we try to go past MAX_INT */ + if (newval < 0) newval = 0; else if (newval > max) newval = max; + SetControlValue (control, (short) newval); + if (newval != value) TEScroll (0, (short) (value - newval) * LINEHEIGHT, hTERec); +} + +//============================================================================= +// pascal Boolean ScrollClickLoop (void) +//============================================================================= +// +//============================================================================= + +pascal Boolean ScrollClickLoop (void) { + Rect tempRect; + Point mouse; + GrafPtr oldPort; + RgnHandle oldClip; + short amount = 0; + + if (FrontWindow () != gCommandWin) return false; + + GetPort (&oldPort); + SetPort (gCommandWin); + GetClip (oldClip = NewRgn ()); + SetRect (&tempRect, INT_MIN, INT_MIN, INT_MAX, INT_MAX); + ClipRect (&tempRect); + + GetMouse (&mouse); + if (mouse.v < TEXTREC->viewRect.top) DoScrollBar (vScroll, -1); + else if (mouse.v > TEXTREC->viewRect.bottom) DoScrollBar (vScroll, 1); + + SetClip (oldClip); + DisposeRgn (oldClip); + SetPort (oldPort); + return true; +} + +//============================================================================= +// static pascal void ScrollProc (ControlHandle control, short thePart) +//============================================================================= +// for clicks in the scroll bar or arrows; update the window properly +//============================================================================= + +pascal void ScrollProc (ControlHandle control, short thePart) { + short amount; + WindowPtr window; + + if (!thePart) return; + window = (*control)->contrlOwner; + switch (thePart) { + case kControlUpButtonPart: amount = -1; break; + case kControlDownButtonPart: amount = 1; break; + case kControlPageUpPart: amount = -linesInView; break; + case kControlPageDownPart: amount = linesInView; break; + } + DoScrollBar (control, amount); +} + +//============================================================================= +// Rect SetTERect (void) +//============================================================================= +// set the dimensions of the text record in its window +//============================================================================= + +Rect SetTERect (void) { + Rect teRect = gCommandWin->portRect; + teRect.right -= SCROLLER_WIDTH; + InsetRect (&teRect, TEXT_MARGIN, TEXT_MARGIN); + linesInView = (teRect.bottom - teRect.top) / LINEHEIGHT; + teRect.bottom = teRect.top + linesInView * LINEHEIGHT; /* round off */ + return teRect; +} + +//============================================================================= +// static void AdjustCursor (EventRecord *theEvent) +//============================================================================= +// make the pointer an I-beam iff it's in the text window +//============================================================================= + +void AdjustCursor (Point theLoc, RgnHandle theRgn) +{ + RgnHandle arrowRgn, iBeamRgn, hiliteRgn, tempRgn; + Rect theRect; + Point thePoint; + + if (gInBackground) + return; + + arrowRgn = NewRgn(); + SetRectRgn(arrowRgn, -32767, -32767, 32767, 32767); + +// GlobalToLocal ((theLoc); ??? + + if (gCommandWin == FrontWindow () ) { + SetPort(gCommandWin); + iBeamRgn = NewRgn(); + hiliteRgn = NewRgn(); + + theRect = TEXTREC->viewRect; + LocalToGlobal((Point *)&(theRect.top)); + LocalToGlobal((Point *)&(theRect.bottom)); + RectRgn(iBeamRgn, &theRect); + + TEGetHiliteRgn(hiliteRgn, hTERec); + thePoint.h = thePoint.v = 0; + LocalToGlobal(&thePoint); + OffsetRgn(hiliteRgn, thePoint.h, thePoint.v); + + DiffRgn(arrowRgn, hiliteRgn, arrowRgn); + DiffRgn(arrowRgn, iBeamRgn, arrowRgn); + + DiffRgn(iBeamRgn, hiliteRgn, iBeamRgn); + + if (PtInRgn(theLoc, iBeamRgn)) { + SetCursor(*GetCursor(iBeamCursor)); + CopyRgn(iBeamRgn, theRgn); + } else if (PtInRgn(theLoc, hiliteRgn)) { + SetCursor(&qd.arrow); + CopyRgn(hiliteRgn, theRgn); + } else { + SetCursor(&qd.arrow); + CopyRgn(arrowRgn, theRgn); + } + + DisposeRgn(iBeamRgn); + DisposeRgn(hiliteRgn); + + } else { + SetCursor(&qd.arrow); + CopyRgn(arrowRgn, theRgn); + } + + DisposeRgn(arrowRgn); +} + + + +//============================================================================= +// static void SetScrollRect (void) +//============================================================================= +// Set Scroll bar rec size +//============================================================================= + +void SetScrollRect (void) { + /* set the dimensions of the scroll bar in its window */ + +// This change fixes the double flash on window resize -EAD + +// MoveControl (vScroll, commandWin->portRect.right - SCROLLER_WIDTH, -1); +// SizeControl (vScroll, SCROLLER_WIDTH + 1, +// (commandWin->portRect.bottom - commandWin->portRect.top) - (SCROLLER_WIDTH - 2)); + (*vScroll)->contrlRect.left = gCommandWin->portRect.right - SCROLLER_WIDTH; + (*vScroll)->contrlRect.top = -1; + (*vScroll)->contrlRect.right = gCommandWin->portRect.right + 1; + (*vScroll)->contrlRect.bottom = gCommandWin->portRect.bottom - (SCROLLER_WIDTH - 1); + +} + +//============================================================================= +// static void AdjustScrollBar (void) +//============================================================================= +// Set the thumb on scrollbar +//============================================================================= + +static void AdjustScrollBar (void) { + /* adjust the scroll bar to match the position of the text view */ + short oldval = GetControlValue (vScroll), oldmax = GetControlMaximum (vScroll); + short value, max; + short test; + + max = TEXTREC->nLines - linesInView; + if ((TEXTREC->teLength > 0) && (*(*TEXTREC->hText + TEXTREC->teLength - 1) == '\r')) max++; + if (max < 0) max = 0; + if (max != oldmax) SetControlMaximum (vScroll, max); + value = (short)((TEXTREC->viewRect.top - TEXTREC->destRect.top) / LINEHEIGHT); +// value = roundup ((TEXTREC->viewRect.top - TEXTREC->destRect.top) / LINEHEIGHT); + if (value < 0) value = 0; else if (value > max) value = max; + if (value != oldval) SetControlValue (vScroll, value); +} + +static short roundup (float x) { /* a kludge to round up a float to an int */ + if (((int) x) != ((int) (x += 0.5))) x += 0.5; + return (int) x; +} + +//============================================================================= +// void DoKeyPress (EventRecord *theEvent) +//============================================================================= +// Hanlde Keyboard Input +//============================================================================= + +void DoKeyPress (EventRecord *theEvent) { + short whatKey = theEvent->message & charCodeMask; + if (theEvent->modifiers & cmdKey) { + long choice; + AdjustMenus (); + if (choice = MenuKey (theEvent->message)) DoMenu (choice); + else if (((whatKey == 'w') || (whatKey == 'W')) && (FrontWindow () == gGraphicsWin)) + HideGrafWin (); + else if (whatKey == LEFTARROW) GoStartOfLine (); + else if (whatKey == RIGHTARROW) GoEndOfLine (); + else if (whatKey == UPARROW) DoScrollBar (vScroll, - linesInView); + else if (whatKey == DOWNARROW) DoScrollBar (vScroll, linesInView); + } + else if (theEvent->modifiers & optionKey) { + if (whatKey == LEFTARROW) GoBackOneWord (); + else if (whatKey == RIGHTARROW) GoForwardOneWord (); + } + else switch (whatKey) { + case PAGEUP: DoScrollBar (vScroll, -linesInView); break; + case PAGEDN: DoScrollBar (vScroll, linesInView); break; + case HOMEKEY: DoScrollBar (vScroll, INT_MIN); break; + case ENDKEY: DoScrollBar (vScroll, INT_MAX); break; + case FNKEY: break; + case HELPKEY: break; + default: recentChar = theEvent->message & charCodeMask; + } +} + +//============================================================================= +// static void DrawOnlyGrowIcon (WindowPtr window) +//============================================================================= +// draw growbox on command window with no scoll bars +//============================================================================= + +static void DrawOnlyGrowIcon (WindowPtr window) +{ + RgnHandle saveRgn; + Rect growRect; + + growRect = window->portRect; + growRect.top = growRect.bottom - SCROLLER_WIDTH; + growRect.left = growRect.right - SCROLLER_WIDTH; + GetClip (saveRgn = NewRgn ()); + ClipRect (&growRect); + DrawGrowIcon (window); + SetClip (saveRgn); + DisposeRgn (saveRgn); +} + +//============================================================================= +// void SetSelection (short start, short end) +//============================================================================= +// set text selection in the command window +//============================================================================= + +void SetSelection (short start, short end) { + TEXTREC->clikStuff = 255; /* to make sure the caret appears at the start of a line when it should */ + /* see tech note "TextEdit EOL Ambiguity" for more information */ + TESetSelect (start, end, hTERec); +} + +//============================================================================= +// static void CancelFlash (void) +//============================================================================= +// cancel the matching-paren flashing +//============================================================================= + +static void CancelFlash (void) { + if (flashTime) { + flashTime = 0; + SetSelection (cursorBeforeFlash, cursorBeforeFlash); + } +} + +//============================================================================= +// static void StopPasting (void) +//============================================================================= +// clean up after finishing a paste +//============================================================================= + +void StopPasting (void) { + pastedLength = 0; + if (pastedTextH) { + DisposeHandle (pastedTextH); + pastedTextH = NULL; + } +} + +//============================================================================= +// static void DoStyle (int whatStyle) +//============================================================================= +// set the text to a certain style +//============================================================================= + +static void DoStyle (int whatStyle) { + TESetStyle (doFace, &(textStyle[whatStyle]), false, hTERec); +} + +//============================================================================= +// static void FlushOutput (void) +//============================================================================= +// clear out the output buffer, dumping its contents to the window +//============================================================================= + +void FlushOutput (void) { + short totalLines, scrollAmount, max; + + if (outputBufferLength == 0) return; + CancelFlash (); + DoStyle (plainStyle); + HLock (hOutputBuffer); + TEInsert (*hOutputBuffer, outputBufferLength, hTERec); + HUnlock (hOutputBuffer); + outputBufferLength = 0; + + if (TEXTREC->teLength > SCROLLBACK_THRESHHOLD) { + /* make sure TE record isn't too long */ +#ifdef ORIGINALCODE + /* I replaced this because Nyquist was crashing after the + buffer got filled. The replacement below is simpler and + eliminates the crashes, although it probably could cause + problems by clearing the selection. + */ + int i = 1, newLength; + TEPtr textPtr; + while ((TEXTREC->teLength - TEXTREC->lineStarts[i]) > + (SCROLLBACK_THRESHHOLD - DELETE_BLOCK)) i++; + i = TEXTREC->lineStarts[i]; + newLength = TEXTREC->teLength - i; + textPtr = (TEPtr)(*(TEXTREC->hText)); + BlockMoveData ((Ptr)((long)textPtr + i), textPtr, newLength); + SetHandleSize (TEXTREC->hText, newLength); + TEXTREC->destRect.top += LINEHEIGHT; + TECalText (hTERec); + TEUpdate (&(TEXTREC->viewRect), hTERec); +#else + /* find the line start after DELETE_BLOCK */ + int i = 1; + while (TEXTREC->lineStarts[i] < DELETE_BLOCK) i++; + TESetSelect(0, TEXTREC->lineStarts[i], hTERec); + TEDelete(hTERec); + /* after deletion, put cursor back at end of buffer */ + TESetSelect(TEXTREC->teLength, TEXTREC->teLength, hTERec); +#endif + } + TESelView (hTERec); + AdjustScrollBar (); +} + +//============================================================================= +// void PrepareForInput (void) +//============================================================================= +// get ready to take input +//============================================================================= + +void PrepareForInput (void) { + FlushOutput (); + cmdStart = TEXTREC->selStart; +} + +//============================================================================= +// static void DeleteRange (void) +//============================================================================= +// delete the selected range of text, updating cmdStart as necessary +//============================================================================= + +void DeleteRange (void) { + if (TEXTREC->selEnd <= cmdStart) return; + if (TEXTREC->selStart < cmdStart) SetSelection (cmdStart, TEXTREC->selEnd); + TEDelete (hTERec); +} + +//============================================================================= +// static void CopyThisLineToEnd (void) +//============================================================================= +// copy the line the caret is on to the end +//============================================================================= + +static void CopyThisLineToEnd (void) { + char *buffer; + short b, i, caretOffset; + + /* first find out exactly where it starts */ + i = TEXTREC->nLines-1; /* first find which line */ + while (TEXTREC->selStart < TEXTREC->lineStarts[i]) i--; + while ((i > 0) && ((*(TEXTREC->hText))[TEXTREC->lineStarts[i]-1] != '\r')) + i--; /* for wrapped lines */ + i = TEXTREC->lineStarts[i]; /* now zero in on the exact character where it begins */ + while ((TEXTCHAR(i) >= '0') && (TEXTCHAR(i) <= '9')) i++; /* skip error level */ + if ((TEXTCHAR(i) == '>') && (TEXTCHAR(i+1) == ' ')) i+=2; /* get rid of leading prompt */ + + caretOffset = TEXTREC->selStart - i; /* how many characters in is the caret? */ + + /* now put the line into the buffer */ + b = 0; + while ((TEXTCHAR(i+b) != '\r') && (i+b < TEXTREC->teLength)) b++; /* find the end of the line */ + buffer = (char *) NewPtr (b); + BlockMoveData (*TEXTREC->hText + i, buffer, b); + buffer[b] = '\0'; + + /* delete whatever's already on the last line */ + SetSelection (cmdStart, TEXTREC->teLength); + TEDelete (hTERec); + + DoStyle (boldStyle); + TEInsert (buffer, b, hTERec); + DisposePtr (buffer); + + if (caretOffset < 0) caretOffset = b; + SetSelection (cmdStart + caretOffset, cmdStart + caretOffset); +} + +//============================================================================= +// Next four functions possition cursor in text +//============================================================================= + +static void GoStartOfLine (void) { + short whichLine = TEXTREC->nLines - 1; /* look for the caret; start at the end and go up */ + while (TEXTREC->lineStarts[whichLine] > TEXTREC->selStart) whichLine--; + SetSelection (TEXTREC->lineStarts[whichLine], TEXTREC->lineStarts[whichLine]); + AdjustScrollBar (); +} + +static void GoEndOfLine (void) { + short whichLine = TEXTREC->nLines - 1; /* look for the caret; start at the end and go up */ + while (TEXTREC->lineStarts[whichLine] > TEXTREC->selStart) whichLine--; + if (whichLine == TEXTREC->nLines - 1) + SetSelection (TEXTREC->teLength, TEXTREC->teLength); + else SetSelection (TEXTREC->lineStarts[whichLine+1] - 1, TEXTREC->lineStarts[whichLine+1] - 1); + AdjustScrollBar (); +} + +static void GoBackOneWord (void) { + short i = TEXTREC->selStart; + while ((i > 0) && !isalnum (TEXTCHAR(i-1))) i--; + while ((i > 0) && isalnum (TEXTCHAR(i-1))) i--; + SetSelection (i, i); +} + +static void GoForwardOneWord (void) { + short i = TEXTREC->selStart; + while ((i < TEXTREC->teLength) && !isalnum (TEXTCHAR(i))) i++; + while ((i < TEXTREC->teLength) && isalnum (TEXTCHAR(i))) i++; + SetSelection (i, i); +} + + +//============================================================================= +// static void EditFreely (void) +//============================================================================= +// Enter text into the command windows +//============================================================================= + +static void EditFreely (void) { + Boolean done; + do { + done = false; + DoEvent (); + if (pastedLength > 0) { /* if there is still text to paste, paste it */ + int i = 0; + CancelFlash (); + if (TEXTREC->selStart < cmdStart) StopPasting (); + else { + while ((i < pastedLength) && (((char *)(*pastedTextH))[i] != '\r')) i++; + DoStyle (boldStyle); + TEInsert (*pastedTextH, i, hTERec); + AdjustScrollBar (); + if (i < pastedLength) { /* we were stopped by a carriage return, so eat it */ + i++; + done = true; + } + pastedLength -= i; + if (pastedLength > 0) { + BlockMoveData ((Ptr)((long)(*pastedTextH) + i), *pastedTextH, pastedLength); + SetHandleSize (pastedTextH, pastedLength); + } else StopPasting (); + } + } + else if (recentChar) { /* if the last event got us a character, process it */ + int i; + Boolean wasOnLastLine; + CancelFlash (); + + if ((TEXTREC->selEnd <= cmdStart) && (TEXTREC->selStart != TEXTREC->selEnd)) continue; + if (TEXTREC->selStart < cmdStart) SetSelection (cmdStart, TEXTREC->selEnd); + wasOnLastLine = (TEXTREC->selStart >= cmdStart); + + if ((recentChar & 0xfc) == 0x1c) { /* was this an arrow key? */ + TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */ + TEKey (recentChar, hTERec); + AdjustScrollBar (); + continue; + } + if (!wasOnLastLine) CopyThisLineToEnd (); + switch (recentChar) { + case FWDDEL: + if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange (); + else if ((TEXTREC->selStart >= cmdStart) && (TEXTREC->selStart < TEXTREC->teLength)) { + TEDeactivate (hTERec); + SetSelection (TEXTREC->selStart, TEXTREC->selStart + 1); + TEDelete (hTERec); + if (FrontWindow () == gCommandWin) TEActivate (hTERec); + } + break; + case CLRKEY: + if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange (); + break; + case DELETE: + if (TEXTREC->selStart != TEXTREC->selEnd) DeleteRange (); + else if (TEXTREC->selStart > cmdStart) { + TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */ + TEKey (DELETE, hTERec); + } + break; + case RETURN: + if (wasOnLastLine) done = true; + break; + case ENTER: /* ENTER ends command no matter what */ + done = true; + break; + default: + DoStyle (boldStyle); + TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */ + TEKey (recentChar, hTERec); + if ((recentChar == ')') && (TEXTREC->selStart > cmdStart)) { + short parenCount = -1; + Boolean inQuotes = false; + i = TEXTREC->selStart - 1; + while ((--i >= cmdStart) && (parenCount != 0)) + switch ((*TEXTREC->hText)[i]) { + case DBLQUOTE: inQuotes = !inQuotes; break; + case '(': if (!inQuotes) parenCount++; break; + case ')': if (!inQuotes) parenCount--; break; + } + if (parenCount == 0) { + cursorBeforeFlash = TEXTREC->selStart; + SetSelection (i+1, i+2); /* flash the matching open-paren */ + flashTime = 10; + } + } else if ((recentChar == DBLQUOTE) && (TEXTREC->selStart > cmdStart)) { + i = TEXTREC->selStart - 1; + while ((--i >= cmdStart) && ((*TEXTREC->hText)[i] != DBLQUOTE)) ; + if ((*TEXTREC->hText)[i] == DBLQUOTE) { + cursorBeforeFlash = TEXTREC->selStart; + SetSelection (i, i+1); /* flash the matching double-quote */ + flashTime = 10; + } + } + } + AdjustScrollBar (); + } + } while (!done); +} + +char *macgets (void) { + /* retrieve a typed character */ + /* Note that this uses some extensive (and clever, if I may say so myself) buffering. */ + int i, b, bufSize; + char *ptr, *buffer; + Boolean done, onLastLine; + + PrepareForInput (); + do { /* repeat until a full expression has been typed */ + EditFreely (); /* allow free editing for a while */ + + /* Now, we have a complete command to parse, if and only if: */ + /* - the cursor was on the last line when the user pressed Return or Enter, and */ + /* - the user either pressed Enter, or else every '(' since the beginning */ + /* of the command is matched by a ')'. */ + /* Quoting is watched for. ( ") is not a complete expression. */ + + done = true; + if (TEXTREC->selStart != TEXTREC->teLength) /* if we're not at the end already */ + SetSelection (TEXTREC->teLength, TEXTREC->teLength); /* send cursor to end */ + TEXTREC->clikStuff = 255; /* to make sure the caret appears where it should */ + TEKey ('\r', hTERec); + + /* check and see if we've completed the command yet */ + if (recentChar != ENTER) { + Boolean inQuotes = false; + short parenCount = 0; + for (i = cmdStart; i < TEXTREC->teLength; i++) + switch ((*TEXTREC->hText)[i]) { + case DBLQUOTE: inQuotes = !inQuotes; break; + case '(': if (!inQuotes) parenCount++; break; + case ')': if (!inQuotes) parenCount--; break; + } + if ((parenCount > 0) || inQuotes) done = false; + } + + AdjustScrollBar (); + } while (!done); + + /* put the entire command into the buffer, and return it */ + bufSize = TEXTREC->teLength - cmdStart; + buffer = (char *) NewPtr (bufSize + 1); + BlockMoveData (*TEXTREC->hText + cmdStart, buffer, bufSize); + buffer[bufSize] = '\0'; + return buffer; +} + +void macputc (int ch) { + /* put a char into the output buffer, and flush the buffer if necessary */ + switch (ch) { + case '\t': + do { macputc (' '); } while (cursorPos & 7); + break; + case DELETE: + if (cursorPos) cursorPos--; /* and fall through to default */ + default: + if (outputBufferLength == MAX_BUF) FlushOutput (); + if (ch == '\n') { + cursorPos = 0; + (*hOutputBuffer)[outputBufferLength++] = '\r'; + } else { + cursorPos++; + (*hOutputBuffer)[outputBufferLength++] = ch; + } + } +} + +void macputs (char *s) { + /* for completeness */ + while (*s) macputc (*s++); +} + +void scrflush (void) { + extern void osflush (void); + /* clear out everything */ + FlushOutput (); + osflush (); +} + +void scrclear (void) { + /* clear text window -- not implemented */ +} + +//============================================================================= +// static void UpdateCmdWindow (void) +//============================================================================= +// main command window update procedure +//============================================================================= + + +void UpdateCmdWindow (void) { + long textBottom; + Rect tempRect; + + InvalRect (&(gCommandWin->portRect)); + BeginUpdate (gCommandWin); + BlockMoveData(&(gCommandWin->portRect), &tempRect, sizeof(Rect)); + tempRect.right -= SCROLLER_WIDTH; + EraseRect (&tempRect); + if (gCommandWinResized) { + TEXTREC->viewRect = SetTERect (); + TEXTREC->destRect.right = TEXTREC->viewRect.right; + TECalText (hTERec); + SetScrollRect (); + gCommandWinResized = false; + } + DrawOnlyGrowIcon (gCommandWin); + FlushOutput (); + + TEXTREC->viewRect = SetTERect (); /* adjust for possible change in height of status line */ + + textBottom = TEXTREC->destRect.top + (TEXTREC->nLines * LINEHEIGHT); + if (TEXTREC->destRect.top > TEXTREC->viewRect.top) + TEScroll (0, (TEXTREC->viewRect.top - TEXTREC->destRect.top), hTERec); + + if (TEXTREC->destRect.top < TEXTREC->viewRect.top) { /* make sure we don't get fractions of lineheights */ + int amountOffTheTop = TEXTREC->viewRect.top - TEXTREC->destRect.top; + if (amountOffTheTop % LINEHEIGHT) TEScroll (0, amountOffTheTop % LINEHEIGHT, hTERec); + } + TEUpdate (&(TEXTREC->viewRect), hTERec); + AdjustScrollBar (); + UpdateControls (gCommandWin, gCommandWin->visRgn); + EndUpdate (gCommandWin); +} + +void ActivateCmdWindow(void) +{ + TEActivate (hTERec); + HiliteControl (vScroll, 0); + DrawOnlyGrowIcon (gCommandWin); +} + +void DeactivateCmdWindow(void) +{ + TEDeactivate (hTERec); + HiliteControl (vScroll, 255); + DrawOnlyGrowIcon (gCommandWin); +} + +void InitalizeCmdWindow(void) +{ + + /* setup the font, size and writing mode for the command window */ + TextFont (kFontIDMonaco); + TextSize (9); + TextFace (0); + TextMode (srcCopy); + textStyle[plainStyle].tsFace = 0; + textStyle[boldStyle].tsFace = bold; + + currentStyle = plainStyle; + + { /* set up scroll bar */ + Rect scrollRect; + vScroll = NewControl (gCommandWin, &scrollRect, "\p", 0, 0, 0, 0, scrollBarProc, 0L); + SetScrollRect (); + ShowControl (vScroll); + } + + { /* set up command text record */ + Rect teRect = SetTERect (); + hTERec = (TEHandle)TEStyleNew (&teRect, &teRect); + TECalText (hTERec); + TEAutoView (true, hTERec); + TESetClickLoop (uppScrollClickLoop, hTERec); + TEActivate (hTERec); + } + + hOutputBuffer = NewHandle (MAX_BUF); /* a handle to a buffer for text to be displayed */ +} + +void CleanupCmdWindow(void) +{ + StopPasting (); + CloseWindow (gCommandWin); + TEDispose (hTERec); + DisposeHandle (hOutputBuffer); +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.h b/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.h new file mode 100644 index 000000000..20b777537 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacCommandWin.h @@ -0,0 +1,17 @@ +/* MacCommandWin.h -- headers for more mac stuff */ + +void SetSelection (short start, short end); +void macputc(int ch); +void macputs(char *s); +void PrepareForInput(void); +void InitalizeCmdWindow(void); +void UpdateCmdWindow(void); +void StopPasting(void); +void DeleteRange(void); +void scrflush(void); +void SetScrollRect(void); +void AdjustCursor(Point theLoc, RgnHandle theRgn); +void DoKeyPress(EventRecord *theEvent); +void ActivateCmdWindow(void); +void DeactivateCmdWindow(void); +void CleanupCmdWindow(void); diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacDrag.h b/lib-src/libnyquist/nyquist/sys/mac/MacDrag.h new file mode 100644 index 000000000..15a48ca59 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacDrag.h @@ -0,0 +1,3 @@ +/* MacDrag.h -- drag text */ + +Boolean DragText(EventRecord *ev); diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.c b/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.c new file mode 100644 index 000000000..dae8ea4f0 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.c @@ -0,0 +1,81 @@ +// Routines that deal with some mac file system stuff -EAD + +#include +#include +#include +//#include "MiscellaneousUtilities.h" + +//========================================================================= +// Function prototypes +//========================================================================= + +void set_mac_file_type(char *filename); +void GetFullPath(FSSpec *theSpec, StringPtr theName); +void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName); + + + +//========================================================================= +// Set the output soundfile type and creator +//========================================================================= + +void set_mac_file_type(char *filename) +{ + Str255 fName; + FSSpec fSpec; + FInfo fFInfo; + + fFInfo.fdType = 'AIFF'; + fFInfo.fdCreator = 'Sd2a'; + + BlockMoveData(filename, &fName[1], 256); + fName[0] = strlen(filename); + FSMakeFSSpec(0, 0, fName, &fSpec); + FSpSetFInfo(&fSpec, &fFInfo); +} + +//================================================================================================================================== +// void GetFullPath(FSSpec *theSpec, StringPtr theName) +//================================================================================================================================== +// Extracts the full pathname for the file pointed to by theSpec and returns it in theName. +//================================================================================================================================== + +void GetFullPath(FSSpec *theSpec, StringPtr theName) +{ + *theName = 0; + if (theSpec->parID != 1) PathNameFromDirID(theSpec->parID, theSpec->vRefNum, theName); + // was: pstrcat(theName, theSpec->name); + strcat(P2CStr(theName), P2CStr(theSpec->name)); + C2PStr((char *) theName); + C2PStr((char *) theSpec->name); + //pstrcat(theName, "\p:"); + theName[*theName + 1] = 0; +} + +//================================================================================================================================== +// void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName) +//================================================================================================================================== +// Given a vRefNum and a directory ID, creates a full path specification. +//================================================================================================================================== + +void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName) +{ + Str255 directoryName; + DirInfo block; + OSErr err; + fullPathName[0] = 0; + block.ioDrDirID = block.ioDrParID = dirID; + block.ioNamePtr = directoryName; + do { + block.ioVRefNum = vRefNum; + block.ioFDirIndex = -1; + block.ioDrDirID = block.ioDrParID; + err = PBGetCatInfo((CInfoPBPtr)&block, false); + //pstrcat(directoryName, (StringPtr)"\p:"); + //pstrinsert(fullPathName, directoryName); + strcat(P2CStr(directoryName), ":"); + strcat((char *) directoryName, (char *) fullPathName); + strcpy((char *)fullPathName, (char *) directoryName); + } while (block.ioDrDirID != 2); + C2PStr((char *) fullPathName); +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.h b/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.h new file mode 100644 index 000000000..581ff0774 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacFileUtils.h @@ -0,0 +1,3 @@ +/* MacFileUtils.h -- more mac stuff */ + +void GetFullPath(FSSpec *theSpec, StringPtr theName); diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacGlobals.h b/lib-src/libnyquist/nyquist/sys/mac/MacGlobals.h new file mode 100644 index 000000000..e0c85738f --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacGlobals.h @@ -0,0 +1,50 @@ +// Window pointers + +extern WindowPtr gCommandWin, gGraphicsWin; + +extern Boolean gCommandWinResized; + + + +// Menu Handles + +extern MenuHandle appleMenu, fileMenu, editMenu, controlMenu; + + + +// The command window text handle + +extern TEHandle hTERec; + +#define TEXTREC (*hTERec) + +#define TEXTCHAR(i) ((*(TEXTREC->hText))[i]) + + + +// more comand window text stuff + +extern CharsHandle pastedTextH; /* a handle to pasted text */ + +extern int pastedLength; /* how many chars there are in the paste buffer */ + +extern int outputBufferLength; + +extern Rect dragRect, sizeRect; + +extern int flashTime, cursorBeforeFlash; + +extern char recentChar; /* the last character typed */ + + + +// Allocate space for UPPs + +extern ControlActionUPP uppScrollProc; + +extern TEClickLoopUPP uppScrollClickLoop; + + + +extern Boolean gInBackground; + diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.c b/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.c new file mode 100644 index 000000000..d6516c0e8 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include "macint.h" + +extern WindowPtr gCommandWin, gGraphicsWin; +extern Boolean gCommandWinResized; +extern Rect dragRect, sizeRect; + +//============================================================================= +// Hanlde Mouse Down Events +//============================================================================= + +void DoMouseDown (EventRecord *theEvent) { + WindowPtr whichWindow; + short int thePart = FindWindow (theEvent->where, &whichWindow); + + switch (thePart) { + case inSysWindow: + SystemClick (theEvent, whichWindow); + break; + case inDrag: + DragWindow (whichWindow, theEvent->where, &dragRect); + break; + case inMenuBar: { + long choice; + AdjustMenus (); + choice = MenuSelect (theEvent->where); + if (choice) DoMenu (choice); + break; + } + case inGoAway: + if ((whichWindow == gGraphicsWin) + && (TrackGoAway (whichWindow, theEvent->where))) + HideGrafWin (); + break; + case inContent: + if ((FrontWindow () == gCommandWin) && (whichWindow == gCommandWin)) + DoContent (theEvent); + else SelectWindow (whichWindow); + break; + case inGrow: + case inZoomIn: + case inZoomOut: { + long newSize; + GrafPtr oldPort; + if (thePart == inGrow) newSize = GrowWindow (whichWindow, theEvent->where, &sizeRect); + if (((thePart == inGrow) && newSize) + || ((thePart != inGrow) && TrackBox (whichWindow, theEvent->where, thePart))) { + GetPort (&oldPort); + SetPort (whichWindow); + EraseRect (&whichWindow->portRect); + if (thePart == inGrow) SizeWindow (whichWindow, LoWord (newSize), HiWord (newSize), -1); + else ZoomWindow (whichWindow, thePart, 0); + gCommandWinResized = true; + InvalRect (&whichWindow->portRect); + SetPort (oldPort); + } + break; + } + } +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.h b/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.h new file mode 100644 index 000000000..73eff486a --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/MacHandleEv.h @@ -0,0 +1,3 @@ +/* MacHandelEv.h -- event handlers */ + +void DoMouseDown(EventRecord *theEvent); diff --git a/lib-src/libnyquist/nyquist/sys/mac/README.txt b/lib-src/libnyquist/nyquist/sys/mac/README.txt new file mode 100644 index 000000000..68885888e --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/README.txt @@ -0,0 +1,69 @@ +README.txt -- information on Nyquist for Mac OS X + +Installation +------------ +The simplest way to install and run Nyquist is to get the pre-compiled +NyquistIDE application, which includes executables, documentation, and +libraries all in one package. + +When the pre-compiled package is uncompressed, it produces two directories: + nyquist + NyquistIDE.app +You should always keep these together. The nyquist directory initially +contains documentation, but when NyquistIDE.app is run, the nyquist +folder is also populated with links to the lib and demos folders, +which contain example code and more documentation. The symbolic links +allow you to easily find these files. + +You can copy both nyquist and NyquistIDE.app to the /Applications folder +if you wish, and you can add NyquistIDE.app to the Dock. + +You will probably run Nyquist using the NyquistIDE application, but +you can also run nyquist from the command line. The executable is +located in + + NyquistIDE.app/Contents/Resources/Java/ny + +To run from the command line, you will need to set the XLISPPATH +environment variable using this command line (if you use the C shell, +e.g. csh): + + setenv XLISPPATH `pwd`/runtime:`pwd`/lib + +If you use the bash shell, use: + + export XLISPPATH=`pwd`/runtime:`pwd`/lib + +Note that this sets XLISPPATH in the environment of the current +command line shell. If you exit the shell or switch to another shell, +the XLISPPATH variable will not be set. Your shell reads an +initialization file when it starts. You can add the XLISPPATH +initialization command to this file if you want the variable to be set +automatically in every instance of your command line shell. + +On the topic of the XLISPPATH, note that this variable is set by +NyquistIDE when running with that application, overriding any other +value. You can extend the search path by creating the file xlisppath +in the same directory as the nyquist executable ny. The xlisppath file +should have colon-separated paths on a single line of text. + +You can also build Nyquist from sources, as described below. + + +How To Build Nyquist on Mac OS X +-------------------------------- +You need to install Xcode, Apple's free software development system +for OS X. + +Xcode 4.3.2 and later +------- +The nyquist project for Xcode v4 is in nyquist/macosxproject/nyquist.xcodeproj + +To build Nyquist or NyquistIDE: + - Open nyquist.wxworkspace in Xcode + - Set the active target to "Nyquist" or "NyquistIDE" + - Click on "build active target" + - ny or NyquistIDE will be produced in a temporary folder managed by Xcode. + To find the files Right click on the Products/NyquistIDE.app of the project + navigator, and select "reveal in finder". + diff --git a/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.c b/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.c new file mode 100644 index 000000000..8acdbf4da --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.c @@ -0,0 +1,123 @@ +/* macaboutbox.c - Display the "about box" of the application. */ +/* Written by Brian Kendig. */ +/* The functions here are only used by macint.c. */ + +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "macint.h" +#define NIL ((void *) 0) + +static DialogPtr aboutBox; +extern Boolean hasColorQD; + +static enum { + theOKButton = 1, + theOKOutline = 2, + theIcon = 3, + theName = 4, + theAboutText = 5, + theCopyright = 6 +} ; + +pascal void DrawOKOutline (WindowPtr dialogWindow, short theItem) { + PenState oldPen; + short iType; + Handle iHandle; + Rect iRect; + + GetPenState (&oldPen); + PenNormal (); + PenSize (3,3); + + GetDialogItem (aboutBox, theOKButton, &iType, &iHandle, &iRect); + InsetRect (&iRect, -4, -4); + FrameRoundRect (&iRect, 16, 16); + + SetPenState (&oldPen); +} + +pascal void DrawIcon (WindowPtr dialogWindow, short theItem) { + short iType; + Handle iHandle; + Rect iRect; + + GetDialogItem (aboutBox, theIcon, &iType, &iHandle, &iRect); + PlotIcon (&iRect, GetResource ('ICN#', 128)); +} + +pascal void DrawName (WindowPtr dialogWindow, short theItem) { + short iType; + Handle iHandle; + Rect iRect; + Str255 string; + + TextFont (kFontIDHelvetica); + TextSize (24); + TextFace (0); + GetDialogItem (aboutBox, theName, &iType, &iHandle, &iRect); + GetIndString (string, STRINGS_RES, 1); + TETextBox (string+1, string[0], &iRect, teFlushLeft); +} + +pascal void DrawAboutText (WindowPtr dialogWindow, short theItem) { + short iType; + Handle iHandle; + Rect iRect; + Str255 string; + + TextFont (kFontIDMonaco); + TextSize (9); + TextFace (0); + GetDialogItem (aboutBox, theAboutText, &iType, &iHandle, &iRect); + GetIndString (string, STRINGS_RES, 2); + TETextBox (string+1, string[0], &iRect, teFlushLeft); +} + +pascal void DrawCopyright (WindowPtr dialogWindow, short theItem) { + short iType; + Handle iHandle; + Rect iRect; + Str255 string; + + TextFont (systemFont); + TextSize (12); + TextFace (0); + GetDialogItem (aboutBox, theCopyright, &iType, &iHandle, &iRect); + GetIndString (string, STRINGS_RES, 3); + TETextBox (string+1, string[0], &iRect, teFlushLeft); +} + +void DoAboutBox (void) { + short itemType, itemHit = 0; + Handle itemHandle; + Rect aboutRect; + short width, hight; + PicHandle aboutPict; + + aboutPict = GetPicture(ABOUT_PICT); + aboutRect = (*aboutPict)->picFrame; + width = aboutRect.right - aboutRect.left; + hight = aboutRect.bottom - aboutRect.top; + + aboutBox = GetNewDialog (ABOUT_BOX, NIL, (WindowPtr) -1); + SizeWindow(aboutBox, width, hight, false); + + ShowWindow (aboutBox); + SetPort(aboutBox); + DrawPicture(aboutPict, &(*aboutPict)->picFrame); + + //itemHit = 0; + //while (itemHit != ok) ModalDialog (NIL, &itemHit); + while (!Button()); + + DisposeDialog (aboutBox); + + FlushEvents(everyEvent, 0); // dmazzoni +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.h b/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.h new file mode 100644 index 000000000..76f699acc --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macaboutbox.h @@ -0,0 +1,3 @@ +/* macaboutbox.h -- header for about box implementation */ + +void DoAboutBox(void); diff --git a/lib-src/libnyquist/nyquist/sys/mac/macdrag.c b/lib-src/libnyquist/nyquist/sys/mac/macdrag.c new file mode 100644 index 000000000..559a278fa --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macdrag.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include + +extern TEHandle hTERec; +// Handle drag from newswatcher -EAD + +/*---------------------------------------------------------------------------- + DragText + + Drag selected text. + + Entry: ev = pointer to mouse down event record. + where = location of mouse down event in local coords. + theTE = handle to TextEdit record. + + Exit: function result = error code. + *dragged = + true if text was dragged. + false if mouse down was not over text selection, or + user did not move the mouse before releasing the + mouse button. + *trashed = true if text was dragged to trash. +----------------------------------------------------------------------------*/ +extern RgnHandle rgn; +//extern EventRecord theEvent; + +Boolean DragText (EventRecord *ev) +{ + DragReference dragRef; + OSErr err = noErr; + Boolean haveDragRef = false; + Handle hText; + RgnHandle dragRgn, tempRgn; + short selStart, selEnd; + char state; + Point theLoc; + GrafPtr curPort; + +// if (!PtInTEHiliteRgn(where, hTERec)) return noErr; + if (!WaitMouseMoved(ev->where)) return noErr; + + GetPort(&curPort); + + CopyRgn(rgn, dragRgn = NewRgn()); + SetPt(&theLoc, 0, 0); + LocalToGlobal(&theLoc); + OffsetRgn(dragRgn, theLoc.h, theLoc.v); + + hText = (**hTERec).hText; + selStart = (**hTERec).selStart; + selEnd = (**hTERec).selEnd; + + err = NewDrag(&dragRef); + if (err != noErr) goto exit; + haveDragRef = true; + state = HGetState(hText); + HLock(hText); + err = AddDragItemFlavor(dragRef, 1, 'TEXT', *hText + selStart, selEnd - selStart, 0); + HSetState(hText, state); + if (err != noErr) goto exit; +// dragRgn = NewRgn(); +// err = TEGetHiliteRgn(dragRgn, hTERec); +// if (err != noErr) goto exit; +// LocalToGlobalRgn(dragRgn); +// OutlineRegion(dragRgn); + SetDragItemBounds(dragRef, 1, &(**dragRgn).rgnBBox); + tempRgn = NewRgn(); + CopyRgn(dragRgn, tempRgn); + InsetRgn(tempRgn, 1, 1); + DiffRgn(dragRgn, tempRgn, dragRgn); + DisposeRgn(tempRgn); + + err = TrackDrag(dragRef, ev, dragRgn); + if (err != noErr && err != userCanceledErr) goto exit; + //*trashed = DragTargetWasTrash(dragRef); +// DisposeRgn(dragRgn); + + DisposeDrag(dragRef); + return true; + +exit: + + if (haveDragRef) DisposeDrag(dragRef); +// if (dragRgn != nil) DisposeRgn(dragRgn); + return false; +} + + + +/*---------------------------------------------------------------------------- + LocalToGlobalRgn + + Convert a region from local to global coordinates. + + Entry: rgn = handle to region. +----------------------------------------------------------------------------*/ + +void LocalToGlobalRgn (RgnHandle rgn) +{ + Point where; + + SetPt(&where, 0, 0); + LocalToGlobal(&where); + OffsetRgn(rgn, where.h, where.v); +} + +/*---------------------------------------------------------------------------- + OutlineRegion + + Change a region into a tracing of its border which is appropriate + for normal dragging. + + Entry: theRgn = handle to region. + + Exit: Region changed to outline of region. + + From Apple "HFS Drag Sample" sample code. +----------------------------------------------------------------------------*/ + +void OutlineRegion (RgnHandle theRgn) +{ + RgnHandle tempRgn; + + tempRgn = NewRgn(); + CopyRgn(theRgn, tempRgn); + InsetRgn(tempRgn, 1, 1); + DiffRgn(theRgn, tempRgn, theRgn); + DisposeRgn(tempRgn); +} + +/*---------------------------------------------------------------------------- + PtInTEHiliteRgn + + Determine whether or not a point is in the current TextEdit hilite + region. + + Entry: where = point in local coords. + theTE = handle to TextEdit record. + + Exit: function result = true if point is in the hilite region. +----------------------------------------------------------------------------*/ + +Boolean PtInTEHiliteRgn (Point where, TEHandle theTE) +{ + Boolean result = false; + RgnHandle rgn = nil; + OSErr err = noErr; + + //if (!HaveTEGetHiliteRgn()) return false; + rgn = NewRgn(); + err = TEGetHiliteRgn(rgn, theTE); + if (err != noErr) goto exit; + result = PtInRgn(where, rgn); + +exit: + + if (rgn != nil) DisposeRgn(rgn); + return result; +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/macfun.c b/lib-src/libnyquist/nyquist/sys/mac/macfun.c new file mode 100644 index 000000000..e92461dca --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macfun.c @@ -0,0 +1,222 @@ +/* macfun.c - macintosh user interface functions for xlisp */ +/* Written by Brian Kendig. */ + +#include +#include +#include +#include "xlisp.h" +#include "macint.h" + +/* externals */ +extern WindowPtr gCommandWin, gGraphicsWin; +extern Boolean hasColorQD; +extern unsigned long startupTicks; +extern void ShowGrafWin (void); + +unsigned long ticks_per_second (void) { return 60; } +unsigned long run_tick_count (void) { return ((unsigned long) TickCount ()) - startupTicks; } +unsigned long real_tick_count (void) { return (unsigned long) TickCount (); } + +LVAL xrealtime (void) { return cvfixnum ((FIXTYPE)real_tick_count()); } /* get-internal-real-time */ +LVAL xruntime (void) { return cvfixnum ((FIXTYPE)run_tick_count()); } /* get-internal-run-time */ +LVAL xtime (void) { return cvfixnum ((FIXTYPE)real_tick_count()); } /* time */ + +/* get an integer parameter */ +LOCAL int getNumber () { + LVAL num = xlgafixnum (); + return ((int) getfixnum (num)); +} + +/* handle commands that require integer arguments */ +LOCAL LVAL GrafCmd (char funct, int nArgs) { + short x, y, z; + if (nArgs > 0) x = getNumber (); + if (nArgs > 1) y = getNumber (); + if (nArgs > 2) z = getNumber (); + xllastarg (); + SetPort (gGraphicsWin); + switch (funct) { + case 'G': ShowGrafWin (); break; + case 'g': HideGrafWin (); break; + case 'x': EraseRect (&gGraphicsWin->portRect); break; + case 's': ShowPen (); break; + case 'h': HidePen (); break; + case 'd': PenMode (x); break; + case 'M': Move (x, y); break; + case 'm': MoveTo (x, y); break; + case 'L': Line (x, y); break; + case 'l': LineTo (x, y); break; + case 'S': PenSize (x, y); break; + case 'p': PenNormal (); break; + case 'c': + if (hasColorQD) { + RGBColor col; col.red = x; col.green = y; col.blue = z; + RGBForeColor (&col); + } break; + } + SetPort (gCommandWin); + return NIL; +} + +LVAL xshowgraphics (void) { return GrafCmd ('G', 0); } /* show graphics win */ +LVAL xhidegraphics (void) { return GrafCmd ('g', 0); } /* hide graphics win */ +LVAL xcleargraphics (void) { return GrafCmd ('x', 0); } /* clear graphics win */ +LVAL xshowpen (void) { return GrafCmd ('s', 0); } /* show the pen */ +LVAL xhidepen (void) { return GrafCmd ('h', 0); } /* hide the pen */ +LVAL xpenmode (void) { return GrafCmd ('d', 1); } /* set the pen mode */ +LVAL xmove (void) { return GrafCmd ('M', 2); } /* move pen in a specified direction */ +LVAL xmoveto (void) { return GrafCmd ('m', 2); } /* move pen to a screen location */ +LVAL xdraw (void) { return GrafCmd ('L', 2); } /* draw a line in a specified direction */ +LVAL xdrawto (void) { return GrafCmd ('l', 2); } /* draw a line to a screen location */ +LVAL xpensize (void) { return GrafCmd ('S', 2); } /* set the pen size */ +LVAL xpennormal (void) { return GrafCmd ('p', 0); } /* set the pen to normal */ +LVAL xcolor (void) { return GrafCmd ('c', 3); } /* set RGB color of pen */ + + +LVAL xgetpen (void) { /* get the pen position */ + LVAL val; + Point p; + xllastarg (); + SetPort ((GrafPtr)gGraphicsWin); + GetPen (&p); + SetPort (gCommandWin); + xlsave1 (val); + val = consa (NIL); + rplaca (val,cvfixnum ((FIXTYPE)p.h)); + rplacd (val,cvfixnum ((FIXTYPE)p.v)); + xlpop (); + return val; +} + +LVAL xpenpat (void) { /* set the pen pattern */ + LVAL plist; + Pattern pat; + int i; + plist = xlgalist (); + xllastarg (); + for (i = 0; i < 8 && consp (plist); ++i, plist = cdr (plist)) +// if (fixp (car (plist))) pat[i] = getfixnum (car (plist)); + SetPort ((GrafPtr)gGraphicsWin); + PenPat (&pat); + SetPort (gCommandWin); + return NIL; +} + + +/* The functions below are not yet implemented. */ + +LVAL xtool (void) { /* call the toolbox */ + int trap = getNumber (); + LVAL val; + +/* asm { + move.l args(A6),D0 + beq L2 + L1: move.l D0,A0 + move.l 2(A0),A1 + move.w 4(A1),-(A7) + move.l 6(A0),D0 + bne L1 + L2: lea L3,A0 + move.w trap(A6),(A0) + L3: dc.w 0xA000 + clr.l val(A6) + } + + return val; */ + return cvfixnum ((FIXTYPE) trap); +} + +LVAL xtool16 (void) { /* call the toolbox with a 16 bit result */ + int trap = getNumber (); + int val; + +/* asm { + clr.w -(A7) + move.l args(A6), D0 + beq L2 + L1: move.l D0, A0 + move.l 2(A0), A1 + move.w 4(A1), -(A7) + move.l 6(A0), D0 + bne L1 + L2: lea L3, A0 + move.w trap(A6), (A0) + L3: dc.w 0xA000 + move.w (A7)+, val(A6) + } + + return cvfixnum ((FIXTYPE) val); */ + return cvfixnum ((FIXTYPE) trap); +} + +LVAL xtool32 (void) { /* call the toolbox with a 32 bit result */ + int trap = getNumber (); + long val; + +/* asm { + clr.l -(A7) + move.l args(A6),D0 + beq L2 + L1: move.l D0,A0 + move.l 2(A0),A1 + move.w 4(A1),-(A7) + move.l 6(A0),D0 + bne L1 + L2: lea L3,A0 + move.w trap(A6),(A0) + L3: dc.w 0xA000 + move.l (A7)+,val(A6) + } + + return cvfixnum ((FIXTYPE) val); */ + return cvfixnum ((FIXTYPE) trap); +} + +LVAL xnewhandle (void) { /* allocate a new handle */ + LVAL num = xlgafixnum (); + long size = getfixnum (num); + xllastarg (); + return cvfixnum ((FIXTYPE) NewHandle (size)); +} + +LVAL xnewptr (void) { /* allocate memory */ + LVAL num = xlgafixnum (); + long size = getfixnum (num); + xllastarg (); + return cvfixnum ((FIXTYPE) NewPtr (size)); +} + +LVAL xhiword (void) { /* return the high order 16 bits of an integer */ + unsigned int val = (unsigned int) (getNumber () >> 16); + xllastarg (); + return cvfixnum ((FIXTYPE) val); +} + +LVAL xloword (void) { /* return the low order 16 bits of an integer */ + unsigned int val = (unsigned int) getNumber (); + xllastarg (); + return cvfixnum ((FIXTYPE) val); +} + +LVAL xrdnohang (void) { /* get the next character in the look-ahead buffer */ + int ch = 0; + xllastarg (); +/* if ((ch = scrnextc ()) == EOF) return NIL; */ + return cvfixnum ((FIXTYPE) ch); +} + +void ossymbols (void) { /* ossymbols - enter important symbols */ + LVAL sym; + + /* setup globals for the window handles */ + sym = xlenter ("*COMMAND-WINDOW*"); + setvalue (sym, cvfixnum ((FIXTYPE) gCommandWin)); + sym = xlenter ("*GRAPHICS-WINDOW*"); + setvalue (sym, cvfixnum ((FIXTYPE) gGraphicsWin)); +} + +void xoserror (char *msg) { /* do nothing */ } + +LVAL xsystem (V) { return NIL; } +LVAL xgetkey (V) { return NIL; } diff --git a/lib-src/libnyquist/nyquist/sys/mac/macint.c b/lib-src/libnyquist/nyquist/sys/mac/macint.c new file mode 100644 index 000000000..bd76af830 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macint.c @@ -0,0 +1,521 @@ +/* macint.c - macintosh interface routines for xlisp 2.1e */ +/* Written by Brian Kendig. */ +/* The functions here are only called by macstuff.c. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include +#include "macint.h" +/* #define FALSE 0 +#define TRUE 1 */ +#define NIL ((void *) 0) + + +#include "MacCommandWin.h" +#include "macaboutbox.h" +#include "MacDrag.h" +#include "MacHandleEv.h" +#include "macstuff.h" +#include "stdio.h" +#define TEXTREC (*hTERec) /* the command window text record */ +#define TEXTCHAR(i) ((*(TEXTREC->hText))[i]) + +// Struct for apple event handling +typedef struct AEventList { + AEEventClass evclass; + AEEventID evid; + void *handler; + long refcon; +} AEventList, *AEventListPtr; + +//=========================================================================== +// GLOBALS DEFINED HERE USE MacGlobals.h FOR ACCESS +//=========================================================================== + +// Menu handles +MenuHandle appleMenu, fileMenu, editMenu, controlMenu; + +/* command and graphics windows */ +WindowPtr gCommandWin, gGraphicsWin; +WindowRecord commandWinRec, bwGraphicsWinRec; +CWindowRecord colorGraphicsWinRec; +Boolean gGraphicsShown, gCommandWinResized = false; + +// Screen size stuff +Rect dragRect, sizeRect; +int screenWidth, screenHeight; /* screen dimensions */ +int sHorizontal, sVertical, sWidth, sHeight; /* command win, split screen */ +int gHorizontal, gVertical, gWidth, gHeight; /* graphics win, split screen */ + +// The Text handle +TEHandle hTERec; + +/* output is buffered */ +//Handle hOutputBuffer = NULL; +int outputBufferLength = 0; + +// Allocate space for UPPs +ControlActionUPP uppScrollProc; +TEClickLoopUPP uppScrollClickLoop; +//AEEventHandlerUPP uppAEOpenFiles, uppAEQuit; + +// Text related globals +CharsHandle pastedTextH = NULL; /* a handle to pasted text */ +int pastedLength = 0; /* how many chars there are in the paste buffer */ +int flashTime = 0, cursorBeforeFlash; /* for flashing cursor when parens match */ +char recentChar; /* the last character typed */ +RgnHandle gMouseRgn; // holds current mouse regin + +/* miscellaneous stuff */ +Boolean gInBackground; /* are we in background or not */ +int wneImplemented; +unsigned long startupTicks; +Boolean hasColorQD; + +short howManyFiles = 0, whichFile = 0; /* keep track of files opened from Finder */ + + +// Prototypes +static pascal OSErr AEQuit (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon); +static pascal OSErr AEOpenFiles (AppleEvent *theAppleEvent, AppleEvent *theReply, long Refcon); +pascal Boolean ScrollClickLoop (void); +pascal void ScrollProc (ControlHandle control, short thePart); +Rect SetTERect (void); +void FlushOutput (void); + +void ShowGrafWin (void) { + /* make the graphics window visible */ + ShowWindow (gGraphicsWin); + SelectWindow (gGraphicsWin); + SetMenuItemText (controlMenu, SHOW_GRAPHICS, "\pHide Graphics"); + //AdjustCursor (); + gGraphicsShown = true; +} + +void HideGrafWin (void) { + /* hide the graphics window */ + HideWindow (gGraphicsWin); + SetMenuItemText (controlMenu, SHOW_GRAPHICS, "\pShow Graphics"); + gGraphicsShown = false; +} + + +static void UpdateGraphWindow () +{ + BeginUpdate (gGraphicsWin); + EndUpdate (gGraphicsWin); +} +void InitMac (void) { +// { /* set up memory properly */ +// int i; + // fix this later. -EAD + //if (DefltStack < STACKMIN) SetApplLimit (CurStackBase - STACKMIN); +// MaxApplZone (); +// for (i = 0; i < MASTERS; i++) MoreMasters (); +// } + AEventListPtr theAppleEvent; + AEventList theEventList[] = { + { kCoreEventClass, kAEOpenDocuments, AEOpenFiles, 0 }, + { kCoreEventClass, kAEQuitApplication, AEQuit, 0 }, + { 0, 0, nil, 0 } + }; + int i; + + /* do all the necessary initialization mumbo-jumbo */ + if (StackSpace() < STACKMIN) + SetApplLimit(GetApplLimit() - STACKMIN); + MaxApplZone(); + /* printf("New StackSpace %lx GetApplLimit %lx\n", + StackSpace(), GetApplLimit()); */ + for (i = 0; i < MASTERS; i++) MoreMasters (); + /* getchar(); */ + + /* initialize the toolbox */ + InitGraf (&qd.thePort); + InitFonts (); + FlushEvents (everyEvent, 0); + InitWindows (); + InitMenus (); + TEInit (); + InitDialogs (NIL); + InitCursor (); + + // Setup Callbacks + uppScrollClickLoop = NewTEClickLoopProc(ScrollClickLoop); + uppScrollProc = NewControlActionProc(ScrollProc); + + // Handlers for core apple events + for (theAppleEvent = theEventList; theAppleEvent->handler; theAppleEvent++) + if (AEInstallEventHandler(theAppleEvent->evclass, theAppleEvent->evid, NewAEEventHandlerProc((ProcPtr)theAppleEvent->handler), + theAppleEvent->refcon, 0) != noErr); + + // Set up the SIOUX window + SIOUXSettings.initializeTB = FALSE; //Toolbox is alread inited + SIOUXSettings.setupmenus = FALSE; //keep the csound menus + SIOUXSettings.autocloseonquit = TRUE; //close sioux without asking for save + SIOUXSettings.showstatusline = FALSE; //no status line + SIOUXSettings.asktosaveonclose = FALSE; //don't ask to save + SIOUXSettings.toppixel = 40; + SIOUXSettings.leftpixel = 5; + + /* see if we have WaitNextEvent and Color Quickdraw */ + wneImplemented = (NGetTrapAddress (_WaitNextEvent, ToolTrap) != NGetTrapAddress (_Unimplemented, ToolTrap)); + if (NGetTrapAddress ((short) Gestalt, ToolTrap) != NGetTrapAddress (_Unimplemented, ToolTrap)) { + long returnCode; + OSErr err = Gestalt (gestaltQuickdrawVersion, &returnCode); + hasColorQD = ((err == noErr) && (returnCode >= gestalt8BitQD)); + } else hasColorQD = false; + + { /* set up menus */ + Handle theMenuBar = GetNewMBar (MBAR_RES); + SetMenuBar (theMenuBar); + appleMenu = (MenuHandle)GetMenuHandle (APPLE_MENU_RES); + fileMenu = (MenuHandle)GetMenuHandle (FILE_MENU_RES); + editMenu = (MenuHandle)GetMenuHandle (EDIT_MENU_RES); + controlMenu = (MenuHandle)GetMenuHandle (CONTROL_MENU_RES); + AppendResMenu (appleMenu, 'DRVR'); + DrawMenuBar (); + } + + /* get the size of the main screen */ + screenWidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left; + screenHeight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top; + + /* compute the size of the graphics window in split-screen mode */ + gHorizontal = SCREEN_MARGIN; + gVertical = MBAR_HEIGHT + TITLEBAR_HEIGHT - 1; + gWidth = screenWidth - (SCREEN_MARGIN * 2); + gHeight = GRAFWIN_HEIGHT; + + /* compute the size of the command window in split-screen mode */ + sHorizontal = SCREEN_MARGIN; + sVertical = MBAR_HEIGHT + TITLEBAR_HEIGHT - 1 + SCREEN_MARGIN + GRAFWIN_HEIGHT; + sWidth = screenWidth - (SCREEN_MARGIN * 2); + sHeight = screenHeight - MBAR_HEIGHT - TITLEBAR_HEIGHT - (SCREEN_MARGIN * 2) - GRAFWIN_HEIGHT - 1; + + /* set up size and drag rects */ + dragRect = (*GetGrayRgn ())->rgnBBox; +// dragRect.left += DRAG_THRESHOLD; +// dragRect.right -= DRAG_THRESHOLD; +// dragRect.bottom -= DRAG_THRESHOLD; + sizeRect.top = MIN_WIN_HEIGHT; + sizeRect.left = MIN_WIN_WIDTH; + sizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top; + sizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left; + + /* create the command window */ + gCommandWin = GetNewWindow (CWINRES, &commandWinRec, (WindowPtr) -1L); + SetPort (gCommandWin); + + /* create the graphics window */ + if (hasColorQD) gGraphicsWin = GetNewCWindow (GWINRES, &colorGraphicsWinRec, (WindowPtr) -1L); + else gGraphicsWin = GetNewWindow (GWINRES, &bwGraphicsWinRec, (WindowPtr) -1L); + + startupTicks = TickCount (); /* take note of what time we're starting up */ + + // Create mouse regin + gMouseRgn = NewRgn(); + + // Initalize some command window stuff + InitalizeCmdWindow(); + + // Turn on text outlineing + TEFeatureFlag(teFOutlineHilite, teBitSet, hTERec); + + HideGrafWin (); + + { /* see if the user launched the app by opening text files from the Finder */ + short doWhat;\ +// call to CountAppFiles was commented out, but that left doWhat uninitialized +// RBD added this ifdef, I wonder where CountAppFiles came from? +#ifdef CountAppFilesDefined + CountAppFiles (&doWhat, &howManyFiles); + if (doWhat != appOpen) howManyFiles = 0; +#else + howManyFiles = 0; +#endif + } + + UpdateCmdWindow (); + +} + + + +static void DoAppleMenu (int theItem) { + switch (theItem) { + case ABOUT_ITEM: + DoAboutBox (); + break; + default: { + Str255 name; + GetMenuItemText (appleMenu, theItem, name); + OpenDeskAcc (name); + break; + } + } +} +/* this should really be in a header for MacFileUtils.c */ +void GetFullPath(FSSpec *theSpec, StringPtr theName); + + +static void DoFileMenu (int theItem) { + extern xlload (char *, int, int); + extern xlabort(char *); + extern xlisp_wrapup (void); + StandardFileReply theFile; + + SFTypeList fileTypes; + Point pt = { 100, 100 }; + + fileTypes[0] = 'TEXT'; + switch (theItem) { + case LOAD: + case LOAD_NOISILY: + StopPasting (); + StandardGetFile(NIL, 1, fileTypes, &theFile); + if (theFile.sfGood) { + Str255 theFullPath; + short wdRefNum; + + OSErr err; + HiliteMenu (0); + + err = OpenWD(theFile.sfFile.vRefNum, theFile.sfFile.parID, 'Nyqu', &wdRefNum); + err = SetVol(NIL, wdRefNum); + SetSelection (TEXTREC->teLength, TEXTREC->teLength); /* send cursor to end */ + + GetFullPath(&theFile.sfFile, theFullPath); + P2CStr(theFullPath); + + if ((xlload((char *) theFullPath, 1, (theItem == LOAD_NOISILY))) == 0) { + xlabort("load error"); + } + macputs ("> "); + PrepareForInput (); + } + break; + case QUIT: + xlisp_wrapup (); + } +} + +static void DoEditMenu (int theItem) { + if (SystemEdit (theItem-1) == false) + switch (theItem) { + case CUT: case COPY: + if (ZeroScrap () == noErr) { + TECopy (hTERec); /* after copying, export the TE scrap */ + if (TEToScrap () != noErr) ZeroScrap (); + } + if (theItem == CUT) DeleteRange (); + break; + case PASTE: { + long scrapOffset; + if (pastedTextH) DisposeHandle (pastedTextH); + pastedTextH = (CharsHandle) NewHandle (0); + pastedLength = GetScrap (pastedTextH, 'TEXT', &scrapOffset); + if (pastedLength < 0) pastedLength = 0; /* error */ + else { + SetHandleSize (pastedTextH, pastedLength + 1); + HLock (pastedTextH); + ((char *)(*pastedTextH))[pastedLength] = '\0'; + HUnlock (pastedTextH); + } + } /* and fall through ... */ + case CLEAR: + DeleteRange (); + break; + } +} + +static void DoControlMenu (int theItem) { + extern xlbreak (char *, char *); + extern char *s_unbound; + extern xlcontinue (void); + extern xlcleanup (void); + extern xlabort (char *); + extern xltoplevel (void); + + scrflush (); + HiliteMenu (0); + switch (theItem) { + case BREAK: StopPasting (); xlbreak ("user break", s_unbound); PrepareForInput (); break; + case CONTINUE: StopPasting (); xlcontinue (); PrepareForInput (); break; + case CLEAN_UP: StopPasting (); xlcleanup (); PrepareForInput (); break; + case CANCEL_INPUT: StopPasting (); xlabort ("input canceled"); PrepareForInput (); break; + case TOP_LEVEL: StopPasting (); xltoplevel (); PrepareForInput (); break; + case SHOW_GRAPHICS: + if (gGraphicsShown) HideGrafWin (); + else ShowGrafWin (); + break; + case SPLIT_SCREEN: + MoveWindow (gCommandWin, sHorizontal, sVertical, -1); + SizeWindow (gCommandWin, sWidth, sHeight, -1); + InvalRect (&gCommandWin->portRect); + SetTERect (); + SetScrollRect (); + ShowGrafWin (); + MoveWindow (gGraphicsWin, gHorizontal, gVertical, -1); + SizeWindow (gGraphicsWin, gWidth, gHeight, -1); + break; + } +} + +void DoMenu (long choice) { + int theMenu = HiWord (choice), theItem = LoWord (choice); + + HiliteMenu (theMenu); + switch (theMenu) { + case APPLE_MENU_RES: DoAppleMenu (theItem); break; + case FILE_MENU_RES: DoFileMenu (theItem); break; + case EDIT_MENU_RES: DoEditMenu (theItem); break; + case CONTROL_MENU_RES: DoControlMenu (theItem); break; + } + HiliteMenu (0); +} + +void AdjustMenus (void) { + /* turn the stuff in the Edit menu on and off as necessary */ + long temp; + DisableItem (editMenu, UNDO); + if (TEXTREC->selStart != TEXTREC->selEnd) { + EnableItem (editMenu, CUT); + EnableItem (editMenu, COPY); + EnableItem (editMenu, CLEAR); + } else { + DisableItem (editMenu, CUT); + DisableItem (editMenu, COPY); + DisableItem (editMenu, CLEAR); + } + if (GetScrap (NIL, 'TEXT', &temp) > 0) EnableItem (editMenu, PASTE); + else DisableItem (editMenu, PASTE); +} + +RgnHandle rgn = nil; + +void DoContent (EventRecord *theEvent) { + /* handle a click in a window's content region */ + ControlHandle theScrollBar; + GrafPtr oldPort; + int scrollValue; + Point mouse = theEvent->where; + int thePart; +// RgnHandle rgn = nil; + + GetPort (&oldPort); + SetPort (gCommandWin); + GlobalToLocal (&mouse); + + // Get Selected text + rgn = NewRgn(); + TEGetHiliteRgn(rgn, hTERec); + + if (thePart = FindControl (mouse, gCommandWin, &theScrollBar)) { + switch (thePart) { + case kControlUpButtonPart: + case kControlDownButtonPart: + case kControlPageUpPart: + case kControlPageDownPart: + scrollValue = TrackControl (theScrollBar, mouse, uppScrollProc); + break; + case kControlIndicatorPart: + scrollValue = GetControlValue (theScrollBar); + thePart = TrackControl (theScrollBar, mouse, NIL); + if (thePart) { + scrollValue -= GetControlValue (theScrollBar); + if (scrollValue) TEScroll (0, scrollValue * LINEHEIGHT, hTERec); + } + break; + } + } else if (PtInRgn(mouse, rgn)) { + if (!DragText(theEvent)) { + TEClick(mouse, false, hTERec); + } + } else if (PtInRect (mouse, &(TEXTREC->viewRect))) { + TEClick (mouse, (theEvent->modifiers & shiftKey) != 0, hTERec); + } + SetPort (oldPort); + DisposeRgn(rgn); +} + + +void DoEvent (void) { + EventRecord theEvent; + + if ((flashTime) && (--flashTime == 0)) SetSelection (cursorBeforeFlash, cursorBeforeFlash); + if (outputBufferLength) FlushOutput (); + if (FrontWindow () == gCommandWin) TEIdle (hTERec); + recentChar = '\0'; + + if (WaitNextEvent (everyEvent, &theEvent, 0, gMouseRgn)) { + + AdjustCursor (theEvent.where, gMouseRgn); + + switch (theEvent.what) { + case kHighLevelEvent: + AEProcessAppleEvent(&theEvent); + break; + case mouseDown: + DoMouseDown (&theEvent); + break; + case keyDown: + case autoKey: + DoKeyPress (&theEvent); + break; + case activateEvt: { + WindowPtr whichWindow = (WindowPtr)theEvent.message; + SetPort (whichWindow); + if (whichWindow == gCommandWin) { + if ((theEvent.modifiers & activeFlag) == 1) { + ActivateCmdWindow(); + } else { + DeactivateCmdWindow(); + } + } + break; + } + case updateEvt: { + if ((WindowPtr)theEvent.message == gCommandWin) UpdateCmdWindow (); + if ((WindowPtr)theEvent.message == gGraphicsWin) UpdateGraphWindow (); + break; + } + case osEvt: + if (((theEvent.message >> 24) & 0xff) == suspendResumeMessage) { + if (theEvent.message & resumeFlag) { + gInBackground = false; + if (FrontWindow () == gCommandWin) { + ActivateCmdWindow(); + } + } else { + gInBackground = true; + if (FrontWindow () == gCommandWin) { + SetPort (gCommandWin); + DeactivateCmdWindow(); + } + } + } + break; + + } + } + AdjustCursor (theEvent.where, gMouseRgn); +} + +void MacWrapUp (void) { + /* take everything down in preparation for quitting */ + CleanupCmdWindow(); + CloseWindow (gGraphicsWin); +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/macint.h b/lib-src/libnyquist/nyquist/sys/mac/macint.h new file mode 100644 index 000000000..6092e6788 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macint.h @@ -0,0 +1,166 @@ +#define INT_MAX +32767 + +#define INT_MIN -32767 + +/* resource id's */ + +#define CWINRES 400 + +#define GWINRES 401 + +#define MBAR_RES 400 + +#define APPLE_MENU_RES 400 + +#define FILE_MENU_RES 401 + +#define EDIT_MENU_RES 402 + +#define CONTROL_MENU_RES 403 + +#define STRINGS_RES 400 + + + +/* Apple menu */ + +#define ABOUT_ITEM 1 + +#define ABOUT_BOX 400 + +#define ABOUT_PICT 400 + + + +/* File menu */ + +#define LOAD 1 + +#define LOAD_NOISILY 2 + +#define QUIT 4 + + + +/* Edit menu */ + +#define UNDO 1 + +#define CUT 3 + +#define COPY 4 + +#define PASTE 5 + +#define CLEAR 6 + + + +/* Control menu */ + +#define BREAK 1 + +#define CONTINUE 2 + +#define CLEAN_UP 3 + +#define CANCEL_INPUT 4 + +#define TOP_LEVEL 5 + +#define SHOW_GRAPHICS 7 + +#define SPLIT_SCREEN 8 + + + +/* window sizing/dragging stuff */ + +#define DRAG_THRESHOLD 8 + +#define MIN_WIN_HEIGHT 80 + +#define MIN_WIN_WIDTH 120 + + + +#define MAX_BUF 250 /* max chars in output buffer */ + +#define SCROLLBACK_THRESHHOLD 30000 /* max chars kept in window */ + +#define DELETE_BLOCK 10000 /* how many chars to delete when threshhold reached */ + + + +#define LINEHEIGHT 11 /* height in pixels of 9-point Geneva, the font used */ + +#define STACKMIN 400000 /* amout of memory for application stack */ + +#define MASTERS 3 /* arbitrary -- how many times to call MoreMasters() */ + + + +/* key codes */ + +#define RETURN 0x0d + +#define ENTER 0x03 + +#define DELETE 0x08 + +#define FWDDEL 0x7F + +#define CLRKEY 0x1b + +#define PAGEUP 0x0b + +#define PAGEDN 0x0c + +#define HOMEKEY 0x01 + +#define ENDKEY 0x04 + +#define HELPKEY 0x05 + +#define FNKEY 0x10 + +#define LEFTARROW 0x1c + +#define RIGHTARROW 0x1d + +#define UPARROW 0x1e + +#define DOWNARROW 0x1f + +#define DBLQUOTE '\"' + + + +/* useful definitions */ + +#define MBAR_HEIGHT 20 + +#define TITLEBAR_HEIGHT 20 + +#define SCROLLER_WIDTH 15 + +#define SCREEN_MARGIN 2 + +#define TEXT_MARGIN 4 + +#define GRAFWIN_HEIGHT 232 + +void AdjustMenus(void); + +void DoMenu(long choice); + +void HideGrafWin(void); + +void DoContent(EventRecord *theEvent); + +void InitMac(void); + +void MacWrapUp(void); + + +void DoEvent (void); diff --git a/lib-src/libnyquist/nyquist/sys/mac/macptrs.h b/lib-src/libnyquist/nyquist/sys/mac/macptrs.h new file mode 100644 index 000000000..4dad03aa8 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macptrs.h @@ -0,0 +1,52 @@ +{ "HIDEPEN", S, xhidepen }, /* 300 */ + +{ "SHOWPEN", S, xshowpen }, /* 301 */ + +{ "GETPEN", S, xgetpen }, /* 302 */ + +{ "PENSIZE", S, xpensize }, /* 303 */ + +{ "PENMODE", S, xpenmode }, /* 304 */ + +{ "PENPAT", S, xpenpat }, /* 305 */ + +{ "PENNORMAL", S, xpennormal }, /* 306 */ + +{ "MOVETO", S, xmoveto }, /* 307 */ + +{ "MOVE", S, xmove }, /* 308 */ + +{ "LINETO", S, xdrawto }, /* 309 */ + +{ "LINE", S, xdraw }, /* 310 */ + +{ "SHOW-GRAPHICS", S, xshowgraphics }, /* 311 */ + +{ "HIDE-GRAPHICS", S, xhidegraphics }, /* 312 */ + +{ "CLEAR-GRAPHICS", S, xcleargraphics }, /* 313 */ + +{ "TOOLBOX", S, xtool }, /* 314 */ + +{ "TOOLBOX-16", S, xtool16 }, /* 315 */ + +{ "TOOLBOX-32", S, xtool32 }, /* 316 */ + +{ "NEWHANDLE", S, xnewhandle }, /* 317 */ + +{ "NEWPTR", S, xnewptr }, /* 318 */ + +{ "HIWORD", S, xhiword }, /* 319 */ + +{ "LOWORD", S, xloword }, /* 320 */ + +{ "READ-CHAR-NO-HANG", S, xrdnohang }, /* 321 */ + + + +/* not implemented - take a look at code in directory "sys:mac:old" */ + +/*{ "COMMAND-POINT-SIZE", S, xptsize }, 322 */ + + + diff --git a/lib-src/libnyquist/nyquist/sys/mac/macstuff.c b/lib-src/libnyquist/nyquist/sys/mac/macstuff.c new file mode 100644 index 000000000..c16c2749e --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macstuff.c @@ -0,0 +1,229 @@ +/* macstuff.c - macintosh interface routines for xlisp */ +/* Written by Brian Kendig. */ +/* This file contains the stuff that the other xlisp files call directly. */ + +#include "cext.h" +#include +#include +#include /* for Random */ +#include /* for DisposePtr */ +#include /* for ExitToShell */ +#include "xlisp.h" +#include +#include "macint.h" +#include "MacCommandWin.h" +#define DELETE 0x08 + +/* externals */ +extern FILE *tfp; /* transcript file pointer */ +extern int cursorPos; +extern char *macgets (void); + +/* local variables */ +int lposition; +static char *linebuf = NULL, *lineptr; +static int numChars; + +/* system-dependent variable definitions */ +static const char os_pathchar = ':'; +static const char os_sepchar = ','; + + +int isascii (char c) { return 1; } /* every char is an ascii char, isn't it? */ + +void osinit (char *banner) { +#ifdef SAFE_NYQUIST +SAFE_NYQUIST is not supported in macstuff.c +#endif + int i; + char version[] = "\nMacintosh interface by Brian Kendig, Erik A. Dahl, and Dominic Mazzoni.\n"; + InitMac (); /* initialize the mac interface routines */ + lposition = 0; /* initialize the line editor */ + for (i = 0; banner[i] != '\0'; i++) macputc (banner[i]); + for (i = 0; version[i] != '\0'; i++) macputc (version[i]); +} + +FILE *osaopen (char *name, char *mode) { + return fopen (name, mode); +} + +FILE *osbopen (char *name, char *mode) { + FILE *f; + char nmode[4]; + strcpy (nmode, mode); strcat (nmode, "b"); + f = fopen(name, nmode); + return f; +} + +int osclose (FILE *fp) { return (fclose (fp)); } +int osaputc (int ch, FILE *fp) { return (putc (ch, fp)); } +int osbputc (int ch, FILE *fp) { return (putc (ch, fp)); } + +/* osagetc - get a character from an ascii file */ +int osagetc(fp) + FILE *fp; +{ + return (getc(fp)); +} + +int ostgetc (void) { + int i; + + if (numChars <= 0) { /* get some more */ + if (linebuf) DisposePtr (linebuf); + linebuf = macgets (); + i = 0; + while (linebuf[i] != '\0') i++; + numChars = i; + if (tfp) for (i = 0; i < numChars; i++) osaputc (linebuf[i], tfp); + lineptr = linebuf; + } + numChars--; + if (*lineptr == '\r') { + lineptr++; + return '\n'; + } else return (*lineptr++); +} + +void ostputc (int ch) { + macputc (ch); + if (tfp) osaputc (ch, tfp); +} + +void osflush (void) { + lineptr = linebuf; + numChars = 0; + lposition = 0; +} + +void oscheck (void) { DoEvent (); } + +void oserror (char *msg) { + char line[100], *p; + sprintf (line,"error: %s\n",msg); + for (p = line; *p != '\0'; ++p) ostputc (*p); +} + +void osfinish(void) { + /* dispose of everything... */ + if (linebuf) DisposePtr(linebuf); + portaudio_exit(); + MacWrapUp (); + ExitToShell (); +} + +#define GPRINTF_MESSAGE_LEN 500 + +/* nyquist_printf -- system independent version of printf */ +/* + * this function prints to console like printf, but using GUI + * rather than stdio when appropriate. + * + */ +void nyquist_printf(char *format, ...) +{ + char temp[GPRINTF_MESSAGE_LEN]; + va_list pvar; + char *p = temp; + va_start(pvar, format); + vsnprintf(temp, GPRINTF_MESSAGE_LEN, format, pvar); + va_end(pvar); + while (*p) ostputc(*p++); +} + +int renamebackup (char *filename) { return 0; } + +static FSSpec prefsFSSpec; +static int need_preferences_file = false; +static char xlisp_path[1024]; /* cache for the path */ +static int valid_xlisp_path = false; + +/* xsetupconsole -- used to configure window in Win32 version */ +LVAL xsetupconsole() { return NIL; } + + +/* this should really be in a header for MacFileUtils.c */ +void GetFullPath(FSSpec *theSpec, StringPtr theName); + + +void get_xlisp_path(char *p, long p_max, int *prefs_found) +{ + Str63 fileName = "\pXLisp Preferences"; + SInt16 foundPrefVRefNum = 0; + SInt32 foundPrefDirID = 0; + OSErr err = noErr; + *p = 0; /* initialize to empty string */ + *prefs_found = false; + /* if we find path in the cache, copy and return */ + if (valid_xlisp_path) { + *prefs_found = true; + strcpy(p, xlisp_path + 10); /* remember, path has XLISPPATH= at head */ + return; + } + /* if we've been here before, do not try opening again */ + if (need_preferences_file) return; + err = FindFolder(kOnSystemDisk, kPreferencesFolderType, + kDontCreateFolder, &foundPrefVRefNum, + &foundPrefDirID); + if (err == noErr) { + err = FSMakeFSSpec(foundPrefVRefNum, foundPrefDirID, + fileName, &prefsFSSpec); + *prefs_found = (err == noErr); + need_preferences_file = !*prefs_found; + } + if (*prefs_found) { + FILE *pf; + GetFullPath(&prefsFSSpec, (StringPtr) xlisp_path); + P2CStr((StringPtr) xlisp_path); + pf = fopen(xlisp_path, "r"); + if (!pf) { + return; /* problem opening the path */ + } + while (fgets(xlisp_path, 1023, pf)) { + if (strncmp(xlisp_path, "XLISPPATH=", 10) == 0) { + valid_xlisp_path = true; + xlisp_path[strlen(xlisp_path) - 1] = 0; /* trim newline */ + strcpy(p, xlisp_path + 10); + break; + } + } + fclose(pf); + } +} + + +/* this is called when we load a file -- if need_preference_file, + * we will build a preference file and insert the path of the file + * we just opened, assuming it will tell us where to find init.lsp + */ +void setup_preferences(char *filename) +{ + if (need_preferences_file) { + unsigned char prefname[256]; + FILE *pf; + char *cp; + int len = 0; + GetFullPath(&prefsFSSpec, prefname); + need_preferences_file = false; + P2CStr(prefname); + /* we expect file-not-found error, path is valid */ + pf = fopen((char *) prefname, "w"); + if (pf == NULL) return; + cp = strrchr((char *) filename, ':'); + if (cp == NULL) return; + cp[1] = 0; + /* now, filename is the path. If filename ends in runtime, this + * is probably the standard nyquist runtime folder. We should put + * the nyquist lib folder on the path too. + */ + len = cp + 1 - filename; + if (len >= 9 && + strcmp(filename + len - 9, ":runtime:") == 0) { + filename[len - 8] = 0; + fprintf(pf, "XLISPPATH=%sruntime:,%slib:\n", filename, filename); + } else { + fprintf(pf, "XLISPPATH=%s\n", filename); + } + fclose(pf); + } +} diff --git a/lib-src/libnyquist/nyquist/sys/mac/macstuff.h b/lib-src/libnyquist/nyquist/sys/mac/macstuff.h new file mode 100644 index 000000000..29b9b32cf --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/macstuff.h @@ -0,0 +1,7 @@ +/* macstuff.h -- header for mac-specific functions */ + +void osfinish(void); +/* put searchpath into p, prefs_found tells if preference file exists */ +void get_xlisp_path(char *p, long p_max, int *prefs_found); +void setup_preferences(char *filename); + diff --git a/lib-src/libnyquist/nyquist/sys/mac/sndsystem.h b/lib-src/libnyquist/nyquist/sys/mac/sndsystem.h new file mode 100644 index 000000000..f34ea8339 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/sndsystem.h @@ -0,0 +1,2 @@ +#include "sndmac.h" + diff --git a/lib-src/libnyquist/nyquist/sys/mac/switches.h b/lib-src/libnyquist/nyquist/sys/mac/switches.h new file mode 100644 index 000000000..c5a8e588b --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/switches.h @@ -0,0 +1,58 @@ +/* switches.h for Macintosh */ + +/* CHANGE LOG + * -------------------------------------------------------------------- + * 28Apr03 dm major reorganization of conditional compilation in Nyquist + */ + + +#define HAS_STDLIB_H 1 +#undef HAS_SYS_TYPES_H +#undef HAS_SYS_STAT_H +#define HAS_STAT_H 1 +#undef HAS_MALLOC_H + +#define HAS_GETTIMEOFDAY 1 + +#undef READ_LINE + +#define XL_BIG_ENDIAN 1 +#undef XL_LITTLE_ENDIAN + +#define USE_RAND 1 +#undef USE_RANDOM + +/* define this to be printf, or define your own fn of the form + void nyquist_printf(char *format, ...); + (for a GUI) +*/ +void nyquist_printf(char *format, ...); + +#define NEED_ULONG 1 +#define NEED_USHORT 1 +#define NEED_BYTE 1 + +#define NEED_ROUND 1 + +#undef NEED_DEFINE_MALLOC + +/* explicitly choose a platform */ +#undef UNIX +#undef WINDOWS +#undef MICROSOFT +#undef DOS +#define MACINTOSH 1 + +#define BUFFERED_SYNCHRONOUS_INPUT 1 +#define SPACE_FOR_PLAY 10000 +#define MAX_CHANNELS 16 + +/* this will enable code to read midi files, etc. */ +#define CMTSTUFF 1 + +/* NYQUIST tells some CMT code that we're really in + * XLISP and NYQUIST + */ +#define NYQUIST 1 + +#include "swlogic.h" diff --git a/lib-src/libnyquist/nyquist/sys/mac/system.lsp b/lib-src/libnyquist/nyquist/sys/mac/system.lsp new file mode 100644 index 000000000..ea65573f0 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/system.lsp @@ -0,0 +1,107 @@ +; system.lsp -- machine/system-dependent definitions +; Macintosh + +(setf ny:bigendianp t) + +;; note that *default-sf-format* is used below by +;; compute-default-sound-file +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-AIFF)) + +;; note that compute-default-sound-file uses *default-sf-format*, +;; so be sure to set *default-sf-format* first (this was just done) +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + + (if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* "points.dat")) + +; turn off switch to play sound as it is computed +(setf *soundenable* T) + +; local definition for play +(defmacro play (expr) + `(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*)) + +(defun r () + (s-save (s-read *default-sound-file*) NY:ALL "" :play t) +) + +; PLAY-FILE -- play a file +(defun play-file (name) + (s-save (s-read name) NY:ALL "" :play t)) + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (eq (char filename 0) #\:)) + +(setf *file-separator* #\:) + +; save the standard function to write points to a file +; +;(setfn s-plot-points s-plot) + +(defun array-max-abs (points) + (let ((m 0.0)) + (dotimes (i (length points)) + (setf m (max m (abs (aref points i))))) + m)) + +(setf graph-width 800) +(setf graph-height 220) + + +(defun s-plot (snd &optional (n 800)) + (show-graphics) + (clear-graphics) + (cond ((soundp snd) + (s-plot-2 snd n (/ graph-height 2) graph-height nil)) + (t + (let ((gh (/ graph-height (length snd))) + hs) + (dotimes (i (length snd)) + (setf hs (s-plot-2 (aref snd i) n (+ (/ gh 2) (* i gh)) gh hs))))))) + + +(defun s-plot-2 (snd n y-offset graph-height horizontal-scale) + (prog ((points (snd-samples snd n)) + maxpoint horizontal-scale vertical-scale) + (setf maxpoint (array-max-abs points)) + (moveto 0 y-offset) + (lineto graph-width y-offset) + (moveto 0 y-offset) + (cond ((null horizontal-scale) + (setf horizontal-scale (/ (float graph-width) (length points))))) + (setf vertical-scale (- (/ (float graph-height) 2 maxpoint))) + (dotimes (i (length points)) + (lineto (truncate (* horizontal-scale i)) + (+ y-offset (truncate (* vertical-scale (aref points i)))))) + (format t "X Axis: ~A to ~A (seconds)\n" (snd-t0 snd) (/ (length points) (snd-srate snd))) + (format t "Y Axis: ~A to ~A\n" (- maxpoint) maxpoint) + (format t "~A samples plotted.\n" (length points)) + (return horizontal-scale) + )) + + + + +; S-EDIT - run the audio editor on a sound +; +;(defmacro s-edit (&optional expr) +; `(prog () +; (if ,expr (s-save ,expr 1000000000 *default-sound-file*)) +; (system (format nil "audio_editor ~A &" +; (soundfilename *default-sound-file*))))) + diff --git a/lib-src/libnyquist/nyquist/sys/mac/xlextstart.c b/lib-src/libnyquist/nyquist/sys/mac/xlextstart.c new file mode 100644 index 000000000..be321fe85 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/mac/xlextstart.c @@ -0,0 +1 @@ +/* nothing to do */ diff --git a/lib-src/libnyquist/nyquist/sys/unix/README.txt b/lib-src/libnyquist/nyquist/sys/unix/README.txt new file mode 100644 index 000000000..a86cf5046 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/README.txt @@ -0,0 +1,166 @@ +README.txt -- Nyquist information for Unix systems + +UNIX INSTALLATION +================= +For Unix systems, Nyquist is distributed as a compressed file of +sources named nyqsrc3.zip, where is the version number +(e.g. v3.01 was in nyqsrc301.zip). To install Nyquist, copy +nyqsrc3.zip) to the directory on your machine where you would +like to install Nyquist. + +Note 1: you will need the "normal tool chain" consisting of the Gnu +C/C++ compiler, linker, C/C++ runtime libraries, autoconf, libtool, +automake, etc. Most linux installations already have this, but some +more recent trimmed-down installations for netbooks and +consumer-oriented computers do not have compilers installed by +default. + +Note 2: There are two main unix versions of Nyquist: alsa and nonalsa. +The alsa version is probably what you want. This version uses ALSA, +the Linux audio system. This has also become standard, but your +machine might not have the ALSA development package (probably named +libasound2-dev), so you might have to install it. If you find you are +missing "asound", you are missing and need to install the ALSA +developmnent package. The nonalsa version is a special version for +Debian linux. The ONLY difference is that it omits -lasound from the +link step, so it does not try to link with ALSA. I assume this works +because the PortAudio library which is included in the Nyquist sources +configures itself differently on Debian and doesn't need ALSA. + +After unzipping sources, type: + + gunzip nyqsrc3.zip + cd nyquist + # In the following line, Debian linux users should + # type "nonalsa" in place of "alsa": + ln -s sys/unix/alsa/Makefile Makefile + setenv XLISPPATH `pwd`/runtime:`pwd`/lib + make + +(For bash shell users, instead of the setenv command, use this: + + export XLISPPATH=`pwd`/runtime:`pwd`/lib +) + +The first line creates a nyquist directory and some +subdirectories. The second line (cd) changes directories to the new +nyquist directory. The third line (ln) makes a link from the top-level +directory to the Makefile for your system. In place of "alsa" in +sys/unix/alsa/Makefile, you should substitute your system +type. Current systems are alsa, nonalsa, next, pmax, rs6k, sgi, and +sparc, but since only the alsa and nonalsa versions have been tested +in recent years, do not expect anything else to work. The setenv (or +export) command tells Nyquist where to search for lisp files to be +loaded when a file is not found in the current directory. See +SHELL STARTUP below for information about how to automate this. + +64-BIT UBUNTU +============= +if xlisp/extern.c fails to compile because of a missing bits/predefs.h, + try using synaptic to update libc6 and libc6-i386 and libc6-dev-i386, or + try sudo apt-get install libc6-dev-i386 + +you may need to install nasm +you may need to install build-essential and g++ +you may need to install lib32asound2-dev +you may need to install lib32stdc++ +you may need to install g++multilib +you may need to install libogg-dev +you may need to install libvorbis-dev +you may need to install Java (perhaps as follows): + download jdk-7u2-linux-x64.tar.gz from + http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u2-download-1377129.html + tar xfvz jdk-7u2-linux-x64.tar.gz + sudo mv ./jdk1.7.0_02 /usr/lib/jvm/jdk1.7.0 + sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1 + sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 + sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1 + sudo update-alternatives --config java + java -version [check that output is 1.7.0_02"] + sudo update-alternatives --config javac + sudo update-alternatives --config java + + + +RUNNING NYQUIST FROM THE COMMAND LINE +===================================== +Assuming the make completes successfully, you can run Nyquist as follows: + ./ny +When you get the prompt, you may begin typing expressions such as +the ones in the following "Examples" section in the Nyquist +manual. (See doc/nyquistman.pdf or doc/home.html). + +RUNNING NYQUIST USING NyquistIDE +===================================== +One you establish that Nyquist (ny) is working from the command line, +you should try using NyquistIDE, the Java-based Nyquist development +environment. First, make jny executable (do this only once when you +install Nyquist): + chmod +x jny +Then try running jNyqIDE by typing: + ./jny + +If the NyquistIDE window does not appear, make sure you have Java +installed (if not, you probably already encountered errors when you +ran the make command.) You can also try recompiling the Java +files. Note that jnyqide/SpecialMacHandler.java will NOT compile +under non-OS X systems. The Makefile renames this file to "hide" it +from the Java compiler, compiles all the remaining java files, and +then restores jnyqide/SpecialMacHandler.java: + make jnyqide/jNyqIDE.jar + +NYQUIST SEARCH PATH UNDER NyquistIDE +==================================== +Note: With Linux and Mac OS X, jNyqIDE defines the environment passed +to Nyquist. If you set XLISPPATH as shown above, it will be passed +along to Nyquist under jNyqIDE. If not, a default XLISPPATH will have +the lib and runtime directories only. This does not apply to Windows +because even though the environment is there, the Windows version of +Nyquist reads the XLISPPATH from the Registry. + +You can also specify the search path by creating the file +nyquist/xlisppath, which should have colon-separated paths on a single +(long) line of text. This file will override the environment variable +XLISPPATH. + +MORE DETAILS +============ +It is good to have USER in the environment with your user ID. This +string is used to construct some file names. NyquistIDE will look for it +in the environment. You can also specify your user ID using the file +nyquist/user, but if you have a shared installation of Nyquist, +this will not be very useful. + +Note: Nyquist looks for the file init.lsp in the current directory. +If you look in the init.lsp in runtime, you will notice two things. +First, init.lsp loads nyquist.lsp from the Nyquist directory, and +second, init.lsp loads system.lsp which in turn defines the macro +play. Normally, Nyquist plays audio through the PortAudio library, +which should work on any system. An alternative is to save audio to a +file and invoke a local non-Nyquist program to play the sound file. +You can modify system.lsp to accomplish this. + +SHELL STARTUP +============= +The (runtime +directory should always be on your XLISPPATH when you run Nyquist, so +you may want to set XLISPPATH in your shell startup file, e.g. .cshrc. + +Which shell are you using? echo $SHELL will tell you. If you use +/bin/bash, your startup file is probably ~/.profile. (Remember that +"~/" means your home directory, so the file will be something like +/home/rbd/.profile). In this file, you can add a line such as: + +export XLISPPATH="/home/rbd/nyquist/runtime:/home/rbd/nyquist/lib" + +Do not use the shorthand `pwd`/runtime, because `pwd` returns the +current working directory, which is not going to be your Nyquist +directory when .profile is loaded. + +If you use /bin/csh (the C Shell), your startup file is probably +~/.cshrc. (Remember that "~/" means your home directory, so the file +will be something like /home/rbd/.profile). In this file, you can add +a line such as: + +setenv XLISPPATH "/home/rbd/nyquist/runtime:/home/rbd/nyquist/lib" + diff --git a/lib-src/libnyquist/nyquist/sys/unix/alsa/Makefile b/lib-src/libnyquist/nyquist/sys/unix/alsa/Makefile new file mode 100644 index 000000000..4dcbb7725 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/alsa/Makefile @@ -0,0 +1,1140 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is ALSA +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +OPT = -O2 -m32 +# OPT = -g -m32 + +EVERYTHING = $(NY) runtime/system.lsp jnyqide/jNyqIDE.jar \ + bin/ser-to-osc bin/test-client + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +onlyny: $(NY) runtime/system.lsp + +JAVASRC = jnyqide/browser.java jnyqide/NyquistThread.java \ + jnyqide/Pair.java jnyqide/BareBonesBrowserLaunch.java \ + jnyqide/EnvelopeFrame.java jnyqide/Piano_Roll.java \ + jnyqide/FindDialog.java jnyqide/PlotFrame.java \ + jnyqide/InstrumentCharacteristics.java jnyqide/PlotMouseAdapter.java \ + jnyqide/Jslide.java jnyqide/PopupListener.java \ + jnyqide/LispFileFilter.java jnyqide/PreferencesDialog.java \ + jnyqide/MainFrame_AboutBox.java jnyqide/ReplaceDialog.java \ + jnyqide/MainFrame.java jnyqide/SpringUtilities.java jnyqide/Main.java \ + jnyqide/NotFoundDialog.java jnyqide/TextColor.java jnyqide/NyqPlot.java \ + jnyqide/Trie.java jnyqide/NyquistFile.java jnyqide/WordList.java + +jnyqide/jNyqIDE.jar: $(JAVASRC) + if [ -r jnyqide/SpecialMacHandler.java ] ; then \ + mv jnyqide/SpecialMacHandler.java jnyqide/SpecialMacHandler.hidden ;\ + fi + cd jnyqide; javac *.java + mv jnyqide/SpecialMacHandler.hidden jnyqide/SpecialMacHandler.java + rm -rf jnyqide/jNyqIDE.jar + jar -cfm jnyqide/jNyqIDE.jar jnyqide/manifest.txt jnyqide/*.class + +# Standard list of includes (common to all unix versions) +# Keeping portaudio and libsndfile sources local to nyquist +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Iffts/src \ + -Inyqstk/include -Inyqstk -Iportaudio/include -Iportaudio/src/common \ + -Iportaudio/src/os/unix \ + -Iliblo -Inylsf -IFLAC/include -Ilibogg/include -Ilibvorbis/include + +# system dependent stuff for alsa: + +AUDIOLIBS = -lasound + +CC = gcc + +LIBPA_PATH = portaudio/lib/.libs +LIBOGG_PATH = libogg/src/.libs +LIBVORBIS_PATH = libvorbis/lib/.libs +LIBLO_PATH = liblo/src/.libs +LIBFLAC_PATH = FLAC/obj/release/lib + +# to enable command line editing, use -DREADLINE. WARNING: THIS WILL +# DISABLE THE ABILITY TO INTERRUPT LISP AND USE SOME OTHER HANDY +# CONTROL CHARACTERS (You will also need the readline and curses libraries) +CFLAGS = -DOSC -DCMTSTUFF $(OPT) $(INCL) \ + -DHAVE_LIBPTHREAD=1 -D_FILE_OFFSET_BITS=64 \ + -DSTK_NYQUIST -DUSE_VSPRINTF \ + -DHAVE_CONFIG_H +LN = g++ -m32 +AR = ar +# to enable command line editing, insert -lreadline -lcurses +LFLAGS = -L/usr/lib32 $(LIBPA_PATH)/libportaudio.a \ + $(LIBLO_PATH)/liblo.a $(AUDIOLIBS) $(LIBFLAC_PATH)/libFLAC.a \ + $(LIBVORBIS_PATH)/libvorbis.a \ + $(LIBVORBIS_PATH)/libvorbisfile.a \ + $(LIBVORBIS_PATH)/libvorbisenc.a $(LIBOGG_PATH)/libogg.a \ + -lm -lpthread -lrt + +TAGS: + find . ( -name "*.c" -o -name "*.h" ) -print | etags - + +tags: TAGS + +# end of system dependencies + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o xlisp/xlstr.o \ + xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o xlisp/path.o tran/abs.o \ + tran/allpoles.o tran/alpass.o tran/alpasscv.o tran/alpassvv.o \ + tran/amosc.o tran/areson.o tran/aresonvc.o tran/aresoncv.o \ + tran/aresonvv.o tran/atone.o tran/atonev.o tran/biquadfilt.o \ + tran/buzz.o tran/chase.o tran/clip.o tran/congen.o tran/const.o \ + tran/coterm.o tran/delaycc.o tran/delaycv.o tran/eqbandvvv.o tran/exp.o \ + tran/follow.o tran/fmosc.o tran/fromobject.o tran/fromarraystream.o \ + tran/gate.o tran/ifft.o tran/instrclar.o tran/instrclarall.o \ + tran/instrclarfreq.o tran/instrsax.o tran/instrsaxall.o \ + tran/instrsaxfreq.o tran/integrate.o tran/log.o tran/lpreson.o \ + tran/maxv.o tran/offset.o tran/oneshot.o tran/osc.o tran/partial.o \ + tran/pluck.o tran/prod.o tran/pwl.o tran/quantize.o tran/recip.o \ + tran/reson.o tran/resonvc.o tran/resoncv.o tran/resonvv.o \ + tran/sampler.o tran/scale.o tran/shape.o tran/sine.o tran/siosc.o \ + tran/slope.o tran/sqrt.o tran/tapf.o tran/tapv.o tran/tone.o \ + tran/tonev.o tran/upsample.o tran/white.o tran/stkrev.o \ + tran/stkpitshift.o tran/stkchorus.o tran/instrbow.o \ + tran/instrbowedfreq.o tran/instrbanded.o tran/instrmandolin.o \ + tran/instrsitar.o tran/instrmodalbar.o tran/instrflute.o \ + tran/instrflutefreq.o tran/instrfluteall.o tran/fmfb.o tran/fmfbv.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o cmt/moxc.o \ + cmt/mem.o cmt/midifile.o cmt/midifns.o cmt/record.o cmt/seq.o \ + cmt/seqmread.o cmt/seqmwrite.o cmt/seqread.o cmt/seqwrite.o \ + cmt/tempomap.o cmt/timebase.o cmt/userio.o nylsf/aiff.o nylsf/alaw.o \ + nylsf/au.o nylsf/audio_detect.o nylsf/avr.o nylsf/broadcast.o \ + nylsf/caf.o nylsf/chanmap.o nylsf/chunk.o nylsf/command.o \ + nylsf/common.o nylsf/dither.o nylsf/double64.o nylsf/dwd.o nylsf/dwvw.o \ + nylsf/file_io.o nylsf/flac.o nylsf/float32.o nylsf/gsm610.o nylsf/htk.o \ + nylsf/id3.o nylsf/ima_adpcm.o nylsf/ima_oki_adpcm.o nylsf/interleave.o \ + nylsf/ircam.o nylsf/macbinary3.o nylsf/macos.o nylsf/mat4.o \ + nylsf/mat5.o nylsf/mpc2k.o nylsf/ms_adpcm.o nylsf/nist.o nylsf/ogg.o \ + nylsf/ogg_vorbis.o nylsf/paf.o nylsf/pcm.o nylsf/pvf.o nylsf/raw.o \ + nylsf/rf64.o nylsf/rx2.o nylsf/sd2.o nylsf/sds.o nylsf/sndfile.o \ + nylsf/strings.o nylsf/svx.o nylsf/txw.o nylsf/ulaw.o nylsf/voc.o \ + nylsf/vox_adpcm.o nylsf/w64.o nylsf/wav.o nylsf/wav_w64.o nylsf/wve.o \ + nylsf/xi.o nylsf/g72x.o nylsf/GSM610/add.o nylsf/GSM610/code.o \ + nylsf/GSM610/decode.o nylsf/GSM610/gsm_create.o \ + nylsf/GSM610/gsm_decode.o nylsf/GSM610/gsm_destroy.o \ + nylsf/GSM610/gsm_encode.o nylsf/GSM610/gsm_option.o \ + nylsf/GSM610/long_term.o nylsf/GSM610/lpc.o nylsf/GSM610/preprocess.o \ + nylsf/GSM610/rpe.o nylsf/GSM610/short_term.o nylsf/GSM610/table.o \ + nylsf/G72x/g721.o nylsf/G72x/g723_16.o nylsf/G72x/g723_24.o \ + nylsf/G72x/g723_40.o nylsf/G72x/g72x.o nyqsrc/debug.o nyqsrc/falloc.o \ + nyqsrc/local.o nyqsrc/handlers.o nyqsrc/multiread.o nyqsrc/seqext.o \ + nyqsrc/seqinterf.o nyqsrc/stats.o nyqsrc/ffilterkit.o nyqsrc/sound.o \ + nyqsrc/add.o nyqsrc/avg.o nyqsrc/compose.o nyqsrc/convolve.o \ + nyqsrc/downsample.o nyqsrc/fft.o nyqsrc/inverse.o nyqsrc/multiseq.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/samples.o nyqsrc/sndmax.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndsliders.o \ + nyqsrc/sliderdata.o nyqsrc/sndwritepa.o nyqsrc/yin.o \ + nyqsrc/nyq-osc-server.o nyqsrc/trigger.o nyqsrc/lpanal.o \ + nyqsrc/phasevocoder.o nyqsrc/pvshell.o nyqstk/src/Generator.o \ + nyqstk/src/SineWave.o nyqstk/src/Function.o nyqstk/src/FileRead.o \ + nyqstk/src/FileWvIn.o nyqstk/src/Effect.o nyqstk/src/Clarinet.o \ + nyqstk/src/Delay.o nyqstk/src/DelayL.o nyqstk/src/Envelope.o \ + nyqstk/src/Filter.o nyqstk/src/Instrmnt.o nyqstk/src/Noise.o \ + nyqstk/src/OneZero.o nyqstk/src/ReedTable.o nyqstk/src/Saxofony.o \ + nyqstk/src/Stk.o nyqstk/src/WaveLoop.o nyqstk/src/WvIn.o \ + nyqstk/src/NRev.o nyqstk/src/JCRev.o nyqstk/src/PRCRev.o \ + nyqstk/src/PitShift.o nyqstk/src/Chorus.o nyqstk/src/Bowed.o \ + nyqstk/src/BowTable.o nyqstk/src/ADSR.o nyqstk/src/OnePole.o \ + nyqstk/src/BiQuad.o nyqstk/src/BandedWG.o nyqstk/src/DelayA.o \ + nyqstk/src/Mandolin.o nyqstk/src/PluckTwo.o nyqstk/src/Sitar.o \ + nyqstk/src/ModalBar.o nyqstk/src/Modal.o nyqstk/src/Flute.o \ + nyqstk/src/JetTable.o nyqstk/src/PoleZero.o nyqstk/stkinit.o \ + nyqstk/instr.o nyqstk/stkint.o ffts/src/fftext.o ffts/src/fftlib.o \ + ffts/src/matlib.o nyqsrc/sndfnint.o nyqsrc/seqfnint.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +SNDFNINT_HDRS = nyqsrc/sndfmt.h nylsf/sndfile.h nyqsrc/sound.h \ + nyqsrc/add.h nyqsrc/avg.h nyqsrc/compose.h nyqsrc/convolve.h \ + nyqsrc/downsample.h nyqsrc/fft.h nyqsrc/inverse.h nyqsrc/multiseq.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/samples.h nyqsrc/sndmax.h \ + nyqsrc/sndread.h nyqsrc/sndseq.h nyqsrc/sndsliders.h \ + nyqsrc/sliderdata.h nyqsrc/sndwritepa.h nyqsrc/yin.h \ + nyqsrc/nyq-osc-server.h nyqsrc/trigger.h nyqsrc/lpanal.h \ + nyqsrc/phasevocoder.h nyqsrc/pvshell.h tran/abs.h tran/allpoles.h \ + tran/alpass.h tran/alpasscv.h tran/alpassvv.h tran/amosc.h \ + tran/areson.h tran/aresonvc.h tran/aresoncv.h tran/aresonvv.h \ + tran/atone.h tran/atonev.h tran/biquadfilt.h tran/buzz.h tran/chase.h \ + tran/clip.h tran/congen.h tran/const.h tran/coterm.h tran/delaycc.h \ + tran/delaycv.h tran/eqbandvvv.h tran/exp.h tran/follow.h tran/fmosc.h \ + tran/fromobject.h tran/fromarraystream.h tran/gate.h tran/ifft.h \ + tran/instrclar.h tran/instrclarall.h tran/instrclarfreq.h \ + tran/instrsax.h tran/instrsaxall.h tran/instrsaxfreq.h tran/integrate.h \ + tran/log.h tran/lpreson.h tran/maxv.h tran/offset.h tran/oneshot.h \ + tran/osc.h tran/partial.h tran/pluck.h tran/prod.h tran/pwl.h \ + tran/quantize.h tran/recip.h tran/reson.h tran/resonvc.h tran/resoncv.h \ + tran/resonvv.h tran/sampler.h tran/scale.h tran/shape.h tran/sine.h \ + tran/siosc.h tran/slope.h tran/sqrt.h tran/tapf.h tran/tapv.h \ + tran/tone.h tran/tonev.h tran/upsample.h tran/white.h tran/stkrev.h \ + tran/stkpitshift.h tran/stkchorus.h tran/instrbow.h \ + tran/instrbowedfreq.h tran/instrbanded.h tran/instrmandolin.h \ + tran/instrsitar.h tran/instrmodalbar.h tran/instrflute.h \ + tran/instrflutefreq.h tran/instrfluteall.h tran/fmfb.h tran/fmfbv.h \ + nyqsrc/sndwrite.h + +SEQFNINT_HDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h \ + nyqsrc/seqinterf.h cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h \ + cmt/seqmwrite.h + + + +liblo/Makefile: + cd liblo; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + # sometimes, residual files cause problems + cd liblo; make clean + +$(LIBLO_PATH)/liblo.a: liblo/Makefile + cd liblo; make + +bin/ser-to-osc: $(LIBLO_PATH)/liblo.a + mkdir -p bin + $(CC) -c $(CFLAGS) liblo/ser-to-osc/ser-to-osc.cpp \ + -o liblo/ser-to-osc/ser-to-osc.o + $(LN) liblo/ser-to-osc/ser-to-osc.o -o bin/ser-to-osc $(LFLAGS) + +bin/test-client: $(LIBLO_PATH)/liblo.a + mkdir -p bin + $(CC) -c $(CFLAGS) liblo/test-client/test-client.c \ + -o liblo/test-client/test-client.o + $(LN) liblo/test-client/test-client.o -o bin/test-client $(LFLAGS) + +portaudio/Makefile: + # note: without-jack avoids 32/64-bit link error on Debian + cd portaudio; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared --without-jack --with-alsa + # sometimes, residual files cause problems + cd portaudio; make clean + +$(LIBPA_PATH)/libportaudio.a: portaudio/Makefile + cd portaudio; make lib/libportaudio.la + +libogg/Makefile: + cd libogg; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + +$(LIBOGG_PATH)/libogg.a: libogg/Makefile + cd libogg; make + +# NOTE: libvorbis/configure on a 64-bit machine will expect to find +# libogg installed (even though we are not going to use the installed +# libogg library, and even though the installed libogg library will +# be for 64-bit architecture. This represents a bug in configure +# because it checks for a 64-bit library when it is building for +# a 32-bit architecture (we pass in CFLAGS=-m32). In spite of the +# bug, configure will build a Makefile that will build a 32-bit +# libvorbis library that we need. We will link it with other +# 32-bit code including 32-bit libogg.a + +libvorbis/Makefile: + cd libvorbis; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + +$(LIBVORBIS_PATH)/libvorbis.a: libvorbis/Makefile + cd libvorbis; make + +$(LIBVORBIS_PATH)/libvorbisfile.a: libvorbis/Makefile + cd libvorbis; make + +$(LIBVORBIS_PATH)/libvorbisenc.a: libvorbis/Makefile + cd libvorbis; make + + +$(LIBFLAC_PATH)/libFLAC.a: FLAC/src/libFLAC/Makefile.lite + cd FLAC/src/libFLAC; make -f Makefile.lite + +$(NY): $(OBJECTS) $(LIBPA_PATH)/libportaudio.a $(LIBLO_PATH)/liblo.a \ + FLAC/obj/release/lib/libFLAC.a \ + $(LIBVORBIS_PATH)/libvorbis.a $(LIBVORBIS_PATH)/libvorbisfile.a \ + $(LIBVORBIS_PATH)/libvorbisenc.a $(LIBOGG_PATH)/libogg.a + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/alsa/system.lsp +# make sure it's there before you make it writeable + touch runtime/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/alsa/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +NYQDEP = nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h $(NYQDEP) + $(CC) -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h $(NYQDEP) + $(CC) -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h $(NYQDEP) + $(CC) -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h $(NYQDEP) + $(CC) -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/convolve.o: nyqsrc/convolve.c nyqsrc/convolve.h $(NYQDEP) + $(CC) -c nyqsrc/convolve.c -o nyqsrc/convolve.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h $(NYQDEP) + $(CC) -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h $(NYQDEP) + $(CC) -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h $(NYQDEP) + $(CC) -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h $(NYQDEP) + $(CC) -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h $(NYQDEP) + $(CC) -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h $(NYQDEP) + $(CC) -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h $(NYQDEP) + $(CC) -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h $(NYQDEP) + $(CC) -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h $(NYQDEP) + $(CC) -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h $(NYQDEP) + $(CC) -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndsliders.o: nyqsrc/sndsliders.c nyqsrc/sndsliders.h $(NYQDEP) + $(CC) -c nyqsrc/sndsliders.c -o nyqsrc/sndsliders.o $(CFLAGS) + +nyqsrc/sliderdata.o: nyqsrc/sliderdata.c nyqsrc/sliderdata.h $(NYQDEP) + $(CC) -c nyqsrc/sliderdata.c -o nyqsrc/sliderdata.o $(CFLAGS) + +nyqsrc/sndwritepa.o: nyqsrc/sndwritepa.c nyqsrc/sndwrite.h + $(CC) -c nyqsrc/sndwritepa.c -o nyqsrc/sndwritepa.o $(CFLAGS) + +nyqsrc/yin.o: nyqsrc/yin.c nyqsrc/yin.h $(NYQDEP) + $(CC) -c nyqsrc/yin.c -o nyqsrc/yin.o $(CFLAGS) + +nyqsrc/nyq-osc-server.o: nyqsrc/nyq-osc-server.c nyqsrc/nyq-osc-server.h $(NYQDEP) + $(CC) -c nyqsrc/nyq-osc-server.c -o nyqsrc/nyq-osc-server.o $(CFLAGS) + +nyqsrc/trigger.o: nyqsrc/trigger.c nyqsrc/trigger.h $(NYQDEP) + $(CC) -c nyqsrc/trigger.c -o nyqsrc/trigger.o $(CFLAGS) + +nyqsrc/lpanal.o: nyqsrc/lpanal.c nyqsrc/lpanal.h $(NYQDEP) + $(CC) -c nyqsrc/lpanal.c -o nyqsrc/lpanal.o $(CFLAGS) + +nyqsrc/phasevocoder.o: nyqsrc/phasevocoder.c nyqsrc/phasevocoder.h $(NYQDEP) + $(CC) -c nyqsrc/phasevocoder.c -o nyqsrc/phasevocoder.o $(CFLAGS) + +nyqsrc/pvshell.o: nyqsrc/pvshell.c nyqsrc/pvshell.h $(NYQDEP) + $(CC) -c nyqsrc/pvshell.c -o nyqsrc/pvshell.o $(CFLAGS) + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h $(NYQDEP) + $(CC) -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h $(NYQDEP) + $(CC) -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + $(CC) -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + $(CC) -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h $(NYQDEP) + $(CC) -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h $(NYQDEP) + $(CC) -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h $(NYQDEP) + $(CC) -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + $(CC) -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h $(NYQDEP) + $(CC) -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +ffts/src/fftext.o: ffts/src/fftext.c ffts/src/fftext.h $(NYQDEP) + $(CC) -c ffts/src/fftext.c -o ffts/src/fftext.o $(CFLAGS) + +ffts/src/fftlib.o: ffts/src/fftlib.c ffts/src/fftlib.h $(NYQDEP) + $(CC) -c ffts/src/fftlib.c -o ffts/src/fftlib.o $(CFLAGS) + +ffts/src/matlib.o: ffts/src/matlib.c ffts/src/matlib.h $(NYQDEP) + $(CC) -c ffts/src/matlib.c -o ffts/src/matlib.o $(CFLAGS) + +tran/abs.o: tran/abs.c tran/abs.h $(NYQDEP) + $(CC) -c tran/abs.c -o tran/abs.o $(CFLAGS) + +tran/allpoles.o: tran/allpoles.c tran/allpoles.h $(NYQDEP) + $(CC) -c tran/allpoles.c -o tran/allpoles.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h $(NYQDEP) + $(CC) -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/alpasscv.o: tran/alpasscv.c tran/alpasscv.h $(NYQDEP) + $(CC) -c tran/alpasscv.c -o tran/alpasscv.o $(CFLAGS) + +tran/alpassvv.o: tran/alpassvv.c tran/alpassvv.h $(NYQDEP) + $(CC) -c tran/alpassvv.c -o tran/alpassvv.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h $(NYQDEP) + $(CC) -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h $(NYQDEP) + $(CC) -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h $(NYQDEP) + $(CC) -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h $(NYQDEP) + $(CC) -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h $(NYQDEP) + $(CC) -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h $(NYQDEP) + $(CC) -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h $(NYQDEP) + $(CC) -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/biquadfilt.o: tran/biquadfilt.c tran/biquadfilt.h $(NYQDEP) + $(CC) -c tran/biquadfilt.c -o tran/biquadfilt.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h $(NYQDEP) + $(CC) -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h $(NYQDEP) + $(CC) -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h $(NYQDEP) + $(CC) -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h $(NYQDEP) + $(CC) -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h $(NYQDEP) + $(CC) -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h $(NYQDEP) + $(CC) -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h $(NYQDEP) + $(CC) -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h $(NYQDEP) + $(CC) -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/eqbandvvv.o: tran/eqbandvvv.c tran/eqbandvvv.h $(NYQDEP) + $(CC) -c tran/eqbandvvv.c -o tran/eqbandvvv.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h $(NYQDEP) + $(CC) -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h $(NYQDEP) + $(CC) -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h $(NYQDEP) + $(CC) -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h $(NYQDEP) + $(CC) -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h $(NYQDEP) + $(CC) -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h $(NYQDEP) + $(CC) -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h $(NYQDEP) + $(CC) -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/instrclar.o: tran/instrclar.c tran/instrclar.h $(NYQDEP) + $(CC) -c tran/instrclar.c -o tran/instrclar.o $(CFLAGS) + +tran/instrclarall.o: tran/instrclarall.c tran/instrclarall.h $(NYQDEP) + $(CC) -c tran/instrclarall.c -o tran/instrclarall.o $(CFLAGS) + +tran/instrclarfreq.o: tran/instrclarfreq.c tran/instrclarfreq.h $(NYQDEP) + $(CC) -c tran/instrclarfreq.c -o tran/instrclarfreq.o $(CFLAGS) + +tran/instrsax.o: tran/instrsax.c tran/instrsax.h $(NYQDEP) + $(CC) -c tran/instrsax.c -o tran/instrsax.o $(CFLAGS) + +tran/instrsaxall.o: tran/instrsaxall.c tran/instrsaxall.h $(NYQDEP) + $(CC) -c tran/instrsaxall.c -o tran/instrsaxall.o $(CFLAGS) + +tran/instrsaxfreq.o: tran/instrsaxfreq.c tran/instrsaxfreq.h $(NYQDEP) + $(CC) -c tran/instrsaxfreq.c -o tran/instrsaxfreq.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h $(NYQDEP) + $(CC) -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h $(NYQDEP) + $(CC) -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/lpreson.o: tran/lpreson.c tran/lpreson.h $(NYQDEP) + $(CC) -c tran/lpreson.c -o tran/lpreson.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h $(NYQDEP) + $(CC) -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h $(NYQDEP) + $(CC) -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h $(NYQDEP) + $(CC) -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h $(NYQDEP) + $(CC) -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h $(NYQDEP) + $(CC) -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h $(NYQDEP) + $(CC) -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h $(NYQDEP) + $(CC) -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h $(NYQDEP) + $(CC) -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h $(NYQDEP) + $(CC) -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h $(NYQDEP) + $(CC) -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h $(NYQDEP) + $(CC) -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h $(NYQDEP) + $(CC) -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h $(NYQDEP) + $(CC) -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h $(NYQDEP) + $(CC) -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h $(NYQDEP) + $(CC) -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h $(NYQDEP) + $(CC) -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h $(NYQDEP) + $(CC) -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h $(NYQDEP) + $(CC) -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h $(NYQDEP) + $(CC) -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h $(NYQDEP) + $(CC) -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/sqrt.o: tran/sqrt.c tran/sqrt.h $(NYQDEP) + $(CC) -c tran/sqrt.c -o tran/sqrt.o $(CFLAGS) + +tran/tapf.o: tran/tapf.c tran/tapf.h $(NYQDEP) + $(CC) -c tran/tapf.c -o tran/tapf.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h $(NYQDEP) + $(CC) -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h $(NYQDEP) + $(CC) -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h $(NYQDEP) + $(CC) -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h $(NYQDEP) + $(CC) -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h $(NYQDEP) + $(CC) -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/stkrev.o: tran/stkrev.c tran/stkrev.h $(NYQDEP) + $(CC) -c tran/stkrev.c -o tran/stkrev.o $(CFLAGS) + +tran/stkpitshift.o: tran/stkpitshift.c tran/stkpitshift.h $(NYQDEP) + $(CC) -c tran/stkpitshift.c -o tran/stkpitshift.o $(CFLAGS) + +tran/stkchorus.o: tran/stkchorus.c tran/stkchorus.h $(NYQDEP) + $(CC) -c tran/stkchorus.c -o tran/stkchorus.o $(CFLAGS) + +tran/instrbow.o: tran/instrbow.c tran/instrbow.h $(NYQDEP) + $(CC) -c tran/instrbow.c -o tran/instrbow.o $(CFLAGS) + +tran/instrbowedfreq.o: tran/instrbowedfreq.c tran/instrbowedfreq.h $(NYQDEP) + $(CC) -c tran/instrbowedfreq.c -o tran/instrbowedfreq.o $(CFLAGS) + +tran/instrbanded.o: tran/instrbanded.c tran/instrbanded.h $(NYQDEP) + $(CC) -c tran/instrbanded.c -o tran/instrbanded.o $(CFLAGS) + +tran/instrmandolin.o: tran/instrmandolin.c tran/instrmandolin.h $(NYQDEP) + $(CC) -c tran/instrmandolin.c -o tran/instrmandolin.o $(CFLAGS) + +tran/instrsitar.o: tran/instrsitar.c tran/instrsitar.h $(NYQDEP) + $(CC) -c tran/instrsitar.c -o tran/instrsitar.o $(CFLAGS) + +tran/instrmodalbar.o: tran/instrmodalbar.c tran/instrmodalbar.h $(NYQDEP) + $(CC) -c tran/instrmodalbar.c -o tran/instrmodalbar.o $(CFLAGS) + +tran/instrflute.o: tran/instrflute.c tran/instrflute.h $(NYQDEP) + $(CC) -c tran/instrflute.c -o tran/instrflute.o $(CFLAGS) + +tran/instrflutefreq.o: tran/instrflutefreq.c tran/instrflutefreq.h $(NYQDEP) + $(CC) -c tran/instrflutefreq.c -o tran/instrflutefreq.o $(CFLAGS) + +tran/instrfluteall.o: tran/instrfluteall.c tran/instrfluteall.h $(NYQDEP) + $(CC) -c tran/instrfluteall.c -o tran/instrfluteall.o $(CFLAGS) + +tran/fmfb.o: tran/fmfb.c tran/fmfb.h $(NYQDEP) + $(CC) -c tran/fmfb.c -o tran/fmfb.o $(CFLAGS) + +tran/fmfbv.o: tran/fmfbv.c tran/fmfbv.h $(NYQDEP) + $(CC) -c tran/fmfbv.c -o tran/fmfbv.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + $(CC) -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + $(CC) -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +nyqstk/stkinit.o: nyqstk/stkinit.cpp nyqstk/stkinit.h + g++ -c nyqstk/stkinit.cpp -o nyqstk/stkinit.o $(CFLAGS) + +nyqstk/instr.o: nyqstk/instr.cpp nyqstk/instr.h + g++ -c nyqstk/instr.cpp -o nyqstk/instr.o $(CFLAGS) + +nyqstk/stkint.o: nyqstk/stkint.cpp nyqstk/stkint.h + g++ -c nyqstk/stkint.cpp -o nyqstk/stkint.o $(CFLAGS) + +nyqstk/src/Generator.o: nyqstk/src/Generator.cpp nyqstk/include/Generator.h + g++ -c nyqstk/src/Generator.cpp -o nyqstk/src/Generator.o $(CFLAGS) + +nyqstk/src/SineWave.o: nyqstk/src/SineWave.cpp nyqstk/include/SineWave.h + g++ -c nyqstk/src/SineWave.cpp -o nyqstk/src/SineWave.o $(CFLAGS) + +nyqstk/src/Function.o: nyqstk/src/Function.cpp nyqstk/include/Function.h + g++ -c nyqstk/src/Function.cpp -o nyqstk/src/Function.o $(CFLAGS) + +nyqstk/src/FileRead.o: nyqstk/src/FileRead.cpp nyqstk/include/FileRead.h + g++ -c nyqstk/src/FileRead.cpp -o nyqstk/src/FileRead.o $(CFLAGS) + +nyqstk/src/FileWvIn.o: nyqstk/src/FileWvIn.cpp nyqstk/include/FileWvIn.h + g++ -c nyqstk/src/FileWvIn.cpp -o nyqstk/src/FileWvIn.o $(CFLAGS) + +nyqstk/src/Effect.o: nyqstk/src/Effect.cpp nyqstk/include/Effect.h + g++ -c nyqstk/src/Effect.cpp -o nyqstk/src/Effect.o $(CFLAGS) + +nyqstk/src/Clarinet.o: nyqstk/src/Clarinet.cpp nyqstk/include/Clarinet.h + g++ -c nyqstk/src/Clarinet.cpp -o nyqstk/src/Clarinet.o $(CFLAGS) + +nyqstk/src/Delay.o: nyqstk/src/Delay.cpp nyqstk/include/Delay.h + g++ -c nyqstk/src/Delay.cpp -o nyqstk/src/Delay.o $(CFLAGS) + +nyqstk/src/DelayL.o: nyqstk/src/DelayL.cpp nyqstk/include/DelayL.h + g++ -c nyqstk/src/DelayL.cpp -o nyqstk/src/DelayL.o $(CFLAGS) + +nyqstk/src/Envelope.o: nyqstk/src/Envelope.cpp nyqstk/include/Envelope.h + g++ -c nyqstk/src/Envelope.cpp -o nyqstk/src/Envelope.o $(CFLAGS) + +nyqstk/src/Filter.o: nyqstk/src/Filter.cpp nyqstk/include/Filter.h + g++ -c nyqstk/src/Filter.cpp -o nyqstk/src/Filter.o $(CFLAGS) + +nyqstk/src/Instrmnt.o: nyqstk/src/Instrmnt.cpp nyqstk/include/Instrmnt.h + g++ -c nyqstk/src/Instrmnt.cpp -o nyqstk/src/Instrmnt.o $(CFLAGS) + +nyqstk/src/Noise.o: nyqstk/src/Noise.cpp nyqstk/include/Noise.h + g++ -c nyqstk/src/Noise.cpp -o nyqstk/src/Noise.o $(CFLAGS) + +nyqstk/src/OneZero.o: nyqstk/src/OneZero.cpp nyqstk/include/OneZero.h + g++ -c nyqstk/src/OneZero.cpp -o nyqstk/src/OneZero.o $(CFLAGS) + +nyqstk/src/ReedTable.o: nyqstk/src/ReedTable.cpp nyqstk/include/ReedTable.h + g++ -c nyqstk/src/ReedTable.cpp -o nyqstk/src/ReedTable.o $(CFLAGS) + +nyqstk/src/Saxofony.o: nyqstk/src/Saxofony.cpp nyqstk/include/Saxofony.h + g++ -c nyqstk/src/Saxofony.cpp -o nyqstk/src/Saxofony.o $(CFLAGS) + +nyqstk/src/Stk.o: nyqstk/src/Stk.cpp nyqstk/include/Stk.h + g++ -c nyqstk/src/Stk.cpp -o nyqstk/src/Stk.o $(CFLAGS) + +nyqstk/src/WaveLoop.o: nyqstk/src/WaveLoop.cpp nyqstk/include/WaveLoop.h + g++ -c nyqstk/src/WaveLoop.cpp -o nyqstk/src/WaveLoop.o $(CFLAGS) + +nyqstk/src/WvIn.o: nyqstk/src/WvIn.cpp nyqstk/include/WvIn.h + g++ -c nyqstk/src/WvIn.cpp -o nyqstk/src/WvIn.o $(CFLAGS) + +nyqstk/src/NRev.o: nyqstk/src/NRev.cpp nyqstk/include/NRev.h + g++ -c nyqstk/src/NRev.cpp -o nyqstk/src/NRev.o $(CFLAGS) + +nyqstk/src/JCRev.o: nyqstk/src/JCRev.cpp nyqstk/include/JCRev.h + g++ -c nyqstk/src/JCRev.cpp -o nyqstk/src/JCRev.o $(CFLAGS) + +nyqstk/src/PRCRev.o: nyqstk/src/PRCRev.cpp nyqstk/include/PRCRev.h + g++ -c nyqstk/src/PRCRev.cpp -o nyqstk/src/PRCRev.o $(CFLAGS) + +nyqstk/src/PitShift.o: nyqstk/src/PitShift.cpp nyqstk/include/PitShift.h + g++ -c nyqstk/src/PitShift.cpp -o nyqstk/src/PitShift.o $(CFLAGS) + +nyqstk/src/Chorus.o: nyqstk/src/Chorus.cpp nyqstk/include/Chorus.h + g++ -c nyqstk/src/Chorus.cpp -o nyqstk/src/Chorus.o $(CFLAGS) + +nyqstk/src/Bowed.o: nyqstk/src/Bowed.cpp nyqstk/include/Bowed.h + g++ -c nyqstk/src/Bowed.cpp -o nyqstk/src/Bowed.o $(CFLAGS) + +nyqstk/src/BowTable.o: nyqstk/src/BowTable.cpp nyqstk/include/BowTable.h + g++ -c nyqstk/src/BowTable.cpp -o nyqstk/src/BowTable.o $(CFLAGS) + +nyqstk/src/ADSR.o: nyqstk/src/ADSR.cpp nyqstk/include/ADSR.h + g++ -c nyqstk/src/ADSR.cpp -o nyqstk/src/ADSR.o $(CFLAGS) + +nyqstk/src/OnePole.o: nyqstk/src/OnePole.cpp nyqstk/include/OnePole.h + g++ -c nyqstk/src/OnePole.cpp -o nyqstk/src/OnePole.o $(CFLAGS) + +nyqstk/src/BiQuad.o: nyqstk/src/BiQuad.cpp nyqstk/include/BiQuad.h + g++ -c nyqstk/src/BiQuad.cpp -o nyqstk/src/BiQuad.o $(CFLAGS) + +nyqstk/src/BandedWG.o: nyqstk/src/BandedWG.cpp nyqstk/include/BandedWG.h + g++ -c nyqstk/src/BandedWG.cpp -o nyqstk/src/BandedWG.o $(CFLAGS) + +nyqstk/src/DelayA.o: nyqstk/src/DelayA.cpp nyqstk/include/DelayA.h + g++ -c nyqstk/src/DelayA.cpp -o nyqstk/src/DelayA.o $(CFLAGS) + +nyqstk/src/Mandolin.o: nyqstk/src/Mandolin.cpp nyqstk/include/Mandolin.h + g++ -c nyqstk/src/Mandolin.cpp -o nyqstk/src/Mandolin.o $(CFLAGS) + +nyqstk/src/PluckTwo.o: nyqstk/src/PluckTwo.cpp nyqstk/include/PluckTwo.h + g++ -c nyqstk/src/PluckTwo.cpp -o nyqstk/src/PluckTwo.o $(CFLAGS) + +nyqstk/src/Sitar.o: nyqstk/src/Sitar.cpp nyqstk/include/Sitar.h + g++ -c nyqstk/src/Sitar.cpp -o nyqstk/src/Sitar.o $(CFLAGS) + +nyqstk/src/ModalBar.o: nyqstk/src/ModalBar.cpp nyqstk/include/ModalBar.h + g++ -c nyqstk/src/ModalBar.cpp -o nyqstk/src/ModalBar.o $(CFLAGS) + +nyqstk/src/Modal.o: nyqstk/src/Modal.cpp nyqstk/include/Modal.h + g++ -c nyqstk/src/Modal.cpp -o nyqstk/src/Modal.o $(CFLAGS) + +nyqstk/src/Flute.o: nyqstk/src/Flute.cpp nyqstk/include/Flute.h + g++ -c nyqstk/src/Flute.cpp -o nyqstk/src/Flute.o $(CFLAGS) + +nyqstk/src/JetTable.o: nyqstk/src/JetTable.cpp nyqstk/include/JetTable.h + g++ -c nyqstk/src/JetTable.cpp -o nyqstk/src/JetTable.o $(CFLAGS) + +nyqstk/src/PoleZero.o: nyqstk/src/PoleZero.cpp nyqstk/include/PoleZero.h + g++ -c nyqstk/src/PoleZero.cpp -o nyqstk/src/PoleZero.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + $(CC) -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + $(CC) -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + $(CC) -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + $(CC) -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + $(CC) -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + $(CC) -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + $(CC) -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + $(CC) -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + $(CC) -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + $(CC) -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + $(CC) -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + $(CC) -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + $(CC) -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + $(CC) -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + $(CC) -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + $(CC) -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + $(CC) -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + $(CC) -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + $(CC) -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + $(CC) -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + $(CC) -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + $(CC) -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + $(CC) -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + $(CC) -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +xlisp/path.o: xlisp/path.c + $(CC) -c xlisp/path.c -o xlisp/path.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + $(CC) -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + $(CC) -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + $(CC) -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + $(CC) -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + $(CC) -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + $(CC) -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + $(CC) -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + $(CC) -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + $(CC) -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + $(CC) -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + $(CC) -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + $(CC) -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + $(CC) -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + $(CC) -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + $(CC) -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + $(CC) -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + $(CC) -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +nylsf/aiff.o: nylsf/aiff.c + $(CC) -c nylsf/aiff.c -o nylsf/aiff.o $(CFLAGS) + +nylsf/alaw.o: nylsf/alaw.c + $(CC) -c nylsf/alaw.c -o nylsf/alaw.o $(CFLAGS) + +nylsf/au.o: nylsf/au.c + $(CC) -c nylsf/au.c -o nylsf/au.o $(CFLAGS) + +nylsf/audio_detect.o: nylsf/audio_detect.c + $(CC) -c nylsf/audio_detect.c -o nylsf/audio_detect.o $(CFLAGS) + +nylsf/avr.o: nylsf/avr.c + $(CC) -c nylsf/avr.c -o nylsf/avr.o $(CFLAGS) + +nylsf/broadcast.o: nylsf/broadcast.c + $(CC) -c nylsf/broadcast.c -o nylsf/broadcast.o $(CFLAGS) + +nylsf/caf.o: nylsf/caf.c + $(CC) -c nylsf/caf.c -o nylsf/caf.o $(CFLAGS) + +nylsf/chanmap.o: nylsf/chanmap.c + $(CC) -c nylsf/chanmap.c -o nylsf/chanmap.o $(CFLAGS) + +nylsf/chunk.o: nylsf/chunk.c + $(CC) -c nylsf/chunk.c -o nylsf/chunk.o $(CFLAGS) + +nylsf/command.o: nylsf/command.c + $(CC) -c nylsf/command.c -o nylsf/command.o $(CFLAGS) + +nylsf/common.o: nylsf/common.c + $(CC) -c nylsf/common.c -o nylsf/common.o $(CFLAGS) + +nylsf/dither.o: nylsf/dither.c + $(CC) -c nylsf/dither.c -o nylsf/dither.o $(CFLAGS) + +nylsf/double64.o: nylsf/double64.c + $(CC) -c nylsf/double64.c -o nylsf/double64.o $(CFLAGS) + +nylsf/dwd.o: nylsf/dwd.c + $(CC) -c nylsf/dwd.c -o nylsf/dwd.o $(CFLAGS) + +nylsf/dwvw.o: nylsf/dwvw.c + $(CC) -c nylsf/dwvw.c -o nylsf/dwvw.o $(CFLAGS) + +nylsf/file_io.o: nylsf/file_io.c + $(CC) -c nylsf/file_io.c -o nylsf/file_io.o $(CFLAGS) + +nylsf/flac.o: nylsf/flac.c + $(CC) -c nylsf/flac.c -o nylsf/flac.o $(CFLAGS) + +nylsf/float32.o: nylsf/float32.c + $(CC) -c nylsf/float32.c -o nylsf/float32.o $(CFLAGS) + +nylsf/gsm610.o: nylsf/gsm610.c + $(CC) -c nylsf/gsm610.c -o nylsf/gsm610.o $(CFLAGS) + +nylsf/htk.o: nylsf/htk.c + $(CC) -c nylsf/htk.c -o nylsf/htk.o $(CFLAGS) + +nylsf/id3.o: nylsf/id3.c + $(CC) -c nylsf/id3.c -o nylsf/id3.o $(CFLAGS) + +nylsf/ima_adpcm.o: nylsf/ima_adpcm.c + $(CC) -c nylsf/ima_adpcm.c -o nylsf/ima_adpcm.o $(CFLAGS) + +nylsf/ima_oki_adpcm.o: nylsf/ima_oki_adpcm.c + $(CC) -c nylsf/ima_oki_adpcm.c -o nylsf/ima_oki_adpcm.o $(CFLAGS) + +nylsf/interleave.o: nylsf/interleave.c + $(CC) -c nylsf/interleave.c -o nylsf/interleave.o $(CFLAGS) + +nylsf/ircam.o: nylsf/ircam.c + $(CC) -c nylsf/ircam.c -o nylsf/ircam.o $(CFLAGS) + +nylsf/macbinary3.o: nylsf/macbinary3.c + $(CC) -c nylsf/macbinary3.c -o nylsf/macbinary3.o $(CFLAGS) + +nylsf/macos.o: nylsf/macos.c + $(CC) -c nylsf/macos.c -o nylsf/macos.o $(CFLAGS) + +nylsf/mat4.o: nylsf/mat4.c + $(CC) -c nylsf/mat4.c -o nylsf/mat4.o $(CFLAGS) + +nylsf/mat5.o: nylsf/mat5.c + $(CC) -c nylsf/mat5.c -o nylsf/mat5.o $(CFLAGS) + +nylsf/mpc2k.o: nylsf/mpc2k.c + $(CC) -c nylsf/mpc2k.c -o nylsf/mpc2k.o $(CFLAGS) + +nylsf/ms_adpcm.o: nylsf/ms_adpcm.c + $(CC) -c nylsf/ms_adpcm.c -o nylsf/ms_adpcm.o $(CFLAGS) + +nylsf/nist.o: nylsf/nist.c + $(CC) -c nylsf/nist.c -o nylsf/nist.o $(CFLAGS) + +nylsf/ogg.o: nylsf/ogg.c + $(CC) -c nylsf/ogg.c -o nylsf/ogg.o $(CFLAGS) + +nylsf/ogg_vorbis.o: nylsf/ogg_vorbis.c + $(CC) -c nylsf/ogg_vorbis.c -o nylsf/ogg_vorbis.o $(CFLAGS) + +nylsf/paf.o: nylsf/paf.c + $(CC) -c nylsf/paf.c -o nylsf/paf.o $(CFLAGS) + +nylsf/pcm.o: nylsf/pcm.c + $(CC) -c nylsf/pcm.c -o nylsf/pcm.o $(CFLAGS) + +nylsf/pvf.o: nylsf/pvf.c + $(CC) -c nylsf/pvf.c -o nylsf/pvf.o $(CFLAGS) + +nylsf/raw.o: nylsf/raw.c + $(CC) -c nylsf/raw.c -o nylsf/raw.o $(CFLAGS) + +nylsf/rf64.o: nylsf/rf64.c + $(CC) -c nylsf/rf64.c -o nylsf/rf64.o $(CFLAGS) + +nylsf/rx2.o: nylsf/rx2.c + $(CC) -c nylsf/rx2.c -o nylsf/rx2.o $(CFLAGS) + +nylsf/sd2.o: nylsf/sd2.c + $(CC) -c nylsf/sd2.c -o nylsf/sd2.o $(CFLAGS) + +nylsf/sds.o: nylsf/sds.c + $(CC) -c nylsf/sds.c -o nylsf/sds.o $(CFLAGS) + +nylsf/sndfile.o: nylsf/sndfile.c + $(CC) -c nylsf/sndfile.c -o nylsf/sndfile.o $(CFLAGS) + +nylsf/strings.o: nylsf/strings.c + $(CC) -c nylsf/strings.c -o nylsf/strings.o $(CFLAGS) + +nylsf/svx.o: nylsf/svx.c + $(CC) -c nylsf/svx.c -o nylsf/svx.o $(CFLAGS) + +nylsf/txw.o: nylsf/txw.c + $(CC) -c nylsf/txw.c -o nylsf/txw.o $(CFLAGS) + +nylsf/ulaw.o: nylsf/ulaw.c + $(CC) -c nylsf/ulaw.c -o nylsf/ulaw.o $(CFLAGS) + +nylsf/voc.o: nylsf/voc.c + $(CC) -c nylsf/voc.c -o nylsf/voc.o $(CFLAGS) + +nylsf/vox_adpcm.o: nylsf/vox_adpcm.c + $(CC) -c nylsf/vox_adpcm.c -o nylsf/vox_adpcm.o $(CFLAGS) + +nylsf/w64.o: nylsf/w64.c + $(CC) -c nylsf/w64.c -o nylsf/w64.o $(CFLAGS) + +nylsf/wav.o: nylsf/wav.c + $(CC) -c nylsf/wav.c -o nylsf/wav.o $(CFLAGS) + +nylsf/wav_w64.o: nylsf/wav_w64.c + $(CC) -c nylsf/wav_w64.c -o nylsf/wav_w64.o $(CFLAGS) + +nylsf/wve.o: nylsf/wve.c + $(CC) -c nylsf/wve.c -o nylsf/wve.o $(CFLAGS) + +nylsf/xi.o: nylsf/xi.c + $(CC) -c nylsf/xi.c -o nylsf/xi.o $(CFLAGS) + +nylsf/g72x.o: nylsf/g72x.c + $(CC) -c nylsf/g72x.c -o nylsf/g72x.o $(CFLAGS) + +nylsf/GSM610/add.o: nylsf/GSM610/add.c + $(CC) -c nylsf/GSM610/add.c -o nylsf/GSM610/add.o $(CFLAGS) + +nylsf/GSM610/code.o: nylsf/GSM610/code.c + $(CC) -c nylsf/GSM610/code.c -o nylsf/GSM610/code.o $(CFLAGS) + +nylsf/GSM610/decode.o: nylsf/GSM610/decode.c + $(CC) -c nylsf/GSM610/decode.c -o nylsf/GSM610/decode.o $(CFLAGS) + +nylsf/GSM610/gsm_create.o: nylsf/GSM610/gsm_create.c + $(CC) -c nylsf/GSM610/gsm_create.c -o nylsf/GSM610/gsm_create.o $(CFLAGS) + +nylsf/GSM610/gsm_decode.o: nylsf/GSM610/gsm_decode.c + $(CC) -c nylsf/GSM610/gsm_decode.c -o nylsf/GSM610/gsm_decode.o $(CFLAGS) + +nylsf/GSM610/gsm_destroy.o: nylsf/GSM610/gsm_destroy.c + $(CC) -c nylsf/GSM610/gsm_destroy.c -o nylsf/GSM610/gsm_destroy.o $(CFLAGS) + +nylsf/GSM610/gsm_encode.o: nylsf/GSM610/gsm_encode.c + $(CC) -c nylsf/GSM610/gsm_encode.c -o nylsf/GSM610/gsm_encode.o $(CFLAGS) + +nylsf/GSM610/gsm_option.o: nylsf/GSM610/gsm_option.c + $(CC) -c nylsf/GSM610/gsm_option.c -o nylsf/GSM610/gsm_option.o $(CFLAGS) + +nylsf/GSM610/long_term.o: nylsf/GSM610/long_term.c + $(CC) -c nylsf/GSM610/long_term.c -o nylsf/GSM610/long_term.o $(CFLAGS) + +nylsf/GSM610/lpc.o: nylsf/GSM610/lpc.c + $(CC) -c nylsf/GSM610/lpc.c -o nylsf/GSM610/lpc.o $(CFLAGS) + +nylsf/GSM610/preprocess.o: nylsf/GSM610/preprocess.c + $(CC) -c nylsf/GSM610/preprocess.c -o nylsf/GSM610/preprocess.o $(CFLAGS) + +nylsf/GSM610/rpe.o: nylsf/GSM610/rpe.c + $(CC) -c nylsf/GSM610/rpe.c -o nylsf/GSM610/rpe.o $(CFLAGS) + +nylsf/GSM610/short_term.o: nylsf/GSM610/short_term.c + $(CC) -c nylsf/GSM610/short_term.c -o nylsf/GSM610/short_term.o $(CFLAGS) + +nylsf/GSM610/table.o: nylsf/GSM610/table.c + $(CC) -c nylsf/GSM610/table.c -o nylsf/GSM610/table.o $(CFLAGS) + +nylsf/G72x/g721.o: nylsf/G72x/g721.c + $(CC) -c nylsf/G72x/g721.c -o nylsf/G72x/g721.o $(CFLAGS) + +nylsf/G72x/g723_16.o: nylsf/G72x/g723_16.c + $(CC) -c nylsf/G72x/g723_16.c -o nylsf/G72x/g723_16.o $(CFLAGS) + +nylsf/G72x/g723_24.o: nylsf/G72x/g723_24.c + $(CC) -c nylsf/G72x/g723_24.c -o nylsf/G72x/g723_24.o $(CFLAGS) + +nylsf/G72x/g723_40.o: nylsf/G72x/g723_40.c + $(CC) -c nylsf/G72x/g723_40.c -o nylsf/G72x/g723_40.o $(CFLAGS) + +nylsf/G72x/g72x.o: nylsf/G72x/g72x.c + $(CC) -c nylsf/G72x/g72x.c -o nylsf/G72x/g72x.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + $(CC) -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +nyqsrc/sndfnintptrs.h: $(SNDFNINT_HDRS) misc/intgen Makefile + $(INTGEN) nyqsrc/sndfnint $(SNDFNINT_HDRS) + +nyqsrc/seqfnintptrs.h: $(SEQFNINT_HDRS) misc/intgen Makefile + $(INTGEN) nyqsrc/seqfnint $(SEQFNINT_HDRS) + +clean: + cd misc; make clean + cd liblo; test -f Makefile && make clean || true + cd portaudio; test -f Makefile && make clean || true + rm -f $(OBJECTS) +# These could be deleted, but they're part of the release, so we won't +# Note that these files are machine-generated: +# rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h +# rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f #*# */#*# + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat + rm -f core.* core + rm -f $(NY) diff --git a/lib-src/libnyquist/nyquist/sys/unix/alsa/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/alsa/system.lsp new file mode 100644 index 000000000..3923bc821 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/alsa/system.lsp @@ -0,0 +1,101 @@ +;; system.lsp -- system-dependent lisp code + +; local definition for play +; this one is for Linux: + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-wave)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "./")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* (strcat (get-user) "-points.dat"))) + + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (or (eq (char filename 0) #\/) + (eq (char filename 0) #\.))) + +; RELATIVE-PATH-P -- test if filename or path is a relative path +; +(defun relative-path-p (filename) + (not (eq (char filename 0) #\/))) + +(setf *file-separator* #\/) + + +;; PLAY-FILE - play a sound file +;; +(defun play-file (name) +;; +;; WARNING: if you invoke an external program to play files, +;; but Nyquist uses internal (portaudio) interface to +;; play synthesized sound, Nyquist may fail to open the +;; sound device while it is playing a sound file and then +;; refuse to play anything. -RBD dec05 +;; (system (strcat "sndplay " (soundfilename name)))) +;; (system (strcat "play " (soundfilename name) ))) +;; + (play (s-read (soundfilename name)))) + +;; R - replay last file written with PLAY +(defun r () (play-file *default-sound-file*)) + +;;;; use this old version if you want to use sndplay to play +;;;; the result file rather than play the samples as they +;;;; are computed. This version does not autonormalize. +;; PLAY - write value of an expression to file and play it +;; +;(defmacro play (expr) +; `(prog (specs) +; (setf specs (s-save (force-srate *sound-srate* ,expr) +; 1000000000 *default-sound-file*)) +; (r))) +;;;; + +; local definition for play +(defmacro play (expr) + `(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*)) + +;; for Linux, modify s-plot (defined in nyquist.lsp) by saving s-plot +;; in standard-s-plot, then call gnuplot to display the points. +;; +;; we also need to save the location of this file so we can find +;; nyquist-plot.txt, the command file for gnuplot +;; +;; This code is broken in the following ways: +;; it tries to run gnuplot even when plotting can be done by NyquistIDE +;; it plots "points.dat", but "points.dat" may not be correct +;; (see *default-plot-file*) +;; it assumes the plot file is in the current directory, but it +;; by default goes to the sound file directory +;; +;; Fix this code or complain if you want to plot with gnuplot while +;; running ny (or even NyquistIDE (jny) if you want). Otherwise, use +;; NyquistIDE to get s-plot to work. +;; +;(setf *runtime-path* (current-path)) +;(display "system.lsp" *runtime-path*) +; +;(setfn standard-s-plot s-plot) +; +;(defun s-plot (s &optional (dur 2.0) (n 1000)) +; (let (plot-file) +; (standard-s-plot s dur n) ;; this calculates the data points +; (setf plot-file (strcat *runtime-path* "nyquist-plot.txt")) +; (system (strcat "gnuplot -persist " plot-file)))) + diff --git a/lib-src/libnyquist/nyquist/sys/unix/cmu/backup.script b/lib-src/libnyquist/nyquist/sys/unix/cmu/backup.script new file mode 100644 index 000000000..f00c59a99 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/cmu/backup.script @@ -0,0 +1 @@ +cp -Rp ../current/* /afs/cs/project/music/proj/nyquist/current diff --git a/lib-src/libnyquist/nyquist/sys/unix/cmu/tar.script b/lib-src/libnyquist/nyquist/sys/unix/cmu/tar.script new file mode 100644 index 000000000..12b23f628 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/cmu/tar.script @@ -0,0 +1,14 @@ +mkdir ../TMP +mv ny ../TMP +mv runtime/system.lsp ../TMP +mv Makefile ../TMP +mv test ../TMP +set NYQDIR=`pwd` +cd .. +ln -fs $NYQDIR nyquist +tar -cvhf - nyquist | compress > nyquist.tar.Z +cd $NYQDIR +mv ../TMP/test . +mv ../TMP/Makefile . +mv ../TMP/system.lsp runtime +mv ../TMP/ny . diff --git a/lib-src/libnyquist/nyquist/sys/unix/cmu/update.lsp b/lib-src/libnyquist/nyquist/sys/unix/cmu/update.lsp new file mode 100644 index 000000000..71743a201 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/cmu/update.lsp @@ -0,0 +1,79 @@ +;; update.lsp -- script to push changes into source directories + +(load "makefile.lsp") ; just to make sure we got the latest bindings + + +;; UPDATE-SOURCES -- makes a script to push changes into source directories +;; +(defun update-sources () + (let (outf) + (load "transfiles.lsp") ; just to make sure we're current + (setf outf (open "script" :direction :output)) + (format outf "# +# source this script file + +# Source Paths: nyqsrc, cmtsrc, xlsrc, trnsrc +") + (format outf " +# +# XLISP SOURCES +# +") + (file-update outf xlfiles ".c" "xlsrc") + (file-update outf xlfiles-h ".h" "xlsrc") + (file-update outf xlfiles-lsp ".lsp" "xlsrc") + + (format outf " +# +# NYQUIST SOURCES +# +") + (file-update outf nyqfiles ".c" "nyqsrc") + (file-update outf (exceptions-filter nyqfiles) ".h" "nyqsrc") + (file-update outf nyqfiles-h ".h" "nyqsrc") + (file-update outf nyqfiles-lsp ".lsp" "nyqsrc") + (file-update outf makefiles "" "nyqsrc") + + (format outf " +# +# CMT SOURCES +# +") + (file-update outf cmtfiles ".c" "cmtsrc") + (file-update outf (exceptions-filter cmtfiles) ".h" "cmtsrc") + (file-update outf cmtfiles-h ".h" "cmtsrc") + +; don't write back machine generated trnsrc files +; (file-update outf transfiles ".c" "trnsrc") +; (file-update outf transfiles ".h" "trnsrc") + + (close outf) + + (format t "DONE writing script, 'source script' to copy files from~%") + (format t "this directory to the source directories~%") + +)) + + +;; EXCEPTIONS-FILTER - remove .h files from list +; the depends-exceptions tells whether a .h file exists for a .c file +;; +(defun exceptions-filter (files) + (let (result) + (dolist (f files) + (let ((ex (assoc f depends-exceptions :test #'equal))) + (cond (ex + (if (and (cdr ex) + (string-search (strcat f ".h") (cadr ex))) + (push f result))) + (t (push f result))))) + result)) + + +;; FILE-UPDATE -- write dependency for source files +;; +(defun file-update (outf files ext dir) + (dolist (f files) + (let ((fname (strcat f ext))) + (format outf "cp -p ~A ~A/~A~%" fname dir fname)))) + diff --git a/lib-src/libnyquist/nyquist/sys/unix/io.c b/lib-src/libnyquist/nyquist/sys/unix/io.c new file mode 100644 index 000000000..21b2abed8 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/io.c @@ -0,0 +1,162 @@ +/* + ********************************************************************** + * File io.c + ********************************************************************** + * + * Non blocking input routine + * Works by puttng the terminal in CBREAK mode and using the FIONREAD + * ioctl call to determine the number of characters in the input queue + */ + +#include "stdio.h" +#include "io.h" +#include +#include +#include +#include +#include "cext.h" + +int IOinputfd; /* input file descriptor (usually 0) */ + +int IOnochar; /* Value to be returned by IOgetchar() + where there is no input to be had */ + +static struct sgttyb IOoldmodes, IOcurrentmodes; + /* Initial and current tty modes */ + +/* + * IOsetup(inputfd) + * Args: + * inputfd - input file descriptor (should be zero for standard input) + * Returns: + * 0 - if all goes well + * -1 - if an ioctl fails (also calls perror) + * Side Effects: + * Puts the terminal in CBREAK mode - before process termination + * IOcleanup() should be called to restore old terminal modes + * Catch's interrupts (if they are not already being caught) and + * calls IOcleanup before exiting + * + */ + +#define ERROR(s) return (perror(s), -1) + +IOsetup(inputfd) +{ + static IOdiegracefully(); + int (*interrupt_handler)(); + + IOinputfd = inputfd; + IOnochar = NOCHAR; + + if(ioctl(IOinputfd, TIOCGETP, &IOoldmodes) < 0) + ERROR("IOsetup"); + + IOcurrentmodes = IOoldmodes; + IOcurrentmodes.sg_flags |= CBREAK; + IOcurrentmodes.sg_flags &= ~ECHO; + if(ioctl(IOinputfd, TIOCSETP, &IOcurrentmodes)) + ERROR("IOsetup-2"); + + if( (interrupt_handler = signal(SIGINT, IOdiegracefully)) != 0) + signal(SIGINT, interrupt_handler); + + return 0; +} + +static +IOdiegracefully() +{ + write(2, "\nBye\n", 5); + IOcleanup(); + EXIT(2); +} + +/* + * IOcleanup() + * Returns: + * 0 - if all goes well + * -1 - if an ioctl fails (also calls perror) + * Side Effects: + * Restores initial terminal modes + */ + +IOcleanup() +{ + if(ioctl(IOinputfd, TIOCSETP, &IOoldmodes) < 0) + ERROR("IOclean"); + + return 0; +} + + +/* + * IOgetchar() + * Returns: + * A character off the input queue if there is one, + * IOnochar if there is no character waiting to be read, + * -1 if an ioctl fails (shouldn't happen if IOsetup went OK) + */ + +#ifndef UNIX_MACH + +IOgetchar() +{ + int n; + char c; + + if(ioctl(IOinputfd, FIONREAD, &n) < 0) + ERROR("IOgetchar"); + if(n <= 0) + return IOnochar; + switch(read(IOinputfd, &c, 1)) { + case 1: + return c; + case 0: + return EOF; + default: + ERROR("IOgetchar-read"); + } +} + +IOgetchar2() +{ + int nfds, readfds = 1 << IOinputfd; + char c; + static struct timeval zero; + + if(IOinputfd < 0 || IOinputfd >= 32) { + printf("IOgetchar2: bad IOinputfd (%d)%s\n", IOinputfd, + IOinputfd == -1 ? "Did you call IOsetup(fd)?" : ""); + } + nfds = select(32, &readfds, 0, 0, &zero); + if(nfds > 0) { + switch(read(IOinputfd, &c, 1)) { + case 0: + return EOF; + case 1: + return c; + default: + printf("IOgetchar2: read failed!\n"); + return NOCHAR; + } + } + else if(nfds < 0) + printf("IOgetchar2: select failed!\n"); + return NOCHAR; +} + +/* + * IOwaitchar() + * Returns: + * A character off the input queue. Waits if necessary. + */ + +int IOwaitchar() +{ + char c; + if (read(IOinputfd, &c, 1) == 1) return c; + else return EOF; +} + +#endif /* UNIX_MACH */ diff --git a/lib-src/libnyquist/nyquist/sys/unix/io.h b/lib-src/libnyquist/nyquist/sys/unix/io.h new file mode 100644 index 000000000..3e50ad957 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/io.h @@ -0,0 +1,9 @@ +#define NOCHAR -2 + +int IOinputfd; +int IOnochar; + +int IOsetup(int inputfd); +int IOcleanup(void); +int IOgetchar(void); +int IOwaitchar(void); diff --git a/lib-src/libnyquist/nyquist/sys/unix/next/Makefile b/lib-src/libnyquist/nyquist/sys/unix/next/Makefile new file mode 100644 index 000000000..10817d1d7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/next/Makefile @@ -0,0 +1,521 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is NEXT +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +# Standard list of includes (common to all unix versions) +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Isnd -Ifft + +# system dependent stuff for next: + +CC = cc +CFLAGS = -DCMTSTUFF -O $(INCL) +LN = cc +LFLAGS = -lm + + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o \ + xlisp/xlstr.o xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o \ + tran/amosc.o tran/clip.o tran/const.o tran/fmosc.o \ + tran/integrate.o tran/log.o tran/maxv.o tran/osc.o \ + tran/prod.o tran/buzz.o tran/pwl.o tran/recip.o \ + tran/upsample.o tran/scale.o tran/sine.o tran/partial.o \ + tran/white.o tran/tone.o tran/tonev.o tran/atonev.o \ + tran/atone.o tran/reson.o tran/areson.o tran/resonvc.o \ + tran/resoncv.o tran/aresonvc.o tran/aresoncv.o tran/resonvv.o \ + tran/aresonvv.o tran/offset.o tran/slope.o tran/delay.o \ + tran/delaycv.o tran/shape.o tran/sampler.o tran/exp.o \ + tran/siosc.o tran/follow.o tran/gate.o tran/quantize.o \ + tran/ifft.o tran/congen.o tran/fromobject.o tran/fromarraystream.o \ + tran/coterm.o tran/convolve.o tran/alpass.o tran/oneshot.o \ + tran/chase.o tran/tapv.o tran/biquad.o tran/pluck.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o \ + cmt/moxc.o cmt/mem.o cmt/midifile.o cmt/midifns.o \ + cmt/record.o cmt/seq.o cmt/seqmread.o cmt/seqmwrite.o \ + cmt/seqread.o cmt/seqwrite.o cmt/tempomap.o cmt/timebase.o \ + cmt/userio.o nyqsrc/debug.o nyqsrc/falloc.o nyqsrc/add.o \ + nyqsrc/local.o nyqsrc/downsample.o nyqsrc/handlers.o nyqsrc/multiread.o \ + nyqsrc/multiseq.o nyqsrc/samples.o nyqsrc/seqext.o nyqsrc/seqinterf.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndwrite.o nyqsrc/sndmax.o \ + nyqsrc/sound.o nyqsrc/stats.o nyqsrc/compose.o nyqsrc/inverse.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/ffilterkit.o nyqsrc/avg.o \ + nyqsrc/fft.o nyqsrc/sndfail.o fft/fftn.o nyqsrc/sndfnint.o \ + nyqsrc/seqfnint.o snd/audionext.o snd/sndnext.o snd/ieeecvt.o \ + snd/snd.o snd/sndcvt.o snd/sndio.o snd/sndheader.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +NYQHDRS = snd/snd.h nyqsrc/sound.h nyqsrc/downsample.h nyqsrc/sndread.h \ + nyqsrc/sndseq.h nyqsrc/add.h nyqsrc/multiseq.h nyqsrc/samples.h \ + nyqsrc/sndwrite.h nyqsrc/sndmax.h nyqsrc/compose.h nyqsrc/inverse.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/fft.h nyqsrc/avg.h \ + tran/amosc.h tran/clip.h tran/const.h tran/fmosc.h \ + tran/integrate.h tran/log.h tran/maxv.h tran/osc.h \ + tran/prod.h tran/buzz.h tran/pwl.h tran/recip.h \ + tran/upsample.h tran/scale.h tran/sine.h tran/partial.h \ + tran/white.h tran/tone.h tran/tonev.h tran/atonev.h \ + tran/atone.h tran/reson.h tran/areson.h tran/resonvc.h \ + tran/resoncv.h tran/aresonvc.h tran/aresoncv.h tran/resonvv.h \ + tran/aresonvv.h tran/offset.h tran/slope.h tran/delaycc.h \ + tran/delaycv.h tran/shape.h tran/sampler.h tran/exp.h \ + tran/siosc.h tran/follow.h tran/gate.h tran/quantize.h \ + tran/ifft.h tran/congen.h tran/fromobject.h tran/fromarraystream.h \ + tran/coterm.h tran/convolve.h tran/alpass.h tran/oneshot.h \ + tran/chase.h tran/tapv.h tran/biquad.h tran/pluck.h + +CMTHDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h nyqsrc/seqinterf.h \ + cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h cmt/seqmwrite.h + + +EVERYTHING = $(NY) runtime/system.lsp + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +$(NY): $(OBJECTS) + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/next/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/next/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + cc -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + cc -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndwrite.o: nyqsrc/sndwrite.c nyqsrc/sndwrite.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndwrite.c -o nyqsrc/sndwrite.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/sndfail.o: nyqsrc/sndfail.c + cc -c nyqsrc/sndfail.c -o nyqsrc/sndfail.o $(CFLAGS) + +snd/audionext.o: snd/audionext.c snd/snd.h + cc -c snd/audionext.c -o snd/audionext.o $(CFLAGS) + +snd/sndnext.o: snd/sndnext.c snd/sndnext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndnext.c -o snd/sndnext.o $(CFLAGS) + +snd/ieeecvt.o: snd/ieeecvt.c snd/ieeecvt.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/ieeecvt.c -o snd/ieeecvt.o $(CFLAGS) + +snd/snd.o: snd/snd.c snd/snd.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/snd.c -o snd/snd.o $(CFLAGS) + +snd/sndcvt.o: snd/sndcvt.c snd/snd.h + cc -c snd/sndcvt.c -o snd/sndcvt.o $(CFLAGS) + +snd/sndio.o: snd/sndio.c snd/snd.h + cc -c snd/sndio.c -o snd/sndio.o $(CFLAGS) + +snd/sndheader.o: snd/sndheader.c snd/sndheader.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndheader.c -o snd/sndheader.o $(CFLAGS) + +fft/fftn.o: fft/fftn.c fft/fftn.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c fft/fftn.c -o fft/fftn.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/convolve.o: tran/convolve.c tran/convolve.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/convolve.c -o tran/convolve.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/biquad.o: tran/biquad.c tran/biquad.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/biquad.c -o tran/biquad.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + cc -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + cc -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + cc -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + cc -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + cc -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + cc -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + cc -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + cc -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + cc -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + cc -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + cc -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + cc -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + cc -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + cc -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + cc -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + cc -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + cc -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + cc -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + cc -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + cc -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + cc -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + cc -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + cc -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + cc -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + cc -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + cc -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + cc -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + cc -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + cc -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + cc -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + cc -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + cc -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + cc -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + cc -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + cc -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + cc -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + cc -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + cc -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + cc -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + cc -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + cc -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + cc -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + cc -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + + +# this doesn't compile with the -O switch (a NeXT compiler bug?) +xlisp/xljump.o : xlisp/xljump.c xlisp/xlisp.h + $(CC) -DCMTSTUFF -c xlisp/xljump.c -o xlisp/xljump.o +misc/intgen: misc/intgen.c + cd misc; make intgen + +misc/unpacker: misc/unpacker.c misc/convert.c + cd misc; make unpacker + +misc/packer: misc/packer.c misc/convert.c + cd misc; make packer + +nyqsrc/sndfnintptrs.h: $(NYQHDRS) snd/snd.h misc/intgen + $(INTGEN) nyqsrc/sndfnint $(NYQHDRS) + +nyqsrc/seqfnintptrs.h: $(CMTHDRS) misc/intgen + $(INTGEN) nyqsrc/seqfnint $(CMTHDRS) + +clean: + cd misc; make clean + rm -f $(OBJECTS) +# Note that these files are machine-generated: + rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h + rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat diff --git a/lib-src/libnyquist/nyquist/sys/unix/next/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/next/system.lsp new file mode 100644 index 000000000..42e247195 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/next/system.lsp @@ -0,0 +1,37 @@ +; local definition for play +; this one is for NeXT: + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-NeXT)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "./")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-head-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* "points.dat")) + +;; PLAY-FILE - play a sound file +;; +(defun play-file (name) + (system (strcat "sndplay " (soundfilename name)))) + +;; R - replay last file written with PLAY +(defun r () (play-file *default-sound-file*)) + +;; PLAY - write value of an expression to file and play it +;; +(defmacro play (expr) + `(prog (specs) + (setf specs (s-save (force-srate *sound-srate* ,expr) + 1000000000 *default-sound-file*)) + (r))) + diff --git a/lib-src/libnyquist/nyquist/sys/unix/nonalsa/Makefile b/lib-src/libnyquist/nyquist/sys/unix/nonalsa/Makefile new file mode 100644 index 000000000..2b3159b2c --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/nonalsa/Makefile @@ -0,0 +1,1140 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is NONALSA +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +OPT = -O2 -m32 +# OPT = -g -m32 + +EVERYTHING = $(NY) runtime/system.lsp jnyqide/jNyqIDE.jar \ + bin/ser-to-osc bin/test-client + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +onlyny: $(NY) runtime/system.lsp + +JAVASRC = jnyqide/browser.java jnyqide/NyquistThread.java \ + jnyqide/Pair.java jnyqide/BareBonesBrowserLaunch.java \ + jnyqide/EnvelopeFrame.java jnyqide/Piano_Roll.java \ + jnyqide/FindDialog.java jnyqide/PlotFrame.java \ + jnyqide/InstrumentCharacteristics.java jnyqide/PlotMouseAdapter.java \ + jnyqide/Jslide.java jnyqide/PopupListener.java \ + jnyqide/LispFileFilter.java jnyqide/PreferencesDialog.java \ + jnyqide/MainFrame_AboutBox.java jnyqide/ReplaceDialog.java \ + jnyqide/MainFrame.java jnyqide/SpringUtilities.java jnyqide/Main.java \ + jnyqide/NotFoundDialog.java jnyqide/TextColor.java jnyqide/NyqPlot.java \ + jnyqide/Trie.java jnyqide/NyquistFile.java jnyqide/WordList.java + +jnyqide/jNyqIDE.jar: $(JAVASRC) + if [ -r jnyqide/SpecialMacHandler.java ] ; then \ + mv jnyqide/SpecialMacHandler.java jnyqide/SpecialMacHandler.hidden ;\ + fi + cd jnyqide; javac *.java + mv jnyqide/SpecialMacHandler.hidden jnyqide/SpecialMacHandler.java + rm -rf jnyqide/jNyqIDE.jar + jar -cfm jnyqide/jNyqIDE.jar jnyqide/manifest.txt jnyqide/*.class + +# Standard list of includes (common to all unix versions) +# Keeping portaudio and libsndfile sources local to nyquist +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Iffts/src \ + -Inyqstk/include -Inyqstk -Iportaudio/include -Iportaudio/src/common \ + -Iportaudio/src/os/unix \ + -Iliblo -Inylsf -IFLAC/include -Ilibogg/include + +# system dependent stuff for nonalsa: + +AUDIOLIBS = + +CC = gcc + +LIBPA_PATH = portaudio/lib/.libs +LIBOGG_PATH = libogg/src/.libs +LIBVORBIS_PATH = libvorbis/lib/.libs +LIBLO_PATH = liblo/src/.libs +LIBFLAC_PATH = FLAC/obj/release/lib + +# to enable command line editing, use -DREADLINE. WARNING: THIS WILL +# DISABLE THE ABILITY TO INTERRUPT LISP AND USE SOME OTHER HANDY +# CONTROL CHARACTERS (You will also need the readline and curses libraries) +CFLAGS = -DOSC -DCMTSTUFF $(OPT) $(INCL) \ + -DHAVE_LIBPTHREAD=1 -D_FILE_OFFSET_BITS=64 \ + -DSTK_NYQUIST -DUSE_VSPRINTF \ + -DHAVE_CONFIG_H +LN = g++ -m32 +AR = ar +# to enable command line editing, insert -lreadline -lcurses +LFLAGS = -L/usr/lib32 $(LIBPA_PATH)/libportaudio.a \ + $(LIBLO_PATH)/liblo.a $(AUDIOLIBS) $(LIBFLAC_PATH)/libFLAC.a \ + $(LIBVORBIS_PATH)/libvorbis.a \ + $(LIBVORBIS_PATH)/libvorbisfile.a \ + $(LIBVORBIS_PATH)/libvorbisenc.a $(LIBOGG_PATH)/libogg.a \ + -lm -lpthread -lrt + +TAGS: + find . ( -name "*.c" -o -name "*.h" ) -print | etags - + +tags: TAGS + +# end of system dependencies + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o xlisp/xlstr.o \ + xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o xlisp/path.o tran/abs.o \ + tran/allpoles.o tran/alpass.o tran/alpasscv.o tran/alpassvv.o \ + tran/amosc.o tran/areson.o tran/aresonvc.o tran/aresoncv.o \ + tran/aresonvv.o tran/atone.o tran/atonev.o tran/biquadfilt.o \ + tran/buzz.o tran/chase.o tran/clip.o tran/congen.o tran/const.o \ + tran/coterm.o tran/delaycc.o tran/delaycv.o tran/eqbandvvv.o tran/exp.o \ + tran/follow.o tran/fmosc.o tran/fromobject.o tran/fromarraystream.o \ + tran/gate.o tran/ifft.o tran/instrclar.o tran/instrclarall.o \ + tran/instrclarfreq.o tran/instrsax.o tran/instrsaxall.o \ + tran/instrsaxfreq.o tran/integrate.o tran/log.o tran/lpreson.o \ + tran/maxv.o tran/offset.o tran/oneshot.o tran/osc.o tran/partial.o \ + tran/pluck.o tran/prod.o tran/pwl.o tran/quantize.o tran/recip.o \ + tran/reson.o tran/resonvc.o tran/resoncv.o tran/resonvv.o \ + tran/sampler.o tran/scale.o tran/shape.o tran/sine.o tran/siosc.o \ + tran/slope.o tran/sqrt.o tran/tapf.o tran/tapv.o tran/tone.o \ + tran/tonev.o tran/upsample.o tran/white.o tran/stkrev.o \ + tran/stkpitshift.o tran/stkchorus.o tran/instrbow.o \ + tran/instrbowedfreq.o tran/instrbanded.o tran/instrmandolin.o \ + tran/instrsitar.o tran/instrmodalbar.o tran/instrflute.o \ + tran/instrflutefreq.o tran/instrfluteall.o tran/fmfb.o tran/fmfbv.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o cmt/moxc.o \ + cmt/mem.o cmt/midifile.o cmt/midifns.o cmt/record.o cmt/seq.o \ + cmt/seqmread.o cmt/seqmwrite.o cmt/seqread.o cmt/seqwrite.o \ + cmt/tempomap.o cmt/timebase.o cmt/userio.o nylsf/aiff.o nylsf/alaw.o \ + nylsf/au.o nylsf/audio_detect.o nylsf/avr.o nylsf/broadcast.o \ + nylsf/caf.o nylsf/chanmap.o nylsf/chunk.o nylsf/command.o \ + nylsf/common.o nylsf/dither.o nylsf/double64.o nylsf/dwd.o nylsf/dwvw.o \ + nylsf/file_io.o nylsf/flac.o nylsf/float32.o nylsf/gsm610.o nylsf/htk.o \ + nylsf/id3.o nylsf/ima_adpcm.o nylsf/ima_oki_adpcm.o nylsf/interleave.o \ + nylsf/ircam.o nylsf/macbinary3.o nylsf/macos.o nylsf/mat4.o \ + nylsf/mat5.o nylsf/mpc2k.o nylsf/ms_adpcm.o nylsf/nist.o nylsf/ogg.o \ + nylsf/ogg_vorbis.o nylsf/paf.o nylsf/pcm.o nylsf/pvf.o nylsf/raw.o \ + nylsf/rf64.o nylsf/rx2.o nylsf/sd2.o nylsf/sds.o nylsf/sndfile.o \ + nylsf/strings.o nylsf/svx.o nylsf/txw.o nylsf/ulaw.o nylsf/voc.o \ + nylsf/vox_adpcm.o nylsf/w64.o nylsf/wav.o nylsf/wav_w64.o nylsf/wve.o \ + nylsf/xi.o nylsf/g72x.o nylsf/GSM610/add.o nylsf/GSM610/code.o \ + nylsf/GSM610/decode.o nylsf/GSM610/gsm_create.o \ + nylsf/GSM610/gsm_decode.o nylsf/GSM610/gsm_destroy.o \ + nylsf/GSM610/gsm_encode.o nylsf/GSM610/gsm_option.o \ + nylsf/GSM610/long_term.o nylsf/GSM610/lpc.o nylsf/GSM610/preprocess.o \ + nylsf/GSM610/rpe.o nylsf/GSM610/short_term.o nylsf/GSM610/table.o \ + nylsf/G72x/g721.o nylsf/G72x/g723_16.o nylsf/G72x/g723_24.o \ + nylsf/G72x/g723_40.o nylsf/G72x/g72x.o nyqsrc/debug.o nyqsrc/falloc.o \ + nyqsrc/local.o nyqsrc/handlers.o nyqsrc/multiread.o nyqsrc/seqext.o \ + nyqsrc/seqinterf.o nyqsrc/stats.o nyqsrc/ffilterkit.o nyqsrc/sound.o \ + nyqsrc/add.o nyqsrc/avg.o nyqsrc/compose.o nyqsrc/convolve.o \ + nyqsrc/downsample.o nyqsrc/fft.o nyqsrc/inverse.o nyqsrc/multiseq.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/samples.o nyqsrc/sndmax.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndsliders.o \ + nyqsrc/sliderdata.o nyqsrc/sndwritepa.o nyqsrc/yin.o \ + nyqsrc/nyq-osc-server.o nyqsrc/trigger.o nyqsrc/lpanal.o \ + nyqsrc/phasevocoder.o nyqsrc/pvshell.o nyqstk/src/Generator.o \ + nyqstk/src/SineWave.o nyqstk/src/Function.o nyqstk/src/FileRead.o \ + nyqstk/src/FileWvIn.o nyqstk/src/Effect.o nyqstk/src/Clarinet.o \ + nyqstk/src/Delay.o nyqstk/src/DelayL.o nyqstk/src/Envelope.o \ + nyqstk/src/Filter.o nyqstk/src/Instrmnt.o nyqstk/src/Noise.o \ + nyqstk/src/OneZero.o nyqstk/src/ReedTable.o nyqstk/src/Saxofony.o \ + nyqstk/src/Stk.o nyqstk/src/WaveLoop.o nyqstk/src/WvIn.o \ + nyqstk/src/NRev.o nyqstk/src/JCRev.o nyqstk/src/PRCRev.o \ + nyqstk/src/PitShift.o nyqstk/src/Chorus.o nyqstk/src/Bowed.o \ + nyqstk/src/BowTable.o nyqstk/src/ADSR.o nyqstk/src/OnePole.o \ + nyqstk/src/BiQuad.o nyqstk/src/BandedWG.o nyqstk/src/DelayA.o \ + nyqstk/src/Mandolin.o nyqstk/src/PluckTwo.o nyqstk/src/Sitar.o \ + nyqstk/src/ModalBar.o nyqstk/src/Modal.o nyqstk/src/Flute.o \ + nyqstk/src/JetTable.o nyqstk/src/PoleZero.o nyqstk/stkinit.o \ + nyqstk/instr.o nyqstk/stkint.o ffts/src/fftext.o ffts/src/fftlib.o \ + ffts/src/matlib.o nyqsrc/sndfnint.o nyqsrc/seqfnint.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +SNDFNINT_HDRS = nyqsrc/sndfmt.h nylsf/sndfile.h nyqsrc/sound.h \ + nyqsrc/add.h nyqsrc/avg.h nyqsrc/compose.h nyqsrc/convolve.h \ + nyqsrc/downsample.h nyqsrc/fft.h nyqsrc/inverse.h nyqsrc/multiseq.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/samples.h nyqsrc/sndmax.h \ + nyqsrc/sndread.h nyqsrc/sndseq.h nyqsrc/sndsliders.h \ + nyqsrc/sliderdata.h nyqsrc/sndwritepa.h nyqsrc/yin.h \ + nyqsrc/nyq-osc-server.h nyqsrc/trigger.h nyqsrc/lpanal.h \ + nyqsrc/phasevocoder.h nyqsrc/pvshell.h tran/abs.h tran/allpoles.h \ + tran/alpass.h tran/alpasscv.h tran/alpassvv.h tran/amosc.h \ + tran/areson.h tran/aresonvc.h tran/aresoncv.h tran/aresonvv.h \ + tran/atone.h tran/atonev.h tran/biquadfilt.h tran/buzz.h tran/chase.h \ + tran/clip.h tran/congen.h tran/const.h tran/coterm.h tran/delaycc.h \ + tran/delaycv.h tran/eqbandvvv.h tran/exp.h tran/follow.h tran/fmosc.h \ + tran/fromobject.h tran/fromarraystream.h tran/gate.h tran/ifft.h \ + tran/instrclar.h tran/instrclarall.h tran/instrclarfreq.h \ + tran/instrsax.h tran/instrsaxall.h tran/instrsaxfreq.h tran/integrate.h \ + tran/log.h tran/lpreson.h tran/maxv.h tran/offset.h tran/oneshot.h \ + tran/osc.h tran/partial.h tran/pluck.h tran/prod.h tran/pwl.h \ + tran/quantize.h tran/recip.h tran/reson.h tran/resonvc.h tran/resoncv.h \ + tran/resonvv.h tran/sampler.h tran/scale.h tran/shape.h tran/sine.h \ + tran/siosc.h tran/slope.h tran/sqrt.h tran/tapf.h tran/tapv.h \ + tran/tone.h tran/tonev.h tran/upsample.h tran/white.h tran/stkrev.h \ + tran/stkpitshift.h tran/stkchorus.h tran/instrbow.h \ + tran/instrbowedfreq.h tran/instrbanded.h tran/instrmandolin.h \ + tran/instrsitar.h tran/instrmodalbar.h tran/instrflute.h \ + tran/instrflutefreq.h tran/instrfluteall.h tran/fmfb.h tran/fmfbv.h \ + nyqsrc/sndwrite.h + +SEQFNINT_HDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h \ + nyqsrc/seqinterf.h cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h \ + cmt/seqmwrite.h + + + +liblo/Makefile: + cd liblo; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + # sometimes, residual files cause problems + cd liblo; make clean + +$(LIBLO_PATH)/liblo.a: liblo/Makefile + cd liblo; make + +bin/ser-to-osc: $(LIBLO_PATH)/liblo.a + mkdir -p bin + $(CC) -c $(CFLAGS) liblo/ser-to-osc/ser-to-osc.cpp \ + -o liblo/ser-to-osc/ser-to-osc.o + $(LN) liblo/ser-to-osc/ser-to-osc.o -o bin/ser-to-osc $(LFLAGS) + +bin/test-client: $(LIBLO_PATH)/liblo.a + mkdir -p bin + $(CC) -c $(CFLAGS) liblo/test-client/test-client.c \ + -o liblo/test-client/test-client.o + $(LN) liblo/test-client/test-client.o -o bin/test-client $(LFLAGS) + +portaudio/Makefile: + # note: without-jack avoids 32/64-bit link error on Debian + cd portaudio; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared --without-jack --with-oss + # sometimes, residual files cause problems + cd portaudio; make clean + +$(LIBPA_PATH)/libportaudio.a: portaudio/Makefile + cd portaudio; make + +libogg/Makefile: + cd libogg; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + +$(LIBOGG_PATH)/libogg.a: libogg/Makefile + cd libogg; make + +# NOTE: libvorbis/configure on a 64-bit machine will expect to find +# libogg installed (even though we are not going to use the installed +# libogg library, and even though the installed libogg library will +# be for 64-bit architecture. This represents a bug in configure +# because it checks for a 64-bit library when it is building for +# a 32-bit architecture (we pass in CFLAGS=-m32). In spite of the +# bug, configure will build a Makefile that will build a 32-bit +# libvorbis library that we need. We will link it with other +# 32-bit code including 32-bit libogg.a + +libvorbis/Makefile: + cd libvorbis; ./configure CFLAGS=-m32 LDFLAGS=-m32 CXXFLAGS=-m32 --enable-static --disable-shared + +$(LIBVORBIS_PATH)/libvorbis.a: libvorbis/Makefile + cd libvorbis; make + +$(LIBVORBIS_PATH)/libvorbisfile.a: libvorbis/Makefile + cd libvorbis; make + +$(LIBVORBIS_PATH)/libvorbisenc.a: libvorbis/Makefile + cd libvorbis; make + + +$(LIBFLAC_PATH)/libFLAC.a: FLAC/src/libFLAC/Makefile.lite + cd FLAC/src/libFLAC; make -f Makefile.lite + +$(NY): $(OBJECTS) $(LIBPA_PATH)/libportaudio.a $(LIBLO_PATH)/liblo.a \ + FLAC/obj/release/lib/libFLAC.a \ + $(LIBVORBIS_PATH)/libvorbis.a $(LIBVORBIS_PATH)/libvorbisfile.a \ + $(LIBVORBIS_PATH)/libvorbisenc.a $(LIBOGG_PATH)/libogg.a + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/nonalsa/system.lsp +# make sure it's there before you make it writeable + touch runtime/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/nonalsa/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +NYQDEP = nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h $(NYQDEP) + $(CC) -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h $(NYQDEP) + $(CC) -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h $(NYQDEP) + $(CC) -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h $(NYQDEP) + $(CC) -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/convolve.o: nyqsrc/convolve.c nyqsrc/convolve.h $(NYQDEP) + $(CC) -c nyqsrc/convolve.c -o nyqsrc/convolve.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h $(NYQDEP) + $(CC) -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h $(NYQDEP) + $(CC) -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h $(NYQDEP) + $(CC) -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h $(NYQDEP) + $(CC) -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h $(NYQDEP) + $(CC) -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h $(NYQDEP) + $(CC) -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h $(NYQDEP) + $(CC) -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h $(NYQDEP) + $(CC) -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h $(NYQDEP) + $(CC) -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h $(NYQDEP) + $(CC) -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndsliders.o: nyqsrc/sndsliders.c nyqsrc/sndsliders.h $(NYQDEP) + $(CC) -c nyqsrc/sndsliders.c -o nyqsrc/sndsliders.o $(CFLAGS) + +nyqsrc/sliderdata.o: nyqsrc/sliderdata.c nyqsrc/sliderdata.h $(NYQDEP) + $(CC) -c nyqsrc/sliderdata.c -o nyqsrc/sliderdata.o $(CFLAGS) + +nyqsrc/sndwritepa.o: nyqsrc/sndwritepa.c nyqsrc/sndwrite.h + $(CC) -c nyqsrc/sndwritepa.c -o nyqsrc/sndwritepa.o $(CFLAGS) + +nyqsrc/yin.o: nyqsrc/yin.c nyqsrc/yin.h $(NYQDEP) + $(CC) -c nyqsrc/yin.c -o nyqsrc/yin.o $(CFLAGS) + +nyqsrc/nyq-osc-server.o: nyqsrc/nyq-osc-server.c nyqsrc/nyq-osc-server.h $(NYQDEP) + $(CC) -c nyqsrc/nyq-osc-server.c -o nyqsrc/nyq-osc-server.o $(CFLAGS) + +nyqsrc/trigger.o: nyqsrc/trigger.c nyqsrc/trigger.h $(NYQDEP) + $(CC) -c nyqsrc/trigger.c -o nyqsrc/trigger.o $(CFLAGS) + +nyqsrc/lpanal.o: nyqsrc/lpanal.c nyqsrc/lpanal.h $(NYQDEP) + $(CC) -c nyqsrc/lpanal.c -o nyqsrc/lpanal.o $(CFLAGS) + +nyqsrc/phasevocoder.o: nyqsrc/phasevocoder.c nyqsrc/phasevocoder.h $(NYQDEP) + $(CC) -c nyqsrc/phasevocoder.c -o nyqsrc/phasevocoder.o $(CFLAGS) + +nyqsrc/pvshell.o: nyqsrc/pvshell.c nyqsrc/pvshell.h $(NYQDEP) + $(CC) -c nyqsrc/pvshell.c -o nyqsrc/pvshell.o $(CFLAGS) + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h $(NYQDEP) + $(CC) -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h $(NYQDEP) + $(CC) -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + $(CC) -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + $(CC) -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h $(NYQDEP) + $(CC) -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h $(NYQDEP) + $(CC) -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h $(NYQDEP) + $(CC) -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + $(CC) -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h $(NYQDEP) + $(CC) -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +ffts/src/fftext.o: ffts/src/fftext.c ffts/src/fftext.h $(NYQDEP) + $(CC) -c ffts/src/fftext.c -o ffts/src/fftext.o $(CFLAGS) + +ffts/src/fftlib.o: ffts/src/fftlib.c ffts/src/fftlib.h $(NYQDEP) + $(CC) -c ffts/src/fftlib.c -o ffts/src/fftlib.o $(CFLAGS) + +ffts/src/matlib.o: ffts/src/matlib.c ffts/src/matlib.h $(NYQDEP) + $(CC) -c ffts/src/matlib.c -o ffts/src/matlib.o $(CFLAGS) + +tran/abs.o: tran/abs.c tran/abs.h $(NYQDEP) + $(CC) -c tran/abs.c -o tran/abs.o $(CFLAGS) + +tran/allpoles.o: tran/allpoles.c tran/allpoles.h $(NYQDEP) + $(CC) -c tran/allpoles.c -o tran/allpoles.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h $(NYQDEP) + $(CC) -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/alpasscv.o: tran/alpasscv.c tran/alpasscv.h $(NYQDEP) + $(CC) -c tran/alpasscv.c -o tran/alpasscv.o $(CFLAGS) + +tran/alpassvv.o: tran/alpassvv.c tran/alpassvv.h $(NYQDEP) + $(CC) -c tran/alpassvv.c -o tran/alpassvv.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h $(NYQDEP) + $(CC) -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h $(NYQDEP) + $(CC) -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h $(NYQDEP) + $(CC) -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h $(NYQDEP) + $(CC) -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h $(NYQDEP) + $(CC) -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h $(NYQDEP) + $(CC) -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h $(NYQDEP) + $(CC) -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/biquadfilt.o: tran/biquadfilt.c tran/biquadfilt.h $(NYQDEP) + $(CC) -c tran/biquadfilt.c -o tran/biquadfilt.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h $(NYQDEP) + $(CC) -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h $(NYQDEP) + $(CC) -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h $(NYQDEP) + $(CC) -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h $(NYQDEP) + $(CC) -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h $(NYQDEP) + $(CC) -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h $(NYQDEP) + $(CC) -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h $(NYQDEP) + $(CC) -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h $(NYQDEP) + $(CC) -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/eqbandvvv.o: tran/eqbandvvv.c tran/eqbandvvv.h $(NYQDEP) + $(CC) -c tran/eqbandvvv.c -o tran/eqbandvvv.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h $(NYQDEP) + $(CC) -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h $(NYQDEP) + $(CC) -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h $(NYQDEP) + $(CC) -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h $(NYQDEP) + $(CC) -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h $(NYQDEP) + $(CC) -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h $(NYQDEP) + $(CC) -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h $(NYQDEP) + $(CC) -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/instrclar.o: tran/instrclar.c tran/instrclar.h $(NYQDEP) + $(CC) -c tran/instrclar.c -o tran/instrclar.o $(CFLAGS) + +tran/instrclarall.o: tran/instrclarall.c tran/instrclarall.h $(NYQDEP) + $(CC) -c tran/instrclarall.c -o tran/instrclarall.o $(CFLAGS) + +tran/instrclarfreq.o: tran/instrclarfreq.c tran/instrclarfreq.h $(NYQDEP) + $(CC) -c tran/instrclarfreq.c -o tran/instrclarfreq.o $(CFLAGS) + +tran/instrsax.o: tran/instrsax.c tran/instrsax.h $(NYQDEP) + $(CC) -c tran/instrsax.c -o tran/instrsax.o $(CFLAGS) + +tran/instrsaxall.o: tran/instrsaxall.c tran/instrsaxall.h $(NYQDEP) + $(CC) -c tran/instrsaxall.c -o tran/instrsaxall.o $(CFLAGS) + +tran/instrsaxfreq.o: tran/instrsaxfreq.c tran/instrsaxfreq.h $(NYQDEP) + $(CC) -c tran/instrsaxfreq.c -o tran/instrsaxfreq.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h $(NYQDEP) + $(CC) -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h $(NYQDEP) + $(CC) -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/lpreson.o: tran/lpreson.c tran/lpreson.h $(NYQDEP) + $(CC) -c tran/lpreson.c -o tran/lpreson.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h $(NYQDEP) + $(CC) -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h $(NYQDEP) + $(CC) -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h $(NYQDEP) + $(CC) -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h $(NYQDEP) + $(CC) -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h $(NYQDEP) + $(CC) -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h $(NYQDEP) + $(CC) -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h $(NYQDEP) + $(CC) -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h $(NYQDEP) + $(CC) -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h $(NYQDEP) + $(CC) -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h $(NYQDEP) + $(CC) -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h $(NYQDEP) + $(CC) -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h $(NYQDEP) + $(CC) -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h $(NYQDEP) + $(CC) -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h $(NYQDEP) + $(CC) -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h $(NYQDEP) + $(CC) -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h $(NYQDEP) + $(CC) -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h $(NYQDEP) + $(CC) -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h $(NYQDEP) + $(CC) -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h $(NYQDEP) + $(CC) -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h $(NYQDEP) + $(CC) -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/sqrt.o: tran/sqrt.c tran/sqrt.h $(NYQDEP) + $(CC) -c tran/sqrt.c -o tran/sqrt.o $(CFLAGS) + +tran/tapf.o: tran/tapf.c tran/tapf.h $(NYQDEP) + $(CC) -c tran/tapf.c -o tran/tapf.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h $(NYQDEP) + $(CC) -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h $(NYQDEP) + $(CC) -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h $(NYQDEP) + $(CC) -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h $(NYQDEP) + $(CC) -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h $(NYQDEP) + $(CC) -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/stkrev.o: tran/stkrev.c tran/stkrev.h $(NYQDEP) + $(CC) -c tran/stkrev.c -o tran/stkrev.o $(CFLAGS) + +tran/stkpitshift.o: tran/stkpitshift.c tran/stkpitshift.h $(NYQDEP) + $(CC) -c tran/stkpitshift.c -o tran/stkpitshift.o $(CFLAGS) + +tran/stkchorus.o: tran/stkchorus.c tran/stkchorus.h $(NYQDEP) + $(CC) -c tran/stkchorus.c -o tran/stkchorus.o $(CFLAGS) + +tran/instrbow.o: tran/instrbow.c tran/instrbow.h $(NYQDEP) + $(CC) -c tran/instrbow.c -o tran/instrbow.o $(CFLAGS) + +tran/instrbowedfreq.o: tran/instrbowedfreq.c tran/instrbowedfreq.h $(NYQDEP) + $(CC) -c tran/instrbowedfreq.c -o tran/instrbowedfreq.o $(CFLAGS) + +tran/instrbanded.o: tran/instrbanded.c tran/instrbanded.h $(NYQDEP) + $(CC) -c tran/instrbanded.c -o tran/instrbanded.o $(CFLAGS) + +tran/instrmandolin.o: tran/instrmandolin.c tran/instrmandolin.h $(NYQDEP) + $(CC) -c tran/instrmandolin.c -o tran/instrmandolin.o $(CFLAGS) + +tran/instrsitar.o: tran/instrsitar.c tran/instrsitar.h $(NYQDEP) + $(CC) -c tran/instrsitar.c -o tran/instrsitar.o $(CFLAGS) + +tran/instrmodalbar.o: tran/instrmodalbar.c tran/instrmodalbar.h $(NYQDEP) + $(CC) -c tran/instrmodalbar.c -o tran/instrmodalbar.o $(CFLAGS) + +tran/instrflute.o: tran/instrflute.c tran/instrflute.h $(NYQDEP) + $(CC) -c tran/instrflute.c -o tran/instrflute.o $(CFLAGS) + +tran/instrflutefreq.o: tran/instrflutefreq.c tran/instrflutefreq.h $(NYQDEP) + $(CC) -c tran/instrflutefreq.c -o tran/instrflutefreq.o $(CFLAGS) + +tran/instrfluteall.o: tran/instrfluteall.c tran/instrfluteall.h $(NYQDEP) + $(CC) -c tran/instrfluteall.c -o tran/instrfluteall.o $(CFLAGS) + +tran/fmfb.o: tran/fmfb.c tran/fmfb.h $(NYQDEP) + $(CC) -c tran/fmfb.c -o tran/fmfb.o $(CFLAGS) + +tran/fmfbv.o: tran/fmfbv.c tran/fmfbv.h $(NYQDEP) + $(CC) -c tran/fmfbv.c -o tran/fmfbv.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + $(CC) -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + $(CC) -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +nyqstk/stkinit.o: nyqstk/stkinit.cpp nyqstk/stkinit.h + g++ -c nyqstk/stkinit.cpp -o nyqstk/stkinit.o $(CFLAGS) + +nyqstk/instr.o: nyqstk/instr.cpp nyqstk/instr.h + g++ -c nyqstk/instr.cpp -o nyqstk/instr.o $(CFLAGS) + +nyqstk/stkint.o: nyqstk/stkint.cpp nyqstk/stkint.h + g++ -c nyqstk/stkint.cpp -o nyqstk/stkint.o $(CFLAGS) + +nyqstk/src/Generator.o: nyqstk/src/Generator.cpp nyqstk/include/Generator.h + g++ -c nyqstk/src/Generator.cpp -o nyqstk/src/Generator.o $(CFLAGS) + +nyqstk/src/SineWave.o: nyqstk/src/SineWave.cpp nyqstk/include/SineWave.h + g++ -c nyqstk/src/SineWave.cpp -o nyqstk/src/SineWave.o $(CFLAGS) + +nyqstk/src/Function.o: nyqstk/src/Function.cpp nyqstk/include/Function.h + g++ -c nyqstk/src/Function.cpp -o nyqstk/src/Function.o $(CFLAGS) + +nyqstk/src/FileRead.o: nyqstk/src/FileRead.cpp nyqstk/include/FileRead.h + g++ -c nyqstk/src/FileRead.cpp -o nyqstk/src/FileRead.o $(CFLAGS) + +nyqstk/src/FileWvIn.o: nyqstk/src/FileWvIn.cpp nyqstk/include/FileWvIn.h + g++ -c nyqstk/src/FileWvIn.cpp -o nyqstk/src/FileWvIn.o $(CFLAGS) + +nyqstk/src/Effect.o: nyqstk/src/Effect.cpp nyqstk/include/Effect.h + g++ -c nyqstk/src/Effect.cpp -o nyqstk/src/Effect.o $(CFLAGS) + +nyqstk/src/Clarinet.o: nyqstk/src/Clarinet.cpp nyqstk/include/Clarinet.h + g++ -c nyqstk/src/Clarinet.cpp -o nyqstk/src/Clarinet.o $(CFLAGS) + +nyqstk/src/Delay.o: nyqstk/src/Delay.cpp nyqstk/include/Delay.h + g++ -c nyqstk/src/Delay.cpp -o nyqstk/src/Delay.o $(CFLAGS) + +nyqstk/src/DelayL.o: nyqstk/src/DelayL.cpp nyqstk/include/DelayL.h + g++ -c nyqstk/src/DelayL.cpp -o nyqstk/src/DelayL.o $(CFLAGS) + +nyqstk/src/Envelope.o: nyqstk/src/Envelope.cpp nyqstk/include/Envelope.h + g++ -c nyqstk/src/Envelope.cpp -o nyqstk/src/Envelope.o $(CFLAGS) + +nyqstk/src/Filter.o: nyqstk/src/Filter.cpp nyqstk/include/Filter.h + g++ -c nyqstk/src/Filter.cpp -o nyqstk/src/Filter.o $(CFLAGS) + +nyqstk/src/Instrmnt.o: nyqstk/src/Instrmnt.cpp nyqstk/include/Instrmnt.h + g++ -c nyqstk/src/Instrmnt.cpp -o nyqstk/src/Instrmnt.o $(CFLAGS) + +nyqstk/src/Noise.o: nyqstk/src/Noise.cpp nyqstk/include/Noise.h + g++ -c nyqstk/src/Noise.cpp -o nyqstk/src/Noise.o $(CFLAGS) + +nyqstk/src/OneZero.o: nyqstk/src/OneZero.cpp nyqstk/include/OneZero.h + g++ -c nyqstk/src/OneZero.cpp -o nyqstk/src/OneZero.o $(CFLAGS) + +nyqstk/src/ReedTable.o: nyqstk/src/ReedTable.cpp nyqstk/include/ReedTable.h + g++ -c nyqstk/src/ReedTable.cpp -o nyqstk/src/ReedTable.o $(CFLAGS) + +nyqstk/src/Saxofony.o: nyqstk/src/Saxofony.cpp nyqstk/include/Saxofony.h + g++ -c nyqstk/src/Saxofony.cpp -o nyqstk/src/Saxofony.o $(CFLAGS) + +nyqstk/src/Stk.o: nyqstk/src/Stk.cpp nyqstk/include/Stk.h + g++ -c nyqstk/src/Stk.cpp -o nyqstk/src/Stk.o $(CFLAGS) + +nyqstk/src/WaveLoop.o: nyqstk/src/WaveLoop.cpp nyqstk/include/WaveLoop.h + g++ -c nyqstk/src/WaveLoop.cpp -o nyqstk/src/WaveLoop.o $(CFLAGS) + +nyqstk/src/WvIn.o: nyqstk/src/WvIn.cpp nyqstk/include/WvIn.h + g++ -c nyqstk/src/WvIn.cpp -o nyqstk/src/WvIn.o $(CFLAGS) + +nyqstk/src/NRev.o: nyqstk/src/NRev.cpp nyqstk/include/NRev.h + g++ -c nyqstk/src/NRev.cpp -o nyqstk/src/NRev.o $(CFLAGS) + +nyqstk/src/JCRev.o: nyqstk/src/JCRev.cpp nyqstk/include/JCRev.h + g++ -c nyqstk/src/JCRev.cpp -o nyqstk/src/JCRev.o $(CFLAGS) + +nyqstk/src/PRCRev.o: nyqstk/src/PRCRev.cpp nyqstk/include/PRCRev.h + g++ -c nyqstk/src/PRCRev.cpp -o nyqstk/src/PRCRev.o $(CFLAGS) + +nyqstk/src/PitShift.o: nyqstk/src/PitShift.cpp nyqstk/include/PitShift.h + g++ -c nyqstk/src/PitShift.cpp -o nyqstk/src/PitShift.o $(CFLAGS) + +nyqstk/src/Chorus.o: nyqstk/src/Chorus.cpp nyqstk/include/Chorus.h + g++ -c nyqstk/src/Chorus.cpp -o nyqstk/src/Chorus.o $(CFLAGS) + +nyqstk/src/Bowed.o: nyqstk/src/Bowed.cpp nyqstk/include/Bowed.h + g++ -c nyqstk/src/Bowed.cpp -o nyqstk/src/Bowed.o $(CFLAGS) + +nyqstk/src/BowTable.o: nyqstk/src/BowTable.cpp nyqstk/include/BowTable.h + g++ -c nyqstk/src/BowTable.cpp -o nyqstk/src/BowTable.o $(CFLAGS) + +nyqstk/src/ADSR.o: nyqstk/src/ADSR.cpp nyqstk/include/ADSR.h + g++ -c nyqstk/src/ADSR.cpp -o nyqstk/src/ADSR.o $(CFLAGS) + +nyqstk/src/OnePole.o: nyqstk/src/OnePole.cpp nyqstk/include/OnePole.h + g++ -c nyqstk/src/OnePole.cpp -o nyqstk/src/OnePole.o $(CFLAGS) + +nyqstk/src/BiQuad.o: nyqstk/src/BiQuad.cpp nyqstk/include/BiQuad.h + g++ -c nyqstk/src/BiQuad.cpp -o nyqstk/src/BiQuad.o $(CFLAGS) + +nyqstk/src/BandedWG.o: nyqstk/src/BandedWG.cpp nyqstk/include/BandedWG.h + g++ -c nyqstk/src/BandedWG.cpp -o nyqstk/src/BandedWG.o $(CFLAGS) + +nyqstk/src/DelayA.o: nyqstk/src/DelayA.cpp nyqstk/include/DelayA.h + g++ -c nyqstk/src/DelayA.cpp -o nyqstk/src/DelayA.o $(CFLAGS) + +nyqstk/src/Mandolin.o: nyqstk/src/Mandolin.cpp nyqstk/include/Mandolin.h + g++ -c nyqstk/src/Mandolin.cpp -o nyqstk/src/Mandolin.o $(CFLAGS) + +nyqstk/src/PluckTwo.o: nyqstk/src/PluckTwo.cpp nyqstk/include/PluckTwo.h + g++ -c nyqstk/src/PluckTwo.cpp -o nyqstk/src/PluckTwo.o $(CFLAGS) + +nyqstk/src/Sitar.o: nyqstk/src/Sitar.cpp nyqstk/include/Sitar.h + g++ -c nyqstk/src/Sitar.cpp -o nyqstk/src/Sitar.o $(CFLAGS) + +nyqstk/src/ModalBar.o: nyqstk/src/ModalBar.cpp nyqstk/include/ModalBar.h + g++ -c nyqstk/src/ModalBar.cpp -o nyqstk/src/ModalBar.o $(CFLAGS) + +nyqstk/src/Modal.o: nyqstk/src/Modal.cpp nyqstk/include/Modal.h + g++ -c nyqstk/src/Modal.cpp -o nyqstk/src/Modal.o $(CFLAGS) + +nyqstk/src/Flute.o: nyqstk/src/Flute.cpp nyqstk/include/Flute.h + g++ -c nyqstk/src/Flute.cpp -o nyqstk/src/Flute.o $(CFLAGS) + +nyqstk/src/JetTable.o: nyqstk/src/JetTable.cpp nyqstk/include/JetTable.h + g++ -c nyqstk/src/JetTable.cpp -o nyqstk/src/JetTable.o $(CFLAGS) + +nyqstk/src/PoleZero.o: nyqstk/src/PoleZero.cpp nyqstk/include/PoleZero.h + g++ -c nyqstk/src/PoleZero.cpp -o nyqstk/src/PoleZero.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + $(CC) -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + $(CC) -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + $(CC) -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + $(CC) -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + $(CC) -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + $(CC) -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + $(CC) -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + $(CC) -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + $(CC) -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + $(CC) -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + $(CC) -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + $(CC) -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + $(CC) -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + $(CC) -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + $(CC) -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + $(CC) -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + $(CC) -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + $(CC) -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + $(CC) -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + $(CC) -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + $(CC) -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + $(CC) -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + $(CC) -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + $(CC) -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +xlisp/path.o: xlisp/path.c + $(CC) -c xlisp/path.c -o xlisp/path.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + $(CC) -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + $(CC) -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + $(CC) -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + $(CC) -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + $(CC) -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + $(CC) -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + $(CC) -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + $(CC) -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + $(CC) -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + $(CC) -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + $(CC) -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + $(CC) -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + $(CC) -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + $(CC) -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + $(CC) -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + $(CC) -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + $(CC) -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +nylsf/aiff.o: nylsf/aiff.c + $(CC) -c nylsf/aiff.c -o nylsf/aiff.o $(CFLAGS) + +nylsf/alaw.o: nylsf/alaw.c + $(CC) -c nylsf/alaw.c -o nylsf/alaw.o $(CFLAGS) + +nylsf/au.o: nylsf/au.c + $(CC) -c nylsf/au.c -o nylsf/au.o $(CFLAGS) + +nylsf/audio_detect.o: nylsf/audio_detect.c + $(CC) -c nylsf/audio_detect.c -o nylsf/audio_detect.o $(CFLAGS) + +nylsf/avr.o: nylsf/avr.c + $(CC) -c nylsf/avr.c -o nylsf/avr.o $(CFLAGS) + +nylsf/broadcast.o: nylsf/broadcast.c + $(CC) -c nylsf/broadcast.c -o nylsf/broadcast.o $(CFLAGS) + +nylsf/caf.o: nylsf/caf.c + $(CC) -c nylsf/caf.c -o nylsf/caf.o $(CFLAGS) + +nylsf/chanmap.o: nylsf/chanmap.c + $(CC) -c nylsf/chanmap.c -o nylsf/chanmap.o $(CFLAGS) + +nylsf/chunk.o: nylsf/chunk.c + $(CC) -c nylsf/chunk.c -o nylsf/chunk.o $(CFLAGS) + +nylsf/command.o: nylsf/command.c + $(CC) -c nylsf/command.c -o nylsf/command.o $(CFLAGS) + +nylsf/common.o: nylsf/common.c + $(CC) -c nylsf/common.c -o nylsf/common.o $(CFLAGS) + +nylsf/dither.o: nylsf/dither.c + $(CC) -c nylsf/dither.c -o nylsf/dither.o $(CFLAGS) + +nylsf/double64.o: nylsf/double64.c + $(CC) -c nylsf/double64.c -o nylsf/double64.o $(CFLAGS) + +nylsf/dwd.o: nylsf/dwd.c + $(CC) -c nylsf/dwd.c -o nylsf/dwd.o $(CFLAGS) + +nylsf/dwvw.o: nylsf/dwvw.c + $(CC) -c nylsf/dwvw.c -o nylsf/dwvw.o $(CFLAGS) + +nylsf/file_io.o: nylsf/file_io.c + $(CC) -c nylsf/file_io.c -o nylsf/file_io.o $(CFLAGS) + +nylsf/flac.o: nylsf/flac.c + $(CC) -c nylsf/flac.c -o nylsf/flac.o $(CFLAGS) + +nylsf/float32.o: nylsf/float32.c + $(CC) -c nylsf/float32.c -o nylsf/float32.o $(CFLAGS) + +nylsf/gsm610.o: nylsf/gsm610.c + $(CC) -c nylsf/gsm610.c -o nylsf/gsm610.o $(CFLAGS) + +nylsf/htk.o: nylsf/htk.c + $(CC) -c nylsf/htk.c -o nylsf/htk.o $(CFLAGS) + +nylsf/id3.o: nylsf/id3.c + $(CC) -c nylsf/id3.c -o nylsf/id3.o $(CFLAGS) + +nylsf/ima_adpcm.o: nylsf/ima_adpcm.c + $(CC) -c nylsf/ima_adpcm.c -o nylsf/ima_adpcm.o $(CFLAGS) + +nylsf/ima_oki_adpcm.o: nylsf/ima_oki_adpcm.c + $(CC) -c nylsf/ima_oki_adpcm.c -o nylsf/ima_oki_adpcm.o $(CFLAGS) + +nylsf/interleave.o: nylsf/interleave.c + $(CC) -c nylsf/interleave.c -o nylsf/interleave.o $(CFLAGS) + +nylsf/ircam.o: nylsf/ircam.c + $(CC) -c nylsf/ircam.c -o nylsf/ircam.o $(CFLAGS) + +nylsf/macbinary3.o: nylsf/macbinary3.c + $(CC) -c nylsf/macbinary3.c -o nylsf/macbinary3.o $(CFLAGS) + +nylsf/macos.o: nylsf/macos.c + $(CC) -c nylsf/macos.c -o nylsf/macos.o $(CFLAGS) + +nylsf/mat4.o: nylsf/mat4.c + $(CC) -c nylsf/mat4.c -o nylsf/mat4.o $(CFLAGS) + +nylsf/mat5.o: nylsf/mat5.c + $(CC) -c nylsf/mat5.c -o nylsf/mat5.o $(CFLAGS) + +nylsf/mpc2k.o: nylsf/mpc2k.c + $(CC) -c nylsf/mpc2k.c -o nylsf/mpc2k.o $(CFLAGS) + +nylsf/ms_adpcm.o: nylsf/ms_adpcm.c + $(CC) -c nylsf/ms_adpcm.c -o nylsf/ms_adpcm.o $(CFLAGS) + +nylsf/nist.o: nylsf/nist.c + $(CC) -c nylsf/nist.c -o nylsf/nist.o $(CFLAGS) + +nylsf/ogg.o: nylsf/ogg.c + $(CC) -c nylsf/ogg.c -o nylsf/ogg.o $(CFLAGS) + +nylsf/ogg_vorbis.o: nylsf/ogg_vorbis.c + $(CC) -c nylsf/ogg_vorbis.c -o nylsf/ogg_vorbis.o $(CFLAGS) + +nylsf/paf.o: nylsf/paf.c + $(CC) -c nylsf/paf.c -o nylsf/paf.o $(CFLAGS) + +nylsf/pcm.o: nylsf/pcm.c + $(CC) -c nylsf/pcm.c -o nylsf/pcm.o $(CFLAGS) + +nylsf/pvf.o: nylsf/pvf.c + $(CC) -c nylsf/pvf.c -o nylsf/pvf.o $(CFLAGS) + +nylsf/raw.o: nylsf/raw.c + $(CC) -c nylsf/raw.c -o nylsf/raw.o $(CFLAGS) + +nylsf/rf64.o: nylsf/rf64.c + $(CC) -c nylsf/rf64.c -o nylsf/rf64.o $(CFLAGS) + +nylsf/rx2.o: nylsf/rx2.c + $(CC) -c nylsf/rx2.c -o nylsf/rx2.o $(CFLAGS) + +nylsf/sd2.o: nylsf/sd2.c + $(CC) -c nylsf/sd2.c -o nylsf/sd2.o $(CFLAGS) + +nylsf/sds.o: nylsf/sds.c + $(CC) -c nylsf/sds.c -o nylsf/sds.o $(CFLAGS) + +nylsf/sndfile.o: nylsf/sndfile.c + $(CC) -c nylsf/sndfile.c -o nylsf/sndfile.o $(CFLAGS) + +nylsf/strings.o: nylsf/strings.c + $(CC) -c nylsf/strings.c -o nylsf/strings.o $(CFLAGS) + +nylsf/svx.o: nylsf/svx.c + $(CC) -c nylsf/svx.c -o nylsf/svx.o $(CFLAGS) + +nylsf/txw.o: nylsf/txw.c + $(CC) -c nylsf/txw.c -o nylsf/txw.o $(CFLAGS) + +nylsf/ulaw.o: nylsf/ulaw.c + $(CC) -c nylsf/ulaw.c -o nylsf/ulaw.o $(CFLAGS) + +nylsf/voc.o: nylsf/voc.c + $(CC) -c nylsf/voc.c -o nylsf/voc.o $(CFLAGS) + +nylsf/vox_adpcm.o: nylsf/vox_adpcm.c + $(CC) -c nylsf/vox_adpcm.c -o nylsf/vox_adpcm.o $(CFLAGS) + +nylsf/w64.o: nylsf/w64.c + $(CC) -c nylsf/w64.c -o nylsf/w64.o $(CFLAGS) + +nylsf/wav.o: nylsf/wav.c + $(CC) -c nylsf/wav.c -o nylsf/wav.o $(CFLAGS) + +nylsf/wav_w64.o: nylsf/wav_w64.c + $(CC) -c nylsf/wav_w64.c -o nylsf/wav_w64.o $(CFLAGS) + +nylsf/wve.o: nylsf/wve.c + $(CC) -c nylsf/wve.c -o nylsf/wve.o $(CFLAGS) + +nylsf/xi.o: nylsf/xi.c + $(CC) -c nylsf/xi.c -o nylsf/xi.o $(CFLAGS) + +nylsf/g72x.o: nylsf/g72x.c + $(CC) -c nylsf/g72x.c -o nylsf/g72x.o $(CFLAGS) + +nylsf/GSM610/add.o: nylsf/GSM610/add.c + $(CC) -c nylsf/GSM610/add.c -o nylsf/GSM610/add.o $(CFLAGS) + +nylsf/GSM610/code.o: nylsf/GSM610/code.c + $(CC) -c nylsf/GSM610/code.c -o nylsf/GSM610/code.o $(CFLAGS) + +nylsf/GSM610/decode.o: nylsf/GSM610/decode.c + $(CC) -c nylsf/GSM610/decode.c -o nylsf/GSM610/decode.o $(CFLAGS) + +nylsf/GSM610/gsm_create.o: nylsf/GSM610/gsm_create.c + $(CC) -c nylsf/GSM610/gsm_create.c -o nylsf/GSM610/gsm_create.o $(CFLAGS) + +nylsf/GSM610/gsm_decode.o: nylsf/GSM610/gsm_decode.c + $(CC) -c nylsf/GSM610/gsm_decode.c -o nylsf/GSM610/gsm_decode.o $(CFLAGS) + +nylsf/GSM610/gsm_destroy.o: nylsf/GSM610/gsm_destroy.c + $(CC) -c nylsf/GSM610/gsm_destroy.c -o nylsf/GSM610/gsm_destroy.o $(CFLAGS) + +nylsf/GSM610/gsm_encode.o: nylsf/GSM610/gsm_encode.c + $(CC) -c nylsf/GSM610/gsm_encode.c -o nylsf/GSM610/gsm_encode.o $(CFLAGS) + +nylsf/GSM610/gsm_option.o: nylsf/GSM610/gsm_option.c + $(CC) -c nylsf/GSM610/gsm_option.c -o nylsf/GSM610/gsm_option.o $(CFLAGS) + +nylsf/GSM610/long_term.o: nylsf/GSM610/long_term.c + $(CC) -c nylsf/GSM610/long_term.c -o nylsf/GSM610/long_term.o $(CFLAGS) + +nylsf/GSM610/lpc.o: nylsf/GSM610/lpc.c + $(CC) -c nylsf/GSM610/lpc.c -o nylsf/GSM610/lpc.o $(CFLAGS) + +nylsf/GSM610/preprocess.o: nylsf/GSM610/preprocess.c + $(CC) -c nylsf/GSM610/preprocess.c -o nylsf/GSM610/preprocess.o $(CFLAGS) + +nylsf/GSM610/rpe.o: nylsf/GSM610/rpe.c + $(CC) -c nylsf/GSM610/rpe.c -o nylsf/GSM610/rpe.o $(CFLAGS) + +nylsf/GSM610/short_term.o: nylsf/GSM610/short_term.c + $(CC) -c nylsf/GSM610/short_term.c -o nylsf/GSM610/short_term.o $(CFLAGS) + +nylsf/GSM610/table.o: nylsf/GSM610/table.c + $(CC) -c nylsf/GSM610/table.c -o nylsf/GSM610/table.o $(CFLAGS) + +nylsf/G72x/g721.o: nylsf/G72x/g721.c + $(CC) -c nylsf/G72x/g721.c -o nylsf/G72x/g721.o $(CFLAGS) + +nylsf/G72x/g723_16.o: nylsf/G72x/g723_16.c + $(CC) -c nylsf/G72x/g723_16.c -o nylsf/G72x/g723_16.o $(CFLAGS) + +nylsf/G72x/g723_24.o: nylsf/G72x/g723_24.c + $(CC) -c nylsf/G72x/g723_24.c -o nylsf/G72x/g723_24.o $(CFLAGS) + +nylsf/G72x/g723_40.o: nylsf/G72x/g723_40.c + $(CC) -c nylsf/G72x/g723_40.c -o nylsf/G72x/g723_40.o $(CFLAGS) + +nylsf/G72x/g72x.o: nylsf/G72x/g72x.c + $(CC) -c nylsf/G72x/g72x.c -o nylsf/G72x/g72x.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + $(CC) -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +nyqsrc/sndfnintptrs.h: $(SNDFNINT_HDRS) misc/intgen Makefile + $(INTGEN) nyqsrc/sndfnint $(SNDFNINT_HDRS) + +nyqsrc/seqfnintptrs.h: $(SEQFNINT_HDRS) misc/intgen Makefile + $(INTGEN) nyqsrc/seqfnint $(SEQFNINT_HDRS) + +clean: + cd misc; make clean + cd liblo; test -f Makefile && make clean || true + cd portaudio; test -f Makefile && make clean || true + rm -f $(OBJECTS) +# These could be deleted, but they're part of the release, so we won't +# Note that these files are machine-generated: +# rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h +# rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f #*# */#*# + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat + rm -f core.* core + rm -f $(NY) diff --git a/lib-src/libnyquist/nyquist/sys/unix/nonalsa/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/nonalsa/system.lsp new file mode 100644 index 000000000..3923bc821 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/nonalsa/system.lsp @@ -0,0 +1,101 @@ +;; system.lsp -- system-dependent lisp code + +; local definition for play +; this one is for Linux: + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-wave)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "./")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* (strcat (get-user) "-points.dat"))) + + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (or (eq (char filename 0) #\/) + (eq (char filename 0) #\.))) + +; RELATIVE-PATH-P -- test if filename or path is a relative path +; +(defun relative-path-p (filename) + (not (eq (char filename 0) #\/))) + +(setf *file-separator* #\/) + + +;; PLAY-FILE - play a sound file +;; +(defun play-file (name) +;; +;; WARNING: if you invoke an external program to play files, +;; but Nyquist uses internal (portaudio) interface to +;; play synthesized sound, Nyquist may fail to open the +;; sound device while it is playing a sound file and then +;; refuse to play anything. -RBD dec05 +;; (system (strcat "sndplay " (soundfilename name)))) +;; (system (strcat "play " (soundfilename name) ))) +;; + (play (s-read (soundfilename name)))) + +;; R - replay last file written with PLAY +(defun r () (play-file *default-sound-file*)) + +;;;; use this old version if you want to use sndplay to play +;;;; the result file rather than play the samples as they +;;;; are computed. This version does not autonormalize. +;; PLAY - write value of an expression to file and play it +;; +;(defmacro play (expr) +; `(prog (specs) +; (setf specs (s-save (force-srate *sound-srate* ,expr) +; 1000000000 *default-sound-file*)) +; (r))) +;;;; + +; local definition for play +(defmacro play (expr) + `(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*)) + +;; for Linux, modify s-plot (defined in nyquist.lsp) by saving s-plot +;; in standard-s-plot, then call gnuplot to display the points. +;; +;; we also need to save the location of this file so we can find +;; nyquist-plot.txt, the command file for gnuplot +;; +;; This code is broken in the following ways: +;; it tries to run gnuplot even when plotting can be done by NyquistIDE +;; it plots "points.dat", but "points.dat" may not be correct +;; (see *default-plot-file*) +;; it assumes the plot file is in the current directory, but it +;; by default goes to the sound file directory +;; +;; Fix this code or complain if you want to plot with gnuplot while +;; running ny (or even NyquistIDE (jny) if you want). Otherwise, use +;; NyquistIDE to get s-plot to work. +;; +;(setf *runtime-path* (current-path)) +;(display "system.lsp" *runtime-path*) +; +;(setfn standard-s-plot s-plot) +; +;(defun s-plot (s &optional (dur 2.0) (n 1000)) +; (let (plot-file) +; (standard-s-plot s dur n) ;; this calculates the data points +; (setf plot-file (strcat *runtime-path* "nyquist-plot.txt")) +; (system (strcat "gnuplot -persist " plot-file)))) + diff --git a/lib-src/libnyquist/nyquist/sys/unix/osstuff.c b/lib-src/libnyquist/nyquist/sys/unix/osstuff.c new file mode 100644 index 000000000..75b736fd6 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/osstuff.c @@ -0,0 +1,817 @@ +/* unixtuff.c - unix interface routines for xlisp + + * HISTORY + * 5-Mar-07 Dannenberg + * worked on hidden_msg() and hidden message handling + * + * 23-Dec-05 Dannenberg + * still more hacks: Mac and Linux don't disable character echo like + * windows does using a pipe to an IDE. To make UNIX versions match + * the Windows behavior (which is preferable), added + * echo_enabled flag and a function to set/clear it from XLisp. + * This will give unix-specific behavior to compensate for the + * unix-specific character echo. This worked, but printed + * (echoenabled nil) on the console, which was pretty ugly, so I + * added ctrl-e and ctrl-f handlers to turn echo on and off. Now + * Java can just send ctrl-f before anything else. Windows must + * ignore ctrl-f. + * + * 28-Apr-03 Mazzoni + * many changes for new conditional compilation organization + * + * 28-Jun-95 Dannenberg + * removed buffering (which could overflow) from ostgetc. + * + * 2-Aprl-88 Dale Amon at CMU-CSD + * Upgraded to xlisp 2.0. Used msstuff.c as a template. + * + * 20-Apr-87 Dale Amon at CMU-CSD + * Added control-c interrupt handler. Puts user in breakloop and allows + * continue. Prints line at which the interrupt occured. Interrupt + * occurs at first eval after ^C has been typed. + * + * 19-APR-87 Dale Amon at CMU-CSD + * switched from rand to random package. Corrected bug in osrand(). It + * did not use the argument n to calculate a rand in range 0 to n-1 as + * advertised. + * 28-OCT-05 Roger Dannenberg at CMU-SCS + * added directory listing functions + */ + +#include "switches.h" +#include + +#include +#include +#include + +#include +#include + +#include "xlisp.h" +#include "term.h" +#include "cext.h" +#include "userio.h" +#include "exitpa.h" +#include "nyq-osc-server.h" +#include "sliderdata.h" /* define sliders -- not just for OSC */ +#include "sound.h" /* define nosc_enabled and mark_sound_time */ +#include "falloc.h" /* define table_memory */ +#define LBSIZE 200 + +/* external variables */ +extern LVAL s_unbound,s_true; +extern FILE *tfp; + +/* local variables */ +static int lindex; +static int lcount = 0; +static int lposition; +static int line_edit = TRUE; + +#ifndef READ_LINE +#define typeahead_max 128 +static char typeahead[typeahead_max]; +static int typeahead_tail = 0; +static int typeahead_head = 0; +static char lbuf[LBSIZE]; +static int lpos[LBSIZE]; +#endif + +static int echo_enabled = 1; + +/* forward declarations */ +FORWARD LOCAL void xflush(); +FORWARD LOCAL int xcheck(); +FORWARD LOCAL void hidden_msg(); + +/*==========================================================================*/ +/* control-c interrupt handling routines and variables. Uses B4.2 signal + handling. Previous SIGINT handler is saved just in case someday we want + to play with turning control c on and off. +*/ + +#include + +static int ctc = FALSE; +static void control_c(int x) {ctc = TRUE;} +void ctcinit() {signal ( SIGINT, control_c );} +static void ctcreset() {signal ( SIGINT, control_c );} + + +/*==========================================================================*/ + + +const char os_pathchar = '/'; +const char os_sepchar = ':'; + + +/* osinit - initialize */ +void osinit(const char *banner) +{ + printf("%s\n",banner); + /* start the random number generator. Older version was srand(1) + seed of 1 makes the sequence repeatable. Random gives better + pseudo randomness than does rand(). + */ +#if USE_RAND + srand(1); +#endif + +#if USE_RANDOM + srandom(1); +#endif + +#ifndef UNIX + /* set control c trap to local routine */ + ctcinit(); +#else + /* sets terminal for raw input and calls ctcinit too */ + term_init(); + term_character(); +#endif + + lposition = 0; + lindex = 0; + lcount = 0; +} + +/* osfinish - clean up before returning to the operating system */ +void osfinish(void) +{ + term_exit(); + portaudio_exit(); +} + +/* oserror - print an error message */ +void oserror(const char *msg) {printf("error: %s\n",msg);} + + +/* osaopen - open an ascii file */ +FILE *osaopen(name,mode) const char *name,*mode; { + FILE *fp = NULL; + if (ok_to_open(name, mode)) + fp = fopen(name,mode); +#ifdef DEBUG_INPUT + printf("osaopen on %s yields %x\n", name, fp); + if (strcmp(name, "/home/rbd/nyquist/lib/xm-test.lsp") == 0) { + // when DEBUG_INPUT is set, this generates a compiler error + // on linux -RBD + debug_input_fp = fp; + printf("osaopen: debug_input_fp gets %x\n", debug_input_fp); + } +#endif + return fp; +} + +/* osbopen - open a binary file */ +FILE *osbopen(name,mode) const char *name,*mode; + { char bmode[10]; + FILE *fp = NULL; + strcpy(bmode,mode); strcat(bmode,"b"); + if (ok_to_open(name, bmode)) + fp = fopen(name,bmode); + return fp; + } + +/* osclose - close a file */ +int osclose(fp) FILE *fp; +{ +#ifdef DEBUG_INPUT + if (debug_input_fp == fp) { + debug_input_fp = NULL; + printf("osclose: debug_input_fp gets %x\n", debug_input_fp); + } +#endif + /* when XLISP is loading files and an error is encountered, the files + * are automatically closed so that the OS will not lock them, confusing + * the user. So we could get here and the file could already be closed + */ + return (fp ? fclose(fp) : 0); +} + +/* osagetc - get a character from an ascii file */ +int osagetc(fp) FILE *fp; { +#ifdef DEBUG_INPUT + int c = getc(fp); + ungetc(c, fp); +#endif + return (getc(fp)); +} + +/* osaputc - put a character to an ascii file */ +int osaputc(int ch, FILE *fp) { return (putc(ch,fp)); } + +/* osoutflush - flush output to a file */ +void osoutflush(FILE *fp) { fflush(fp); } + +extern int dbgflg; + +/* osbgetc - get a character from a binary file */ +/* int osbgetc(fp) FILE *fp; {return (getc(fp));} */ +int osbgetc(FILE *fp) { + int c = (getc(fp)); + /* if (dbgflg) printf("osbgetc: got %d from FILE %x\n", c, fp); + */ + return c; +} + +/* osbputc - put a character to a binary file */ +int osbputc(ch,fp) int ch; FILE *fp; {return (putc(ch,fp));} + +#ifdef OLDEST_OSTGETC +/* ostgetc - get a character from the terminal */ +int ostgetc() +{ + int ch; + switch (ch = term_getchar()) { + case '\n': + lbuf[lcount++] = '\n'; + lposition = 0; + if (tfp) + for (lindex = 0; lindex < lcount; ++lindex) + osaputc(lbuf[lindex],tfp); + lindex = 0; lcount = 0; + return (ch); + case '\010': + case '\177': + if (lcount) { + lcount--; + while (lposition > lpos[lcount]) { + lposition--; + } + } + break; + case '\032': + xflush(); + return (EOF); + default: + if (ch == '\t' || (ch >= 0x20 && ch < 0x7F)) { + lbuf[lcount] = ch; + lpos[lcount] = lposition; + if (ch == '\t') + do {} while (++lposition & 7); + else {lposition++;} + lcount++; + return (ch); + } + else { + xflush(); + switch (ch) { + case '\003': xltoplevel(); /* control-c */ + case '\007': xlcleanup(); /* control-g */ + case '\020': xlcontinue(); /* control-p */ + case '\032': return (EOF); /* control-z */ + + /* moved from oscheck until I figure out how to + set up interrupt to handle these two */ + case '\002': xflush(); xlbreak("BREAK",s_unbound); + break; /* control-b */ + case '\024': xinfo(); break; /* control-t */ + + default: return (ch); + } + } + } +} +#else +#if OLD_OSTGETC +/* ostgetc - get a character from the terminal */ +int ostgetc() +{ int ch; + + for (;;) { + ch = term_getchar(); + oscheck(); + switch (ch) { + case '\003': xltoplevel(); /* control-c */ + case '\007': xlcleanup(); /* control-g */ + case '\020': xlcontinue(); /* control-p */ + case '\032': return EOF; /* control-z */ + case '\002': xflush(); xlbreak("BREAK",s_unbound); + break; /* control-b */ + case '\024': xinfo(); break; /* control-t */ + case '\t': + case '\n': + default: + if (tfp) osaputc(ch, tfp); + return ch; + } + } +} +#else +#ifdef READLINE + +#include +#include + +char *readline_line = NULL; +int readline_pos = 0; +int readline_len = 0; +int readline_first = 1; + +extern int xldebug; + +int ostgetc() +{ + int rval; + + if (readline_first) + using_history(); + + if (!readline_line) { + char prompt[10]; + if (xldebug==0) + sprintf(prompt, "> "); + else + sprintf(prompt, "%d> ", xldebug); + readline_line = readline(prompt); + if (readline_line == NULL) + return EOF; + add_history(readline_line); + readline_len = strlen(readline_line); + readline_pos = 0; + } + + rval = readline_line[readline_pos]; + if (readline_pos == readline_len) { + free(readline_line); + readline_line = NULL; + return '\n'; + } + readline_pos++; + + return rval; +} + + +#else /* no readline */ + + +void end_of_line_edit() +{ + line_edit = FALSE; + if (tfp) { + for (lindex = 0; lindex < lcount; ++lindex) + osaputc(lbuf[lindex], tfp); + } + lindex = 0; +} + +/* THIS IS THE "REAL" ostgetc(): */ +LOCAL int rawtchar() +{ + int ch; + if (typeahead_tail != typeahead_head) { + ch = typeahead[typeahead_head++]; + typeahead_head &= (typeahead_max - 1); + /* printf("[%c]", ch); */ + if (ch == 0xFF) ch = -1; /* char to int conversion of EOF */ + } else { + fflush(stdout); /* necessary on OS X with Java IDE - I don't know why. */ + /* don't use getchar() or buffering will cause out-of-order input */ + ch = term_getchar(); + /* printf("{%c}", ch); */ + } + return ch; +} + +int ostgetc() +{ +/* + * NOTE: lbuf[] accumulates characters as they are typed + * lpos[] is the column position of the characters + * lcount is the number of characters in lbuf + * lposition is current position + * lindex is index of next char to output + * line_edit is true iff we're inputing characters + * + */ + int ch; + + while (line_edit) { + ch = rawtchar(); + if (ch == EOF) xlisp_wrapup(); + oscheck(); /* in case user typed ^C */ + /* assume for now we should add the character */ + lbuf[lcount] = ch; + lpos[lcount] = lposition; + lcount++; + lposition++; + + /* now do all the special character processing */ + switch (ch) { + case '\001': /* take out non-printing character */ + lcount--; + lposition--; + mark_audio_time(); + break; + case '\n': + lposition = 0; + end_of_line_edit(); + if (echo_enabled) { + osaputc('\r', stdout); + osaputc(ch, stdout); + } + break; + /* delete key generates: 1b, 5b, 33, 7E + which is: ESC, [, 3, ~ */ + case '\010': /* backspace */ + case '\177': /* delete */ + lcount--; /* take out backspace or delete char */ + lposition--; + if (lcount) { + lcount--; + while (lposition > lpos[lcount]) { + if (echo_enabled) { + putchar('\010'); + putchar(' '); + putchar('\010'); + } + lposition--; + } + } + break; + case '\025': /* control-u */ + lcount--; + lposition--; + if (lcount) { + while (lposition > lpos[0]) { + if (echo_enabled) { + putchar('\010'); + putchar(' '); + putchar('\010'); + } + lposition--; + } + lcount = 0; + } + break; + + /* note that control-z never reaches here */ + case '\003': /* control-c */ + xltoplevel(); + lcount = 0; + break; + case '\007': /* control-g */ + lcount--; /* take out non-printing char */ + lposition--; + xlcleanup(); + lcount = 0; + break; + case '\016': + lcount--; /* take out non-printing char */ + lposition--; + hidden_msg(); /* process hidden msg chars */ + break; + case '\020': /* control-p */ + lcount--; /* take out non-printing char */ + lposition--; + xlcontinue(); + lcount = 0; + break; + case '\002': + lcount--; /* take out non-printing char */ + lposition--; + xflush(); /* control-b */ + xlbreak("BREAK",s_unbound); + break; + case '\005': /* control-e */ + lcount--; /* take out non-printing char */ + lposition--; + echo_enabled = TRUE; + break; + case '\006': /* control-f */ + lcount--; /* take out non-printing char */ + lposition--; + echo_enabled = FALSE; + break; + case '\024': /* control-t */ + lcount--; /* take out non-printing char */ + lposition--; + xinfo(); + lcount = 0; + break; + + case '\t': /* TAB */ + lposition--; /* undo the increment above */ + do { + lposition++; + if (echo_enabled) osaputc(' ', stdout); + } while (lposition & 7); + break; + default: + if (echo_enabled) osaputc(ch, stdout); + break; + } + // avoid line buffer overflow here: + if (lposition > LBSIZE - 10) { + // buffer is about to overflow, so write newline and + // feed chars to XLISP + if (echo_enabled) { + osaputc('\r', stdout); + osaputc('\n', stdout); + } + lposition = 0; + end_of_line_edit(); + } + } + if (lindex + 1 >= lcount) { + lcount = 0; + line_edit = TRUE; + } + ch = lbuf[lindex++]; + /* printf("-%c-", ch); */ + if (echo_enabled) fflush(stdout); + return ch; +} +#endif +#endif +#endif + + +/* ostputc - put a character to the terminal */ +void ostputc(int ch) + { + oscheck(); /* check for control characters */ + + /* output the character */ + if (ch == '\n') {lposition = 0;} + else {lposition++;} + + /* output the character to the transcript file */ + if (tfp) osaputc(ch,tfp); + putchar(((char) ch)); + } + +/* ostoutflush - flush output buffer */ +void ostoutflush() +{ + if (tfp) fflush(tfp); + fflush(stdout); +} + +/* osflush - flush the terminal input buffer */ +void osflush(void) +{ + lindex = lcount = lposition = 0; + line_edit = TRUE; +} + + +/* hidden_msg - process a "hidden message" + * + * NOTE: a "hidden message" is a sequence of characters starting + * with '\016' and ending with '\021'. These are designed to allow + * a graphical interface, namely jNyqIDE, to control sliders in + * real-time (during synthesis). The character sequences are hidden + * meaning they are not echoed and they are not interpreted as LISP. + * + * This function assumes that '\016' has been received already. + */ +LOCAL void hidden_msg() +{ +#define MSGBUF_MAX 64 + char msgbuf[MSGBUF_MAX]; + int msgbufx = 0; + char type_char = rawtchar(); + char ch; + // message is terminated by '\021' + while ((ch = term_getchar()) != '\021' && ch != EOF && + msgbufx < MSGBUF_MAX - 1) { + msgbuf[msgbufx++] = ch; + } + msgbuf[msgbufx++] = 0; + // printf("hidden message: %s, len %ld\n", msgbuf, (long) strlen(msgbuf)); + if (msgbufx < MSGBUF_MAX) { + if (type_char == 'S') { // slider change message + int index; + float value; + if (sscanf(msgbuf, "%d %g", &index, &value) == 2) { + set_slider(index, value); + } + } + } /* other hidden messages could be parsed here */ +} + + +/* oscheck - check for control characters during execution */ +/* + * NOTE: to support type-ahead, unused characters are put + * into a queue to be removed by ostgetc + */ +void oscheck(void) +{ + int ch; + +#if OSC + if (nosc_enabled) nosc_poll(); +#endif + + if (ctc) { /* control-c */ + /* printf("[oscheck: control-c detected]"); */ + ctc=FALSE; ctcreset(); + xflush(); xltoplevel(); return; + } + + if ((ch = xcheck())) { + switch (ch) { + case BREAK_CHAR: /* control-b */ + /* printf("BREAK_CHAR\n"); */ + xflush(); xlbreak("BREAK",s_unbound); break; + case '\024': /* control-t */ + /* printf("control-t\n"); */ + xinfo(); break; + case '\025': /* control-u */ + /* printf("control-u\n"); */ + xcleanup(); + case '\016': { /* begin hidden message */ + /* printf("hidden msg\n"); */ + hidden_msg(); + break; + } + case '\001': /* control-a -- mark audio time */ + mark_audio_time(); break; + case -1: /* EOF - lost connection, so die */ + xlisp_wrapup(); + break; + case -2: /* no character was ready */ + break; + default: + /* printf("Got %d\n", ch); */ +#ifndef READ_LINE + /* printf("+%c+", ch); */ + typeahead[typeahead_tail++] = ch; + typeahead_tail &= (typeahead_max - 1); + if (typeahead_tail == typeahead_head) { + oserror("Input buffer overflow\n"); + } +#endif + break; + } + } + + run_time++; + // when compute-bound, run_time is incremented by 10000 in about 15s, so + // that's about 700 Hz. We want to flush any output at about 2Hz, so + // we'll pick 400 as a round number. + // It's 2014, and now I'm seeing 3000 Hz. That's very high, so I + // changed SAMPLE to get this down to about 66Hz. Using % 30 to get + // 2Hz flush rate. + if (run_time % 30 == 0) { + fflush(stdout); + if (run_time_limit > 0 && run_time > run_time_limit) { + xlfatal("Run time limit exceeded"); + } + if (memory_limit > 0 && + npools * MAXPOOLSIZE + table_memory + total > + memory_limit * 1000000) { + xlfatal("Memory limit exceeded"); + } + } +} + +/* xflush - flush the input line buffer and start a new line */ +LOCAL void xflush() +{ + osflush(); + ostputc('\n'); +} + +/* xsystem - execute a system command */ +LVAL xsystem() +{ /*LVAL strval;*/ + unsigned char *cmd = NULL; + if (SAFE_NYQUIST) return NULL; + if (moreargs()) + cmd = (unsigned char *)getstring(xlgastring()); + xllastarg(); + return (system((char *) cmd) == -1 ? cvfixnum((FIXTYPE)errno) : s_true); +} + + +/* xsetdir -- set current directory of the process */ +LVAL xsetdir() +{ + char *dir = (char *)getstring(xlgastring()); + int result = -1; + LVAL cwd = NULL; + int verbose = TRUE; + if (moreargs()) { + verbose = (xlgetarg() != NIL); + } + xllastarg(); + if (ok_to_open(dir, "r")) + result = chdir(dir); + if (result) { + /* perror("SETDIR"); -- Nyquist uses SETDIR to search for directories + * at startup, so failures are normal, and seeing error messages + * could be confusing, so don't print them. The NULL return indicates + * an error, but doesn't tell which one it is. + * But now, SETDIR has a second verbose parameter that is nil when + * searching for directories. -RBD + */ + if (verbose) perror("Directory Setting Error"); + return NULL; + } + dir = getcwd(NULL, 1000); + if (dir) { + cwd = cvstring(dir); + free(dir); + } + return cwd; +} + +/* xget_temp_path -- get a path to create temp files */ +LVAL xget_temp_path() +{ + return cvstring("/tmp/"); +} + +/* xget_user -- get a string identifying the user, for use in file names */ +LVAL xget_user() +{ + const char *user = getenv("USER"); + if (!user || !*user) { + errputstr("Warning: could not get user ID, using 'nyquist'\n"); + user = "nyquist"; + } + return cvstring(user); +} + + +/* xechoenabled -- set/clear echo_enabled flag (unix only) */ +LVAL xechoenabled() +{ + int flag = (xlgetarg() != NULL); + xllastarg(); + echo_enabled = flag; + return NULL; +} + + +#define OSDIR_LIST_READY 0 +#define OSDIR_LIST_STARTED 1 +#define OSDIR_LIST_DONE 2 +static int osdir_list_status = OSDIR_LIST_READY; +static DIR *osdir_dir; + +/* osdir_list_start -- open a directory listing */ +int osdir_list_start(const char *path) +{ + if (osdir_list_status != OSDIR_LIST_READY) { + osdir_list_finish(); /* close current listing */ + } + osdir_dir = NULL; + if (ok_to_open(path, "r")) + osdir_dir = opendir(path); + if (!osdir_dir) { + return FALSE; + } + osdir_list_status = OSDIR_LIST_STARTED; + return TRUE; +} + + +/* osdir_list_next -- read the next entry from a directory */ +const char *osdir_list_next() +{ + if (osdir_list_status != OSDIR_LIST_STARTED) { + return NULL; + } + struct dirent *entry = readdir(osdir_dir); + if (!entry) { + osdir_list_status = OSDIR_LIST_DONE; + return NULL; + } else { + return entry->d_name; + } +} + + +/* osdir_list_finish -- close an open directory */ +void osdir_list_finish() +{ + if (osdir_list_status != OSDIR_LIST_READY) { + closedir(osdir_dir); + } + osdir_list_status = OSDIR_LIST_READY; +} + + +/* xcheck -- return a character if one is present */ +LOCAL int xcheck() +{ + int ch = term_testchar(); + return ch; +} + +/* xgetkey - get a key from the keyboard */ +LVAL xgetkey() {xllastarg(); return (cvfixnum((FIXTYPE)term_getchar()));} + +/* ossymbols - enter os specific symbols */ +void ossymbols(void) {} + +/* xsetupconsole -- used to configure window in Win32 version */ +LVAL xsetupconsole() { return NIL; } + diff --git a/lib-src/libnyquist/nyquist/sys/unix/osx/README.txt b/lib-src/libnyquist/nyquist/sys/unix/osx/README.txt new file mode 100644 index 000000000..17cc86624 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/osx/README.txt @@ -0,0 +1,60 @@ +sys/unix/osx/README.txt -- notes on OS X (Apple) version of Nyquist + +Roger B. Dannenberg +23 April 2011 + +HOW TO REBUILD STUBS TO CALL NYQUIST PRIMITIVES FROM XLISP + +The file nyqsrc/sndfnint.c implements XLISP functions that correspond +to Nyquist primitives such as SND-OSC. This file and a number of +associated files (such as sndfnintdefs.h) are built automatically by +the intgen program. This process is automated in the Linux Makefile, +but here's how to do it under OS X. + +0. COMPILE NYQUIST WITH XCODE +Before changing the sources, make sure you can compile your existing +installation of Nyquist using XCODE. + +1. COMPILE INTGEN WITH XCODE +From XCODE, choose Active Configuration: Deployment, Active Target: +intgen, Active Executable: intgen. + +Build (Command-B). + +Result is in nyquist/macosxproject/build/Deployment/intgen. You might +want to make an alias to this or move it to your ~/bin directory or +change your PATH so you can execute this from the command line without +typing the full path. In the following, I assume simply typing +"intgen" will run the application. + +After setting up intgen to run, the command "which intgen" should +indicate the path to intgen that the shell will use. + +2. WORK IN A TERMINAL WINDOW AND CD TO THE MAIN NYQUIST DIRECTORY +Open a Terminal application. +cd nyquist [or navigate using cd to wherever your nyquist sources are] + +3. GENERATE THE INTERFACE CODE +Note: if you are adding a new primitive, you will want to modify +sys/unix/osx/sndfnint.cmdline by inserting the name of the header (.h) +file for the new primitive. (For a nyquist release, the name should +also go into a list in nyquist/misc/transfiles.lsp and the Makefiles +should be rebuilt, but we'll stick to the Apple-specific tasks here.) + +intgen @sys/unix/osx/sndfnint.cmdline + +The files sndfnint.c, sndfnint.lsp, sndfnintdefs.h, and sndfnintptrs.h +will be generated and placed in the current (nyquist) directory. + +4. INSTALL THE FILES +You might want to make a safe backup copy of the original +nyqsrc/sndfnint.c, nyqsrc/sndfnint.lsp, nyqsrc/sndfnintdefs.h, and +nyqsrc/sndfnintptrs.h for reference. + +Move the new files to nyqsrc: + +mv sndfnint.c sndfnint.lsp sndfnintdefs.h sndfnintptrs.h nyqsrc + +5. RECOMPILE NYQUIST WITH XCODE + + diff --git a/lib-src/libnyquist/nyquist/sys/unix/osx/run b/lib-src/libnyquist/nyquist/sys/unix/osx/run new file mode 100644 index 000000000..bd037c9ef --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/osx/run @@ -0,0 +1,5 @@ +#csh +# INSTRUCTIONS: for developers, in the top nyquist directory: +# ln -l sys/unix/osx/run +# ln -s macosxproject/build/ny +java -cp jnyqide/NyquistIDE.jar jnyqide.Main diff --git a/lib-src/libnyquist/nyquist/sys/unix/osx/sndfnint.cmdline b/lib-src/libnyquist/nyquist/sys/unix/osx/sndfnint.cmdline new file mode 100644 index 000000000..78d041e67 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/osx/sndfnint.cmdline @@ -0,0 +1,105 @@ +sndfnint +nyqsrc/sndfmt.h +nylsf/sndfile.h +nyqsrc/sound.h +nyqsrc/add.h +nyqsrc/avg.h +nyqsrc/compose.h +nyqsrc/convolve.h +nyqsrc/downsample.h +nyqsrc/fft.h +nyqsrc/inverse.h +nyqsrc/multiseq.h +nyqsrc/resamp.h +nyqsrc/resampv.h +nyqsrc/samples.h +nyqsrc/sndmax.h +nyqsrc/sndread.h +nyqsrc/sndseq.h +nyqsrc/sndsliders.h +nyqsrc/sndwrite.h +nyqsrc/yin.h +nyqsrc/nyq-osc-server.h +nyqsrc/trigger.h +nyqsrc/lpanal.h +nyqsrc/phasevocoder.h +nyqsrc/pvshell.h +tran/abs.h +tran/allpoles.h +tran/alpass.h +tran/alpasscv.h +tran/alpassvv.h +tran/amosc.h +tran/areson.h +tran/aresonvc.h +tran/aresoncv.h +tran/aresonvv.h +tran/atone.h +tran/atonev.h +tran/biquadfilt.h +tran/buzz.h +tran/chase.h +tran/clip.h +tran/congen.h +tran/const.h +tran/coterm.h +tran/delaycc.h +tran/delaycv.h +tran/eqbandvvv.h +tran/exp.h +tran/follow.h +tran/fmosc.h +tran/fromobject.h +tran/fromarraystream.h +tran/gate.h +tran/ifft.h +tran/instrclar.h +tran/instrclarall.h +tran/instrclarfreq.h +tran/instrsax.h +tran/instrsaxall.h +tran/instrsaxfreq.h +tran/integrate.h +tran/log.h +tran/lpreson.h +tran/maxv.h +tran/offset.h +tran/oneshot.h +tran/osc.h +tran/partial.h +tran/pluck.h +tran/prod.h +tran/pwl.h +tran/quantize.h +tran/recip.h +tran/reson.h +tran/resonvc.h +tran/resoncv.h +tran/resonvv.h +tran/sampler.h +tran/scale.h +tran/shape.h +tran/sine.h +tran/siosc.h +tran/slope.h +tran/sqrt.h +tran/tapf.h +tran/tapv.h +tran/tone.h +tran/tonev.h +tran/upsample.h +tran/white.h +tran/stkrev.h +tran/stkpitshift.h +tran/stkchorus.h +tran/instrbow.h +tran/instrbowedfreq.h +tran/instrbanded.h +tran/instrmandolin.h +tran/instrsitar.h +tran/instrmodalbar.h +tran/instrflute.h +tran/instrflutefreq.h +tran/instrfluteall.h +tran/fmfb.h +tran/fmfbv.h diff --git a/lib-src/libnyquist/nyquist/sys/unix/osx/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/osx/system.lsp new file mode 100644 index 000000000..2ecd6ed1d --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/osx/system.lsp @@ -0,0 +1,69 @@ +;; system.lsp -- system-dependent lisp code + +; local definition for play +; this one is for Mac OS-X: + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-wave)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "/tmp")) + +(format t "*default-sf-dir* (default sound file directory) is ~A~%" + *default-sf-dir*) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* (strcat (get-user) "-points.dat"))) + + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (or (eq (char filename 0) #\/) + (eq (char filename 0) #\.))) + +; RELATIVE-PATH-P -- test if filename or path is a relative path +; +(defun relative-path-p (filename) + (not (eq (char filename 0) #\/))) + +(setf *file-separator* #\/) + + +;; PLAY-FILE - play a sound file +;; +(defun play-file (name) + (s-save (s-read name) NY:ALL "" :play t)) + + +;; R - replay last file written with PLAY +(defun r () (play-file *default-sound-file*)) + +;;;; use this old version if you want to use sndplay to play +;;;; the result file rather than play the samples as they +;;;; are computed. This version does not autonormalize. +;; PLAY - write value of an expression to file and play it +;; +;(defmacro play (expr) +; `(prog (specs) +; (setf specs (s-save (force-srate *sound-srate* ,expr) +; 1000000000 *default-sound-file*)) +; (r))) +;;;; + +; local definition for play +(defmacro play (expr) + `(s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*)) + +;; use standard s-plot diff --git a/lib-src/libnyquist/nyquist/sys/unix/pl b/lib-src/libnyquist/nyquist/sys/unix/pl new file mode 100644 index 000000000..b58e58c08 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/pl @@ -0,0 +1,2 @@ +graph < points.dat | plot -Ttek + diff --git a/lib-src/libnyquist/nyquist/sys/unix/pmax/Makefile b/lib-src/libnyquist/nyquist/sys/unix/pmax/Makefile new file mode 100644 index 000000000..878479093 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/pmax/Makefile @@ -0,0 +1,520 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is PMAX +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +# Standard list of includes (common to all unix versions) +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Isnd -Ifft + +# system dependent stuff for pmax: + +CC = cc +CFLAGS = -DCMTSTUFF -g $(INCL) +LN = cc +LFLAGS = -lm + + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o \ + xlisp/xlstr.o xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o \ + tran/amosc.o tran/clip.o tran/const.o tran/fmosc.o \ + tran/integrate.o tran/log.o tran/maxv.o tran/osc.o \ + tran/prod.o tran/buzz.o tran/pwl.o tran/recip.o \ + tran/upsample.o tran/scale.o tran/sine.o tran/partial.o \ + tran/white.o tran/tone.o tran/tonev.o tran/atonev.o \ + tran/atone.o tran/reson.o tran/areson.o tran/resonvc.o \ + tran/resoncv.o tran/aresonvc.o tran/aresoncv.o tran/resonvv.o \ + tran/aresonvv.o tran/offset.o tran/slope.o tran/delay.o \ + tran/delaycv.o tran/shape.o tran/sampler.o tran/exp.o \ + tran/siosc.o tran/follow.o tran/gate.o tran/quantize.o \ + tran/ifft.o tran/congen.o tran/fromobject.o tran/fromarraystream.o \ + tran/coterm.o tran/convolve.o tran/alpass.o tran/oneshot.o \ + tran/chase.o tran/tapv.o tran/biquad.o tran/pluck.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o \ + cmt/moxc.o cmt/mem.o cmt/midifile.o cmt/midifns.o \ + cmt/record.o cmt/seq.o cmt/seqmread.o cmt/seqmwrite.o \ + cmt/seqread.o cmt/seqwrite.o cmt/tempomap.o cmt/timebase.o \ + cmt/userio.o nyqsrc/debug.o nyqsrc/falloc.o nyqsrc/add.o \ + nyqsrc/local.o nyqsrc/downsample.o nyqsrc/handlers.o nyqsrc/multiread.o \ + nyqsrc/multiseq.o nyqsrc/samples.o nyqsrc/seqext.o nyqsrc/seqinterf.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndwrite.o nyqsrc/sndmax.o \ + nyqsrc/sound.o nyqsrc/stats.o nyqsrc/compose.o nyqsrc/inverse.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/ffilterkit.o nyqsrc/avg.o \ + nyqsrc/fft.o nyqsrc/sndfail.o fft/fftn.o nyqsrc/sndfnint.o \ + nyqsrc/seqfnint.o snd/audiopmax.o snd/sndpmax.o snd/ieeecvt.o \ + snd/snd.o snd/sndcvt.o snd/sndio.o snd/sndheader.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +NYQHDRS = snd/snd.h nyqsrc/sound.h nyqsrc/downsample.h nyqsrc/sndread.h \ + nyqsrc/sndseq.h nyqsrc/add.h nyqsrc/multiseq.h nyqsrc/samples.h \ + nyqsrc/sndwrite.h nyqsrc/sndmax.h nyqsrc/compose.h nyqsrc/inverse.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/fft.h nyqsrc/avg.h \ + tran/amosc.h tran/clip.h tran/const.h tran/fmosc.h \ + tran/integrate.h tran/log.h tran/maxv.h tran/osc.h \ + tran/prod.h tran/buzz.h tran/pwl.h tran/recip.h \ + tran/upsample.h tran/scale.h tran/sine.h tran/partial.h \ + tran/white.h tran/tone.h tran/tonev.h tran/atonev.h \ + tran/atone.h tran/reson.h tran/areson.h tran/resonvc.h \ + tran/resoncv.h tran/aresonvc.h tran/aresoncv.h tran/resonvv.h \ + tran/aresonvv.h tran/offset.h tran/slope.h tran/delaycc.h \ + tran/delaycv.h tran/shape.h tran/sampler.h tran/exp.h \ + tran/siosc.h tran/follow.h tran/gate.h tran/quantize.h \ + tran/ifft.h tran/congen.h tran/fromobject.h tran/fromarraystream.h \ + tran/coterm.h tran/convolve.h tran/alpass.h tran/oneshot.h \ + tran/chase.h tran/tapv.h tran/biquad.h tran/pluck.h + +CMTHDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h nyqsrc/seqinterf.h \ + cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h cmt/seqmwrite.h + + +EVERYTHING = $(NY) runtime/system.lsp + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +$(NY): $(OBJECTS) + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/pmax/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/pmax/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + cc -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + cc -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndwrite.o: nyqsrc/sndwrite.c nyqsrc/sndwrite.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndwrite.c -o nyqsrc/sndwrite.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/sndfail.o: nyqsrc/sndfail.c + cc -c nyqsrc/sndfail.c -o nyqsrc/sndfail.o $(CFLAGS) + +snd/audiopmax.o: snd/audiopmax.c snd/snd.h + cc -c snd/audiopmax.c -o snd/audiopmax.o $(CFLAGS) + +snd/sndpmax.o: snd/sndpmax.c snd/sndpmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndpmax.c -o snd/sndpmax.o $(CFLAGS) + +snd/ieeecvt.o: snd/ieeecvt.c snd/ieeecvt.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/ieeecvt.c -o snd/ieeecvt.o $(CFLAGS) + +snd/snd.o: snd/snd.c snd/snd.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/snd.c -o snd/snd.o $(CFLAGS) + +snd/sndcvt.o: snd/sndcvt.c snd/snd.h + cc -c snd/sndcvt.c -o snd/sndcvt.o $(CFLAGS) + +snd/sndio.o: snd/sndio.c snd/snd.h + cc -c snd/sndio.c -o snd/sndio.o $(CFLAGS) + +snd/sndheader.o: snd/sndheader.c snd/sndheader.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndheader.c -o snd/sndheader.o $(CFLAGS) + +fft/fftn.o: fft/fftn.c fft/fftn.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c fft/fftn.c -o fft/fftn.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/convolve.o: tran/convolve.c tran/convolve.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/convolve.c -o tran/convolve.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/biquad.o: tran/biquad.c tran/biquad.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/biquad.c -o tran/biquad.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + cc -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + cc -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + cc -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + cc -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + cc -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + cc -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + cc -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + cc -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + cc -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + cc -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + cc -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + cc -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + cc -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + cc -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + cc -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + cc -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + cc -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + cc -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + cc -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + cc -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + cc -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + cc -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + cc -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + cc -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + cc -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + cc -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + cc -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + cc -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + cc -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + cc -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + cc -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + cc -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + cc -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + cc -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + cc -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + cc -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + cc -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + cc -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + cc -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + cc -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + cc -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + cc -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + cc -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + cc -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +misc/unpacker: misc/unpacker.c misc/convert.c + cd misc; make unpacker + +misc/packer: misc/packer.c misc/convert.c + cd misc; make packer + +nyqsrc/sndfnintptrs.h: $(NYQHDRS) snd/snd.h misc/intgen + $(INTGEN) nyqsrc/sndfnint $(NYQHDRS) + +nyqsrc/seqfnintptrs.h: $(CMTHDRS) misc/intgen + $(INTGEN) nyqsrc/seqfnint $(CMTHDRS) + +clean: + cd misc; make clean + rm -f $(OBJECTS) +# Note that these files are machine-generated: + rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h + rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat diff --git a/lib-src/libnyquist/nyquist/sys/unix/pmax/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/pmax/system.lsp new file mode 100644 index 000000000..6371aa0fb --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/pmax/system.lsp @@ -0,0 +1,37 @@ +; machine.lsp -- machine/system-dependent definitions +; rs6000 + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-none)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "/tmp/")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +; local definition for play + + +(defun p6k () + (system (format nil + "/usr/itc/projects/depot/tactus/bin/acpaplay ~A/~A < playparms" + *default-sf-dir* + *default-sound-file*))) + + +(defmacro play (expr) + `(prog (specs playparms) + (setf specs (s-save ',expr 1000000000 *default-sound-file*)) + (setf playparms (open "playparms" :direction :output)) + (format playparms "~A~%16~%2~%~A~%" (car specs) (cadr specs)) + (close playparms) + (p6k))) + + diff --git a/lib-src/libnyquist/nyquist/sys/unix/rs6k/Makefile b/lib-src/libnyquist/nyquist/sys/unix/rs6k/Makefile new file mode 100644 index 000000000..1ba39f466 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/rs6k/Makefile @@ -0,0 +1,529 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is RS6K +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +# Standard list of includes (common to all unix versions) +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Isnd -Ifft + +# system dependent stuff for rs6k: + +MIDI = /afs/cs/project/music/rs6k/midilib +CC = cc +# change -g to -O for optimization +CFLAGS = -DCMTSTUFF -g $(INCL) -I$(MIDI) +XFLAGS = $(CFLAGS) -qlanglvl=extended +LN = xlc -qattr -qlist +LFLAGS = -lm -L$(MIDI) -lmidi -lbsd -lg + + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o \ + xlisp/xlstr.o xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o \ + tran/amosc.o tran/clip.o tran/const.o tran/fmosc.o \ + tran/integrate.o tran/log.o tran/maxv.o tran/osc.o \ + tran/prod.o tran/buzz.o tran/pwl.o tran/recip.o \ + tran/upsample.o tran/scale.o tran/sine.o tran/partial.o \ + tran/white.o tran/tone.o tran/tonev.o tran/atonev.o \ + tran/atone.o tran/reson.o tran/areson.o tran/resonvc.o \ + tran/resoncv.o tran/aresonvc.o tran/aresoncv.o tran/resonvv.o \ + tran/aresonvv.o tran/offset.o tran/slope.o tran/delay.o \ + tran/delaycv.o tran/shape.o tran/sampler.o tran/exp.o \ + tran/siosc.o tran/follow.o tran/gate.o tran/quantize.o \ + tran/ifft.o tran/congen.o tran/fromobject.o tran/fromarraystream.o \ + tran/coterm.o tran/convolve.o tran/alpass.o tran/oneshot.o \ + tran/chase.o tran/tapv.o tran/biquad.o tran/pluck.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o \ + cmt/moxc.o cmt/mem.o cmt/midifile.o cmt/midifns.o \ + cmt/record.o cmt/seq.o cmt/seqmread.o cmt/seqmwrite.o \ + cmt/seqread.o cmt/seqwrite.o cmt/tempomap.o cmt/timebase.o \ + cmt/userio.o nyqsrc/debug.o nyqsrc/falloc.o nyqsrc/add.o \ + nyqsrc/local.o nyqsrc/downsample.o nyqsrc/handlers.o nyqsrc/multiread.o \ + nyqsrc/multiseq.o nyqsrc/samples.o nyqsrc/seqext.o nyqsrc/seqinterf.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndwrite.o nyqsrc/sndmax.o \ + nyqsrc/sound.o nyqsrc/stats.o nyqsrc/compose.o nyqsrc/inverse.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/ffilterkit.o nyqsrc/avg.o \ + nyqsrc/fft.o nyqsrc/sndfail.o fft/fftn.o nyqsrc/sndfnint.o \ + nyqsrc/seqfnint.o snd/audiors6k.o snd/sndrs6k.o snd/ieeecvt.o \ + snd/snd.o snd/sndcvt.o snd/sndio.o snd/sndheader.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +NYQHDRS = snd/snd.h nyqsrc/sound.h nyqsrc/downsample.h nyqsrc/sndread.h \ + nyqsrc/sndseq.h nyqsrc/add.h nyqsrc/multiseq.h nyqsrc/samples.h \ + nyqsrc/sndwrite.h nyqsrc/sndmax.h nyqsrc/compose.h nyqsrc/inverse.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/fft.h nyqsrc/avg.h \ + tran/amosc.h tran/clip.h tran/const.h tran/fmosc.h \ + tran/integrate.h tran/log.h tran/maxv.h tran/osc.h \ + tran/prod.h tran/buzz.h tran/pwl.h tran/recip.h \ + tran/upsample.h tran/scale.h tran/sine.h tran/partial.h \ + tran/white.h tran/tone.h tran/tonev.h tran/atonev.h \ + tran/atone.h tran/reson.h tran/areson.h tran/resonvc.h \ + tran/resoncv.h tran/aresonvc.h tran/aresoncv.h tran/resonvv.h \ + tran/aresonvv.h tran/offset.h tran/slope.h tran/delaycc.h \ + tran/delaycv.h tran/shape.h tran/sampler.h tran/exp.h \ + tran/siosc.h tran/follow.h tran/gate.h tran/quantize.h \ + tran/ifft.h tran/congen.h tran/fromobject.h tran/fromarraystream.h \ + tran/coterm.h tran/convolve.h tran/alpass.h tran/oneshot.h \ + tran/chase.h tran/tapv.h tran/biquad.h tran/pluck.h + +CMTHDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h nyqsrc/seqinterf.h \ + cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h cmt/seqmwrite.h + + +EVERYTHING = $(NY) runtime/system.lsp + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +$(NY): $(OBJECTS) + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/rs6k/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/rs6k/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + cc -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + cc -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndwrite.o: nyqsrc/sndwrite.c nyqsrc/sndwrite.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndwrite.c -o nyqsrc/sndwrite.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/sndfail.o: nyqsrc/sndfail.c + cc -c nyqsrc/sndfail.c -o nyqsrc/sndfail.o $(CFLAGS) + +snd/audiors6k.o: snd/audiors6k.c snd/snd.h + cc -c snd/audiors6k.c -o snd/audiors6k.o $(CFLAGS) + +snd/sndrs6k.o: snd/sndrs6k.c snd/sndrs6k.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndrs6k.c -o snd/sndrs6k.o $(CFLAGS) + +snd/ieeecvt.o: snd/ieeecvt.c snd/ieeecvt.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/ieeecvt.c -o snd/ieeecvt.o $(CFLAGS) + +snd/snd.o: snd/snd.c snd/snd.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/snd.c -o snd/snd.o $(CFLAGS) + +snd/sndcvt.o: snd/sndcvt.c snd/snd.h + cc -c snd/sndcvt.c -o snd/sndcvt.o $(CFLAGS) + +snd/sndio.o: snd/sndio.c snd/snd.h + cc -c snd/sndio.c -o snd/sndio.o $(CFLAGS) + +snd/sndheader.o: snd/sndheader.c snd/sndheader.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndheader.c -o snd/sndheader.o $(CFLAGS) + +fft/fftn.o: fft/fftn.c fft/fftn.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c fft/fftn.c -o fft/fftn.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/convolve.o: tran/convolve.c tran/convolve.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/convolve.c -o tran/convolve.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/biquad.o: tran/biquad.c tran/biquad.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/biquad.c -o tran/biquad.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + cc -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + cc -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + cc -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + cc -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + cc -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + cc -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + cc -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + cc -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + cc -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + cc -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + cc -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + cc -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + cc -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + cc -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + cc -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + cc -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + cc -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + cc -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + cc -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + cc -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + cc -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + cc -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + cc -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + cc -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + cc -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + cc -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + cc -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + cc -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + cc -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + cc -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + cc -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + cc -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + cc -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + cc -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + cc -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + cc -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + cc -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + cc -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + cc -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + cc -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + cc -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + cc -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + cc -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + cc -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +misc/unpacker: misc/unpacker.c misc/convert.c + cd misc; make unpacker + +misc/packer: misc/packer.c misc/convert.c + cd misc; make packer + +nyqsrc/sndfnintptrs.h: $(NYQHDRS) snd/snd.h misc/intgen + $(INTGEN) nyqsrc/sndfnint $(NYQHDRS) + +nyqsrc/seqfnintptrs.h: $(CMTHDRS) misc/intgen + $(INTGEN) nyqsrc/seqfnint $(CMTHDRS) + +clean: + cd misc; make clean + rm -f $(OBJECTS) +# Note that these files are machine-generated: + rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h + rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat + +tar: cleaner + sh -v sys/unix/cmu/tar.script + +backup: cleaner + sh -v sys/unix/cmu/backup.script diff --git a/lib-src/libnyquist/nyquist/sys/unix/rs6k/plotscript b/lib-src/libnyquist/nyquist/sys/unix/rs6k/plotscript new file mode 100644 index 000000000..a26ea6028 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/rs6k/plotscript @@ -0,0 +1,3 @@ +cat $1 | graph | tplot -Ttek +echo "Type ^D to exit" +cat diff --git a/lib-src/libnyquist/nyquist/sys/unix/rs6k/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/rs6k/system.lsp new file mode 100644 index 000000000..e64e0709d --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/rs6k/system.lsp @@ -0,0 +1,80 @@ +; machine.lsp -- machine/system-dependent definitions +; rs6000 + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-NeXT)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "/tmp/")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* "points.dat")) + +; turn off switch to play sound as it is computed +(setf *soundenable* nil) + +; local definition for play + +(defmacro play (expr) + `(let () + (s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*) + (r))) + + +(defun r () + (play-file *default-sound-file*)) + + +; PLAY-FILE -- play a file +(defun play-file (name) + (system (format nil "acpaplay ~A" (soundfilename name)))) + + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (or (eq (char filename 0) #\/) + (eq (char filename 0) #\.))) + +(setf *file-separator* #\/) + + +; save the standard function to write points to a file +; +(setfn s-plot-points s-plot) + + + +; S-PLOT - plot a small number of points +; +(defun s-plot (&rest args) + (let ((n (soundfilename *default-plot-file*))) + (apply #'s-plot-points args) + (cond ((boundp '*plotscript-file*)) + (t + (format t "*plotscript-file* is unbound, setting it to: \n") + (format t " sys/unix/rs6k/plotscript\n") + (format t "You may need to set it to a full path\n") + (setf *plotscript-file* "sys/unix/rs6k/plotscript"))) + (system (format nil "xterm -t -e ~A ~A" *plotscript-file* n)))) + + +; S-EDIT - run the audio editor on a sound +; +(defmacro s-edit (&optional expr) + `(prog () + (if ,expr (s-save ,expr 1000000000 *default-sound-file*)) + (system (format nil "audio_editor ~A &" + (soundfilename *default-sound-file*))))) + diff --git a/lib-src/libnyquist/nyquist/sys/unix/setup b/lib-src/libnyquist/nyquist/sys/unix/setup new file mode 100644 index 000000000..06a1ad843 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/setup @@ -0,0 +1,10 @@ +mkdir cmt demos lib misc nyqsrc runtime sys test tran xlisp +cd sys +mkdir unix mac win +cd unix +mkdir cmu next pmax rs6k sgi sparc +cd .. +cd win +mkdir msvc +cd .. +cd .. diff --git a/lib-src/libnyquist/nyquist/sys/unix/sgi/Makefile b/lib-src/libnyquist/nyquist/sys/unix/sgi/Makefile new file mode 100644 index 000000000..309bc1978 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/sgi/Makefile @@ -0,0 +1,521 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is SGI +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +# Standard list of includes (common to all unix versions) +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Isnd -Ifft + +# system dependent stuff for sgi: + +CC = cc +CFLAGS = -DCMTSTUFF -g $(INCL) +LN = cc +LFLAGS = -lm +# you would need -lmd if UNIX_IRIX_MIDIFNS were defined in midifns.c + + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o \ + xlisp/xlstr.o xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o \ + tran/amosc.o tran/clip.o tran/const.o tran/fmosc.o \ + tran/integrate.o tran/log.o tran/maxv.o tran/osc.o \ + tran/prod.o tran/buzz.o tran/pwl.o tran/recip.o \ + tran/upsample.o tran/scale.o tran/sine.o tran/partial.o \ + tran/white.o tran/tone.o tran/tonev.o tran/atonev.o \ + tran/atone.o tran/reson.o tran/areson.o tran/resonvc.o \ + tran/resoncv.o tran/aresonvc.o tran/aresoncv.o tran/resonvv.o \ + tran/aresonvv.o tran/offset.o tran/slope.o tran/delay.o \ + tran/delaycv.o tran/shape.o tran/sampler.o tran/exp.o \ + tran/siosc.o tran/follow.o tran/gate.o tran/quantize.o \ + tran/ifft.o tran/congen.o tran/fromobject.o tran/fromarraystream.o \ + tran/coterm.o tran/convolve.o tran/alpass.o tran/oneshot.o \ + tran/chase.o tran/tapv.o tran/biquad.o tran/pluck.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o \ + cmt/moxc.o cmt/mem.o cmt/midifile.o cmt/midifns.o \ + cmt/record.o cmt/seq.o cmt/seqmread.o cmt/seqmwrite.o \ + cmt/seqread.o cmt/seqwrite.o cmt/tempomap.o cmt/timebase.o \ + cmt/userio.o nyqsrc/debug.o nyqsrc/falloc.o nyqsrc/add.o \ + nyqsrc/local.o nyqsrc/downsample.o nyqsrc/handlers.o nyqsrc/multiread.o \ + nyqsrc/multiseq.o nyqsrc/samples.o nyqsrc/seqext.o nyqsrc/seqinterf.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndwrite.o nyqsrc/sndmax.o \ + nyqsrc/sound.o nyqsrc/stats.o nyqsrc/compose.o nyqsrc/inverse.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/ffilterkit.o nyqsrc/avg.o \ + nyqsrc/fft.o nyqsrc/sndfail.o fft/fftn.o nyqsrc/sndfnint.o \ + nyqsrc/seqfnint.o snd/audiosgi.o snd/sndsgi.o snd/ieeecvt.o \ + snd/snd.o snd/sndcvt.o snd/sndio.o snd/sndheader.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +NYQHDRS = snd/snd.h nyqsrc/sound.h nyqsrc/downsample.h nyqsrc/sndread.h \ + nyqsrc/sndseq.h nyqsrc/add.h nyqsrc/multiseq.h nyqsrc/samples.h \ + nyqsrc/sndwrite.h nyqsrc/sndmax.h nyqsrc/compose.h nyqsrc/inverse.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/fft.h nyqsrc/avg.h \ + tran/amosc.h tran/clip.h tran/const.h tran/fmosc.h \ + tran/integrate.h tran/log.h tran/maxv.h tran/osc.h \ + tran/prod.h tran/buzz.h tran/pwl.h tran/recip.h \ + tran/upsample.h tran/scale.h tran/sine.h tran/partial.h \ + tran/white.h tran/tone.h tran/tonev.h tran/atonev.h \ + tran/atone.h tran/reson.h tran/areson.h tran/resonvc.h \ + tran/resoncv.h tran/aresonvc.h tran/aresoncv.h tran/resonvv.h \ + tran/aresonvv.h tran/offset.h tran/slope.h tran/delaycc.h \ + tran/delaycv.h tran/shape.h tran/sampler.h tran/exp.h \ + tran/siosc.h tran/follow.h tran/gate.h tran/quantize.h \ + tran/ifft.h tran/congen.h tran/fromobject.h tran/fromarraystream.h \ + tran/coterm.h tran/convolve.h tran/alpass.h tran/oneshot.h \ + tran/chase.h tran/tapv.h tran/biquad.h tran/pluck.h + +CMTHDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h nyqsrc/seqinterf.h \ + cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h cmt/seqmwrite.h + + +EVERYTHING = $(NY) runtime/system.lsp + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +$(NY): $(OBJECTS) + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/sgi/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/sgi/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + cc -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + cc -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndwrite.o: nyqsrc/sndwrite.c nyqsrc/sndwrite.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndwrite.c -o nyqsrc/sndwrite.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/sndfail.o: nyqsrc/sndfail.c + cc -c nyqsrc/sndfail.c -o nyqsrc/sndfail.o $(CFLAGS) + +snd/audiosgi.o: snd/audiosgi.c snd/snd.h + cc -c snd/audiosgi.c -o snd/audiosgi.o $(CFLAGS) + +snd/sndsgi.o: snd/sndsgi.c snd/sndsgi.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndsgi.c -o snd/sndsgi.o $(CFLAGS) + +snd/ieeecvt.o: snd/ieeecvt.c snd/ieeecvt.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/ieeecvt.c -o snd/ieeecvt.o $(CFLAGS) + +snd/snd.o: snd/snd.c snd/snd.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/snd.c -o snd/snd.o $(CFLAGS) + +snd/sndcvt.o: snd/sndcvt.c snd/snd.h + cc -c snd/sndcvt.c -o snd/sndcvt.o $(CFLAGS) + +snd/sndio.o: snd/sndio.c snd/snd.h + cc -c snd/sndio.c -o snd/sndio.o $(CFLAGS) + +snd/sndheader.o: snd/sndheader.c snd/sndheader.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndheader.c -o snd/sndheader.o $(CFLAGS) + +fft/fftn.o: fft/fftn.c fft/fftn.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c fft/fftn.c -o fft/fftn.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/convolve.o: tran/convolve.c tran/convolve.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/convolve.c -o tran/convolve.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/biquad.o: tran/biquad.c tran/biquad.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/biquad.c -o tran/biquad.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + cc -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + cc -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + cc -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + cc -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + cc -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + cc -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + cc -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + cc -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + cc -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + cc -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + cc -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + cc -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + cc -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + cc -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + cc -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + cc -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + cc -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + cc -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + cc -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + cc -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + cc -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + cc -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + cc -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + cc -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + cc -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + cc -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + cc -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + cc -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + cc -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + cc -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + cc -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + cc -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + cc -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + cc -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + cc -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + cc -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + cc -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + cc -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + cc -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + cc -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + cc -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + cc -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + cc -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + cc -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +misc/unpacker: misc/unpacker.c misc/convert.c + cd misc; make unpacker + +misc/packer: misc/packer.c misc/convert.c + cd misc; make packer + +nyqsrc/sndfnintptrs.h: $(NYQHDRS) snd/snd.h misc/intgen + $(INTGEN) nyqsrc/sndfnint $(NYQHDRS) + +nyqsrc/seqfnintptrs.h: $(CMTHDRS) misc/intgen + $(INTGEN) nyqsrc/seqfnint $(CMTHDRS) + +clean: + cd misc; make clean + rm -f $(OBJECTS) +# Note that these files are machine-generated: + rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h + rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat diff --git a/lib-src/libnyquist/nyquist/sys/unix/sgi/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/sgi/system.lsp new file mode 100644 index 000000000..062a62f61 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/sgi/system.lsp @@ -0,0 +1,46 @@ +; machine.lsp -- machine/system-dependent definitions +; SGI/IRIX + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-AIFF)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "/tmp/")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +(if (not (boundp '*default-plot-file*)) + (setf *default-plot-file* "points.dat")) + +(defmacro play (expr) + `(let () + (s-save-autonorm ,expr NY:ALL *default-sound-file* :play *soundenable*) + (r))) + +(defun r () + (play-file *default-sound-file*)) + +; PLAY-FILE -- play a file +(defun play-file (name) + (system (strcat "sfplay " (soundfilename name)))) + + +; FULL-NAME-P -- test if file name is a full path or relative path +; +; (otherwise the *default-sf-dir* will be prepended +; +(defun full-name-p (filename) + (or (eq (char filename 0) #\/) + (eq (char filename 0) #\.))) + +(setf *file-separator* #\/) + +(sound-off) ; sgi implementation does not support real-time audio output yet + diff --git a/lib-src/libnyquist/nyquist/sys/unix/sndsystem.h b/lib-src/libnyquist/nyquist/sys/unix/sndsystem.h new file mode 100644 index 000000000..be8e49c00 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/sndsystem.h @@ -0,0 +1,41 @@ +/* sndsystem.h -- system-specific definitions */ +/* + NOTES: you need a different sndswitches.h for each implementation, so +this is a separate file. Things you need to define here: + +1) Either UNIX, WIN32, or MACINTOSH should be defined. + +2) Either the following function declaration: + void snd_fail(char *msg); +or + #define snd_fail(msg) ... + +3) typedef FASTFLOAT to be either a double or a float, whichever +computes faster (PowerPCs are faster at double math than float math) + +4) typedef MEMFLOAT to be how you would store a sample in memory +(this should normally be float) + +5) min() must be defined (either a macro or a function) + +6) max() must be defined (either a macro or a function) + +*/ + +#define UNIX + +#define snd_fail(msg) xlfail(msg) +#define snd_warn(msg) errputstr(msg) +typedef double FASTFLOAT; +typedef float MEMFLOAT; + +/* avoid conflict with Windows */ +#ifndef max + +/* min(n, sizeof(long)) doesn't work on RS6K without this: + * (I never tracked down what min() was called and what was wrong.) + */ +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define max(a, b) ((a) > (b) ? (a) : (b)) + +#endif diff --git a/lib-src/libnyquist/nyquist/sys/unix/sparc/Makefile b/lib-src/libnyquist/nyquist/sys/unix/sparc/Makefile new file mode 100644 index 000000000..5a0fba29b --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/sparc/Makefile @@ -0,0 +1,520 @@ +# +# Makefile for Nyquist, SYSTEM-TYPE is SPARC +# run make in the top-level Nyquist directory to compile Nyquist +# +# NOTE: this file is machine-generated. DO NOT EDIT! +# Instead, modify makefile.lsp and regenerate the makefile. +# Ports and bug fixes are welcome - please mail them to +# dannenberg@cs.cmu.edu. Thanks. +# + +# This is the resulting executable (normally "ny"): +NY = ny + +# Standard list of includes (common to all unix versions) +INCL = -Inyqsrc -Itran -Ixlisp -Isys/unix -Icmt -Isnd -Ifft + +# system dependent stuff for sparc: + +CC = gcc +CFLAGS = -DCMTSTUFF -g $(INCL) +LN = $(CC) +LFLAGS = -lm + + +INTGEN = misc/intgen + +# Object files for Nyquist: +OBJECTS = xlisp/extern.o xlisp/xldmem.o xlisp/xlbfun.o xlisp/xlcont.o \ + xlisp/xldbug.o xlisp/xleval.o xlisp/xlfio.o xlisp/xlftab.o \ + xlisp/xlglob.o xlisp/xlimage.o xlisp/xlinit.o xlisp/xlio.o \ + xlisp/xlisp.o xlisp/xljump.o xlisp/xllist.o xlisp/xlmath.o \ + xlisp/xlobj.o xlisp/xlpp.o xlisp/xlprin.o xlisp/xlread.o \ + xlisp/xlstr.o xlisp/xlsubr.o xlisp/xlsym.o xlisp/xlsys.o \ + tran/amosc.o tran/clip.o tran/const.o tran/fmosc.o \ + tran/integrate.o tran/log.o tran/maxv.o tran/osc.o \ + tran/prod.o tran/buzz.o tran/pwl.o tran/recip.o \ + tran/upsample.o tran/scale.o tran/sine.o tran/partial.o \ + tran/white.o tran/tone.o tran/tonev.o tran/atonev.o \ + tran/atone.o tran/reson.o tran/areson.o tran/resonvc.o \ + tran/resoncv.o tran/aresonvc.o tran/aresoncv.o tran/resonvv.o \ + tran/aresonvv.o tran/offset.o tran/slope.o tran/delay.o \ + tran/delaycv.o tran/shape.o tran/sampler.o tran/exp.o \ + tran/siosc.o tran/follow.o tran/gate.o tran/quantize.o \ + tran/ifft.o tran/congen.o tran/fromobject.o tran/fromarraystream.o \ + tran/coterm.o tran/convolve.o tran/alpass.o tran/oneshot.o \ + tran/chase.o tran/tapv.o tran/biquad.o tran/pluck.o \ + cmt/cext.o cmt/cleanup.o cmt/cmdline.o cmt/cmtcmd.o \ + cmt/moxc.o cmt/mem.o cmt/midifile.o cmt/midifns.o \ + cmt/record.o cmt/seq.o cmt/seqmread.o cmt/seqmwrite.o \ + cmt/seqread.o cmt/seqwrite.o cmt/tempomap.o cmt/timebase.o \ + cmt/userio.o nyqsrc/debug.o nyqsrc/falloc.o nyqsrc/add.o \ + nyqsrc/local.o nyqsrc/downsample.o nyqsrc/handlers.o nyqsrc/multiread.o \ + nyqsrc/multiseq.o nyqsrc/samples.o nyqsrc/seqext.o nyqsrc/seqinterf.o \ + nyqsrc/sndread.o nyqsrc/sndseq.o nyqsrc/sndwrite.o nyqsrc/sndmax.o \ + nyqsrc/sound.o nyqsrc/stats.o nyqsrc/compose.o nyqsrc/inverse.o \ + nyqsrc/resamp.o nyqsrc/resampv.o nyqsrc/ffilterkit.o nyqsrc/avg.o \ + nyqsrc/fft.o nyqsrc/sndfail.o fft/fftn.o nyqsrc/sndfnint.o \ + nyqsrc/seqfnint.o snd/audiosparc.o snd/sndsparc.o snd/ieeecvt.o \ + snd/snd.o snd/sndcvt.o snd/sndio.o snd/sndheader.o \ + sys/unix/osstuff.o sys/unix/term.o + +# Sound functions to add to xlisp +NYQHDRS = snd/snd.h nyqsrc/sound.h nyqsrc/downsample.h nyqsrc/sndread.h \ + nyqsrc/sndseq.h nyqsrc/add.h nyqsrc/multiseq.h nyqsrc/samples.h \ + nyqsrc/sndwrite.h nyqsrc/sndmax.h nyqsrc/compose.h nyqsrc/inverse.h \ + nyqsrc/resamp.h nyqsrc/resampv.h nyqsrc/fft.h nyqsrc/avg.h \ + tran/amosc.h tran/clip.h tran/const.h tran/fmosc.h \ + tran/integrate.h tran/log.h tran/maxv.h tran/osc.h \ + tran/prod.h tran/buzz.h tran/pwl.h tran/recip.h \ + tran/upsample.h tran/scale.h tran/sine.h tran/partial.h \ + tran/white.h tran/tone.h tran/tonev.h tran/atonev.h \ + tran/atone.h tran/reson.h tran/areson.h tran/resonvc.h \ + tran/resoncv.h tran/aresonvc.h tran/aresoncv.h tran/resonvv.h \ + tran/aresonvv.h tran/offset.h tran/slope.h tran/delaycc.h \ + tran/delaycv.h tran/shape.h tran/sampler.h tran/exp.h \ + tran/siosc.h tran/follow.h tran/gate.h tran/quantize.h \ + tran/ifft.h tran/congen.h tran/fromobject.h tran/fromarraystream.h \ + tran/coterm.h tran/convolve.h tran/alpass.h tran/oneshot.h \ + tran/chase.h tran/tapv.h tran/biquad.h tran/pluck.h + +CMTHDRS = cmt/seqdecls.h nyqsrc/seqext.h cmt/seq.h nyqsrc/seqinterf.h \ + cmt/seqread.h cmt/seqmread.h cmt/seqwrite.h cmt/seqmwrite.h + + +EVERYTHING = $(NY) runtime/system.lsp + +CURRENT = $(EVERYTHING) + +current: $(CURRENT) + +$(NY): $(OBJECTS) + $(LN) $(OBJECTS) $(LFLAGS) -o $(NY) + +# copy appropriate system.lsp and make it read-only; +# changes should be made to sys/unix//system.lsp +runtime/system.lsp: sys/unix/sparc/system.lsp + chmod +w runtime/system.lsp + cp -p sys/unix/sparc/system.lsp runtime/system.lsp + chmod -w runtime/system.lsp + +nyqsrc/debug.o: nyqsrc/debug.c nyqsrc/debug.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/debug.c -o nyqsrc/debug.o $(CFLAGS) + +nyqsrc/falloc.o: nyqsrc/falloc.c nyqsrc/falloc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/falloc.c -o nyqsrc/falloc.o $(CFLAGS) + +nyqsrc/add.o: nyqsrc/add.c nyqsrc/add.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/add.c -o nyqsrc/add.o $(CFLAGS) + +nyqsrc/local.o: nyqsrc/local.c xlisp/xlisp.h nyqsrc/sound.h + cc -c nyqsrc/local.c -o nyqsrc/local.o $(CFLAGS) + +nyqsrc/downsample.o: nyqsrc/downsample.c nyqsrc/downsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/downsample.c -o nyqsrc/downsample.o $(CFLAGS) + +nyqsrc/handlers.o: nyqsrc/handlers.c + cc -c nyqsrc/handlers.c -o nyqsrc/handlers.o $(CFLAGS) + +nyqsrc/multiread.o: nyqsrc/multiread.c nyqsrc/multiread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiread.c -o nyqsrc/multiread.o $(CFLAGS) + +nyqsrc/multiseq.o: nyqsrc/multiseq.c nyqsrc/multiseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/multiseq.c -o nyqsrc/multiseq.o $(CFLAGS) + +nyqsrc/samples.o: nyqsrc/samples.c nyqsrc/samples.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/samples.c -o nyqsrc/samples.o $(CFLAGS) + +nyqsrc/seqext.o: nyqsrc/seqext.c nyqsrc/seqext.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqext.c -o nyqsrc/seqext.o $(CFLAGS) + +nyqsrc/seqinterf.o: nyqsrc/seqinterf.c nyqsrc/seqinterf.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/seqinterf.c -o nyqsrc/seqinterf.o $(CFLAGS) + +nyqsrc/sndread.o: nyqsrc/sndread.c nyqsrc/sndread.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndread.c -o nyqsrc/sndread.o $(CFLAGS) + +nyqsrc/sndseq.o: nyqsrc/sndseq.c nyqsrc/sndseq.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndseq.c -o nyqsrc/sndseq.o $(CFLAGS) + +nyqsrc/sndwrite.o: nyqsrc/sndwrite.c nyqsrc/sndwrite.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndwrite.c -o nyqsrc/sndwrite.o $(CFLAGS) + +nyqsrc/sndmax.o: nyqsrc/sndmax.c nyqsrc/sndmax.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sndmax.c -o nyqsrc/sndmax.o $(CFLAGS) + +nyqsrc/sound.o: nyqsrc/sound.c nyqsrc/sound.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/sound.c -o nyqsrc/sound.o $(CFLAGS) + +nyqsrc/stats.o: nyqsrc/stats.c nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/stats.c -o nyqsrc/stats.o $(CFLAGS) + +nyqsrc/compose.o: nyqsrc/compose.c nyqsrc/compose.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/compose.c -o nyqsrc/compose.o $(CFLAGS) + +nyqsrc/inverse.o: nyqsrc/inverse.c nyqsrc/inverse.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/inverse.c -o nyqsrc/inverse.o $(CFLAGS) + +nyqsrc/resamp.o: nyqsrc/resamp.c nyqsrc/resamp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resamp.c -o nyqsrc/resamp.o $(CFLAGS) + +nyqsrc/resampv.o: nyqsrc/resampv.c nyqsrc/resampv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/resampv.c -o nyqsrc/resampv.o $(CFLAGS) + +nyqsrc/ffilterkit.o: nyqsrc/ffilterkit.c nyqsrc/ffilterkit.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/ffilterkit.c -o nyqsrc/ffilterkit.o $(CFLAGS) + +nyqsrc/avg.o: nyqsrc/avg.c nyqsrc/avg.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/avg.c -o nyqsrc/avg.o $(CFLAGS) + +nyqsrc/fft.o: nyqsrc/fft.c nyqsrc/fft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c nyqsrc/fft.c -o nyqsrc/fft.o $(CFLAGS) + +nyqsrc/sndfail.o: nyqsrc/sndfail.c + cc -c nyqsrc/sndfail.c -o nyqsrc/sndfail.o $(CFLAGS) + +snd/audiosparc.o: snd/audiosparc.c snd/snd.h + cc -c snd/audiosparc.c -o snd/audiosparc.o $(CFLAGS) + +snd/sndsparc.o: snd/sndsparc.c snd/sndsparc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndsparc.c -o snd/sndsparc.o $(CFLAGS) + +snd/ieeecvt.o: snd/ieeecvt.c snd/ieeecvt.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/ieeecvt.c -o snd/ieeecvt.o $(CFLAGS) + +snd/snd.o: snd/snd.c snd/snd.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/snd.c -o snd/snd.o $(CFLAGS) + +snd/sndcvt.o: snd/sndcvt.c snd/snd.h + cc -c snd/sndcvt.c -o snd/sndcvt.o $(CFLAGS) + +snd/sndio.o: snd/sndio.c snd/snd.h + cc -c snd/sndio.c -o snd/sndio.o $(CFLAGS) + +snd/sndheader.o: snd/sndheader.c snd/sndheader.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c snd/sndheader.c -o snd/sndheader.o $(CFLAGS) + +fft/fftn.o: fft/fftn.c fft/fftn.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c fft/fftn.c -o fft/fftn.o $(CFLAGS) + +tran/amosc.o: tran/amosc.c tran/amosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/amosc.c -o tran/amosc.o $(CFLAGS) + +tran/clip.o: tran/clip.c tran/clip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/clip.c -o tran/clip.o $(CFLAGS) + +tran/const.o: tran/const.c tran/const.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/const.c -o tran/const.o $(CFLAGS) + +tran/fmosc.o: tran/fmosc.c tran/fmosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fmosc.c -o tran/fmosc.o $(CFLAGS) + +tran/integrate.o: tran/integrate.c tran/integrate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/integrate.c -o tran/integrate.o $(CFLAGS) + +tran/log.o: tran/log.c tran/log.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/log.c -o tran/log.o $(CFLAGS) + +tran/maxv.o: tran/maxv.c tran/maxv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/maxv.c -o tran/maxv.o $(CFLAGS) + +tran/osc.o: tran/osc.c tran/osc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/osc.c -o tran/osc.o $(CFLAGS) + +tran/prod.o: tran/prod.c tran/prod.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/prod.c -o tran/prod.o $(CFLAGS) + +tran/buzz.o: tran/buzz.c tran/buzz.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/buzz.c -o tran/buzz.o $(CFLAGS) + +tran/pwl.o: tran/pwl.c tran/pwl.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pwl.c -o tran/pwl.o $(CFLAGS) + +tran/recip.o: tran/recip.c tran/recip.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/recip.c -o tran/recip.o $(CFLAGS) + +tran/upsample.o: tran/upsample.c tran/upsample.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/upsample.c -o tran/upsample.o $(CFLAGS) + +tran/scale.o: tran/scale.c tran/scale.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/scale.c -o tran/scale.o $(CFLAGS) + +tran/sine.o: tran/sine.c tran/sine.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sine.c -o tran/sine.o $(CFLAGS) + +tran/partial.o: tran/partial.c tran/partial.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/partial.c -o tran/partial.o $(CFLAGS) + +tran/white.o: tran/white.c tran/white.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/white.c -o tran/white.o $(CFLAGS) + +tran/tone.o: tran/tone.c tran/tone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tone.c -o tran/tone.o $(CFLAGS) + +tran/tonev.o: tran/tonev.c tran/tonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tonev.c -o tran/tonev.o $(CFLAGS) + +tran/atonev.o: tran/atonev.c tran/atonev.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atonev.c -o tran/atonev.o $(CFLAGS) + +tran/atone.o: tran/atone.c tran/atone.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/atone.c -o tran/atone.o $(CFLAGS) + +tran/reson.o: tran/reson.c tran/reson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/reson.c -o tran/reson.o $(CFLAGS) + +tran/areson.o: tran/areson.c tran/areson.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/areson.c -o tran/areson.o $(CFLAGS) + +tran/resonvc.o: tran/resonvc.c tran/resonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvc.c -o tran/resonvc.o $(CFLAGS) + +tran/resoncv.o: tran/resoncv.c tran/resoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resoncv.c -o tran/resoncv.o $(CFLAGS) + +tran/aresonvc.o: tran/aresonvc.c tran/aresonvc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvc.c -o tran/aresonvc.o $(CFLAGS) + +tran/aresoncv.o: tran/aresoncv.c tran/aresoncv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresoncv.c -o tran/aresoncv.o $(CFLAGS) + +tran/resonvv.o: tran/resonvv.c tran/resonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/resonvv.c -o tran/resonvv.o $(CFLAGS) + +tran/aresonvv.o: tran/aresonvv.c tran/aresonvv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/aresonvv.c -o tran/aresonvv.o $(CFLAGS) + +tran/offset.o: tran/offset.c tran/offset.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/offset.c -o tran/offset.o $(CFLAGS) + +tran/slope.o: tran/slope.c tran/slope.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/slope.c -o tran/slope.o $(CFLAGS) + +tran/delaycc.o: tran/delaycc.c tran/delaycc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycc.c -o tran/delaycc.o $(CFLAGS) + +tran/delaycv.o: tran/delaycv.c tran/delaycv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/delaycv.c -o tran/delaycv.o $(CFLAGS) + +tran/shape.o: tran/shape.c tran/shape.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/shape.c -o tran/shape.o $(CFLAGS) + +tran/sampler.o: tran/sampler.c tran/sampler.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/sampler.c -o tran/sampler.o $(CFLAGS) + +tran/exp.o: tran/exp.c tran/exp.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/exp.c -o tran/exp.o $(CFLAGS) + +tran/siosc.o: tran/siosc.c tran/siosc.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/siosc.c -o tran/siosc.o $(CFLAGS) + +tran/follow.o: tran/follow.c tran/follow.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/follow.c -o tran/follow.o $(CFLAGS) + +tran/gate.o: tran/gate.c tran/gate.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/gate.c -o tran/gate.o $(CFLAGS) + +tran/quantize.o: tran/quantize.c tran/quantize.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/quantize.c -o tran/quantize.o $(CFLAGS) + +tran/ifft.o: tran/ifft.c tran/ifft.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/ifft.c -o tran/ifft.o $(CFLAGS) + +tran/congen.o: tran/congen.c tran/congen.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/congen.c -o tran/congen.o $(CFLAGS) + +tran/fromobject.o: tran/fromobject.c tran/fromobject.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromobject.c -o tran/fromobject.o $(CFLAGS) + +tran/fromarraystream.o: tran/fromarraystream.c tran/fromarraystream.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/fromarraystream.c -o tran/fromarraystream.o $(CFLAGS) + +tran/coterm.o: tran/coterm.c tran/coterm.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/coterm.c -o tran/coterm.o $(CFLAGS) + +tran/convolve.o: tran/convolve.c tran/convolve.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/convolve.c -o tran/convolve.o $(CFLAGS) + +tran/alpass.o: tran/alpass.c tran/alpass.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/alpass.c -o tran/alpass.o $(CFLAGS) + +tran/oneshot.o: tran/oneshot.c tran/oneshot.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/oneshot.c -o tran/oneshot.o $(CFLAGS) + +tran/chase.o: tran/chase.c tran/chase.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/chase.c -o tran/chase.o $(CFLAGS) + +tran/tapv.o: tran/tapv.c tran/tapv.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/tapv.c -o tran/tapv.o $(CFLAGS) + +tran/biquad.o: tran/biquad.c tran/biquad.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/biquad.c -o tran/biquad.o $(CFLAGS) + +tran/pluck.o: tran/pluck.c tran/pluck.h nyqsrc/sound.h nyqsrc/falloc.h nyqsrc/cque.h + cc -c tran/pluck.c -o tran/pluck.o $(CFLAGS) + +nyqsrc/sndfnint.o: nyqsrc/sndfnint.c + cc -c nyqsrc/sndfnint.c -o nyqsrc/sndfnint.o $(CFLAGS) + +nyqsrc/seqfnint.o: nyqsrc/seqfnint.c + cc -c nyqsrc/seqfnint.c -o nyqsrc/seqfnint.o $(CFLAGS) + +xlisp/xlftab.o: nyqsrc/sndfnintptrs.h nyqsrc/sndfnintdefs.h nyqsrc/seqfnintptrs.h nyqsrc/seqfnintdefs.h + cc -c xlisp/xlftab.c -o xlisp/xlftab.o $(CFLAGS) + +xlisp/extern.o: xlisp/extern.c + cc -c xlisp/extern.c -o xlisp/extern.o $(CFLAGS) + +xlisp/xldmem.o: xlisp/xldmem.c + cc -c xlisp/xldmem.c -o xlisp/xldmem.o $(CFLAGS) + +xlisp/xlbfun.o: xlisp/xlbfun.c + cc -c xlisp/xlbfun.c -o xlisp/xlbfun.o $(CFLAGS) + +xlisp/xlcont.o: xlisp/xlcont.c + cc -c xlisp/xlcont.c -o xlisp/xlcont.o $(CFLAGS) + +xlisp/xldbug.o: xlisp/xldbug.c + cc -c xlisp/xldbug.c -o xlisp/xldbug.o $(CFLAGS) + +xlisp/xleval.o: xlisp/xleval.c + cc -c xlisp/xleval.c -o xlisp/xleval.o $(CFLAGS) + +xlisp/xlfio.o: xlisp/xlfio.c + cc -c xlisp/xlfio.c -o xlisp/xlfio.o $(CFLAGS) + +xlisp/xlglob.o: xlisp/xlglob.c + cc -c xlisp/xlglob.c -o xlisp/xlglob.o $(CFLAGS) + +xlisp/xlimage.o: xlisp/xlimage.c + cc -c xlisp/xlimage.c -o xlisp/xlimage.o $(CFLAGS) + +xlisp/xlinit.o: xlisp/xlinit.c + cc -c xlisp/xlinit.c -o xlisp/xlinit.o $(CFLAGS) + +xlisp/xlio.o: xlisp/xlio.c + cc -c xlisp/xlio.c -o xlisp/xlio.o $(CFLAGS) + +xlisp/xlisp.o: xlisp/xlisp.c + cc -c xlisp/xlisp.c -o xlisp/xlisp.o $(CFLAGS) + +xlisp/xljump.o: xlisp/xljump.c + cc -c xlisp/xljump.c -o xlisp/xljump.o $(CFLAGS) + +xlisp/xllist.o: xlisp/xllist.c + cc -c xlisp/xllist.c -o xlisp/xllist.o $(CFLAGS) + +xlisp/xlmath.o: xlisp/xlmath.c + cc -c xlisp/xlmath.c -o xlisp/xlmath.o $(CFLAGS) + +xlisp/xlobj.o: xlisp/xlobj.c + cc -c xlisp/xlobj.c -o xlisp/xlobj.o $(CFLAGS) + +xlisp/xlpp.o: xlisp/xlpp.c + cc -c xlisp/xlpp.c -o xlisp/xlpp.o $(CFLAGS) + +xlisp/xlprin.o: xlisp/xlprin.c + cc -c xlisp/xlprin.c -o xlisp/xlprin.o $(CFLAGS) + +xlisp/xlread.o: xlisp/xlread.c + cc -c xlisp/xlread.c -o xlisp/xlread.o $(CFLAGS) + +xlisp/xlstr.o: xlisp/xlstr.c + cc -c xlisp/xlstr.c -o xlisp/xlstr.o $(CFLAGS) + +xlisp/xlsubr.o: xlisp/xlsubr.c + cc -c xlisp/xlsubr.c -o xlisp/xlsubr.o $(CFLAGS) + +xlisp/xlsym.o: xlisp/xlsym.c + cc -c xlisp/xlsym.c -o xlisp/xlsym.o $(CFLAGS) + +xlisp/xlsys.o: xlisp/xlsys.c + cc -c xlisp/xlsys.c -o xlisp/xlsys.o $(CFLAGS) + +cmt/cext.o: cmt/cext.c + cc -c cmt/cext.c -o cmt/cext.o $(CFLAGS) + +cmt/cleanup.o: cmt/cleanup.c + cc -c cmt/cleanup.c -o cmt/cleanup.o $(CFLAGS) + +cmt/cmdline.o: cmt/cmdline.c + cc -c cmt/cmdline.c -o cmt/cmdline.o $(CFLAGS) + +cmt/cmtcmd.o: cmt/cmtcmd.c + cc -c cmt/cmtcmd.c -o cmt/cmtcmd.o $(CFLAGS) + +cmt/moxc.o: cmt/moxc.c + cc -c cmt/moxc.c -o cmt/moxc.o $(CFLAGS) + +cmt/mem.o: cmt/mem.c + cc -c cmt/mem.c -o cmt/mem.o $(CFLAGS) + +cmt/midifile.o: cmt/midifile.c + cc -c cmt/midifile.c -o cmt/midifile.o $(CFLAGS) + +cmt/midifns.o: cmt/midifns.c + cc -c cmt/midifns.c -o cmt/midifns.o $(CFLAGS) + +cmt/record.o: cmt/record.c + cc -c cmt/record.c -o cmt/record.o $(CFLAGS) + +cmt/seq.o: cmt/seq.c + cc -c cmt/seq.c -o cmt/seq.o $(CFLAGS) + +cmt/seqmread.o: cmt/seqmread.c + cc -c cmt/seqmread.c -o cmt/seqmread.o $(CFLAGS) + +cmt/seqmwrite.o: cmt/seqmwrite.c + cc -c cmt/seqmwrite.c -o cmt/seqmwrite.o $(CFLAGS) + +cmt/seqread.o: cmt/seqread.c + cc -c cmt/seqread.c -o cmt/seqread.o $(CFLAGS) + +cmt/seqwrite.o: cmt/seqwrite.c + cc -c cmt/seqwrite.c -o cmt/seqwrite.o $(CFLAGS) + +cmt/tempomap.o: cmt/tempomap.c + cc -c cmt/tempomap.c -o cmt/tempomap.o $(CFLAGS) + +cmt/timebase.o: cmt/timebase.c + cc -c cmt/timebase.c -o cmt/timebase.o $(CFLAGS) + +cmt/userio.o: cmt/userio.c + cc -c cmt/userio.c -o cmt/userio.o $(CFLAGS) + +sys/unix/osstuff.o: sys/unix/osstuff.c + cc -c sys/unix/osstuff.c -o sys/unix/osstuff.o $(CFLAGS) + +misc/intgen: misc/intgen.c + cd misc; make intgen + +misc/unpacker: misc/unpacker.c misc/convert.c + cd misc; make unpacker + +misc/packer: misc/packer.c misc/convert.c + cd misc; make packer + +nyqsrc/sndfnintptrs.h: $(NYQHDRS) snd/snd.h misc/intgen + $(INTGEN) nyqsrc/sndfnint $(NYQHDRS) + +nyqsrc/seqfnintptrs.h: $(CMTHDRS) misc/intgen + $(INTGEN) nyqsrc/seqfnint $(CMTHDRS) + +clean: + cd misc; make clean + rm -f $(OBJECTS) +# Note that these files are machine-generated: + rm -f nyqsrc/sndfnintptrs.h nyqsrc/sndfnint.c nyqsrc/sndfnintdefs.h + rm -f nyqsrc/seqfnintptrs.h nyqsrc/seqfnint.c nyqsrc/seqfnintdefs.h + +cleaner: clean + cd misc; make cleaner + rm -f *.backup */*.backup + rm -f *~ */*.*~ + rm -f *.save */*.save + rm -f *.CKP */*.CKP + rm -f *.BAK */*.BAK + rm -f *.old */*.old + rm -f *.gold */*.gold + rm -f playparms + rm -f points.dat diff --git a/lib-src/libnyquist/nyquist/sys/unix/sparc/system.lsp b/lib-src/libnyquist/nyquist/sys/unix/sparc/system.lsp new file mode 100644 index 000000000..4d6dfb3f7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/sparc/system.lsp @@ -0,0 +1,33 @@ +; machine.lsp -- machine/system-dependent definitions +; sparc + +(setf *default-sound-srate* 8192) + +(if (not (boundp '*default-sf-format*)) + (setf *default-sf-format* snd-head-NeXT)) + +(if (not (boundp '*default-sound-file*)) + (compute-default-sound-file)) + +(if (not (boundp '*default-sf-dir*)) + (setf *default-sf-dir* "/tmp")) + +(if (not (boundp '*default-sf-mode*)) + (setf *default-sf-mode* snd-mode-pcm)) + +(if (not (boundp '*default-sf-bits*)) + (setf *default-sf-bits* 16)) + +; local definition for play + +(defun r () + (system (format nil + "play ~A" + *default-sound-file*))) + +(defmacro play (expr) + `(prog (specs) + (setf specs (s-save ,expr NY:ALL *default-sound-file*)) + (r))) + + diff --git a/lib-src/libnyquist/nyquist/sys/unix/switches.h b/lib-src/libnyquist/nyquist/sys/unix/switches.h index 28ae51319..ef9181b27 100644 --- a/lib-src/libnyquist/nyquist/sys/unix/switches.h +++ b/lib-src/libnyquist/nyquist/sys/unix/switches.h @@ -193,5 +193,20 @@ */ #define NYQUIST 1 +/* If SAFE_NYQUIST is defined, Nyquist will prevent: + * - writes anywhere except in the directory tree + * named after the -w flag (if any) on the command + * line + * - play sounds or open the audio input or output + * - any networking functions. + */ + +/* If SECURE_NYQUIST is defined, Nyquist will + * not read anywhere except in the directory forest + * given by the initial search path (XLISPPATH) and + * by a path list following -r on the command line + * (if any). + */ + #include "swlogic.h" diff --git a/lib-src/libnyquist/nyquist/sys/unix/term.c b/lib-src/libnyquist/nyquist/sys/unix/term.c new file mode 100644 index 000000000..2218febd5 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/term.c @@ -0,0 +1,133 @@ +/* term.c -- Routines for managing terminal I/O settings by Alan Cox. + * From LJ 17 */ + +/* Thanks to Dave Cook for rescuing it */ + +/* CHANGE LOG + * -------------------------------------------------------------------- + * 28Apr03 dm include ioctl.h and declare void ctcinit(); + */ + + +#include +#ifndef __APPLE__ +#include +#endif +#include +#include +#include +#include +#include + +void ctcinit(); + +/* This will be used for new terminal settings. */ +static struct termios current; + +/* This will hold the initial state so that we can restor it later. */ +static struct termios initial; + +/* Restor the termianl settings to those saved when term_init was called. */ +void term_restore(void) +{ + tcsetattr(0, TCSANOW, &initial); +} + +/* Clean up termianl; called on exit. */ +void term_exit() +{ + term_restore(); +} + +/* Will be called when contrl-Z is pressed; + * this correctly handles the terminal. */ +void term_ctrlz() +{ + signal(SIGTSTP, term_ctrlz); + term_restore(); + kill(getpid(), SIGSTOP); +} + +/* Will be called when the application is continued + * after having been stopped. */ +void term_cont() +{ + signal(SIGCONT, term_cont); + tcsetattr(0, TCSANOW, ¤t); +} + +/* Needs to be called to initialize the terminal. */ +void term_init(void) +{ + /* If stdin isn't a terminal this fails. + But then so does tcsetattr(), so it doesn't matter. */ + tcgetattr(0, &initial); + /* Save a copy to work with later. */ + current = initial; + /* We _must_ clean up when we exit. */ + /* signal(SIGINT, term_exit); */ + ctcinit(); /* XLisp wants to catch ctrl C */ + signal(SIGQUIT, term_exit); + /* Control-Z must also be handled. */ + signal(SIGTSTP, term_ctrlz); + signal(SIGCONT, term_cont); + atexit(term_exit); +} + +/* Set character-by-character input mode. */ +void term_character(void) +{ + /* One or more characters are sufficient to cause a read return. */ + current.c_cc[VMIN] = 1; + /* No timeout; read waits forever until ready. */ + current.c_cc[VTIME] = 0; + /* Line-by-line mode off */ + current.c_lflag &= ~ICANON; +#ifndef READ_LINE + current.c_lflag &= ~ECHO; +#endif + tcsetattr(0, TCSANOW, ¤t); +} + +/* Return to line-by-line input mode. */ +void term_line(void) +{ + current.c_lflag |= ICANON; + tcsetattr(0, TCSANOW, ¤t); +} + + +#define ERROR(s) return (perror(s), -1) + +/* term_testchar -- tell whether character is ready or not, + * + * if ready, return it, otherwise return -2 + */ +int term_testchar() +{ + int n; + char c; + + if (ioctl(0, FIONREAD, &n) < 0) + ERROR("IOgetchar"); + if (n == 0) return -2; + switch(read(0, &c, 1)) { + case 1: + return c; + case 0: + return EOF; + default: + ERROR("IOgetchar-read"); + } +} + + +/* term_getchar -- get a character (block if necessary) */ +/**/ +int term_getchar() +{ + char c; + int rslt = read(0, &c, 1); + return (rslt == 1 ? c : EOF); +} + diff --git a/lib-src/libnyquist/nyquist/sys/unix/term.h b/lib-src/libnyquist/nyquist/sys/unix/term.h new file mode 100644 index 000000000..4a6ac4c7c --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/term.h @@ -0,0 +1,6 @@ +void term_init(); +void term_exit(); +void ctcinit(); /* not implemented in term.h */ +int term_testchar(); +int term_getchar(); +void term_character(); diff --git a/lib-src/libnyquist/nyquist/sys/unix/termtest.c b/lib-src/libnyquist/nyquist/sys/unix/termtest.c new file mode 100644 index 000000000..08d4c8486 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/unix/termtest.c @@ -0,0 +1,28 @@ +/* this was written to test the term.c code, which was + found on the web for use in XLisp to enable ^C and other + character-by-character handling + */ + +#include "term.h" +#include + +void ctcinit() +{ + signal(SIGINT, term_exit); +} + + +main() +{ + int c; + int count = 0; + term_init(); + term_character(); + while ((c = term_testchar()) == -2) count++; + printf("got %c after %d\n", c, count); + while ((c = getchar()) != 'x') { + printf("got '%c' = %x\n", c, c); + } + term_exit(); +} + diff --git a/lib-src/libnyquist/nyquist/sys/win/README.txt b/lib-src/libnyquist/nyquist/sys/win/README.txt new file mode 100644 index 000000000..dcccb83ad --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/README.txt @@ -0,0 +1,191 @@ +README.txt -- Nyquist information for Windows + +Installation +------------ +The Win32 version of Nyquist is packaged as a compiled (runtime) +system in an executable installer. For most users, the runtime version +contain everything you need to run Nyquist, including the executable, +examples, and documentation, packaged as an executable installer +program. After executing the installer, just find Nyquist in your +Start menu to run it. You may begin typing expressions such as the +ones in the following "Examples" section of the Nyquist manual (in +doc/nyquistman.pdf or doc/home.html). + +(See "The 'java is not recognized' Error" below if you get this error +message.) + +A source version is also available (the same source download is for +Win32, Mac OS X, and Linux). The source version is intended for +developers who want to recompile Nyquist. The contents of the source +archive are extracted to the C:\nyquist directory, but you can put it +anywhere you like. You can then open the workspace file, nyquist.sln, +using Microsoft Visual C++. You can build and run the command line +version of Nyquist from within Visual C++. There is a batch file, +comp-ide.bat, for bulding the Nyquist IDE. This requires the Java SDK +from Sun Microsystems. + +64-bit Windows +-------------- +Nyquist runs on 64-bit Windows. Although you can compile a 64-bit +native version, Nyquist is currently released for 32-bit Windows. +When running on 64-bit Windows, note that the Registry entries will +be under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\CMU\Nyquist. The +"Wow6432Node" creates a special namespace for 32-bit programs. + +Optional +-------- +Nyquist needs to know where to find the standard runtime files. The +location of runtime files must be stored in the Registry. The +installers create a registry entry, but if you move Nyquist or deal +with different versions, you can edit the Registry manually as +follows: + + Run the Registry editor (e.g. type regedit into the Start Search + box of the Start menu and type the Enter key). + + Find and highlight the SOFTWARE key under HKEY_LOCAL_MACHINE. + + If you are on 64-bit Windows using 32-bit Nyquist, open the + Wow6432Node key under SOFTWARE. + + Open the CMU key (if it is not there, use the Edit:New:Key menu + item to create a CMU key. CMU is case sensitive.) + + Highlight the new CMU key. + + Open the Nyquist key (if it is not there, use the Edit:New:Key menu + item to create a Nyquist key. Nyquist is case sensitive.) + + Highlight the new Nyquist key. + + Find the XLISPPATH string (if it is not there, use the + Edit:New:String menu item to create a new string and change the + name by typing XLISPPATH). + + Select XLISPPATH and choose the Edit:Modify... menu item. + In the String Edit box, type a list of paths you want Nyquist to + search for lisp files. For example, if you installed Nyquist as + C:\nyquist, then type: + + C:\nyquist\runtime,C:\nyquist\lib + + The paths should be separated by a comma or semicolon and no + space. The runtime path is essential, and the lib path may become + essential in a future release. You can also add paths to personal + libraries of Lisp and Nyquist code. + + Click the OK button of the string box and exit from the Registry + Editor application. + + +What if Nyquist functions are undefined? +---------------------------------------- +If you do not have administrative privileges for your machine, the +installer may fail to set up the Registry entry that Nyquist uses to +find initialization files. In this case, Nyquist will run a lisp +interpreter, but many Nyquist functions will not be defined. If you +can log in as administrator, do it and reinstall Nyquist. If you do +not have permission, you can still run Nyquist as follows: + +Create a file named init.lsp in the same directory as Nyquist.exe +(the default location is C:\Program Files\Nyquist, but you may +have installed it in some other location.) Put the following text +in init.lsp: + + (setf *search-path* + "C:/Program Files/Nyquist/runtime,C:/Program Files/Nyquist/lib") + (load "C:/Program Files/Nyquist/runtime/init.lsp") + +Note: in the three places where you see C:/Program Files/Nyquist, +insert the full path where Nyquist is actually installed. Use forward +slashes (/) rather than back slashes (\) to separate directories. For +example, if Nyquist is installed at D:\rbd\nyquist, then init.lsp +should contain: + + (setf *search-path* "D:/rbd/nyquist/runtime,D:/rbd/nyquist/lib") + (load "d:/rbd/nyquist/runtime/init.lsp") + +The variable *search-path*, if defined, is used in place of the +registry to determine search paths for files. + +SystemRoot +---------- +(Ignore this paragraph if you are not planning to use Open Sound +Control under Windows.) + +If Nyquist prints an error message and quits when you enable Open +Sound Control (using osc-enable), check to see if you have an +environment variable SystemRoot, e.g. type set to a command prompt and +look for the value of SystemRoot. The normal value is C:\windows. If +the value is something else, you should put the environment entry, for +example: + + SystemRoot="D:\windows" + +into a file named systemroot (no extension). Put this file in your +nyquist directory. When you run jNyqIDE, it will look for this file +and pass the contents as an environment variable to Nyquist. The +Nyquist process needs this to open a UDP socket, which is needed for +Open Sound Control. + +The window vanishes, "java is not recognized", and other errors +--------------------------------------------------------------- +Sometimes Nyquist pops up a window that closes instantly. This +indicates that Java was not found. + +Sometimes, Nyquist will run directly from the installer, but then it +will not start from the Windows Start menu. You can try running the +nyquist/jnyqide.bat program from a Windows command prompt (cmd). +If that fails, and you see an error similar to "java is not recognized +as in internal or external command error", the problem may be that +paths are not set up properly to allow the Windows shell to find java. + +Right click on "My Computer" on the Windows desktop and select +"Properties." Under the "Advanced" tap, press the "Environment +Variables" button, and look for PATH under "System Variables." Make +sure the Java bin directory is on the path. If it is not, you will +have to find your installation of Java and add the appropriate +directory to the PATH variable, e.g. "C:\Program +Files\Java\jdk1.7.0\bin." + +Another possible problem is that your Java version is not compatible +with Nyquist. In that case, you should see an error message +complaining about "Unsupported major.minor version...". The current +major.minor version is 51 and you need to have Java version 1.7 +installed. (Use the command: java -version to find out your java +version number.) + +You might have to reboot for these changes to take effect. + +Compile Nyquist for using Visual Studio +--------------------------------------- +Nyquist can be compiled using Visual Studio 2010 or 2012. You can +download Visual C++ Express 2010 and Visual Studio 2012 Express for +free from Mircosoft website. + +If you use Visual C++ 2010 Express, you MUST install SP1 (service pack +1). + +Open nyquist-vc2010.sln; If you are using Visual Studio 2012 or later +versions, open nyquist.sln instead. + +In Visual Studio, + Set solution configuration to "Release" and solution platforms + to "Win32". + Click Debug->Build Solution (or press F7) + + Click Debug->Start Debugging (or press F5) + +To build jnyqide, + Check if you have installed JDK and have the directory to + javac.exe added to your system PATH. + Run comp-ide.bat under the project root. It will compile .java + files under jnyqide. + For debugging, you can run the IDE immediately. + First copy nyquist\WinRel\nyquist.exe to nyquist\ (only do + this each time you recompile nyquist.) + Then, run jnyqide.bat. + To generate a release: + Run releasenyqide.bat under the project root. It will copy + all the necessary files to .\nyqrelide\. You can run + jnyqide.bat from there. diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/inttypes.h b/lib-src/libnyquist/nyquist/sys/win/msvc/inttypes.h new file mode 100644 index 000000000..b86685cea --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/inttypes.h @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2000,2001 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. + * + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +/* + * -- Standard C header, defined in ISO/IEC 9899:1999 + * (aka "C99"), section 7.8. This defines format string conversion + * specifiers suitable for use within arguments to fprintf and fscanf + * and their ilk. + */ + +#if !defined(_INTTYPES_H_) +#define _INTTYPES_H_ + +#include + +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) + /* Translator is not ISO/IEC 9899:1999-compliant. */ + #if !defined(restrict) + #define restrict + #define __RESTRICT_KEYWORD_DEFINED__ + #endif +#endif + +/* "C++ implementations should define these macros only when + * __STDC_FORMAT_MACROS is defined before is included." + */ +#if (! defined(__cplusplus)) || defined(__STDC_FORMAT_MACROS) + + #undef __PRI_8_LENGTH_MODIFIER__ + #undef __PRI_64_LENGTH_MODIFIER__ + #undef __SCN_8_LENGTH_MODIFIER__ + #undef __SCN_64_LENGTH_MODIFIER__ + + #if defined(__STDC_LIBRARY_SUPPORTED__) + #define __PRI_8_LENGTH_MODIFIER__ "%hh" + #define __PRI_64_LENGTH_MODIFIER__ "%ll" + #define __SCN_8_LENGTH_MODIFIER__ "%hh" + #define __SCN_64_LENGTH_MODIFIER__ "%ll" + #else + #define __PRI_8_LENGTH_MODIFIER__ "%" /* none */ + #define __PRI_64_LENGTH_MODIFIER__ "%q" + #endif + + #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d" + #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i" + #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o" + #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u" + #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x" + #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X" + + #define PRId16 "%hd" + #define PRIi16 "%hi" + #define PRIo16 "%ho" + #define PRIu16 "%hu" + #define PRIx16 "%hx" + #define PRIX16 "%hX" + + #define PRId32 "%ld" + #define PRIi32 "%li" + #define PRIo32 "%lo" + #define PRIu32 "%lu" + #define PRIx32 "%lx" + #define PRIX32 "%lX" + + #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d" + #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i" + #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o" + #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u" + #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x" + #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X" + + #define PRIdLEAST8 PRId8 + #define PRIiLEAST8 PRIi8 + #define PRIoLEAST8 PRIo8 + #define PRIuLEAST8 PRIu8 + #define PRIxLEAST8 PRIx8 + #define PRIXLEAST8 PRIX8 + + #define PRIdLEAST16 PRId16 + #define PRIiLEAST16 PRIi16 + #define PRIoLEAST16 PRIo16 + #define PRIuLEAST16 PRIu16 + #define PRIxLEAST16 PRIx16 + #define PRIXLEAST16 PRIX16 + + #define PRIdLEAST32 PRId32 + #define PRIiLEAST32 PRIi32 + #define PRIoLEAST32 PRIo32 + #define PRIuLEAST32 PRIu32 + #define PRIxLEAST32 PRIx32 + #define PRIXLEAST32 PRIX32 + + #define PRIdLEAST64 PRId64 + #define PRIiLEAST64 PRIi64 + #define PRIoLEAST64 PRIo64 + #define PRIuLEAST64 PRIu64 + #define PRIxLEAST64 PRIx64 + #define PRIXLEAST64 PRIX64 + + #define PRIdFAST8 PRId32 + #define PRIiFAST8 PRIi32 + #define PRIoFAST8 PRIo32 + #define PRIuFAST8 PRIu32 + #define PRIxFAST8 PRIx32 + #define PRIXFAST8 PRIX32 + + #define PRIdFAST16 PRId32 + #define PRIiFAST16 PRIi32 + #define PRIoFAST16 PRIo32 + #define PRIuFAST16 PRIu32 + #define PRIxFAST16 PRIx32 + #define PRIXFAST16 PRIX32 + + #define PRIdFAST32 PRId32 + #define PRIiFAST32 PRIi32 + #define PRIoFAST32 PRIo32 + #define PRIuFAST32 PRIu32 + #define PRIxFAST32 PRIx32 + #define PRIXFAST32 PRIX32 + + #define PRIdFAST64 PRId64 + #define PRIiFAST64 PRIi64 + #define PRIoFAST64 PRIo64 + #define PRIuFAST64 PRIu64 + #define PRIxFAST64 PRIx64 + #define PRIXFAST64 PRIX64 + + #define PRIdPTR PRId32 + #define PRIiPTR PRIi32 + #define PRIoPTR PRIo32 + #define PRIuPTR PRIu32 + #define PRIxPTR PRIx32 + #define PRIXPTR PRIX32 + + #define PRIdMAX PRId64 + #define PRIiMAX PRIi64 + #define PRIoMAX PRIo64 + #define PRIuMAX PRIu64 + #define PRIxMAX PRIx64 + #define PRIXMAX PRIX64 + + #if defined(__SCN_8_LENGTH_MODIFIER__) + #define SCNd8 __SCN_8_LENGTH_MODIFIER__ "d" + #define SCNi8 __SCN_8_LENGTH_MODIFIER__ "i" + #define SCNo8 __SCN_8_LENGTH_MODIFIER__ "o" + #define SCNu8 __SCN_8_LENGTH_MODIFIER__ "u" + #define SCNx8 __SCN_8_LENGTH_MODIFIER__ "x" + #endif + + #define SCNd16 "%hd" + #define SCNi16 "%hi" + #define SCNo16 "%ho" + #define SCNu16 "%hu" + #define SCNx16 "%hx" + + #define SCNd32 "%ld" + #define SCNi32 "%li" + #define SCNo32 "%lo" + #define SCNu32 "%lu" + #define SCNx32 "%lx" + + #if defined(__SCN_64_LENGTH_MODIFIER__) + #define SCNd64 __SCN_64_LENGTH_MODIFIER__ "d" + #define SCNi64 __SCN_64_LENGTH_MODIFIER__ "i" + #define SCNo64 __SCN_64_LENGTH_MODIFIER__ "o" + #define SCNu64 __SCN_64_LENGTH_MODIFIER__ "u" + #define SCNx64 __SCN_64_LENGTH_MODIFIER__ "x" + #endif + + #if defined(__SCN_8_LENGTH_MODIFIER__) + #define SCNdLEAST8 SCNd8 + #define SCNiLEAST8 SCNi8 + #define SCNoLEAST8 SCNo8 + #define SCNuLEAST8 SCNu8 + #define SCNxLEAST8 SCNx8 + #endif + + #define SCNdLEAST16 SCNd16 + #define SCNiLEAST16 SCNi16 + #define SCNoLEAST16 SCNo16 + #define SCNuLEAST16 SCNu16 + #define SCNxLEAST16 SCNx16 + + #define SCNdLEAST32 SCNd32 + #define SCNiLEAST32 SCNi32 + #define SCNoLEAST32 SCNo32 + #define SCNuLEAST32 SCNu32 + #define SCNxLEAST32 SCNx32 + + #if defined(__SCN_64_LENGTH_MODIFIER__) + #define SCNdLEAST64 SCNd64 + #define SCNiLEAST64 SCNi64 + #define SCNoLEAST64 SCNo64 + #define SCNuLEAST64 SCNu64 + #define SCNxLEAST64 SCNx64 + #endif + + #define SCNdFAST8 SCNd32 + #define SCNiFAST8 SCNi32 + #define SCNoFAST8 SCNo32 + #define SCNuFAST8 SCNu32 + #define SCNxFAST8 SCNx32 + + #define SCNdFAST16 SCNd32 + #define SCNiFAST16 SCNi32 + #define SCNoFAST16 SCNo32 + #define SCNuFAST16 SCNu32 + #define SCNxFAST16 SCNx32 + + #define SCNdFAST32 SCNd32 + #define SCNiFAST32 SCNi32 + #define SCNoFAST32 SCNo32 + #define SCNuFAST32 SCNu32 + #define SCNxFAST32 SCNx32 + + #if defined(__SCN_64_LENGTH_MODIFIER__) + #define SCNdFAST64 SCNd64 + #define SCNiFAST64 SCNi64 + #define SCNoFAST64 SCNo64 + #define SCNuFAST64 SCNu64 + #define SCNxFAST64 SCNx64 + #endif + + #define SCNdPTR SCNd32 + #define SCNiPTR SCNi32 + #define SCNoPTR SCNo32 + #define SCNuPTR SCNu32 + #define SCNxPTR SCNx32 + + #if defined(__SCN_64_LENGTH_MODIFIER__) + #define SCNdMAX SCNd64 + #define SCNiMAX SCNi64 + #define SCNoMAX SCNo64 + #define SCNuMAX SCNu64 + #define SCNxMAX SCNx64 + #endif + +#endif /* if C++, then __STDC_FORMAT_MACROS enables the above macros */ + +#if defined(__STDC_LIBRARY_SUPPORTED__) + + /* 7.8.2.1 */ + extern intmax_t imaxabs(intmax_t j); + + /* 7.8.2.2 */ + typedef struct { + intmax_t quot; + intmax_t rem; + } imaxdiv_t; + + extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom); + + /* 7.8.2.3 */ + extern intmax_t strtoimax(const char * restrict nptr, char ** restrict endptr, int base); + extern uintmax_t strtoumax(const char * restrict nptr, char ** restrict endptr, int base); + + /* 7.8.2.4 */ + extern intmax_t wcstoimax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); + extern uintmax_t wcstoumax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base); + +#endif + +/* + No need to #undef the __*_{8,64}_LENGTH_MODIFIER__ macros; + in fact, you can't #undef them, because later uses of any of + their dependents will *not* then do the intended substitution. + Expansion of a #define like this one: + + #define x IDENT y + + uses the cpp value of IDENT at the location where x is *expanded*, + not where it is #defined. +*/ + +#if defined(__RESTRICT_KEYWORD_DEFINED__) + #undef restrict + #undef __RESTRICT_KEYWORD_DEFINED__ +#endif + +#endif /* !_INTTYPES_H_ */ \ No newline at end of file diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/mapinls.h b/lib-src/libnyquist/nyquist/sys/win/msvc/mapinls.h new file mode 100644 index 000000000..7fd4975ca --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/mapinls.h @@ -0,0 +1,213 @@ +/* + * M A P I N L S . H + * + * Internationalization Support Utilities + * + * Copyright 1986-1996 Microsoft Corporation. All Rights Reserved. + */ + +#ifndef _MAPINLS_H_ +#define _MAPINLS_H_ +#pragma option -b + +#if defined (WIN32) && !defined (_WIN32) +#define _WIN32 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* We don't want to include windows.h in case that conflicts with an */ +/* earlier inclusion of compobj.h */ + +#if !defined(WINAPI) + #if defined(_WIN32) && (_MSC_VER >= 800) + #define WINAPI __stdcall + #elif defined(WIN16) + #define WINAPI _far _pascal + #else + #define WINAPI _far _pascal + #endif +#endif + +#if defined(DOS) || defined(_MAC) +#pragma option -b. +#include +#pragma option -b +#endif + +#ifndef FAR +#define FAR +#endif + +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned long DWORD; +typedef unsigned int UINT; +typedef int BOOL; + +#ifndef __CHAR_DEFINED__ +typedef char CHAR; +#endif + +#ifdef UNICODE +typedef WCHAR TCHAR; +#else +typedef char TCHAR; +#endif + +// typedef unsigned short WCHAR; +typedef WCHAR FAR * LPWSTR; +typedef const WCHAR FAR * LPCWSTR; +typedef CHAR FAR * LPSTR; +typedef const CHAR FAR * LPCSTR; +typedef TCHAR FAR * LPTSTR; +typedef const TCHAR FAR * LPCTSTR; +typedef DWORD LCID; +typedef const void FAR * LPCVOID; + +#ifndef _MAC +#ifndef LPOLESTR +#if !defined (_WIN32) + +#define LPOLESTR LPSTR +#define LPCOLESTR LPCSTR +#define OLECHAR char +#define OLESTR(str) str + +#else /* Win32 */ + +#define LPOLESTR LPWSTR +#define LPCOLESTR LPCWSTR +#define OLECHAR WCHAR +#define OLESTR(str) L##str + +#endif /* !_WIN32 */ +#endif /* LPOLESTR */ +#endif /* _MAC */ + +#define NORM_IGNORECASE 0x00000001 /* ignore case */ +#define NORM_IGNORENONSPACE 0x00000002 /* ignore diacritics */ +#define NORM_IGNORESYMBOLS 0x00000004 /* ignore symbols */ + +#if defined (_WIN32) /* from winnls.h */ +#define NORM_IGNOREKANATYPE 0x00010000 /* ignore kanatype */ +#define NORM_IGNOREWIDTH 0x00020000 /* ignore width */ +#elif defined (WIN16) /* from olenls.h */ +#define NORM_IGNOREWIDTH 0x00000008 /* ignore width */ +#define NORM_IGNOREKANATYPE 0x00000040 /* ignore kanatype */ +#endif + +#if defined(WIN16) + +#define lstrcpyA lstrcpy +#define lstrlenA lstrlen +#define lstrcmpA lstrcmp +#define lstrcmpiA lstrcmpi +#define LoadStringA LoadString +#define IsBadStringPtrA(a1, a2) IsBadStringPtr(a1, a2) +#define wvsprintfA wvsprintf +#define MessageBoxA MessageBox +#define GetModuleHandleA GetModuleHandle +#define CreateWindowA CreateWindow +#define RegisterClassA RegisterClass +#define CharToOemBuff AnsiToOemBuff +#define CharToOem AnsiToOem +#define CharUpperBuff AnsiUpperBuff +#define CharUpper AnsiUpper + +#elif defined(DOS) || defined(_MAC) + +#define IsBadReadPtr(lp, cb) (FALSE) +#define IsBadWritePtr(lp, cb) (FALSE) +#define IsBadHugeReadPtr(lp, cb) (FALSE) +#define IsBadHugeWritePtr(lp, cb) (FALSE) +#define IsBadCodePtr(lpfn) (FALSE) +#ifdef _MAC +#undef IsBadStringPtr +#endif +#define IsBadStringPtr(lpsz, cchMax) (FALSE) +#define IsBadStringPtrA(lpsz, cchMax) (FALSE) + +#if defined(DOS) + +#define lstrcpyA strcpy +#define lstrlenA strlen +#define lstrcmpA strcmp +#define lstrcmp strcmp +#define lstrcmpi strcmpi +#define lstrcpy strcpy +#define lstrcat strcat +#define lstrlen strlen +#define wsprintf sprintf + +#endif +#endif + +#if defined(DOS) || defined(WIN16) +/* Simulate effect of afx header */ +#define __T(x) x +#define _T(x) __T(x) +#define TEXT _T +#endif + +#define CP_ACP 0 /* default to ANSI code page */ +#define CP_OEMCP 1 /* default to OEM code page */ + +LCID WINAPI MNLS_GetUserDefaultLCID(void); +UINT WINAPI MNLS_GetACP(void); +int WINAPI MNLS_CompareStringA(LCID Locale, DWORD dwCmpFlags, + LPCSTR lpString1, int cchCount1, LPCSTR lpString2, + int cchCount2); +int WINAPI MNLS_CompareStringW(LCID Locale, DWORD dwCmpFlags, + LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, + int cchCount2); +int WINAPI MNLS_MultiByteToWideChar(UINT uCodePage, DWORD dwFlags, + LPCSTR lpMultiByteStr, int cchMultiByte, + LPWSTR lpWideCharStr, int cchWideChar); +int WINAPI MNLS_WideCharToMultiByte(UINT uCodePage, DWORD dwFlags, + LPCWSTR lpWideCharStr, int cchWideChar, + LPSTR lpMultiByteStr, int cchMultiByte, + LPCSTR lpDefaultChar, BOOL FAR *lpfUsedDefaultChar); +int WINAPI MNLS_lstrlenW(LPCWSTR lpString); +int WINAPI MNLS_lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2); +LPWSTR WINAPI MNLS_lstrcpyW(LPWSTR lpString1, LPCWSTR lpString2); +BOOL WINAPI MNLS_IsBadStringPtrW(LPCWSTR lpsz, UINT ucchMax); + +#if defined(_WIN32) && !defined(_WINNT) && !defined(_WIN95) && !defined(_MAC) +#define _WINNT +#endif + +#if !defined(_WINNT) && !defined(_WIN95) +#define GetUserDefaultLCID MNLS_GetUserDefaultLCID +#define GetACP MNLS_GetACP +#define MultiByteToWideChar MNLS_MultiByteToWideChar +#define WideCharToMultiByte MNLS_WideCharToMultiByte +#define CompareStringA MNLS_CompareStringA +#endif + +#if !defined(MAPI_NOWIDECHAR) + +#define lstrlenW MNLS_lstrlenW +#define lstrcmpW MNLS_lstrcmpW +#define lstrcpyW MNLS_lstrcpyW +#define CompareStringW MNLS_CompareStringW + +#if defined(WIN16) || defined(_WINNT) || defined(_WIN95) +#define IsBadStringPtrW MNLS_IsBadStringPtrW +#elif defined(_MAC) +#define IsBadStringPtrW(lpsz, cchMax) (FALSE) +#else +#define IsBadStringPtrW (FALSE) +#endif + +#endif /* ! MAPI_NOWIDECHAR */ + +#ifdef __cplusplus +} +#endif + +#pragma option -b. +#endif /* _MAPINLS_H_ */ + diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/mapiwin.h b/lib-src/libnyquist/nyquist/sys/win/msvc/mapiwin.h new file mode 100644 index 000000000..38383c3a6 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/mapiwin.h @@ -0,0 +1,274 @@ +/* + * M A P I W I N . H + * + * Definitions used by the MAPI Development Team to aid in + * developing single-source service providers that run on + * both WIN32 and WIN16 platforms. + * There are three sections. + * + * The first section defines how to call something that + * is available by different methods in WIN16 vs. WIN32. + * As such, they are totally new mechanisms. + * + * The second section establishes things that are available + * AS-IS in one environment but we have to define for the + * other environment. + * + * The third section simply defines a few conventions + * (simplifications) for common operations. + * + * Copyright (c) 2009 Microsoft Corporation. All Rights Reserved. + */ + +/* + * Routines are included in the first section to manage per-instance + * global variables for DLLs. They assume that all of the DLL's + * per-instance global variables live in a single block of memory. + * Functions are provided to install and retrieve the correct block of + * memory for the current instance. + * + * There are only two functions: + * + * PvGetInstanceGlobals Call this to get the address of the + * per-instance globals structure. + * ScSetinstanceGlobals Call this to install the + * per-instance globals structure. It + * may fail if the number of instances + * exceeds a certain limit. + * + * The caller is free to choose the name, size, and allocation + * method of the per-instance global variables structure. + * + * The WIN32 implementation uses a pointer in the DLL's data + * segment. This assumes that the DLL gets a separate instance + * of the default data segment per calling process. + * + * The WIN16 implementation uses a fixed array of pointers and a + * matching fixed array of keys unique to the calling process. + */ + +/* + * The second section consists largely of Win32 file I/O functions + * that are not supported under Win16. These functions are + * implemented in mapiwin.c, using DOS calls. Most have limitations + * relative to their Win32 counterparts, which are spelled out in + * the comments to the source code. + */ + +#ifndef __MAPIWIN_H__ +#define __MAPIWIN_H__ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#if defined (WIN32) && !defined (_WIN32) +#define _WIN32 +#endif + +#include "mapinls.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined(_MAC) + +#define MULDIV(x,y,z) MulDiv(x,y,z) + +LPVOID FAR PASCAL PvGetInstanceGlobals(WORD wDataSet); +LONG FAR PASCAL ScSetInstanceGlobals(LPVOID pv, WORD wDataSet); +LONG FAR PASCAL ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid, + WORD wDataSet); +LPVOID FAR PASCAL PvGetVerifyInstanceGlobals(DWORD dwPid, DWORD wDataSet); +LPVOID FAR PASCAL PvSlowGetInstanceGlobals(DWORD dwPid, DWORD wDataSet); +BOOL FAR PASCAL FCleanupInstanceGlobals(WORD, DWORD); + +#elif defined(_WIN64) || defined(_WIN32) + +#define MULDIV(x,y,z) MulDiv(x,y,z) + +extern LPVOID pinstX; +#define PvGetInstanceGlobals() pinstX +#define ScSetInstanceGlobals(_pv) (pinstX = _pv, 0) +#define PvGetVerifyInstanceGlobals(_pid) pinstX +#define ScSetVerifyInstanceGlobals(_pv,_pid) (pinstX = _pv, 0) +#define PvSlowGetInstanceGlobals(_pid) pinstX + +#else +#error "Unknown Platform: MAPI is currently supported on Win32 and Win64" +#endif + +#if (defined(_WIN64) || defined(_WIN32)) && !defined(_MAC) +#define szMAPIDLLSuffix "32" +#elif defined(DOS) +#define szMAPIDLLSuffix "" +#elif defined(_MAC) +#define szMAPIDLLSuffix "M" +#else +#error "Don't know the suffix for DLLs on this platform" +#endif + +/********************************/ +/* Things missing from one */ +/* system-provided environment */ +/* or the other. */ +/********************************/ + +#if !defined(_WIN64) && !defined(_WIN32) +#define ZeroMemory(pb,cb) memset((pb),0,(cb)) +#define FillMemory(pb,cb,b) memset((pb),(b),(cb)) +#define CopyMemory(pbDst,pbSrc,cb) do \ + { \ + size_t _cb = (size_t)(cb); \ + if (_cb) \ + memcpy(pbDst,pbSrc,_cb);\ + } while (FALSE) +#define MoveMemory(pbDst,pbSrc,cb) memmove((pbDst),(pbSrc),(cb)) + +#define UNALIGNED + +#endif + +#if defined(_MAC) + +typedef int INT; +typedef unsigned long ULONG; +typedef short SHORT; +typedef unsigned short USHORT; +typedef double LONGLONG; +typedef double DWORDLONG; +typedef unsigned char UCHAR; +typedef unsigned char FAR* PUCHAR; +typedef int BOOL; + + +/* Synchronization */ +#define InterlockedIncrement(plong) (++(*(plong))) +#define InterlockedDecrement(plong) (--(*(plong))) + +#ifndef CreateMutex +#define CreateMutexA CreateMutex +#define CreateMutexW CreateMutex +#define CreateMutex(pv, bool, sz) (INVALID_HANDLE_VALUE) +#endif + +#define WaitForSingleObject(hObj, dw) ((void)0) +#define ReleaseMutex(hObj) ((BOOL)1) +#define CloseMutexHandle(hObj) TRUE + +#define CRITICAL_SECTION ULONG +#define InitializeCriticalSection(_pcs) ((void)0) +#define DeleteCriticalSection(_pcs) ((void)0) +#define EnterCriticalSection(_pcs) ((void)0) +#define LeaveCriticalSection(_pcs) ((void)0) + +#define MAX_PATH 260 + +#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 + +#define CREATE_NEW 1 +#define CREATE_ALWAYS 2 +#define OPEN_EXISTING 3 +#define OPEN_ALWAYS 4 +#define TRUNCATE_EXISTING 5 + +#define FILE_ATTRIBUTE_READONLY 0x00000001 +#define FILE_ATTRIBUTE_HIDDEN 0x00000002 +#define FILE_ATTRIBUTE_SYSTEM 0x00000004 +#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 +#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 +#define FILE_ATTRIBUTE_NORMAL 0x00000080 +#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 + +#define FILE_FLAG_WRITE_THROUGH 0x80000000 +#define FILE_FLAG_RANDOM_ACCESS 0x10000000 + +#define TIME_ZONE_ID_UNKNOWN 0 +#define TIME_ZONE_ID_STANDARD 1 +#define TIME_ZONE_ID_DAYLIGHT 2 + + + +DWORD WINAPI GetLastError(void); +DWORD WINAPI GetFileAttributes(LPCSTR lpFileName); +DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); +BOOL WINAPI GetFileTime(HANDLE hFile, FILETIME FAR *lpftCreation, + FILETIME FAR *lpftLastAccess, FILETIME FAR *lpftLastWrite); +BOOL WINAPI SetFileTime(HANDLE hFile, const FILETIME FAR *lpftCreation, + const FILETIME FAR *lpftLastAccess, + const FILETIME FAR *lpftLastWrite); +DWORD WINAPI SetFilePointer(HANDLE hFile, LONG lDistanceToMove, + LONG FAR *lpDistanceToMoveHigh, DWORD dwMoveMethod); +BOOL WINAPI SetEndOfFile(HANDLE hFile); +BOOL WINAPI CloseHandle(HANDLE hObject); +DWORD WINAPI GetTempPath(DWORD nBufferLength, LPSTR lpBuffer); +UINT WINAPI GetTempFileName32 (LPCSTR lpPathName, LPCSTR lpPrefixString, + UINT uUnique, LPSTR lpTempFileName); +BOOL WINAPI DeleteFile(LPCSTR lpFileName); +BOOL WINAPI RemoveDirectory(LPCSTR lpPathName); +BOOL WINAPI CopyFile(LPCSTR szSrc, LPCSTR szDst, BOOL fFailIfExists); +BOOL WINAPI MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName); +HANDLE WINAPI FindFirstFile(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData); +BOOL WINAPI FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData); +BOOL WINAPI FindClose(HANDLE hFindFile); +DWORD WINAPI GetFullPathName(LPCSTR lpFileName, DWORD nBufferLength, + LPSTR lpBuffer, LPSTR *lpFilePart); +void WINAPI Sleep(DWORD dwMilliseconds); +LONG WINAPI CompareFileTime(const FILETIME FAR *, const FILETIME FAR *); +BOOL WINAPI LocalFileTimeToFileTime(const FILETIME FAR *, FILETIME FAR *); +BOOL WINAPI FileTimeToLocalFileTime(const FILETIME FAR *, FILETIME FAR *); +BOOL WINAPI FileTimeToSystemTime(const FILETIME FAR *, SYSTEMTIME FAR *); +BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME FAR *, FILETIME FAR *); +void WINAPI GetSystemTime(SYSTEMTIME FAR *); +void WINAPI GetLocalTime(SYSTEMTIME FAR *); +BOOL WINAPI FileTimeToDosDateTime(const FILETIME FAR * lpFileTime, + WORD FAR *lpFatDate, WORD FAR *lpFatTime); +BOOL WINAPI DosDateTimeToFileTime(WORD wFatDate, WORD wFatTime, + FILETIME FAR * lpFileTime); +DWORD WINAPI GetTimeZoneInformation( + LPTIME_ZONE_INFORMATION lpTimeZoneInformation); +BOOL WINAPI SetTimeZoneInformation( + const TIME_ZONE_INFORMATION FAR *lpTimeZoneInformation); + +DWORD WINAPI GetCurrentProcessId(void); +long WINAPI MulDiv32(long, long, long); + +#else /* _MAC */ + +/* Remaps GetTempFileName32() to the real 32bit version */ + +#define GetTempFileName32(_szPath,_szPfx,_n,_lpbuf) GetTempFileName(_szPath,_szPfx,_n,_lpbuf) + +#define CloseMutexHandle CloseHandle + +#endif /* _MAC */ + + +#ifdef _MAC +#define CRITICAL_SECTION ULONG +#define InitializeCriticalSection(_pcs) ((void)0) +#define DeleteCriticalSection(_pcs) ((void)0) +#define EnterCriticalSection(_pcs) ((void)0) +#define LeaveCriticalSection(_pcs) ((void)0) +#endif + +/********************************/ +/* Our private conventions */ +/* (common to WIN32/WIN64) */ +/********************************/ + +#define Cbtszsize(_a) ((lstrlen(_a)+1)*sizeof(TCHAR)) +#define CbtszsizeA(_a) ((lstrlenA(_a) + 1)) +#define CbtszsizeW(_a) ((lstrlenW(_a) + 1) * sizeof(WCHAR)) +#define HexCchOf(_s) (sizeof(_s)*2+1) +#define HexSizeOf(_s) (HexCchOf(_s)*sizeof(TCHAR)) + +BOOL WINAPI IsBadBoundedStringPtr(const void FAR* lpsz, UINT cchMax); + +#ifdef __cplusplus +} +#endif + +#endif /* __MAPIWIN_H__ */ diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/stdint.h b/lib-src/libnyquist/nyquist/sys/win/msvc/stdint.h new file mode 100644 index 000000000..c8691fac7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/stdint.h @@ -0,0 +1,55 @@ +/* stdint.h -- missing from Microsoft compilers, so this is a + * version constructed solely for libsndfile. It does not + * have a complete set of definitions. + * + * This file should be in a directory of include files used only + * by Microsoft compilers + * + * Roger Dannenberg, Aug 2012 + */ + +#ifndef _MSC_VER +#error "This Microsoft-specific file was included by a non-Microsoft compiler" +#endif + +#ifndef STDINT_H +#define STDINT_H + +#ifdef __cplusplus +extern "C" { +#endif +#include +#ifdef __cplusplus +} +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +#define _W64 __w64 +#else +#define _W64 +#endif +#endif + +#if (_MSC_VER < 1300) +//typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +//typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#else +//typedef signed __int8 int8_t; +typedef signed __int16 int16_t; +typedef signed __int32 int32_t; +//typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +#endif +//typedef signed __int64 int64_t; +//typedef unsigned __int64 uint64_t; + + +#endif // STDINT_H + diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/switches.h b/lib-src/libnyquist/nyquist/sys/win/msvc/switches.h index 9e21c6edc..ecc2786e9 100644 --- a/lib-src/libnyquist/nyquist/sys/win/msvc/switches.h +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/switches.h @@ -95,7 +95,7 @@ void nyquist_printf(char *format, ...); #define HAVE_SSIZE_T 1 /* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 0 +#define HAVE_STDINT_H 1 /* Define to 1 if you have the header file. */ #define HAVE_SYS_STAT_H 1 diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/winfun.c b/lib-src/libnyquist/nyquist/sys/win/msvc/winfun.c index 5360e659c..6416017a7 100644 --- a/lib-src/libnyquist/nyquist/sys/win/msvc/winfun.c +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/winfun.c @@ -14,49 +14,69 @@ xsetdir - set current directory of the process */ LVAL xsetdir() { TCHAR ssCurDir[MAX_PATH], szCurDir[MAX_PATH]; + int verbose = TRUE; strcpy(ssCurDir, getstring(xlgastring())); + if (moreargs()) { + verbose = (xlgetarg() != NIL); + } xllastarg(); - if (SetCurrentDirectory(ssCurDir)) { - if (GetCurrentDirectory( - sizeof(szCurDir)/sizeof(TCHAR), szCurDir)) { - return cvstring(szCurDir); - /* create the result string - stdputstr("Current Directory: "); - stdputstr(szCurDir); - stdputstr("\n"); */ + if (ok_to_open(ssCurDir, "r")) + if (SetCurrentDirectory(ssCurDir)) { + if (GetCurrentDirectory( + sizeof(szCurDir)/sizeof(TCHAR), szCurDir)) { + return cvstring(szCurDir); + /* create the result string + stdputstr("Current Directory: "); + stdputstr(szCurDir); + stdputstr("\n"); */ + } } } - stdputstr("Directory Setting Error\n"); + if (verbose) stdputstr("Directory Setting Error\n"); /* return nil on error*/ return NIL; } + +// test if source matches "c:\\windows" (case insensitive) +// +static int is_windows_dir(char *source) +{ + char *windows_dir = "c:\\windows"; + while (*source) { + if (!*windows_dir || tolower(*source++) != *windows_dir++) { + return FALSE; + } + } + return !*windows_dir; +} + + /* xget_temp_path -- get a path to create temp files */ LVAL xget_temp_path() { char *p; char szDir[MAX_PATH]; - char szDirLC[MAX_PATH]; int rslt = GetTempPath(MAX_PATH, szDir); - if (rslt > MAX_PATH || rslt <= 0) { - return cvstring(""); - } else { - /* Vista apparently treats c:\windows with + if (!(rslt > MAX_PATH || rslt <= 0)) { + /* Vista apparently treats c:\windows with * special semantics, so just don't allow * GetTempPath to put us in c:\windows... */ - strcpy(szDirLC, szDir); /* convert to lower case */ - for (p = szDirLC; *p; p++) { - *p = tolower(*p); - } - if (strstr(szDirLC, "c:\\windows")) { - /* c:\windows is bad. */ - return cvstring(""); + if (!is_windows_dir(szDir)) { + return cvstring(szDir); } + } + // if not defined or "c:\\windows", which is bad + p = getenv("TEMP"); + if (p && strlen(p) < MAX_PATH) strcpy(szDir, p); + else *szDir = 0; + if (!is_windows_dir(szDir)) { return cvstring(szDir); } + return cvstring(""); } //Updated End diff --git a/lib-src/libnyquist/nyquist/sys/win/msvc/winstuff.c b/lib-src/libnyquist/nyquist/sys/win/msvc/winstuff.c index 88498ec9b..65475692f 100644 --- a/lib-src/libnyquist/nyquist/sys/win/msvc/winstuff.c +++ b/lib-src/libnyquist/nyquist/sys/win/msvc/winstuff.c @@ -59,8 +59,9 @@ const char os_sepchar = ','; #include "xlisp.h" #include "cext.h" #include "userio.h" -#include "sliders.h" +#include "sliderdata.h" #include "sound.h" /* define nosc_enabled */ +#include "falloc.h" /* define table_memory */ /* externals */ extern FILE *tfp; /* transcript file pointer */ @@ -196,7 +197,7 @@ void start_input_thread() void osinit (char *banner) { - printf(banner); + printf("%s\n", banner); if (_isatty( _fileno( stdin ) ) ){ redirect_flag = 0; #ifdef DEBUG @@ -217,13 +218,23 @@ void osinit (char *banner) } FILE *osaopen (char *name, char *mode) { - return fopen (name, mode); + FILE *fp = NULL; +#ifdef SAFE_NYQUIST + if (ok_to_open(name, mode)) +#endif + fp = fopen (name, mode); + return fp; } FILE *osbopen (char *name, char *mode) { + FILE *fp = NULL; char nmode[4]; strcpy (nmode, mode); strcat (nmode, "b"); - return (fopen (name, nmode)); +#ifdef SAFE_NYQUIST + if (ok_to_open(name, mode)) +#endif + fp = fopen (name, mode); + return fp; } int osclose (FILE *fp) { return (fclose (fp)); } @@ -285,7 +296,7 @@ void osflush (void) { } -void oscheck (void) { +void oscheck (void) { MSG lpMsg; #if OSC @@ -317,6 +328,19 @@ void oscheck (void) { osflush(); xlbreak("BREAK", s_unbound); } + run_time++; + if (run_time % 30 == 0) { + // maybe we should call fflush here like in Unix; I'm not sure if this is + // a bug or it is not necessary for Windows - RBD + if (run_time_limit > 0 && run_time > run_time_limit) { + xlfatal("Run time limit exceeded"); + } + if (memory_limit > 0 && + npools * MAXPOOLSIZE + table_memory + total > + memory_limit * 1000000) { + xlfatal("Memory limit exceeded"); + } + } } //Update end @@ -351,6 +375,7 @@ static char osdir_path[OSDIR_MAX_PATH]; // osdir_list_start -- prepare to list a directory int osdir_list_start(char *path) { + if (!ok_to_open(path, "r")) return FALSE; if (strlen(path) >= OSDIR_MAX_PATH - 2) { xlcerror("LISTDIR path too big", "return nil", NULL); return FALSE; @@ -368,7 +393,7 @@ int osdir_list_start(char *path) } -char *osdir_list_next() +const char *osdir_list_next() { if (FindNextFile(hFind, &FindFileData) == 0) { osdir_list_status = OSDIR_LIST_DONE; diff --git a/lib-src/libnyquist/nyquist/sys/win/nyqrelide.iss b/lib-src/libnyquist/nyquist/sys/win/nyqrelide.iss new file mode 100644 index 000000000..05b112374 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/nyqrelide.iss @@ -0,0 +1,45 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +[Setup] +; NOTE: The value of AppId uniquely identifies this application. +; Do not use the same AppId value in installers for other applications. +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) +AppId={{3E29123D-0726-441C-8A38-42836B05F74C} +AppName=NyquistIDE +AppVerName=NyquistIDE 3.08 +AppPublisher=Roger B. Dannenberg +AppPublisherURL=http://www.cs.cmu.edu/~music/nyquist +AppSupportURL=http://www.cs.cmu.edu/~music/nyquist +AppUpdatesURL=http://www.cs.cmu.edu/~music/nyquist +DefaultDirName={pf}\Nyquist +DefaultGroupName=Nyquist +LicenseFile=nyqrelide\license.txt +InfoAfterFile=nyqrelide\Readme.txt +OutputDir=setup +OutputBaseFilename=setupnyqiderun +SetupIconFile=sys\win\wingui\nycon.ico +SourceDir=c:\Users\Roger\research\nyquist2013 +Compression=lzma +SolidCompression=yes + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked + +[Files] +Source: "nyqrelide\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +; NOTE: Don't use "Flags: ignoreversion" on any shared system files + +[Registry] +Root: HKLM32; Subkey: "Software\CMU\Nyquist"; ValueType: string; ValueName: "XLISPPATH"; ValueData: "{app}\runtime,{app}\lib" + +[Icons] +Name: "{group}\NyquistIDE"; Filename: "{app}\jnyqide.bat"; WorkingDir: "{app}" +Name: "{commondesktop}\NyquistIDE"; Filename: "{app}\jnyqide.bat"; WorkingDir: "{app}"; Tasks: desktopicon + +[Run] +Filename: "{app}\jnyqide.bat"; WorkingDir: "{app}"; Description: "{cm:LaunchProgram,NyquistIDE}"; Flags: shellexec postinstall skipifsilent + diff --git a/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj b/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj new file mode 100644 index 000000000..feeaf8151 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj @@ -0,0 +1,1270 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {208E5158-7B25-4185-8D8E-5E5BFC2153EC} + nyquist + + + + Application + false + NotSet + + + Application + false + NotSet + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)WinRel\ + $(SolutionDir)WinRel\ + false + $(SolutionDir)WinDebug\ + $(SolutionDir)WinDebug\ + true + ..\..\..\FLAC\win32;..\..\..\Win32\Release;..\..\..\liblo\lib\Release;$(LibraryPath) + ..\..\..\Win32\Debug;..\..\..\liblo\lib\Debug;$(LibraryPath) + C:\Users\Roger\research\nyquist\cmt;C:\Users\Roger\research\nyquist\sys\win\msvc;$(IncludePath) + C:\Users\Roger\research\nyquist\cmt;C:\Users\Roger\research\nyquist\sys\win\msvc;$(IncludePath) + + + + ..\..\..\WinRel/nyquist.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\..\xlisp;..\..\..\snd;..\..\..\nyqsrc;..\..\..\tran;..\..\..\cmt;..\..\..\liblo;..\..\..\nyqstk;..\..\..\nyqstk\include;..\..\..\sys\win\msvc;..\..\..\ffts\src;..\..\..\portaudio\include;..\..\..\nylsf;..\..\..\portaudio\src\common;..\..\..\liblo\pthreads.2;..\..\..\FLAC\include;..\..\..\libogg\include;..\..\..\libvorbis\include;%(AdditionalIncludeDirectories) + OSC;WIN32;CMTSTUFF;_CONSOLE;NDEBUG;FLAC__NO_DLL;PA_USE_WMME;%(PreprocessorDefinitions) + true + MultiThreaded + true + ..\..\..\WinRel/nyquist.pch + ..\..\..\WinRel/ + ..\..\..\WinRel/ + ..\..\..\WinRel/ + Level3 + true + 4996;%(DisableSpecificWarnings) + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + /VERBOSE:LIB %(AdditionalOptions) + wsock32.lib;winmm.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;setupapi.lib;libFLAC_static.lib;libogg_static.lib;libvorbis_static.lib;libvorbisfile_static.lib;liblo_static.lib;libportaudio_static.lib;libsndfile_static.lib;%(AdditionalDependencies) + ..\..\..\WinRel/nyquist.exe + true + ..\..\..\WinRel/nyquist.pdb + Console + false + + + MachineX86 + + + false + + + true + ..\..\..\WinRel/nyquist.bsc + + + true + + + + + ..\..\..\WinDebug/nyquist.tlb + + + + + Disabled + ..\..\..\xlisp;..\..\..\snd;..\..\..\nyqsrc;..\..\..\tran;..\..\..\cmt;..\..\..\liblo;..\..\..\nyqstk;..\..\..\nyqstk\include;..\..\..\sys\win\msvc;..\..\..\ffts\src;..\..\..\portaudio\include;..\..\..\nylsf;..\..\..\portaudio\src\common;..\..\..\liblo\pthreads.2;..\..\..\FLAC\include;..\..\..\libogg\include;..\..\..\libvorbis\include;%(AdditionalIncludeDirectories) + OSC;WIN32;CMTSTUFF;_CONSOLE;_DEBUG;PA_USE_WDMKS;FLAC__NO_DLL;PA_USE_WMME;%(PreprocessorDefinitions) + true + MultiThreadedDebugDLL + ..\..\..\WinDebug/nyquist.pch + ..\..\..\WinDebug/ + ..\..\..\WinDebug/ + ..\..\..\WinDebug/ + Level3 + true + EditAndContinue + 4996;%(DisableSpecificWarnings) + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + /VERBOSE:LIB + wsock32.lib;winmm.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;setupapi.lib;libFLAC_static.lib;libogg_static.lib;libvorbis_static.lib;libvorbisfile_static.lib;liblo_static.lib;libsndfile_static.lib;libportaudio_static.lib;%(AdditionalDependencies) + true + true + ..\..\..\WinDebug/nyquist.pdb + Console + false + + + MachineX86 + + + true + ..\..\..\WinDebug/nyquist.bsc + + + false + + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + $(IntDir)%(Filename)1.obj + $(IntDir)%(Filename)1.xdc + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj.user b/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj.user new file mode 100644 index 000000000..695b5c78b --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/vc2010/nyquist.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/button.h b/lib-src/libnyquist/nyquist/sys/win/wingui/button.h new file mode 100644 index 000000000..1f5e24800 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/button.h @@ -0,0 +1,2 @@ +// button.h -- simple slider input + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/cppext.h b/lib-src/libnyquist/nyquist/sys/win/wingui/cppext.h new file mode 100644 index 000000000..319449ad0 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/cppext.h @@ -0,0 +1,39 @@ +#pragma warning( disable: 4237 ) // eub: temporary kludge + +// RBD -- this will define true, false, bool +#include "yvals.h" + +//these preprocessor checks seem to get rid of compiler +// error (redecl boolean) +// typedef int bool; +//#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +//#endif + +#define EOS '\000' + +// now defined by yvals.h: +//#define true 1 +//#define false 0 + +#define MALLOC ::malloc // note -- these macros are not consistently used +#define FREE ::free + +void *MEMGET(long n); +void *MEMFREE(void *data, long n); + +#define STREQ(a, b) (strcmp((a), (b)) == 0) + +typedef unsigned long uint32; +typedef long int32; +typedef unsigned short uint16; +typedef short int16; +typedef unsigned char uint8; + +//istvan 082197 +// RBD commented out the following, instead, we're including yvals.h, +// a microsoft-dependent file +// #ifndef bool +// typedef unsigned char bool; +// #endif diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/longque.cpp b/lib-src/libnyquist/nyquist/sys/win/wingui/longque.cpp new file mode 100644 index 000000000..c47764961 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/longque.cpp @@ -0,0 +1,34 @@ +#include "stddef.h" +#include "cppext.h" +#include "longque.h" +#include "stdlib.h" + +void longque::init(int size) +{ + head = 0; + tail = 0; + count = 0; + max = size; + buff = (long *) malloc(sizeof(long) * size); +} + + +void longque::finish() +{ + free(buff); +} + + +//1 producer-consumer safe +long longque::remove() +{ + long l; + if (count <= 0) return 0; + count--; + l = buff[head++]; + if (head == max) head = 0; + return l; +} + + + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/longque.h b/lib-src/libnyquist/nyquist/sys/win/wingui/longque.h new file mode 100644 index 000000000..c8e1e0ab7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/longque.h @@ -0,0 +1,28 @@ +class longque { +public: + void init(int size); + void finish(); + //1 producer-consumer safe + void insert(long l) { + buff[tail] = l; + count++; + tail++; + if (tail == max) tail = 0; + } + long remove(); + bool fullp() { + return count >= max; + } + bool emptyp() { + return count <= 0; + } +protected: + int max; + long *buff; + int head; + int tail; + int count; +}; + + + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/resource.h b/lib-src/libnyquist/nyquist/sys/win/wingui/resource.h new file mode 100644 index 000000000..7db69c169 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/resource.h @@ -0,0 +1,21 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by winmain.rc +// +#define IDM_ABOUT 100 +#define IDI_NYCON 101 +#define ID_FILE_LOAD 101 +#define ID_FILE_RELOAD 102 +#define ID_FILE_EXIT 103 +#define IDC_STATIC -1 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_COMMAND_VALUE 104 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/slider.h b/lib-src/libnyquist/nyquist/sys/win/wingui/slider.h new file mode 100644 index 000000000..9b765adef --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/slider.h @@ -0,0 +1,6 @@ +// slider.h -- simple slider input + +#define NUMSLIDERS 9 +extern HWND sliders[NUMSLIDERS]; + +void set_slider_pos(HWND hwnd, int ival); diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/textio.cpp b/lib-src/libnyquist/nyquist/sys/win/wingui/textio.cpp new file mode 100644 index 000000000..0d3f5f268 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/textio.cpp @@ -0,0 +1,248 @@ +// textio.cpp -- handles text input and output to edit control + + +/* +Overview of character input: + ostgetc is called to get characters from stdin for XLisp + ostgetc gets characters using ggetchar() and performs line editing + ggetchar gets characters using wait_ascii() + wait_ascii() get characters from typein:queue; it calls + process_win_events if there are no characters, and it returns + ABORT_CHAR or BREAK_CHAR if abort_flag is set + characters get into typein::queue when the key handler is called + + get_ascii is similar to wait_ascii, but it doesn't wait: it just + checks for input with process_win_events and returns a character + if there is one, otherwise, it returns false +*/ + +#include +#include +#include +#include +#include "cppext.h" +#include "longque.h" +#include "textio.h" +#include "typein.h" + +#include "button.h" +#include "slider.h" +#include "winmain.h" +#include "assert.h" +extern "C" { +#include "xlisp.h" +} + +#define GPRINTF_MESSAGE_LEN 500 + + +//istvanmerge +//int abort_flag = 0; + +longque typein::queue; + + +void typein::init() +{ + queue.init(100); +} + + +void typein::finish() +{ + queue.finish(); +} + + + +void typein::handler(char *inp) +{ + if (!queue.fullp()) { + if (*inp == ABORT_CHAR) { + abort_flag = ABORT_LEVEL; + free(inp); + } else if (!abort_flag && *inp == BREAK_CHAR) { + abort_flag = BREAK_LEVEL; + free(inp); + } else if (!abort_flag && *inp == INFO_CHAR) { + xinfo(); + free(inp); + } else queue.insert((long) inp); + } +} + + +extern char *next_ascii; + +extern "C" +int get_ascii(char *c) +{ + check_aborted(); /* input buffer check */ + if (!next_ascii && typein::queue.emptyp()) return false; + *c = wait_ascii(); + return true; // recurse with new string +} + + +/* check_aborted -- see if any characters are available, check for ctrl C */ +extern "C" +int check_aborted() +{ + process_win_events(USE_PEEK); + /* handle input messages, if ^C, handler will set abort flag */ + return abort_flag; +} + + + +/* define with va_alist and use vsprintf to get temp */ +extern "C" +void gprintf(long where, char *format, ...) +{ + char temp[GPRINTF_MESSAGE_LEN]; + va_list pvar; + va_start(pvar, format); + _vsnprintf(temp, GPRINTF_MESSAGE_LEN, format, pvar); + va_end(pvar); + + switch((long) where) { + case GTRANS: + break; + case GERROR: + break; + case GFATAL: + edit_append("FATAL: "); + edit_append(temp); + break; + case GDEBUG: + edit_append("DEBUG: "); + edit_append(temp); + break; + default: + edit_append("UNKNOWN: "); + edit_append(temp); + break; + } + edit_append(temp); +} + +#if defined(nyquist_printf) +#error "nyquist_printf should not be defined yet" +#endif + +extern "C" +void nyquist_printf(const char *format, ...) +{ + char temp[GPRINTF_MESSAGE_LEN]; + va_list pvar; + va_start(pvar, format); + _vsnprintf(temp, GPRINTF_MESSAGE_LEN, format, pvar); + va_end(pvar); + edit_append(temp); +} + +/************************************************************************** +* gputchar +* General putchar +**************************************************************************/ +extern "C" +void gputchar(int c) +{ + char tmp[4]; + tmp[0] = c; + tmp[1] = 0; + edit_append(tmp); +} + + +/************************************************************************** +* ggetchar +* General getchar +**************************************************************************/ + +extern "C" +int ggetchar() +{ + return wait_ascii(); +} + +/************************************************************************** +* ggets +* General gets +**************************************************************************/ + +extern "C" +char *ggets(char *str) +{ + char *s = str; + int c; + + do { + c = ggetchar(); + if (c == '\b' /* backspace */) { + if (s != str) { + gputchar('\b'); + gputchar((int)' '); + gputchar('\b'); + s--; + } else { + gputchar((int)0x07); + } + } else *s++ = (char) c; + } while (c != (int) '\n' && !abort_flag); + + *(s-1) = EOS; + if (abort_flag) *str = EOS; + return str; +} + + +/**************************************************************************** +* askbool +* Inputs: +* char *prompt: string to prompt for user input +* int deflt: true or false default +* Returns: +* boolean: true or false as entered by user +* Effect: +* prompts user for yes or no input, returns result +****************************************************************************/ +extern "C" +int askbool(char *prompt, int deflt) +{ +#define undefined -1 + char defchar; /* the default answer */ + char c; /* user input */ + char in_string[100]; + int result = -1; /* the result: -1 = undefined, 0 = false, 1 = true */ + if (deflt) defchar = 'y'; + else defchar = 'n'; + while (result == undefined) { + gprintf(GTRANS, "%s? [%c]: ", prompt, defchar); + ggets(in_string); + c = in_string[0]; + if (islower(c)) c = toupper(c); + if (c == 'Y') result = true; + else if (c == 'N') result = false; + else if (c == EOS) result = deflt; + else if (abort_flag) result = deflt; + /* space before Please to separate from user's type-in: */ + else gprintf(GTRANS, " Please type Y or N.\n"); + } + if (abort_flag == BREAK_LEVEL) { + abort_flag = 0; + result = deflt; + gprintf(GTRANS, "\n"); + } + return result; +} + + +extern "C" +void io_init() +{ +} + + + + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/textio.h b/lib-src/libnyquist/nyquist/sys/win/wingui/textio.h new file mode 100644 index 000000000..a7a269cd7 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/textio.h @@ -0,0 +1,36 @@ +#define CR '\n' +#define ABORT_CHAR 0x03 +#define BREAK_CHAR 0x02 +#define CLEANUP_CHAR 0x07 +#define INFO_CHAR '\024' + +#define BREAK_LEVEL 1 +#define ABORT_LEVEL 2 + +#ifdef __cplusplus +extern "C" { +#endif + +int ggetchar(void); +void gprintf(long where, char *format, ...); +void gputchar(int c); +int get_ascii(char *c); +char *ggets(char *str); +int check_aborted(); +int askbool(char *prompt, int deflt); +char wait_ascii(); +void io_init(); +/* this is not entirely kosher: nyquist_printf is also declared in sound.h + so that all C programs will see it. Perhaps it should go into cext.h, but + I'm not sure I want to drag all that into here. + */ +void nyquist_printf(const char *format, ...); + +#ifdef __cplusplus +} +#endif + +#define GTRANS 0 +#define GERROR 1 +#define GFATAL 2 +#define GDEBUG 3 diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/typein.h b/lib-src/libnyquist/nyquist/sys/win/wingui/typein.h new file mode 100644 index 000000000..3ab5b759e --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/typein.h @@ -0,0 +1,8 @@ +class typein { +public: + static longque queue; + static void init(void); + static void finish(void); + static void handler(char *inp); +}; + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/winguistuff.c b/lib-src/libnyquist/nyquist/sys/win/wingui/winguistuff.c new file mode 100644 index 000000000..e977f9a06 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/winguistuff.c @@ -0,0 +1,366 @@ +/* winstuff.c - windows interface routines for xlisp */ +/* Written by Chris Tchou. */ +/* This file contains the stuff that the other xlisp files call directly. */ + +#include "windows.h" +#include +//#include /* for Random */ +#include /* for DisposPtr */ +#include +//#include /* for ExitToShell */ +#include "xlisp.h" +#include "textio.h" + +#if OSC +#include "sliders.h" /* define sliders */ +#include "sound.h" /* define nosc_enabled */ +#endif +#include "falloc.h" /* define table_memory */ + +const char os_pathchar = '\\'; +const char os_sepchar = ','; + + +/* externals */ +extern FILE *tfp; /* transcript file pointer */ +extern int cursorPos; +extern char *macgets (void); + +#define LBSIZE 200 + +/* local variables */ +static char lbuf[LBSIZE]; +static int lpos[LBSIZE]; +static int lindex; +static int lcount = 0; +static int lposition; +static int line_edit = TRUE; + +//int isascii (char c) { return 1; } /* every char is an ascii char, isn't it? */ + +void osinit(const char *banner) { +// int i; + char version[] = "\nWindows console interface by Roger Dannenberg.\n"; +// InitMac (); /* initialize the mac interface routines */ +// lposition = 0; /* initialize the line editor */ +// for (i = 0; banner[i] != '\0'; i++) macputc (banner[i]); +// for (i = 0; version[i] != '\0'; i++) macputc (version[i]); + nyquist_printf(banner); + nyquist_printf(version); +} + + +FILE *osaopen (const char *name, const char *mode) { + FILE *fp = NULL; + if (ok_to_open(name, mode)) + fp = fopen (name, mode); + return fp; +} + +FILE *osbopen (const char *name, const char *mode) { + FILE *fp = NULL; + char nmode[4]; + strcpy (nmode, mode); strcat (nmode, "b"); + if (ok_to_open(name, mode)) + fp = fopen (name, mode); + return fp; +} + +int osclose (FILE *fp) { return (fclose (fp)); } +int osaputc (int ch, FILE *fp) { return (putc (ch, fp)); } +int osbputc (int ch, FILE *fp) { return (putc (ch, fp)); } +void osoutflush(FILE *fp) { fflush(fp); } + +/* osagetc - get a character from an ascii file */ +int osagetc(fp) + FILE *fp; +{ + return (getc(fp)); +} + + +extern int abort_flag; + + +#define OLDGETC +#ifdef OLDGETC + +int ostgetc (void) { +/* int i; + + if (numChars <= 0) { /* get some more */ +/* if (linebuf) DisposPtr (linebuf); + linebuf = macgets (); + i = 0; + while (linebuf[i] != '\0') i++; + numChars = i; + if (tfp) for (i = 0; i < numChars; i++) osaputc (linebuf[i], tfp); + lineptr = linebuf; + } + numChars--; + if (*lineptr == '\r') { + lineptr++; + return '\n'; + } else return (*lineptr++);*/ + + int ch = ggetchar(); + oscheck(); /* in case user typed ^C */ + if (ch == BREAK_CHAR && abort_flag == BREAK_LEVEL) { + abort_flag = 0; + } + return ch; +} + +#else + +void end_of_line_edit() +{ + line_edit = FALSE; + if (tfp) { + for (lindex = 0; lindex < lcount; ++lindex) + osaputc(lbuf[lindex], tfp); + } + lindex = 0; +} + + + +int ostgetc() +{ +/* + * NOTE: lbuf[] accumulates characters as they are typed + * lpos[] is the column position of the characters + * lcount is the number of characters in lbuf + * lposition is current position + * lindex is index of next char to output + * line_edit is true iff we're inputing characters + * + */ + int ch; + + while (line_edit) { + ch = ggetchar(); + oscheck(); /* in case user typed ^C */ + if (ch == BREAK_CHAR && abort_flag == BREAK_LEVEL) { + abort_flag = 0; + } + /* assume for now we should add the character */ + lbuf[lcount] = ch; + lpos[lcount] = lposition; + lcount++; + lposition++; + + /* now do all the special character processing */ + switch (ch) { + case '\n': + lposition = 0; + end_of_line_edit(); + gputchar('\r'); + gputchar(ch); + break; + /* delete key generates: 1b, 5b, 33, 7E + which is: ESC, [, 3, ~ */ + case '\010': /* backspace */ + case '\177': /* delete */ + lcount--; /* take out backspace or delete char */ + lposition--; + if (lcount) { + lcount--; + while (lposition > lpos[lcount]) { + gputchar('\010'); + gputchar(' '); + gputchar('\010'); + lposition--; + } + } + break; + case '\025': /* control-u */ + lcount--; + lposition--; + if (lcount) { + while (lposition > lpos[0]) { + gputchar('\010'); + gputchar(' '); + gputchar('\010'); + lposition--; + } + lcount = 0; + } + break; + + /* note that control-z never reaches here */ + case '\003': /* control-c */ + xltoplevel(); + lcount = 0; + break; + case '\007': /* control-g */ + xlcleanup(); + lcount = 0; + break; + case '\020': /* control-p */ + xlcontinue(); + lcount = 0; + break; + case '\002': + ostputc('\n'); /* control-b */ + xlbreak("BREAK",s_unbound); + break; + case '\024': /* control-t */ + xinfo(); + lcount = 0; + break; + case '\t': /* TAB */ + lposition--; /* undo the increment above */ + do { + lposition++; + gputchar(' '); + } while (lposition & 7); + break; + default: + gputchar(ch); + break; + } + } + if (lindex + 1 >= lcount) { + lcount = 0; + line_edit = TRUE; + } + ch = lbuf[lindex++]; + /* printf("[%c]", ch); */ + fflush(stdout); + return ch; +} +#endif + + +void ostputc (int ch) { +// macputc (ch); + gputchar(ch); // console + + if (tfp) osaputc (ch, tfp); +} + +void ostoutflush() +{ + if (tfp) fflush(tfp); + /* since ostputc calls gputchar which just calls putchar, + I'm going to flush stdout rather than extending the + "g" abstraction with a gflush() call. -RBD + */ + fflush(stdout); +} + +void osflush (void) { + lindex = lcount = lposition = 0; + line_edit = TRUE; +} + +extern int abort_flag; + +void oscheck (void) +{ + +#if OSC + if (nosc_enabled) nosc_poll(); +#endif + + check_aborted(); + if (abort_flag == ABORT_LEVEL) { + abort_flag = 0; + osflush(); + xltoplevel(); + } else if (abort_flag == BREAK_LEVEL) { + abort_flag = 0; + osflush(); + xlbreak("BREAK",s_unbound); + } + run_time++; + if (run_time % 30 == 0) { + // maybe we should call fflush here like in Unix; I'm not sure if this is + // a bug or it is not necessary for Windows - RBD + if (run_time_limit > 0 && run_time > run_time_limit) { + xlfatal("Run time limit exceeded"); + } + if (memory_limit > 0 && + npools * MAXPOOLSIZE + table_memory + total > + memory_limit * 1000000) { + xlfatal("Memory limit exceeded"); + } + } +} + +void oserror(const char *msg) { + char line[100], *p; + sprintf (line,"error: %s\n",msg); + for (p = line; *p != '\0'; ++p) ostputc (*p); +} + +void osfinish(void) { + portaudio_exit(); + /* dispose of everything... */ +// if (linebuf) DisposPtr (linebuf); +// MacWrapUp (); +// ExitToShell (); +} + +int renamebackup (char *filename) { return 0; } + + + +static WIN32_FIND_DATA FindFileData; +static HANDLE hFind = INVALID_HANDLE_VALUE; +#define OSDIR_LIST_READY 0 +#define OSDIR_LIST_STARTED 1 +#define OSDIR_LIST_DONE 2 +static osdir_list_status = OSDIR_LIST_READY; +#define OSDIR_MAX_PATH 256 +static char osdir_path[OSDIR_MAX_PATH]; + +// osdir_list_start -- prepare to list a directory +int osdir_list_start(const char *path) +{ + if (strlen(path) >= OSDIR_MAX_PATH - 2) { + xlcerror("LISTDIR path too big", "return nil", NULL); + return FALSE; + } + if (!ok_to_open(path, "r")) return FALSE; + strcpy(osdir_path, path); + strcat(osdir_path, "/*"); // make a pattern to match all files + if (osdir_list_status != OSDIR_LIST_READY) { + osdir_list_finish(); // close previously interrupted listing + } + hFind = FindFirstFile(osdir_path, &FindFileData); // get the "." + if (hFind == INVALID_HANDLE_VALUE) return FALSE; + if (FindNextFile(hFind, &FindFileData) == 0) return FALSE; // get the ".." + osdir_list_status = OSDIR_LIST_STARTED; + return TRUE; +} + + +const char *osdir_list_next() +{ + if (FindNextFile(hFind, &FindFileData) == 0) { + osdir_list_status = OSDIR_LIST_DONE; + return NULL; + } + return FindFileData.cFileName; +} + +void osdir_list_finish() +{ + if (osdir_list_status != OSDIR_LIST_READY) { + FindClose(hFind); + } + osdir_list_status = OSDIR_LIST_READY; +} + + +/* xechoenabled -- set/clear echo_enabled flag (unix only) */ +LVAL xechoenabled() +{ + int flag = (xlgetarg() != NULL); + xllastarg(); + // echo_enabled = flag; -- do nothing in Windows + return NULL; +} + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.cpp b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.cpp new file mode 100644 index 000000000..8b21f08ed --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.cpp @@ -0,0 +1,657 @@ +#include "windows.h" /* required for all Windows applications */ +#include "cppext.h" +#include "longque.h" +#include "button.h" +#include "slider.h" +#include "winmain.h" /* specific to this program */ +#include "stdlib.h" +#include "string.h" +#include "stdio.h" +#include "textio.h" +#include "mmsystem.h" +#include +#include // for Sleep() +#include "stdio.h" +#include "resource.h" +#include "typein.h" +#include "xlispfns.h" +#include "winfun.h" + +//#define THUMBTRACK // tries to get continuous scrollbars with SB_THUMBTRACK messages. + // doesn't work -- zone 1 doesn't seem to wake up until the button-up. + +//#include "saudio.h" + +//#define D if(0) + +HWND buttons[NUMBUTTONS]; +HWND sliders[NUMSLIDERS]; + +HWND textinput; +HWND textoutput; +HFONT hfont; + +HWND alt_win; +WNDPROC alt_proc; + + +extern "C" { + HINSTANCE hInst; /* current instance */ + HWND hMainWindow; /* main window handle */ +} +/* HINSTANCE hInst; /* current instance */ +/* HWND hMainWindow; /* main window handle */ + + +int quit_value; // return value from WinMain +int abort_flag = 0; + + +// there's some state here: +// when we get a message from the input queue, it is an entire +// string. We save the string and a pointer to the next char +// +char *get_ascii_string = NULL; +char *next_ascii = NULL; + +//asciiwait -- wait for ascii input +char wait_ascii() +{ + if (next_ascii && *next_ascii) { + char c = *next_ascii++; + if (c == '\r') c = '\n'; + _RPT1(_CRT_WARN, "|%c|", c); + return c; + } + if (get_ascii_string) { + _RPT2(_CRT_WARN, "free get_ascii_string %x %s\n", + get_ascii_string, get_ascii_string); + free(get_ascii_string); + get_ascii_string = NULL; + next_ascii = NULL; + } + // no input, so look for Windows messages + while (typein::queue.emptyp() && !abort_flag) { + process_win_events(USE_GET); + } + if (abort_flag == ABORT_LEVEL) return ABORT_CHAR; + if (abort_flag == BREAK_LEVEL) return BREAK_CHAR; + get_ascii_string = (char *) typein::queue.remove(); + _RPT2(_CRT_WARN, "removed %x: %s\n", get_ascii_string, get_ascii_string); + edit_append(get_ascii_string); + next_ascii = get_ascii_string; + return wait_ascii(); +} + + +//process_win_events -- receive and handle windows by either: +// USE_PEEK: non-blocking +// USE_GET: blocks +void process_win_events(int method) +{ + MSG msg; + edit_append(""); // flush the output + if (method == USE_GET) { + //blocks until at least a message arrives + if (GetMessage(&msg, //msg stored here + NULL, //receive ALL application messages + NULL,NULL)) //no msg filtering + { + //standard windows loop + TranslateMessage(&msg); //posts another msg if there is a virtual to WM_CHAR mapping + DispatchMessage(&msg); //calls object's receive function + } else { + //is this ever entered??? + quit_value = msg.wParam; + abort_flag = ABORT_CHAR; + exit(0); + } + } else { + //default: process all messges that already exist (non-blocking) + while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE | PM_NOYIELD)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +} + +//STUFF TO PROVIDE CONSOLE------------------------------------------------- +//terminate strings and strip out LF +int lf2crlf(char *dest, char *src) +{ + char *d = dest; + while (*src) { + if (*src == '\n') { + *dest++ = '\r'; + } + *dest++ = *src++; + } + *dest = EOS; + return dest - d; /* string length */ +} + +#define EDIT_HIGH_WATER 10000 +#define EDIT_LOW_WATER 9000 + +#define EABUFFMAX 110 +static char eabuff[EABUFFMAX]; /* edit_append buffer */ +static char eabuffx = 0; + +static void edit_append2(char *txt2); + +/* edit_append -- optimizes output by buffering + * + * call with empty string to flush buffer + */ +void edit_append(char *txt) +{ + /* new algorithm to deal with long strings on input: + * if input is longer than 50, insert a zero and + * call recursively; then undo the zero and continue. + */ + char txt2[100]; + while (strlen(txt) > 50) { + char temp = txt[50]; + txt[50] = 0; + edit_append(txt); /* strlen(txt) == 50 */ + txt = txt + 50; + txt[0] = temp; + } + int len = lf2crlf(txt2, txt); + if ((eabuffx + len + 1 > EABUFFMAX) || ((len == 0) && eabuffx)) { + edit_append2(eabuff); + eabuffx = 0; + } + strcpy(eabuff + eabuffx, txt2); + eabuffx += len; +} + + +static void edit_append2(char *txt2) +{ + int len; + int lines; + if (*txt2 == '\b') { // special case: erase last character + long len = SendMessage(textoutput, WM_GETTEXTLENGTH, (WPARAM) 0, (LPARAM) 0); + if (len > 0) { + // select the last character: + SendMessage(textoutput, EM_SETSEL, (WPARAM) len - 1, (LPARAM) -1); + // delete the last character: + SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) "")); + } + return; + } + // to put insertion point at the end, first select + // everything ... + //wparam is UINT ; lparam is LONG + SendMessage(textoutput, EM_SETSEL, (WPARAM) 0, (LPARAM) -1); + // then remove selection, leaving cursor at the end: + SendMessage(textoutput, EM_SETSEL, (WPARAM) -1, (LPARAM) -1); + // now, replacement actually appends to the buffer: + SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) txt2)); + // if the number of characters exceeds EDIT_HIGH_WATER, then + // trim the number of characters to EDIT_LOW_WATER by deleting + // all lines up to the one containing total-EDIT_LOW_WATER + lines = (int) SendMessage(textoutput, EM_GETLINECOUNT, (WPARAM) 0, (LPARAM) 0); + len = (int) SendMessage(textoutput, EM_LINEINDEX, (WPARAM)(lines - 1), (LPARAM) 0); + len += (int) SendMessage(textoutput, EM_LINELENGTH, (WPARAM)(lines - 1), (LPARAM) 0); + if (len > EDIT_HIGH_WATER) { + //these SendMessages operate to completion + lines = (int) SendMessage(textoutput, EM_LINEFROMCHAR, + (WPARAM)(len - EDIT_LOW_WATER), (LPARAM) 0); + len = (int) SendMessage(textoutput, EM_LINEINDEX, (WPARAM)(lines), (LPARAM) 0); + SendMessage(textoutput, EM_SETSEL, (WPARAM) 0, (LPARAM)(len)); + SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) "")); + } +} + +//THE STUFF REQUIRED BY WINDOWS APPLICATIONS---------------------------------- + + +// we will subclass the textinput window with a window procedure that detects +// the Enter key (hex 0x0d) and sets a flag. Then in the main window proc, +// when an EN_CHANGE message is received, we will know the user typed Enter, +// so we can transfer the text to XLISP. +// +// This would be a good place also to add editing characters to scroll through +// previous entries. +// +WNDPROC DefaultEditWndProc = NULL; +#define ENTER_KEY 0x0d +bool enter_flag = false; + + +long CALLBACK EditWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == WM_CHAR) { + if (wParam == ENTER_KEY) enter_flag = true; + _RPT1(_CRT_WARN, "wm_char is %x\n", wParam); + } + return CallWindowProc(DefaultEditWndProc, hWnd, message, wParam, lParam); +} + + + +//All applications need to register +BOOL InitApplication(HINSTANCE hInstance /* current instance */) +{ + WNDCLASS wc; + + /* Fill in window class structure with parameters that describe the */ + /* main window. */ + wc.style = NULL; /* Class style(s). */ + wc.lpfnWndProc = MainWndProc; /* Function to retrieve messages for */ + /* windows of this class. */ + wc.cbClsExtra = 0; /* No per-class extra data. */ + wc.cbWndExtra = 0; /* No per-window extra data. */ + wc.hInstance = hInstance; /* Application that owns the class. */ + wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NYCON)); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); + wc.lpszMenuName = "MAINMENU"; /* Name of menu resource in .RC file. */ + wc.lpszClassName = "CMTWClass"; /* Name used in call to CreateWindow. */ + + /* Register the window class and return success/failure code. */ + return (RegisterClass(&wc)); + +} + + +static char *button_names[NUMBUTTONS] = { "Load File", "Reload File", + "Replay Sound", "Break", "Top", "Up", "Info", "F1", "F2", "F3", "F4" }; + + +//each time this application is run, the following program must be run +BOOL InitInstance( + HINSTANCE hInstance, /* Current instance identifier. */ + int nCmdShow) /* Param for first ShowWindow() call. */ +{ + int i; + RECT rect; + LRESULT rslt; + + /* Save the instance handle in static variable, which will be used in */ + /* many subsequent calls from this application to Windows. */ + + hInst = hInstance; + + /* Create a main window for this application instance. */ + + hMainWindow = CreateWindow( + "CMTWClass", /* See RegisterClass() call. */ + "Nyquist", /* Text for window title bar. */ + WS_OVERLAPPEDWINDOW, /* Window style. */ + CW_USEDEFAULT, /* Default horizontal position. */ + CW_USEDEFAULT, /* Default vertical position. */ + CW_USEDEFAULT, /* Default width. */ + CW_USEDEFAULT, /* Default height. */ + NULL, /* Overlapped windows have no parent. */ + NULL, /* Use the window class menu. */ + hInstance, /* This instance owns this window. */ + NULL /* Pointer not needed. */ + ); + + /* If window could not be created, return "failure" */ + + if (!hMainWindow) + return (FALSE); + + GetClientRect(hMainWindow, (LPRECT) &rect); + + /* Make the window visible; update its client area; and return "success" */ + + const int button_y = 25; // size in pixels + const int slider_x = 20; + const int slider_gap = 1; + const int input_height = 48; // how high is input type-in edit control + int slider_xsum = slider_x * NUMSLIDERS; + int button_ysum = button_y * NUMBUTTONS_VERT; + + + ShowWindow(hMainWindow, nCmdShow); /* Show the window */ + UpdateWindow(hMainWindow); /* Sends WM_PAINT message */ + for (i = 0; i < NUMBUTTONS; i++) { + int x = 0; + int y = i * button_y; + int width = slider_xsum; + if (i > 2) { + y = (3 + (i - 3) / 2) * button_y; + width = width / 2; + if ((i & 1) == 0) x = width; + } + buttons[i] = CreateWindow("Button", //lpszClassName + button_names[i],//windowName + BS_PUSHBUTTON | //Style: 1) PB + WS_CHILD | // 2) must reside w/in parent + WS_VISIBLE, // 3) initially visible + x, y, width, button_y, + hMainWindow, //owner window + (HMENU)(IDC_BUTTON+i), + //&buttonsH[i], //child window Id + hInstance, //application instance + NULL); //WM_CREATE argument + + //activate current window & display w/current size and position + ShowWindow(buttons[i], SW_SHOW); + //update (nonempty) client area via WM_PAINT + UpdateWindow(buttons[i]); + } + + for (i=0; i= IDC_BUTTON && wid < IDC_BUTTON + NUMBUTTONS) { + SetFocus(textinput); /* get focus back */ + type_this(button_msgs[wid - IDC_BUTTON]); + } else if (wid == IDC_EDIT_INPUT) { + if (code == EN_CHANGE) { + if (enter_flag) { + enter_flag = false; + long len = SendMessage(hwndCtrl, WM_GETTEXTLENGTH, 0, 0); + len++; // allow for terminating null character + char *buffer = (char *) malloc(len); + SendMessage(hwndCtrl, WM_GETTEXT, (WPARAM) len, (LPARAM) buffer); + _RPT2(_CRT_WARN, "inserting %x: %s\n", buffer, buffer); + typein::handler(buffer); + SendMessage(hwndCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) ""); + } + } + } else if (wid == IDC_EDIT) { + if (code == EN_CHANGE) { + } else { + } + } else { + /*Let Windows process it*/ + printf("unhandled: message %d\n", message); + return (DefWindowProc(hWnd, message, wParam, lParam)); + } + break; + } + case WM_DESTROY: + //message: window being destroyed + PostQuitMessage(0); + break; +#ifdef MOUSEBUTTON_INPUT + case WM_LBUTTONDOWN: { + //message: left mouse button pressed while cursor in client area + //never used, need SetCaputure??? + int /*???*/ xPos LOWORD(lParam); + int /*???*/ yPos HIWORD(lParam); + //int /*???*/ fwKeys; virtual keys not used!!! + buffer[0] = '<'; + _itoa(xPos,buffer+1,10/*radix*/); + i = strlen(buffer); + buffer[i++] = ','; + _itoa(yPos,buffer+i,10/*radix*/); + i = strlen(buffer); + buffer[i++] = '>'; + buffer[i] = 0; + edit_append(buffer); + break; +#endif +#ifdef DEBUGINPUT + //WM_USER msg codes are from the callbacks------------------------- + case WM_USER_TIMEOUT: { + //dummy message just unblocks GetMessage + break; + } + //remaining wMsg codes generated elsewhere------------------------------------ + case WM_KILLFOCUS: { + //message: this window's loosing focus, focus must be set to new window + HWND newFocus = (HWND) wParam; + if (newFocus == textoutput) { + //why not also set buttons, sliders...??? + SetFocus(hWnd); + } + break; + } + case WM_VSCROLL: { + //message: control bar scroll I/O + //where is window scroll bar handled??? + //why is this not also a WM_COMMAND??? + HWND hwndCtrl = (HWND) lParam; + short int nPos = HIWORD(wParam); + int code = LOWORD(wParam); + int i; + for (i = 0; i < NUMSLIDERS; i++) { + if (sliders[i] == hwndCtrl) { + int pos = GetScrollPos(hwndCtrl /*parent*/, SB_CTL /*control*/); + switch (code) { + case SB_LINEUP: pos--; break; + case SB_LINEDOWN: pos++; break; + case SB_PAGEUP: pos -= 10; break; + case SB_PAGEDOWN: pos += 10; break; + case SB_ENDSCROLL: + break; //why not continue??? + case SB_THUMBTRACK: +#ifdef THUMBTRACK + pos = nPos; + break; +#else + continue; // no silly multiple messages +#endif + //break; + case SB_THUMBPOSITION: +#ifndef THUMBTRACK + pos = nPos; +#endif + break; + case SB_TOP: pos = 0; break; + case SB_BOTTOM: pos = 127; break; + default: continue; //avoid SetScrollPos + } + // SetScrollRange() set the range to 0-127, but clip just to make sure: + if (pos < 0) pos = 0; + if (pos > 127) pos = 127; + if (code != SB_ENDSCROLL +#ifdef THUMBTRACK + && code != SB_THUMBTRACK +#endif + ) { + //ctrlevents.insert(CTRLEVENT(IDC_SLIDER + i, 127 - pos)); + } + SetScrollPos(hwndCtrl /*parent*/, SB_CTL /*control sb*/, pos /*new position*/, TRUE /*redraw*/); + break; + } + } + break; + } +#endif + default: + //Pass on all unproccessed messages + return (DefWindowProc(hWnd, message, wParam, lParam)); + } + return (NULL); //all messages currently return this... +} + + +/**************************************************************************** + + FUNCTION: About(HWND, unsigned, WORD, LONG) + + PURPOSE: Processes messages for "About" dialog box + + MESSAGES: + + WM_INITDIALOG - initialize dialog box + WM_COMMAND - Input received + + COMMENTS: + + No initialization is needed for this particular dialog box, but TRUE + must be returned to Windows. + + Wait for user to click on "Ok" button, then close the dialog box. + +****************************************************************************/ + +extern "C" BOOL CALLBACK About( + HWND hDlg, /* window handle of the dialog box */ + unsigned message, /* type of message */ + WORD wParam, /* message-specific information */ + LONG lParam) +{ + switch (message) + { + case WM_INITDIALOG: /* message: initialize dialog box */ + return (TRUE); + + case WM_COMMAND: /* message: received a command */ + if (wParam == IDOK /* "OK" box selected? */ + || wParam == IDCANCEL) /* System menu close command? */ + { + EndDialog(hDlg, TRUE); /* Exits the dialog box */ + return TRUE; + } + break; + } + return FALSE; /* Didn't process a message */ +} + + +/* Load File support */ + +extern "C" + +void RegisterWindow(HWND w, WNDPROC p) { + alt_win = w; + alt_proc = p; +} diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.h b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.h new file mode 100644 index 000000000..955a9c367 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.h @@ -0,0 +1,28 @@ +#include "resource.h" + +#ifdef __cplusplus +extern "C" { +#endif + +BOOL InitApplication(HANDLE); +BOOL InitInstance(HANDLE, int); +long CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); +BOOL CALLBACK About(HWND, unsigned, WORD, LONG); +void RegisterWindow(HWND, WNDPROC); + +#define IDC_EDIT 300 +#define IDC_EDIT_INPUT 301 +#define IDC_BUTTON 400 +#define IDC_SLIDER 500 + +#define NUMBUTTONS 11 +// 7 buttons high: +#define NUMBUTTONS_VERT 7 + +extern int abort_flag; + +#ifdef __cplusplus +} +#endif + +#include "winmain2.h" diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.rc b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.rc new file mode 100644 index 000000000..9dd5de1fb --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain.rc @@ -0,0 +1,120 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +MAINMENU MENU DISCARDABLE +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Load...", ID_FILE_LOAD + MENUITEM "&Reload", ID_FILE_RELOAD + MENUITEM SEPARATOR + MENUITEM "E&xit", ID_FILE_EXIT + END + POPUP "&Help" + BEGIN + MENUITEM "&About Nyquist...", IDM_ABOUT + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +ABOUTBOX DIALOG DISCARDABLE 22, 17, 177, 98 +STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU +CAPTION "About Nyquist" +FONT 8, "MS Sans Serif" +BEGIN + CTEXT "Nyquist, a language for music composition",IDC_STATIC,0, + 5,177,8 + CTEXT " and sound synthesis.",IDC_STATIC,0,14,177,8 + CTEXT "Version 2.16",IDC_STATIC,0,76,177,8 + DEFPUSHBUTTON "OK",IDOK,145,84,32,14,WS_GROUP + CTEXT "Copyright (c) 2001, by Roger B. Dannenberg",IDC_STATIC, + 0,66,177,8 + CTEXT "http://www.cs.cmu.edu/~rbd/nyquist",IDC_STATIC,0,26,177, + 8 + ICON IDI_NYCON,IDC_STATIC,79,38,21,20 +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""windows.h""\r\n" + "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_NYCON ICON DISCARDABLE "nycon.ico" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/winmain2.h b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain2.h new file mode 100644 index 000000000..711bd7662 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/winmain2.h @@ -0,0 +1,41 @@ +extern int quit_flag; +extern int waiting_flag; +extern long start_time; // initial system time in ms +extern long the_time; // current time - updated by periodic interrupt + +extern HWND hMainWindow; /* main window handle */ + +void edit_append(char *txt); +void debugeventwait(); +bool get_mouse(int &x, int &y); +void wait_mouse(int &x, int &y); +void pause(long ms); + +// parameters to process_win_events() +#define USE_GET 0 +#define USE_PEEK 1 + +void process_win_events(int method); + +#define CTRLEVENT(a, b) (((long) (a))<<16 | (b)) + +#define WM_USER_TIMEOUT (WM_USER + 0) +#define WM_USER_TIMESHOW (WM_USER + 1) +#define WM_USER_TIMESHOW1 (WM_USER + 2) + +#define WM_USER_MIDI_INPUT (WM_USER + 10) +#define WM_USER_MIDISHOW (WM_USER + 11) +#define WM_USER_MIDISHOW1 (WM_USER + 12) + +#define WM_USER_MIDI_IN_ERROR (WM_USER + 20) +#define WM_USER_MIDI_OUT_ERROR (WM_USER + 21) + +#define TIMERCB 1 +#define MIDIINCB 2 +#define FROMTIMERCB(x) ((x) == TIMERCB) +#define FROMMIDIINCB(x) ((x) == MIDIINCB) + +#define TEXT_WIN_HT 200 + + + diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/xlextstart.c b/lib-src/libnyquist/nyquist/sys/win/wingui/xlextstart.c new file mode 100644 index 000000000..be321fe85 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/xlextstart.c @@ -0,0 +1 @@ +/* nothing to do */ diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.c b/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.c new file mode 100644 index 000000000..e9b058411 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.c @@ -0,0 +1,11 @@ +#include "xlisp.h" +#include "xlispfns.h" + + +void run_xlisp() +{ + xlisp_main_init(0,NULL); + xlisp_main(); + /* clean up */ + xlisp_wrapup(); +} diff --git a/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.h b/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.h new file mode 100644 index 000000000..256584a28 --- /dev/null +++ b/lib-src/libnyquist/nyquist/sys/win/wingui/xlispfns.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +void run_xlisp(); + +#ifdef __cplusplus +} +#endif diff --git a/lib-src/libnyquist/nyquist/tran/abs.alg b/lib-src/libnyquist/nyquist/tran/abs.alg index 2c139e687..3079d0d2b 100644 --- a/lib-src/libnyquist/nyquist/tran/abs.alg +++ b/lib-src/libnyquist/nyquist/tran/abs.alg @@ -1,9 +1,12 @@ (ABS-ALG (NAME "abs") (ARGUMENTS ("sound_type" "input")) - (ALWAYS-SCALE input) + (linear input) (START (MIN input)) - (INNER-LOOP "{ sample_type s = input; sample_type o = s; if (o < 0.0) o = -o; output = o; }") + (INNER-LOOP "{ sample_type s = input; + sample_type o = s; + if (o < 0.0) o = -o; + output = o; }") (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) ) diff --git a/lib-src/libnyquist/nyquist/tran/abs.c b/lib-src/libnyquist/nyquist/tran/abs.c index 130d18562..986854e9a 100644 --- a/lib-src/libnyquist/nyquist/tran/abs.c +++ b/lib-src/libnyquist/nyquist/tran/abs.c @@ -9,7 +9,7 @@ #include "cext.h" #include "abs.h" -void abs_free(); +void abs_free(snd_susp_type a_susp); typedef struct abs_susp_struct { @@ -22,8 +22,9 @@ typedef struct abs_susp_struct { } abs_susp_node, *abs_susp_type; -void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) +void abs_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + abs_susp_type susp = (abs_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -32,9 +33,8 @@ void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; - register sample_type input_scale_reg = susp->input->scale; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "abs_s_fetch"); + falloc_sample_block(out, "abs_n_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -51,6 +51,7 @@ void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -62,6 +63,7 @@ void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -83,7 +85,10 @@ void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ sample_type s = (input_scale_reg * *input_ptr_reg++); sample_type o = s; if (o < 0.0) o = -o; *out_ptr_reg++ = o; }; + { sample_type s = *input_ptr_reg++; + sample_type o = s; + if (o < 0.0) o = -o; + *out_ptr_reg++ = o; }; } while (--n); /* inner loop */ /* using input_ptr_reg is a bad idea on RS/6000: */ @@ -106,14 +111,12 @@ void abs_s_fetch(register abs_susp_type susp, snd_list_type snd_list) } else if (susp->susp.log_stop_cnt == susp->susp.current) { susp->logically_stopped = true; } -} /* abs_s_fetch */ +} /* abs_n_fetch */ -void abs_toss_fetch(susp, snd_list) - register abs_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void abs_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + abs_susp_type susp = (abs_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -128,25 +131,28 @@ void abs_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void abs_mark(abs_susp_type susp) +void abs_mark(snd_susp_type a_susp) { + abs_susp_type susp = (abs_susp_type) a_susp; sound_xlmark(susp->input); } -void abs_free(abs_susp_type susp) +void abs_free(snd_susp_type a_susp) { + abs_susp_type susp = (abs_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(abs_susp_node), "abs_free"); } -void abs_print_tree(abs_susp_type susp, int n) +void abs_print_tree(snd_susp_type a_susp, int n) { + abs_susp_type susp = (abs_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -158,11 +164,17 @@ sound_type snd_make_abs(sound_type input) register abs_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + /* combine scale factors of linear inputs (INPUT) */ + scale_factor *= input->scale; + input->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (input->sr < sr) { input->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, abs_susp_node, "snd_make_abs"); - susp->susp.fetch = abs_s_fetch; + susp->susp.fetch = abs_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < input->t0) sound_prepend_zeros(input, t0); @@ -171,8 +183,8 @@ sound_type snd_make_abs(sound_type input) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = abs_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = abs_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/allpoles.alg b/lib-src/libnyquist/nyquist/tran/allpoles.alg index ab2985093..c8da6870d 100644 --- a/lib-src/libnyquist/nyquist/tran/allpoles.alg +++ b/lib-src/libnyquist/nyquist/tran/allpoles.alg @@ -45,26 +45,21 @@ (CONSTANT "ak_array" "ak_coefs" "ak_len" "gain") -(SAMPLE-RATE "x_snd->sr") -(INNER-LOOP-LOCALS "double z0; long xi; long xj;") - -(INNER-LOOP " - z0 = x_snd*gain; - for (xi=0; xi < ak_len ; xi++) - { - xj = index + xi; if (xj >= ak_len) xj -= ak_len; - z0 += ak_coefs[xi] * zk_buf[xj]; - } - zk_buf[index] = z0; - index++; if (index == ak_len) index = 0; - output = (sample_type) z0; -") +(SAMPLE-RATE (MAX x_snd)) +(INNER-LOOP-LOCALS " double z0; long xi; long xj;") +(INNER-LOOP "z0 = x_snd*gain; + for (xi=0; xi < ak_len ; xi++) { + xj = index + xi; if (xj >= ak_len) xj -= ak_len; + z0 += ak_coefs[xi] * zk_buf[xj]; + } + zk_buf[index] = z0; + index++; if (index == ak_len) index = 0; + output = (sample_type) z0") (FINALIZATION " free(susp->zk_buf); free(susp->ak_coefs); - susp->ak_array = NULL; /* free array */ -") + susp->ak_array = NULL; /* free array */\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/allpoles.c b/lib-src/libnyquist/nyquist/tran/allpoles.c index 39e47a500..a17fae549 100644 --- a/lib-src/libnyquist/nyquist/tran/allpoles.c +++ b/lib-src/libnyquist/nyquist/tran/allpoles.c @@ -9,7 +9,7 @@ #include "cext.h" #include "allpoles.h" -void allpoles_free(); +void allpoles_free(snd_susp_type a_susp); typedef struct allpoles_susp_struct { @@ -29,8 +29,9 @@ typedef struct allpoles_susp_struct { } allpoles_susp_node, *allpoles_susp_type; -void allpoles_s_fetch(register allpoles_susp_type susp, snd_list_type snd_list) +void allpoles_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + allpoles_susp_type susp = (allpoles_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -63,6 +64,7 @@ void allpoles_s_fetch(register allpoles_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -74,6 +76,7 @@ void allpoles_s_fetch(register allpoles_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -126,17 +129,14 @@ void allpoles_s_fetch(register allpoles_susp_type susp, snd_list_type snd_list) x_snd_ptr_reg = susp->x_snd_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double z0; long xi; long xj; - z0 = (x_snd_scale_reg * *x_snd_ptr_reg++)*gain_reg; - for (xi=0; xi < ak_len_reg ; xi++) - { - xj = index_reg + xi; if (xj >= ak_len_reg) xj -= ak_len_reg; - z0 += ak_coefs_reg[xi] * zk_buf_reg[xj]; - } - zk_buf_reg[index_reg] = z0; - index_reg++; if (index_reg == ak_len_reg) index_reg = 0; - *out_ptr_reg++ = (sample_type) z0; -; + double z0; long xi; long xj; z0 = (x_snd_scale_reg * *x_snd_ptr_reg++)*gain_reg; + for (xi=0; xi < ak_len_reg ; xi++) { + xj = index_reg + xi; if (xj >= ak_len_reg) xj -= ak_len_reg; + z0 += ak_coefs_reg[xi] * zk_buf_reg[xj]; + } + zk_buf_reg[index_reg] = z0; + index_reg++; if (index_reg == ak_len_reg) index_reg = 0; + *out_ptr_reg++ = (sample_type) z0; } while (--n); /* inner loop */ susp->zk_buf = zk_buf_reg; @@ -164,11 +164,9 @@ double z0; long xi; long xj; } /* allpoles_s_fetch */ -void allpoles_toss_fetch(susp, snd_list) - register allpoles_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void allpoles_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + allpoles_susp_type susp = (allpoles_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -183,19 +181,21 @@ void allpoles_toss_fetch(susp, snd_list) susp->x_snd_ptr += n; susp_took(x_snd_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void allpoles_mark(allpoles_susp_type susp) +void allpoles_mark(snd_susp_type a_susp) { + allpoles_susp_type susp = (allpoles_susp_type) a_susp; if (susp->ak_array) mark(susp->ak_array); sound_xlmark(susp->x_snd); } -void allpoles_free(allpoles_susp_type susp) +void allpoles_free(snd_susp_type a_susp) { + allpoles_susp_type susp = (allpoles_susp_type) a_susp; free(susp->zk_buf); free(susp->ak_coefs); @@ -205,8 +205,9 @@ void allpoles_free(allpoles_susp_type susp) } -void allpoles_print_tree(allpoles_susp_type susp, int n) +void allpoles_print_tree(snd_susp_type a_susp, int n) { + allpoles_susp_type susp = (allpoles_susp_type) a_susp; indent(n); stdputstr("x_snd:"); sound_print_tree_1(susp->x_snd, n); @@ -218,7 +219,6 @@ sound_type snd_make_allpoles(sound_type x_snd, LVAL ak_array, double gain) register allpoles_susp_type susp; rate_type sr = x_snd->sr; time_type t0 = x_snd->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, allpoles_susp_node, "snd_make_allpoles"); @@ -237,8 +237,8 @@ sound_type snd_make_allpoles(sound_type x_snd, LVAL ak_array, double gain) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = allpoles_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = allpoles_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/alpass.alg b/lib-src/libnyquist/nyquist/tran/alpass.alg index 99d8eb9a0..3ee3b7fa5 100644 --- a/lib-src/libnyquist/nyquist/tran/alpass.alg +++ b/lib-src/libnyquist/nyquist/tran/alpass.alg @@ -12,11 +12,11 @@ (NOT-REGISTER delaybuf) (LINEAR input) (TERMINATE (MIN input)) -(INNER-LOOP-LOCALS "register sample_type y, z;\n") -(INNER-LOOP " y = *delayptr; - *delayptr++ = z = (sample_type) (feedback * y + input); - output = (sample_type) (y - feedback * z); - if (delayptr >= endptr) delayptr = susp->delaybuf;") +(INNER-LOOP-LOCALS " register sample_type y, z;\n") +(INNER-LOOP "y = *delayptr; + *delayptr++ = z = (sample_type) (feedback * y + input); + output = (sample_type) (y - feedback * z); + if (delayptr >= endptr) delayptr = susp->delaybuf") (FINALIZATION "free(susp->delaybuf);") ) diff --git a/lib-src/libnyquist/nyquist/tran/alpass.c b/lib-src/libnyquist/nyquist/tran/alpass.c index cad43ef7e..7ab00c7e0 100644 --- a/lib-src/libnyquist/nyquist/tran/alpass.c +++ b/lib-src/libnyquist/nyquist/tran/alpass.c @@ -9,7 +9,7 @@ #include "cext.h" #include "alpass.h" -void alpass_free(); +void alpass_free(snd_susp_type a_susp); typedef struct alpass_susp_struct { @@ -27,8 +27,9 @@ typedef struct alpass_susp_struct { } alpass_susp_node, *alpass_susp_type; -void alpass_n_fetch(register alpass_susp_type susp, snd_list_type snd_list) +void alpass_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpass_susp_type susp = (alpass_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -58,6 +59,7 @@ void alpass_n_fetch(register alpass_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -68,11 +70,11 @@ void alpass_n_fetch(register alpass_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -register sample_type y, z; - y = *delayptr_reg; - *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); - *out_ptr_reg++ = (sample_type) (y - feedback_reg * z); - if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + register sample_type y, z; + y = *delayptr_reg; + *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); + *out_ptr_reg++ = (sample_type) (y - feedback_reg * z); + if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -93,11 +95,9 @@ register sample_type y, z; } /* alpass_n_fetch */ -void alpass_toss_fetch(susp, snd_list) - register alpass_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void alpass_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + alpass_susp_type susp = (alpass_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -112,25 +112,28 @@ void alpass_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void alpass_mark(alpass_susp_type susp) +void alpass_mark(snd_susp_type a_susp) { + alpass_susp_type susp = (alpass_susp_type) a_susp; sound_xlmark(susp->input); } -void alpass_free(alpass_susp_type susp) +void alpass_free(snd_susp_type a_susp) { + alpass_susp_type susp = (alpass_susp_type) a_susp; free(susp->delaybuf); sound_unref(susp->input); ffree_generic(susp, sizeof(alpass_susp_node), "alpass_free"); } -void alpass_print_tree(alpass_susp_type susp, int n) +void alpass_print_tree(snd_susp_type a_susp, int n) { + alpass_susp_type susp = (alpass_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -142,7 +145,6 @@ sound_type snd_make_alpass(sound_type input, time_type delay, double feedback) register alpass_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; /* combine scale factors of linear inputs (INPUT) */ @@ -167,8 +169,8 @@ sound_type snd_make_alpass(sound_type input, time_type delay, double feedback) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = alpass_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = alpass_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/alpasscv.alg b/lib-src/libnyquist/nyquist/tran/alpasscv.alg index ba1602a99..62960479c 100644 --- a/lib-src/libnyquist/nyquist/tran/alpasscv.alg +++ b/lib-src/libnyquist/nyquist/tran/alpasscv.alg @@ -1,6 +1,7 @@ (ALPASSCV-ALG (NAME "alpasscv") (ARGUMENTS ("sound_type" "input") ("time_type" "delay") ("sound_type" "feedback")) +(SAMPLE-RATE (MAX input)) (START (MAX input feedback)) (STATE ("long" "delaylen" "max(1, round(input->sr * delay))") ("sample_type *" "delaybuf" @@ -11,11 +12,12 @@ (NOT-REGISTER delaybuf) (LINEAR input) (TERMINATE (MIN input)) -(INNER-LOOP-LOCALS "register sample_type y, z, fb;\n") -(INNER-LOOP " y = *delayptr; - *delayptr++ = z = (sample_type) ((fb = feedback) * y + input); - output = (sample_type) (y - fb * z); - if (delayptr >= endptr) delayptr = susp->delaybuf;") +(INNER-LOOP-LOCALS " register sample_type y, z, fb;\n") +(INNER-LOOP "y = *delayptr; + *delayptr++ = z = (sample_type) + ((fb = feedback) * y + input); + output = (sample_type) (y - fb * z); + if (delayptr >= endptr) delayptr = susp->delaybuf") (FINALIZATION "free(susp->delaybuf);") ) diff --git a/lib-src/libnyquist/nyquist/tran/alpasscv.c b/lib-src/libnyquist/nyquist/tran/alpasscv.c index 99c48552f..a68814877 100644 --- a/lib-src/libnyquist/nyquist/tran/alpasscv.c +++ b/lib-src/libnyquist/nyquist/tran/alpasscv.c @@ -9,11 +9,12 @@ #include "cext.h" #include "alpasscv.h" -void alpasscv_free(); +void alpasscv_free(snd_susp_type a_susp); typedef struct alpasscv_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; sound_type input; long input_cnt; @@ -22,6 +23,15 @@ typedef struct alpasscv_susp_struct { long feedback_cnt; sample_block_values_type feedback_ptr; + /* support for interpolation of feedback */ + sample_type feedback_x1_sample; + double feedback_pHaSe; + double feedback_pHaSe_iNcR; + + /* support for ramp between samples of feedback */ + double output_per_feedback; + long feedback_n; + long delaylen; sample_type *delaybuf; sample_type *delayptr; @@ -29,8 +39,9 @@ typedef struct alpasscv_susp_struct { } alpasscv_susp_node, *alpasscv_susp_type; -void alpasscv_nn_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) +void alpasscv_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -64,6 +75,7 @@ void alpasscv_nn_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -74,11 +86,12 @@ void alpasscv_nn_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -register sample_type y, z, fb; - y = *delayptr_reg; - *delayptr_reg++ = z = (sample_type) ((fb = *feedback_ptr_reg++) * y + *input_ptr_reg++); - *out_ptr_reg++ = (sample_type) (y - fb * z); - if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + register sample_type y, z, fb; + y = *delayptr_reg; + *delayptr_reg++ = z = (sample_type) + ((fb = *feedback_ptr_reg++) * y + *input_ptr_reg++); + *out_ptr_reg++ = (sample_type) (y - fb * z); + if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -102,8 +115,9 @@ register sample_type y, z, fb; } /* alpasscv_nn_fetch */ -void alpasscv_ns_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) +void alpasscv_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -138,6 +152,7 @@ void alpasscv_ns_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -148,11 +163,12 @@ void alpasscv_ns_fetch(register alpasscv_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -register sample_type y, z, fb; - y = *delayptr_reg; - *delayptr_reg++ = z = (sample_type) ((fb = (feedback_scale_reg * *feedback_ptr_reg++)) * y + *input_ptr_reg++); - *out_ptr_reg++ = (sample_type) (y - fb * z); - if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + register sample_type y, z, fb; + y = *delayptr_reg; + *delayptr_reg++ = z = (sample_type) + ((fb = (feedback_scale_reg * *feedback_ptr_reg++)) * y + *input_ptr_reg++); + *out_ptr_reg++ = (sample_type) (y - fb * z); + if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -176,11 +192,205 @@ register sample_type y, z, fb; } /* alpasscv_ns_fetch */ -void alpasscv_toss_fetch(susp, snd_list) - register alpasscv_susp_type susp; - snd_list_type snd_list; +void alpasscv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register double feedback_pHaSe_iNcR_rEg = susp->feedback_pHaSe_iNcR; + register double feedback_pHaSe_ReG; + register sample_type feedback_x1_sample_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpasscv_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + susp->feedback_x1_sample = susp_fetch_sample(feedback, feedback_ptr, feedback_cnt); + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_pHaSe_ReG = susp->feedback_pHaSe; + feedback_x1_sample_reg = susp->feedback_x1_sample; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, fb; + if (feedback_pHaSe_ReG >= 1.0) { + feedback_x1_sample_reg = feedback_x2_sample; + /* pick up next sample as feedback_x2_sample: */ + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + feedback_pHaSe_ReG -= 1.0; + susp_check_samples_break(feedback, feedback_ptr, feedback_cnt, feedback_x2_sample); + } + y = *delayptr_reg; + *delayptr_reg++ = z = (sample_type) + ((fb = + (feedback_x1_sample_reg * (1 - feedback_pHaSe_ReG) + feedback_x2_sample * feedback_pHaSe_ReG)) * y + *input_ptr_reg++); + *out_ptr_reg++ = (sample_type) (y - fb * z); + if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + feedback_pHaSe_ReG += feedback_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->delayptr = delayptr_reg; + susp->feedback_pHaSe = feedback_pHaSe_ReG; + susp->feedback_x1_sample = feedback_x1_sample_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpasscv_ni_fetch */ + + +void alpasscv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type feedback_DeLtA; + sample_type feedback_val; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpasscv_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->feedback_pHaSe = 1.0; + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next feedback_x2_sample when phase goes past 1.0; */ + /* we use feedback_n (computed below) to avoid roundoff errors: */ + if (susp->feedback_n <= 0) { + susp->feedback_x1_sample = feedback_x2_sample; + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + susp->feedback_pHaSe -= 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + /* feedback_n gets number of samples before phase exceeds 1.0: */ + susp->feedback_n = (long) ((1.0 - susp->feedback_pHaSe) * + susp->output_per_feedback); + } + togo = min(togo, susp->feedback_n); + feedback_DeLtA = (sample_type) ((feedback_x2_sample - susp->feedback_x1_sample) * susp->feedback_pHaSe_iNcR); + feedback_val = (sample_type) (susp->feedback_x1_sample * (1.0 - susp->feedback_pHaSe) + + feedback_x2_sample * susp->feedback_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, fb; + y = *delayptr_reg; + *delayptr_reg++ = z = (sample_type) + ((fb = feedback_val) * y + *input_ptr_reg++); + *out_ptr_reg++ = (sample_type) (y - fb * z); + if (delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + feedback_val += feedback_DeLtA; + } while (--n); /* inner loop */ + + susp->delayptr = delayptr_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->feedback_pHaSe += togo * susp->feedback_pHaSe_iNcR; + susp->feedback_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpasscv_nr_fetch */ + + +void alpasscv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -203,27 +413,30 @@ void alpasscv_toss_fetch(susp, snd_list) susp->feedback_ptr += n; susp_took(feedback_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void alpasscv_mark(alpasscv_susp_type susp) +void alpasscv_mark(snd_susp_type a_susp) { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; sound_xlmark(susp->input); sound_xlmark(susp->feedback); } -void alpasscv_free(alpasscv_susp_type susp) +void alpasscv_free(snd_susp_type a_susp) { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; free(susp->delaybuf); sound_unref(susp->input); sound_unref(susp->feedback); ffree_generic(susp, sizeof(alpasscv_susp_node), "alpasscv_free"); } -void alpasscv_print_tree(alpasscv_susp_type susp, int n) +void alpasscv_print_tree(snd_susp_type a_susp, int n) { + alpasscv_susp_type susp = (alpasscv_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -237,7 +450,7 @@ void alpasscv_print_tree(alpasscv_susp_type susp, int n) sound_type snd_make_alpasscv(sound_type input, time_type delay, sound_type feedback) { register alpasscv_susp_type susp; - rate_type sr = max(input->sr, feedback->sr); + rate_type sr = input->sr; time_type t0 = max(input->t0, feedback->t0); int interp_desc = 0; sample_type scale_factor = 1.0F; @@ -255,12 +468,20 @@ sound_type snd_make_alpasscv(sound_type input, time_type delay, sound_type feedb susp->delayptr = susp->delaybuf; susp->endptr = susp->delaybuf + susp->delaylen; + /* make sure no sample rate is too high */ + if (feedback->sr > sr) { + sound_unref(feedback); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); interp_desc = (interp_desc << 2) + interp_style(feedback, sr); switch (interp_desc) { case INTERP_nn: susp->susp.fetch = alpasscv_nn_fetch; break; case INTERP_ns: susp->susp.fetch = alpasscv_ns_fetch; break; + case INTERP_ni: susp->susp.fetch = alpasscv_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = alpasscv_nr_fetch; break; default: snd_badsr(); break; } @@ -273,8 +494,8 @@ sound_type snd_make_alpasscv(sound_type input, time_type delay, sound_type feedb /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = alpasscv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = alpasscv_toss_fetch; } /* initialize susp state */ @@ -285,11 +506,16 @@ sound_type snd_make_alpasscv(sound_type input, time_type delay, sound_type feedb susp->susp.print_tree = alpasscv_print_tree; susp->susp.name = "alpasscv"; susp->susp.log_stop_cnt = UNKNOWN; + susp->started = false; susp->susp.current = 0; susp->input = input; susp->input_cnt = 0; susp->feedback = feedback; susp->feedback_cnt = 0; + susp->feedback_pHaSe = 0.0; + susp->feedback_pHaSe_iNcR = feedback->sr / sr; + susp->feedback_n = 0; + susp->output_per_feedback = sr / feedback->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/alpassvc.alg b/lib-src/libnyquist/nyquist/tran/alpassvc.alg index c3c13db77..358da10be 100644 --- a/lib-src/libnyquist/nyquist/tran/alpassvc.alg +++ b/lib-src/libnyquist/nyquist/tran/alpassvc.alg @@ -9,6 +9,7 @@ (NAME "alpassvc") (ARGUMENTS ("sound_type" "input") ("sound_type" "delaysnd") ("double" "feedback") ("double" "maxdelay")) +(SAMPLE-RATE (MAX input)) (START (MAX input delaysnd)) (STATE ("float" "delay_scale_factor" "(float) (input->sr * delaysnd->scale)") ("double" "feedback" "feedback") @@ -21,39 +22,40 @@ (CONSTANT "feedback" "delaylen" "endptr" "delay_scale_factor") (NOT-REGISTER delaybuf) (LINEAR input) +(INTERNAL-SCALING delaysnd) (TERMINATE (MIN input)) -(INNER-LOOP-LOCALS " register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr;\n") -(INNER-LOOP " - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - delaysamp = delaysnd * delay_scale_factor; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr + buflen - (delayi + 1); - if (yptr >= endptr) yptr -= buflen; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ +(INNER-LOOP-LOCALS " register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr;\n") +(INNER-LOOP "/* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + delaysamp = delaysnd * delay_scale_factor; + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr + buflen - (delayi + 1); + if (yptr >= endptr) yptr -= buflen; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ - *delayptr++ = z = (sample_type) (feedback * y + input); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr > endptr) { - delayptr = susp->delaybuf; - *delayptr++ = *endptr; - } - output = (sample_type) (y - feedback * z);") -(FINALIZATION "free(susp->delaybuf);") + *delayptr++ = z = (sample_type) (feedback * y + input); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr > endptr) { + delayptr = susp->delaybuf; + *delayptr++ = *endptr; + } + output = (sample_type) (y - feedback * z)") +(FINALIZATION "free(susp->delaybuf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/alpassvc.c b/lib-src/libnyquist/nyquist/tran/alpassvc.c index e5bdf4bd2..62dca79a8 100644 --- a/lib-src/libnyquist/nyquist/tran/alpassvc.c +++ b/lib-src/libnyquist/nyquist/tran/alpassvc.c @@ -9,11 +9,12 @@ #include "cext.h" #include "alpassvc.h" -void alpassvc_free(); +void alpassvc_free(snd_susp_type a_susp); typedef struct alpassvc_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; sound_type input; long input_cnt; @@ -22,6 +23,15 @@ typedef struct alpassvc_susp_struct { long delaysnd_cnt; sample_block_values_type delaysnd_ptr; + /* support for interpolation of delaysnd */ + sample_type delaysnd_x1_sample; + double delaysnd_pHaSe; + double delaysnd_pHaSe_iNcR; + + /* support for ramp between samples of delaysnd */ + double output_per_delaysnd; + long delaysnd_n; + float delay_scale_factor; double feedback; long buflen; @@ -31,8 +41,9 @@ typedef struct alpassvc_susp_struct { } alpassvc_susp_node, *alpassvc_susp_type; -void alpassvc_nn_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) +void alpassvc_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -69,6 +80,7 @@ void alpassvc_nn_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -82,38 +94,38 @@ void alpassvc_nn_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + delaysamp = *delaysnd_ptr_reg++ * delay_scale_factor_reg; + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - delaysamp = *delaysnd_ptr_reg++ * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - feedback_reg * z);; + *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - feedback_reg * z); } while (--n); /* inner loop */ susp->buflen = buflen_reg; @@ -138,9 +150,11 @@ void alpassvc_nn_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) } /* alpassvc_nn_fetch */ -void alpassvc_ns_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) +void alpassvc_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ + sample_type delaysnd_x2_sample; int togo; int n; sample_block_type out; @@ -153,13 +167,24 @@ void alpassvc_ns_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) register long buflen_reg; register sample_type * delayptr_reg; register sample_type * endptr_reg; - register sample_type delaysnd_scale_reg = susp->delaysnd->scale; - register sample_block_values_type delaysnd_ptr_reg; + register double delaysnd_pHaSe_iNcR_rEg = susp->delaysnd_pHaSe_iNcR; + register double delaysnd_pHaSe_ReG; + register sample_type delaysnd_x1_sample_reg; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "alpassvc_ns_fetch"); + falloc_sample_block(out, "alpassvc_ni_fetch"); out_ptr = out->samples; snd_list->block = out; + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + susp->delaysnd_x1_sample = (susp->delaysnd_cnt--, *(susp->delaysnd_ptr)); + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + while (cnt < max_sample_block_len) { /* outer loop */ /* first compute how many samples to generate in inner loop: */ /* don't overflow the output sample block: */ @@ -169,14 +194,11 @@ void alpassvc_ns_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) susp_check_term_samples(input, input_ptr, input_cnt); togo = min(togo, susp->input_cnt); - /* don't run past the delaysnd input sample block: */ - susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); - togo = min(togo, susp->delaysnd_cnt); - /* don't run past terminate time */ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -186,53 +208,64 @@ void alpassvc_ns_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) buflen_reg = susp->buflen; delayptr_reg = susp->delayptr; endptr_reg = susp->endptr; - delaysnd_ptr_reg = susp->delaysnd_ptr; + delaysnd_pHaSe_ReG = susp->delaysnd_pHaSe; + delaysnd_x1_sample_reg = susp->delaysnd_x1_sample; input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (delaysnd_pHaSe_ReG >= 1.0) { + delaysnd_x1_sample_reg = delaysnd_x2_sample; + /* pick up next sample as delaysnd_x2_sample: */ + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + delaysnd_pHaSe_ReG -= 1.0; + susp_check_samples_break(delaysnd, delaysnd_ptr, delaysnd_cnt, delaysnd_x2_sample); + } + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + delaysamp = + (delaysnd_x1_sample_reg * (1 - delaysnd_pHaSe_ReG) + delaysnd_x2_sample * delaysnd_pHaSe_ReG) * delay_scale_factor_reg; + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - delaysamp = (delaysnd_scale_reg * *delaysnd_ptr_reg++) * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - feedback_reg * z);; + *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - feedback_reg * z); + delaysnd_pHaSe_ReG += delaysnd_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ + togo -= n; susp->buflen = buflen_reg; susp->delayptr = delayptr_reg; - /* using delaysnd_ptr_reg is a bad idea on RS/6000: */ - susp->delaysnd_ptr += togo; + susp->delaysnd_pHaSe = delaysnd_pHaSe_ReG; + susp->delaysnd_x1_sample = delaysnd_x1_sample_reg; /* using input_ptr_reg is a bad idea on RS/6000: */ susp->input_ptr += togo; out_ptr += togo; susp_took(input_cnt, togo); - susp_took(delaysnd_cnt, togo); cnt += togo; } /* outer loop */ @@ -243,14 +276,145 @@ void alpassvc_ns_fetch(register alpassvc_susp_type susp, snd_list_type snd_list) snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* alpassvc_ns_fetch */ +} /* alpassvc_ni_fetch */ -void alpassvc_toss_fetch(susp, snd_list) - register alpassvc_susp_type susp; - snd_list_type snd_list; +void alpassvc_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_DeLtA; + sample_type delaysnd_val; + sample_type delaysnd_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register double feedback_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvc_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->delaysnd_pHaSe = 1.0; + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next delaysnd_x2_sample when phase goes past 1.0; */ + /* we use delaysnd_n (computed below) to avoid roundoff errors: */ + if (susp->delaysnd_n <= 0) { + susp->delaysnd_x1_sample = delaysnd_x2_sample; + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + susp->delaysnd_pHaSe -= 1.0; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + /* delaysnd_n gets number of samples before phase exceeds 1.0: */ + susp->delaysnd_n = (long) ((1.0 - susp->delaysnd_pHaSe) * + susp->output_per_delaysnd); + } + togo = min(togo, susp->delaysnd_n); + delaysnd_DeLtA = (sample_type) ((delaysnd_x2_sample - susp->delaysnd_x1_sample) * susp->delaysnd_pHaSe_iNcR); + delaysnd_val = (sample_type) (susp->delaysnd_x1_sample * (1.0 - susp->delaysnd_pHaSe) + + delaysnd_x2_sample * susp->delaysnd_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + feedback_reg = susp->feedback; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + delaysamp = delaysnd_val * delay_scale_factor_reg; + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (feedback_reg * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - feedback_reg * z); + delaysnd_val += delaysnd_DeLtA; + } while (--n); /* inner loop */ + + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->delaysnd_pHaSe += togo * susp->delaysnd_pHaSe_iNcR; + susp->delaysnd_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvc_nr_fetch */ + + +void alpassvc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -273,27 +437,31 @@ void alpassvc_toss_fetch(susp, snd_list) susp->delaysnd_ptr += n; susp_took(delaysnd_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void alpassvc_mark(alpassvc_susp_type susp) +void alpassvc_mark(snd_susp_type a_susp) { + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; sound_xlmark(susp->input); sound_xlmark(susp->delaysnd); } -void alpassvc_free(alpassvc_susp_type susp) +void alpassvc_free(snd_susp_type a_susp) { -free(susp->delaybuf); sound_unref(susp->input); + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; +free(susp->delaybuf); + sound_unref(susp->input); sound_unref(susp->delaysnd); ffree_generic(susp, sizeof(alpassvc_susp_node), "alpassvc_free"); } -void alpassvc_print_tree(alpassvc_susp_type susp, int n) +void alpassvc_print_tree(snd_susp_type a_susp, int n) { + alpassvc_susp_type susp = (alpassvc_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -307,7 +475,7 @@ void alpassvc_print_tree(alpassvc_susp_type susp, int n) sound_type snd_make_alpassvc(sound_type input, sound_type delaysnd, double feedback, double maxdelay) { register alpassvc_susp_type susp; - rate_type sr = max(input->sr, delaysnd->sr); + rate_type sr = input->sr; time_type t0 = max(input->t0, delaysnd->t0); int interp_desc = 0; sample_type scale_factor = 1.0F; @@ -327,12 +495,20 @@ sound_type snd_make_alpassvc(sound_type input, sound_type delaysnd, double feedb susp->delayptr = susp->delaybuf; susp->endptr = susp->delaybuf + susp->buflen; + /* make sure no sample rate is too high */ + if (delaysnd->sr > sr) { + sound_unref(delaysnd); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); interp_desc = (interp_desc << 2) + interp_style(delaysnd, sr); switch (interp_desc) { + case INTERP_ns: /* handled below */ case INTERP_nn: susp->susp.fetch = alpassvc_nn_fetch; break; - case INTERP_ns: susp->susp.fetch = alpassvc_ns_fetch; break; + case INTERP_ni: susp->susp.fetch = alpassvc_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = alpassvc_nr_fetch; break; default: snd_badsr(); break; } @@ -345,8 +521,8 @@ sound_type snd_make_alpassvc(sound_type input, sound_type delaysnd, double feedb /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = alpassvc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = alpassvc_toss_fetch; } /* initialize susp state */ @@ -357,11 +533,16 @@ sound_type snd_make_alpassvc(sound_type input, sound_type delaysnd, double feedb susp->susp.print_tree = alpassvc_print_tree; susp->susp.name = "alpassvc"; susp->susp.log_stop_cnt = UNKNOWN; + susp->started = false; susp->susp.current = 0; susp->input = input; susp->input_cnt = 0; susp->delaysnd = delaysnd; susp->delaysnd_cnt = 0; + susp->delaysnd_pHaSe = 0.0; + susp->delaysnd_pHaSe_iNcR = delaysnd->sr / sr; + susp->delaysnd_n = 0; + susp->output_per_delaysnd = sr / delaysnd->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/alpassvv.alg b/lib-src/libnyquist/nyquist/tran/alpassvv.alg index cb4416cb7..56b4a6aa8 100644 --- a/lib-src/libnyquist/nyquist/tran/alpassvv.alg +++ b/lib-src/libnyquist/nyquist/tran/alpassvv.alg @@ -7,8 +7,8 @@ ;; locations in the buffer. ;; (NAME "alpassvv") -(ARGUMENTS ("sound_type" "input") ("sound_type" "delaysnd") ("sound_type" "feedback") - ("double" "maxdelay")) +(ARGUMENTS ("sound_type" "input") ("sound_type" "delaysnd") + ("sound_type" "feedback") ("double" "maxdelay")) (START (MAX input delaysnd)) (STATE ("float" "delay_scale_factor" "(float) (input->sr * delaysnd->scale)") ("long" "buflen" "max(2, (long) (input->sr * maxdelay + 2.5))") @@ -19,41 +19,45 @@ ("sample_type *" "endptr" "susp->delaybuf + susp->buflen")) (CONSTANT "delaylen" "endptr" "delay_scale_factor") (NOT-REGISTER delaybuf) +(SAMPLE-RATE (MAX input)) (LINEAR input) +(INTERNAL-SCALING delaysnd) ; incorporated into delay_scale_factor (TERMINATE (MIN input)) -(INNER-LOOP-LOCALS " register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr;\n") -(INNER-LOOP " - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - register sample_type fb = feedback; - delaysamp = delaysnd * delay_scale_factor; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr + buflen - (delayi + 1); - if (yptr >= endptr) yptr -= buflen; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr++ = z = (sample_type) (fb * y + input); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr > endptr) { - delayptr = susp->delaybuf; - *delayptr++ = *endptr; - } - output = (sample_type) (y - fb * z);") +(INNER-LOOP-LOCALS " register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr;\n") +(INNER-LOOP "{ + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) feedback; + delaysamp = (sample_type) (delaysnd * delay_scale_factor); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr + buflen - (delayi + 1); + if (yptr >= endptr) yptr -= buflen; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr++ = z = (sample_type) (fb * y + input); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr > endptr) { + delayptr = susp->delaybuf; + *delayptr++ = *endptr; + } + output = (sample_type) (y - fb * z); + }") (FINALIZATION "free(susp->delaybuf);") ) diff --git a/lib-src/libnyquist/nyquist/tran/alpassvv.c b/lib-src/libnyquist/nyquist/tran/alpassvv.c index 308e6de21..00681998b 100644 --- a/lib-src/libnyquist/nyquist/tran/alpassvv.c +++ b/lib-src/libnyquist/nyquist/tran/alpassvv.c @@ -9,11 +9,12 @@ #include "cext.h" #include "alpassvv.h" -void alpassvv_free(); +void alpassvv_free(snd_susp_type a_susp); typedef struct alpassvv_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; sound_type input; long input_cnt; @@ -21,10 +22,28 @@ typedef struct alpassvv_susp_struct { sound_type delaysnd; long delaysnd_cnt; sample_block_values_type delaysnd_ptr; + + /* support for interpolation of delaysnd */ + sample_type delaysnd_x1_sample; + double delaysnd_pHaSe; + double delaysnd_pHaSe_iNcR; + + /* support for ramp between samples of delaysnd */ + double output_per_delaysnd; + long delaysnd_n; sound_type feedback; long feedback_cnt; sample_block_values_type feedback_ptr; + /* support for interpolation of feedback */ + sample_type feedback_x1_sample; + double feedback_pHaSe; + double feedback_pHaSe_iNcR; + + /* support for ramp between samples of feedback */ + double output_per_feedback; + long feedback_n; + float delay_scale_factor; long buflen; sample_type *delaybuf; @@ -33,8 +52,9 @@ typedef struct alpassvv_susp_struct { } alpassvv_susp_node, *alpassvv_susp_type; -void alpassvv_nnn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list) +void alpassvv_nnn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -75,6 +95,7 @@ void alpassvv_nnn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -88,39 +109,41 @@ void alpassvv_nnn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; - - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - register sample_type fb = *feedback_ptr_reg++; - delaysamp = *delaysnd_ptr_reg++ * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - fb * z);; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) *feedback_ptr_reg++; + delaysamp = (sample_type) (*delaysnd_ptr_reg++ * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; } while (--n); /* inner loop */ susp->buflen = buflen_reg; @@ -148,8 +171,9 @@ void alpassvv_nnn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list } /* alpassvv_nnn_fetch */ -void alpassvv_nns_fetch(register alpassvv_susp_type susp, snd_list_type snd_list) +void alpassvv_nns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -191,6 +215,7 @@ void alpassvv_nns_fetch(register alpassvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -204,39 +229,41 @@ void alpassvv_nns_fetch(register alpassvv_susp_type susp, snd_list_type snd_list input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; - - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - register sample_type fb = (feedback_scale_reg * *feedback_ptr_reg++); - delaysamp = *delaysnd_ptr_reg++ * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - fb * z);; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) (feedback_scale_reg * *feedback_ptr_reg++); + delaysamp = (sample_type) (*delaysnd_ptr_reg++ * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; } while (--n); /* inner loop */ susp->buflen = buflen_reg; @@ -264,9 +291,11 @@ void alpassvv_nns_fetch(register alpassvv_susp_type susp, snd_list_type snd_list } /* alpassvv_nns_fetch */ -void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list) +void alpassvv_nni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ + sample_type feedback_x2_sample; int togo; int n; sample_block_type out; @@ -278,14 +307,25 @@ void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list register long buflen_reg; register sample_type * delayptr_reg; register sample_type * endptr_reg; - register sample_block_values_type feedback_ptr_reg; - register sample_type delaysnd_scale_reg = susp->delaysnd->scale; + register double feedback_pHaSe_iNcR_rEg = susp->feedback_pHaSe_iNcR; + register double feedback_pHaSe_ReG; + register sample_type feedback_x1_sample_reg; register sample_block_values_type delaysnd_ptr_reg; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "alpassvv_nsn_fetch"); + falloc_sample_block(out, "alpassvv_nni_fetch"); out_ptr = out->samples; snd_list->block = out; + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + susp->feedback_x1_sample = susp_fetch_sample(feedback, feedback_ptr, feedback_cnt); + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + while (cnt < max_sample_block_len) { /* outer loop */ /* first compute how many samples to generate in inner loop: */ /* don't overflow the output sample block: */ @@ -299,6 +339,284 @@ void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); togo = min(togo, susp->delaysnd_cnt); + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_pHaSe_ReG = susp->feedback_pHaSe; + feedback_x1_sample_reg = susp->feedback_x1_sample; + delaysnd_ptr_reg = susp->delaysnd_ptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (feedback_pHaSe_ReG >= 1.0) { + feedback_x1_sample_reg = feedback_x2_sample; + /* pick up next sample as feedback_x2_sample: */ + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + feedback_pHaSe_ReG -= 1.0; + susp_check_samples_break(feedback, feedback_ptr, feedback_cnt, feedback_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) + (feedback_x1_sample_reg * (1 - feedback_pHaSe_ReG) + feedback_x2_sample * feedback_pHaSe_ReG); + delaysamp = (sample_type) (*delaysnd_ptr_reg++ * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + feedback_pHaSe_ReG += feedback_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + susp->feedback_pHaSe = feedback_pHaSe_ReG; + susp->feedback_x1_sample = feedback_x1_sample_reg; + /* using delaysnd_ptr_reg is a bad idea on RS/6000: */ + susp->delaysnd_ptr += togo; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp_took(delaysnd_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nni_fetch */ + + +void alpassvv_nnr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type feedback_DeLtA; + sample_type feedback_val; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type delaysnd_ptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nnr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->feedback_pHaSe = 1.0; + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* don't run past the delaysnd input sample block: */ + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + togo = min(togo, susp->delaysnd_cnt); + + /* grab next feedback_x2_sample when phase goes past 1.0; */ + /* we use feedback_n (computed below) to avoid roundoff errors: */ + if (susp->feedback_n <= 0) { + susp->feedback_x1_sample = feedback_x2_sample; + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + susp->feedback_pHaSe -= 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + /* feedback_n gets number of samples before phase exceeds 1.0: */ + susp->feedback_n = (long) ((1.0 - susp->feedback_pHaSe) * + susp->output_per_feedback); + } + togo = min(togo, susp->feedback_n); + feedback_DeLtA = (sample_type) ((feedback_x2_sample - susp->feedback_x1_sample) * susp->feedback_pHaSe_iNcR); + feedback_val = (sample_type) (susp->feedback_x1_sample * (1.0 - susp->feedback_pHaSe) + + feedback_x2_sample * susp->feedback_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + delaysnd_ptr_reg = susp->delaysnd_ptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) feedback_val; + delaysamp = (sample_type) (*delaysnd_ptr_reg++ * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + feedback_val += feedback_DeLtA; + } while (--n); /* inner loop */ + + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + /* using delaysnd_ptr_reg is a bad idea on RS/6000: */ + susp->delaysnd_ptr += togo; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp_took(delaysnd_cnt, togo); + susp->feedback_pHaSe += togo * susp->feedback_pHaSe_iNcR; + susp->feedback_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nnr_fetch */ + + +void alpassvv_nin_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type feedback_ptr_reg; + register double delaysnd_pHaSe_iNcR_rEg = susp->delaysnd_pHaSe_iNcR; + register double delaysnd_pHaSe_ReG; + register sample_type delaysnd_x1_sample_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nin_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + susp->delaysnd_x1_sample = (susp->delaysnd_cnt--, *(susp->delaysnd_ptr)); + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + /* don't run past the feedback input sample block: */ susp_check_samples(feedback, feedback_ptr, feedback_cnt); togo = min(togo, susp->feedback_cnt); @@ -307,6 +625,7 @@ void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -316,56 +635,69 @@ void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list delayptr_reg = susp->delayptr; endptr_reg = susp->endptr; feedback_ptr_reg = susp->feedback_ptr; - delaysnd_ptr_reg = susp->delaysnd_ptr; + delaysnd_pHaSe_ReG = susp->delaysnd_pHaSe; + delaysnd_x1_sample_reg = susp->delaysnd_x1_sample; input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; - - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - register sample_type fb = *feedback_ptr_reg++; - delaysamp = (delaysnd_scale_reg * *delaysnd_ptr_reg++) * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - fb * z);; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (delaysnd_pHaSe_ReG >= 1.0) { + delaysnd_x1_sample_reg = delaysnd_x2_sample; + /* pick up next sample as delaysnd_x2_sample: */ + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + delaysnd_pHaSe_ReG -= 1.0; + susp_check_samples_break(delaysnd, delaysnd_ptr, delaysnd_cnt, delaysnd_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) *feedback_ptr_reg++; + delaysamp = (sample_type) ( + (delaysnd_x1_sample_reg * (1 - delaysnd_pHaSe_ReG) + delaysnd_x2_sample * delaysnd_pHaSe_ReG) * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_pHaSe_ReG += delaysnd_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ + togo -= n; susp->buflen = buflen_reg; susp->delayptr = delayptr_reg; /* using feedback_ptr_reg is a bad idea on RS/6000: */ susp->feedback_ptr += togo; - /* using delaysnd_ptr_reg is a bad idea on RS/6000: */ - susp->delaysnd_ptr += togo; + susp->delaysnd_pHaSe = delaysnd_pHaSe_ReG; + susp->delaysnd_x1_sample = delaysnd_x1_sample_reg; /* using input_ptr_reg is a bad idea on RS/6000: */ susp->input_ptr += togo; out_ptr += togo; susp_took(input_cnt, togo); - susp_took(delaysnd_cnt, togo); susp_took(feedback_cnt, togo); cnt += togo; } /* outer loop */ @@ -377,12 +709,14 @@ void alpassvv_nsn_fetch(register alpassvv_susp_type susp, snd_list_type snd_list snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* alpassvv_nsn_fetch */ +} /* alpassvv_nin_fetch */ -void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list) +void alpassvv_nis_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ + sample_type delaysnd_x2_sample; int togo; int n; sample_block_type out; @@ -396,13 +730,24 @@ void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list register sample_type * endptr_reg; register sample_type feedback_scale_reg = susp->feedback->scale; register sample_block_values_type feedback_ptr_reg; - register sample_type delaysnd_scale_reg = susp->delaysnd->scale; - register sample_block_values_type delaysnd_ptr_reg; + register double delaysnd_pHaSe_iNcR_rEg = susp->delaysnd_pHaSe_iNcR; + register double delaysnd_pHaSe_ReG; + register sample_type delaysnd_x1_sample_reg; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "alpassvv_nss_fetch"); + falloc_sample_block(out, "alpassvv_nis_fetch"); out_ptr = out->samples; snd_list->block = out; + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + susp->delaysnd_x1_sample = (susp->delaysnd_cnt--, *(susp->delaysnd_ptr)); + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + while (cnt < max_sample_block_len) { /* outer loop */ /* first compute how many samples to generate in inner loop: */ /* don't overflow the output sample block: */ @@ -412,10 +757,6 @@ void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list susp_check_term_samples(input, input_ptr, input_cnt); togo = min(togo, susp->input_cnt); - /* don't run past the delaysnd input sample block: */ - susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); - togo = min(togo, susp->delaysnd_cnt); - /* don't run past the feedback input sample block: */ susp_check_samples(feedback, feedback_ptr, feedback_cnt); togo = min(togo, susp->feedback_cnt); @@ -424,6 +765,7 @@ void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -433,56 +775,69 @@ void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list delayptr_reg = susp->delayptr; endptr_reg = susp->endptr; feedback_ptr_reg = susp->feedback_ptr; - delaysnd_ptr_reg = susp->delaysnd_ptr; + delaysnd_pHaSe_ReG = susp->delaysnd_pHaSe; + delaysnd_x1_sample_reg = susp->delaysnd_x1_sample; input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register sample_type y, z, delaysamp; - register int delayi; - register sample_type *yptr; - - /* compute where to read y, we want y to be delay_snd samples - * after delay_ptr, where we write the new sample. First, - * conver from seconds to samples. Note: don't use actual sound_type - * names in comments! The translator isn't smart enough. - */ - register sample_type fb = (feedback_scale_reg * *feedback_ptr_reg++); - delaysamp = (delaysnd_scale_reg * *delaysnd_ptr_reg++) * delay_scale_factor_reg; - delayi = (int) delaysamp; /* get integer part */ - delaysamp = delaysamp - delayi; /* get phase */ - yptr = delayptr_reg + buflen_reg - (delayi + 1); - if (yptr >= endptr_reg) yptr -= buflen_reg; - /* now get y, the out-put of the delay, using interpolation */ - /* note that as phase increases, we use more of yptr[0] because - positive phase means longer buffer means read earlier sample */ - y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); - /* WARNING: no check to keep delaysamp in range, so do this in LISP */ - - *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - if (delayptr_reg > endptr_reg) { - delayptr_reg = susp->delaybuf; - *delayptr_reg++ = *endptr_reg; - } - *out_ptr_reg++ = (sample_type) (y - fb * z);; + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (delaysnd_pHaSe_ReG >= 1.0) { + delaysnd_x1_sample_reg = delaysnd_x2_sample; + /* pick up next sample as delaysnd_x2_sample: */ + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + delaysnd_pHaSe_ReG -= 1.0; + susp_check_samples_break(delaysnd, delaysnd_ptr, delaysnd_cnt, delaysnd_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) (feedback_scale_reg * *feedback_ptr_reg++); + delaysamp = (sample_type) ( + (delaysnd_x1_sample_reg * (1 - delaysnd_pHaSe_ReG) + delaysnd_x2_sample * delaysnd_pHaSe_ReG) * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_pHaSe_ReG += delaysnd_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ + togo -= n; susp->buflen = buflen_reg; susp->delayptr = delayptr_reg; /* using feedback_ptr_reg is a bad idea on RS/6000: */ susp->feedback_ptr += togo; - /* using delaysnd_ptr_reg is a bad idea on RS/6000: */ - susp->delaysnd_ptr += togo; + susp->delaysnd_pHaSe = delaysnd_pHaSe_ReG; + susp->delaysnd_x1_sample = delaysnd_x1_sample_reg; /* using input_ptr_reg is a bad idea on RS/6000: */ susp->input_ptr += togo; out_ptr += togo; susp_took(input_cnt, togo); - susp_took(delaysnd_cnt, togo); susp_took(feedback_cnt, togo); cnt += togo; } /* outer loop */ @@ -494,14 +849,930 @@ void alpassvv_nss_fetch(register alpassvv_susp_type susp, snd_list_type snd_list snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* alpassvv_nss_fetch */ +} /* alpassvv_nis_fetch */ -void alpassvv_toss_fetch(susp, snd_list) - register alpassvv_susp_type susp; - snd_list_type snd_list; +void alpassvv_nii_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_x2_sample; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register double feedback_pHaSe_iNcR_rEg = susp->feedback_pHaSe_iNcR; + register double feedback_pHaSe_ReG; + register sample_type feedback_x1_sample_reg; + register double delaysnd_pHaSe_iNcR_rEg = susp->delaysnd_pHaSe_iNcR; + register double delaysnd_pHaSe_ReG; + register sample_type delaysnd_x1_sample_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nii_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + susp->delaysnd_x1_sample = (susp->delaysnd_cnt--, *(susp->delaysnd_ptr)); + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + susp->feedback_x1_sample = susp_fetch_sample(feedback, feedback_ptr, feedback_cnt); + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_pHaSe_ReG = susp->feedback_pHaSe; + feedback_x1_sample_reg = susp->feedback_x1_sample; + delaysnd_pHaSe_ReG = susp->delaysnd_pHaSe; + delaysnd_x1_sample_reg = susp->delaysnd_x1_sample; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (delaysnd_pHaSe_ReG >= 1.0) { + delaysnd_x1_sample_reg = delaysnd_x2_sample; + /* pick up next sample as delaysnd_x2_sample: */ + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + delaysnd_pHaSe_ReG -= 1.0; + susp_check_samples_break(delaysnd, delaysnd_ptr, delaysnd_cnt, delaysnd_x2_sample); + } + if (feedback_pHaSe_ReG >= 1.0) { + feedback_x1_sample_reg = feedback_x2_sample; + /* pick up next sample as feedback_x2_sample: */ + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + feedback_pHaSe_ReG -= 1.0; + susp_check_samples_break(feedback, feedback_ptr, feedback_cnt, feedback_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) + (feedback_x1_sample_reg * (1 - feedback_pHaSe_ReG) + feedback_x2_sample * feedback_pHaSe_ReG); + delaysamp = (sample_type) ( + (delaysnd_x1_sample_reg * (1 - delaysnd_pHaSe_ReG) + delaysnd_x2_sample * delaysnd_pHaSe_ReG) * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_pHaSe_ReG += delaysnd_pHaSe_iNcR_rEg; + feedback_pHaSe_ReG += feedback_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + susp->feedback_pHaSe = feedback_pHaSe_ReG; + susp->feedback_x1_sample = feedback_x1_sample_reg; + susp->delaysnd_pHaSe = delaysnd_pHaSe_ReG; + susp->delaysnd_x1_sample = delaysnd_x1_sample_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nii_fetch */ + + +void alpassvv_nir_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_x2_sample; + sample_type feedback_DeLtA; + sample_type feedback_val; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register double delaysnd_pHaSe_iNcR_rEg = susp->delaysnd_pHaSe_iNcR; + register double delaysnd_pHaSe_ReG; + register sample_type delaysnd_x1_sample_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nir_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + susp->delaysnd_x1_sample = (susp->delaysnd_cnt--, *(susp->delaysnd_ptr)); + susp->feedback_pHaSe = 1.0; + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next feedback_x2_sample when phase goes past 1.0; */ + /* we use feedback_n (computed below) to avoid roundoff errors: */ + if (susp->feedback_n <= 0) { + susp->feedback_x1_sample = feedback_x2_sample; + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + susp->feedback_pHaSe -= 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + /* feedback_n gets number of samples before phase exceeds 1.0: */ + susp->feedback_n = (long) ((1.0 - susp->feedback_pHaSe) * + susp->output_per_feedback); + } + togo = min(togo, susp->feedback_n); + feedback_DeLtA = (sample_type) ((feedback_x2_sample - susp->feedback_x1_sample) * susp->feedback_pHaSe_iNcR); + feedback_val = (sample_type) (susp->feedback_x1_sample * (1.0 - susp->feedback_pHaSe) + + feedback_x2_sample * susp->feedback_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + delaysnd_pHaSe_ReG = susp->delaysnd_pHaSe; + delaysnd_x1_sample_reg = susp->delaysnd_x1_sample; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (delaysnd_pHaSe_ReG >= 1.0) { + delaysnd_x1_sample_reg = delaysnd_x2_sample; + /* pick up next sample as delaysnd_x2_sample: */ + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + delaysnd_pHaSe_ReG -= 1.0; + susp_check_samples_break(delaysnd, delaysnd_ptr, delaysnd_cnt, delaysnd_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) feedback_val; + delaysamp = (sample_type) ( + (delaysnd_x1_sample_reg * (1 - delaysnd_pHaSe_ReG) + delaysnd_x2_sample * delaysnd_pHaSe_ReG) * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_pHaSe_ReG += delaysnd_pHaSe_iNcR_rEg; + feedback_val += feedback_DeLtA; + } while (--n); /* inner loop */ + + togo -= n; + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + susp->delaysnd_pHaSe = delaysnd_pHaSe_ReG; + susp->delaysnd_x1_sample = delaysnd_x1_sample_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->feedback_pHaSe += togo * susp->feedback_pHaSe_iNcR; + susp->feedback_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nir_fetch */ + + +void alpassvv_nrn_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_DeLtA; + sample_type delaysnd_val; + sample_type delaysnd_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type feedback_ptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nrn_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->delaysnd_pHaSe = 1.0; + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next delaysnd_x2_sample when phase goes past 1.0; */ + /* we use delaysnd_n (computed below) to avoid roundoff errors: */ + if (susp->delaysnd_n <= 0) { + susp->delaysnd_x1_sample = delaysnd_x2_sample; + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + susp->delaysnd_pHaSe -= 1.0; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + /* delaysnd_n gets number of samples before phase exceeds 1.0: */ + susp->delaysnd_n = (long) ((1.0 - susp->delaysnd_pHaSe) * + susp->output_per_delaysnd); + } + togo = min(togo, susp->delaysnd_n); + delaysnd_DeLtA = (sample_type) ((delaysnd_x2_sample - susp->delaysnd_x1_sample) * susp->delaysnd_pHaSe_iNcR); + delaysnd_val = (sample_type) (susp->delaysnd_x1_sample * (1.0 - susp->delaysnd_pHaSe) + + delaysnd_x2_sample * susp->delaysnd_pHaSe); + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) *feedback_ptr_reg++; + delaysamp = (sample_type) (delaysnd_val * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_val += delaysnd_DeLtA; + } while (--n); /* inner loop */ + + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->delaysnd_pHaSe += togo * susp->delaysnd_pHaSe_iNcR; + susp->delaysnd_n -= togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nrn_fetch */ + + +void alpassvv_nrs_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_DeLtA; + sample_type delaysnd_val; + sample_type delaysnd_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_type feedback_scale_reg = susp->feedback->scale; + register sample_block_values_type feedback_ptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nrs_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->delaysnd_pHaSe = 1.0; + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next delaysnd_x2_sample when phase goes past 1.0; */ + /* we use delaysnd_n (computed below) to avoid roundoff errors: */ + if (susp->delaysnd_n <= 0) { + susp->delaysnd_x1_sample = delaysnd_x2_sample; + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + susp->delaysnd_pHaSe -= 1.0; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + /* delaysnd_n gets number of samples before phase exceeds 1.0: */ + susp->delaysnd_n = (long) ((1.0 - susp->delaysnd_pHaSe) * + susp->output_per_delaysnd); + } + togo = min(togo, susp->delaysnd_n); + delaysnd_DeLtA = (sample_type) ((delaysnd_x2_sample - susp->delaysnd_x1_sample) * susp->delaysnd_pHaSe_iNcR); + delaysnd_val = (sample_type) (susp->delaysnd_x1_sample * (1.0 - susp->delaysnd_pHaSe) + + delaysnd_x2_sample * susp->delaysnd_pHaSe); + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) (feedback_scale_reg * *feedback_ptr_reg++); + delaysamp = (sample_type) (delaysnd_val * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_val += delaysnd_DeLtA; + } while (--n); /* inner loop */ + + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->delaysnd_pHaSe += togo * susp->delaysnd_pHaSe_iNcR; + susp->delaysnd_n -= togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nrs_fetch */ + + +void alpassvv_nri_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_DeLtA; + sample_type delaysnd_val; + sample_type delaysnd_x2_sample; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register double feedback_pHaSe_iNcR_rEg = susp->feedback_pHaSe_iNcR; + register double feedback_pHaSe_ReG; + register sample_type feedback_x1_sample_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nri_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->delaysnd_pHaSe = 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + susp->feedback_x1_sample = susp_fetch_sample(feedback, feedback_ptr, feedback_cnt); + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next delaysnd_x2_sample when phase goes past 1.0; */ + /* we use delaysnd_n (computed below) to avoid roundoff errors: */ + if (susp->delaysnd_n <= 0) { + susp->delaysnd_x1_sample = delaysnd_x2_sample; + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + susp->delaysnd_pHaSe -= 1.0; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + /* delaysnd_n gets number of samples before phase exceeds 1.0: */ + susp->delaysnd_n = (long) ((1.0 - susp->delaysnd_pHaSe) * + susp->output_per_delaysnd); + } + togo = min(togo, susp->delaysnd_n); + delaysnd_DeLtA = (sample_type) ((delaysnd_x2_sample - susp->delaysnd_x1_sample) * susp->delaysnd_pHaSe_iNcR); + delaysnd_val = (sample_type) (susp->delaysnd_x1_sample * (1.0 - susp->delaysnd_pHaSe) + + delaysnd_x2_sample * susp->delaysnd_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_pHaSe_ReG = susp->feedback_pHaSe; + feedback_x1_sample_reg = susp->feedback_x1_sample; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + if (feedback_pHaSe_ReG >= 1.0) { + feedback_x1_sample_reg = feedback_x2_sample; + /* pick up next sample as feedback_x2_sample: */ + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + feedback_pHaSe_ReG -= 1.0; + susp_check_samples_break(feedback, feedback_ptr, feedback_cnt, feedback_x2_sample); + } + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) + (feedback_x1_sample_reg * (1 - feedback_pHaSe_ReG) + feedback_x2_sample * feedback_pHaSe_ReG); + delaysamp = (sample_type) (delaysnd_val * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_val += delaysnd_DeLtA; + feedback_pHaSe_ReG += feedback_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + susp->feedback_pHaSe = feedback_pHaSe_ReG; + susp->feedback_x1_sample = feedback_x1_sample_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->delaysnd_pHaSe += togo * susp->delaysnd_pHaSe_iNcR; + susp->delaysnd_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nri_fetch */ + + +void alpassvv_nrr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type delaysnd_DeLtA; + sample_type delaysnd_val; + sample_type delaysnd_x2_sample; + sample_type feedback_DeLtA; + sample_type feedback_val; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register float delay_scale_factor_reg; + register long buflen_reg; + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type input_ptr_reg; + falloc_sample_block(out, "alpassvv_nrr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->delaysnd_pHaSe = 1.0; + susp->feedback_pHaSe = 1.0; + } + + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the input input sample block: */ + susp_check_term_samples(input, input_ptr, input_cnt); + togo = min(togo, susp->input_cnt); + + /* grab next delaysnd_x2_sample when phase goes past 1.0; */ + /* we use delaysnd_n (computed below) to avoid roundoff errors: */ + if (susp->delaysnd_n <= 0) { + susp->delaysnd_x1_sample = delaysnd_x2_sample; + susp->delaysnd_ptr++; + susp_took(delaysnd_cnt, 1); + susp->delaysnd_pHaSe -= 1.0; + susp_check_samples(delaysnd, delaysnd_ptr, delaysnd_cnt); + delaysnd_x2_sample = *(susp->delaysnd_ptr); + /* delaysnd_n gets number of samples before phase exceeds 1.0: */ + susp->delaysnd_n = (long) ((1.0 - susp->delaysnd_pHaSe) * + susp->output_per_delaysnd); + } + togo = min(togo, susp->delaysnd_n); + delaysnd_DeLtA = (sample_type) ((delaysnd_x2_sample - susp->delaysnd_x1_sample) * susp->delaysnd_pHaSe_iNcR); + delaysnd_val = (sample_type) (susp->delaysnd_x1_sample * (1.0 - susp->delaysnd_pHaSe) + + delaysnd_x2_sample * susp->delaysnd_pHaSe); + + /* grab next feedback_x2_sample when phase goes past 1.0; */ + /* we use feedback_n (computed below) to avoid roundoff errors: */ + if (susp->feedback_n <= 0) { + susp->feedback_x1_sample = feedback_x2_sample; + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + susp->feedback_pHaSe -= 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + /* feedback_n gets number of samples before phase exceeds 1.0: */ + susp->feedback_n = (long) ((1.0 - susp->feedback_pHaSe) * + susp->output_per_feedback); + } + togo = min(togo, susp->feedback_n); + feedback_DeLtA = (sample_type) ((feedback_x2_sample - susp->feedback_x1_sample) * susp->feedback_pHaSe_iNcR); + feedback_val = (sample_type) (susp->feedback_x1_sample * (1.0 - susp->feedback_pHaSe) + + feedback_x2_sample * susp->feedback_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delay_scale_factor_reg = susp->delay_scale_factor; + buflen_reg = susp->buflen; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + input_ptr_reg = susp->input_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + register sample_type y, z, delaysamp; + register int delayi; + register sample_type *yptr; + { + /* compute where to read y, we want y to be delay_snd samples + * after delay_ptr, where we write the new sample. First, + * conver from seconds to samples. Note: don't use actual sound_type + * names in comments! The translator isn't smart enough. + */ + register sample_type fb = (sample_type) feedback_val; + delaysamp = (sample_type) (delaysnd_val * delay_scale_factor_reg); + delayi = (int) delaysamp; /* get integer part */ + delaysamp = delaysamp - delayi; /* get phase */ + yptr = delayptr_reg + buflen_reg - (delayi + 1); + if (yptr >= endptr_reg) yptr -= buflen_reg; + /* now get y, the out-put of the delay, using interpolation */ + /* note that as phase increases, we use more of yptr[0] because + positive phase means longer buffer means read earlier sample */ + y = (float) ((yptr[0] * delaysamp) + (yptr[1] * (1.0 - delaysamp))); + /* WARNING: no check to keep delaysamp in range, so + do this in LISP */ + + *delayptr_reg++ = z = (sample_type) (fb * y + *input_ptr_reg++); + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + if (delayptr_reg > endptr_reg) { + delayptr_reg = susp->delaybuf; + *delayptr_reg++ = *endptr_reg; + } + *out_ptr_reg++ = (sample_type) (y - fb * z); + }; + delaysnd_val += delaysnd_DeLtA; + feedback_val += feedback_DeLtA; + } while (--n); /* inner loop */ + + susp->buflen = buflen_reg; + susp->delayptr = delayptr_reg; + /* using input_ptr_reg is a bad idea on RS/6000: */ + susp->input_ptr += togo; + out_ptr += togo; + susp_took(input_cnt, togo); + susp->delaysnd_pHaSe += togo * susp->delaysnd_pHaSe_iNcR; + susp->delaysnd_n -= togo; + susp->feedback_pHaSe += togo * susp->feedback_pHaSe_iNcR; + susp->feedback_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* alpassvv_nrr_fetch */ + + +void alpassvv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -532,20 +1803,22 @@ void alpassvv_toss_fetch(susp, snd_list) susp->feedback_ptr += n; susp_took(feedback_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void alpassvv_mark(alpassvv_susp_type susp) +void alpassvv_mark(snd_susp_type a_susp) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; sound_xlmark(susp->input); sound_xlmark(susp->delaysnd); sound_xlmark(susp->feedback); } -void alpassvv_free(alpassvv_susp_type susp) +void alpassvv_free(snd_susp_type a_susp) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; free(susp->delaybuf); sound_unref(susp->input); sound_unref(susp->delaysnd); sound_unref(susp->feedback); @@ -553,8 +1826,9 @@ free(susp->delaybuf); sound_unref(susp->input); } -void alpassvv_print_tree(alpassvv_susp_type susp, int n) +void alpassvv_print_tree(snd_susp_type a_susp, int n) { + alpassvv_susp_type susp = (alpassvv_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -572,7 +1846,7 @@ void alpassvv_print_tree(alpassvv_susp_type susp, int n) sound_type snd_make_alpassvv(sound_type input, sound_type delaysnd, sound_type feedback, double maxdelay) { register alpassvv_susp_type susp; - rate_type sr = max(max(input->sr, delaysnd->sr), feedback->sr); + rate_type sr = input->sr; time_type t0 = max(input->t0, delaysnd->t0); int interp_desc = 0; sample_type scale_factor = 1.0F; @@ -591,15 +1865,37 @@ sound_type snd_make_alpassvv(sound_type input, sound_type delaysnd, sound_type f susp->delayptr = susp->delaybuf; susp->endptr = susp->delaybuf + susp->buflen; + /* make sure no sample rate is too high */ + if (delaysnd->sr > sr) { + sound_unref(delaysnd); + snd_badsr(); + } + if (feedback->sr > sr) { + sound_unref(feedback); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); interp_desc = (interp_desc << 2) + interp_style(delaysnd, sr); interp_desc = (interp_desc << 2) + interp_style(feedback, sr); switch (interp_desc) { + case INTERP_nsn: /* handled below */ case INTERP_nnn: susp->susp.fetch = alpassvv_nnn_fetch; break; + case INTERP_nss: /* handled below */ case INTERP_nns: susp->susp.fetch = alpassvv_nns_fetch; break; - case INTERP_nsn: susp->susp.fetch = alpassvv_nsn_fetch; break; - case INTERP_nss: susp->susp.fetch = alpassvv_nss_fetch; break; + case INTERP_nsi: /* handled below */ + case INTERP_nni: susp->susp.fetch = alpassvv_nni_fetch; break; + case INTERP_nsr: /* handled below */ + case INTERP_nnr: susp->susp.fetch = alpassvv_nnr_fetch; break; + case INTERP_nin: susp->susp.fetch = alpassvv_nin_fetch; break; + case INTERP_nis: susp->susp.fetch = alpassvv_nis_fetch; break; + case INTERP_nii: susp->susp.fetch = alpassvv_nii_fetch; break; + case INTERP_nir: susp->susp.fetch = alpassvv_nir_fetch; break; + case INTERP_nrn: susp->susp.fetch = alpassvv_nrn_fetch; break; + case INTERP_nrs: susp->susp.fetch = alpassvv_nrs_fetch; break; + case INTERP_nri: susp->susp.fetch = alpassvv_nri_fetch; break; + case INTERP_nrr: susp->susp.fetch = alpassvv_nrr_fetch; break; default: snd_badsr(); break; } @@ -613,8 +1909,8 @@ sound_type snd_make_alpassvv(sound_type input, sound_type delaysnd, sound_type f /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = alpassvv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = alpassvv_toss_fetch; } /* initialize susp state */ @@ -625,13 +1921,22 @@ sound_type snd_make_alpassvv(sound_type input, sound_type delaysnd, sound_type f susp->susp.print_tree = alpassvv_print_tree; susp->susp.name = "alpassvv"; susp->susp.log_stop_cnt = UNKNOWN; + susp->started = false; susp->susp.current = 0; susp->input = input; susp->input_cnt = 0; susp->delaysnd = delaysnd; susp->delaysnd_cnt = 0; + susp->delaysnd_pHaSe = 0.0; + susp->delaysnd_pHaSe_iNcR = delaysnd->sr / sr; + susp->delaysnd_n = 0; + susp->output_per_delaysnd = sr / delaysnd->sr; susp->feedback = feedback; susp->feedback_cnt = 0; + susp->feedback_pHaSe = 0.0; + susp->feedback_pHaSe_iNcR = feedback->sr / sr; + susp->feedback_n = 0; + susp->output_per_feedback = sr / feedback->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/amosc.alg b/lib-src/libnyquist/nyquist/tran/amosc.alg index 01032022a..1e9d22813 100644 --- a/lib-src/libnyquist/nyquist/tran/amosc.alg +++ b/lib-src/libnyquist/nyquist/tran/amosc.alg @@ -16,18 +16,16 @@ (ALWAYS-SCALE amod) (TERMINATE (MIN amod)) (LOGICAL-STOP (MIN amod)) -(INNER-LOOP " - long table_index = (long) phase; - double x1 = (double) (table_ptr[table_index]); - output = (sample_type) (x1 + (phase - table_index) * - (table_ptr[table_index + 1] - x1)) * amod; - phase += ph_incr; - while (phase > table_len) phase -= table_len; -") +(INNER-LOOP "{ +\t\tlong table_index = (long) phase; +\t\tdouble x1 = (double) (table_ptr[table_index]); +\t\toutput = (sample_type) ((x1 + (phase - table_index) * +\t\t (table_ptr[table_index + 1] - x1)) * amod); +\t\tphase += ph_incr; +\t\twhile (phase > table_len) phase -= table_len; +\t }") (CONSTANT "ph_incr" "table_len" "table_ptr" "the_table") - (SAMPLE-RATE "sr") -(FINALIZATION " table_unref(susp->the_table); -") +(FINALIZATION " table_unref(susp->the_table);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/amosc.c b/lib-src/libnyquist/nyquist/tran/amosc.c index 16e45b470..714b5941c 100644 --- a/lib-src/libnyquist/nyquist/tran/amosc.c +++ b/lib-src/libnyquist/nyquist/tran/amosc.c @@ -9,17 +9,27 @@ #include "cext.h" #include "amosc.h" -void amosc_free(); +void amosc_free(snd_susp_type a_susp); typedef struct amosc_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; boolean logically_stopped; sound_type amod; long amod_cnt; sample_block_values_type amod_ptr; + /* support for interpolation of amod */ + sample_type amod_x1_sample; + double amod_pHaSe; + double amod_pHaSe_iNcR; + + /* support for ramp between samples of amod */ + double output_per_amod; + long amod_n; + double ph_incr; table_type the_table; sample_type *table_ptr; @@ -28,8 +38,9 @@ typedef struct amosc_susp_struct { } amosc_susp_node, *amosc_susp_type; -void amosc_s_fetch(register amosc_susp_type susp, snd_list_type snd_list) +void amosc_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + amosc_susp_type susp = (amosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -61,6 +72,7 @@ void amosc_s_fetch(register amosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -72,6 +84,7 @@ void amosc_s_fetch(register amosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -97,14 +110,14 @@ void amosc_s_fetch(register amosc_susp_type susp, snd_list_type snd_list) amod_ptr_reg = susp->amod_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - long table_index = (long) phase_reg; - double x1 = (double) (table_ptr_reg[table_index]); - *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * - (table_ptr_reg[table_index + 1] - x1)) * (amod_scale_reg * *amod_ptr_reg++); - phase_reg += ph_incr_reg; - while (phase_reg > table_len_reg) phase_reg -= table_len_reg; -; + { + long table_index = (long) phase_reg; + double x1 = (double) (table_ptr_reg[table_index]); + *out_ptr_reg++ = (sample_type) ((x1 + (phase_reg - table_index) * + (table_ptr_reg[table_index + 1] - x1)) * (amod_scale_reg * *amod_ptr_reg++)); + phase_reg += ph_incr_reg; + while (phase_reg > table_len_reg) phase_reg -= table_len_reg; + }; } while (--n); /* inner loop */ susp->phase = phase_reg; @@ -131,11 +144,263 @@ void amosc_s_fetch(register amosc_susp_type susp, snd_list_type snd_list) } /* amosc_s_fetch */ -void amosc_toss_fetch(susp, snd_list) - register amosc_susp_type susp; - snd_list_type snd_list; +void amosc_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + amosc_susp_type susp = (amosc_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type amod_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double ph_incr_reg; + register sample_type * table_ptr_reg; + register double table_len_reg; + register double phase_reg; + register double amod_pHaSe_iNcR_rEg = susp->amod_pHaSe_iNcR; + register double amod_pHaSe_ReG; + register sample_type amod_x1_sample_reg; + falloc_sample_block(out, "amosc_i_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(amod, amod_ptr, amod_cnt); + susp->amod_x1_sample = susp_fetch_sample(amod, amod_ptr, amod_cnt); + } + + susp_check_term_log_samples(amod, amod_ptr, amod_cnt); + amod_x2_sample = susp_current_sample(amod, amod_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + ph_incr_reg = susp->ph_incr; + table_ptr_reg = susp->table_ptr; + table_len_reg = susp->table_len; + phase_reg = susp->phase; + amod_pHaSe_ReG = susp->amod_pHaSe; + amod_x1_sample_reg = susp->amod_x1_sample; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (amod_pHaSe_ReG >= 1.0) { + amod_x1_sample_reg = amod_x2_sample; + /* pick up next sample as amod_x2_sample: */ + susp->amod_ptr++; + susp_took(amod_cnt, 1); + amod_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(amod, amod_ptr, amod_cnt, amod_x2_sample); + } + { + long table_index = (long) phase_reg; + double x1 = (double) (table_ptr_reg[table_index]); + *out_ptr_reg++ = (sample_type) ((x1 + (phase_reg - table_index) * + (table_ptr_reg[table_index + 1] - x1)) * + (amod_x1_sample_reg * (1 - amod_pHaSe_ReG) + amod_x2_sample * amod_pHaSe_ReG)); + phase_reg += ph_incr_reg; + while (phase_reg > table_len_reg) phase_reg -= table_len_reg; + }; + amod_pHaSe_ReG += amod_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->phase = phase_reg; + susp->amod_pHaSe = amod_pHaSe_ReG; + susp->amod_x1_sample = amod_x1_sample_reg; + out_ptr += togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* amosc_i_fetch */ + + +void amosc_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + amosc_susp_type susp = (amosc_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type amod_DeLtA; + sample_type amod_val; + sample_type amod_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double ph_incr_reg; + register sample_type * table_ptr_reg; + register double table_len_reg; + register double phase_reg; + falloc_sample_block(out, "amosc_r_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->amod_pHaSe = 1.0; + } + + susp_check_term_log_samples(amod, amod_ptr, amod_cnt); + amod_x2_sample = susp_current_sample(amod, amod_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* grab next amod_x2_sample when phase goes past 1.0; */ + /* we use amod_n (computed below) to avoid roundoff errors: */ + if (susp->amod_n <= 0) { + susp->amod_x1_sample = amod_x2_sample; + susp->amod_ptr++; + susp_took(amod_cnt, 1); + susp->amod_pHaSe -= 1.0; + susp_check_term_log_samples(amod, amod_ptr, amod_cnt); + amod_x2_sample = susp_current_sample(amod, amod_ptr); + /* amod_n gets number of samples before phase exceeds 1.0: */ + susp->amod_n = (long) ((1.0 - susp->amod_pHaSe) * + susp->output_per_amod); + } + togo = min(togo, susp->amod_n); + amod_DeLtA = (sample_type) ((amod_x2_sample - susp->amod_x1_sample) * susp->amod_pHaSe_iNcR); + amod_val = (sample_type) (susp->amod_x1_sample * (1.0 - susp->amod_pHaSe) + + amod_x2_sample * susp->amod_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + ph_incr_reg = susp->ph_incr; + table_ptr_reg = susp->table_ptr; + table_len_reg = susp->table_len; + phase_reg = susp->phase; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + { + long table_index = (long) phase_reg; + double x1 = (double) (table_ptr_reg[table_index]); + *out_ptr_reg++ = (sample_type) ((x1 + (phase_reg - table_index) * + (table_ptr_reg[table_index + 1] - x1)) * amod_val); + phase_reg += ph_incr_reg; + while (phase_reg > table_len_reg) phase_reg -= table_len_reg; + }; + amod_val += amod_DeLtA; + } while (--n); /* inner loop */ + + susp->phase = phase_reg; + out_ptr += togo; + susp->amod_pHaSe += togo * susp->amod_pHaSe_iNcR; + susp->amod_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* amosc_r_fetch */ + + +void amosc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + amosc_susp_type susp = (amosc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -150,26 +415,29 @@ void amosc_toss_fetch(susp, snd_list) susp->amod_ptr += n; susp_took(amod_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void amosc_mark(amosc_susp_type susp) +void amosc_mark(snd_susp_type a_susp) { + amosc_susp_type susp = (amosc_susp_type) a_susp; sound_xlmark(susp->amod); } -void amosc_free(amosc_susp_type susp) +void amosc_free(snd_susp_type a_susp) { + amosc_susp_type susp = (amosc_susp_type) a_susp; table_unref(susp->the_table); sound_unref(susp->amod); ffree_generic(susp, sizeof(amosc_susp_node), "amosc_free"); } -void amosc_print_tree(amosc_susp_type susp, int n) +void amosc_print_tree(snd_susp_type a_susp, int n) { + amosc_susp_type susp = (amosc_susp_type) a_susp; indent(n); stdputstr("amod:"); sound_print_tree_1(susp->amod, n); @@ -191,7 +459,23 @@ sound_type snd_make_amosc(sound_type input, double step, rate_type sr, double hz susp->table_len = susp->the_table->length; susp->phase = compute_phase(phase, step, (long) susp->table_len, input->sr, sr, hz, &susp->ph_incr); - susp->susp.fetch = amosc_s_fetch; + + /* make sure no sample rate is too high */ + if (amod->sr > sr) { + sound_unref(amod); + snd_badsr(); + } + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(amod, sr); + switch (interp_desc) { + case INTERP_n: /* handled below */ + case INTERP_s: susp->susp.fetch = amosc_s_fetch; break; + case INTERP_i: susp->susp.fetch = amosc_i_fetch; break; + case INTERP_r: susp->susp.fetch = amosc_r_fetch; break; + default: snd_badsr(); break; + } + susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < amod->t0) sound_prepend_zeros(amod, t0); @@ -200,8 +484,8 @@ sound_type snd_make_amosc(sound_type input, double step, rate_type sr, double hz /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = amosc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = amosc_toss_fetch; } /* initialize susp state */ @@ -213,9 +497,14 @@ sound_type snd_make_amosc(sound_type input, double step, rate_type sr, double hz susp->susp.name = "amosc"; susp->logically_stopped = false; susp->susp.log_stop_cnt = logical_stop_cnt_cvt(amod); + susp->started = false; susp->susp.current = 0; susp->amod = amod; susp->amod_cnt = 0; + susp->amod_pHaSe = 0.0; + susp->amod_pHaSe_iNcR = amod->sr / sr; + susp->amod_n = 0; + susp->output_per_amod = sr / amod->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/areson.c b/lib-src/libnyquist/nyquist/tran/areson.c index 6fb04e23d..f39c65f62 100644 --- a/lib-src/libnyquist/nyquist/tran/areson.c +++ b/lib-src/libnyquist/nyquist/tran/areson.c @@ -9,7 +9,7 @@ #include "cext.h" #include "areson.h" -void areson_free(); +void areson_free(snd_susp_type a_susp); typedef struct areson_susp_struct { @@ -28,8 +28,9 @@ typedef struct areson_susp_struct { } areson_susp_node, *areson_susp_type; -void areson_n_fetch(register areson_susp_type susp, snd_list_type snd_list) +void areson_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + areson_susp_type susp = (areson_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -61,6 +62,7 @@ void areson_n_fetch(register areson_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -72,6 +74,7 @@ void areson_n_fetch(register areson_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -98,7 +101,7 @@ void areson_n_fetch(register areson_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current;current = *input_ptr_reg++; + register double y0, current; current = *input_ptr_reg++; *out_ptr_reg++ = (sample_type) (y0 = c1_reg * current + c2_reg * y1_reg - c3_reg * y2_reg); y2_reg = y1_reg; y1_reg = y0 - current; } while (--n); /* inner loop */ @@ -128,11 +131,9 @@ void areson_n_fetch(register areson_susp_type susp, snd_list_type snd_list) } /* areson_n_fetch */ -void areson_toss_fetch(susp, snd_list) - register areson_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void areson_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + areson_susp_type susp = (areson_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -147,25 +148,28 @@ void areson_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void areson_mark(areson_susp_type susp) +void areson_mark(snd_susp_type a_susp) { + areson_susp_type susp = (areson_susp_type) a_susp; sound_xlmark(susp->input); } -void areson_free(areson_susp_type susp) +void areson_free(snd_susp_type a_susp) { + areson_susp_type susp = (areson_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(areson_susp_node), "areson_free"); } -void areson_print_tree(areson_susp_type susp, int n) +void areson_print_tree(snd_susp_type a_susp, int n) { + areson_susp_type susp = (areson_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -180,7 +184,6 @@ sound_type snd_make_areson(sound_type input, double hz, double bw, int normaliza double omc3; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; /* combine scale factors of linear inputs (INPUT) */ @@ -210,8 +213,8 @@ sound_type snd_make_areson(sound_type input, double hz, double bw, int normaliza /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = areson_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = areson_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/aresoncv.alg b/lib-src/libnyquist/nyquist/tran/aresoncv.alg index f43986736..4709dd384 100644 --- a/lib-src/libnyquist/nyquist/tran/aresoncv.alg +++ b/lib-src/libnyquist/nyquist/tran/aresoncv.alg @@ -2,9 +2,8 @@ (NAME "aresoncv") (ARGUMENTS ("sound_type" "s1") ("double" "hz") ("sound_type" "bw") ("int" "normalization")) -(INLINE-INTERPOLATION T) (LINEAR s1) -(ALWAYS-SCALE bw) +(ALWAYS-SCALE bw) ; because there's a necessary scale factor -PI2/sr (START (MAX s1 bw)) (TERMINATE (MIN s1 bw)) (LOGICAL-STOP (MIN s1)) @@ -18,19 +17,19 @@ ("double" "y1" "0.0") ("double" "y2" "0.0; bw->scale = (float) (bw->scale * (-PI2 / s1->sr))")) -(DEPENDS ("c3co" "hz" "exp(bw)") - ("c3p1" "hz" "c3co + 1.0" TEMP "double") - ("c3t4" "hz" "c3co * 4.0" TEMP "double") - ("omc3" "hz" "1.0 - c3co" TEMP "double") - ("c2" "hz" "c3t4 * coshz / c3p1") - ("c1" "hz" "(normalization == 0 ? 0.0 : +(DEPENDS ("c3co" "bw" "exp(bw)") + ("c3p1" "bw" "c3co + 1.0" TEMP "double") + ("c3t4" "bw" "c3co * 4.0" TEMP "double") + ("omc3" "bw" "1.0 - c3co" TEMP "double") + ("c2" "bw" "c3t4 * coshz / c3p1") + ("c1" "bw" "(normalization == 0 ? 0.0 : (normalization == 1 ? 1.0 - omc3 * sqrt(1.0 - c2 * c2 / c3t4) : 1.0 - sqrt(c3p1 * c3p1 - c2 * c2) * omc3 / c3p1))")) (CONSTANT "c1" "c2" "c3co" "coshz" "normalization") -(FORCE-INTO-REGISTER normalization coshz scale1) -(INNER-LOOP-LOCALS " register double y0, current;") -(INNER-LOOP " - current = s1; +(FORCE-INTO-REGISTER normalization coshz) +(INNER-LOOP-LOCALS " register double y0, current; +") +(INNER-LOOP "current = s1; output = (float) (y0 = c1 * current + c2 * y1 - c3co * y2); y2 = y1; y1 = y0 - current") ) diff --git a/lib-src/libnyquist/nyquist/tran/aresoncv.c b/lib-src/libnyquist/nyquist/tran/aresoncv.c index d29e599b0..ed6c0284a 100644 --- a/lib-src/libnyquist/nyquist/tran/aresoncv.c +++ b/lib-src/libnyquist/nyquist/tran/aresoncv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "aresoncv.h" -void aresoncv_free(); +void aresoncv_free(snd_susp_type a_susp); typedef struct aresoncv_susp_struct { @@ -43,8 +43,9 @@ typedef struct aresoncv_susp_struct { } aresoncv_susp_node, *aresoncv_susp_type; -void aresoncv_ns_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) +void aresoncv_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -84,6 +85,7 @@ void aresoncv_ns_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -95,6 +97,7 @@ void aresoncv_ns_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -125,6 +128,17 @@ void aresoncv_ns_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ register double y0, current; + double c3p1; + double c3t4; + double omc3; + c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); + c3p1 = c3co_reg + 1.0; + c3t4 = c3co_reg * 4.0; + omc3 = 1.0 - c3co_reg; + c2_reg = c3t4 * coshz_reg / c3p1; + c1_reg = (normalization_reg == 0 ? 0.0 : + (normalization_reg == 1 ? 1.0 - omc3 * sqrt(1.0 - c2_reg * c2_reg / c3t4) : + 1.0 - sqrt(c3p1 * c3p1 - c2_reg * c2_reg) * omc3 / c3p1)); current = *s1_ptr_reg++; *out_ptr_reg++ = (float) (y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg); y2_reg = y1_reg; y1_reg = y0 - current; @@ -158,8 +172,9 @@ void aresoncv_ns_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) } /* aresoncv_ns_fetch */ -void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) +void aresoncv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -185,9 +200,20 @@ void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) /* make sure sounds are primed with first values */ if (!susp->started) { + double c3p1; + double c3t4; + double omc3; susp->started = true; susp_check_term_samples(bw, bw_ptr, bw_cnt); susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); + susp->c3co = exp(susp->bw_x1_sample); + c3p1 = susp->c3co + 1.0; + c3t4 = susp->c3co * 4.0; + omc3 = 1.0 - susp->c3co; + susp->c2 = c3t4 * susp->coshz / c3p1; + susp->c1 = (susp->normalization == 0 ? 0.0 : + (susp->normalization == 1 ? 1.0 - omc3 * sqrt(1.0 - susp->c2 * susp->c2 / c3t4) : + 1.0 - sqrt(c3p1 * c3p1 - susp->c2 * susp->c2) * omc3 / c3p1)); } while (cnt < max_sample_block_len) { /* outer loop */ @@ -203,6 +229,7 @@ void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -214,6 +241,7 @@ void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -244,16 +272,27 @@ void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (bw_pHaSe_ReG >= 1.0) { + register double y0, current; + if (bw_pHaSe_ReG >= 1.0) { /* fixup-depends bw */ + double c3p1; + double c3t4; + double omc3; /* pick up next sample as bw_x1_sample: */ susp->bw_ptr++; susp_took(bw_cnt, 1); bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); + c3co_reg = exp(bw_x1_sample_reg); + c3p1 = c3co_reg + 1.0; + c3t4 = c3co_reg * 4.0; + omc3 = 1.0 - c3co_reg; + c2_reg = c3t4 * coshz_reg / c3p1; + c1_reg = (normalization_reg == 0 ? 0.0 : + (normalization_reg == 1 ? 1.0 - omc3 * sqrt(1.0 - c2_reg * c2_reg / c3t4) : + 1.0 - sqrt(c3p1 * c3p1 - c2_reg * c2_reg) * omc3 / c3p1)); } - current = *s1_ptr_reg++; *out_ptr_reg++ = (float) (y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg); y2_reg = y1_reg; y1_reg = y0 - current; @@ -288,8 +327,9 @@ void aresoncv_ni_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) } /* aresoncv_ni_fetch */ -void aresoncv_nr_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) +void aresoncv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -331,12 +371,23 @@ void aresoncv_nr_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) /* grab next bw_x1_sample when phase goes past 1.0; */ /* use bw_n (computed below) to avoid roundoff errors: */ if (susp->bw_n <= 0) { + double c3p1; + double c3t4; + double omc3; susp_check_term_samples(bw, bw_ptr, bw_cnt); susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); susp->bw_pHaSe -= 1.0; /* bw_n gets number of samples before phase exceeds 1.0: */ susp->bw_n = (long) ((1.0 - susp->bw_pHaSe) * susp->output_per_bw); + susp->c3co = exp(susp->bw_x1_sample); + c3p1 = susp->c3co + 1.0; + c3t4 = susp->c3co * 4.0; + omc3 = 1.0 - susp->c3co; + susp->c2 = c3t4 * susp->coshz / c3p1; + susp->c1 = (susp->normalization == 0 ? 0.0 : + (susp->normalization == 1 ? 1.0 - omc3 * sqrt(1.0 - susp->c2 * susp->c2 / c3t4) : + 1.0 - sqrt(c3p1 * c3p1 - susp->c2 * susp->c2) * omc3 / c3p1)); } togo = min(togo, susp->bw_n); bw_val = susp->bw_x1_sample; @@ -344,6 +395,7 @@ void aresoncv_nr_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -355,6 +407,7 @@ void aresoncv_nr_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -416,11 +469,9 @@ void aresoncv_nr_fetch(register aresoncv_susp_type susp, snd_list_type snd_list) } /* aresoncv_nr_fetch */ -void aresoncv_toss_fetch(susp, snd_list) - register aresoncv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void aresoncv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -443,27 +494,30 @@ void aresoncv_toss_fetch(susp, snd_list) susp->bw_ptr += n; susp_took(bw_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void aresoncv_mark(aresoncv_susp_type susp) +void aresoncv_mark(snd_susp_type a_susp) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->bw); } -void aresoncv_free(aresoncv_susp_type susp) +void aresoncv_free(snd_susp_type a_susp) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->bw); ffree_generic(susp, sizeof(aresoncv_susp_node), "aresoncv_free"); } -void aresoncv_print_tree(aresoncv_susp_type susp, int n) +void aresoncv_print_tree(snd_susp_type a_susp, int n) { + aresoncv_susp_type susp = (aresoncv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -499,6 +553,12 @@ sound_type snd_make_aresoncv(sound_type s1, double hz, sound_type bw, int normal susp->y2 = 0.0; bw->scale = (float) (bw->scale * (-PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (bw->sr > sr) { + sound_unref(bw); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(bw, sr); @@ -519,8 +579,8 @@ sound_type snd_make_aresoncv(sound_type s1, double hz, sound_type bw, int normal /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = aresoncv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = aresoncv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/aresonvc.alg b/lib-src/libnyquist/nyquist/tran/aresonvc.alg index 277ef8a40..13cf90098 100644 --- a/lib-src/libnyquist/nyquist/tran/aresonvc.alg +++ b/lib-src/libnyquist/nyquist/tran/aresonvc.alg @@ -3,7 +3,6 @@ (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz") ("double" "bw") ("int" "normalization")) (LINEAR s1) -(INLINE-INTERPOLATION T) (ALWAYS-SCALE hz) (START (MAX s1 hz)) (TERMINATE (MIN s1 hz)) diff --git a/lib-src/libnyquist/nyquist/tran/aresonvc.c b/lib-src/libnyquist/nyquist/tran/aresonvc.c index f0c47fced..966d4780b 100644 --- a/lib-src/libnyquist/nyquist/tran/aresonvc.c +++ b/lib-src/libnyquist/nyquist/tran/aresonvc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "aresonvc.h" -void aresonvc_free(); +void aresonvc_free(snd_susp_type a_susp); typedef struct aresonvc_susp_struct { @@ -45,8 +45,9 @@ typedef struct aresonvc_susp_struct { } aresonvc_susp_node, *aresonvc_susp_type; -void aresonvc_ns_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) +void aresonvc_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -88,6 +89,7 @@ void aresonvc_ns_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -99,6 +101,7 @@ void aresonvc_ns_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -134,7 +137,7 @@ void aresonvc_ns_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) c1_reg = (normalization_reg == 0 ? 0.0 : (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -168,8 +171,9 @@ current = *s1_ptr_reg++; } /* aresonvc_ns_fetch */ -void aresonvc_ni_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) +void aresonvc_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -219,6 +223,7 @@ void aresonvc_ni_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -230,6 +235,7 @@ void aresonvc_ni_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -270,12 +276,12 @@ void aresonvc_ni_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) hz_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz, hz_ptr, hz_cnt, hz_x1_sample_reg); hz_x1_sample_reg = susp_current_sample(hz, hz_ptr); - c2_reg = susp->c2 = c3t4_reg * cos(hz_x1_sample_reg) / c3p1_reg; - c1_reg = susp->c1 = (normalization_reg == 0 ? 0.0 : + c2_reg = c3t4_reg * cos(hz_x1_sample_reg) / c3p1_reg; + c1_reg = (normalization_reg == 0 ? 0.0 : (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -310,8 +316,9 @@ current = *s1_ptr_reg++; } /* aresonvc_ni_fetch */ -void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) +void aresonvc_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz_val; int togo; @@ -372,6 +379,7 @@ void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -383,6 +391,7 @@ void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -413,7 +422,7 @@ void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current;current = *s1_ptr_reg++; + register double y0, current; current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -446,11 +455,9 @@ void aresonvc_nr_fetch(register aresonvc_susp_type susp, snd_list_type snd_list) } /* aresonvc_nr_fetch */ -void aresonvc_toss_fetch(susp, snd_list) - register aresonvc_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void aresonvc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -473,27 +480,30 @@ void aresonvc_toss_fetch(susp, snd_list) susp->hz_ptr += n; susp_took(hz_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void aresonvc_mark(aresonvc_susp_type susp) +void aresonvc_mark(snd_susp_type a_susp) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz); } -void aresonvc_free(aresonvc_susp_type susp) +void aresonvc_free(snd_susp_type a_susp) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz); ffree_generic(susp, sizeof(aresonvc_susp_node), "aresonvc_free"); } -void aresonvc_print_tree(aresonvc_susp_type susp, int n) +void aresonvc_print_tree(snd_susp_type a_susp, int n) { + aresonvc_susp_type susp = (aresonvc_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -531,6 +541,12 @@ sound_type snd_make_aresonvc(sound_type s1, sound_type hz, double bw, int normal susp->y2 = 0.0; hz->scale = (sample_type) (hz->scale * (PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (hz->sr > sr) { + sound_unref(hz); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz, sr); @@ -551,8 +567,8 @@ sound_type snd_make_aresonvc(sound_type s1, sound_type hz, double bw, int normal /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = aresonvc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = aresonvc_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/aresonvv.alg b/lib-src/libnyquist/nyquist/tran/aresonvv.alg index a56c2fd58..c2efb2141 100644 --- a/lib-src/libnyquist/nyquist/tran/aresonvv.alg +++ b/lib-src/libnyquist/nyquist/tran/aresonvv.alg @@ -2,7 +2,6 @@ (NAME "aresonvv") (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz1") ("sound_type" "bw") ("int" "normalization")) -(INLINE-INTERPOLATION T) (ALWAYS-SCALE hz1 bw) (START (MAX s1 hz1 bw)) (TERMINATE (MIN s1 hz1 bw)) @@ -28,7 +27,7 @@ ("recompute" "hz1" "true") ("c3co" "bw" "exp(bw)") ("c3p1" "bw" "c3co + 1.0") - ("c3t4" "bw" "c3co * 4.0") + ("c3t4" "bw" "c3co * 4.0") ("omc3" "bw" "1.0 - c3co") ("recompute" "bw" "true")) (JOINT-DEPENDENCY (("hz1" "bw") @@ -36,13 +35,15 @@ " recompute = false;" " c2 = c3t4 * coshz / c3p1;" " c1 = (normalization == 0 ? 0.0 :" -" (normalization == 1 ? 1.0 - omc3 * sqrt(1.0 - c2 * c2 / c3t4) :" -" 1.0 - sqrt(c3p1 * c3p1 - c2 * c2) * omc3 / c3p1));" +" (normalization == 1 ? " +" 1.0 - omc3 * sqrt(1.0 - c2 * c2 / c3t4) :" +" 1.0 - sqrt(c3p1 * c3p1 - c2 * c2) * " +" omc3 / c3p1));" "}")) (CONSTANT "c1" "c2" "c3co" "coshz" "c3p1" "c3t4" "omc3" "normalization" "scale1") (FORCE-INTO-REGISTER recompute) ;c3t4 c3p1 normalization omc3 scale1 -(INNER-LOOP-LOCALS " register double y0, current;") +(INNER-LOOP-LOCALS " register double y0, current;\n") (INNER-LOOP "current = s1; y0 = c1 * current + c2 * y1 - c3co * y2; output = (sample_type) y0; diff --git a/lib-src/libnyquist/nyquist/tran/aresonvv.c b/lib-src/libnyquist/nyquist/tran/aresonvv.c index b38d9d923..a6cfb2e26 100644 --- a/lib-src/libnyquist/nyquist/tran/aresonvv.c +++ b/lib-src/libnyquist/nyquist/tran/aresonvv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "aresonvv.h" -void aresonvv_free(); +void aresonvv_free(snd_susp_type a_susp); typedef struct aresonvv_susp_struct { @@ -60,8 +60,9 @@ typedef struct aresonvv_susp_struct { } aresonvv_susp_node, *aresonvv_susp_type; -void aresonvv_nss_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -111,6 +112,7 @@ void aresonvv_nss_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -122,6 +124,7 @@ void aresonvv_nss_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -156,7 +159,8 @@ void aresonvv_nss_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); + register double y0, current; + coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); recompute_reg = true; c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); c3p1_reg = c3co_reg + 1.0; @@ -167,10 +171,12 @@ void aresonvv_nss_fetch(register aresonvv_susp_type susp, snd_list_type snd_list recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -208,8 +214,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nss_fetch */ -void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nsi_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -268,6 +275,7 @@ void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -279,6 +287,7 @@ void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -314,7 +323,8 @@ void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (bw_pHaSe_ReG >= 1.0) { + register double y0, current; + if (bw_pHaSe_ReG >= 1.0) { /* fixup-depends bw */ /* pick up next sample as bw_x1_sample: */ susp->bw_ptr++; @@ -322,11 +332,11 @@ void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); recompute_reg = true; @@ -334,10 +344,12 @@ void aresonvv_nsi_fetch(register aresonvv_susp_type susp, snd_list_type snd_list recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -376,8 +388,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nsi_fetch */ -void aresonvv_nsr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nsr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -447,6 +460,7 @@ void aresonvv_nsr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -458,6 +472,7 @@ void aresonvv_nsr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -491,16 +506,19 @@ void aresonvv_nsr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); + register double y0, current; + coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); recompute_reg = true; if (recompute_reg) { recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -537,8 +555,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nsr_fetch */ -void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nis_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -594,6 +613,7 @@ void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -605,6 +625,7 @@ void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -640,7 +661,8 @@ void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (hz1_pHaSe_ReG >= 1.0) { + register double y0, current; + if (hz1_pHaSe_ReG >= 1.0) { /* fixup-depends hz1 */ /* pick up next sample as hz1_x1_sample: */ susp->hz1_ptr++; @@ -648,8 +670,8 @@ void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); c3p1_reg = c3co_reg + 1.0; @@ -660,10 +682,12 @@ void aresonvv_nis_fetch(register aresonvv_susp_type susp, snd_list_type snd_list recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -702,8 +726,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nis_fetch */ -void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nii_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -763,6 +788,7 @@ void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -774,6 +800,7 @@ void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -810,7 +837,8 @@ void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (hz1_pHaSe_ReG >= 1.0) { + register double y0, current; + if (hz1_pHaSe_ReG >= 1.0) { /* fixup-depends hz1 */ /* pick up next sample as hz1_x1_sample: */ susp->hz1_ptr++; @@ -818,8 +846,8 @@ void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } if (bw_pHaSe_ReG >= 1.0) { /* fixup-depends bw */ @@ -829,20 +857,22 @@ void aresonvv_nii_fetch(register aresonvv_susp_type susp, snd_list_type snd_list bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -881,8 +911,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nii_fetch */ -void aresonvv_nir_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nir_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -953,6 +984,7 @@ void aresonvv_nir_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -964,6 +996,7 @@ void aresonvv_nir_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -998,7 +1031,8 @@ void aresonvv_nir_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (hz1_pHaSe_ReG >= 1.0) { + register double y0, current; + if (hz1_pHaSe_ReG >= 1.0) { /* fixup-depends hz1 */ /* pick up next sample as hz1_x1_sample: */ susp->hz1_ptr++; @@ -1006,17 +1040,19 @@ void aresonvv_nir_fetch(register aresonvv_susp_type susp, snd_list_type snd_list hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -1054,8 +1090,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nir_fetch */ -void aresonvv_nrs_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nrs_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; int togo; @@ -1122,6 +1159,7 @@ void aresonvv_nrs_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1133,6 +1171,7 @@ void aresonvv_nrs_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1166,7 +1205,8 @@ void aresonvv_nrs_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); + register double y0, current; + c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); c3p1_reg = c3co_reg + 1.0; c3t4_reg = c3co_reg * 4.0; omc3_reg = 1.0 - c3co_reg; @@ -1175,10 +1215,12 @@ void aresonvv_nrs_fetch(register aresonvv_susp_type susp, snd_list_type snd_list recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -1215,8 +1257,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nrs_fetch */ -void aresonvv_nri_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nri_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; int togo; @@ -1287,6 +1330,7 @@ void aresonvv_nri_fetch(register aresonvv_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1298,6 +1342,7 @@ void aresonvv_nri_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1332,7 +1377,8 @@ void aresonvv_nri_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current; if (bw_pHaSe_ReG >= 1.0) { + register double y0, current; + if (bw_pHaSe_ReG >= 1.0) { /* fixup-depends bw */ /* pick up next sample as bw_x1_sample: */ susp->bw_ptr++; @@ -1340,20 +1386,22 @@ void aresonvv_nri_fetch(register aresonvv_susp_type susp, snd_list_type snd_list bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; c2_reg = c3t4_reg * coshz_reg / c3p1_reg; c1_reg = (normalization_reg == 0 ? 0.0 : - (normalization_reg == 1 ? 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)); + (normalization_reg == 1 ? + 1.0 - omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : + 1.0 - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * + omc3_reg / c3p1_reg)); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -1391,8 +1439,9 @@ current = *s1_ptr_reg++; } /* aresonvv_nri_fetch */ -void aresonvv_nrr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list) +void aresonvv_nrr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; sample_type bw_val; @@ -1469,13 +1518,16 @@ void aresonvv_nrr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list susp->recompute = false; susp->c2 = susp->c3t4 * susp->coshz / susp->c3p1; susp->c1 = (susp->normalization == 0 ? 0.0 : - (susp->normalization == 1 ? 1.0 - susp->omc3 * sqrt(1.0 - susp->c2 * susp->c2 / susp->c3t4) : - 1.0 - sqrt(susp->c3p1 * susp->c3p1 - susp->c2 * susp->c2) * susp->omc3 / susp->c3p1)); + (susp->normalization == 1 ? + 1.0 - susp->omc3 * sqrt(1.0 - susp->c2 * susp->c2 / susp->c3t4) : + 1.0 - sqrt(susp->c3p1 * susp->c3p1 - susp->c2 * susp->c2) * + susp->omc3 / susp->c3p1)); } /* don't run past terminate time */ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1487,6 +1539,7 @@ void aresonvv_nrr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1514,7 +1567,8 @@ void aresonvv_nrr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double y0, current;current = *s1_ptr_reg++; + register double y0, current; + current = *s1_ptr_reg++; y0 = c1_reg * current + c2_reg * y1_reg - c3co_reg * y2_reg; *out_ptr_reg++ = (sample_type) y0; y2_reg = y1_reg; y1_reg = y0 - current; @@ -1550,11 +1604,9 @@ void aresonvv_nrr_fetch(register aresonvv_susp_type susp, snd_list_type snd_list } /* aresonvv_nrr_fetch */ -void aresonvv_toss_fetch(susp, snd_list) - register aresonvv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void aresonvv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -1585,20 +1637,22 @@ void aresonvv_toss_fetch(susp, snd_list) susp->bw_ptr += n; susp_took(bw_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void aresonvv_mark(aresonvv_susp_type susp) +void aresonvv_mark(snd_susp_type a_susp) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz1); sound_xlmark(susp->bw); } -void aresonvv_free(aresonvv_susp_type susp) +void aresonvv_free(snd_susp_type a_susp) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz1); sound_unref(susp->bw); @@ -1606,8 +1660,9 @@ void aresonvv_free(aresonvv_susp_type susp) } -void aresonvv_print_tree(aresonvv_susp_type susp, int n) +void aresonvv_print_tree(snd_susp_type a_susp, int n) { + aresonvv_susp_type susp = (aresonvv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -1653,6 +1708,16 @@ sound_type snd_make_aresonvv(sound_type s1, sound_type hz1, sound_type bw, int n hz1->scale = (sample_type) (hz1->scale * (PI2 / s1->sr)); bw->scale = (sample_type) (bw->scale * (-PI2 / s1->sr));; + /* make sure no sample rate is too high */ + if (hz1->sr > sr) { + sound_unref(hz1); + snd_badsr(); + } + if (bw->sr > sr) { + sound_unref(bw); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz1, sr); @@ -1687,8 +1752,8 @@ sound_type snd_make_aresonvv(sound_type s1, sound_type hz1, sound_type bw, int n /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = aresonvv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = aresonvv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/atone.alg b/lib-src/libnyquist/nyquist/tran/atone.alg index 03b4d9f37..d8ed3ba54 100644 --- a/lib-src/libnyquist/nyquist/tran/atone.alg +++ b/lib-src/libnyquist/nyquist/tran/atone.alg @@ -8,12 +8,14 @@ ("double" "cc" "bb - sqrt((bb * bb) - 1.0)") ("double" "prev" "0.0")) (CONSTANT "cc") -(INNER-LOOP-LOCALS " double current; +(INNER-LOOP-LOCALS " double current; ") (INNER-LOOP "current = s; - prev = cc * (prev + current); /* use prev as temp variable ... */ - output = (float) prev; /* ... so we can do proper type conversion */ - prev -= current;") + /* use prev as temp variable ... */ + prev = cc * (prev + current); + /* ... so we can do proper type conversion */ + output = (float) prev; + prev -= current") ; old code was: ; prev = (output = cc * (prev + current)) - current;") ) diff --git a/lib-src/libnyquist/nyquist/tran/atone.c b/lib-src/libnyquist/nyquist/tran/atone.c index 2ff1f5df2..01ff97dc6 100644 --- a/lib-src/libnyquist/nyquist/tran/atone.c +++ b/lib-src/libnyquist/nyquist/tran/atone.c @@ -9,7 +9,7 @@ #include "cext.h" #include "atone.h" -void atone_free(); +void atone_free(snd_susp_type a_susp); typedef struct atone_susp_struct { @@ -25,8 +25,9 @@ typedef struct atone_susp_struct { } atone_susp_node, *atone_susp_type; -void atone_n_fetch(register atone_susp_type susp, snd_list_type snd_list) +void atone_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + atone_susp_type susp = (atone_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -55,6 +56,7 @@ void atone_n_fetch(register atone_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -66,6 +68,7 @@ void atone_n_fetch(register atone_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -89,11 +92,13 @@ void atone_n_fetch(register atone_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double current; -current = *s_ptr_reg++; - prev_reg = cc_reg * (prev_reg + current); /* use prev_reg as temp variable ... */ - *out_ptr_reg++ = (float) prev_reg; /* ... so we can do proper type conversion */ - prev_reg -= current;; + double current; + current = *s_ptr_reg++; + /* use prev_reg as temp variable ... */ + prev_reg = cc_reg * (prev_reg + current); + /* ... so we can do proper type conversion */ + *out_ptr_reg++ = (float) prev_reg; + prev_reg -= current; } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -120,8 +125,9 @@ current = *s_ptr_reg++; } /* atone_n_fetch */ -void atone_s_fetch(register atone_susp_type susp, snd_list_type snd_list) +void atone_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + atone_susp_type susp = (atone_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -151,6 +157,7 @@ void atone_s_fetch(register atone_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -162,6 +169,7 @@ void atone_s_fetch(register atone_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -185,11 +193,13 @@ void atone_s_fetch(register atone_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double current; -current = (s_scale_reg * *s_ptr_reg++); - prev_reg = cc_reg * (prev_reg + current); /* use prev_reg as temp variable ... */ - *out_ptr_reg++ = (float) prev_reg; /* ... so we can do proper type conversion */ - prev_reg -= current;; + double current; + current = (s_scale_reg * *s_ptr_reg++); + /* use prev_reg as temp variable ... */ + prev_reg = cc_reg * (prev_reg + current); + /* ... so we can do proper type conversion */ + *out_ptr_reg++ = (float) prev_reg; + prev_reg -= current; } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -216,11 +226,9 @@ current = (s_scale_reg * *s_ptr_reg++); } /* atone_s_fetch */ -void atone_toss_fetch(susp, snd_list) - register atone_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void atone_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + atone_susp_type susp = (atone_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -235,25 +243,28 @@ void atone_toss_fetch(susp, snd_list) susp->s_ptr += n; susp_took(s_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void atone_mark(atone_susp_type susp) +void atone_mark(snd_susp_type a_susp) { + atone_susp_type susp = (atone_susp_type) a_susp; sound_xlmark(susp->s); } -void atone_free(atone_susp_type susp) +void atone_free(snd_susp_type a_susp) { + atone_susp_type susp = (atone_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(atone_susp_node), "atone_free"); } -void atone_print_tree(atone_susp_type susp, int n) +void atone_print_tree(snd_susp_type a_susp, int n) { + atone_susp_type susp = (atone_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); @@ -290,8 +301,8 @@ sound_type snd_make_atone(sound_type s, double hz) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = atone_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = atone_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/atonev.alg b/lib-src/libnyquist/nyquist/tran/atonev.alg index 441206fe0..a02a29fb9 100644 --- a/lib-src/libnyquist/nyquist/tran/atonev.alg +++ b/lib-src/libnyquist/nyquist/tran/atonev.alg @@ -1,8 +1,7 @@ (ATONEV-ALG (NAME "atonev") (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz")) -(INLINE-INTERPOLATION T) -(LINEAR hz) +(LINEAR s1) (ALWAYS-SCALE hz) (START (MAX s1 hz)) (TERMINATE (MIN s1 hz)) @@ -10,16 +9,14 @@ (STATE ("double" "cc" "0.0") ("double" "prev" "0.0; hz->scale = (sample_type) (hz->scale * (PI2 / s1->sr))")) -(LINEAR s1) (SAMPLE-RATE (MAX s1)) (STEP-FUNCTION hz) (DEPENDS ("bb" "hz" "2.0 - cos(hz)" TEMP "register double") ("cc" "hz" "bb - sqrt((bb * bb) - 1.0)")) (CONSTANT "cc") -(INNER-LOOP-LOCALS " double current; -") +(INNER-LOOP-LOCALS " double current;\n") (INNER-LOOP "current = s1; prev = cc * (prev + current); output = (sample_type) prev; - prev -= current;") + prev -= current") ) diff --git a/lib-src/libnyquist/nyquist/tran/atonev.c b/lib-src/libnyquist/nyquist/tran/atonev.c index 72532c644..8324a1900 100644 --- a/lib-src/libnyquist/nyquist/tran/atonev.c +++ b/lib-src/libnyquist/nyquist/tran/atonev.c @@ -9,7 +9,7 @@ #include "cext.h" #include "atonev.h" -void atonev_free(); +void atonev_free(snd_susp_type a_susp); typedef struct atonev_susp_struct { @@ -38,8 +38,9 @@ typedef struct atonev_susp_struct { } atonev_susp_node, *atonev_susp_type; -void atonev_ns_fetch(register atonev_susp_type susp, snd_list_type snd_list) +void atonev_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + atonev_susp_type susp = (atonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -74,6 +75,7 @@ void atonev_ns_fetch(register atonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -85,6 +87,7 @@ void atonev_ns_fetch(register atonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -109,14 +112,14 @@ void atonev_ns_fetch(register atonev_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double current; + double current; register double bb; bb = 2.0 - cos((hz_scale_reg * *hz_ptr_reg++)); cc_reg = bb - sqrt((bb * bb) - 1.0); -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; prev_reg = cc_reg * (prev_reg + current); *out_ptr_reg++ = (sample_type) prev_reg; - prev_reg -= current;; + prev_reg -= current; } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -146,8 +149,9 @@ current = *s1_ptr_reg++; } /* atonev_ns_fetch */ -void atonev_ni_fetch(register atonev_susp_type susp, snd_list_type snd_list) +void atonev_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + atonev_susp_type susp = (atonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -189,6 +193,7 @@ void atonev_ni_fetch(register atonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -200,6 +205,7 @@ void atonev_ni_fetch(register atonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -225,7 +231,7 @@ void atonev_ni_fetch(register atonev_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double current; + double current; if (hz_pHaSe_ReG >= 1.0) { /* fixup-depends hz */ register double bb; @@ -236,12 +242,12 @@ void atonev_ni_fetch(register atonev_susp_type susp, snd_list_type snd_list) susp_check_term_samples_break(hz, hz_ptr, hz_cnt, hz_x1_sample_reg); hz_x1_sample_reg = susp_current_sample(hz, hz_ptr); bb = 2.0 - cos(hz_x1_sample_reg); - cc_reg = susp->cc = bb - sqrt((bb * bb) - 1.0); + cc_reg = bb - sqrt((bb * bb) - 1.0); } -current = *s1_ptr_reg++; + current = *s1_ptr_reg++; prev_reg = cc_reg * (prev_reg + current); *out_ptr_reg++ = (sample_type) prev_reg; - prev_reg -= current;; + prev_reg -= current; hz_pHaSe_ReG += hz_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -272,8 +278,9 @@ current = *s1_ptr_reg++; } /* atonev_ni_fetch */ -void atonev_nr_fetch(register atonev_susp_type susp, snd_list_type snd_list) +void atonev_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + atonev_susp_type susp = (atonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz_val; int togo; @@ -326,6 +333,7 @@ void atonev_nr_fetch(register atonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -337,6 +345,7 @@ void atonev_nr_fetch(register atonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -360,11 +369,11 @@ void atonev_nr_fetch(register atonev_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double current; -current = *s1_ptr_reg++; + double current; + current = *s1_ptr_reg++; prev_reg = cc_reg * (prev_reg + current); *out_ptr_reg++ = (sample_type) prev_reg; - prev_reg -= current;; + prev_reg -= current; } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -393,11 +402,9 @@ current = *s1_ptr_reg++; } /* atonev_nr_fetch */ -void atonev_toss_fetch(susp, snd_list) - register atonev_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void atonev_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + atonev_susp_type susp = (atonev_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -420,27 +427,30 @@ void atonev_toss_fetch(susp, snd_list) susp->hz_ptr += n; susp_took(hz_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void atonev_mark(atonev_susp_type susp) +void atonev_mark(snd_susp_type a_susp) { + atonev_susp_type susp = (atonev_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz); } -void atonev_free(atonev_susp_type susp) +void atonev_free(snd_susp_type a_susp) { + atonev_susp_type susp = (atonev_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz); ffree_generic(susp, sizeof(atonev_susp_node), "atonev_free"); } -void atonev_print_tree(atonev_susp_type susp, int n) +void atonev_print_tree(snd_susp_type a_susp, int n) { + atonev_susp_type susp = (atonev_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -471,6 +481,12 @@ sound_type snd_make_atonev(sound_type s1, sound_type hz) susp->prev = 0.0; hz->scale = (sample_type) (hz->scale * (PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (hz->sr > sr) { + sound_unref(hz); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz, sr); @@ -491,8 +507,8 @@ sound_type snd_make_atonev(sound_type s1, sound_type hz) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = atonev_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = atonev_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/biquadfilt.alg b/lib-src/libnyquist/nyquist/tran/biquadfilt.alg index da2c75b67..1961257a9 100644 --- a/lib-src/libnyquist/nyquist/tran/biquadfilt.alg +++ b/lib-src/libnyquist/nyquist/tran/biquadfilt.alg @@ -7,8 +7,9 @@ (LISPNAME "biquad") (ARGUMENTS ("sound_type" "s") ("double" "b0") ("double" "b1") ("double" "b2") - ("double" "a1") ("double" "a2") + ("double" "a1") ("double" "a2") ("double" "z1init") ("double" "z2init")) +(LINEAR s) (START (MIN s)) (TERMINATE (MIN s)) (LOGICAL-STOP (MIN s)) @@ -20,9 +21,9 @@ ("double" "a1" "a1") ("double" "a2" "a2")) (CONSTANT "b0" "b1" "b2" "a1" "a2") -(INNER-LOOP-LOCALS "double z0;") -(INNER-LOOP " z0 = s + a1*z1 + a2*z2; - output = (sample_type) (z0*b0 + z1*b1 + z2*b2); - z2 = z1; z1 = z0;") +(INNER-LOOP-LOCALS " double z0;") +(INNER-LOOP "z0 = s + a1*z1 + a2*z2; + output = (sample_type) (z0*b0 + z1*b1 + z2*b2); + z2 = z1; z1 = z0") ) diff --git a/lib-src/libnyquist/nyquist/tran/biquadfilt.c b/lib-src/libnyquist/nyquist/tran/biquadfilt.c index c5e81da62..5656f6ec5 100644 --- a/lib-src/libnyquist/nyquist/tran/biquadfilt.c +++ b/lib-src/libnyquist/nyquist/tran/biquadfilt.c @@ -9,7 +9,7 @@ #include "cext.h" #include "biquadfilt.h" -void biquadfilt_free(); +void biquadfilt_free(snd_susp_type a_susp); typedef struct biquadfilt_susp_struct { @@ -30,8 +30,9 @@ typedef struct biquadfilt_susp_struct { } biquadfilt_susp_node, *biquadfilt_susp_type; -void biquadfilt_n_fetch(register biquadfilt_susp_type susp, snd_list_type snd_list) +void biquadfilt_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + biquadfilt_susp_type susp = (biquadfilt_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -65,6 +66,7 @@ void biquadfilt_n_fetch(register biquadfilt_susp_type susp, snd_list_type snd_li if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -76,6 +78,7 @@ void biquadfilt_n_fetch(register biquadfilt_susp_type susp, snd_list_type snd_li * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -104,9 +107,9 @@ void biquadfilt_n_fetch(register biquadfilt_susp_type susp, snd_list_type snd_li s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double z0; z0 = *s_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; - *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); - z2_reg = z1_reg; z1_reg = z0;; + double z0; z0 = *s_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; + *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); + z2_reg = z1_reg; z1_reg = z0; } while (--n); /* inner loop */ susp->z1 = z1_reg; @@ -134,116 +137,9 @@ double z0; z0 = *s_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; } /* biquadfilt_n_fetch */ -void biquadfilt_s_fetch(register biquadfilt_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double z1_reg; - register double z2_reg; - register double b0_reg; - register double b1_reg; - register double b2_reg; - register double a1_reg; - register double a2_reg; - register sample_type s_scale_reg = susp->s->scale; - register sample_block_values_type s_ptr_reg; - falloc_sample_block(out, "biquadfilt_s_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s input sample block: */ - susp_check_term_log_samples(s, s_ptr, s_cnt); - togo = min(togo, susp->s_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - z1_reg = susp->z1; - z2_reg = susp->z2; - b0_reg = susp->b0; - b1_reg = susp->b1; - b2_reg = susp->b2; - a1_reg = susp->a1; - a2_reg = susp->a2; - s_ptr_reg = susp->s_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ -double z0; z0 = (s_scale_reg * *s_ptr_reg++) + a1_reg*z1_reg + a2_reg*z2_reg; - *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); - z2_reg = z1_reg; z1_reg = z0;; - } while (--n); /* inner loop */ - - susp->z1 = z1_reg; - susp->z2 = z2_reg; - /* using s_ptr_reg is a bad idea on RS/6000: */ - susp->s_ptr += togo; - out_ptr += togo; - susp_took(s_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* biquadfilt_s_fetch */ - - -void biquadfilt_toss_fetch(susp, snd_list) - register biquadfilt_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void biquadfilt_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + biquadfilt_susp_type susp = (biquadfilt_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -258,25 +154,28 @@ void biquadfilt_toss_fetch(susp, snd_list) susp->s_ptr += n; susp_took(s_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void biquadfilt_mark(biquadfilt_susp_type susp) +void biquadfilt_mark(snd_susp_type a_susp) { + biquadfilt_susp_type susp = (biquadfilt_susp_type) a_susp; sound_xlmark(susp->s); } -void biquadfilt_free(biquadfilt_susp_type susp) +void biquadfilt_free(snd_susp_type a_susp) { + biquadfilt_susp_type susp = (biquadfilt_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(biquadfilt_susp_node), "biquadfilt_free"); } -void biquadfilt_print_tree(biquadfilt_susp_type susp, int n) +void biquadfilt_print_tree(snd_susp_type a_susp, int n) { + biquadfilt_susp_type susp = (biquadfilt_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); @@ -288,9 +187,15 @@ sound_type snd_make_biquadfilt(sound_type s, double b0, double b1, double b2, do register biquadfilt_susp_type susp; rate_type sr = s->sr; time_type t0 = s->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + /* combine scale factors of linear inputs (S) */ + scale_factor *= s->scale; + s->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (s->sr < sr) { s->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, biquadfilt_susp_node, "snd_make_biquadfilt"); susp->z1 = z1init; susp->z2 = z2init; @@ -299,15 +204,7 @@ sound_type snd_make_biquadfilt(sound_type s, double b0, double b1, double b2, do susp->b2 = b2; susp->a1 = a1; susp->a2 = a2; - - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(s, sr); - switch (interp_desc) { - case INTERP_n: susp->susp.fetch = biquadfilt_n_fetch; break; - case INTERP_s: susp->susp.fetch = biquadfilt_s_fetch; break; - default: snd_badsr(); break; - } - + susp->susp.fetch = biquadfilt_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s->t0) sound_prepend_zeros(s, t0); @@ -316,8 +213,8 @@ sound_type snd_make_biquadfilt(sound_type s, double b0, double b1, double b2, do /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = biquadfilt_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = biquadfilt_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/buzz.alg b/lib-src/libnyquist/nyquist/tran/buzz.alg index 1bbf108f5..29bb17d7c 100644 --- a/lib-src/libnyquist/nyquist/tran/buzz.alg +++ b/lib-src/libnyquist/nyquist/tran/buzz.alg @@ -18,16 +18,13 @@ : (sample_type) (SINE_TABLE_LEN * 0.5 / sr)")) ;cancel 0/0 (ALWAYS-SCALE s_fm) -(INLINE-INTERPOLATION T) ; so that modulation can be low frequency (STEP-FUNCTION s_fm) (TERMINATE (MIN s_fm)) (LOGICAL-STOP (MIN s_fm)) -(INNER-LOOP-LOCALS " long table_index; +(INNER-LOOP-LOCALS " long table_index; double x1; - sample_type num, denom, samp; -") -(INNER-LOOP " - table_index = (long) phase; + sample_type num, denom, samp;\n") +(INNER-LOOP "table_index = (long) phase; x1 = sine_table[table_index]; denom = (sample_type) (x1 + (phase - table_index) * (sine_table[table_index + 1] - x1)); @@ -48,7 +45,6 @@ /* watch out for negative frequencies! */ while (phase < 0) phase += SINE_TABLE_LEN") (CONSTANT "ph_incr" "n_2_p1" "n_2_r") - (SAMPLE-RATE "sr") ) diff --git a/lib-src/libnyquist/nyquist/tran/buzz.c b/lib-src/libnyquist/nyquist/tran/buzz.c index 561981179..3273305f3 100644 --- a/lib-src/libnyquist/nyquist/tran/buzz.c +++ b/lib-src/libnyquist/nyquist/tran/buzz.c @@ -9,7 +9,7 @@ #include "cext.h" #include "buzz.h" -void buzz_free(); +void buzz_free(snd_susp_type a_susp); typedef struct buzz_susp_struct { @@ -40,8 +40,9 @@ typedef struct buzz_susp_struct { #include "sine.h" -void buzz_s_fetch(register buzz_susp_type susp, snd_list_type snd_list) +void buzz_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + buzz_susp_type susp = (buzz_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -73,6 +74,7 @@ void buzz_s_fetch(register buzz_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -84,6 +86,7 @@ void buzz_s_fetch(register buzz_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -109,10 +112,9 @@ void buzz_s_fetch(register buzz_susp_type susp, snd_list_type snd_list) s_fm_ptr_reg = susp->s_fm_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; sample_type num, denom, samp; - table_index = (long) phase_reg; x1 = sine_table[table_index]; denom = (sample_type) (x1 + (phase_reg - table_index) * @@ -159,8 +161,9 @@ void buzz_s_fetch(register buzz_susp_type susp, snd_list_type snd_list) } /* buzz_s_fetch */ -void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) +void buzz_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + buzz_susp_type susp = (buzz_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -196,6 +199,7 @@ void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -207,6 +211,7 @@ void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -233,7 +238,7 @@ void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) s_fm_x1_sample_reg = susp->s_fm_x1_sample; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; sample_type num, denom, samp; if (s_fm_pHaSe_ReG >= 1.0) { @@ -245,7 +250,6 @@ void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) susp_check_term_log_samples_break(s_fm, s_fm_ptr, s_fm_cnt, s_fm_x1_sample_reg); s_fm_x1_sample_reg = susp_current_sample(s_fm, s_fm_ptr); } - table_index = (long) phase_reg; x1 = sine_table[table_index]; denom = (sample_type) (x1 + (phase_reg - table_index) * @@ -293,8 +297,9 @@ void buzz_i_fetch(register buzz_susp_type susp, snd_list_type snd_list) } /* buzz_i_fetch */ -void buzz_r_fetch(register buzz_susp_type susp, snd_list_type snd_list) +void buzz_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + buzz_susp_type susp = (buzz_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type s_fm_val; int togo; @@ -341,6 +346,7 @@ void buzz_r_fetch(register buzz_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -352,6 +358,7 @@ void buzz_r_fetch(register buzz_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -376,10 +383,9 @@ void buzz_r_fetch(register buzz_susp_type susp, snd_list_type snd_list) phase_reg = susp->phase; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; sample_type num, denom, samp; - table_index = (long) phase_reg; x1 = sine_table[table_index]; denom = (sample_type) (x1 + (phase_reg - table_index) * @@ -425,11 +431,9 @@ void buzz_r_fetch(register buzz_susp_type susp, snd_list_type snd_list) } /* buzz_r_fetch */ -void buzz_toss_fetch(susp, snd_list) - register buzz_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void buzz_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + buzz_susp_type susp = (buzz_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -444,25 +448,28 @@ void buzz_toss_fetch(susp, snd_list) susp->s_fm_ptr += n; susp_took(s_fm_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void buzz_mark(buzz_susp_type susp) +void buzz_mark(snd_susp_type a_susp) { + buzz_susp_type susp = (buzz_susp_type) a_susp; sound_xlmark(susp->s_fm); } -void buzz_free(buzz_susp_type susp) +void buzz_free(snd_susp_type a_susp) { + buzz_susp_type susp = (buzz_susp_type) a_susp; sound_unref(susp->s_fm); ffree_generic(susp, sizeof(buzz_susp_node), "buzz_free"); } -void buzz_print_tree(buzz_susp_type susp, int n) +void buzz_print_tree(snd_susp_type a_susp, int n) { + buzz_susp_type susp = (buzz_susp_type) a_susp; indent(n); stdputstr("s_fm:"); sound_print_tree_1(susp->s_fm, n); @@ -486,6 +493,12 @@ sound_type snd_make_buzz(long n, rate_type sr, double hz, time_type t0, sound_ty s_fm->scale *= hz != 0 ? (sample_type) (susp->ph_incr / hz) : (sample_type) (SINE_TABLE_LEN * 0.5 / sr); + /* make sure no sample rate is too high */ + if (s_fm->sr > sr) { + sound_unref(s_fm); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s_fm, sr); switch (interp_desc) { @@ -504,8 +517,8 @@ sound_type snd_make_buzz(long n, rate_type sr, double hz, time_type t0, sound_ty /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = buzz_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = buzz_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/chase.alg b/lib-src/libnyquist/nyquist/tran/chase.alg index dd4b0c1f7..701e80569 100644 --- a/lib-src/libnyquist/nyquist/tran/chase.alg +++ b/lib-src/libnyquist/nyquist/tran/chase.alg @@ -1,19 +1,20 @@ (CHASE-ALG (NAME "chase") - (ARGUMENTS ("sound_type" "input") ("double" "risetime") ("double" "falltime")) + (ARGUMENTS ("sound_type" "input") ("double" "risetime") + ("double" "falltime")) (STATE ("double" "level" "0.0") - ("double" "upslope" "1.0/(input->sr * risetime)") - ("double" "downslope" "1.0/(input->sr * falltime)")) + ("double" "upslope" "1.0 / (input->sr * risetime)") + ("double" "downslope" "1.0 / (input->sr * falltime)")) (START (MIN input)) - (INNER-LOOP " double x = input; - if (x > level) { - level += upslope; - if (x < level) level = x; - } else { - level -= downslope; - if (x > level) level = x; - } - output = (sample_type) level;") + (INNER-LOOP "double x = input; + if (x > level) { + level += upslope; + if (x < level) level = x; + } else { + level -= downslope; + if (x > level) level = x; + } + output = (sample_type) level") (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) ) diff --git a/lib-src/libnyquist/nyquist/tran/chase.c b/lib-src/libnyquist/nyquist/tran/chase.c index 30d664a6a..53996bf4a 100644 --- a/lib-src/libnyquist/nyquist/tran/chase.c +++ b/lib-src/libnyquist/nyquist/tran/chase.c @@ -9,7 +9,7 @@ #include "cext.h" #include "chase.h" -void chase_free(); +void chase_free(snd_susp_type a_susp); typedef struct chase_susp_struct { @@ -26,8 +26,9 @@ typedef struct chase_susp_struct { } chase_susp_node, *chase_susp_type; -void chase_n_fetch(register chase_susp_type susp, snd_list_type snd_list) +void chase_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + chase_susp_type susp = (chase_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -57,6 +58,7 @@ void chase_n_fetch(register chase_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -68,6 +70,7 @@ void chase_n_fetch(register chase_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -92,15 +95,15 @@ void chase_n_fetch(register chase_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double x = *input_ptr_reg++; - if (x > level_reg) { - level_reg += upslope_reg; - if (x < level_reg) level_reg = x; - } else { - level_reg -= downslope_reg; - if (x > level_reg) level_reg = x; - } - *out_ptr_reg++ = (sample_type) level_reg;; + double x = *input_ptr_reg++; + if (x > level_reg) { + level_reg += upslope_reg; + if (x < level_reg) level_reg = x; + } else { + level_reg -= downslope_reg; + if (x > level_reg) level_reg = x; + } + *out_ptr_reg++ = (sample_type) level_reg; } while (--n); /* inner loop */ susp->level = level_reg; @@ -129,8 +132,9 @@ void chase_n_fetch(register chase_susp_type susp, snd_list_type snd_list) } /* chase_n_fetch */ -void chase_s_fetch(register chase_susp_type susp, snd_list_type snd_list) +void chase_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + chase_susp_type susp = (chase_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -161,6 +165,7 @@ void chase_s_fetch(register chase_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -172,6 +177,7 @@ void chase_s_fetch(register chase_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -196,15 +202,15 @@ void chase_s_fetch(register chase_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double x = (input_scale_reg * *input_ptr_reg++); - if (x > level_reg) { - level_reg += upslope_reg; - if (x < level_reg) level_reg = x; - } else { - level_reg -= downslope_reg; - if (x > level_reg) level_reg = x; - } - *out_ptr_reg++ = (sample_type) level_reg;; + double x = (input_scale_reg * *input_ptr_reg++); + if (x > level_reg) { + level_reg += upslope_reg; + if (x < level_reg) level_reg = x; + } else { + level_reg -= downslope_reg; + if (x > level_reg) level_reg = x; + } + *out_ptr_reg++ = (sample_type) level_reg; } while (--n); /* inner loop */ susp->level = level_reg; @@ -233,11 +239,9 @@ void chase_s_fetch(register chase_susp_type susp, snd_list_type snd_list) } /* chase_s_fetch */ -void chase_toss_fetch(susp, snd_list) - register chase_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void chase_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + chase_susp_type susp = (chase_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -252,25 +256,28 @@ void chase_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void chase_mark(chase_susp_type susp) +void chase_mark(snd_susp_type a_susp) { + chase_susp_type susp = (chase_susp_type) a_susp; sound_xlmark(susp->input); } -void chase_free(chase_susp_type susp) +void chase_free(snd_susp_type a_susp) { + chase_susp_type susp = (chase_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(chase_susp_node), "chase_free"); } -void chase_print_tree(chase_susp_type susp, int n) +void chase_print_tree(snd_susp_type a_susp, int n) { + chase_susp_type susp = (chase_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -287,8 +294,8 @@ sound_type snd_make_chase(sound_type input, double risetime, double falltime) time_type t0_min = t0; falloc_generic(susp, chase_susp_node, "snd_make_chase"); susp->level = 0.0; - susp->upslope = 1.0/(input->sr * risetime); - susp->downslope = 1.0/(input->sr * falltime); + susp->upslope = 1.0 / (input->sr * risetime); + susp->downslope = 1.0 / (input->sr * falltime); /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); @@ -306,8 +313,8 @@ sound_type snd_make_chase(sound_type input, double risetime, double falltime) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = chase_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = chase_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/clip.alg b/lib-src/libnyquist/nyquist/tran/clip.alg index 1bf56fe57..807a355d2 100644 --- a/lib-src/libnyquist/nyquist/tran/clip.alg +++ b/lib-src/libnyquist/nyquist/tran/clip.alg @@ -3,7 +3,10 @@ (ARGUMENTS ("sound_type" "s") ("double" "level")) (STATE ("sample_type" "level" "(sample_type) level")) (START (MIN s)) - (INNER-LOOP "double x = s; output = (sample_type) (x > level ? level : (x < -level ? -level : x))") + (INNER-LOOP "double x = s; + output = (sample_type) + (x > level ? + level : (x < -level ? -level : x))") (TERMINATE (MIN s)) (LOGICAL-STOP (MIN s)) ) diff --git a/lib-src/libnyquist/nyquist/tran/clip.c b/lib-src/libnyquist/nyquist/tran/clip.c index e6a5bec9e..1d5067b79 100644 --- a/lib-src/libnyquist/nyquist/tran/clip.c +++ b/lib-src/libnyquist/nyquist/tran/clip.c @@ -9,7 +9,7 @@ #include "cext.h" #include "clip.h" -void clip_free(); +void clip_free(snd_susp_type a_susp); typedef struct clip_susp_struct { @@ -24,8 +24,9 @@ typedef struct clip_susp_struct { } clip_susp_node, *clip_susp_type; -void clip_n_fetch(register clip_susp_type susp, snd_list_type snd_list) +void clip_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + clip_susp_type susp = (clip_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void clip_n_fetch(register clip_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void clip_n_fetch(register clip_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,10 @@ void clip_n_fetch(register clip_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double x = *s_ptr_reg++; *out_ptr_reg++ = (sample_type) (x > level_reg ? level_reg : (x < -level_reg ? -level_reg : x)); + double x = *s_ptr_reg++; + *out_ptr_reg++ = (sample_type) + (x > level_reg ? + level_reg : (x < -level_reg ? -level_reg : x)); } while (--n); /* inner loop */ susp->level = level_reg; @@ -113,8 +119,9 @@ double x = *s_ptr_reg++; *out_ptr_reg++ = (sample_type) (x > level_reg ? level_r } /* clip_n_fetch */ -void clip_s_fetch(register clip_susp_type susp, snd_list_type snd_list) +void clip_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + clip_susp_type susp = (clip_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -143,6 +150,7 @@ void clip_s_fetch(register clip_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -154,6 +162,7 @@ void clip_s_fetch(register clip_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -176,7 +185,10 @@ void clip_s_fetch(register clip_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double x = (s_scale_reg * *s_ptr_reg++); *out_ptr_reg++ = (sample_type) (x > level_reg ? level_reg : (x < -level_reg ? -level_reg : x)); + double x = (s_scale_reg * *s_ptr_reg++); + *out_ptr_reg++ = (sample_type) + (x > level_reg ? + level_reg : (x < -level_reg ? -level_reg : x)); } while (--n); /* inner loop */ susp->level = level_reg; @@ -203,11 +215,9 @@ double x = (s_scale_reg * *s_ptr_reg++); *out_ptr_reg++ = (sample_type) (x > lev } /* clip_s_fetch */ -void clip_toss_fetch(susp, snd_list) - register clip_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void clip_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + clip_susp_type susp = (clip_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -222,25 +232,28 @@ void clip_toss_fetch(susp, snd_list) susp->s_ptr += n; susp_took(s_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void clip_mark(clip_susp_type susp) +void clip_mark(snd_susp_type a_susp) { + clip_susp_type susp = (clip_susp_type) a_susp; sound_xlmark(susp->s); } -void clip_free(clip_susp_type susp) +void clip_free(snd_susp_type a_susp) { + clip_susp_type susp = (clip_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(clip_susp_node), "clip_free"); } -void clip_print_tree(clip_susp_type susp, int n) +void clip_print_tree(snd_susp_type a_susp, int n) { + clip_susp_type susp = (clip_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); @@ -274,8 +287,8 @@ sound_type snd_make_clip(sound_type s, double level) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = clip_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = clip_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/congen.alg b/lib-src/libnyquist/nyquist/tran/congen.alg index 9ff02d2e9..d437b9845 100644 --- a/lib-src/libnyquist/nyquist/tran/congen.alg +++ b/lib-src/libnyquist/nyquist/tran/congen.alg @@ -6,12 +6,12 @@ ("double" "rise_factor" "exp(log(0.5) / (sndin->sr * risetime))") ("double" "fall_factor" "exp(log(0.5) / (sndin->sr * falltime))")) (CONSTANT "fall_factor" "rise_factor") -(ALWAYS-SCALE sndin) (TERMINATE (MIN sndin)) -(INNER-LOOP " sample_type current = sndin; - if (current > value) { - value = current - (current - value) * rise_factor; - } else { - value = current - (current - value) * fall_factor; - } - output = (sample_type) value;")) +(INNER-LOOP "sample_type current = sndin; + if (current > value) { + value = current - (current - value) * rise_factor; + } else { + value = current - (current - value) * fall_factor; + } + output = (sample_type) value") +) diff --git a/lib-src/libnyquist/nyquist/tran/congen.c b/lib-src/libnyquist/nyquist/tran/congen.c index ed074c770..cdd22b7c5 100644 --- a/lib-src/libnyquist/nyquist/tran/congen.c +++ b/lib-src/libnyquist/nyquist/tran/congen.c @@ -9,7 +9,7 @@ #include "cext.h" #include "congen.h" -void congen_free(); +void congen_free(snd_susp_type a_susp); typedef struct congen_susp_struct { @@ -25,8 +25,79 @@ typedef struct congen_susp_struct { } congen_susp_node, *congen_susp_type; -void congen_s_fetch(register congen_susp_type susp, snd_list_type snd_list) +void congen_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + congen_susp_type susp = (congen_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double value_reg; + register double rise_factor_reg; + register double fall_factor_reg; + register sample_block_values_type sndin_ptr_reg; + falloc_sample_block(out, "congen_n_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the sndin input sample block: */ + susp_check_term_samples(sndin, sndin_ptr, sndin_cnt); + togo = min(togo, susp->sndin_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + value_reg = susp->value; + rise_factor_reg = susp->rise_factor; + fall_factor_reg = susp->fall_factor; + sndin_ptr_reg = susp->sndin_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + sample_type current = *sndin_ptr_reg++; + if (current > value_reg) { + value_reg = current - (current - value_reg) * rise_factor_reg; + } else { + value_reg = current - (current - value_reg) * fall_factor_reg; + } + *out_ptr_reg++ = (sample_type) value_reg; + } while (--n); /* inner loop */ + + susp->value = value_reg; + /* using sndin_ptr_reg is a bad idea on RS/6000: */ + susp->sndin_ptr += togo; + out_ptr += togo; + susp_took(sndin_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* congen_n_fetch */ + + +void congen_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + congen_susp_type susp = (congen_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -57,6 +128,7 @@ void congen_s_fetch(register congen_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -67,13 +139,13 @@ void congen_s_fetch(register congen_susp_type susp, snd_list_type snd_list) sndin_ptr_reg = susp->sndin_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - sample_type current = (sndin_scale_reg * *sndin_ptr_reg++); - if (current > value_reg) { - value_reg = current - (current - value_reg) * rise_factor_reg; - } else { - value_reg = current - (current - value_reg) * fall_factor_reg; - } - *out_ptr_reg++ = (sample_type) value_reg;; + sample_type current = (sndin_scale_reg * *sndin_ptr_reg++); + if (current > value_reg) { + value_reg = current - (current - value_reg) * rise_factor_reg; + } else { + value_reg = current - (current - value_reg) * fall_factor_reg; + } + *out_ptr_reg++ = (sample_type) value_reg; } while (--n); /* inner loop */ susp->value = value_reg; @@ -94,11 +166,9 @@ void congen_s_fetch(register congen_susp_type susp, snd_list_type snd_list) } /* congen_s_fetch */ -void congen_toss_fetch(susp, snd_list) - register congen_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void congen_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + congen_susp_type susp = (congen_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -113,25 +183,28 @@ void congen_toss_fetch(susp, snd_list) susp->sndin_ptr += n; susp_took(sndin_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void congen_mark(congen_susp_type susp) +void congen_mark(snd_susp_type a_susp) { + congen_susp_type susp = (congen_susp_type) a_susp; sound_xlmark(susp->sndin); } -void congen_free(congen_susp_type susp) +void congen_free(snd_susp_type a_susp) { + congen_susp_type susp = (congen_susp_type) a_susp; sound_unref(susp->sndin); ffree_generic(susp, sizeof(congen_susp_node), "congen_free"); } -void congen_print_tree(congen_susp_type susp, int n) +void congen_print_tree(snd_susp_type a_susp, int n) { + congen_susp_type susp = (congen_susp_type) a_susp; indent(n); stdputstr("sndin:"); sound_print_tree_1(susp->sndin, n); @@ -150,7 +223,15 @@ sound_type snd_make_congen(sound_type sndin, double risetime, double falltime) susp->value = 0; susp->rise_factor = exp(log(0.5) / (sndin->sr * risetime)); susp->fall_factor = exp(log(0.5) / (sndin->sr * falltime)); - susp->susp.fetch = congen_s_fetch; + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(sndin, sr); + switch (interp_desc) { + case INTERP_n: susp->susp.fetch = congen_n_fetch; break; + case INTERP_s: susp->susp.fetch = congen_s_fetch; break; + default: snd_badsr(); break; + } + susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < sndin->t0) sound_prepend_zeros(sndin, t0); @@ -159,8 +240,8 @@ sound_type snd_make_congen(sound_type sndin, double risetime, double falltime) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = congen_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = congen_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/const.c b/lib-src/libnyquist/nyquist/tran/const.c index 042cd5297..c85a2793e 100644 --- a/lib-src/libnyquist/nyquist/tran/const.c +++ b/lib-src/libnyquist/nyquist/tran/const.c @@ -9,7 +9,7 @@ #include "cext.h" #include "const.h" -void const_free(); +void const_free(snd_susp_type a_susp); typedef struct const_susp_struct { @@ -20,8 +20,9 @@ typedef struct const_susp_struct { } const_susp_node, *const_susp_type; -void const__fetch(register const_susp_type susp, snd_list_type snd_list) +void const__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + const_susp_type susp = (const_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -44,6 +45,7 @@ void const__fetch(register const_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -51,7 +53,7 @@ void const__fetch(register const_susp_type susp, snd_list_type snd_list) c_reg = susp->c; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = c_reg; + *out_ptr_reg++ = c_reg; } while (--n); /* inner loop */ out_ptr += togo; @@ -68,13 +70,14 @@ void const__fetch(register const_susp_type susp, snd_list_type snd_list) } /* const__fetch */ -void const_free(const_susp_type susp) +void const_free(snd_susp_type a_susp) { + const_susp_type susp = (const_susp_type) a_susp; ffree_generic(susp, sizeof(const_susp_node), "const_free"); } -void const_print_tree(const_susp_type susp, int n) +void const_print_tree(snd_susp_type a_susp, int n) { } @@ -89,7 +92,7 @@ sound_type snd_make_const(double c, time_type t0, rate_type sr, time_type d) susp->c = (sample_type) c; susp->susp.fetch = const__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = const_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/convolve.alg b/lib-src/libnyquist/nyquist/tran/convolve.alg index 94107b467..79c40b7a2 100644 --- a/lib-src/libnyquist/nyquist/tran/convolve.alg +++ b/lib-src/libnyquist/nyquist/tran/convolve.alg @@ -33,31 +33,28 @@ void h_reverse(sample_type *h, long len) (TERMINATE (MIN x_snd)) (LOGICAL-STOP (MIN x_snd)) (INNER-LOOP-LOCALS - "long i; double sum;") -(INNER-LOOP " - /* see if we've reached end of x_buffer */ - if ((x_buffer_pointer + x_buf_len) <= (x_buffer_current + h_len)) { - /* shift x_buffer from current back to base */ - for (i = 1; i < h_len; i++) { - x_buffer_pointer[i-1] = x_buffer_current[i]; - } - /* this will be incremented back to x_buffer_pointer below */ - x_buffer_current = x_buffer_pointer - 1; - } - - x_buffer_current++; - - x_buffer_current[h_len - 1] = x_snd; - - sum = 0.0; - for (i = 0; i < h_len; i++) { - sum += x_buffer_current[i] * h_buf[i]; - } - - output = (sample_type) sum; -") + " long i; double sum;") +(INNER-LOOP "/* see if we've reached end of x_buffer */ + if ((x_buffer_pointer + x_buf_len) <= (x_buffer_current + h_len)) { + /* shift x_buffer from current back to base */ + for (i = 1; i < h_len; i++) { + x_buffer_pointer[i-1] = x_buffer_current[i]; + } + /* this will be incremented back to x_buffer_pointer below */ + x_buffer_current = x_buffer_pointer - 1; + } + + x_buffer_current++; + + x_buffer_current[h_len - 1] = x_snd; + + sum = 0.0; + for (i = 0; i < h_len; i++) { + sum += x_buffer_current[i] * h_buf[i]; + } + output = (sample_type) sum") (CONSTANT "h_buf" "h_len" "x_buf_len" "table") (SAMPLE-RATE "x_snd->sr") (FINALIZATION " table_unref(susp->table); - free(susp->x_buffer_pointer);") + free(susp->x_buffer_pointer);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/coterm.alg b/lib-src/libnyquist/nyquist/tran/coterm.alg index 84bce1da7..2855fa53d 100644 --- a/lib-src/libnyquist/nyquist/tran/coterm.alg +++ b/lib-src/libnyquist/nyquist/tran/coterm.alg @@ -1,6 +1,7 @@ (COTERM-ALG (NAME "coterm") (ARGUMENTS ("sound_type" "s1") ("sound_type" "s2")) + (SAMPLE-RATE (MAX s1)) (START (MAX s1 s2)) (INNER-LOOP "{sample_type dummy = s2; output = s1;}") (LINEAR s1) diff --git a/lib-src/libnyquist/nyquist/tran/coterm.c b/lib-src/libnyquist/nyquist/tran/coterm.c index dfc4a1d95..d70b1b49c 100644 --- a/lib-src/libnyquist/nyquist/tran/coterm.c +++ b/lib-src/libnyquist/nyquist/tran/coterm.c @@ -9,11 +9,12 @@ #include "cext.h" #include "coterm.h" -void coterm_free(); +void coterm_free(snd_susp_type a_susp); typedef struct coterm_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; boolean logically_stopped; sound_type s1; @@ -22,11 +23,21 @@ typedef struct coterm_susp_struct { sound_type s2; long s2_cnt; sample_block_values_type s2_ptr; + + /* support for interpolation of s2 */ + sample_type s2_x1_sample; + double s2_pHaSe; + double s2_pHaSe_iNcR; + + /* support for ramp between samples of s2 */ + double output_per_s2; + long s2_n; } coterm_susp_node, *coterm_susp_type; -void coterm_nn_fetch(register coterm_susp_type susp, snd_list_type snd_list) +void coterm_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + coterm_susp_type susp = (coterm_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -58,6 +69,7 @@ void coterm_nn_fetch(register coterm_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -69,6 +81,7 @@ void coterm_nn_fetch(register coterm_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -91,7 +104,7 @@ void coterm_nn_fetch(register coterm_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{sample_type dummy = *s2_ptr_reg++; *out_ptr_reg++ = *s1_ptr_reg++;}; + {sample_type dummy = *s2_ptr_reg++; *out_ptr_reg++ = *s1_ptr_reg++;}; } while (--n); /* inner loop */ /* using s2_ptr_reg is a bad idea on RS/6000: */ @@ -120,11 +133,249 @@ void coterm_nn_fetch(register coterm_susp_type susp, snd_list_type snd_list) } /* coterm_nn_fetch */ -void coterm_toss_fetch(susp, snd_list) - register coterm_susp_type susp; - snd_list_type snd_list; +void coterm_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + coterm_susp_type susp = (coterm_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double s2_pHaSe_iNcR_rEg = susp->s2_pHaSe_iNcR; + register double s2_pHaSe_ReG; + register sample_type s2_x1_sample_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "coterm_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + susp->s2_x1_sample = (susp->s2_cnt--, *(susp->s2_ptr)); + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = *(susp->s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_pHaSe_ReG = susp->s2_pHaSe; + s2_x1_sample_reg = susp->s2_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s2_pHaSe_ReG >= 1.0) { + s2_x1_sample_reg = s2_x2_sample; + /* pick up next sample as s2_x2_sample: */ + susp->s2_ptr++; + susp_took(s2_cnt, 1); + s2_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(s2, s2_ptr, s2_cnt, s2_x2_sample); + } + {sample_type dummy = + (s2_x1_sample_reg * (1 - s2_pHaSe_ReG) + s2_x2_sample * s2_pHaSe_ReG); *out_ptr_reg++ = *s1_ptr_reg++;}; + s2_pHaSe_ReG += s2_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->s2_pHaSe = s2_pHaSe_ReG; + susp->s2_x1_sample = s2_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* coterm_ni_fetch */ + + +void coterm_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + coterm_susp_type susp = (coterm_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_DeLtA; + sample_type s2_val; + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "coterm_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s2_pHaSe = 1.0; + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = *(susp->s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next s2_x2_sample when phase goes past 1.0; */ + /* we use s2_n (computed below) to avoid roundoff errors: */ + if (susp->s2_n <= 0) { + susp->s2_x1_sample = s2_x2_sample; + susp->s2_ptr++; + susp_took(s2_cnt, 1); + susp->s2_pHaSe -= 1.0; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = *(susp->s2_ptr); + /* s2_n gets number of samples before phase exceeds 1.0: */ + susp->s2_n = (long) ((1.0 - susp->s2_pHaSe) * + susp->output_per_s2); + } + togo = min(togo, susp->s2_n); + s2_DeLtA = (sample_type) ((s2_x2_sample - susp->s2_x1_sample) * susp->s2_pHaSe_iNcR); + s2_val = (sample_type) (susp->s2_x1_sample * (1.0 - susp->s2_pHaSe) + + s2_x2_sample * susp->s2_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + {sample_type dummy = s2_val; *out_ptr_reg++ = *s1_ptr_reg++;}; + s2_val += s2_DeLtA; + } while (--n); /* inner loop */ + + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->s2_pHaSe += togo * susp->s2_pHaSe_iNcR; + susp->s2_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* coterm_nr_fetch */ + + +void coterm_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + coterm_susp_type susp = (coterm_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -147,27 +398,30 @@ void coterm_toss_fetch(susp, snd_list) susp->s2_ptr += n; susp_took(s2_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void coterm_mark(coterm_susp_type susp) +void coterm_mark(snd_susp_type a_susp) { + coterm_susp_type susp = (coterm_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->s2); } -void coterm_free(coterm_susp_type susp) +void coterm_free(snd_susp_type a_susp) { + coterm_susp_type susp = (coterm_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->s2); ffree_generic(susp, sizeof(coterm_susp_node), "coterm_free"); } -void coterm_print_tree(coterm_susp_type susp, int n) +void coterm_print_tree(snd_susp_type a_susp, int n) { + coterm_susp_type susp = (coterm_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -181,7 +435,7 @@ void coterm_print_tree(coterm_susp_type susp, int n) sound_type snd_make_coterm(sound_type s1, sound_type s2) { register coterm_susp_type susp; - rate_type sr = max(s1->sr, s2->sr); + rate_type sr = s1->sr; time_type t0 = max(s1->t0, s2->t0); int interp_desc = 0; sample_type scale_factor = 1.0F; @@ -195,7 +449,24 @@ sound_type snd_make_coterm(sound_type s1, sound_type s2) if (s1->sr < sr) { s1->scale = scale_factor; scale_factor = 1.0F; } falloc_generic(susp, coterm_susp_node, "snd_make_coterm"); - susp->susp.fetch = coterm_nn_fetch; + + /* make sure no sample rate is too high */ + if (s2->sr > sr) { + sound_unref(s2); + snd_badsr(); + } + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(s1, sr); + interp_desc = (interp_desc << 2) + interp_style(s2, sr); + switch (interp_desc) { + case INTERP_ns: /* handled below */ + case INTERP_nn: susp->susp.fetch = coterm_nn_fetch; break; + case INTERP_ni: susp->susp.fetch = coterm_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = coterm_nr_fetch; break; + default: snd_badsr(); break; + } + susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -205,8 +476,8 @@ sound_type snd_make_coterm(sound_type s1, sound_type s2) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = coterm_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = coterm_toss_fetch; } /* initialize susp state */ @@ -221,11 +492,16 @@ sound_type snd_make_coterm(sound_type s1, sound_type s2) lsc = logical_stop_cnt_cvt(s2); if (susp->susp.log_stop_cnt > lsc) susp->susp.log_stop_cnt = lsc; + susp->started = false; susp->susp.current = 0; susp->s1 = s1; susp->s1_cnt = 0; susp->s2 = s2; susp->s2_cnt = 0; + susp->s2_pHaSe = 0.0; + susp->s2_pHaSe_iNcR = s2->sr / sr; + susp->s2_n = 0; + susp->output_per_s2 = sr / s2->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/delay.alg b/lib-src/libnyquist/nyquist/tran/delay.alg index 8e2d50272..3898bb808 100644 --- a/lib-src/libnyquist/nyquist/tran/delay.alg +++ b/lib-src/libnyquist/nyquist/tran/delay.alg @@ -13,8 +13,8 @@ (LINEAR input) (TERMINATE (MIN input)) (INNER-LOOP "output = *delayptr; - *delayptr = (sample_type) (*delayptr * feedback) + input; - if (++delayptr >= endptr) delayptr = susp->delaybuf;") -(FINALIZATION "free(susp->delaybuf);") + *delayptr = (sample_type) (*delayptr * feedback) + input; + if (++delayptr >= endptr) delayptr = susp->delaybuf") +(FINALIZATION "free(susp->delaybuf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/delaycc.alg b/lib-src/libnyquist/nyquist/tran/delaycc.alg index 8e2d50272..3898bb808 100644 --- a/lib-src/libnyquist/nyquist/tran/delaycc.alg +++ b/lib-src/libnyquist/nyquist/tran/delaycc.alg @@ -13,8 +13,8 @@ (LINEAR input) (TERMINATE (MIN input)) (INNER-LOOP "output = *delayptr; - *delayptr = (sample_type) (*delayptr * feedback) + input; - if (++delayptr >= endptr) delayptr = susp->delaybuf;") -(FINALIZATION "free(susp->delaybuf);") + *delayptr = (sample_type) (*delayptr * feedback) + input; + if (++delayptr >= endptr) delayptr = susp->delaybuf") +(FINALIZATION "free(susp->delaybuf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/delaycc.c b/lib-src/libnyquist/nyquist/tran/delaycc.c index 3584d89ad..b507b7d5f 100644 --- a/lib-src/libnyquist/nyquist/tran/delaycc.c +++ b/lib-src/libnyquist/nyquist/tran/delaycc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "delaycc.h" -void delay_free(); +void delay_free(snd_susp_type a_susp); typedef struct delay_susp_struct { @@ -27,8 +27,9 @@ typedef struct delay_susp_struct { } delay_susp_node, *delay_susp_type; -void delay_n_fetch(register delay_susp_type susp, snd_list_type snd_list) +void delay_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + delay_susp_type susp = (delay_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -58,6 +59,7 @@ void delay_n_fetch(register delay_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -68,9 +70,9 @@ void delay_n_fetch(register delay_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *delayptr_reg; - *delayptr_reg = (sample_type) (*delayptr_reg * feedback_reg) + *input_ptr_reg++; - if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = (sample_type) (*delayptr_reg * feedback_reg) + *input_ptr_reg++; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -91,11 +93,9 @@ void delay_n_fetch(register delay_susp_type susp, snd_list_type snd_list) } /* delay_n_fetch */ -void delay_toss_fetch(susp, snd_list) - register delay_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void delay_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + delay_susp_type susp = (delay_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -110,25 +110,29 @@ void delay_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void delay_mark(delay_susp_type susp) +void delay_mark(snd_susp_type a_susp) { + delay_susp_type susp = (delay_susp_type) a_susp; sound_xlmark(susp->input); } -void delay_free(delay_susp_type susp) +void delay_free(snd_susp_type a_susp) { -free(susp->delaybuf); sound_unref(susp->input); + delay_susp_type susp = (delay_susp_type) a_susp; +free(susp->delaybuf); + sound_unref(susp->input); ffree_generic(susp, sizeof(delay_susp_node), "delay_free"); } -void delay_print_tree(delay_susp_type susp, int n) +void delay_print_tree(snd_susp_type a_susp, int n) { + delay_susp_type susp = (delay_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -140,7 +144,6 @@ sound_type snd_make_delay(sound_type input, time_type delay, double feedback) register delay_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; /* combine scale factors of linear inputs (INPUT) */ @@ -165,8 +168,8 @@ sound_type snd_make_delay(sound_type input, time_type delay, double feedback) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = delay_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = delay_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/delaycv.alg b/lib-src/libnyquist/nyquist/tran/delaycv.alg index 5823dbd1f..01cc1bc28 100644 --- a/lib-src/libnyquist/nyquist/tran/delaycv.alg +++ b/lib-src/libnyquist/nyquist/tran/delaycv.alg @@ -12,8 +12,8 @@ (LINEAR s) (TERMINATE (MIN s)) (INNER-LOOP "output = *delayptr; - *delayptr = *delayptr * feedback + s; - if (++delayptr >= endptr) delayptr = susp->delaybuf;") -(FINALIZATION "free(susp->delaybuf);") + *delayptr = *delayptr * feedback + s; + if (++delayptr >= endptr) delayptr = susp->delaybuf") +(FINALIZATION "free(susp->delaybuf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/delaycv.c b/lib-src/libnyquist/nyquist/tran/delaycv.c index 984e88de4..f4aa3d55c 100644 --- a/lib-src/libnyquist/nyquist/tran/delaycv.c +++ b/lib-src/libnyquist/nyquist/tran/delaycv.c @@ -9,19 +9,38 @@ #include "cext.h" #include "delaycv.h" -void delaycv_free(); +void delaycv_free(snd_susp_type a_susp); typedef struct delaycv_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; sound_type s; long s_cnt; sample_block_values_type s_ptr; + + /* support for interpolation of s */ + sample_type s_x1_sample; + double s_pHaSe; + double s_pHaSe_iNcR; + + /* support for ramp between samples of s */ + double output_per_s; + long s_n; sound_type feedback; long feedback_cnt; sample_block_values_type feedback_ptr; + /* support for interpolation of feedback */ + sample_type feedback_x1_sample; + double feedback_pHaSe; + double feedback_pHaSe_iNcR; + + /* support for ramp between samples of feedback */ + double output_per_feedback; + long feedback_n; + long delaylen; sample_type *delaybuf; sample_type *delayptr; @@ -29,8 +48,9 @@ typedef struct delaycv_susp_struct { } delaycv_susp_node, *delaycv_susp_type; -void delaycv_nn_fetch(register delaycv_susp_type susp, snd_list_type snd_list) +void delaycv_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + delaycv_susp_type susp = (delaycv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -64,6 +84,7 @@ void delaycv_nn_fetch(register delaycv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -74,9 +95,9 @@ void delaycv_nn_fetch(register delaycv_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *delayptr_reg; - *delayptr_reg = *delayptr_reg * *feedback_ptr_reg++ + *s_ptr_reg++; - if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * *feedback_ptr_reg++ + *s_ptr_reg++; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -101,8 +122,9 @@ void delaycv_nn_fetch(register delaycv_susp_type susp, snd_list_type snd_list) } /* delaycv_nn_fetch */ -void delaycv_ns_fetch(register delaycv_susp_type susp, snd_list_type snd_list) +void delaycv_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + delaycv_susp_type susp = (delaycv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -137,6 +159,7 @@ void delaycv_ns_fetch(register delaycv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -147,9 +170,9 @@ void delaycv_ns_fetch(register delaycv_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *delayptr_reg; - *delayptr_reg = *delayptr_reg * (feedback_scale_reg * *feedback_ptr_reg++) + *s_ptr_reg++; - if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf;; + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * (feedback_scale_reg * *feedback_ptr_reg++) + *s_ptr_reg++; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; } while (--n); /* inner loop */ susp->delayptr = delayptr_reg; @@ -174,11 +197,587 @@ void delaycv_ns_fetch(register delaycv_susp_type susp, snd_list_type snd_list) } /* delaycv_ns_fetch */ -void delaycv_toss_fetch(susp, snd_list) - register delaycv_susp_type susp; - snd_list_type snd_list; +void delaycv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register double feedback_pHaSe_iNcR_rEg = susp->feedback_pHaSe_iNcR; + register double feedback_pHaSe_ReG; + register sample_type feedback_x1_sample_reg; + register sample_block_values_type s_ptr_reg; + falloc_sample_block(out, "delaycv_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + susp->feedback_x1_sample = susp_fetch_sample(feedback, feedback_ptr, feedback_cnt); + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s input sample block: */ + susp_check_term_samples(s, s_ptr, s_cnt); + togo = min(togo, susp->s_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_pHaSe_ReG = susp->feedback_pHaSe; + feedback_x1_sample_reg = susp->feedback_x1_sample; + s_ptr_reg = susp->s_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (feedback_pHaSe_ReG >= 1.0) { + feedback_x1_sample_reg = feedback_x2_sample; + /* pick up next sample as feedback_x2_sample: */ + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + feedback_pHaSe_ReG -= 1.0; + susp_check_samples_break(feedback, feedback_ptr, feedback_cnt, feedback_x2_sample); + } + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * + (feedback_x1_sample_reg * (1 - feedback_pHaSe_ReG) + feedback_x2_sample * feedback_pHaSe_ReG) + *s_ptr_reg++; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + feedback_pHaSe_ReG += feedback_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + susp->feedback_pHaSe = feedback_pHaSe_ReG; + susp->feedback_x1_sample = feedback_x1_sample_reg; + /* using s_ptr_reg is a bad idea on RS/6000: */ + susp->s_ptr += togo; + out_ptr += togo; + susp_took(s_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_ni_fetch */ + + +void delaycv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type feedback_DeLtA; + sample_type feedback_val; + sample_type feedback_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type s_ptr_reg; + falloc_sample_block(out, "delaycv_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->feedback_pHaSe = 1.0; + } + + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s input sample block: */ + susp_check_term_samples(s, s_ptr, s_cnt); + togo = min(togo, susp->s_cnt); + + /* grab next feedback_x2_sample when phase goes past 1.0; */ + /* we use feedback_n (computed below) to avoid roundoff errors: */ + if (susp->feedback_n <= 0) { + susp->feedback_x1_sample = feedback_x2_sample; + susp->feedback_ptr++; + susp_took(feedback_cnt, 1); + susp->feedback_pHaSe -= 1.0; + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + feedback_x2_sample = susp_current_sample(feedback, feedback_ptr); + /* feedback_n gets number of samples before phase exceeds 1.0: */ + susp->feedback_n = (long) ((1.0 - susp->feedback_pHaSe) * + susp->output_per_feedback); + } + togo = min(togo, susp->feedback_n); + feedback_DeLtA = (sample_type) ((feedback_x2_sample - susp->feedback_x1_sample) * susp->feedback_pHaSe_iNcR); + feedback_val = (sample_type) (susp->feedback_x1_sample * (1.0 - susp->feedback_pHaSe) + + feedback_x2_sample * susp->feedback_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + s_ptr_reg = susp->s_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * feedback_val + *s_ptr_reg++; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + feedback_val += feedback_DeLtA; + } while (--n); /* inner loop */ + + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + /* using s_ptr_reg is a bad idea on RS/6000: */ + susp->s_ptr += togo; + out_ptr += togo; + susp_took(s_cnt, togo); + susp->feedback_pHaSe += togo * susp->feedback_pHaSe_iNcR; + susp->feedback_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_nr_fetch */ + + +void delaycv_in_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type feedback_ptr_reg; + register double s_pHaSe_iNcR_rEg = susp->s_pHaSe_iNcR; + register double s_pHaSe_ReG; + register sample_type s_x1_sample_reg; + falloc_sample_block(out, "delaycv_in_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_samples(s, s_ptr, s_cnt); + susp->s_x1_sample = susp_fetch_sample(s, s_ptr, s_cnt); + } + + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + s_pHaSe_ReG = susp->s_pHaSe; + s_x1_sample_reg = susp->s_x1_sample; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s_pHaSe_ReG >= 1.0) { + s_x1_sample_reg = s_x2_sample; + /* pick up next sample as s_x2_sample: */ + susp->s_ptr++; + susp_took(s_cnt, 1); + s_pHaSe_ReG -= 1.0; + susp_check_term_samples_break(s, s_ptr, s_cnt, s_x2_sample); + } + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * *feedback_ptr_reg++ + + (s_x1_sample_reg * (1 - s_pHaSe_ReG) + s_x2_sample * s_pHaSe_ReG); + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + s_pHaSe_ReG += s_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + susp->s_pHaSe = s_pHaSe_ReG; + susp->s_x1_sample = s_x1_sample_reg; + out_ptr += togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_in_fetch */ + + +void delaycv_is_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_type feedback_scale_reg = susp->feedback->scale; + register sample_block_values_type feedback_ptr_reg; + register double s_pHaSe_iNcR_rEg = susp->s_pHaSe_iNcR; + register double s_pHaSe_ReG; + register sample_type s_x1_sample_reg; + falloc_sample_block(out, "delaycv_is_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_samples(s, s_ptr, s_cnt); + susp->s_x1_sample = susp_fetch_sample(s, s_ptr, s_cnt); + } + + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + s_pHaSe_ReG = susp->s_pHaSe; + s_x1_sample_reg = susp->s_x1_sample; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s_pHaSe_ReG >= 1.0) { + s_x1_sample_reg = s_x2_sample; + /* pick up next sample as s_x2_sample: */ + susp->s_ptr++; + susp_took(s_cnt, 1); + s_pHaSe_ReG -= 1.0; + susp_check_term_samples_break(s, s_ptr, s_cnt, s_x2_sample); + } + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * (feedback_scale_reg * *feedback_ptr_reg++) + + (s_x1_sample_reg * (1 - s_pHaSe_ReG) + s_x2_sample * s_pHaSe_ReG); + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + s_pHaSe_ReG += s_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + susp->s_pHaSe = s_pHaSe_ReG; + susp->s_x1_sample = s_x1_sample_reg; + out_ptr += togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_is_fetch */ + + +void delaycv_rn_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_DeLtA; + sample_type s_val; + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_block_values_type feedback_ptr_reg; + falloc_sample_block(out, "delaycv_rn_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s_pHaSe = 1.0; + } + + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* grab next s_x2_sample when phase goes past 1.0; */ + /* we use s_n (computed below) to avoid roundoff errors: */ + if (susp->s_n <= 0) { + susp->s_x1_sample = s_x2_sample; + susp->s_ptr++; + susp_took(s_cnt, 1); + susp->s_pHaSe -= 1.0; + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + /* s_n gets number of samples before phase exceeds 1.0: */ + susp->s_n = (long) ((1.0 - susp->s_pHaSe) * + susp->output_per_s); + } + togo = min(togo, susp->s_n); + s_DeLtA = (sample_type) ((s_x2_sample - susp->s_x1_sample) * susp->s_pHaSe_iNcR); + s_val = (sample_type) (susp->s_x1_sample * (1.0 - susp->s_pHaSe) + + s_x2_sample * susp->s_pHaSe); + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * *feedback_ptr_reg++ + s_val; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + s_val += s_DeLtA; + } while (--n); /* inner loop */ + + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + out_ptr += togo; + susp->s_pHaSe += togo * susp->s_pHaSe_iNcR; + susp->s_n -= togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_rn_fetch */ + + +void delaycv_rs_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + delaycv_susp_type susp = (delaycv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_DeLtA; + sample_type s_val; + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type * delayptr_reg; + register sample_type * endptr_reg; + register sample_type feedback_scale_reg = susp->feedback->scale; + register sample_block_values_type feedback_ptr_reg; + falloc_sample_block(out, "delaycv_rs_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s_pHaSe = 1.0; + } + + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* grab next s_x2_sample when phase goes past 1.0; */ + /* we use s_n (computed below) to avoid roundoff errors: */ + if (susp->s_n <= 0) { + susp->s_x1_sample = s_x2_sample; + susp->s_ptr++; + susp_took(s_cnt, 1); + susp->s_pHaSe -= 1.0; + susp_check_term_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + /* s_n gets number of samples before phase exceeds 1.0: */ + susp->s_n = (long) ((1.0 - susp->s_pHaSe) * + susp->output_per_s); + } + togo = min(togo, susp->s_n); + s_DeLtA = (sample_type) ((s_x2_sample - susp->s_x1_sample) * susp->s_pHaSe_iNcR); + s_val = (sample_type) (susp->s_x1_sample * (1.0 - susp->s_pHaSe) + + s_x2_sample * susp->s_pHaSe); + + /* don't run past the feedback input sample block: */ + susp_check_samples(feedback, feedback_ptr, feedback_cnt); + togo = min(togo, susp->feedback_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + n = togo; + delayptr_reg = susp->delayptr; + endptr_reg = susp->endptr; + feedback_ptr_reg = susp->feedback_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = *delayptr_reg; + *delayptr_reg = *delayptr_reg * (feedback_scale_reg * *feedback_ptr_reg++) + s_val; + if (++delayptr_reg >= endptr_reg) delayptr_reg = susp->delaybuf; + s_val += s_DeLtA; + } while (--n); /* inner loop */ + + susp->delayptr = delayptr_reg; + susp->endptr = endptr_reg; + /* using feedback_ptr_reg is a bad idea on RS/6000: */ + susp->feedback_ptr += togo; + out_ptr += togo; + susp->s_pHaSe += togo * susp->s_pHaSe_iNcR; + susp->s_n -= togo; + susp_took(feedback_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } +} /* delaycv_rs_fetch */ + + +void delaycv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + delaycv_susp_type susp = (delaycv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -201,27 +800,31 @@ void delaycv_toss_fetch(susp, snd_list) susp->feedback_ptr += n; susp_took(feedback_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void delaycv_mark(delaycv_susp_type susp) +void delaycv_mark(snd_susp_type a_susp) { + delaycv_susp_type susp = (delaycv_susp_type) a_susp; sound_xlmark(susp->s); sound_xlmark(susp->feedback); } -void delaycv_free(delaycv_susp_type susp) +void delaycv_free(snd_susp_type a_susp) { -free(susp->delaybuf); sound_unref(susp->s); + delaycv_susp_type susp = (delaycv_susp_type) a_susp; +free(susp->delaybuf); + sound_unref(susp->s); sound_unref(susp->feedback); ffree_generic(susp, sizeof(delaycv_susp_node), "delaycv_free"); } -void delaycv_print_tree(delaycv_susp_type susp, int n) +void delaycv_print_tree(snd_susp_type a_susp, int n) { + delaycv_susp_type susp = (delaycv_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); @@ -259,6 +862,12 @@ sound_type snd_make_delaycv(sound_type s, time_type delay, sound_type feedback) switch (interp_desc) { case INTERP_nn: susp->susp.fetch = delaycv_nn_fetch; break; case INTERP_ns: susp->susp.fetch = delaycv_ns_fetch; break; + case INTERP_ni: susp->susp.fetch = delaycv_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = delaycv_nr_fetch; break; + case INTERP_in: susp->susp.fetch = delaycv_in_fetch; break; + case INTERP_is: susp->susp.fetch = delaycv_is_fetch; break; + case INTERP_rn: susp->susp.fetch = delaycv_rn_fetch; break; + case INTERP_rs: susp->susp.fetch = delaycv_rs_fetch; break; default: snd_badsr(); break; } @@ -271,8 +880,8 @@ sound_type snd_make_delaycv(sound_type s, time_type delay, sound_type feedback) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = delaycv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = delaycv_toss_fetch; } /* initialize susp state */ @@ -283,11 +892,20 @@ sound_type snd_make_delaycv(sound_type s, time_type delay, sound_type feedback) susp->susp.print_tree = delaycv_print_tree; susp->susp.name = "delaycv"; susp->susp.log_stop_cnt = UNKNOWN; + susp->started = false; susp->susp.current = 0; susp->s = s; susp->s_cnt = 0; + susp->s_pHaSe = 0.0; + susp->s_pHaSe_iNcR = s->sr / sr; + susp->s_n = 0; + susp->output_per_s = sr / s->sr; susp->feedback = feedback; susp->feedback_cnt = 0; + susp->feedback_pHaSe = 0.0; + susp->feedback_pHaSe_iNcR = feedback->sr / sr; + susp->feedback_n = 0; + susp->output_per_feedback = sr / feedback->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/downproto.c b/lib-src/libnyquist/nyquist/tran/downproto.c new file mode 100644 index 000000000..6f23a811e --- /dev/null +++ b/lib-src/libnyquist/nyquist/tran/downproto.c @@ -0,0 +1,540 @@ +#include "stdio.h" +#ifndef mips +#include "stdlib.h" +#endif +#include "xlisp.h" +#include "sound.h" + +#include "falloc.h" +#include "cext.h" +#include "downproto.h" + +void down_free(); + + +typedef struct down_susp_struct { + snd_susp_node susp; + boolean started; + long terminate_cnt; + boolean logically_stopped; + sound_type s; + long s_cnt; + sample_block_values_type s_ptr; + + /* support for interpolation of s */ + sample_type s_x1_sample; + double s_pHaSe; + double s_pHaSe_iNcR; + + /* support for ramp between samples of s */ + double output_per_s; + long s_n; +} down_susp_node, *down_susp_type; + + +void down_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + down_susp_type susp = (down_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_block_values_type s_ptr_reg; + falloc_sample_block(out, "down_n_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s input sample block: */ + susp_check_term_log_samples(s, s_ptr, s_cnt); + togo = min(togo, susp->s_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s_ptr_reg = susp->s_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = *s_ptr_reg++; + } while (--n); /* inner loop */ + + /* using s_ptr_reg is a bad idea on RS/6000: */ + susp->s_ptr += togo; + out_ptr += togo; + susp_took(s_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* down_n_fetch */ + + +void down_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + down_susp_type susp = (down_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type s_scale_reg = susp->s->scale; + register sample_block_values_type s_ptr_reg; + falloc_sample_block(out, "down_s_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s input sample block: */ + susp_check_term_log_samples(s, s_ptr, s_cnt); + togo = min(togo, susp->s_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s_ptr_reg = susp->s_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = (s_scale_reg * *s_ptr_reg++); + } while (--n); /* inner loop */ + + /* using s_ptr_reg is a bad idea on RS/6000: */ + susp->s_ptr += togo; + out_ptr += togo; + susp_took(s_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* down_s_fetch */ + + +void down_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + down_susp_type susp = (down_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double s_pHaSe_iNcR_rEg = susp->s_pHaSe_iNcR; + register double s_pHaSe_ReG; + register sample_type s_x1_sample_reg; + falloc_sample_block(out, "down_i_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(s, s_ptr, s_cnt); + susp->s_x1_sample = susp_fetch_sample(s, s_ptr, s_cnt); + } + + susp_check_term_log_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s_pHaSe_ReG = susp->s_pHaSe; + s_x1_sample_reg = susp->s_x1_sample; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s_pHaSe_ReG >= 1.0) { + s_x1_sample_reg = s_x2_sample; + /* pick up next sample as s_x2_sample: */ + susp->s_ptr++; + susp_took(s_cnt, 1); + s_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(s, s_ptr, s_cnt, s_x2_sample); + } + *out_ptr_reg++ = + (s_x1_sample_reg * (1 - s_pHaSe_ReG) + s_x2_sample * s_pHaSe_ReG); + s_pHaSe_ReG += s_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->s_pHaSe = s_pHaSe_ReG; + susp->s_x1_sample = s_x1_sample_reg; + out_ptr += togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* down_i_fetch */ + + +void down_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + down_susp_type susp = (down_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s_DeLtA; + sample_type s_val; + sample_type s_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + falloc_sample_block(out, "down_r_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s_pHaSe = 1.0; + } + + susp_check_term_log_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* grab next s_x2_sample when phase goes past 1.0; */ + /* we use s_n (computed below) to avoid roundoff errors: */ + if (susp->s_n <= 0) { + susp->s_x1_sample = s_x2_sample; + susp->s_ptr++; + susp_took(s_cnt, 1); + susp->s_pHaSe -= 1.0; + susp_check_term_log_samples(s, s_ptr, s_cnt); + s_x2_sample = susp_current_sample(s, s_ptr); + /* s_n gets number of samples before phase exceeds 1.0: */ + susp->s_n = (long) ((1.0 - susp->s_pHaSe) * + susp->output_per_s); + } + togo = min(togo, susp->s_n); + s_DeLtA = (sample_type) ((s_x2_sample - susp->s_x1_sample) * susp->s_pHaSe_iNcR); + s_val = (sample_type) (susp->s_x1_sample * (1.0 - susp->s_pHaSe) + + s_x2_sample * susp->s_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = s_val; + s_val += s_DeLtA; + } while (--n); /* inner loop */ + + out_ptr += togo; + susp->s_pHaSe += togo * susp->s_pHaSe_iNcR; + susp->s_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* down_r_fetch */ + + +void down_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + down_susp_type susp = (down_susp_type) a_susp; + time_type final_time = susp->susp.t0; + long n; + + /* fetch samples from s up to final_time for this block of zeros */ + while ((round((final_time - susp->s->t0) * susp->s->sr)) >= + susp->s->current) + susp_get_samples(s, s_ptr, s_cnt); + /* convert to normal processing when we hit final_count */ + /* we want each signal positioned at final_time */ + n = round((final_time - susp->s->t0) * susp->s->sr - + (susp->s->current - susp->s_cnt)); + susp->s_ptr += n; + susp_took(s_cnt, n); + susp->susp.fetch = susp->susp.keep_fetch; + (*(susp->susp.fetch))(a_susp, snd_list); +} + + +void down_mark(snd_susp_type a_susp) +{ + down_susp_type susp = (down_susp_type) a_susp; + sound_xlmark(susp->s); +} + + +void down_free(snd_susp_type a_susp) +{ + down_susp_type susp = (down_susp_type) a_susp; + sound_unref(susp->s); + ffree_generic(susp, sizeof(down_susp_node), "down_free"); +} + + +void down_print_tree(snd_susp_type a_susp, int n) +{ + down_susp_type susp = (down_susp_type) a_susp; + indent(n); + stdputstr("s:"); + sound_print_tree_1(susp->s, n); +} + + +sound_type snd_make_down(rate_type sr, sound_type s) +{ + register down_susp_type susp; + /* sr specified as input parameter */ + time_type t0 = s->t0; + int interp_desc = 0; + sample_type scale_factor = 1.0F; + time_type t0_min = t0; + if (s->sr < sr) { + sound_unref(s); + xlfail("snd-down: output sample rate must be lower than input"); + } + falloc_generic(susp, down_susp_node, "snd_make_down"); + + /* make sure no sample rate is too high */ + if (s->sr > sr) { + sound_unref(s); + snd_badsr(); + } + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(s, sr); + switch (interp_desc) { + case INTERP_n: susp->susp.fetch = down_n_fetch; break; + case INTERP_s: susp->susp.fetch = down_s_fetch; break; + case INTERP_i: susp->susp.fetch = down_i_fetch; break; + case INTERP_r: susp->susp.fetch = down_r_fetch; break; + default: snd_badsr(); break; + } + + susp->terminate_cnt = UNKNOWN; + /* handle unequal start times, if any */ + if (t0 < s->t0) sound_prepend_zeros(s, t0); + /* minimum start time over all inputs: */ + t0_min = min(s->t0, t0); + /* how many samples to toss before t0: */ + susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); + if (susp->susp.toss_cnt > 0) { + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = down_toss_fetch; + } + + /* initialize susp state */ + susp->susp.free = down_free; + susp->susp.sr = sr; + susp->susp.t0 = t0; + susp->susp.mark = down_mark; + susp->susp.print_tree = down_print_tree; + susp->susp.name = "down"; + susp->logically_stopped = false; + susp->susp.log_stop_cnt = logical_stop_cnt_cvt(s); + susp->started = false; + susp->susp.current = 0; + susp->s = s; + susp->s_cnt = 0; + susp->s_pHaSe = 0.0; + susp->s_pHaSe_iNcR = s->sr / sr; + susp->s_n = 0; + susp->output_per_s = sr / s->sr; + return sound_create((snd_susp_type)susp, t0, sr, scale_factor); +} + + +sound_type snd_down(rate_type sr, sound_type s) +{ + sound_type s_copy = sound_copy(s); + return snd_make_down(sr, s_copy); +} diff --git a/lib-src/libnyquist/nyquist/tran/downproto.h b/lib-src/libnyquist/nyquist/tran/downproto.h new file mode 100644 index 000000000..55a61fe6e --- /dev/null +++ b/lib-src/libnyquist/nyquist/tran/downproto.h @@ -0,0 +1,3 @@ +sound_type snd_make_down(rate_type sr, sound_type s); +sound_type snd_down(rate_type sr, sound_type s); + /* LISP: (snd-down ANYNUM SOUND) */ diff --git a/lib-src/libnyquist/nyquist/tran/eqbandv.alg b/lib-src/libnyquist/nyquist/tran/eqbandv.alg index 1837f4307..462b54767 100644 --- a/lib-src/libnyquist/nyquist/tran/eqbandv.alg +++ b/lib-src/libnyquist/nyquist/tran/eqbandv.alg @@ -11,7 +11,6 @@ (LOGICAL-STOP (MIN s1 hz)) ;; gain width)) (SAMPLE-RATE (MAX s1)) (INTERNAL-SCALING s1) -(INLINE-INTERPOLATION T) (ALWAYS-SCALE hz) (STEP-FUNCTION hz gain width) (STATE ("double" "scale1" "s1->scale") @@ -48,9 +47,9 @@ (FORCE-INTO-REGISTER recompute) (STEP-FUNCTION hz) ;; gain width) (CONSTANT "w1" "sw" "cw" "J" "g" "b0" "b1" "b2" "b3" "a0" "a1" "a2") -(INNER-LOOP-LOCALS "double z0;") -(INNER-LOOP " z0 = s + a1*z1 + a2*z2; - output = (sample_type) (z0*b0 + z1*b1 + z2*b2); - z2 = z1; z1 = z0;") +(INNER-LOOP-LOCALS " double z0;") +(INNER-LOOP "z0 = s + a1*z1 + a2*z2; + output = (sample_type) (z0*b0 + z1*b1 + z2*b2); + z2 = z1; z1 = z0") ) diff --git a/lib-src/libnyquist/nyquist/tran/eqbandvvv.alg b/lib-src/libnyquist/nyquist/tran/eqbandvvv.alg index c2a14a448..e7dd7946a 100644 --- a/lib-src/libnyquist/nyquist/tran/eqbandvvv.alg +++ b/lib-src/libnyquist/nyquist/tran/eqbandvvv.alg @@ -12,9 +12,9 @@ (LOGICAL-STOP (MIN input hz gain width)) (SAMPLE-RATE (MAX input)) ;;(INTERNAL-SCALING input hz gain width) -(INLINE-INTERPOLATION T) (MATCHED-SAMPLE-RATE hz gain width) -(ALWAYS-SCALE input hz gain width) +(LINEAR input) +(ALWAYS-SCALE hz gain width) (STEP-FUNCTION hz gain width) (STATE ("double" "inp_scale" "input->scale") ("double" "w1" "0.0") @@ -47,18 +47,19 @@ " /* a0 = 1.0 + gg / J; */" " double a_0_recip = J / (J + gg);" " recompute = false;" -" gg = sw * sinh(log_of_2_over_2 * width * w1 / sw);" +" gg = sw * sinh(log_of_2_over_2 * " +" width * w1 / sw);" " b0 = (1.0 + gg * J) * a_0_recip;" " b1 *= a_0_recip;" " b2 = (1.0 - gg * J) * a_0_recip;" " a1 *= a_0_recip;" " a2 = (gg / J - 1.0) * a_0_recip;" "}")) -(FORCE-INTO-REGISTER recompute inp_period cw) +(FORCE-INTO-REGISTER inp_period cw) (CONSTANT "w1" "sw" "cw" "J" "gg" "b0" "b1" "b2" "b3" "a0" "a1" "a2" "inp_period") (INNER-LOOP-LOCALS " double z0;\n") -(INNER-LOOP " z0 = input + a1*z1 + a2*z2; - output = (sample_type) (z0*b0 + z1*b1 + z2*b2); - z2 = z1; z1 = z0;") +(INNER-LOOP "z0 = input + a1*z1 + a2*z2; + output = (sample_type) (z0*b0 + z1*b1 + z2*b2); + z2 = z1; z1 = z0") ) diff --git a/lib-src/libnyquist/nyquist/tran/eqbandvvv.c b/lib-src/libnyquist/nyquist/tran/eqbandvvv.c index 1c5bcb514..eadd76037 100644 --- a/lib-src/libnyquist/nyquist/tran/eqbandvvv.c +++ b/lib-src/libnyquist/nyquist/tran/eqbandvvv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "eqbandvvv.h" -void eqbandvvv_free(); +void eqbandvvv_free(snd_susp_type a_susp); typedef struct eqbandvvv_susp_struct { @@ -78,8 +78,9 @@ typedef struct eqbandvvv_susp_struct { #define log_of_2_over_2 0.3465735902799726547086 -void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_list) +void eqbandvvv_nsss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -109,9 +110,8 @@ void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l register sample_block_values_type gain_ptr_reg; register sample_type hz_scale_reg = susp->hz->scale; register sample_block_values_type hz_ptr_reg; - register sample_type input_scale_reg = susp->input->scale; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "eqbandvvv_ssss_fetch"); + falloc_sample_block(out, "eqbandvvv_nsss_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -140,6 +140,7 @@ void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -151,6 +152,7 @@ void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -204,16 +206,17 @@ void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l /* a0_reg = 1.0 + gg_reg / J_reg; */ double a_0_recip = J_reg / (J_reg + gg_reg); recompute_reg = false; - gg_reg = sw_reg * sinh(log_of_2_over_2 * (width_scale_reg * *width_ptr_reg++) * w1_reg / sw_reg); + gg_reg = sw_reg * sinh(log_of_2_over_2 * + (width_scale_reg * *width_ptr_reg++) * w1_reg / sw_reg); b0_reg = (1.0 + gg_reg * J_reg) * a_0_recip; b1_reg *= a_0_recip; b2_reg = (1.0 - gg_reg * J_reg) * a_0_recip; a1_reg *= a_0_recip; a2_reg = (gg_reg / J_reg - 1.0) * a_0_recip; } - z0 = (input_scale_reg * *input_ptr_reg++) + a1_reg*z1_reg + a2_reg*z2_reg; - *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); - z2_reg = z1_reg; z1_reg = z0;; + z0 = *input_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; + *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); + z2_reg = z1_reg; z1_reg = z0; } while (--n); /* inner loop */ susp->z1 = z1_reg; @@ -248,11 +251,12 @@ void eqbandvvv_ssss_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l } else if (susp->susp.log_stop_cnt == susp->susp.current) { susp->logically_stopped = true; } -} /* eqbandvvv_ssss_fetch */ +} /* eqbandvvv_nsss_fetch */ -void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_list) +void eqbandvvv_niii_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -285,9 +289,8 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l register double hz_pHaSe_iNcR_rEg = susp->hz_pHaSe_iNcR; register double hz_pHaSe_ReG; register sample_type hz_x1_sample_reg; - register sample_type input_scale_reg = susp->input->scale; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "eqbandvvv_siii_fetch"); + falloc_sample_block(out, "eqbandvvv_niii_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -324,6 +327,7 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -335,6 +339,7 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -386,12 +391,12 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l hz_pHaSe_ReG -= 1.0; susp_check_term_log_samples_break(hz, hz_ptr, hz_cnt, hz_x1_sample_reg); hz_x1_sample_reg = susp_current_sample(hz, hz_ptr); - w1_reg = susp->w1 = PI2 * hz_x1_sample_reg * inp_period_reg; - sw_reg = susp->sw = sin(w1_reg); - cw_reg = susp->cw = cos(w1_reg); - b1_reg = susp->b1 = -2.0 * cw_reg; - a1_reg = susp->a1 = -b1_reg; - recompute_reg = susp->recompute = true; + w1_reg = PI2 * hz_x1_sample_reg * inp_period_reg; + sw_reg = sin(w1_reg); + cw_reg = cos(w1_reg); + b1_reg = -2.0 * cw_reg; + a1_reg = -b1_reg; + recompute_reg = true; } if (gain_pHaSe_ReG >= 1.0) { /* fixup-depends gain */ @@ -401,8 +406,8 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l gain_pHaSe_ReG -= 1.0; susp_check_term_log_samples_break(gain, gain_ptr, gain_cnt, gain_x1_sample_reg); gain_x1_sample_reg = susp_current_sample(gain, gain_ptr); - J_reg = susp->J = sqrt(gain_x1_sample_reg); - recompute_reg = susp->recompute = true; + J_reg = sqrt(gain_x1_sample_reg); + recompute_reg = true; } if (width_pHaSe_ReG >= 1.0) { /* fixup-depends width */ @@ -412,22 +417,23 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l width_pHaSe_ReG -= 1.0; susp_check_term_log_samples_break(width, width_ptr, width_cnt, width_x1_sample_reg); width_x1_sample_reg = susp_current_sample(width, width_ptr); - recompute_reg = susp->recompute = true; + recompute_reg = true; } if (recompute_reg) { /* a0_reg = 1.0 + gg_reg / J_reg; */ double a_0_recip = J_reg / (J_reg + gg_reg); recompute_reg = false; - gg_reg = sw_reg * sinh(log_of_2_over_2 * width_x1_sample_reg * w1_reg / sw_reg); + gg_reg = sw_reg * sinh(log_of_2_over_2 * + width_x1_sample_reg * w1_reg / sw_reg); b0_reg = (1.0 + gg_reg * J_reg) * a_0_recip; b1_reg *= a_0_recip; b2_reg = (1.0 - gg_reg * J_reg) * a_0_recip; a1_reg *= a_0_recip; a2_reg = (gg_reg / J_reg - 1.0) * a_0_recip; } - z0 = (input_scale_reg * *input_ptr_reg++) + a1_reg*z1_reg + a2_reg*z2_reg; - *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); - z2_reg = z1_reg; z1_reg = z0;; + z0 = *input_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; + *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); + z2_reg = z1_reg; z1_reg = z0; hz_pHaSe_ReG += hz_pHaSe_iNcR_rEg; gain_pHaSe_ReG += gain_pHaSe_iNcR_rEg; width_pHaSe_ReG += width_pHaSe_iNcR_rEg; @@ -463,11 +469,12 @@ void eqbandvvv_siii_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l } else if (susp->susp.log_stop_cnt == susp->susp.current) { susp->logically_stopped = true; } -} /* eqbandvvv_siii_fetch */ +} /* eqbandvvv_niii_fetch */ -void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_list) +void eqbandvvv_nrrr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz_val; sample_type gain_val; @@ -487,11 +494,9 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l register double a2_reg; register double z1_reg; register double z2_reg; - register boolean recompute_reg; register double inp_period_reg; - register sample_type input_scale_reg = susp->input->scale; register sample_block_values_type input_ptr_reg; - falloc_sample_block(out, "eqbandvvv_srrr_fetch"); + falloc_sample_block(out, "eqbandvvv_nrrr_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -567,7 +572,8 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l /* susp->a0 = 1.0 + susp->gg / susp->J; */ double a_0_recip = susp->J / (susp->J + susp->gg); susp->recompute = false; - susp->gg = susp->sw * sinh(log_of_2_over_2 * width_val * susp->w1 / susp->sw); + susp->gg = susp->sw * sinh(log_of_2_over_2 * + width_val * susp->w1 / susp->sw); susp->b0 = (1.0 + susp->gg * susp->J) * a_0_recip; susp->b1 *= a_0_recip; susp->b2 = (1.0 - susp->gg * susp->J) * a_0_recip; @@ -578,6 +584,7 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -589,6 +596,7 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -615,20 +623,18 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l a2_reg = susp->a2; z1_reg = susp->z1; z2_reg = susp->z2; - recompute_reg = susp->recompute; inp_period_reg = susp->inp_period; input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ double z0; - z0 = (input_scale_reg * *input_ptr_reg++) + a1_reg*z1_reg + a2_reg*z2_reg; - *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); - z2_reg = z1_reg; z1_reg = z0;; + z0 = *input_ptr_reg++ + a1_reg*z1_reg + a2_reg*z2_reg; + *out_ptr_reg++ = (sample_type) (z0*b0_reg + z1_reg*b1_reg + z2_reg*b2_reg); + z2_reg = z1_reg; z1_reg = z0; } while (--n); /* inner loop */ susp->z1 = z1_reg; susp->z2 = z2_reg; - susp->recompute = recompute_reg; /* using input_ptr_reg is a bad idea on RS/6000: */ susp->input_ptr += togo; out_ptr += togo; @@ -655,13 +661,12 @@ void eqbandvvv_srrr_fetch(register eqbandvvv_susp_type susp, snd_list_type snd_l } else if (susp->susp.log_stop_cnt == susp->susp.current) { susp->logically_stopped = true; } -} /* eqbandvvv_srrr_fetch */ +} /* eqbandvvv_nrrr_fetch */ -void eqbandvvv_toss_fetch(susp, snd_list) - register eqbandvvv_susp_type susp; - snd_list_type snd_list; -{ +void eqbandvvv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -700,12 +705,13 @@ void eqbandvvv_toss_fetch(susp, snd_list) susp->width_ptr += n; susp_took(width_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void eqbandvvv_mark(eqbandvvv_susp_type susp) +void eqbandvvv_mark(snd_susp_type a_susp) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; sound_xlmark(susp->input); sound_xlmark(susp->hz); sound_xlmark(susp->gain); @@ -713,8 +719,9 @@ void eqbandvvv_mark(eqbandvvv_susp_type susp) } -void eqbandvvv_free(eqbandvvv_susp_type susp) +void eqbandvvv_free(snd_susp_type a_susp) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; sound_unref(susp->input); sound_unref(susp->hz); sound_unref(susp->gain); @@ -723,8 +730,9 @@ void eqbandvvv_free(eqbandvvv_susp_type susp) } -void eqbandvvv_print_tree(eqbandvvv_susp_type susp, int n) +void eqbandvvv_print_tree(snd_susp_type a_susp, int n) { + eqbandvvv_susp_type susp = (eqbandvvv_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -752,6 +760,13 @@ sound_type snd_make_eqbandvvv(sound_type input, sound_type hz, sound_type gain, sample_type scale_factor = 1.0F; time_type t0_min = t0; long lsc; + /* combine scale factors of linear inputs (INPUT) */ + scale_factor *= input->scale; + input->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (input->sr < sr) { input->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, eqbandvvv_susp_node, "snd_make_eqbandvvv"); susp->inp_scale = input->scale; susp->w1 = 0.0; @@ -770,6 +785,20 @@ sound_type snd_make_eqbandvvv(sound_type input, sound_type hz, sound_type gain, susp->recompute = false; susp->inp_period = 1.0 / input->sr; + /* make sure no sample rate is too high */ + if (hz->sr > sr) { + sound_unref(hz); + snd_badsr(); + } + if (gain->sr > sr) { + sound_unref(gain); + snd_badsr(); + } + if (width->sr > sr) { + sound_unref(width); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); interp_desc = (interp_desc << 2) + interp_style(hz, sr); @@ -783,19 +812,9 @@ sound_type snd_make_eqbandvvv(sound_type input, sound_type hz, sound_type gain, case INTERP_nsnn: /* handled below */ case INTERP_nsns: /* handled below */ case INTERP_nssn: /* handled below */ - case INTERP_nsss: /* handled below */ - case INTERP_snnn: /* handled below */ - case INTERP_snns: /* handled below */ - case INTERP_snsn: /* handled below */ - case INTERP_snss: /* handled below */ - case INTERP_ssnn: /* handled below */ - case INTERP_ssns: /* handled below */ - case INTERP_sssn: /* handled below */ - case INTERP_ssss: susp->susp.fetch = eqbandvvv_ssss_fetch; break; - case INTERP_niii: /* handled below */ - case INTERP_siii: susp->susp.fetch = eqbandvvv_siii_fetch; break; - case INTERP_nrrr: /* handled below */ - case INTERP_srrr: susp->susp.fetch = eqbandvvv_srrr_fetch; break; + case INTERP_nsss: susp->susp.fetch = eqbandvvv_nsss_fetch; break; + case INTERP_niii: susp->susp.fetch = eqbandvvv_niii_fetch; break; + case INTERP_nrrr: susp->susp.fetch = eqbandvvv_nrrr_fetch; break; default: snd_badsr(); break; } @@ -810,8 +829,8 @@ sound_type snd_make_eqbandvvv(sound_type input, sound_type hz, sound_type gain, /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = eqbandvvv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = eqbandvvv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/exp.c b/lib-src/libnyquist/nyquist/tran/exp.c index 1cae60e44..2e9771214 100644 --- a/lib-src/libnyquist/nyquist/tran/exp.c +++ b/lib-src/libnyquist/nyquist/tran/exp.c @@ -9,7 +9,7 @@ #include "cext.h" #include "exp.h" -void exp_free(); +void exp_free(snd_susp_type a_susp); typedef struct exp_susp_struct { @@ -22,8 +22,9 @@ typedef struct exp_susp_struct { } exp_susp_node, *exp_susp_type; -void exp_s_fetch(register exp_susp_type susp, snd_list_type snd_list) +void exp_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + exp_susp_type susp = (exp_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -51,6 +52,7 @@ void exp_s_fetch(register exp_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -62,6 +64,7 @@ void exp_s_fetch(register exp_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -83,7 +86,7 @@ void exp_s_fetch(register exp_susp_type susp, snd_list_type snd_list) in_ptr_reg = susp->in_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) exp((in_scale_reg * *in_ptr_reg++)); + *out_ptr_reg++ = (sample_type) exp((in_scale_reg * *in_ptr_reg++)); } while (--n); /* inner loop */ /* using in_ptr_reg is a bad idea on RS/6000: */ @@ -109,11 +112,9 @@ void exp_s_fetch(register exp_susp_type susp, snd_list_type snd_list) } /* exp_s_fetch */ -void exp_toss_fetch(susp, snd_list) - register exp_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void exp_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + exp_susp_type susp = (exp_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -128,25 +129,28 @@ void exp_toss_fetch(susp, snd_list) susp->in_ptr += n; susp_took(in_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void exp_mark(exp_susp_type susp) +void exp_mark(snd_susp_type a_susp) { + exp_susp_type susp = (exp_susp_type) a_susp; sound_xlmark(susp->in); } -void exp_free(exp_susp_type susp) +void exp_free(snd_susp_type a_susp) { + exp_susp_type susp = (exp_susp_type) a_susp; sound_unref(susp->in); ffree_generic(susp, sizeof(exp_susp_node), "exp_free"); } -void exp_print_tree(exp_susp_type susp, int n) +void exp_print_tree(snd_susp_type a_susp, int n) { + exp_susp_type susp = (exp_susp_type) a_susp; indent(n); stdputstr("in:"); sound_print_tree_1(susp->in, n); @@ -158,7 +162,6 @@ sound_type snd_make_exp(sound_type in) register exp_susp_type susp; rate_type sr = in->sr; time_type t0 = in->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, exp_susp_node, "snd_make_exp"); @@ -171,8 +174,8 @@ sound_type snd_make_exp(sound_type in) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = exp_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = exp_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/exprel.alg b/lib-src/libnyquist/nyquist/tran/exprel.alg index 2e29a4bbb..f39e50cdf 100644 --- a/lib-src/libnyquist/nyquist/tran/exprel.alg +++ b/lib-src/libnyquist/nyquist/tran/exprel.alg @@ -7,7 +7,8 @@ (EXPREL-ALG (NAME "exprel") -(ARGUMENTS ("sound_type" "signal") ("time_type" "release_time") ("double" "fall_time")) +(ARGUMENTS ("sound_type" "signal") ("time_type" "release_time") + ("double" "fall_time")) (SUPPORT-FUNCTIONS "#define ST_HOLD 0 #define ST_FALL 1 #define ST_FALL_UNTIL 2 @@ -16,9 +17,9 @@ #define ST_RISE 5 /* Overview: -This operation passes its input to its output until the release time. Then, it takes -the last sample output as a starting point for an exponential decay, with a duration -of falltime. +This operation passes its input to its output until the release time. +Then, it takes the last sample output as a starting point for an +exponential decay, with a duration of falltime. */ ") @@ -31,19 +32,19 @@ of falltime. (LOGICAL-STOP "release_time") (LINEAR signal) (INNER-LOOP "{ - sample_type result; - if (falling) { - value = value * decay; - result = value; - } else { - result = signal; - if (release_time <= susp->susp.current + cnt + togo - n) { - value = result; - falling = 1; - } - } - output = (sample_type) value; - }") + sample_type result; + if (falling) { + value = value * decay; + result = value; + } else { + result = signal; + if (release_time <= susp->susp.current + cnt + togo - n) { + value = result; + falling = 1; + } + } + output = (sample_type) value; + }") ) need to do logical stop time and termination time diff --git a/lib-src/libnyquist/nyquist/tran/fmfb.alg b/lib-src/libnyquist/nyquist/tran/fmfb.alg index 801da0535..0bc2b7e67 100644 --- a/lib-src/libnyquist/nyquist/tran/fmfb.alg +++ b/lib-src/libnyquist/nyquist/tran/fmfb.alg @@ -1,6 +1,7 @@ (FMFB-ALG (NAME "fmfb") - (ARGUMENTS ("time_type" "t0")("double" "hz") ("rate_type" "sr")("double" "index") ("time_type" "d")) + (ARGUMENTS ("time_type" "t0") ("double" "hz") ("rate_type" "sr") + ("double" "index") ("time_type" "d")) (TERMINATE (AFTER "d")) (STATE ("double" "yy" "0.0") ("double" "sin_y" "0.0") @@ -9,18 +10,17 @@ "hz * SINE_TABLE_LEN / sr") ("double" "index" "index * SINE_TABLE_LEN / PI2")) (INNER-LOOP "xx += x_incr; - if (xx > SINE_TABLE_LEN) xx -= SINE_TABLE_LEN; - /* xx incremented and index scaled to table index, and - sin_y is a signal (-1 to +1) */ - yy = xx + index * sin_y; - /* so yy is a table index */ - while (yy > SINE_TABLE_LEN) yy -= SINE_TABLE_LEN; - while (yy < 0) yy += SINE_TABLE_LEN; - sin_y = sine_table[(int) yy]; /* truncation gets valid index */ - /* sin_y is now a signal not ready for table lookup */ - output = sin_y;") + if (xx > SINE_TABLE_LEN) xx -= SINE_TABLE_LEN; + /* xx incremented and index scaled to table index, and + sin_y is a signal (-1 to +1) */ + yy = xx + index * sin_y; + /* so yy is a table index */ + while (yy > SINE_TABLE_LEN) yy -= SINE_TABLE_LEN; + while (yy < 0) yy += SINE_TABLE_LEN; + sin_y = sine_table[(int) yy]; /* truncation gets valid index */ + /* sin_y is now a signal not ready for table lookup */ + output = sin_y") (CONSTANT "x_incr") (SAMPLE-RATE "sr") - (SUPPORT-HEADER "#include \"sine.h\" /* sine_table and SINE_TABLE_LEN */ -") + (SUPPORT-HEADER "#include \"sine.h\" /* sine_table and SINE_TABLE_LEN */\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/fmfb.c b/lib-src/libnyquist/nyquist/tran/fmfb.c index 28ce95ea6..c081d8170 100644 --- a/lib-src/libnyquist/nyquist/tran/fmfb.c +++ b/lib-src/libnyquist/nyquist/tran/fmfb.c @@ -9,7 +9,7 @@ #include "cext.h" #include "fmfb.h" -void fmfb_free(); +void fmfb_free(snd_susp_type a_susp); typedef struct fmfb_susp_struct { @@ -24,8 +24,9 @@ typedef struct fmfb_susp_struct { } fmfb_susp_node, *fmfb_susp_type; -void fmfb__fetch(register fmfb_susp_type susp, snd_list_type snd_list) +void fmfb__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmfb_susp_type susp = (fmfb_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -52,6 +53,7 @@ void fmfb__fetch(register fmfb_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -63,17 +65,17 @@ void fmfb__fetch(register fmfb_susp_type susp, snd_list_type snd_list) index_reg = susp->index; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -xx_reg += x_incr_reg; - if (xx_reg > SINE_TABLE_LEN) xx_reg -= SINE_TABLE_LEN; - /* xx_reg incremented and index_reg scaled to table index_reg, and - sin_y_reg is a signal (-1 to +1) */ - yy_reg = xx_reg + index_reg * sin_y_reg; - /* so yy_reg is a table index_reg */ - while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; - while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; - sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index_reg */ - /* sin_y_reg is now a signal not ready for table lookup */ - *out_ptr_reg++ = sin_y_reg;; + xx_reg += x_incr_reg; + if (xx_reg > SINE_TABLE_LEN) xx_reg -= SINE_TABLE_LEN; + /* xx_reg incremented and index_reg scaled to table index_reg, and + sin_y_reg is a signal (-1 to +1) */ + yy_reg = xx_reg + index_reg * sin_y_reg; + /* so yy_reg is a table index_reg */ + while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; + while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; + sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index_reg */ + /* sin_y_reg is now a signal not ready for table lookup */ + *out_ptr_reg++ = sin_y_reg; } while (--n); /* inner loop */ susp->yy = yy_reg; @@ -94,13 +96,14 @@ xx_reg += x_incr_reg; } /* fmfb__fetch */ -void fmfb_free(fmfb_susp_type susp) +void fmfb_free(snd_susp_type a_susp) { + fmfb_susp_type susp = (fmfb_susp_type) a_susp; ffree_generic(susp, sizeof(fmfb_susp_node), "fmfb_free"); } -void fmfb_print_tree(fmfb_susp_type susp, int n) +void fmfb_print_tree(snd_susp_type a_susp, int n) { } @@ -119,7 +122,7 @@ sound_type snd_make_fmfb(time_type t0, double hz, rate_type sr, double index, ti susp->index = index * SINE_TABLE_LEN / PI2; susp->susp.fetch = fmfb__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = fmfb_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/fmfbv.alg b/lib-src/libnyquist/nyquist/tran/fmfbv.alg index 8034ddb5d..5295c29e4 100644 --- a/lib-src/libnyquist/nyquist/tran/fmfbv.alg +++ b/lib-src/libnyquist/nyquist/tran/fmfbv.alg @@ -1,11 +1,11 @@ (FMFBV-ALG - (NAME "fmfbv") - (ARGUMENTS ("time_type" "t0")("double" "hz") ("rate_type" "sr")("sound_type" "index")) + (NAME "fmfbv") ; FM feedback unit generator + (ARGUMENTS ("time_type" "t0") ("double" "hz") ("rate_type" "sr") + ("sound_type" "index")) (START (MIN index)) (TERMINATE (MIN index)) (LOGICAL-STOP (MIN index)) (STEP-FUNCTION index) - (INLINE-INTERPOLATION T) (STATE ("double" "yy" "0.0") ("double" "sin_y" "0.0") ("double" "phase" "0.0") @@ -13,16 +13,16 @@ index->scale *= SINE_TABLE_LEN / PI2 ")) (INNER-LOOP "phase += ph_incr; - if (phase > SINE_TABLE_LEN) phase -= SINE_TABLE_LEN; - /* PHASE is incremented and INDEX scaled to table INDEX, and - sin_y is a signal (-1 to +1) */ - yy = phase + index * sin_y; - /* so yy is a table index */ - while (yy > SINE_TABLE_LEN) yy -= SINE_TABLE_LEN; - while (yy < 0) yy += SINE_TABLE_LEN; - sin_y = sine_table[(int) yy]; /* truncation gets valid index */ - /* sin_y is now a signal not ready for table lookup */ - output = sin_y;") + if (phase > SINE_TABLE_LEN) phase -= SINE_TABLE_LEN; + /* PHASE is incremented and INDEX scaled to table INDEX, and + sin_y is a signal (-1 to +1) */ + yy = phase + index * sin_y; + /* so yy is a table index */ + while (yy > SINE_TABLE_LEN) yy -= SINE_TABLE_LEN; + while (yy < 0) yy += SINE_TABLE_LEN; + sin_y = sine_table[(int) yy]; /* truncation gets valid index */ + /* sin_y is now a signal ready for table lookup */ + output = sin_y") (CONSTANT "ph_incr") (SAMPLE-RATE "sr") (SUPPORT-HEADER "#include \"sine.h\" /* sine_table and SINE_TABLE_LEN */ diff --git a/lib-src/libnyquist/nyquist/tran/fmfbv.c b/lib-src/libnyquist/nyquist/tran/fmfbv.c index e843a459d..4d486649d 100644 --- a/lib-src/libnyquist/nyquist/tran/fmfbv.c +++ b/lib-src/libnyquist/nyquist/tran/fmfbv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "fmfbv.h" -void fmfbv_free(); +void fmfbv_free(snd_susp_type a_susp); typedef struct fmfbv_susp_struct { @@ -37,8 +37,9 @@ typedef struct fmfbv_susp_struct { } fmfbv_susp_node, *fmfbv_susp_type; -void fmfbv_n_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) +void fmfbv_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -69,6 +70,7 @@ void fmfbv_n_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -80,6 +82,7 @@ void fmfbv_n_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -105,17 +108,17 @@ void fmfbv_n_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) index_ptr_reg = susp->index_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -phase_reg += ph_incr_reg; - if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; - /* PHASE is incremented and INDEX scaled to table INDEX, and - sin_y_reg is a signal (-1 to +1) */ - yy_reg = phase_reg + *index_ptr_reg++ * sin_y_reg; - /* so yy_reg is a table index */ - while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; - while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; - sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ - /* sin_y_reg is now a signal not ready for table lookup */ - *out_ptr_reg++ = sin_y_reg;; + phase_reg += ph_incr_reg; + if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; + /* PHASE is incremented and INDEX scaled to table INDEX, and + sin_y_reg is a signal (-1 to +1) */ + yy_reg = phase_reg + *index_ptr_reg++ * sin_y_reg; + /* so yy_reg is a table index */ + while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; + while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; + sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ + /* sin_y_reg is now a signal ready for table lookup */ + *out_ptr_reg++ = sin_y_reg; } while (--n); /* inner loop */ susp->yy = yy_reg; @@ -144,8 +147,9 @@ phase_reg += ph_incr_reg; } /* fmfbv_n_fetch */ -void fmfbv_s_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) +void fmfbv_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -177,6 +181,7 @@ void fmfbv_s_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -188,6 +193,7 @@ void fmfbv_s_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -213,17 +219,17 @@ void fmfbv_s_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) index_ptr_reg = susp->index_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -phase_reg += ph_incr_reg; - if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; - /* PHASE is incremented and INDEX scaled to table INDEX, and - sin_y_reg is a signal (-1 to +1) */ - yy_reg = phase_reg + (index_scale_reg * *index_ptr_reg++) * sin_y_reg; - /* so yy_reg is a table index */ - while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; - while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; - sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ - /* sin_y_reg is now a signal not ready for table lookup */ - *out_ptr_reg++ = sin_y_reg;; + phase_reg += ph_incr_reg; + if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; + /* PHASE is incremented and INDEX scaled to table INDEX, and + sin_y_reg is a signal (-1 to +1) */ + yy_reg = phase_reg + (index_scale_reg * *index_ptr_reg++) * sin_y_reg; + /* so yy_reg is a table index */ + while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; + while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; + sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ + /* sin_y_reg is now a signal ready for table lookup */ + *out_ptr_reg++ = sin_y_reg; } while (--n); /* inner loop */ susp->yy = yy_reg; @@ -252,8 +258,9 @@ phase_reg += ph_incr_reg; } /* fmfbv_s_fetch */ -void fmfbv_i_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) +void fmfbv_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -289,6 +296,7 @@ void fmfbv_i_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -300,6 +308,7 @@ void fmfbv_i_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -335,17 +344,17 @@ void fmfbv_i_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) susp_check_term_log_samples_break(index, index_ptr, index_cnt, index_x1_sample_reg); index_x1_sample_reg = susp_current_sample(index, index_ptr); } -phase_reg += ph_incr_reg; - if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; - /* PHASE is incremented and INDEX scaled to table INDEX, and - sin_y_reg is a signal (-1 to +1) */ - yy_reg = phase_reg + index_x1_sample_reg * sin_y_reg; - /* so yy_reg is a table index */ - while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; - while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; - sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ - /* sin_y_reg is now a signal not ready for table lookup */ - *out_ptr_reg++ = sin_y_reg;; + phase_reg += ph_incr_reg; + if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; + /* PHASE is incremented and INDEX scaled to table INDEX, and + sin_y_reg is a signal (-1 to +1) */ + yy_reg = phase_reg + index_x1_sample_reg * sin_y_reg; + /* so yy_reg is a table index */ + while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; + while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; + sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ + /* sin_y_reg is now a signal ready for table lookup */ + *out_ptr_reg++ = sin_y_reg; index_pHaSe_ReG += index_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -375,8 +384,9 @@ phase_reg += ph_incr_reg; } /* fmfbv_i_fetch */ -void fmfbv_r_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) +void fmfbv_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type index_val; int togo; @@ -423,6 +433,7 @@ void fmfbv_r_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -434,6 +445,7 @@ void fmfbv_r_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -458,17 +470,17 @@ void fmfbv_r_fetch(register fmfbv_susp_type susp, snd_list_type snd_list) ph_incr_reg = susp->ph_incr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -phase_reg += ph_incr_reg; - if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; - /* PHASE is incremented and INDEX scaled to table INDEX, and - sin_y_reg is a signal (-1 to +1) */ - yy_reg = phase_reg + index_val * sin_y_reg; - /* so yy_reg is a table index */ - while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; - while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; - sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ - /* sin_y_reg is now a signal not ready for table lookup */ - *out_ptr_reg++ = sin_y_reg;; + phase_reg += ph_incr_reg; + if (phase_reg > SINE_TABLE_LEN) phase_reg -= SINE_TABLE_LEN; + /* PHASE is incremented and INDEX scaled to table INDEX, and + sin_y_reg is a signal (-1 to +1) */ + yy_reg = phase_reg + index_val * sin_y_reg; + /* so yy_reg is a table index */ + while (yy_reg > SINE_TABLE_LEN) yy_reg -= SINE_TABLE_LEN; + while (yy_reg < 0) yy_reg += SINE_TABLE_LEN; + sin_y_reg = sine_table[(int) yy_reg]; /* truncation gets valid index */ + /* sin_y_reg is now a signal ready for table lookup */ + *out_ptr_reg++ = sin_y_reg; } while (--n); /* inner loop */ susp->yy = yy_reg; @@ -496,11 +508,9 @@ phase_reg += ph_incr_reg; } /* fmfbv_r_fetch */ -void fmfbv_toss_fetch(susp, snd_list) - register fmfbv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void fmfbv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -515,25 +525,28 @@ void fmfbv_toss_fetch(susp, snd_list) susp->index_ptr += n; susp_took(index_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void fmfbv_mark(fmfbv_susp_type susp) +void fmfbv_mark(snd_susp_type a_susp) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; sound_xlmark(susp->index); } -void fmfbv_free(fmfbv_susp_type susp) +void fmfbv_free(snd_susp_type a_susp) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; sound_unref(susp->index); ffree_generic(susp, sizeof(fmfbv_susp_node), "fmfbv_free"); } -void fmfbv_print_tree(fmfbv_susp_type susp, int n) +void fmfbv_print_tree(snd_susp_type a_susp, int n) { + fmfbv_susp_type susp = (fmfbv_susp_type) a_susp; indent(n); stdputstr("index:"); sound_print_tree_1(susp->index, n); @@ -556,6 +569,12 @@ sound_type snd_make_fmfbv(time_type t0, double hz, rate_type sr, sound_type inde index->scale *= SINE_TABLE_LEN / PI2 ; + /* make sure no sample rate is too high */ + if (index->sr > sr) { + sound_unref(index); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(index, sr); switch (interp_desc) { @@ -574,8 +593,8 @@ sound_type snd_make_fmfbv(time_type t0, double hz, rate_type sr, sound_type inde /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = fmfbv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = fmfbv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/fmosc.alg b/lib-src/libnyquist/nyquist/tran/fmosc.alg index 1bbbc98b1..b002d04ee 100644 --- a/lib-src/libnyquist/nyquist/tran/fmosc.alg +++ b/lib-src/libnyquist/nyquist/tran/fmosc.alg @@ -15,11 +15,10 @@ : s->sr / (sr * step_to_hz(step))") ) ; cancel 0/0 (ALWAYS-SCALE s_fm) -(INLINE-INTERPOLATION T) ; so that modulation can be low frequency (STEP-FUNCTION s_fm) (TERMINATE (MIN s_fm)) (LOGICAL-STOP (MIN s_fm)) -(INNER-LOOP-LOCALS " long table_index; +(INNER-LOOP-LOCALS " long table_index; double x1; ") (INNER-LOOP "table_index = (long) phase; @@ -33,7 +32,5 @@ (CONSTANT "ph_incr" "table_len" "table_ptr" "table") (SAMPLE-RATE "sr") -(FINALIZATION " table_unref(susp->the_table); -") +(FINALIZATION " table_unref(susp->the_table);\n") ) - diff --git a/lib-src/libnyquist/nyquist/tran/fmosc.c b/lib-src/libnyquist/nyquist/tran/fmosc.c index cbff1beed..ad71edbdf 100644 --- a/lib-src/libnyquist/nyquist/tran/fmosc.c +++ b/lib-src/libnyquist/nyquist/tran/fmosc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "fmosc.h" -void fmosc_free(); +void fmosc_free(snd_susp_type a_susp); typedef struct fmosc_susp_struct { @@ -38,8 +38,9 @@ typedef struct fmosc_susp_struct { } fmosc_susp_node, *fmosc_susp_type; -void fmosc_s_fetch(register fmosc_susp_type susp, snd_list_type snd_list) +void fmosc_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -71,6 +72,7 @@ void fmosc_s_fetch(register fmosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -82,6 +84,7 @@ void fmosc_s_fetch(register fmosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -107,9 +110,9 @@ void fmosc_s_fetch(register fmosc_susp_type susp, snd_list_type snd_list) s_fm_ptr_reg = susp->s_fm_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -143,8 +146,9 @@ table_index = (long) phase_reg; } /* fmosc_s_fetch */ -void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list) +void fmosc_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -180,6 +184,7 @@ void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -191,6 +196,7 @@ void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -217,7 +223,7 @@ void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list) s_fm_x1_sample_reg = susp->s_fm_x1_sample; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; if (s_fm_pHaSe_ReG >= 1.0) { /* fixup-depends s_fm */ @@ -228,7 +234,7 @@ void fmosc_i_fetch(register fmosc_susp_type susp, snd_list_type snd_list) susp_check_term_log_samples_break(s_fm, s_fm_ptr, s_fm_cnt, s_fm_x1_sample_reg); s_fm_x1_sample_reg = susp_current_sample(s_fm, s_fm_ptr); } -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -263,8 +269,9 @@ table_index = (long) phase_reg; } /* fmosc_i_fetch */ -void fmosc_r_fetch(register fmosc_susp_type susp, snd_list_type snd_list) +void fmosc_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type s_fm_val; int togo; @@ -311,6 +318,7 @@ void fmosc_r_fetch(register fmosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -322,6 +330,7 @@ void fmosc_r_fetch(register fmosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -346,9 +355,9 @@ void fmosc_r_fetch(register fmosc_susp_type susp, snd_list_type snd_list) phase_reg = susp->phase; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double x1; -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -381,11 +390,9 @@ table_index = (long) phase_reg; } /* fmosc_r_fetch */ -void fmosc_toss_fetch(susp, snd_list) - register fmosc_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void fmosc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -400,26 +407,29 @@ void fmosc_toss_fetch(susp, snd_list) susp->s_fm_ptr += n; susp_took(s_fm_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void fmosc_mark(fmosc_susp_type susp) +void fmosc_mark(snd_susp_type a_susp) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; sound_xlmark(susp->s_fm); } -void fmosc_free(fmosc_susp_type susp) +void fmosc_free(snd_susp_type a_susp) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; table_unref(susp->the_table); sound_unref(susp->s_fm); ffree_generic(susp, sizeof(fmosc_susp_node), "fmosc_free"); } -void fmosc_print_tree(fmosc_susp_type susp, int n) +void fmosc_print_tree(snd_susp_type a_susp, int n) { + fmosc_susp_type susp = (fmosc_susp_type) a_susp; indent(n); stdputstr("s_fm:"); sound_print_tree_1(susp->s_fm, n); @@ -444,6 +454,12 @@ sound_type snd_make_fmosc(sound_type s, double step, rate_type sr, double hz, ti s_fm->scale *= hz != 0 ? (sample_type) (susp->ph_incr / hz) : s->sr / (sr * step_to_hz(step)); + /* make sure no sample rate is too high */ + if (s_fm->sr > sr) { + sound_unref(s_fm); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s_fm, sr); switch (interp_desc) { @@ -462,8 +478,8 @@ sound_type snd_make_fmosc(sound_type s, double step, rate_type sr, double hz, ti /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = fmosc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = fmosc_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/follow.alg b/lib-src/libnyquist/nyquist/tran/follow.alg index 9765897b5..6cd9c2004 100644 --- a/lib-src/libnyquist/nyquist/tran/follow.alg +++ b/lib-src/libnyquist/nyquist/tran/follow.alg @@ -47,7 +47,7 @@ static sample_type *create_buf(double floor, long lookahead) } ") (ARGUMENTS ("sound_type" "sndin") ("double" "floor") ("double" "risetime") - ("double" "falltime") ("long" "lookahead")) + ("double" "falltime") ("long" "lookahead")) (START (MIN sndin)) (STATE ("long" "lookahead" "lookahead = lookahead + 1") ("sample_type *" "delaybuf" "create_buf(floor, lookahead)") @@ -63,7 +63,7 @@ static sample_type *create_buf(double floor, long lookahead) (NOT-REGISTER delaybuf) (ALWAYS-SCALE sndin) (TERMINATE (MIN sndin)) -(INNER-LOOP " sample_type current = sndin; +(INNER-LOOP "sample_type current = sndin; sample_type high = (sample_type) (*prevptr * rise_factor); sample_type low = (sample_type) (*prevptr * fall_factor); if (low < floor) low = (sample_type) floor; @@ -100,7 +100,7 @@ static sample_type *create_buf(double floor, long lookahead) } prevptr = delayptr++; if (delayptr == endptr) delayptr = susp->delaybuf; - output = *delayptr;") + output = *delayptr") (FINALIZATION "free(susp->delaybuf);") ) diff --git a/lib-src/libnyquist/nyquist/tran/follow.c b/lib-src/libnyquist/nyquist/tran/follow.c index 695c4b67c..a17f357b8 100644 --- a/lib-src/libnyquist/nyquist/tran/follow.c +++ b/lib-src/libnyquist/nyquist/tran/follow.c @@ -9,7 +9,7 @@ #include "cext.h" #include "follow.h" -void follow_free(); +void follow_free(snd_susp_type a_susp); typedef struct follow_susp_struct { @@ -76,8 +76,9 @@ static sample_type *create_buf(double floor, long lookahead) } -void follow_s_fetch(register follow_susp_type susp, snd_list_type snd_list) +void follow_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + follow_susp_type susp = (follow_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -112,6 +113,7 @@ void follow_s_fetch(register follow_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -163,7 +165,7 @@ void follow_s_fetch(register follow_susp_type susp, snd_list_type snd_list) } prevptr_reg = delayptr_reg++; if (delayptr_reg == endptr_reg) delayptr_reg = susp->delaybuf; - *out_ptr_reg++ = *delayptr_reg;; + *out_ptr_reg++ = *delayptr_reg; } while (--n); /* inner loop */ togo -= n; @@ -188,11 +190,9 @@ void follow_s_fetch(register follow_susp_type susp, snd_list_type snd_list) } /* follow_s_fetch */ -void follow_toss_fetch(susp, snd_list) - register follow_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void follow_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + follow_susp_type susp = (follow_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -207,25 +207,28 @@ void follow_toss_fetch(susp, snd_list) susp->sndin_ptr += n; susp_took(sndin_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void follow_mark(follow_susp_type susp) +void follow_mark(snd_susp_type a_susp) { + follow_susp_type susp = (follow_susp_type) a_susp; sound_xlmark(susp->sndin); } -void follow_free(follow_susp_type susp) +void follow_free(snd_susp_type a_susp) { + follow_susp_type susp = (follow_susp_type) a_susp; free(susp->delaybuf); sound_unref(susp->sndin); ffree_generic(susp, sizeof(follow_susp_node), "follow_free"); } -void follow_print_tree(follow_susp_type susp, int n) +void follow_print_tree(snd_susp_type a_susp, int n) { + follow_susp_type susp = (follow_susp_type) a_susp; indent(n); stdputstr("sndin:"); sound_print_tree_1(susp->sndin, n); @@ -237,7 +240,6 @@ sound_type snd_make_follow(sound_type sndin, double floor, double risetime, doub register follow_susp_type susp; rate_type sr = sndin->sr; time_type t0 = sndin->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, follow_susp_node, "snd_make_follow"); @@ -260,8 +262,8 @@ sound_type snd_make_follow(sound_type sndin, double floor, double risetime, doub /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = follow_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = follow_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/fromarraystream.alg b/lib-src/libnyquist/nyquist/tran/fromarraystream.alg index 4ae22547d..6b1729e23 100644 --- a/lib-src/libnyquist/nyquist/tran/fromarraystream.alg +++ b/lib-src/libnyquist/nyquist/tran/fromarraystream.alg @@ -61,11 +61,10 @@ out: togo = 0; /* indicate termination */ } togo = min(togo, susp->length - susp->index); ") - (INNER-LOOP "output = samples[index++];") + (INNER-LOOP "output = samples[index++]") (CONSTANT "length" "samples" "array" "src") (TERMINATE COMPUTED) - (FINALIZATION " free(susp->samples); -") + (FINALIZATION " free(susp->samples);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/fromarraystream.c b/lib-src/libnyquist/nyquist/tran/fromarraystream.c index 7df0a9b88..b7db2c76b 100644 --- a/lib-src/libnyquist/nyquist/tran/fromarraystream.c +++ b/lib-src/libnyquist/nyquist/tran/fromarraystream.c @@ -9,7 +9,7 @@ #include "cext.h" #include "fromarraystream.h" -void fromarraystream_free(); +void fromarraystream_free(snd_susp_type a_susp); typedef struct fromarraystream_susp_struct { @@ -34,8 +34,9 @@ typedef struct fromarraystream_susp_struct { #include "samples.h" -void fromarraystream__fetch(register fromarraystream_susp_type susp, snd_list_type snd_list) +void fromarraystream__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fromarraystream_susp_type susp = (fromarraystream_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -100,7 +101,7 @@ out: togo = 0; /* indicate termination */ samples_reg = susp->samples; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = samples_reg[index_reg++];; + *out_ptr_reg++ = samples_reg[index_reg++]; } while (--n); /* inner loop */ susp->index = index_reg; @@ -118,21 +119,23 @@ out: togo = 0; /* indicate termination */ } /* fromarraystream__fetch */ -void fromarraystream_mark(fromarraystream_susp_type susp) +void fromarraystream_mark(snd_susp_type a_susp) { + fromarraystream_susp_type susp = (fromarraystream_susp_type) a_susp; if (susp->src) mark(susp->src); if (susp->array) mark(susp->array); } -void fromarraystream_free(fromarraystream_susp_type susp) +void fromarraystream_free(snd_susp_type a_susp) { + fromarraystream_susp_type susp = (fromarraystream_susp_type) a_susp; free(susp->samples); ffree_generic(susp, sizeof(fromarraystream_susp_node), "fromarraystream_free"); } -void fromarraystream_print_tree(fromarraystream_susp_type susp, int n) +void fromarraystream_print_tree(snd_susp_type a_susp, int n) { } diff --git a/lib-src/libnyquist/nyquist/tran/fromobject.alg b/lib-src/libnyquist/nyquist/tran/fromobject.alg index f119a7fd0..5c8d016d5 100644 --- a/lib-src/libnyquist/nyquist/tran/fromobject.alg +++ b/lib-src/libnyquist/nyquist/tran/fromobject.alg @@ -21,8 +21,7 @@ break; /* we're done */ } ") - (INNER-LOOP -" LVAL rslt = xleval(cons(s_send, cons(src, + (INNER-LOOP "LVAL rslt = xleval(cons(s_send, cons(src, consa(s_next)))); if (floatp(rslt)) { output = (sample_type) getflonum(rslt); diff --git a/lib-src/libnyquist/nyquist/tran/fromobject.c b/lib-src/libnyquist/nyquist/tran/fromobject.c index f744a9d4f..edb758c37 100644 --- a/lib-src/libnyquist/nyquist/tran/fromobject.c +++ b/lib-src/libnyquist/nyquist/tran/fromobject.c @@ -9,7 +9,7 @@ #include "cext.h" #include "fromobject.h" -void fromobject_free(); +void fromobject_free(snd_susp_type a_susp); typedef struct fromobject_susp_struct { @@ -29,8 +29,9 @@ typedef struct fromobject_susp_struct { #include "samples.h" -void fromobject__fetch(register fromobject_susp_type susp, snd_list_type snd_list) +void fromobject__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + fromobject_susp_type susp = (fromobject_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -87,19 +88,21 @@ void fromobject__fetch(register fromobject_susp_type susp, snd_list_type snd_lis } /* fromobject__fetch */ -void fromobject_mark(fromobject_susp_type susp) +void fromobject_mark(snd_susp_type a_susp) { + fromobject_susp_type susp = (fromobject_susp_type) a_susp; if (susp->src) mark(susp->src); } -void fromobject_free(fromobject_susp_type susp) +void fromobject_free(snd_susp_type a_susp) { + fromobject_susp_type susp = (fromobject_susp_type) a_susp; ffree_generic(susp, sizeof(fromobject_susp_node), "fromobject_free"); } -void fromobject_print_tree(fromobject_susp_type susp, int n) +void fromobject_print_tree(snd_susp_type a_susp, int n) { } diff --git a/lib-src/libnyquist/nyquist/tran/gate.alg b/lib-src/libnyquist/nyquist/tran/gate.alg index eb3e0a4f0..e430139c9 100644 --- a/lib-src/libnyquist/nyquist/tran/gate.alg +++ b/lib-src/libnyquist/nyquist/tran/gate.alg @@ -1,6 +1,7 @@ (GATE-ALG (NAME "gate") -(ARGUMENTS ("sound_type" "signal") ("time_type" "lookahead") ("double" "risetime") +(ARGUMENTS ("sound_type" "signal") ("time_type" "lookahead") + ("double" "risetime") ("double" "falltime") ("double" "floor") ("double" "threshold")) (START (MIN signal)) (SUPPORT-FUNCTIONS "#define ST_HOLD 0 @@ -11,24 +12,27 @@ #define ST_RISE 5 /* Overview: -This operation generates an exponential rise and decay suitable for implementing a -noise gate. The decay starts when the signal drops below threshold and stays there -for longer than lookahead. -Decay continues until the value reaches floor, at which point the decay stops -and the value is held constant. Either during the decay or after the floor is reached, -if the signal goes above threshold, then the output value will rise to 1.0 (0dB) at -the point the signal crosses the threshold. Again, lookahead is used, so the rise -actually starts before the signal crosses the threshold. The rise rate is constant -and set so that a rise from floor to 0dB occurs in the specified risetime. Similarly, -the fall rate is constant such that a fall from 0dB to the floor takes falltime. +This operation generates an exponential rise and decay suitable for +implementing a noise gate. The decay starts when the signal drops +below threshold and stays there for longer than lookahead. +Decay continues until the value reaches floor, at which point the +decay stops and the value is held constant. Either during the decay +or after the floor is reached, if the signal goes above threshold, +then the output value will rise to 1.0 (0dB) at the point the +signal crosses the threshold. Again, lookahead is used, so the rise +actually starts before the signal crosses the threshold. The rise +rate is constant and set so that a rise from floor to 0dB occurs +in the specified risetime. Similarly, the fall rate is constant +such that a fall from 0dB to the floor takes falltime. -Rather than looking ahead, the output actually lags the input by lookahead. The caller -should advance the time of the input signal in order to get a correct output signal, -and this will be taken care of in Lisp code. +Rather than looking ahead, the output actually lags the input by +lookahead. The caller should advance the time of the input signal +in order to get a correct output signal, and this will be taken +care of in Lisp code. -The implementation is a finite-state machine that simultaneously computes the value -and scans ahead for threshold crossings. Time points, remembered as sample counts are -saved in variables: +The implementation is a finite-state machine that simultaneously +computes the value and scans ahead for threshold crossings. Time +points, remembered as sample counts are saved in variables: on_count -- the time at which the rise should complete off_count -- the time at which the fall should begin rise_factor -- multiply by this to get exponential rise @@ -86,81 +90,82 @@ void compute_start_rise(gate_susp_type susp) ("int" "state" "ST_OFF") ("double" "value" "susp->floor")) -(CONSTANT "lookahead" "rise_time" "fall_time" "floor" "threshold" "delay_len" "end_ptr" - "rise_factor" "fall_factor") +(CONSTANT "lookahead" "rise_time" "fall_time" "floor" + "threshold" "delay_len" "end_ptr" + "rise_factor" "fall_factor") (NOT-REGISTER delay_buf rise_factor fall_factor rise_time fall_time floor on_count start_fall start_rise) (LINEAR signal) (TERMINATE (MIN signal)) (INNER-LOOP "{ - sample_type future = signal; - long now = susp->susp.current + cnt + togo - n; - - switch (state) { - /* hold at 1.0 and look for the moment to begin fall: */ - case ST_HOLD: - if (future >= threshold) { - off_count = now + delay_len; - } else if (now >= off_count) { - state = ST_FALL; - stop_count = (long) (now + susp->fall_time); - susp->start_fall = now; + sample_type future = signal; + long now = susp->susp.current + cnt + togo - n; + + switch (state) { + /* hold at 1.0 and look for the moment to begin fall: */ + case ST_HOLD: + if (future >= threshold) { + off_count = now + delay_len; + } else if (now >= off_count) { + state = ST_FALL; + stop_count = (long) (now + susp->fall_time); + susp->start_fall = now; + } + break; + /* fall until stop_count while looking for next rise time */ + case ST_FALL: + if (future >= threshold) { + off_count = susp->on_count = now + delay_len; + compute_start_rise(susp); + state = ST_FALL_UNTIL; + } else if (now == stop_count) { + state = ST_OFF; + value = susp->floor; + } else value *= susp->fall_factor; + break; + /* fall until start_rise while looking for next fall time */ + case ST_FALL_UNTIL: + value *= susp->fall_factor; + if (future >= threshold) { + off_count = now + delay_len; + } + if (now >= susp->start_rise) { + state = ST_RISE; + } else if (now >= stop_count) { + state = ST_OFF_UNTIL; + value = susp->floor; + } + break; + /* hold at floor (minimum value) and look for next rise time */ + case ST_OFF: + if (future >= threshold) { + off_count = susp->on_count = now + delay_len; + compute_start_rise(susp); + state = ST_OFF_UNTIL; + } + break; + /* hold at floor until start_rise while looking for next fall time */ + case ST_OFF_UNTIL: + if (future >= threshold) { + off_count = now + delay_len; + } + if (now >= susp->start_rise) { + state = ST_RISE; + } + break; + /* rise while looking for fall time */ + case ST_RISE: + value *= susp->rise_factor; + if (future >= threshold) { + off_count = now + delay_len; + } + if (now >= susp->on_count) { + value = 1.0; + state = ST_HOLD; + } + break; } - break; - /* fall until stop_count while looking for next rise time */ - case ST_FALL: - if (future >= threshold) { - off_count = susp->on_count = now + delay_len; - compute_start_rise(susp); - state = ST_FALL_UNTIL; - } else if (now == stop_count) { - state = ST_OFF; - value = susp->floor; - } else value *= susp->fall_factor; - break; - /* fall until start_rise while looking for next fall time */ - case ST_FALL_UNTIL: - value *= susp->fall_factor; - if (future >= threshold) { - off_count = now + delay_len; - } - if (now >= susp->start_rise) { - state = ST_RISE; - } else if (now >= stop_count) { - state = ST_OFF_UNTIL; - value = susp->floor; - } - break; - /* hold at floor (minimum value) and look for next rise time */ - case ST_OFF: - if (future >= threshold) { - off_count = susp->on_count = now + delay_len; - compute_start_rise(susp); - state = ST_OFF_UNTIL; - } - break; - /* hold at floor until start_rise while looking for next fall time */ - case ST_OFF_UNTIL: - if (future >= threshold) { - off_count = now + delay_len; - } - if (now >= susp->start_rise) { - state = ST_RISE; - } - break; - /* rise while looking for fall time */ - case ST_RISE: - value *= susp->rise_factor; - if (future >= threshold) { - off_count = now + delay_len; - } - if (now >= susp->on_count) { - value = 1.0; - state = ST_HOLD; - } - break; - } - output = (sample_type) value; - }") + output = (sample_type) value; + }") ) diff --git a/lib-src/libnyquist/nyquist/tran/gate.c b/lib-src/libnyquist/nyquist/tran/gate.c index eec4a9d5f..8172e1d9d 100644 --- a/lib-src/libnyquist/nyquist/tran/gate.c +++ b/lib-src/libnyquist/nyquist/tran/gate.c @@ -9,7 +9,7 @@ #include "cext.h" #include "gate.h" -void gate_free(); +void gate_free(snd_susp_type a_susp); typedef struct gate_susp_struct { @@ -43,24 +43,27 @@ typedef struct gate_susp_struct { #define ST_RISE 5 /* Overview: -This operation generates an exponential rise and decay suitable for implementing a -noise gate. The decay starts when the signal drops below threshold and stays there -for longer than lookahead. -Decay continues until the value reaches floor, at which point the decay stops -and the value is held constant. Either during the decay or after the floor is reached, -if the signal goes above threshold, then the output value will rise to 1.0 (0dB) at -the point the signal crosses the threshold. Again, lookahead is used, so the rise -actually starts before the signal crosses the threshold. The rise rate is constant -and set so that a rise from floor to 0dB occurs in the specified risetime. Similarly, -the fall rate is constant such that a fall from 0dB to the floor takes falltime. +This operation generates an exponential rise and decay suitable for +implementing a noise gate. The decay starts when the signal drops +below threshold and stays there for longer than lookahead. +Decay continues until the value reaches floor, at which point the +decay stops and the value is held constant. Either during the decay +or after the floor is reached, if the signal goes above threshold, +then the output value will rise to 1.0 (0dB) at the point the +signal crosses the threshold. Again, lookahead is used, so the rise +actually starts before the signal crosses the threshold. The rise +rate is constant and set so that a rise from floor to 0dB occurs +in the specified risetime. Similarly, the fall rate is constant +such that a fall from 0dB to the floor takes falltime. -Rather than looking ahead, the output actually lags the input by lookahead. The caller -should advance the time of the input signal in order to get a correct output signal, -and this will be taken care of in Lisp code. +Rather than looking ahead, the output actually lags the input by +lookahead. The caller should advance the time of the input signal +in order to get a correct output signal, and this will be taken +care of in Lisp code. -The implementation is a finite-state machine that simultaneously computes the value -and scans ahead for threshold crossings. Time points, remembered as sample counts are -saved in variables: +The implementation is a finite-state machine that simultaneously +computes the value and scans ahead for threshold crossings. Time +points, remembered as sample counts are saved in variables: on_count -- the time at which the rise should complete off_count -- the time at which the fall should begin rise_factor -- multiply by this to get exponential rise @@ -103,8 +106,9 @@ void compute_start_rise(gate_susp_type susp) } -void gate_n_fetch(register gate_susp_type susp, snd_list_type snd_list) +void gate_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + gate_susp_type susp = (gate_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -137,6 +141,7 @@ void gate_n_fetch(register gate_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -150,76 +155,76 @@ void gate_n_fetch(register gate_susp_type susp, snd_list_type snd_list) signal_ptr_reg = susp->signal_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ - sample_type future = *signal_ptr_reg++; - long now = susp->susp.current + cnt + togo - n; - - switch (state_reg) { - /* hold at 1.0 and look for the moment to begin fall: */ - case ST_HOLD: - if (future >= threshold_reg) { - off_count_reg = now + delay_len_reg; - } else if (now >= off_count_reg) { - state_reg = ST_FALL; - stop_count_reg = (long) (now + susp->fall_time); - susp->start_fall = now; + { + sample_type future = *signal_ptr_reg++; + long now = susp->susp.current + cnt + togo - n; + + switch (state_reg) { + /* hold at 1.0 and look for the moment to begin fall: */ + case ST_HOLD: + if (future >= threshold_reg) { + off_count_reg = now + delay_len_reg; + } else if (now >= off_count_reg) { + state_reg = ST_FALL; + stop_count_reg = (long) (now + susp->fall_time); + susp->start_fall = now; + } + break; + /* fall until stop_count_reg while looking for next rise time */ + case ST_FALL: + if (future >= threshold_reg) { + off_count_reg = susp->on_count = now + delay_len_reg; + compute_start_rise(susp); + state_reg = ST_FALL_UNTIL; + } else if (now == stop_count_reg) { + state_reg = ST_OFF; + value_reg = susp->floor; + } else value_reg *= susp->fall_factor; + break; + /* fall until start_rise while looking for next fall time */ + case ST_FALL_UNTIL: + value_reg *= susp->fall_factor; + if (future >= threshold_reg) { + off_count_reg = now + delay_len_reg; + } + if (now >= susp->start_rise) { + state_reg = ST_RISE; + } else if (now >= stop_count_reg) { + state_reg = ST_OFF_UNTIL; + value_reg = susp->floor; + } + break; + /* hold at floor (minimum value_reg) and look for next rise time */ + case ST_OFF: + if (future >= threshold_reg) { + off_count_reg = susp->on_count = now + delay_len_reg; + compute_start_rise(susp); + state_reg = ST_OFF_UNTIL; + } + break; + /* hold at floor until start_rise while looking for next fall time */ + case ST_OFF_UNTIL: + if (future >= threshold_reg) { + off_count_reg = now + delay_len_reg; + } + if (now >= susp->start_rise) { + state_reg = ST_RISE; + } + break; + /* rise while looking for fall time */ + case ST_RISE: + value_reg *= susp->rise_factor; + if (future >= threshold_reg) { + off_count_reg = now + delay_len_reg; + } + if (now >= susp->on_count) { + value_reg = 1.0; + state_reg = ST_HOLD; + } + break; } - break; - /* fall until stop_count_reg while looking for next rise time */ - case ST_FALL: - if (future >= threshold_reg) { - off_count_reg = susp->on_count = now + delay_len_reg; - compute_start_rise(susp); - state_reg = ST_FALL_UNTIL; - } else if (now == stop_count_reg) { - state_reg = ST_OFF; - value_reg = susp->floor; - } else value_reg *= susp->fall_factor; - break; - /* fall until start_rise while looking for next fall time */ - case ST_FALL_UNTIL: - value_reg *= susp->fall_factor; - if (future >= threshold_reg) { - off_count_reg = now + delay_len_reg; - } - if (now >= susp->start_rise) { - state_reg = ST_RISE; - } else if (now >= stop_count_reg) { - state_reg = ST_OFF_UNTIL; - value_reg = susp->floor; - } - break; - /* hold at floor (minimum value_reg) and look for next rise time */ - case ST_OFF: - if (future >= threshold_reg) { - off_count_reg = susp->on_count = now + delay_len_reg; - compute_start_rise(susp); - state_reg = ST_OFF_UNTIL; - } - break; - /* hold at floor until start_rise while looking for next fall time */ - case ST_OFF_UNTIL: - if (future >= threshold_reg) { - off_count_reg = now + delay_len_reg; - } - if (now >= susp->start_rise) { - state_reg = ST_RISE; - } - break; - /* rise while looking for fall time */ - case ST_RISE: - value_reg *= susp->rise_factor; - if (future >= threshold_reg) { - off_count_reg = now + delay_len_reg; - } - if (now >= susp->on_count) { - value_reg = 1.0; - state_reg = ST_HOLD; - } - break; - } - *out_ptr_reg++ = (sample_type) value_reg; - }; + *out_ptr_reg++ = (sample_type) value_reg; + }; } while (--n); /* inner loop */ togo -= n; @@ -244,11 +249,9 @@ void gate_n_fetch(register gate_susp_type susp, snd_list_type snd_list) } /* gate_n_fetch */ -void gate_toss_fetch(susp, snd_list) - register gate_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void gate_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + gate_susp_type susp = (gate_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -263,25 +266,28 @@ void gate_toss_fetch(susp, snd_list) susp->signal_ptr += n; susp_took(signal_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void gate_mark(gate_susp_type susp) +void gate_mark(snd_susp_type a_susp) { + gate_susp_type susp = (gate_susp_type) a_susp; sound_xlmark(susp->signal); } -void gate_free(gate_susp_type susp) +void gate_free(snd_susp_type a_susp) { + gate_susp_type susp = (gate_susp_type) a_susp; sound_unref(susp->signal); ffree_generic(susp, sizeof(gate_susp_node), "gate_free"); } -void gate_print_tree(gate_susp_type susp, int n) +void gate_print_tree(snd_susp_type a_susp, int n) { + gate_susp_type susp = (gate_susp_type) a_susp; indent(n); stdputstr("signal:"); sound_print_tree_1(susp->signal, n); @@ -293,7 +299,6 @@ sound_type snd_make_gate(sound_type signal, time_type lookahead, double risetime register gate_susp_type susp; rate_type sr = signal->sr; time_type t0 = signal->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; /* combine scale factors of linear inputs (SIGNAL) */ @@ -327,8 +332,8 @@ sound_type snd_make_gate(sound_type signal, time_type lookahead, double risetime /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = gate_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = gate_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/generate-defines.lsp b/lib-src/libnyquist/nyquist/tran/generate-defines.lsp new file mode 100644 index 000000000..28d385d9a --- /dev/null +++ b/lib-src/libnyquist/nyquist/tran/generate-defines.lsp @@ -0,0 +1,57 @@ +;; generate-defines.lsp +;; +;; Roger B. Dannenberg +;; July 2012 +;; +;; + + +;; GENERATE-DEFINES -- generate INTERP_xxx defines for sound.h +;; +;; n is number of parameters +;; +(defun generate-defines (n) + (let ((count (int-power 2 n)) + sum code pos) + (dotimes (i count) + (format t "#define INTERP_") + (setf sum 0) + (dotimes (j n) + (setf pos (- n 1 j)) ; bit position + (cond ((testbit i pos) + (setf code "s") + (setf sum (+ sum (int-power 4 pos)))) + (t + (setf code "n"))) + (format t "~A" code)) + (format t " ~A~%" sum)))) + + +(defun get-int-field (n pos len) +;; from integer n, extract len bits starting at pos, +;; e.g. (get-int-field 0x1234 8 4) -> 2 +;; pos for low-order bit is 0; the low order bit returned +;; is at pos; the high-order bit is at pos + len - 1 + (setf n (/ n (int-power 2 pos))) + (setf n (rem n (int-power 2 len))) + n) + + +(defun generate-full-defines (n) + (let ((count (int-power 4 n)) + code pos fld) + (dotimes (i count) + (format t "#define INTERP_") + (setf sum 0) + (dotimes (j n) + (setf pos (* 2 (- n 1 j))) ; bit position + (setf fld (get-int-field i pos 2)) + (setf code (char "nsir" fld)) + (format t "~A" code)) + (format t " ~A~%" i)))) + + +(defun int-power (i exponent) (truncate (+ 0.5 (power i exponent)))) +(defun testbit (n pos) (/= 0 (logand n (int-power 2 pos)))) + +(generate-full-defines 4) diff --git a/lib-src/libnyquist/nyquist/tran/ifft.alg b/lib-src/libnyquist/nyquist/tran/ifft.alg index c63435186..a5846413f 100644 --- a/lib-src/libnyquist/nyquist/tran/ifft.alg +++ b/lib-src/libnyquist/nyquist/tran/ifft.alg @@ -168,15 +168,13 @@ out: togo = 0; /* indicate termination */ susp->outbuf[i] += susp->samples[i]; } } - togo = min(togo, susp->stepsize - susp->index); -") - (INNER-LOOP "output = outbuf[index++];") + togo = min(togo, susp->stepsize - susp->index);\n") + (INNER-LOOP "output = outbuf[index++]") (CONSTANT "length" "samples" "array" "src" "window") (TERMINATE COMPUTED) (FINALIZATION " if (susp->samples) free(susp->samples); if (susp->table) table_unref(susp->table); - if (susp->outbuf) free(susp->outbuf); -") + if (susp->outbuf) free(susp->outbuf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/ifft.c b/lib-src/libnyquist/nyquist/tran/ifft.c index 3165f156a..5c6c922b6 100644 --- a/lib-src/libnyquist/nyquist/tran/ifft.c +++ b/lib-src/libnyquist/nyquist/tran/ifft.c @@ -1,6 +1,4 @@ #include "stdio.h" -#define _USE_MATH_DEFINES 1 /* for Visual C++ to get M_LN2 */ -#include #ifndef mips #include "stdlib.h" #endif @@ -11,7 +9,7 @@ #include "cext.h" #include "ifft.h" -void ifft_free(); +void ifft_free(snd_susp_type a_susp); typedef struct ifft_susp_struct { @@ -85,8 +83,9 @@ table_type get_window_samples(LVAL window, sample_type **samples, long *len) } -void ifft__fetch(register ifft_susp_type susp, snd_list_type snd_list) +void ifft__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + ifft_susp_type susp = (ifft_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -174,7 +173,7 @@ out: togo = 0; /* indicate termination */ /* here is where the IFFT and windowing should take place */ //fftnf(1, &n, susp->samples, susp->samples + n, -1, 1.0); - m = round(log(n) / M_LN2); + m = round(log2(n)); if (!fftInit(m)) riffts(susp->samples, m, 1); else xlfail("FFT initialization error"); if (susp->window) { @@ -208,7 +207,7 @@ out: togo = 0; /* indicate termination */ outbuf_reg = susp->outbuf; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = outbuf_reg[index_reg++];; + *out_ptr_reg++ = outbuf_reg[index_reg++]; } while (--n); /* inner loop */ susp->index = index_reg; @@ -227,15 +226,17 @@ out: togo = 0; /* indicate termination */ } /* ifft__fetch */ -void ifft_mark(ifft_susp_type susp) +void ifft_mark(snd_susp_type a_susp) { + ifft_susp_type susp = (ifft_susp_type) a_susp; if (susp->src) mark(susp->src); if (susp->array) mark(susp->array); } -void ifft_free(ifft_susp_type susp) +void ifft_free(snd_susp_type a_susp) { + ifft_susp_type susp = (ifft_susp_type) a_susp; if (susp->samples) free(susp->samples); if (susp->table) table_unref(susp->table); if (susp->outbuf) free(susp->outbuf); @@ -243,7 +244,7 @@ void ifft_free(ifft_susp_type susp) } -void ifft_print_tree(ifft_susp_type susp, int n) +void ifft_print_tree(snd_susp_type a_susp, int n) { } diff --git a/lib-src/libnyquist/nyquist/tran/init.lsp b/lib-src/libnyquist/nyquist/tran/init.lsp index ac49ca130..6957222d2 100644 --- a/lib-src/libnyquist/nyquist/tran/init.lsp +++ b/lib-src/libnyquist/nyquist/tran/init.lsp @@ -4,8 +4,12 @@ (load "../runtime/misc.lsp") -;; set to T to get interpolation within inner loops -(setf *INLINE-INTERPOLATION* nil) +;; set to T to get interpolation within inner loops, +;; inline interpolation adds about 10% to code size and +;; should increase performance substantially when using +;; "light" primitives such as time-varying filters and +;; multiplies with envelopes +(setf *INLINE-INTERPOLATION* T) ;; set to T to get ANSI headers and NIL to get antique headers (setf *ANSI* NIL) @@ -22,3 +26,5 @@ (setf *gc-flag* t) (setf *watch* nil) + +(print "Assuming you ran Nyquist in nyquist/tran, type (m) to regenerate all source code from .alg files") diff --git a/lib-src/libnyquist/nyquist/tran/instrbanded.alg b/lib-src/libnyquist/nyquist/tran/instrbanded.alg index 49345d98f..f099644cd 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbanded.alg +++ b/lib-src/libnyquist/nyquist/tran/instrbanded.alg @@ -1,24 +1,22 @@ (INSTRBANDED-ALG (NAME "bandedwg") -(ARGUMENTS ("double" "freq") ("sound_type" "bowpress_env") ("int" "preset")("rate_type" "sr")) +(ARGUMENTS ("double" "freq") ("sound_type" "bowpress_env") ("int" "preset") + ("rate_type" "sr")) (STATE ("struct instr *" "mybanded" "initInstrument(BANDEDWG, round(sr)); controlChange(susp->mybanded, 16, preset);") - ("int" "temp_ret_value" "noteOn(susp->mybanded, freq, 1.0)")) + ("int" "temp_ret_value" "noteOn(susp->mybanded, freq, 1.0)") + ("float" "bowpress_scale" + "bowpress_env->scale * BANDEDWG_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING bowpress_env) (START (min bowpress_env)) (NOT-IN-INNER-LOOP "freq" "temp_ret_value" "preset") +(CONSTANT "bowpress_scale") (SAMPLE-RATE "sr") -(ALWAYS-SCALE bowpress_env) (TERMINATE (min bowpress_env)) -(INNER-LOOP " - controlChange(mybanded, 2, BANDEDWG_CONTROL_CHANGE_CONST * bowpress_env); - output = (sample_type) tick(mybanded)") -(SUPPORT-HEADER " - #define BANDEDWG_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->mybanded); -") +(INNER-LOOP "controlChange(mybanded, 2, bowpress_scale * bowpress_env); + output = (sample_type) tick(mybanded)") +(SUPPORT-HEADER "#define BANDEDWG_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->mybanded);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrbanded.c b/lib-src/libnyquist/nyquist/tran/instrbanded.c index 585bcfc57..eeaaedb07 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbanded.c +++ b/lib-src/libnyquist/nyquist/tran/instrbanded.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrbanded.h" -void bandedwg_free(); +void bandedwg_free(snd_susp_type a_susp); typedef struct bandedwg_susp_struct { @@ -21,14 +21,16 @@ typedef struct bandedwg_susp_struct { struct instr *mybanded; int temp_ret_value; + float bowpress_scale; } bandedwg_susp_node, *bandedwg_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void bandedwg_s_fetch(register bandedwg_susp_type susp, snd_list_type snd_list) +void bandedwg_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + bandedwg_susp_type susp = (bandedwg_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -38,9 +40,9 @@ void bandedwg_s_fetch(register bandedwg_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * mybanded_reg; - register sample_type bowpress_env_scale_reg = susp->bowpress_env->scale; + register float bowpress_scale_reg; register sample_block_values_type bowpress_env_ptr_reg; - falloc_sample_block(out, "bandedwg_s_fetch"); + falloc_sample_block(out, "bandedwg_n_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -57,17 +59,18 @@ void bandedwg_s_fetch(register bandedwg_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; mybanded_reg = susp->mybanded; + bowpress_scale_reg = susp->bowpress_scale; bowpress_env_ptr_reg = susp->bowpress_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(mybanded_reg, 2, BANDEDWG_CONTROL_CHANGE_CONST * (bowpress_env_scale_reg * *bowpress_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(mybanded_reg); + controlChange(mybanded_reg, 2, bowpress_scale_reg * *bowpress_env_ptr_reg++); + *out_ptr_reg++ = (sample_type) tick(mybanded_reg); } while (--n); /* inner loop */ susp->mybanded = mybanded_reg; @@ -85,14 +88,12 @@ void bandedwg_s_fetch(register bandedwg_susp_type susp, snd_list_type snd_list) snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* bandedwg_s_fetch */ +} /* bandedwg_n_fetch */ -void bandedwg_toss_fetch(susp, snd_list) - register bandedwg_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void bandedwg_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + bandedwg_susp_type susp = (bandedwg_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -107,27 +108,29 @@ void bandedwg_toss_fetch(susp, snd_list) susp->bowpress_env_ptr += n; susp_took(bowpress_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void bandedwg_mark(bandedwg_susp_type susp) +void bandedwg_mark(snd_susp_type a_susp) { + bandedwg_susp_type susp = (bandedwg_susp_type) a_susp; sound_xlmark(susp->bowpress_env); } -void bandedwg_free(bandedwg_susp_type susp) +void bandedwg_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mybanded); + bandedwg_susp_type susp = (bandedwg_susp_type) a_susp; + deleteInstrument(susp->mybanded); sound_unref(susp->bowpress_env); ffree_generic(susp, sizeof(bandedwg_susp_node), "bandedwg_free"); } -void bandedwg_print_tree(bandedwg_susp_type susp, int n) +void bandedwg_print_tree(snd_susp_type a_susp, int n) { + bandedwg_susp_type susp = (bandedwg_susp_type) a_susp; indent(n); stdputstr("bowpress_env:"); sound_print_tree_1(susp->bowpress_env, n); @@ -139,14 +142,20 @@ sound_type snd_make_bandedwg(double freq, sound_type bowpress_env, int preset, r register bandedwg_susp_type susp; /* sr specified as input parameter */ time_type t0 = bowpress_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, bandedwg_susp_node, "snd_make_bandedwg"); susp->mybanded = initInstrument(BANDEDWG, round(sr)); controlChange(susp->mybanded, 16, preset);; susp->temp_ret_value = noteOn(susp->mybanded, freq, 1.0); - susp->susp.fetch = bandedwg_s_fetch; + susp->bowpress_scale = bowpress_env->scale * BANDEDWG_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (bowpress_env->sr > sr) { + sound_unref(bowpress_env); + snd_badsr(); + } else if (bowpress_env->sr < sr) bowpress_env = snd_make_up(sr, bowpress_env); + susp->susp.fetch = bandedwg_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < bowpress_env->t0) sound_prepend_zeros(bowpress_env, t0); @@ -155,8 +164,8 @@ sound_type snd_make_bandedwg(double freq, sound_type bowpress_env, int preset, r /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = bandedwg_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = bandedwg_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrbanded.h b/lib-src/libnyquist/nyquist/tran/instrbanded.h index f582d9e57..99970dc94 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbanded.h +++ b/lib-src/libnyquist/nyquist/tran/instrbanded.h @@ -1,5 +1,4 @@ sound_type snd_make_bandedwg(double freq, sound_type bowpress_env, int preset, rate_type sr); sound_type snd_bandedwg(double freq, sound_type bowpress_env, int preset, rate_type sr); /* LISP: (snd-bandedwg ANYNUM SOUND FIXNUM ANYNUM) */ - - #define BANDEDWG_CONTROL_CHANGE_CONST 128 +#define BANDEDWG_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrbow.alg b/lib-src/libnyquist/nyquist/tran/instrbow.alg index 315eb549d..1ddf37bba 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbow.alg +++ b/lib-src/libnyquist/nyquist/tran/instrbow.alg @@ -3,23 +3,18 @@ (ARGUMENTS ("double" "freq") ("sound_type" "bowpress_env") ("rate_type" "sr")) (STATE ("struct instr *" "mybow" "initInstrument(BOWED, round(sr)); controlChange(susp->mybow, 1, 0.0);") - ("int" "temp_ret_value" "noteOn(susp->mybow, freq, 1.0)")) + ("int" "temp_ret_value" "noteOn(susp->mybow, freq, 1.0)") + ("float" "bow_scale" "bowpress_env->scale * BOW_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING bowpress_env) (START (min bowpress_env)) (NOT-IN-INNER-LOOP "freq" "temp_ret_value") +(CONSTANT "bow_scale") (SAMPLE-RATE "sr") -(ALWAYS-SCALE bowpress_env) (TERMINATE (min bowpress_env)) -(INNER-LOOP " - controlChange(mybow, 128, BOW_CONTROL_CHANGE_CONST * bowpress_env); - output = (sample_type) tick(mybow)") -(SUPPORT-HEADER " - #define BOW_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->mybow); -") +(INNER-LOOP "controlChange(mybow, 128, bow_scale * bowpress_env); + output = (sample_type) tick(mybow)") +(SUPPORT-HEADER "#define BOW_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->mybow);\n") ) - diff --git a/lib-src/libnyquist/nyquist/tran/instrbow.c b/lib-src/libnyquist/nyquist/tran/instrbow.c index b9cc841de..7672d21bf 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbow.c +++ b/lib-src/libnyquist/nyquist/tran/instrbow.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrbow.h" -void bowed_free(); +void bowed_free(snd_susp_type a_susp); typedef struct bowed_susp_struct { @@ -21,14 +21,16 @@ typedef struct bowed_susp_struct { struct instr *mybow; int temp_ret_value; + float bow_scale; } bowed_susp_node, *bowed_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void bowed_s_fetch(register bowed_susp_type susp, snd_list_type snd_list) +void bowed_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + bowed_susp_type susp = (bowed_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -38,9 +40,9 @@ void bowed_s_fetch(register bowed_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * mybow_reg; - register sample_type bowpress_env_scale_reg = susp->bowpress_env->scale; + register float bow_scale_reg; register sample_block_values_type bowpress_env_ptr_reg; - falloc_sample_block(out, "bowed_s_fetch"); + falloc_sample_block(out, "bowed_n_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -57,17 +59,18 @@ void bowed_s_fetch(register bowed_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; mybow_reg = susp->mybow; + bow_scale_reg = susp->bow_scale; bowpress_env_ptr_reg = susp->bowpress_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(mybow_reg, 128, BOW_CONTROL_CHANGE_CONST * (bowpress_env_scale_reg * *bowpress_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(mybow_reg); + controlChange(mybow_reg, 128, bow_scale_reg * *bowpress_env_ptr_reg++); + *out_ptr_reg++ = (sample_type) tick(mybow_reg); } while (--n); /* inner loop */ susp->mybow = mybow_reg; @@ -85,14 +88,12 @@ void bowed_s_fetch(register bowed_susp_type susp, snd_list_type snd_list) snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* bowed_s_fetch */ +} /* bowed_n_fetch */ -void bowed_toss_fetch(susp, snd_list) - register bowed_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void bowed_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + bowed_susp_type susp = (bowed_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -107,27 +108,29 @@ void bowed_toss_fetch(susp, snd_list) susp->bowpress_env_ptr += n; susp_took(bowpress_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void bowed_mark(bowed_susp_type susp) +void bowed_mark(snd_susp_type a_susp) { + bowed_susp_type susp = (bowed_susp_type) a_susp; sound_xlmark(susp->bowpress_env); } -void bowed_free(bowed_susp_type susp) +void bowed_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mybow); + bowed_susp_type susp = (bowed_susp_type) a_susp; + deleteInstrument(susp->mybow); sound_unref(susp->bowpress_env); ffree_generic(susp, sizeof(bowed_susp_node), "bowed_free"); } -void bowed_print_tree(bowed_susp_type susp, int n) +void bowed_print_tree(snd_susp_type a_susp, int n) { + bowed_susp_type susp = (bowed_susp_type) a_susp; indent(n); stdputstr("bowpress_env:"); sound_print_tree_1(susp->bowpress_env, n); @@ -139,14 +142,20 @@ sound_type snd_make_bowed(double freq, sound_type bowpress_env, rate_type sr) register bowed_susp_type susp; /* sr specified as input parameter */ time_type t0 = bowpress_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, bowed_susp_node, "snd_make_bowed"); susp->mybow = initInstrument(BOWED, round(sr)); controlChange(susp->mybow, 1, 0.0);; susp->temp_ret_value = noteOn(susp->mybow, freq, 1.0); - susp->susp.fetch = bowed_s_fetch; + susp->bow_scale = bowpress_env->scale * BOW_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (bowpress_env->sr > sr) { + sound_unref(bowpress_env); + snd_badsr(); + } else if (bowpress_env->sr < sr) bowpress_env = snd_make_up(sr, bowpress_env); + susp->susp.fetch = bowed_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < bowpress_env->t0) sound_prepend_zeros(bowpress_env, t0); @@ -155,8 +164,8 @@ sound_type snd_make_bowed(double freq, sound_type bowpress_env, rate_type sr) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = bowed_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = bowed_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrbow.h b/lib-src/libnyquist/nyquist/tran/instrbow.h index 2da6d16f3..cb8718fd7 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbow.h +++ b/lib-src/libnyquist/nyquist/tran/instrbow.h @@ -1,5 +1,4 @@ sound_type snd_make_bowed(double freq, sound_type bowpress_env, rate_type sr); sound_type snd_bowed(double freq, sound_type bowpress_env, rate_type sr); /* LISP: (snd-bowed ANYNUM SOUND ANYNUM) */ - - #define BOW_CONTROL_CHANGE_CONST 128 +#define BOW_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.alg b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.alg index dca0b469a..57ad0299d 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.alg +++ b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.alg @@ -1,28 +1,24 @@ (INSTRBOWED-FREQ-ALG (NAME "bowed_freq") (ARGUMENTS ("double" "freq") ("sound_type" "bowpress_env") - ("sound_type" "freq_env") ("rate_type" "sr")) + ("sound_type" "freq_env") ("rate_type" "sr")) (STATE ("struct instr *" "mybow" "initInstrument(BOWED, round(sr)); controlChange(susp->mybow, 1, 0.0);") ("int" "temp_ret_value" "noteOn(susp->mybow, freq, 1.0)") - ("double" "frequency" "freq")) + ("float" "bow_scale" "bowpress_env->scale * BOW_CONTROL_CHANGE_CONST") + ("double" "frequency" "freq")) +(INLINE-INTERPOLATION no) +(ALWAYS-SCALE freq_env) +(INTERNAL-SCALING bowpress_env) (START (min bowpress_env)) (NOT-IN-INNER-LOOP "temp_ret_value") -(CONSTANT "frequency") +(CONSTANT "frequency" "bow_scale") (SAMPLE-RATE "sr") -(MATCHED-SAMPLE-RATE freq_env bowpress_env) (TERMINATE (min bowpress_env)) -(INNER-LOOP " - controlChange(mybow, 128, BOW_CONTROL_CHANGE_CONST * bowpress_env); +(INNER-LOOP "controlChange(mybow, 128, bow_scale * bowpress_env); setFrequency(mybow, frequency + freq_env); - output = (sample_type) tick(mybow)") -(SUPPORT-HEADER " - #define BOW_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->mybow); -") + output = (sample_type) tick(mybow)") +(SUPPORT-HEADER "#define BOW_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->mybow);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.c b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.c index 99961bbbb..178184f07 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.c +++ b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrbowedfreq.h" -void bowed_freq_free(); +void bowed_freq_free(snd_susp_type a_susp); typedef struct bowed_freq_susp_struct { @@ -24,87 +24,17 @@ typedef struct bowed_freq_susp_struct { struct instr *mybow; int temp_ret_value; + float bow_scale; double frequency; } bowed_freq_susp_node, *bowed_freq_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void bowed_freq_nn_fetch(register bowed_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * mybow_reg; - register double frequency_reg; - register sample_block_values_type freq_env_ptr_reg; - register sample_block_values_type bowpress_env_ptr_reg; - falloc_sample_block(out, "bowed_freq_nn_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the bowpress_env input sample block: */ - susp_check_term_samples(bowpress_env, bowpress_env_ptr, bowpress_env_cnt); - togo = min(togo, susp->bowpress_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - mybow_reg = susp->mybow; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - bowpress_env_ptr_reg = susp->bowpress_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(mybow_reg, 128, BOW_CONTROL_CHANGE_CONST * *bowpress_env_ptr_reg++); - setFrequency(mybow_reg, frequency_reg + *freq_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(mybow_reg); - } while (--n); /* inner loop */ - - susp->mybow = mybow_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using bowpress_env_ptr_reg is a bad idea on RS/6000: */ - susp->bowpress_env_ptr += togo; - out_ptr += togo; - susp_took(bowpress_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* bowed_freq_nn_fetch */ - - -void bowed_freq_ss_fetch(register bowed_freq_susp_type susp, snd_list_type snd_list) +void bowed_freq_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + bowed_freq_susp_type susp = (bowed_freq_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -114,12 +44,12 @@ void bowed_freq_ss_fetch(register bowed_freq_susp_type susp, snd_list_type snd_l register sample_block_values_type out_ptr_reg; register struct instr * mybow_reg; + register float bow_scale_reg; register double frequency_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type bowpress_env_scale_reg = susp->bowpress_env->scale; register sample_block_values_type bowpress_env_ptr_reg; - falloc_sample_block(out, "bowed_freq_ss_fetch"); + falloc_sample_block(out, "bowed_freq_ns_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -140,20 +70,21 @@ void bowed_freq_ss_fetch(register bowed_freq_susp_type susp, snd_list_type snd_l if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; mybow_reg = susp->mybow; + bow_scale_reg = susp->bow_scale; frequency_reg = susp->frequency; freq_env_ptr_reg = susp->freq_env_ptr; bowpress_env_ptr_reg = susp->bowpress_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(mybow_reg, 128, BOW_CONTROL_CHANGE_CONST * (bowpress_env_scale_reg * *bowpress_env_ptr_reg++)); + controlChange(mybow_reg, 128, bow_scale_reg * *bowpress_env_ptr_reg++); setFrequency(mybow_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(mybow_reg); + *out_ptr_reg++ = (sample_type) tick(mybow_reg); } while (--n); /* inner loop */ susp->mybow = mybow_reg; @@ -174,14 +105,12 @@ void bowed_freq_ss_fetch(register bowed_freq_susp_type susp, snd_list_type snd_l snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* bowed_freq_ss_fetch */ +} /* bowed_freq_ns_fetch */ -void bowed_freq_toss_fetch(susp, snd_list) - register bowed_freq_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void bowed_freq_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + bowed_freq_susp_type susp = (bowed_freq_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -204,29 +133,31 @@ void bowed_freq_toss_fetch(susp, snd_list) susp->freq_env_ptr += n; susp_took(freq_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void bowed_freq_mark(bowed_freq_susp_type susp) +void bowed_freq_mark(snd_susp_type a_susp) { + bowed_freq_susp_type susp = (bowed_freq_susp_type) a_susp; sound_xlmark(susp->bowpress_env); sound_xlmark(susp->freq_env); } -void bowed_freq_free(bowed_freq_susp_type susp) +void bowed_freq_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mybow); + bowed_freq_susp_type susp = (bowed_freq_susp_type) a_susp; + deleteInstrument(susp->mybow); sound_unref(susp->bowpress_env); sound_unref(susp->freq_env); ffree_generic(susp, sizeof(bowed_freq_susp_node), "bowed_freq_free"); } -void bowed_freq_print_tree(bowed_freq_susp_type susp, int n) +void bowed_freq_print_tree(snd_susp_type a_susp, int n) { + bowed_freq_susp_type susp = (bowed_freq_susp_type) a_susp; indent(n); stdputstr("bowpress_env:"); sound_print_tree_1(susp->bowpress_env, n); @@ -242,24 +173,25 @@ sound_type snd_make_bowed_freq(double freq, sound_type bowpress_env, sound_type register bowed_freq_susp_type susp; /* sr specified as input parameter */ time_type t0 = bowpress_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, bowed_freq_susp_node, "snd_make_bowed_freq"); susp->mybow = initInstrument(BOWED, round(sr)); controlChange(susp->mybow, 1, 0.0);; susp->temp_ret_value = noteOn(susp->mybow, freq, 1.0); + susp->bow_scale = bowpress_env->scale * BOW_CONTROL_CHANGE_CONST; susp->frequency = freq; - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(bowpress_env, sr); - interp_desc = (interp_desc << 2) + interp_style(freq_env, sr); - switch (interp_desc) { - case INTERP_nn: susp->susp.fetch = bowed_freq_nn_fetch; break; - case INTERP_ss: susp->susp.fetch = bowed_freq_ss_fetch; break; - default: snd_badsr(); break; - } - + /* make sure no sample rate is too high */ + if (bowpress_env->sr > sr) { + sound_unref(bowpress_env); + snd_badsr(); + } else if (bowpress_env->sr < sr) bowpress_env = snd_make_up(sr, bowpress_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + susp->susp.fetch = bowed_freq_ns_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < bowpress_env->t0) sound_prepend_zeros(bowpress_env, t0); @@ -269,8 +201,8 @@ sound_type snd_make_bowed_freq(double freq, sound_type bowpress_env, sound_type /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = bowed_freq_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = bowed_freq_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.h b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.h index 8b657c9ce..c47479a74 100644 --- a/lib-src/libnyquist/nyquist/tran/instrbowedfreq.h +++ b/lib-src/libnyquist/nyquist/tran/instrbowedfreq.h @@ -1,5 +1,4 @@ sound_type snd_make_bowed_freq(double freq, sound_type bowpress_env, sound_type freq_env, rate_type sr); sound_type snd_bowed_freq(double freq, sound_type bowpress_env, sound_type freq_env, rate_type sr); /* LISP: (snd-bowed_freq ANYNUM SOUND SOUND ANYNUM) */ - - #define BOW_CONTROL_CHANGE_CONST 128 +#define BOW_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrclar.alg b/lib-src/libnyquist/nyquist/tran/instrclar.alg index 71467923e..60bee5705 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclar.alg +++ b/lib-src/libnyquist/nyquist/tran/instrclar.alg @@ -3,23 +3,19 @@ (ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("rate_type" "sr")) (STATE ("struct instr *" "clar" "initInstrument(CLARINET, round(sr)); controlChange(susp->clar, 1, 0.0);") - ("int" "temp_ret_value" "noteOn(susp->clar, freq, 1.0)")) + ("int" "temp_ret_value" "noteOn(susp->clar, freq, 1.0)") + ("float" "breath_scale" "breath_env->scale * CLAR_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "freq" "temp_ret_value") +(CONSTANT "breath_scale") (SAMPLE-RATE "sr") -(ALWAYS-SCALE breath_env) (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(clar, 128, CLAR_CONTROL_CHANGE_CONST * breath_env); - output = (sample_type) tick(clar)") -(SUPPORT-HEADER " - #define CLAR_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->clar); -") +(INNER-LOOP "controlChange(clar, 128, breath_scale * breath_env); + output = (sample_type) tick(clar)") +(SUPPORT-HEADER "#define CLAR_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->clar);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrclar.c b/lib-src/libnyquist/nyquist/tran/instrclar.c index 8f9cb3862..ac7e10620 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclar.c +++ b/lib-src/libnyquist/nyquist/tran/instrclar.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrclar.h" -void clarinet_free(); +void clarinet_free(snd_susp_type a_susp); typedef struct clarinet_susp_struct { @@ -21,14 +21,16 @@ typedef struct clarinet_susp_struct { struct instr *clar; int temp_ret_value; + float breath_scale; } clarinet_susp_node, *clarinet_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void clarinet_s_fetch(register clarinet_susp_type susp, snd_list_type snd_list) +void clarinet_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + clarinet_susp_type susp = (clarinet_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -38,9 +40,9 @@ void clarinet_s_fetch(register clarinet_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * clar_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; + register float breath_scale_reg; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "clarinet_s_fetch"); + falloc_sample_block(out, "clarinet_n_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -57,17 +59,18 @@ void clarinet_s_fetch(register clarinet_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; clar_reg = susp->clar; + breath_scale_reg = susp->breath_scale; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(clar_reg, 128, CLAR_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(clar_reg); + controlChange(clar_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + *out_ptr_reg++ = (sample_type) tick(clar_reg); } while (--n); /* inner loop */ susp->clar = clar_reg; @@ -85,14 +88,12 @@ void clarinet_s_fetch(register clarinet_susp_type susp, snd_list_type snd_list) snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* clarinet_s_fetch */ +} /* clarinet_n_fetch */ -void clarinet_toss_fetch(susp, snd_list) - register clarinet_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void clarinet_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + clarinet_susp_type susp = (clarinet_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -107,27 +108,29 @@ void clarinet_toss_fetch(susp, snd_list) susp->breath_env_ptr += n; susp_took(breath_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void clarinet_mark(clarinet_susp_type susp) +void clarinet_mark(snd_susp_type a_susp) { + clarinet_susp_type susp = (clarinet_susp_type) a_susp; sound_xlmark(susp->breath_env); } -void clarinet_free(clarinet_susp_type susp) +void clarinet_free(snd_susp_type a_susp) { - - deleteInstrument(susp->clar); + clarinet_susp_type susp = (clarinet_susp_type) a_susp; + deleteInstrument(susp->clar); sound_unref(susp->breath_env); ffree_generic(susp, sizeof(clarinet_susp_node), "clarinet_free"); } -void clarinet_print_tree(clarinet_susp_type susp, int n) +void clarinet_print_tree(snd_susp_type a_susp, int n) { + clarinet_susp_type susp = (clarinet_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -139,14 +142,20 @@ sound_type snd_make_clarinet(double freq, sound_type breath_env, rate_type sr) register clarinet_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, clarinet_susp_node, "snd_make_clarinet"); susp->clar = initInstrument(CLARINET, round(sr)); controlChange(susp->clar, 1, 0.0);; susp->temp_ret_value = noteOn(susp->clar, freq, 1.0); - susp->susp.fetch = clarinet_s_fetch; + susp->breath_scale = breath_env->scale * CLAR_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + susp->susp.fetch = clarinet_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -155,8 +164,8 @@ sound_type snd_make_clarinet(double freq, sound_type breath_env, rate_type sr) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = clarinet_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = clarinet_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrclar.h b/lib-src/libnyquist/nyquist/tran/instrclar.h index 7408945e9..3f39796ec 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclar.h +++ b/lib-src/libnyquist/nyquist/tran/instrclar.h @@ -1,5 +1,4 @@ sound_type snd_make_clarinet(double freq, sound_type breath_env, rate_type sr); sound_type snd_clarinet(double freq, sound_type breath_env, rate_type sr); /* LISP: (snd-clarinet ANYNUM SOUND ANYNUM) */ - - #define CLAR_CONTROL_CHANGE_CONST 128 +#define CLAR_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrclarall.alg b/lib-src/libnyquist/nyquist/tran/instrclarall.alg index a10f26cad..8f89d38d5 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarall.alg +++ b/lib-src/libnyquist/nyquist/tran/instrclarall.alg @@ -9,36 +9,37 @@ ;; noise -- noise, Noise 4 ;; (NAME "clarinet_all") -(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("sound_type" "freq_env") - ("double" "vibrato_freq") ("double" "vibrato_gain") - ("sound_type" "reed_stiffness") ("sound_type" "noise") ("rate_type" "sr")) +(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") + ("sound_type" "freq_env") + ("double" "vibrato_freq") ("double" "vibrato_gain") + ("sound_type" "reed_stiffness") ("sound_type" "noise_env") + ("rate_type" "sr")) ;; use a constant rate of 1.0 because it will actually be conrolled ;; by breath_env (STATE ("struct instr *" "clar" "initInstrument(CLARINET, round(sr)); noteOn(susp->clar, freq, 1.0); controlChange(susp->clar, 11, CLAR_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->clar, 1, CLAR_CONTROL_CHANGE_CONST * vibrato_gain);") - ("double" "frequency" "freq")) + ("double" "frequency" "freq") + ("float" "breath_scale" "breath_env->scale * CLAR_CONTROL_CHANGE_CONST") + ("float" "reed_scale" "reed_stiffness->scale * CLAR_CONTROL_CHANGE_CONST") + ("float" "noise_scale" "noise_env->scale * CLAR_CONTROL_CHANGE_CONST")) (START (min breath_env)) -(MATCHED-SAMPLE-RATE freq_env breath_env reed_stiffness noise) -(ALWAYS-SCALE freq_env breath_env reed_stiffness noise) -(CONSTANT "frequency") +; matched doesn't help much because controlChange() is called in inner loop +;(MATCHED-SAMPLE-RATE freq_env breath_env reed_stiffness noise_env) +(ALWAYS-SCALE freq_env) +(INTERNAL-SCALING breath_env reed_stiffness noise_env) +(INLINE-INTERPOLATION no) +(CONSTANT "frequency" "breath_scale" "reed_scale" "noise_scale") (SAMPLE-RATE "sr") (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(clar, 128, CLAR_CONTROL_CHANGE_CONST * breath_env); - controlChange(clar, 2, CLAR_CONTROL_CHANGE_CONST * reed_stiffness); - controlChange(clar, 4, CLAR_CONTROL_CHANGE_CONST * noise); - setFrequency(clar, frequency + freq_env); - output = (sample_type) tick(clar)") -(SUPPORT-HEADER " - #define CLAR_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->clar); -") +(INNER-LOOP "controlChange(clar, 128, breath_scale * breath_env); + controlChange(clar, 2, reed_scale * reed_stiffness); + controlChange(clar, 4, noise_scale * noise_env); + setFrequency(clar, frequency + freq_env); + output = (sample_type) tick(clar)") +(SUPPORT-HEADER "#define CLAR_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->clar);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrclarall.c b/lib-src/libnyquist/nyquist/tran/instrclarall.c index 7b65cc198..e929673f2 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarall.c +++ b/lib-src/libnyquist/nyquist/tran/instrclarall.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrclarall.h" -void clarinet_all_free(); +void clarinet_all_free(snd_susp_type a_susp); typedef struct clarinet_all_susp_struct { @@ -24,20 +24,24 @@ typedef struct clarinet_all_susp_struct { sound_type reed_stiffness; long reed_stiffness_cnt; sample_block_values_type reed_stiffness_ptr; - sound_type noise; - long noise_cnt; - sample_block_values_type noise_ptr; + sound_type noise_env; + long noise_env_cnt; + sample_block_values_type noise_env_ptr; struct instr *clar; double frequency; + float breath_scale; + float reed_scale; + float noise_scale; } clarinet_all_susp_node, *clarinet_all_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void clarinet_all_ssss_fetch(register clarinet_all_susp_type susp, snd_list_type snd_list) +void clarinet_all_nsnn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + clarinet_all_susp_type susp = (clarinet_all_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -48,15 +52,15 @@ void clarinet_all_ssss_fetch(register clarinet_all_susp_type susp, snd_list_type register struct instr * clar_reg; register double frequency_reg; - register sample_type noise_scale_reg = susp->noise->scale; - register sample_block_values_type noise_ptr_reg; - register sample_type reed_stiffness_scale_reg = susp->reed_stiffness->scale; + register float breath_scale_reg; + register float reed_scale_reg; + register float noise_scale_reg; + register sample_block_values_type noise_env_ptr_reg; register sample_block_values_type reed_stiffness_ptr_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "clarinet_all_ssss_fetch"); + falloc_sample_block(out, "clarinet_all_nsnn_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -77,37 +81,40 @@ void clarinet_all_ssss_fetch(register clarinet_all_susp_type susp, snd_list_type susp_check_samples(reed_stiffness, reed_stiffness_ptr, reed_stiffness_cnt); togo = min(togo, susp->reed_stiffness_cnt); - /* don't run past the noise input sample block: */ - susp_check_samples(noise, noise_ptr, noise_cnt); - togo = min(togo, susp->noise_cnt); + /* don't run past the noise_env input sample block: */ + susp_check_samples(noise_env, noise_env_ptr, noise_env_cnt); + togo = min(togo, susp->noise_env_cnt); /* don't run past terminate time */ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; clar_reg = susp->clar; frequency_reg = susp->frequency; - noise_ptr_reg = susp->noise_ptr; + breath_scale_reg = susp->breath_scale; + reed_scale_reg = susp->reed_scale; + noise_scale_reg = susp->noise_scale; + noise_env_ptr_reg = susp->noise_env_ptr; reed_stiffness_ptr_reg = susp->reed_stiffness_ptr; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(clar_reg, 128, CLAR_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - controlChange(clar_reg, 2, CLAR_CONTROL_CHANGE_CONST * (reed_stiffness_scale_reg * *reed_stiffness_ptr_reg++)); - controlChange(clar_reg, 4, CLAR_CONTROL_CHANGE_CONST * (noise_scale_reg * *noise_ptr_reg++)); - setFrequency(clar_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(clar_reg); + controlChange(clar_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + controlChange(clar_reg, 2, reed_scale_reg * *reed_stiffness_ptr_reg++); + controlChange(clar_reg, 4, noise_scale_reg * *noise_env_ptr_reg++); + setFrequency(clar_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); + *out_ptr_reg++ = (sample_type) tick(clar_reg); } while (--n); /* inner loop */ susp->clar = clar_reg; - /* using noise_ptr_reg is a bad idea on RS/6000: */ - susp->noise_ptr += togo; + /* using noise_env_ptr_reg is a bad idea on RS/6000: */ + susp->noise_env_ptr += togo; /* using reed_stiffness_ptr_reg is a bad idea on RS/6000: */ susp->reed_stiffness_ptr += togo; /* using freq_env_ptr_reg is a bad idea on RS/6000: */ @@ -118,7 +125,7 @@ void clarinet_all_ssss_fetch(register clarinet_all_susp_type susp, snd_list_type susp_took(breath_env_cnt, togo); susp_took(freq_env_cnt, togo); susp_took(reed_stiffness_cnt, togo); - susp_took(noise_cnt, togo); + susp_took(noise_env_cnt, togo); cnt += togo; } /* outer loop */ @@ -129,14 +136,12 @@ void clarinet_all_ssss_fetch(register clarinet_all_susp_type susp, snd_list_type snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* clarinet_all_ssss_fetch */ +} /* clarinet_all_nsnn_fetch */ -void clarinet_all_toss_fetch(susp, snd_list) - register clarinet_all_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void clarinet_all_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + clarinet_all_susp_type susp = (clarinet_all_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -152,10 +157,10 @@ void clarinet_all_toss_fetch(susp, snd_list) while ((round((final_time - susp->reed_stiffness->t0) * susp->reed_stiffness->sr)) >= susp->reed_stiffness->current) susp_get_samples(reed_stiffness, reed_stiffness_ptr, reed_stiffness_cnt); - /* fetch samples from noise up to final_time for this block of zeros */ - while ((round((final_time - susp->noise->t0) * susp->noise->sr)) >= - susp->noise->current) - susp_get_samples(noise, noise_ptr, noise_cnt); + /* fetch samples from noise_env up to final_time for this block of zeros */ + while ((round((final_time - susp->noise_env->t0) * susp->noise_env->sr)) >= + susp->noise_env->current) + susp_get_samples(noise_env, noise_env_ptr, noise_env_cnt); /* convert to normal processing when we hit final_count */ /* we want each signal positioned at final_time */ n = round((final_time - susp->breath_env->t0) * susp->breath_env->sr - @@ -170,38 +175,40 @@ void clarinet_all_toss_fetch(susp, snd_list) (susp->reed_stiffness->current - susp->reed_stiffness_cnt)); susp->reed_stiffness_ptr += n; susp_took(reed_stiffness_cnt, n); - n = round((final_time - susp->noise->t0) * susp->noise->sr - - (susp->noise->current - susp->noise_cnt)); - susp->noise_ptr += n; - susp_took(noise_cnt, n); + n = round((final_time - susp->noise_env->t0) * susp->noise_env->sr - + (susp->noise_env->current - susp->noise_env_cnt)); + susp->noise_env_ptr += n; + susp_took(noise_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void clarinet_all_mark(clarinet_all_susp_type susp) +void clarinet_all_mark(snd_susp_type a_susp) { + clarinet_all_susp_type susp = (clarinet_all_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); sound_xlmark(susp->reed_stiffness); - sound_xlmark(susp->noise); + sound_xlmark(susp->noise_env); } -void clarinet_all_free(clarinet_all_susp_type susp) +void clarinet_all_free(snd_susp_type a_susp) { - - deleteInstrument(susp->clar); + clarinet_all_susp_type susp = (clarinet_all_susp_type) a_susp; + deleteInstrument(susp->clar); sound_unref(susp->breath_env); sound_unref(susp->freq_env); sound_unref(susp->reed_stiffness); - sound_unref(susp->noise); + sound_unref(susp->noise_env); ffree_generic(susp, sizeof(clarinet_all_susp_node), "clarinet_all_free"); } -void clarinet_all_print_tree(clarinet_all_susp_type susp, int n) +void clarinet_all_print_tree(snd_susp_type a_susp, int n) { + clarinet_all_susp_type susp = (clarinet_all_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -215,17 +222,16 @@ void clarinet_all_print_tree(clarinet_all_susp_type susp, int n) sound_print_tree_1(susp->reed_stiffness, n); indent(n); - stdputstr("noise:"); - sound_print_tree_1(susp->noise, n); + stdputstr("noise_env:"); + sound_print_tree_1(susp->noise_env, n); } -sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, rate_type sr) +sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, rate_type sr) { register clarinet_all_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, clarinet_all_susp_node, "snd_make_clarinet_all"); @@ -234,20 +240,41 @@ sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type controlChange(susp->clar, 11, CLAR_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->clar, 1, CLAR_CONTROL_CHANGE_CONST * vibrato_gain);; susp->frequency = freq; - susp->susp.fetch = clarinet_all_ssss_fetch; + susp->breath_scale = breath_env->scale * CLAR_CONTROL_CHANGE_CONST; + susp->reed_scale = reed_stiffness->scale * CLAR_CONTROL_CHANGE_CONST; + susp->noise_scale = noise_env->scale * CLAR_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + if (reed_stiffness->sr > sr) { + sound_unref(reed_stiffness); + snd_badsr(); + } else if (reed_stiffness->sr < sr) reed_stiffness = snd_make_up(sr, reed_stiffness); + if (noise_env->sr > sr) { + sound_unref(noise_env); + snd_badsr(); + } else if (noise_env->sr < sr) noise_env = snd_make_up(sr, noise_env); + susp->susp.fetch = clarinet_all_nsnn_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); if (t0 < freq_env->t0) sound_prepend_zeros(freq_env, t0); if (t0 < reed_stiffness->t0) sound_prepend_zeros(reed_stiffness, t0); - if (t0 < noise->t0) sound_prepend_zeros(noise, t0); + if (t0 < noise_env->t0) sound_prepend_zeros(noise_env, t0); /* minimum start time over all inputs: */ - t0_min = min(breath_env->t0, min(freq_env->t0, min(reed_stiffness->t0, min(noise->t0, t0)))); + t0_min = min(breath_env->t0, min(freq_env->t0, min(reed_stiffness->t0, min(noise_env->t0, t0)))); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = clarinet_all_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = clarinet_all_toss_fetch; } /* initialize susp state */ @@ -265,17 +292,17 @@ sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type susp->freq_env_cnt = 0; susp->reed_stiffness = reed_stiffness; susp->reed_stiffness_cnt = 0; - susp->noise = noise; - susp->noise_cnt = 0; + susp->noise_env = noise_env; + susp->noise_env_cnt = 0; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } -sound_type snd_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, rate_type sr) +sound_type snd_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, rate_type sr) { sound_type breath_env_copy = sound_copy(breath_env); sound_type freq_env_copy = sound_copy(freq_env); sound_type reed_stiffness_copy = sound_copy(reed_stiffness); - sound_type noise_copy = sound_copy(noise); - return snd_make_clarinet_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, reed_stiffness_copy, noise_copy, sr); + sound_type noise_env_copy = sound_copy(noise_env); + return snd_make_clarinet_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, reed_stiffness_copy, noise_env_copy, sr); } diff --git a/lib-src/libnyquist/nyquist/tran/instrclarall.h b/lib-src/libnyquist/nyquist/tran/instrclarall.h index 5f47d107c..b7268f56d 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarall.h +++ b/lib-src/libnyquist/nyquist/tran/instrclarall.h @@ -1,5 +1,4 @@ -sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, rate_type sr); -sound_type snd_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, rate_type sr); +sound_type snd_make_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, rate_type sr); +sound_type snd_clarinet_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, rate_type sr); /* LISP: (snd-clarinet_all ANYNUM SOUND SOUND ANYNUM ANYNUM SOUND SOUND ANYNUM) */ - - #define CLAR_CONTROL_CHANGE_CONST 128 +#define CLAR_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrclarfreq.alg b/lib-src/libnyquist/nyquist/tran/instrclarfreq.alg index 3e408b662..79218a458 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarfreq.alg +++ b/lib-src/libnyquist/nyquist/tran/instrclarfreq.alg @@ -1,29 +1,26 @@ (INSTRCLAR-FREQ-ALG (NAME "clarinet_freq") -(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("sound_type" "freq_env") - ("rate_type" "sr")) +(ARGUMENTS ("double" "freq1") ("sound_type" "breath_env") + ("sound_type" "freq_env") ("rate_type" "sr")) (STATE ("struct instr *" "clar" "initInstrument(CLARINET, round(sr)); controlChange(susp->clar, 1, 0.0);") - ("int" "temp_ret_value" "noteOn(susp->clar, freq, 1.0)") - ("double" "frequency" "freq")) + ("int" "temp_ret_value" "noteOn(susp->clar, freq1, 1.0)") + ("double" "frequency" "freq1") + ("float" "breath_scale" "breath_env->scale * CLAR_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) +(ALWAYS-SCALE freq_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "temp_ret_value") -(CONSTANT "frequency") +(CONSTANT "frequency" "breath_scale") (SAMPLE-RATE "sr") -(MATCHED-SAMPLE-RATE freq_env breath_env) +;(MATCHED-SAMPLE-RATE freq_env breath_env) (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(clar, 128, CLAR_CONTROL_CHANGE_CONST * breath_env); - setFrequency(clar, frequency + freq_env); - output = (sample_type) tick(clar)") -(SUPPORT-HEADER " - #define CLAR_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->clar); -") +(INNER-LOOP "controlChange(clar, 128, breath_scale * breath_env); + setFrequency(clar, frequency + freq_env); + output = (sample_type) tick(clar)") +(SUPPORT-HEADER "#define CLAR_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->clar);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrclarfreq.c b/lib-src/libnyquist/nyquist/tran/instrclarfreq.c index 7f1e8c657..51bdaef5c 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarfreq.c +++ b/lib-src/libnyquist/nyquist/tran/instrclarfreq.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrclarfreq.h" -void clarinet_freq_free(); +void clarinet_freq_free(snd_susp_type a_susp); typedef struct clarinet_freq_susp_struct { @@ -25,86 +25,16 @@ typedef struct clarinet_freq_susp_struct { struct instr *clar; int temp_ret_value; double frequency; + float breath_scale; } clarinet_freq_susp_node, *clarinet_freq_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void clarinet_freq_nn_fetch(register clarinet_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * clar_reg; - register double frequency_reg; - register sample_block_values_type freq_env_ptr_reg; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "clarinet_freq_nn_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - clar_reg = susp->clar; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(clar_reg, 128, CLAR_CONTROL_CHANGE_CONST * *breath_env_ptr_reg++); - setFrequency(clar_reg, frequency_reg + *freq_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(clar_reg); - } while (--n); /* inner loop */ - - susp->clar = clar_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* clarinet_freq_nn_fetch */ - - -void clarinet_freq_ss_fetch(register clarinet_freq_susp_type susp, snd_list_type snd_list) +void clarinet_freq_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + clarinet_freq_susp_type susp = (clarinet_freq_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -115,11 +45,11 @@ void clarinet_freq_ss_fetch(register clarinet_freq_susp_type susp, snd_list_type register struct instr * clar_reg; register double frequency_reg; + register float breath_scale_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "clarinet_freq_ss_fetch"); + falloc_sample_block(out, "clarinet_freq_ns_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -140,20 +70,21 @@ void clarinet_freq_ss_fetch(register clarinet_freq_susp_type susp, snd_list_type if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; clar_reg = susp->clar; frequency_reg = susp->frequency; + breath_scale_reg = susp->breath_scale; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(clar_reg, 128, CLAR_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - setFrequency(clar_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(clar_reg); + controlChange(clar_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + setFrequency(clar_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); + *out_ptr_reg++ = (sample_type) tick(clar_reg); } while (--n); /* inner loop */ susp->clar = clar_reg; @@ -174,14 +105,12 @@ void clarinet_freq_ss_fetch(register clarinet_freq_susp_type susp, snd_list_type snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* clarinet_freq_ss_fetch */ +} /* clarinet_freq_ns_fetch */ -void clarinet_freq_toss_fetch(susp, snd_list) - register clarinet_freq_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void clarinet_freq_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + clarinet_freq_susp_type susp = (clarinet_freq_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -204,29 +133,31 @@ void clarinet_freq_toss_fetch(susp, snd_list) susp->freq_env_ptr += n; susp_took(freq_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void clarinet_freq_mark(clarinet_freq_susp_type susp) +void clarinet_freq_mark(snd_susp_type a_susp) { + clarinet_freq_susp_type susp = (clarinet_freq_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); } -void clarinet_freq_free(clarinet_freq_susp_type susp) +void clarinet_freq_free(snd_susp_type a_susp) { - - deleteInstrument(susp->clar); + clarinet_freq_susp_type susp = (clarinet_freq_susp_type) a_susp; + deleteInstrument(susp->clar); sound_unref(susp->breath_env); sound_unref(susp->freq_env); ffree_generic(susp, sizeof(clarinet_freq_susp_node), "clarinet_freq_free"); } -void clarinet_freq_print_tree(clarinet_freq_susp_type susp, int n) +void clarinet_freq_print_tree(snd_susp_type a_susp, int n) { + clarinet_freq_susp_type susp = (clarinet_freq_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -237,29 +168,30 @@ void clarinet_freq_print_tree(clarinet_freq_susp_type susp, int n) } -sound_type snd_make_clarinet_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr) +sound_type snd_make_clarinet_freq(double freq1, sound_type breath_env, sound_type freq_env, rate_type sr) { register clarinet_freq_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, clarinet_freq_susp_node, "snd_make_clarinet_freq"); susp->clar = initInstrument(CLARINET, round(sr)); controlChange(susp->clar, 1, 0.0);; - susp->temp_ret_value = noteOn(susp->clar, freq, 1.0); - susp->frequency = freq; - - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(breath_env, sr); - interp_desc = (interp_desc << 2) + interp_style(freq_env, sr); - switch (interp_desc) { - case INTERP_nn: susp->susp.fetch = clarinet_freq_nn_fetch; break; - case INTERP_ss: susp->susp.fetch = clarinet_freq_ss_fetch; break; - default: snd_badsr(); break; - } + susp->temp_ret_value = noteOn(susp->clar, freq1, 1.0); + susp->frequency = freq1; + susp->breath_scale = breath_env->scale * CLAR_CONTROL_CHANGE_CONST; + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + susp->susp.fetch = clarinet_freq_ns_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -269,8 +201,8 @@ sound_type snd_make_clarinet_freq(double freq, sound_type breath_env, sound_type /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = clarinet_freq_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = clarinet_freq_toss_fetch; } /* initialize susp state */ @@ -290,9 +222,9 @@ sound_type snd_make_clarinet_freq(double freq, sound_type breath_env, sound_type } -sound_type snd_clarinet_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr) +sound_type snd_clarinet_freq(double freq1, sound_type breath_env, sound_type freq_env, rate_type sr) { sound_type breath_env_copy = sound_copy(breath_env); sound_type freq_env_copy = sound_copy(freq_env); - return snd_make_clarinet_freq(freq, breath_env_copy, freq_env_copy, sr); + return snd_make_clarinet_freq(freq1, breath_env_copy, freq_env_copy, sr); } diff --git a/lib-src/libnyquist/nyquist/tran/instrclarfreq.h b/lib-src/libnyquist/nyquist/tran/instrclarfreq.h index 1ee6a22a7..bed9adc43 100644 --- a/lib-src/libnyquist/nyquist/tran/instrclarfreq.h +++ b/lib-src/libnyquist/nyquist/tran/instrclarfreq.h @@ -1,5 +1,4 @@ -sound_type snd_make_clarinet_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); -sound_type snd_clarinet_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); +sound_type snd_make_clarinet_freq(double freq1, sound_type breath_env, sound_type freq_env, rate_type sr); +sound_type snd_clarinet_freq(double freq1, sound_type breath_env, sound_type freq_env, rate_type sr); /* LISP: (snd-clarinet_freq ANYNUM SOUND SOUND ANYNUM) */ - - #define CLAR_CONTROL_CHANGE_CONST 128 +#define CLAR_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrflute.alg b/lib-src/libnyquist/nyquist/tran/instrflute.alg index 363d9a5f3..8433138cd 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflute.alg +++ b/lib-src/libnyquist/nyquist/tran/instrflute.alg @@ -3,23 +3,20 @@ (ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("rate_type" "sr")) (STATE ("struct instr *" "myflute" "initInstrument(FLUTE, round(sr)); controlChange(susp->myflute, 1, 0.0);") - ("int" "temp_ret_value" "noteOn(susp->myflute, freq, 1.0)")) + ("int" "temp_ret_value" "noteOn(susp->myflute, freq, 1.0)") + ("float" "breath_scale" + "breath_env->scale * FLUTE_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "freq" "temp_ret_value") +(CONSTANT "breath_scale") (SAMPLE-RATE "sr") -(ALWAYS-SCALE breath_env) (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(myflute, 128, FLUTE_CONTROL_CHANGE_CONST * breath_env); - output = (sample_type) tick(myflute)") -(SUPPORT-HEADER " - #define FLUTE_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->myflute); -") +(INNER-LOOP "controlChange(myflute, 128, breath_scale * breath_env); + output = (sample_type) tick(myflute)") +(SUPPORT-HEADER "#define FLUTE_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->myflute);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrflute.c b/lib-src/libnyquist/nyquist/tran/instrflute.c index eebefed1a..84d21752f 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflute.c +++ b/lib-src/libnyquist/nyquist/tran/instrflute.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrflute.h" -void flute_free(); +void flute_free(snd_susp_type a_susp); typedef struct flute_susp_struct { @@ -21,14 +21,16 @@ typedef struct flute_susp_struct { struct instr *myflute; int temp_ret_value; + float breath_scale; } flute_susp_node, *flute_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void flute_s_fetch(register flute_susp_type susp, snd_list_type snd_list) +void flute_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + flute_susp_type susp = (flute_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -38,9 +40,9 @@ void flute_s_fetch(register flute_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * myflute_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; + register float breath_scale_reg; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "flute_s_fetch"); + falloc_sample_block(out, "flute_n_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -57,17 +59,18 @@ void flute_s_fetch(register flute_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; myflute_reg = susp->myflute; + breath_scale_reg = susp->breath_scale; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(myflute_reg, 128, FLUTE_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(myflute_reg); + controlChange(myflute_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + *out_ptr_reg++ = (sample_type) tick(myflute_reg); } while (--n); /* inner loop */ susp->myflute = myflute_reg; @@ -85,14 +88,12 @@ void flute_s_fetch(register flute_susp_type susp, snd_list_type snd_list) snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* flute_s_fetch */ +} /* flute_n_fetch */ -void flute_toss_fetch(susp, snd_list) - register flute_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void flute_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + flute_susp_type susp = (flute_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -107,27 +108,29 @@ void flute_toss_fetch(susp, snd_list) susp->breath_env_ptr += n; susp_took(breath_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void flute_mark(flute_susp_type susp) +void flute_mark(snd_susp_type a_susp) { + flute_susp_type susp = (flute_susp_type) a_susp; sound_xlmark(susp->breath_env); } -void flute_free(flute_susp_type susp) +void flute_free(snd_susp_type a_susp) { - - deleteInstrument(susp->myflute); + flute_susp_type susp = (flute_susp_type) a_susp; + deleteInstrument(susp->myflute); sound_unref(susp->breath_env); ffree_generic(susp, sizeof(flute_susp_node), "flute_free"); } -void flute_print_tree(flute_susp_type susp, int n) +void flute_print_tree(snd_susp_type a_susp, int n) { + flute_susp_type susp = (flute_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -139,14 +142,20 @@ sound_type snd_make_flute(double freq, sound_type breath_env, rate_type sr) register flute_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, flute_susp_node, "snd_make_flute"); susp->myflute = initInstrument(FLUTE, round(sr)); controlChange(susp->myflute, 1, 0.0);; susp->temp_ret_value = noteOn(susp->myflute, freq, 1.0); - susp->susp.fetch = flute_s_fetch; + susp->breath_scale = breath_env->scale * FLUTE_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + susp->susp.fetch = flute_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -155,8 +164,8 @@ sound_type snd_make_flute(double freq, sound_type breath_env, rate_type sr) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = flute_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = flute_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrflute.h b/lib-src/libnyquist/nyquist/tran/instrflute.h index 3158cbdd2..1e611f3f4 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflute.h +++ b/lib-src/libnyquist/nyquist/tran/instrflute.h @@ -1,5 +1,4 @@ sound_type snd_make_flute(double freq, sound_type breath_env, rate_type sr); sound_type snd_flute(double freq, sound_type breath_env, rate_type sr); /* LISP: (snd-flute ANYNUM SOUND ANYNUM) */ - - #define FLUTE_CONTROL_CHANGE_CONST 128 +#define FLUTE_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrfluteall.alg b/lib-src/libnyquist/nyquist/tran/instrfluteall.alg index 045b52b02..c44c7e11e 100644 --- a/lib-src/libnyquist/nyquist/tran/instrfluteall.alg +++ b/lib-src/libnyquist/nyquist/tran/instrfluteall.alg @@ -9,35 +9,35 @@ ;; noise -- noise, Noise 4 ;; (NAME "flute_all") -(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("sound_type" "freq_env") +(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") + ("sound_type" "freq_env") ("double" "vibrato_freq") ("double" "vibrato_gain") - ("sound_type" "jet_delay") ("sound_type" "noise") ("rate_type" "sr")) + ("sound_type" "jet_delay") ("sound_type" "noise_env") ("rate_type" "sr")) ;; use a constant rate of 1.0 because it will actually be conrolled ;; by breath_env (STATE ("struct instr *" "myflute" "initInstrument(FLUTE, round(sr)); noteOn(susp->myflute, freq, 1.0); controlChange(susp->myflute, 11, FLUTE_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->myflute, 1, FLUTE_CONTROL_CHANGE_CONST * vibrato_gain);") - ("double" "frequency" "freq")) + ("double" "frequency" "freq") + ("float" "breath_scale" "breath_env->scale * FLUTE_CONTROL_CHANGE_CONST") + ("float" "jet_scale" "jet_delay->scale * FLUTE_CONTROL_CHANGE_CONST") + ("float" "noise_scale" "noise_env->scale * FLUTE_CONTROL_CHANGE_CONST")) (START (min breath_env)) -(MATCHED-SAMPLE-RATE freq_env breath_env jet_delay noise) -(ALWAYS-SCALE freq_env breath_env jet_delay noise) -(CONSTANT "frequency") +; matched doesn't help much because controlChange() is called in inner loop +;(MATCHED-SAMPLE-RATE freq_env breath_env jet_delay noise_env) +(ALWAYS-SCALE freq_env) +(INTERNAL-SCALING breath_env jet_delay noise_env) +(INLINE-INTERPOLATION no) +(CONSTANT "frequency" "breath_scale" "jet_scale" "noise_scale") (SAMPLE-RATE "sr") (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(myflute, 128, FLUTE_CONTROL_CHANGE_CONST * breath_env); - controlChange(myflute, 2, FLUTE_CONTROL_CHANGE_CONST * jet_delay); - controlChange(myflute, 4, FLUTE_CONTROL_CHANGE_CONST * noise); - setFrequency(myflute, frequency + freq_env); - output = (sample_type) tick(myflute)") -(SUPPORT-HEADER " - #define FLUTE_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->myflute); -") +(INNER-LOOP "controlChange(myflute, 128, breath_scale * breath_env); + controlChange(myflute, 2, jet_scale * jet_delay); + controlChange(myflute, 4, noise_scale * noise_env); + setFrequency(myflute, frequency + freq_env); + output = (sample_type) tick(myflute)") +(SUPPORT-HEADER "#define FLUTE_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->myflute);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrfluteall.c b/lib-src/libnyquist/nyquist/tran/instrfluteall.c index 64e3f5669..49e7c8837 100644 --- a/lib-src/libnyquist/nyquist/tran/instrfluteall.c +++ b/lib-src/libnyquist/nyquist/tran/instrfluteall.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrfluteall.h" -void flute_all_free(); +void flute_all_free(snd_susp_type a_susp); typedef struct flute_all_susp_struct { @@ -24,20 +24,24 @@ typedef struct flute_all_susp_struct { sound_type jet_delay; long jet_delay_cnt; sample_block_values_type jet_delay_ptr; - sound_type noise; - long noise_cnt; - sample_block_values_type noise_ptr; + sound_type noise_env; + long noise_env_cnt; + sample_block_values_type noise_env_ptr; struct instr *myflute; double frequency; + float breath_scale; + float jet_scale; + float noise_scale; } flute_all_susp_node, *flute_all_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void flute_all_ssss_fetch(register flute_all_susp_type susp, snd_list_type snd_list) +void flute_all_nsnn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + flute_all_susp_type susp = (flute_all_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -48,15 +52,15 @@ void flute_all_ssss_fetch(register flute_all_susp_type susp, snd_list_type snd_l register struct instr * myflute_reg; register double frequency_reg; - register sample_type noise_scale_reg = susp->noise->scale; - register sample_block_values_type noise_ptr_reg; - register sample_type jet_delay_scale_reg = susp->jet_delay->scale; + register float breath_scale_reg; + register float jet_scale_reg; + register float noise_scale_reg; + register sample_block_values_type noise_env_ptr_reg; register sample_block_values_type jet_delay_ptr_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "flute_all_ssss_fetch"); + falloc_sample_block(out, "flute_all_nsnn_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -77,37 +81,40 @@ void flute_all_ssss_fetch(register flute_all_susp_type susp, snd_list_type snd_l susp_check_samples(jet_delay, jet_delay_ptr, jet_delay_cnt); togo = min(togo, susp->jet_delay_cnt); - /* don't run past the noise input sample block: */ - susp_check_samples(noise, noise_ptr, noise_cnt); - togo = min(togo, susp->noise_cnt); + /* don't run past the noise_env input sample block: */ + susp_check_samples(noise_env, noise_env_ptr, noise_env_cnt); + togo = min(togo, susp->noise_env_cnt); /* don't run past terminate time */ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; myflute_reg = susp->myflute; frequency_reg = susp->frequency; - noise_ptr_reg = susp->noise_ptr; + breath_scale_reg = susp->breath_scale; + jet_scale_reg = susp->jet_scale; + noise_scale_reg = susp->noise_scale; + noise_env_ptr_reg = susp->noise_env_ptr; jet_delay_ptr_reg = susp->jet_delay_ptr; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(myflute_reg, 128, FLUTE_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - controlChange(myflute_reg, 2, FLUTE_CONTROL_CHANGE_CONST * (jet_delay_scale_reg * *jet_delay_ptr_reg++)); - controlChange(myflute_reg, 4, FLUTE_CONTROL_CHANGE_CONST * (noise_scale_reg * *noise_ptr_reg++)); - setFrequency(myflute_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(myflute_reg); + controlChange(myflute_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + controlChange(myflute_reg, 2, jet_scale_reg * *jet_delay_ptr_reg++); + controlChange(myflute_reg, 4, noise_scale_reg * *noise_env_ptr_reg++); + setFrequency(myflute_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); + *out_ptr_reg++ = (sample_type) tick(myflute_reg); } while (--n); /* inner loop */ susp->myflute = myflute_reg; - /* using noise_ptr_reg is a bad idea on RS/6000: */ - susp->noise_ptr += togo; + /* using noise_env_ptr_reg is a bad idea on RS/6000: */ + susp->noise_env_ptr += togo; /* using jet_delay_ptr_reg is a bad idea on RS/6000: */ susp->jet_delay_ptr += togo; /* using freq_env_ptr_reg is a bad idea on RS/6000: */ @@ -118,7 +125,7 @@ void flute_all_ssss_fetch(register flute_all_susp_type susp, snd_list_type snd_l susp_took(breath_env_cnt, togo); susp_took(freq_env_cnt, togo); susp_took(jet_delay_cnt, togo); - susp_took(noise_cnt, togo); + susp_took(noise_env_cnt, togo); cnt += togo; } /* outer loop */ @@ -129,14 +136,12 @@ void flute_all_ssss_fetch(register flute_all_susp_type susp, snd_list_type snd_l snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* flute_all_ssss_fetch */ +} /* flute_all_nsnn_fetch */ -void flute_all_toss_fetch(susp, snd_list) - register flute_all_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void flute_all_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + flute_all_susp_type susp = (flute_all_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -152,10 +157,10 @@ void flute_all_toss_fetch(susp, snd_list) while ((round((final_time - susp->jet_delay->t0) * susp->jet_delay->sr)) >= susp->jet_delay->current) susp_get_samples(jet_delay, jet_delay_ptr, jet_delay_cnt); - /* fetch samples from noise up to final_time for this block of zeros */ - while ((round((final_time - susp->noise->t0) * susp->noise->sr)) >= - susp->noise->current) - susp_get_samples(noise, noise_ptr, noise_cnt); + /* fetch samples from noise_env up to final_time for this block of zeros */ + while ((round((final_time - susp->noise_env->t0) * susp->noise_env->sr)) >= + susp->noise_env->current) + susp_get_samples(noise_env, noise_env_ptr, noise_env_cnt); /* convert to normal processing when we hit final_count */ /* we want each signal positioned at final_time */ n = round((final_time - susp->breath_env->t0) * susp->breath_env->sr - @@ -170,38 +175,40 @@ void flute_all_toss_fetch(susp, snd_list) (susp->jet_delay->current - susp->jet_delay_cnt)); susp->jet_delay_ptr += n; susp_took(jet_delay_cnt, n); - n = round((final_time - susp->noise->t0) * susp->noise->sr - - (susp->noise->current - susp->noise_cnt)); - susp->noise_ptr += n; - susp_took(noise_cnt, n); + n = round((final_time - susp->noise_env->t0) * susp->noise_env->sr - + (susp->noise_env->current - susp->noise_env_cnt)); + susp->noise_env_ptr += n; + susp_took(noise_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void flute_all_mark(flute_all_susp_type susp) +void flute_all_mark(snd_susp_type a_susp) { + flute_all_susp_type susp = (flute_all_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); sound_xlmark(susp->jet_delay); - sound_xlmark(susp->noise); + sound_xlmark(susp->noise_env); } -void flute_all_free(flute_all_susp_type susp) +void flute_all_free(snd_susp_type a_susp) { - - deleteInstrument(susp->myflute); + flute_all_susp_type susp = (flute_all_susp_type) a_susp; + deleteInstrument(susp->myflute); sound_unref(susp->breath_env); sound_unref(susp->freq_env); sound_unref(susp->jet_delay); - sound_unref(susp->noise); + sound_unref(susp->noise_env); ffree_generic(susp, sizeof(flute_all_susp_node), "flute_all_free"); } -void flute_all_print_tree(flute_all_susp_type susp, int n) +void flute_all_print_tree(snd_susp_type a_susp, int n) { + flute_all_susp_type susp = (flute_all_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -215,17 +222,16 @@ void flute_all_print_tree(flute_all_susp_type susp, int n) sound_print_tree_1(susp->jet_delay, n); indent(n); - stdputstr("noise:"); - sound_print_tree_1(susp->noise, n); + stdputstr("noise_env:"); + sound_print_tree_1(susp->noise_env, n); } -sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise, rate_type sr) +sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise_env, rate_type sr) { register flute_all_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, flute_all_susp_node, "snd_make_flute_all"); @@ -234,20 +240,41 @@ sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type fre controlChange(susp->myflute, 11, FLUTE_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->myflute, 1, FLUTE_CONTROL_CHANGE_CONST * vibrato_gain);; susp->frequency = freq; - susp->susp.fetch = flute_all_ssss_fetch; + susp->breath_scale = breath_env->scale * FLUTE_CONTROL_CHANGE_CONST; + susp->jet_scale = jet_delay->scale * FLUTE_CONTROL_CHANGE_CONST; + susp->noise_scale = noise_env->scale * FLUTE_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + if (jet_delay->sr > sr) { + sound_unref(jet_delay); + snd_badsr(); + } else if (jet_delay->sr < sr) jet_delay = snd_make_up(sr, jet_delay); + if (noise_env->sr > sr) { + sound_unref(noise_env); + snd_badsr(); + } else if (noise_env->sr < sr) noise_env = snd_make_up(sr, noise_env); + susp->susp.fetch = flute_all_nsnn_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); if (t0 < freq_env->t0) sound_prepend_zeros(freq_env, t0); if (t0 < jet_delay->t0) sound_prepend_zeros(jet_delay, t0); - if (t0 < noise->t0) sound_prepend_zeros(noise, t0); + if (t0 < noise_env->t0) sound_prepend_zeros(noise_env, t0); /* minimum start time over all inputs: */ - t0_min = min(breath_env->t0, min(freq_env->t0, min(jet_delay->t0, min(noise->t0, t0)))); + t0_min = min(breath_env->t0, min(freq_env->t0, min(jet_delay->t0, min(noise_env->t0, t0)))); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = flute_all_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = flute_all_toss_fetch; } /* initialize susp state */ @@ -265,17 +292,17 @@ sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type fre susp->freq_env_cnt = 0; susp->jet_delay = jet_delay; susp->jet_delay_cnt = 0; - susp->noise = noise; - susp->noise_cnt = 0; + susp->noise_env = noise_env; + susp->noise_env_cnt = 0; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } -sound_type snd_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise, rate_type sr) +sound_type snd_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise_env, rate_type sr) { sound_type breath_env_copy = sound_copy(breath_env); sound_type freq_env_copy = sound_copy(freq_env); sound_type jet_delay_copy = sound_copy(jet_delay); - sound_type noise_copy = sound_copy(noise); - return snd_make_flute_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, jet_delay_copy, noise_copy, sr); + sound_type noise_env_copy = sound_copy(noise_env); + return snd_make_flute_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, jet_delay_copy, noise_env_copy, sr); } diff --git a/lib-src/libnyquist/nyquist/tran/instrfluteall.h b/lib-src/libnyquist/nyquist/tran/instrfluteall.h index f8ca679dd..063dec3e5 100644 --- a/lib-src/libnyquist/nyquist/tran/instrfluteall.h +++ b/lib-src/libnyquist/nyquist/tran/instrfluteall.h @@ -1,5 +1,4 @@ -sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise, rate_type sr); -sound_type snd_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise, rate_type sr); +sound_type snd_make_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise_env, rate_type sr); +sound_type snd_flute_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type jet_delay, sound_type noise_env, rate_type sr); /* LISP: (snd-flute_all ANYNUM SOUND SOUND ANYNUM ANYNUM SOUND SOUND ANYNUM) */ - - #define FLUTE_CONTROL_CHANGE_CONST 128 +#define FLUTE_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrflutefreq.alg b/lib-src/libnyquist/nyquist/tran/instrflutefreq.alg index bab34ec48..ba3ed40ed 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflutefreq.alg +++ b/lib-src/libnyquist/nyquist/tran/instrflutefreq.alg @@ -5,24 +5,21 @@ (STATE ("struct instr *" "myflute" "initInstrument(FLUTE, round(sr)); controlChange(susp->myflute, 1, 0.0);") ("int" "temp_ret_value" "noteOn(susp->myflute, freq, 1.0)") - ("double" "frequency" "freq")) + ("float" "breath_scale" "breath_env->scale * FLUTE_CONTROL_CHANGE_CONST") + ("double" "frequency" "freq")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) +(ALWAYS-SCALE freq_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "temp_ret_value") -(CONSTANT "frequency") +(CONSTANT "frequency" "breath_scale") (SAMPLE-RATE "sr") -(MATCHED-SAMPLE-RATE freq_env breath_env) +;(MATCHED-SAMPLE-RATE freq_env breath_env) (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(myflute, 128, FLUTE_CONTROL_CHANGE_CONST * breath_env); +(INNER-LOOP "controlChange(myflute, 128, breath_scale * breath_env); setFrequency(myflute, frequency + freq_env); output = (sample_type) tick(myflute)") -(SUPPORT-HEADER " - #define FLUTE_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->myflute); -") +(SUPPORT-HEADER "#define FLUTE_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->myflute);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrflutefreq.c b/lib-src/libnyquist/nyquist/tran/instrflutefreq.c index 8369edfb0..2c203e16f 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflutefreq.c +++ b/lib-src/libnyquist/nyquist/tran/instrflutefreq.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrflutefreq.h" -void flute_freq_free(); +void flute_freq_free(snd_susp_type a_susp); typedef struct flute_freq_susp_struct { @@ -24,87 +24,17 @@ typedef struct flute_freq_susp_struct { struct instr *myflute; int temp_ret_value; + float breath_scale; double frequency; } flute_freq_susp_node, *flute_freq_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void flute_freq_nn_fetch(register flute_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * myflute_reg; - register double frequency_reg; - register sample_block_values_type freq_env_ptr_reg; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "flute_freq_nn_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - myflute_reg = susp->myflute; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(myflute_reg, 128, FLUTE_CONTROL_CHANGE_CONST * *breath_env_ptr_reg++); - setFrequency(myflute_reg, frequency_reg + *freq_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(myflute_reg); - } while (--n); /* inner loop */ - - susp->myflute = myflute_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* flute_freq_nn_fetch */ - - -void flute_freq_ss_fetch(register flute_freq_susp_type susp, snd_list_type snd_list) +void flute_freq_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + flute_freq_susp_type susp = (flute_freq_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -114,12 +44,12 @@ void flute_freq_ss_fetch(register flute_freq_susp_type susp, snd_list_type snd_l register sample_block_values_type out_ptr_reg; register struct instr * myflute_reg; + register float breath_scale_reg; register double frequency_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "flute_freq_ss_fetch"); + falloc_sample_block(out, "flute_freq_ns_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -140,18 +70,19 @@ void flute_freq_ss_fetch(register flute_freq_susp_type susp, snd_list_type snd_l if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; myflute_reg = susp->myflute; + breath_scale_reg = susp->breath_scale; frequency_reg = susp->frequency; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(myflute_reg, 128, FLUTE_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); + controlChange(myflute_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); setFrequency(myflute_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); *out_ptr_reg++ = (sample_type) tick(myflute_reg); } while (--n); /* inner loop */ @@ -174,14 +105,12 @@ void flute_freq_ss_fetch(register flute_freq_susp_type susp, snd_list_type snd_l snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* flute_freq_ss_fetch */ +} /* flute_freq_ns_fetch */ -void flute_freq_toss_fetch(susp, snd_list) - register flute_freq_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void flute_freq_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + flute_freq_susp_type susp = (flute_freq_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -204,29 +133,31 @@ void flute_freq_toss_fetch(susp, snd_list) susp->freq_env_ptr += n; susp_took(freq_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void flute_freq_mark(flute_freq_susp_type susp) +void flute_freq_mark(snd_susp_type a_susp) { + flute_freq_susp_type susp = (flute_freq_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); } -void flute_freq_free(flute_freq_susp_type susp) +void flute_freq_free(snd_susp_type a_susp) { - - deleteInstrument(susp->myflute); + flute_freq_susp_type susp = (flute_freq_susp_type) a_susp; + deleteInstrument(susp->myflute); sound_unref(susp->breath_env); sound_unref(susp->freq_env); ffree_generic(susp, sizeof(flute_freq_susp_node), "flute_freq_free"); } -void flute_freq_print_tree(flute_freq_susp_type susp, int n) +void flute_freq_print_tree(snd_susp_type a_susp, int n) { + flute_freq_susp_type susp = (flute_freq_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -242,24 +173,25 @@ sound_type snd_make_flute_freq(double freq, sound_type breath_env, sound_type fr register flute_freq_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, flute_freq_susp_node, "snd_make_flute_freq"); susp->myflute = initInstrument(FLUTE, round(sr)); controlChange(susp->myflute, 1, 0.0);; susp->temp_ret_value = noteOn(susp->myflute, freq, 1.0); + susp->breath_scale = breath_env->scale * FLUTE_CONTROL_CHANGE_CONST; susp->frequency = freq; - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(breath_env, sr); - interp_desc = (interp_desc << 2) + interp_style(freq_env, sr); - switch (interp_desc) { - case INTERP_nn: susp->susp.fetch = flute_freq_nn_fetch; break; - case INTERP_ss: susp->susp.fetch = flute_freq_ss_fetch; break; - default: snd_badsr(); break; - } - + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + susp->susp.fetch = flute_freq_ns_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -269,8 +201,8 @@ sound_type snd_make_flute_freq(double freq, sound_type breath_env, sound_type fr /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = flute_freq_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = flute_freq_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrflutefreq.h b/lib-src/libnyquist/nyquist/tran/instrflutefreq.h index 15ca31dfb..fb51879a3 100644 --- a/lib-src/libnyquist/nyquist/tran/instrflutefreq.h +++ b/lib-src/libnyquist/nyquist/tran/instrflutefreq.h @@ -1,5 +1,4 @@ sound_type snd_make_flute_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); sound_type snd_flute_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); /* LISP: (snd-flute_freq ANYNUM SOUND SOUND ANYNUM) */ - - #define FLUTE_CONTROL_CHANGE_CONST 128 +#define FLUTE_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrmandolin.alg b/lib-src/libnyquist/nyquist/tran/instrmandolin.alg index 4d1654e5b..5d672f51a 100644 --- a/lib-src/libnyquist/nyquist/tran/instrmandolin.alg +++ b/lib-src/libnyquist/nyquist/tran/instrmandolin.alg @@ -1,7 +1,7 @@ (INSTRMANDOLIN-ALG (NAME "mandolin") -(ARGUMENTS ("time_type" "t0")("double" "freq") ("time_type" "d") - ("double" "body_size")("double" "detune")("rate_type" "sr")) +(ARGUMENTS ("time_type" "t0") ("double" "freq") ("time_type" "d") + ("double" "body_size") ("double" "detune") ("rate_type" "sr")) (STATE ("struct instr *" "mymand" "initInstrument(MANDOLIN, round(sr)); controlChange(susp->mymand, 1, detune); controlChange(susp->mymand, 2, MAND_CONTROL_CHANGE_CONST * body_size);") @@ -9,17 +9,8 @@ (NOT-IN-INNER-LOOP "freq" "temp_ret_value" "body_size" "detune") (SAMPLE-RATE "sr") (TERMINATE (after "d")) -(INNER-LOOP " - output = (sample_type) tick(mymand)") -(SUPPORT-HEADER " - #define MAND_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" - -") -(FINALIZATION " - deleteInstrument(susp->mymand); -") +(INNER-LOOP "output = (sample_type) tick(mymand)") +(SUPPORT-HEADER "#define MAND_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n") +(FINALIZATION " deleteInstrument(susp->mymand);\n") ) - diff --git a/lib-src/libnyquist/nyquist/tran/instrmandolin.c b/lib-src/libnyquist/nyquist/tran/instrmandolin.c index 6beae2ad7..accae066f 100644 --- a/lib-src/libnyquist/nyquist/tran/instrmandolin.c +++ b/lib-src/libnyquist/nyquist/tran/instrmandolin.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrmandolin.h" -void mandolin_free(); +void mandolin_free(snd_susp_type a_susp); typedef struct mandolin_susp_struct { @@ -20,13 +20,12 @@ typedef struct mandolin_susp_struct { int temp_ret_value; } mandolin_susp_node, *mandolin_susp_type; - - #include "instr.h" +#include "instr.h" - -void mandolin__fetch(register mandolin_susp_type susp, snd_list_type snd_list) +void mandolin__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + mandolin_susp_type susp = (mandolin_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -49,6 +48,7 @@ void mandolin__fetch(register mandolin_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -56,8 +56,7 @@ void mandolin__fetch(register mandolin_susp_type susp, snd_list_type snd_list) mymand_reg = susp->mymand; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) tick(mymand_reg); + *out_ptr_reg++ = (sample_type) tick(mymand_reg); } while (--n); /* inner loop */ susp->mymand = mymand_reg; @@ -75,15 +74,15 @@ void mandolin__fetch(register mandolin_susp_type susp, snd_list_type snd_list) } /* mandolin__fetch */ -void mandolin_free(mandolin_susp_type susp) +void mandolin_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mymand); + mandolin_susp_type susp = (mandolin_susp_type) a_susp; + deleteInstrument(susp->mymand); ffree_generic(susp, sizeof(mandolin_susp_node), "mandolin_free"); } -void mandolin_print_tree(mandolin_susp_type susp, int n) +void mandolin_print_tree(snd_susp_type a_susp, int n) { } @@ -101,7 +100,7 @@ sound_type snd_make_mandolin(time_type t0, double freq, time_type d, double body susp->temp_ret_value = noteOn(susp->mymand, freq, 1.0); susp->susp.fetch = mandolin__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = mandolin_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/instrmandolin.h b/lib-src/libnyquist/nyquist/tran/instrmandolin.h index 965cbe31b..6c84f9664 100644 --- a/lib-src/libnyquist/nyquist/tran/instrmandolin.h +++ b/lib-src/libnyquist/nyquist/tran/instrmandolin.h @@ -1,5 +1,4 @@ sound_type snd_make_mandolin(time_type t0, double freq, time_type d, double body_size, double detune, rate_type sr); sound_type snd_mandolin(time_type t0, double freq, time_type d, double body_size, double detune, rate_type sr); /* LISP: (snd-mandolin ANYNUM ANYNUM ANYNUM ANYNUM ANYNUM ANYNUM) */ - - #define MAND_CONTROL_CHANGE_CONST 128 +#define MAND_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrmodalbar.alg b/lib-src/libnyquist/nyquist/tran/instrmodalbar.alg index 4a2cc3460..6b060bd63 100644 --- a/lib-src/libnyquist/nyquist/tran/instrmodalbar.alg +++ b/lib-src/libnyquist/nyquist/tran/instrmodalbar.alg @@ -7,13 +7,8 @@ (NOT-IN-INNER-LOOP "freq" "temp_ret_value") (SAMPLE-RATE "sr") (TERMINATE (after "dur")) -(INNER-LOOP " - output = (sample_type) tick(mymbar)") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->mymbar); -") +(INNER-LOOP "output = (sample_type) tick(mymbar)") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n") +(FINALIZATION " deleteInstrument(susp->mymbar);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrmodalbar.c b/lib-src/libnyquist/nyquist/tran/instrmodalbar.c index 29b0035f7..f13fc30be 100644 --- a/lib-src/libnyquist/nyquist/tran/instrmodalbar.c +++ b/lib-src/libnyquist/nyquist/tran/instrmodalbar.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrmodalbar.h" -void modalbar_free(); +void modalbar_free(snd_susp_type a_susp); typedef struct modalbar_susp_struct { @@ -20,12 +20,12 @@ typedef struct modalbar_susp_struct { int temp_ret_value; } modalbar_susp_node, *modalbar_susp_type; - - #include "instr.h" +#include "instr.h" -void modalbar__fetch(register modalbar_susp_type susp, snd_list_type snd_list) +void modalbar__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + modalbar_susp_type susp = (modalbar_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -48,6 +48,7 @@ void modalbar__fetch(register modalbar_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -55,8 +56,7 @@ void modalbar__fetch(register modalbar_susp_type susp, snd_list_type snd_list) mymbar_reg = susp->mymbar; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) tick(mymbar_reg); + *out_ptr_reg++ = (sample_type) tick(mymbar_reg); } while (--n); /* inner loop */ susp->mymbar = mymbar_reg; @@ -74,15 +74,15 @@ void modalbar__fetch(register modalbar_susp_type susp, snd_list_type snd_list) } /* modalbar__fetch */ -void modalbar_free(modalbar_susp_type susp) +void modalbar_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mymbar); + modalbar_susp_type susp = (modalbar_susp_type) a_susp; + deleteInstrument(susp->mymbar); ffree_generic(susp, sizeof(modalbar_susp_node), "modalbar_free"); } -void modalbar_print_tree(modalbar_susp_type susp, int n) +void modalbar_print_tree(snd_susp_type a_susp, int n) { } @@ -99,7 +99,7 @@ sound_type snd_make_modalbar(time_type t0, double freq, int preset, time_type du susp->temp_ret_value = noteOn(susp->mymbar, freq, 1.0);; susp->susp.fetch = modalbar__fetch; - susp->terminate_cnt = round((dur) * sr); + susp->terminate_cnt = check_terminate_cnt(round((dur) * sr)); /* initialize susp state */ susp->susp.free = modalbar_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/instrsax.alg b/lib-src/libnyquist/nyquist/tran/instrsax.alg index d70883917..3fc7b5456 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsax.alg +++ b/lib-src/libnyquist/nyquist/tran/instrsax.alg @@ -3,22 +3,18 @@ (ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("rate_type" "sr")) (STATE ("struct instr *" "sax" "initInstrument(SAXOFONY, round(sr)); controlChange(susp->sax, 1, 0.0);") - ("int" "temp_ret_value" "noteOn(susp->sax, freq, 1.0)")) + ("int" "temp_ret_value" "noteOn(susp->sax, freq, 1.0)") + ("float" "breath_scale" "breath_env->scale * SAX_CONTROL_CHANGE_CONST")) +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "freq" "temp_ret_value") (SAMPLE-RATE "sr") (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(sax, 128, SAX_CONTROL_CHANGE_CONST * breath_env); - output = (sample_type) tick(sax)") -(SUPPORT-HEADER " - #define SAX_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->sax); -") +(INNER-LOOP "controlChange(sax, 128, breath_scale * breath_env); + output = (sample_type) tick(sax)") +(SUPPORT-HEADER "#define SAX_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->sax);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrsax.c b/lib-src/libnyquist/nyquist/tran/instrsax.c index e70b3a6f8..31bccc08f 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsax.c +++ b/lib-src/libnyquist/nyquist/tran/instrsax.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrsax.h" -void sax_free(); +void sax_free(snd_susp_type a_susp); typedef struct sax_susp_struct { @@ -21,14 +21,16 @@ typedef struct sax_susp_struct { struct instr *sax; int temp_ret_value; + float breath_scale; } sax_susp_node, *sax_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void sax_n_fetch(register sax_susp_type susp, snd_list_type snd_list) +void sax_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sax_susp_type susp = (sax_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -38,6 +40,7 @@ void sax_n_fetch(register sax_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * sax_reg; + register float breath_scale_reg; register sample_block_values_type breath_env_ptr_reg; falloc_sample_block(out, "sax_n_fetch"); out_ptr = out->samples; @@ -56,20 +59,22 @@ void sax_n_fetch(register sax_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; sax_reg = susp->sax; + breath_scale_reg = susp->breath_scale; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * *breath_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(sax_reg); + controlChange(sax_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + *out_ptr_reg++ = (sample_type) tick(sax_reg); } while (--n); /* inner loop */ susp->sax = sax_reg; + susp->breath_scale = breath_scale_reg; /* using breath_env_ptr_reg is a bad idea on RS/6000: */ susp->breath_env_ptr += togo; out_ptr += togo; @@ -87,72 +92,9 @@ void sax_n_fetch(register sax_susp_type susp, snd_list_type snd_list) } /* sax_n_fetch */ -void sax_s_fetch(register sax_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * sax_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "sax_s_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - sax_reg = susp->sax; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(sax_reg); - } while (--n); /* inner loop */ - - susp->sax = sax_reg; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* sax_s_fetch */ - - -void sax_toss_fetch(susp, snd_list) - register sax_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void sax_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + sax_susp_type susp = (sax_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -167,27 +109,29 @@ void sax_toss_fetch(susp, snd_list) susp->breath_env_ptr += n; susp_took(breath_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void sax_mark(sax_susp_type susp) +void sax_mark(snd_susp_type a_susp) { + sax_susp_type susp = (sax_susp_type) a_susp; sound_xlmark(susp->breath_env); } -void sax_free(sax_susp_type susp) +void sax_free(snd_susp_type a_susp) { - - deleteInstrument(susp->sax); + sax_susp_type susp = (sax_susp_type) a_susp; + deleteInstrument(susp->sax); sound_unref(susp->breath_env); ffree_generic(susp, sizeof(sax_susp_node), "sax_free"); } -void sax_print_tree(sax_susp_type susp, int n) +void sax_print_tree(snd_susp_type a_susp, int n) { + sax_susp_type susp = (sax_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -199,22 +143,20 @@ sound_type snd_make_sax(double freq, sound_type breath_env, rate_type sr) register sax_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, sax_susp_node, "snd_make_sax"); susp->sax = initInstrument(SAXOFONY, round(sr)); controlChange(susp->sax, 1, 0.0);; susp->temp_ret_value = noteOn(susp->sax, freq, 1.0); + susp->breath_scale = breath_env->scale * SAX_CONTROL_CHANGE_CONST; - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(breath_env, sr); - switch (interp_desc) { - case INTERP_n: susp->susp.fetch = sax_n_fetch; break; - case INTERP_s: susp->susp.fetch = sax_s_fetch; break; - default: snd_badsr(); break; - } - + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + susp->susp.fetch = sax_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -223,8 +165,8 @@ sound_type snd_make_sax(double freq, sound_type breath_env, rate_type sr) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = sax_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = sax_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrsax.h b/lib-src/libnyquist/nyquist/tran/instrsax.h index 4227342c4..512b74469 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsax.h +++ b/lib-src/libnyquist/nyquist/tran/instrsax.h @@ -1,5 +1,4 @@ sound_type snd_make_sax(double freq, sound_type breath_env, rate_type sr); sound_type snd_sax(double freq, sound_type breath_env, rate_type sr); /* LISP: (snd-sax ANYNUM SOUND ANYNUM) */ - - #define SAX_CONTROL_CHANGE_CONST 128 +#define SAX_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxall.alg b/lib-src/libnyquist/nyquist/tran/instrsaxall.alg index bcc61ad02..f09d25ac4 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxall.alg +++ b/lib-src/libnyquist/nyquist/tran/instrsaxall.alg @@ -2,37 +2,42 @@ (NAME "sax_all") (ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("sound_type" "freq_env") ("double" "vibrato_freq") ("double" "vibrato_gain") - ("sound_type" "reed_stiffness") ("sound_type" "noise") + ("sound_type" "reed_stiffness") ("sound_type" "noise_env") ("sound_type" "blow_pos") ("sound_type" "reed_table_offset") ("rate_type" "sr")) (STATE ("struct instr *" "sax" "initInstrument(SAXOFONY, round(sr)); noteOn(susp->sax, freq, 1.0); controlChange(susp->sax, 29, SAX_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->sax, 1, SAX_CONTROL_CHANGE_CONST * vibrato_gain);") - ("double" "frequency" "freq")) + ("double" "frequency" "freq") + ("float" "breath_scale" "breath_env->scale * SAX_CONTROL_CHANGE_CONST") + ("float" "reed_scale" "reed_stiffness->scale * SAX_CONTROL_CHANGE_CONST") + ("float" "noise_scale" "noise_env->scale * SAX_CONTROL_CHANGE_CONST") + ("float" "blow_scale" "blow_pos->scale * SAX_CONTROL_CHANGE_CONST") + ("float" "offset_scale" + "reed_table_offset->scale * SAX_CONTROL_CHANGE_CONST")) + (START (min breath_env)) -(MATCHED-SAMPLE-RATE freq_env breath_env - reed_stiffness noise blow_pos reed_table_offset) -(CONSTANT "frequency") -(ALWAYS-SCALE freq_env breath_env reed_stiffness noise blow_pos reed_table_offset) +; matched doesn't help much because controlChange() is called in inner loop +;(MATCHED-SAMPLE-RATE freq_env breath_env +; reed_stiffness noise_env blow_pos reed_table_offset) +(CONSTANT "frequency" "breath_scale" "reed_scale" "noise_scale" + "blow_scale" "offset_scale") +(ALWAYS-SCALE freq_env) +(INTERNAL-SCALING breath_env reed_stiffness noise_env + blow_pos reed_table_offset) +(INLINE-INTERPOLATION no) (SAMPLE-RATE "sr") (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(sax, 128, SAX_CONTROL_CHANGE_CONST * breath_env); - controlChange(sax, 2, SAX_CONTROL_CHANGE_CONST * reed_stiffness); - controlChange(sax, 4, SAX_CONTROL_CHANGE_CONST * noise); - controlChange(sax, 11, SAX_CONTROL_CHANGE_CONST * blow_pos); - controlChange(sax, 26, SAX_CONTROL_CHANGE_CONST * reed_table_offset); - setFrequency(sax, frequency + freq_env); - output = (sample_type) tick(sax)") -(SUPPORT-HEADER " - #define SAX_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->sax); -") +(INNER-LOOP "controlChange(sax, 128, breath_scale * breath_env); + controlChange(sax, 2, reed_scale * reed_stiffness); + controlChange(sax, 4, noise_scale * noise_env); + controlChange(sax, 11, blow_scale * blow_pos); + controlChange(sax, 26, offset_scale * reed_table_offset); + setFrequency(sax, frequency + freq_env); + output = (sample_type) tick(sax)") +(SUPPORT-HEADER "#define SAX_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->sax);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxall.c b/lib-src/libnyquist/nyquist/tran/instrsaxall.c index 6b0aa898a..b6d5fdc0d 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxall.c +++ b/lib-src/libnyquist/nyquist/tran/instrsaxall.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrsaxall.h" -void sax_all_free(); +void sax_all_free(snd_susp_type a_susp); typedef struct sax_all_susp_struct { @@ -24,9 +24,9 @@ typedef struct sax_all_susp_struct { sound_type reed_stiffness; long reed_stiffness_cnt; sample_block_values_type reed_stiffness_ptr; - sound_type noise; - long noise_cnt; - sample_block_values_type noise_ptr; + sound_type noise_env; + long noise_env_cnt; + sample_block_values_type noise_env_ptr; sound_type blow_pos; long blow_pos_cnt; sample_block_values_type blow_pos_ptr; @@ -36,14 +36,20 @@ typedef struct sax_all_susp_struct { struct instr *sax; double frequency; + float breath_scale; + float reed_scale; + float noise_scale; + float blow_scale; + float offset_scale; } sax_all_susp_node, *sax_all_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_list) +void sax_all_nsnnnn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sax_all_susp_type susp = (sax_all_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -54,19 +60,19 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis register struct instr * sax_reg; register double frequency_reg; - register sample_type reed_table_offset_scale_reg = susp->reed_table_offset->scale; + register float breath_scale_reg; + register float reed_scale_reg; + register float noise_scale_reg; + register float blow_scale_reg; + register float offset_scale_reg; register sample_block_values_type reed_table_offset_ptr_reg; - register sample_type blow_pos_scale_reg = susp->blow_pos->scale; register sample_block_values_type blow_pos_ptr_reg; - register sample_type noise_scale_reg = susp->noise->scale; - register sample_block_values_type noise_ptr_reg; - register sample_type reed_stiffness_scale_reg = susp->reed_stiffness->scale; + register sample_block_values_type noise_env_ptr_reg; register sample_block_values_type reed_stiffness_ptr_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "sax_all_ssssss_fetch"); + falloc_sample_block(out, "sax_all_nsnnnn_fetch"); out_ptr = out->samples; snd_list->block = out; @@ -87,9 +93,9 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis susp_check_samples(reed_stiffness, reed_stiffness_ptr, reed_stiffness_cnt); togo = min(togo, susp->reed_stiffness_cnt); - /* don't run past the noise input sample block: */ - susp_check_samples(noise, noise_ptr, noise_cnt); - togo = min(togo, susp->noise_cnt); + /* don't run past the noise_env input sample block: */ + susp_check_samples(noise_env, noise_env_ptr, noise_env_cnt); + togo = min(togo, susp->noise_env_cnt); /* don't run past the blow_pos input sample block: */ susp_check_samples(blow_pos, blow_pos_ptr, blow_pos_cnt); @@ -103,28 +109,33 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; sax_reg = susp->sax; frequency_reg = susp->frequency; + breath_scale_reg = susp->breath_scale; + reed_scale_reg = susp->reed_scale; + noise_scale_reg = susp->noise_scale; + blow_scale_reg = susp->blow_scale; + offset_scale_reg = susp->offset_scale; reed_table_offset_ptr_reg = susp->reed_table_offset_ptr; blow_pos_ptr_reg = susp->blow_pos_ptr; - noise_ptr_reg = susp->noise_ptr; + noise_env_ptr_reg = susp->noise_env_ptr; reed_stiffness_ptr_reg = susp->reed_stiffness_ptr; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - controlChange(sax_reg, 2, SAX_CONTROL_CHANGE_CONST * (reed_stiffness_scale_reg * *reed_stiffness_ptr_reg++)); - controlChange(sax_reg, 4, SAX_CONTROL_CHANGE_CONST * (noise_scale_reg * *noise_ptr_reg++)); - controlChange(sax_reg, 11, SAX_CONTROL_CHANGE_CONST * (blow_pos_scale_reg * *blow_pos_ptr_reg++)); - controlChange(sax_reg, 26, SAX_CONTROL_CHANGE_CONST * (reed_table_offset_scale_reg * *reed_table_offset_ptr_reg++)); - setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(sax_reg); + controlChange(sax_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + controlChange(sax_reg, 2, reed_scale_reg * *reed_stiffness_ptr_reg++); + controlChange(sax_reg, 4, noise_scale_reg * *noise_env_ptr_reg++); + controlChange(sax_reg, 11, blow_scale_reg * *blow_pos_ptr_reg++); + controlChange(sax_reg, 26, offset_scale_reg * *reed_table_offset_ptr_reg++); + setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); + *out_ptr_reg++ = (sample_type) tick(sax_reg); } while (--n); /* inner loop */ susp->sax = sax_reg; @@ -132,8 +143,8 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis susp->reed_table_offset_ptr += togo; /* using blow_pos_ptr_reg is a bad idea on RS/6000: */ susp->blow_pos_ptr += togo; - /* using noise_ptr_reg is a bad idea on RS/6000: */ - susp->noise_ptr += togo; + /* using noise_env_ptr_reg is a bad idea on RS/6000: */ + susp->noise_env_ptr += togo; /* using reed_stiffness_ptr_reg is a bad idea on RS/6000: */ susp->reed_stiffness_ptr += togo; /* using freq_env_ptr_reg is a bad idea on RS/6000: */ @@ -144,7 +155,7 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis susp_took(breath_env_cnt, togo); susp_took(freq_env_cnt, togo); susp_took(reed_stiffness_cnt, togo); - susp_took(noise_cnt, togo); + susp_took(noise_env_cnt, togo); susp_took(blow_pos_cnt, togo); susp_took(reed_table_offset_cnt, togo); cnt += togo; @@ -157,14 +168,12 @@ void sax_all_ssssss_fetch(register sax_all_susp_type susp, snd_list_type snd_lis snd_list->block_len = cnt; susp->susp.current += cnt; } -} /* sax_all_ssssss_fetch */ +} /* sax_all_nsnnnn_fetch */ -void sax_all_toss_fetch(susp, snd_list) - register sax_all_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void sax_all_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + sax_all_susp_type susp = (sax_all_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -180,10 +189,10 @@ void sax_all_toss_fetch(susp, snd_list) while ((round((final_time - susp->reed_stiffness->t0) * susp->reed_stiffness->sr)) >= susp->reed_stiffness->current) susp_get_samples(reed_stiffness, reed_stiffness_ptr, reed_stiffness_cnt); - /* fetch samples from noise up to final_time for this block of zeros */ - while ((round((final_time - susp->noise->t0) * susp->noise->sr)) >= - susp->noise->current) - susp_get_samples(noise, noise_ptr, noise_cnt); + /* fetch samples from noise_env up to final_time for this block of zeros */ + while ((round((final_time - susp->noise_env->t0) * susp->noise_env->sr)) >= + susp->noise_env->current) + susp_get_samples(noise_env, noise_env_ptr, noise_env_cnt); /* fetch samples from blow_pos up to final_time for this block of zeros */ while ((round((final_time - susp->blow_pos->t0) * susp->blow_pos->sr)) >= susp->blow_pos->current) @@ -206,10 +215,10 @@ void sax_all_toss_fetch(susp, snd_list) (susp->reed_stiffness->current - susp->reed_stiffness_cnt)); susp->reed_stiffness_ptr += n; susp_took(reed_stiffness_cnt, n); - n = round((final_time - susp->noise->t0) * susp->noise->sr - - (susp->noise->current - susp->noise_cnt)); - susp->noise_ptr += n; - susp_took(noise_cnt, n); + n = round((final_time - susp->noise_env->t0) * susp->noise_env->sr - + (susp->noise_env->current - susp->noise_env_cnt)); + susp->noise_env_ptr += n; + susp_took(noise_env_cnt, n); n = round((final_time - susp->blow_pos->t0) * susp->blow_pos->sr - (susp->blow_pos->current - susp->blow_pos_cnt)); susp->blow_pos_ptr += n; @@ -219,37 +228,39 @@ void sax_all_toss_fetch(susp, snd_list) susp->reed_table_offset_ptr += n; susp_took(reed_table_offset_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void sax_all_mark(sax_all_susp_type susp) +void sax_all_mark(snd_susp_type a_susp) { + sax_all_susp_type susp = (sax_all_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); sound_xlmark(susp->reed_stiffness); - sound_xlmark(susp->noise); + sound_xlmark(susp->noise_env); sound_xlmark(susp->blow_pos); sound_xlmark(susp->reed_table_offset); } -void sax_all_free(sax_all_susp_type susp) +void sax_all_free(snd_susp_type a_susp) { - - deleteInstrument(susp->sax); + sax_all_susp_type susp = (sax_all_susp_type) a_susp; + deleteInstrument(susp->sax); sound_unref(susp->breath_env); sound_unref(susp->freq_env); sound_unref(susp->reed_stiffness); - sound_unref(susp->noise); + sound_unref(susp->noise_env); sound_unref(susp->blow_pos); sound_unref(susp->reed_table_offset); ffree_generic(susp, sizeof(sax_all_susp_node), "sax_all_free"); } -void sax_all_print_tree(sax_all_susp_type susp, int n) +void sax_all_print_tree(snd_susp_type a_susp, int n) { + sax_all_susp_type susp = (sax_all_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -263,8 +274,8 @@ void sax_all_print_tree(sax_all_susp_type susp, int n) sound_print_tree_1(susp->reed_stiffness, n); indent(n); - stdputstr("noise:"); - sound_print_tree_1(susp->noise, n); + stdputstr("noise_env:"); + sound_print_tree_1(susp->noise_env, n); indent(n); stdputstr("blow_pos:"); @@ -276,12 +287,11 @@ void sax_all_print_tree(sax_all_susp_type susp, int n) } -sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, sound_type blow_pos, sound_type reed_table_offset, rate_type sr) +sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, sound_type blow_pos, sound_type reed_table_offset, rate_type sr) { register sax_all_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, sax_all_susp_node, "snd_make_sax_all"); @@ -290,22 +300,53 @@ sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_ controlChange(susp->sax, 29, SAX_CONTROL_CHANGE_CONST * vibrato_freq); controlChange(susp->sax, 1, SAX_CONTROL_CHANGE_CONST * vibrato_gain);; susp->frequency = freq; - susp->susp.fetch = sax_all_ssssss_fetch; + susp->breath_scale = breath_env->scale * SAX_CONTROL_CHANGE_CONST; + susp->reed_scale = reed_stiffness->scale * SAX_CONTROL_CHANGE_CONST; + susp->noise_scale = noise_env->scale * SAX_CONTROL_CHANGE_CONST; + susp->blow_scale = blow_pos->scale * SAX_CONTROL_CHANGE_CONST; + susp->offset_scale = reed_table_offset->scale * SAX_CONTROL_CHANGE_CONST; + + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + if (reed_stiffness->sr > sr) { + sound_unref(reed_stiffness); + snd_badsr(); + } else if (reed_stiffness->sr < sr) reed_stiffness = snd_make_up(sr, reed_stiffness); + if (noise_env->sr > sr) { + sound_unref(noise_env); + snd_badsr(); + } else if (noise_env->sr < sr) noise_env = snd_make_up(sr, noise_env); + if (blow_pos->sr > sr) { + sound_unref(blow_pos); + snd_badsr(); + } else if (blow_pos->sr < sr) blow_pos = snd_make_up(sr, blow_pos); + if (reed_table_offset->sr > sr) { + sound_unref(reed_table_offset); + snd_badsr(); + } else if (reed_table_offset->sr < sr) reed_table_offset = snd_make_up(sr, reed_table_offset); + susp->susp.fetch = sax_all_nsnnnn_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); if (t0 < freq_env->t0) sound_prepend_zeros(freq_env, t0); if (t0 < reed_stiffness->t0) sound_prepend_zeros(reed_stiffness, t0); - if (t0 < noise->t0) sound_prepend_zeros(noise, t0); + if (t0 < noise_env->t0) sound_prepend_zeros(noise_env, t0); if (t0 < blow_pos->t0) sound_prepend_zeros(blow_pos, t0); if (t0 < reed_table_offset->t0) sound_prepend_zeros(reed_table_offset, t0); /* minimum start time over all inputs: */ - t0_min = min(breath_env->t0, min(freq_env->t0, min(reed_stiffness->t0, min(noise->t0, min(blow_pos->t0, min(reed_table_offset->t0, t0)))))); + t0_min = min(breath_env->t0, min(freq_env->t0, min(reed_stiffness->t0, min(noise_env->t0, min(blow_pos->t0, min(reed_table_offset->t0, t0)))))); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = sax_all_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = sax_all_toss_fetch; } /* initialize susp state */ @@ -323,8 +364,8 @@ sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_ susp->freq_env_cnt = 0; susp->reed_stiffness = reed_stiffness; susp->reed_stiffness_cnt = 0; - susp->noise = noise; - susp->noise_cnt = 0; + susp->noise_env = noise_env; + susp->noise_env_cnt = 0; susp->blow_pos = blow_pos; susp->blow_pos_cnt = 0; susp->reed_table_offset = reed_table_offset; @@ -333,13 +374,13 @@ sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_ } -sound_type snd_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, sound_type blow_pos, sound_type reed_table_offset, rate_type sr) +sound_type snd_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, sound_type blow_pos, sound_type reed_table_offset, rate_type sr) { sound_type breath_env_copy = sound_copy(breath_env); sound_type freq_env_copy = sound_copy(freq_env); sound_type reed_stiffness_copy = sound_copy(reed_stiffness); - sound_type noise_copy = sound_copy(noise); + sound_type noise_env_copy = sound_copy(noise_env); sound_type blow_pos_copy = sound_copy(blow_pos); sound_type reed_table_offset_copy = sound_copy(reed_table_offset); - return snd_make_sax_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, reed_stiffness_copy, noise_copy, blow_pos_copy, reed_table_offset_copy, sr); + return snd_make_sax_all(freq, breath_env_copy, freq_env_copy, vibrato_freq, vibrato_gain, reed_stiffness_copy, noise_env_copy, blow_pos_copy, reed_table_offset_copy, sr); } diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxall.h b/lib-src/libnyquist/nyquist/tran/instrsaxall.h index d8d0c5127..6fc23e1f3 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxall.h +++ b/lib-src/libnyquist/nyquist/tran/instrsaxall.h @@ -1,5 +1,4 @@ -sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, sound_type blow_pos, sound_type reed_table_offset, rate_type sr); -sound_type snd_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise, sound_type blow_pos, sound_type reed_table_offset, rate_type sr); +sound_type snd_make_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, sound_type blow_pos, sound_type reed_table_offset, rate_type sr); +sound_type snd_sax_all(double freq, sound_type breath_env, sound_type freq_env, double vibrato_freq, double vibrato_gain, sound_type reed_stiffness, sound_type noise_env, sound_type blow_pos, sound_type reed_table_offset, rate_type sr); /* LISP: (snd-sax_all ANYNUM SOUND SOUND ANYNUM ANYNUM SOUND SOUND SOUND SOUND ANYNUM) */ - - #define SAX_CONTROL_CHANGE_CONST 128 +#define SAX_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.alg b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.alg index 09ef2d6ba..2e40195b5 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.alg +++ b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.alg @@ -1,27 +1,29 @@ (INSTRSAX-FREQ-ALG (NAME "sax_freq") -(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") ("sound_type" "freq_env") ("rate_type" "sr")) +(ARGUMENTS ("double" "freq") ("sound_type" "breath_env") + ("sound_type" "freq_env") ("rate_type" "sr")) (STATE ("struct instr *" "sax" "initInstrument(SAXOFONY, round(sr)); controlChange(susp->sax, 1, 0.0);") ("int" "temp_ret_value" "noteOn(susp->sax, freq, 1.0)") + ("float" "breath_scale" "breath_env->scale * SAX_CONTROL_CHANGE_CONST") ("double" "frequency" "freq")) +; since sax is a physical model calculated one sample at a time, there is +; relatively little advantage to inner loop optimization, so always do +; scaling in the inner loop and do not do interpolation inline. This should +; generate just one implementation of the fetch function, saving code space. +(INLINE-INTERPOLATION no) +(INTERNAL-SCALING breath_env) +(ALWAYS-SCALE freq_env) (START (min breath_env)) (NOT-IN-INNER-LOOP "temp_ret_value") -(CONSTANT "frequency") +(CONSTANT "frequency" "breath_scale") (SAMPLE-RATE "sr") (TERMINATE (min breath_env)) -(INNER-LOOP " - controlChange(sax, 128, SAX_CONTROL_CHANGE_CONST * breath_env); - setFrequency(sax, frequency + freq_env); - output = (sample_type) tick(sax)") -(SUPPORT-HEADER " - #define SAX_CONTROL_CHANGE_CONST 128 -") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->sax); -") +(INNER-LOOP "controlChange(sax, 128, breath_scale * breath_env); + setFrequency(sax, frequency + freq_env); + output = (sample_type) tick(sax)") +(SUPPORT-HEADER "#define SAX_CONTROL_CHANGE_CONST 128\n") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n#include \"upsample.h\"\n") +(FINALIZATION " deleteInstrument(susp->sax);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.c b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.c index 284dd7f52..e0124dd26 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.c +++ b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrsaxfreq.h" -void sax_freq_free(); +void sax_freq_free(snd_susp_type a_susp); typedef struct sax_freq_susp_struct { @@ -24,87 +24,17 @@ typedef struct sax_freq_susp_struct { struct instr *sax; int temp_ret_value; + float breath_scale; double frequency; } sax_freq_susp_node, *sax_freq_susp_type; - - #include "instr.h" +#include "instr.h" +#include "upsample.h" -void sax_freq_nn_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * sax_reg; - register double frequency_reg; - register sample_block_values_type freq_env_ptr_reg; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "sax_freq_nn_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - sax_reg = susp->sax; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * *breath_env_ptr_reg++); - setFrequency(sax_reg, frequency_reg + *freq_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(sax_reg); - } while (--n); /* inner loop */ - - susp->sax = sax_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* sax_freq_nn_fetch */ - - -void sax_freq_ns_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) +void sax_freq_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sax_freq_susp_type susp = (sax_freq_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -114,6 +44,7 @@ void sax_freq_ns_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) register sample_block_values_type out_ptr_reg; register struct instr * sax_reg; + register float breath_scale_reg; register double frequency_reg; register sample_type freq_env_scale_reg = susp->freq_env->scale; register sample_block_values_type freq_env_ptr_reg; @@ -139,20 +70,21 @@ void sax_freq_ns_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; sax_reg = susp->sax; + breath_scale_reg = susp->breath_scale; frequency_reg = susp->frequency; freq_env_ptr_reg = susp->freq_env_ptr; breath_env_ptr_reg = susp->breath_env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * *breath_env_ptr_reg++); - setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(sax_reg); + controlChange(sax_reg, 128, breath_scale_reg * *breath_env_ptr_reg++); + setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); + *out_ptr_reg++ = (sample_type) tick(sax_reg); } while (--n); /* inner loop */ susp->sax = sax_reg; @@ -176,158 +108,9 @@ void sax_freq_ns_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) } /* sax_freq_ns_fetch */ -void sax_freq_sn_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * sax_reg; - register double frequency_reg; - register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "sax_freq_sn_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - sax_reg = susp->sax; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - setFrequency(sax_reg, frequency_reg + *freq_env_ptr_reg++); - *out_ptr_reg++ = (sample_type) tick(sax_reg); - } while (--n); /* inner loop */ - - susp->sax = sax_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* sax_freq_sn_fetch */ - - -void sax_freq_ss_fetch(register sax_freq_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct instr * sax_reg; - register double frequency_reg; - register sample_type freq_env_scale_reg = susp->freq_env->scale; - register sample_block_values_type freq_env_ptr_reg; - register sample_type breath_env_scale_reg = susp->breath_env->scale; - register sample_block_values_type breath_env_ptr_reg; - falloc_sample_block(out, "sax_freq_ss_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the breath_env input sample block: */ - susp_check_term_samples(breath_env, breath_env_ptr, breath_env_cnt); - togo = min(togo, susp->breath_env_cnt); - - /* don't run past the freq_env input sample block: */ - susp_check_samples(freq_env, freq_env_ptr, freq_env_cnt); - togo = min(togo, susp->freq_env_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - n = togo; - sax_reg = susp->sax; - frequency_reg = susp->frequency; - freq_env_ptr_reg = susp->freq_env_ptr; - breath_env_ptr_reg = susp->breath_env_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - controlChange(sax_reg, 128, SAX_CONTROL_CHANGE_CONST * (breath_env_scale_reg * *breath_env_ptr_reg++)); - setFrequency(sax_reg, frequency_reg + (freq_env_scale_reg * *freq_env_ptr_reg++)); - *out_ptr_reg++ = (sample_type) tick(sax_reg); - } while (--n); /* inner loop */ - - susp->sax = sax_reg; - /* using freq_env_ptr_reg is a bad idea on RS/6000: */ - susp->freq_env_ptr += togo; - /* using breath_env_ptr_reg is a bad idea on RS/6000: */ - susp->breath_env_ptr += togo; - out_ptr += togo; - susp_took(breath_env_cnt, togo); - susp_took(freq_env_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } -} /* sax_freq_ss_fetch */ - - -void sax_freq_toss_fetch(susp, snd_list) - register sax_freq_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void sax_freq_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + sax_freq_susp_type susp = (sax_freq_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -350,29 +133,31 @@ void sax_freq_toss_fetch(susp, snd_list) susp->freq_env_ptr += n; susp_took(freq_env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void sax_freq_mark(sax_freq_susp_type susp) +void sax_freq_mark(snd_susp_type a_susp) { + sax_freq_susp_type susp = (sax_freq_susp_type) a_susp; sound_xlmark(susp->breath_env); sound_xlmark(susp->freq_env); } -void sax_freq_free(sax_freq_susp_type susp) +void sax_freq_free(snd_susp_type a_susp) { - - deleteInstrument(susp->sax); + sax_freq_susp_type susp = (sax_freq_susp_type) a_susp; + deleteInstrument(susp->sax); sound_unref(susp->breath_env); sound_unref(susp->freq_env); ffree_generic(susp, sizeof(sax_freq_susp_node), "sax_freq_free"); } -void sax_freq_print_tree(sax_freq_susp_type susp, int n) +void sax_freq_print_tree(snd_susp_type a_susp, int n) { + sax_freq_susp_type susp = (sax_freq_susp_type) a_susp; indent(n); stdputstr("breath_env:"); sound_print_tree_1(susp->breath_env, n); @@ -388,26 +173,25 @@ sound_type snd_make_sax_freq(double freq, sound_type breath_env, sound_type freq register sax_freq_susp_type susp; /* sr specified as input parameter */ time_type t0 = breath_env->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, sax_freq_susp_node, "snd_make_sax_freq"); susp->sax = initInstrument(SAXOFONY, round(sr)); controlChange(susp->sax, 1, 0.0);; susp->temp_ret_value = noteOn(susp->sax, freq, 1.0); + susp->breath_scale = breath_env->scale * SAX_CONTROL_CHANGE_CONST; susp->frequency = freq; - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(breath_env, sr); - interp_desc = (interp_desc << 2) + interp_style(freq_env, sr); - switch (interp_desc) { - case INTERP_nn: susp->susp.fetch = sax_freq_nn_fetch; break; - case INTERP_ns: susp->susp.fetch = sax_freq_ns_fetch; break; - case INTERP_sn: susp->susp.fetch = sax_freq_sn_fetch; break; - case INTERP_ss: susp->susp.fetch = sax_freq_ss_fetch; break; - default: snd_badsr(); break; - } - + /* make sure no sample rate is too high */ + if (breath_env->sr > sr) { + sound_unref(breath_env); + snd_badsr(); + } else if (breath_env->sr < sr) breath_env = snd_make_up(sr, breath_env); + if (freq_env->sr > sr) { + sound_unref(freq_env); + snd_badsr(); + } else if (freq_env->sr < sr) freq_env = snd_make_up(sr, freq_env); + susp->susp.fetch = sax_freq_ns_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < breath_env->t0) sound_prepend_zeros(breath_env, t0); @@ -417,8 +201,8 @@ sound_type snd_make_sax_freq(double freq, sound_type breath_env, sound_type freq /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = sax_freq_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = sax_freq_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.h b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.h index 71e2f4d3b..a0b0796b5 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsaxfreq.h +++ b/lib-src/libnyquist/nyquist/tran/instrsaxfreq.h @@ -1,5 +1,4 @@ sound_type snd_make_sax_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); sound_type snd_sax_freq(double freq, sound_type breath_env, sound_type freq_env, rate_type sr); /* LISP: (snd-sax_freq ANYNUM SOUND SOUND ANYNUM) */ - - #define SAX_CONTROL_CHANGE_CONST 128 +#define SAX_CONTROL_CHANGE_CONST 128 diff --git a/lib-src/libnyquist/nyquist/tran/instrsitar.alg b/lib-src/libnyquist/nyquist/tran/instrsitar.alg index d2d2d56a6..dc5bd394c 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsitar.alg +++ b/lib-src/libnyquist/nyquist/tran/instrsitar.alg @@ -1,17 +1,13 @@ (INSTRSITAR-ALG (NAME "sitar") -(ARGUMENTS ("time_type" "t0")("double" "freq")("time_type" "dur")("rate_type" "sr")) +(ARGUMENTS ("time_type" "t0") ("double" "freq") ("time_type" "dur") + ("rate_type" "sr")) (STATE ("struct instr *" "mysitar" "initInstrument(SITAR, round(sr))") ("int" "temp_ret_value" "noteOn(susp->mysitar, freq, 1.0)")) (NOT-IN-INNER-LOOP "freq" "temp_ret_value") (SAMPLE-RATE "sr") (TERMINATE (after "dur")) -(INNER-LOOP " - output = (sample_type) tick(mysitar)") -(SUPPORT-FUNCTIONS " - #include \"instr.h\" -") -(FINALIZATION " - deleteInstrument(susp->mysitar); -") +(INNER-LOOP "output = (sample_type) tick(mysitar)") +(SUPPORT-FUNCTIONS "#include \"instr.h\"\n") +(FINALIZATION " deleteInstrument(susp->mysitar);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/instrsitar.c b/lib-src/libnyquist/nyquist/tran/instrsitar.c index 9aa812742..2c05d89ea 100644 --- a/lib-src/libnyquist/nyquist/tran/instrsitar.c +++ b/lib-src/libnyquist/nyquist/tran/instrsitar.c @@ -9,7 +9,7 @@ #include "cext.h" #include "instrsitar.h" -void sitar_free(); +void sitar_free(snd_susp_type a_susp); typedef struct sitar_susp_struct { @@ -20,12 +20,12 @@ typedef struct sitar_susp_struct { int temp_ret_value; } sitar_susp_node, *sitar_susp_type; - - #include "instr.h" +#include "instr.h" -void sitar__fetch(register sitar_susp_type susp, snd_list_type snd_list) +void sitar__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sitar_susp_type susp = (sitar_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -48,6 +48,7 @@ void sitar__fetch(register sitar_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -55,8 +56,7 @@ void sitar__fetch(register sitar_susp_type susp, snd_list_type snd_list) mysitar_reg = susp->mysitar; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) tick(mysitar_reg); + *out_ptr_reg++ = (sample_type) tick(mysitar_reg); } while (--n); /* inner loop */ susp->mysitar = mysitar_reg; @@ -74,15 +74,15 @@ void sitar__fetch(register sitar_susp_type susp, snd_list_type snd_list) } /* sitar__fetch */ -void sitar_free(sitar_susp_type susp) +void sitar_free(snd_susp_type a_susp) { - - deleteInstrument(susp->mysitar); + sitar_susp_type susp = (sitar_susp_type) a_susp; + deleteInstrument(susp->mysitar); ffree_generic(susp, sizeof(sitar_susp_node), "sitar_free"); } -void sitar_print_tree(sitar_susp_type susp, int n) +void sitar_print_tree(snd_susp_type a_susp, int n) { } @@ -98,7 +98,7 @@ sound_type snd_make_sitar(time_type t0, double freq, time_type dur, rate_type sr susp->temp_ret_value = noteOn(susp->mysitar, freq, 1.0); susp->susp.fetch = sitar__fetch; - susp->terminate_cnt = round((dur) * sr); + susp->terminate_cnt = check_terminate_cnt(round((dur) * sr)); /* initialize susp state */ susp->susp.free = sitar_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/integrate.alg b/lib-src/libnyquist/nyquist/tran/integrate.alg index 34b4ecbd1..665f8a5c2 100644 --- a/lib-src/libnyquist/nyquist/tran/integrate.alg +++ b/lib-src/libnyquist/nyquist/tran/integrate.alg @@ -7,6 +7,6 @@ (LOGICAL-STOP (MIN input)) (STATE ("double" "integral" "0.0; scale_factor = (sample_type) (scale_factor / input->sr)")) -(INNER-LOOP "output = (sample_type) integral; integral += input;") +(INNER-LOOP "output = (sample_type) integral; integral += input") ) diff --git a/lib-src/libnyquist/nyquist/tran/integrate.c b/lib-src/libnyquist/nyquist/tran/integrate.c index f9459ffa1..510eda9b4 100644 --- a/lib-src/libnyquist/nyquist/tran/integrate.c +++ b/lib-src/libnyquist/nyquist/tran/integrate.c @@ -9,7 +9,7 @@ #include "cext.h" #include "integrate.h" -void integrate_free(); +void integrate_free(snd_susp_type a_susp); typedef struct integrate_susp_struct { @@ -24,8 +24,9 @@ typedef struct integrate_susp_struct { } integrate_susp_node, *integrate_susp_type; -void integrate_n_fetch(register integrate_susp_type susp, snd_list_type snd_list) +void integrate_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + integrate_susp_type susp = (integrate_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void integrate_n_fetch(register integrate_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void integrate_n_fetch(register integrate_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,7 @@ void integrate_n_fetch(register integrate_susp_type susp, snd_list_type snd_list input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) integral_reg; integral_reg += *input_ptr_reg++;; + *out_ptr_reg++ = (sample_type) integral_reg; integral_reg += *input_ptr_reg++; } while (--n); /* inner loop */ susp->integral = integral_reg; @@ -113,11 +116,9 @@ void integrate_n_fetch(register integrate_susp_type susp, snd_list_type snd_list } /* integrate_n_fetch */ -void integrate_toss_fetch(susp, snd_list) - register integrate_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void integrate_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + integrate_susp_type susp = (integrate_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -132,25 +133,28 @@ void integrate_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void integrate_mark(integrate_susp_type susp) +void integrate_mark(snd_susp_type a_susp) { + integrate_susp_type susp = (integrate_susp_type) a_susp; sound_xlmark(susp->input); } -void integrate_free(integrate_susp_type susp) +void integrate_free(snd_susp_type a_susp) { + integrate_susp_type susp = (integrate_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(integrate_susp_node), "integrate_free"); } -void integrate_print_tree(integrate_susp_type susp, int n) +void integrate_print_tree(snd_susp_type a_susp, int n) { + integrate_susp_type susp = (integrate_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -162,7 +166,6 @@ sound_type snd_make_integrate(sound_type input) register integrate_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; /* combine scale factors of linear inputs (INPUT) */ @@ -184,8 +187,8 @@ sound_type snd_make_integrate(sound_type input) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = integrate_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = integrate_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/log.c b/lib-src/libnyquist/nyquist/tran/log.c index deb8d996a..6df2a7fb8 100644 --- a/lib-src/libnyquist/nyquist/tran/log.c +++ b/lib-src/libnyquist/nyquist/tran/log.c @@ -9,7 +9,7 @@ #include "cext.h" #include "log.h" -void log_free(); +void log_free(snd_susp_type a_susp); typedef struct log_susp_struct { @@ -22,8 +22,9 @@ typedef struct log_susp_struct { } log_susp_node, *log_susp_type; -void log_s_fetch(register log_susp_type susp, snd_list_type snd_list) +void log_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + log_susp_type susp = (log_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -51,6 +52,7 @@ void log_s_fetch(register log_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -62,6 +64,7 @@ void log_s_fetch(register log_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -83,7 +86,7 @@ void log_s_fetch(register log_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) log((input_scale_reg * *input_ptr_reg++)); + *out_ptr_reg++ = (sample_type) log((input_scale_reg * *input_ptr_reg++)); } while (--n); /* inner loop */ /* using input_ptr_reg is a bad idea on RS/6000: */ @@ -109,11 +112,9 @@ void log_s_fetch(register log_susp_type susp, snd_list_type snd_list) } /* log_s_fetch */ -void log_toss_fetch(susp, snd_list) - register log_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void log_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + log_susp_type susp = (log_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -128,25 +129,28 @@ void log_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void log_mark(log_susp_type susp) +void log_mark(snd_susp_type a_susp) { + log_susp_type susp = (log_susp_type) a_susp; sound_xlmark(susp->input); } -void log_free(log_susp_type susp) +void log_free(snd_susp_type a_susp) { + log_susp_type susp = (log_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(log_susp_node), "log_free"); } -void log_print_tree(log_susp_type susp, int n) +void log_print_tree(snd_susp_type a_susp, int n) { + log_susp_type susp = (log_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -158,7 +162,6 @@ sound_type snd_make_log(sound_type input) register log_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, log_susp_node, "snd_make_log"); @@ -171,8 +174,8 @@ sound_type snd_make_log(sound_type input) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = log_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = log_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/lpreson.alg b/lib-src/libnyquist/nyquist/tran/lpreson.alg index 65e517930..e2eafc6f1 100644 --- a/lib-src/libnyquist/nyquist/tran/lpreson.alg +++ b/lib-src/libnyquist/nyquist/tran/lpreson.alg @@ -9,7 +9,7 @@ (ALWAYS-SCALE x_snd) (TERMINATE (MIN x_snd)) (LOGICAL-STOP (MIN x_snd)) -(SAMPLE-RATE "x_snd->sr") +(SAMPLE-RATE (MAX x_snd)) (STATE ("long" "fr_indx" "0") ("long" "ak_len" "0") ; length of coefs ak array @@ -84,26 +84,21 @@ out: togo = 0; /* indicate termination */ ") -(INNER-LOOP-LOCALS "double z0; long xi; long xj;") +(INNER-LOOP-LOCALS " double z0; long xi; long xj;") -(INNER-LOOP " - z0 = x_snd * gain; - for (xi=0; xi < ak_len; xi++) { - xj = index + xi; if (xj >= ak_len) xj -= ak_len; - z0 += ak_coefs[xi] * zk_buf[xj]; - } - zk_buf[index] = z0; - index++; if (index == ak_len) index = 0; - fr_indx++; - output = (sample_type) z0; -") +(INNER-LOOP "z0 = x_snd * gain; + for (xi=0; xi < ak_len; xi++) { + xj = index + xi; if (xj >= ak_len) xj -= ak_len; + z0 += ak_coefs[xi] * zk_buf[xj]; + } + zk_buf[index] = z0; + index++; if (index == ak_len) index = 0; + fr_indx++; + output = (sample_type) z0") (CONSTANT "frame_length" "src") - -(FINALIZATION " free(susp->ak_coefs); - free(susp->zk_buf); -") - +(FINALIZATION " free(susp->ak_coefs); + free(susp->zk_buf);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/lpreson.c b/lib-src/libnyquist/nyquist/tran/lpreson.c index 3c08f05fc..318d93bbd 100644 --- a/lib-src/libnyquist/nyquist/tran/lpreson.c +++ b/lib-src/libnyquist/nyquist/tran/lpreson.c @@ -9,7 +9,7 @@ #include "cext.h" #include "lpreson.h" -void lpreson_free(); +void lpreson_free(snd_susp_type a_susp); typedef struct lpreson_susp_struct { @@ -36,8 +36,9 @@ typedef struct lpreson_susp_struct { -void lpreson_s_fetch(register lpreson_susp_type susp, snd_list_type snd_list) +void lpreson_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + lpreson_susp_type susp = (lpreson_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -71,6 +72,7 @@ void lpreson_s_fetch(register lpreson_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -82,6 +84,7 @@ void lpreson_s_fetch(register lpreson_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -169,17 +172,15 @@ out: togo = 0; /* indicate termination */ x_snd_ptr_reg = susp->x_snd_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double z0; long xi; long xj; - z0 = (x_snd_scale_reg * *x_snd_ptr_reg++) * gain_reg; - for (xi=0; xi < ak_len_reg; xi++) { - xj = index_reg + xi; if (xj >= ak_len_reg) xj -= ak_len_reg; - z0 += ak_coefs_reg[xi] * zk_buf_reg[xj]; - } - zk_buf_reg[index_reg] = z0; - index_reg++; if (index_reg == ak_len_reg) index_reg = 0; - fr_indx_reg++; - *out_ptr_reg++ = (sample_type) z0; -; + double z0; long xi; long xj; z0 = (x_snd_scale_reg * *x_snd_ptr_reg++) * gain_reg; + for (xi=0; xi < ak_len_reg; xi++) { + xj = index_reg + xi; if (xj >= ak_len_reg) xj -= ak_len_reg; + z0 += ak_coefs_reg[xi] * zk_buf_reg[xj]; + } + zk_buf_reg[index_reg] = z0; + index_reg++; if (index_reg == ak_len_reg) index_reg = 0; + fr_indx_reg++; + *out_ptr_reg++ = (sample_type) z0; } while (--n); /* inner loop */ susp->fr_indx = fr_indx_reg; @@ -211,11 +212,9 @@ double z0; long xi; long xj; } /* lpreson_s_fetch */ -void lpreson_toss_fetch(susp, snd_list) - register lpreson_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void lpreson_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + lpreson_susp_type susp = (lpreson_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -230,29 +229,32 @@ void lpreson_toss_fetch(susp, snd_list) susp->x_snd_ptr += n; susp_took(x_snd_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void lpreson_mark(lpreson_susp_type susp) +void lpreson_mark(snd_susp_type a_susp) { + lpreson_susp_type susp = (lpreson_susp_type) a_susp; if (susp->frame) mark(susp->frame); if (susp->src) mark(susp->src); sound_xlmark(susp->x_snd); } -void lpreson_free(lpreson_susp_type susp) +void lpreson_free(snd_susp_type a_susp) { - free(susp->ak_coefs); - free(susp->zk_buf); + lpreson_susp_type susp = (lpreson_susp_type) a_susp; + free(susp->ak_coefs); + free(susp->zk_buf); sound_unref(susp->x_snd); ffree_generic(susp, sizeof(lpreson_susp_node), "lpreson_free"); } -void lpreson_print_tree(lpreson_susp_type susp, int n) +void lpreson_print_tree(snd_susp_type a_susp, int n) { + lpreson_susp_type susp = (lpreson_susp_type) a_susp; indent(n); stdputstr("x_snd:"); sound_print_tree_1(susp->x_snd, n); @@ -264,7 +266,6 @@ sound_type snd_make_lpreson(sound_type x_snd, LVAL src, time_type frame_time) register lpreson_susp_type susp; rate_type sr = x_snd->sr; time_type t0 = x_snd->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, lpreson_susp_node, "snd_make_lpreson"); @@ -286,8 +287,8 @@ sound_type snd_make_lpreson(sound_type x_snd, LVAL src, time_type frame_time) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = lpreson_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = lpreson_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/maxv.alg b/lib-src/libnyquist/nyquist/tran/maxv.alg index d80092173..5e52e5f49 100644 --- a/lib-src/libnyquist/nyquist/tran/maxv.alg +++ b/lib-src/libnyquist/nyquist/tran/maxv.alg @@ -1,11 +1,14 @@ (MAXV-ALG (NAME "maxv") (ARGUMENTS ("sound_type" "s1") ("sound_type" "s2")) - (ALWAYS-SCALE s1 s2) + (SAMPLE-RATE (MAX s1 s2)) + (COMMUTATIVE (s1 s2)) (START (MAX s1 s2)) - (INNER-LOOP "double x1 = s1; - double x2 = s2; - output = (sample_type) (x1 > x2 ? x1 : x2)") + (INNER-LOOP "{ +\t\tdouble x1 = s1; +\t\tdouble x2 = s2; +\t\toutput = (sample_type) (x1 > x2 ? x1 : x2); +\t }") (TERMINATE (MIN s1 s2)) (LOGICAL-STOP (MIN s1 s2)) ) diff --git a/lib-src/libnyquist/nyquist/tran/maxv.c b/lib-src/libnyquist/nyquist/tran/maxv.c index a313b2efd..6eecd4f29 100644 --- a/lib-src/libnyquist/nyquist/tran/maxv.c +++ b/lib-src/libnyquist/nyquist/tran/maxv.c @@ -9,11 +9,12 @@ #include "cext.h" #include "maxv.h" -void maxv_free(); +void maxv_free(snd_susp_type a_susp); typedef struct maxv_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; boolean logically_stopped; sound_type s1; @@ -22,11 +23,474 @@ typedef struct maxv_susp_struct { sound_type s2; long s2_cnt; sample_block_values_type s2_ptr; + + /* support for interpolation of s2 */ + sample_type s2_x1_sample; + double s2_pHaSe; + double s2_pHaSe_iNcR; + + /* support for ramp between samples of s2 */ + double output_per_s2; + long s2_n; } maxv_susp_node, *maxv_susp_type; -void maxv_ss_fetch(register maxv_susp_type susp, snd_list_type snd_list) +void maxv_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_block_values_type s2_ptr_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_nn_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past the s2 input sample block: */ + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + togo = min(togo, susp->s2_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_ptr_reg = susp->s2_ptr; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + { + double x1 = *s1_ptr_reg++; + double x2 = *s2_ptr_reg++; + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + } while (--n); /* inner loop */ + + /* using s2_ptr_reg is a bad idea on RS/6000: */ + susp->s2_ptr += togo; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp_took(s2_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_nn_fetch */ + + +void maxv_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type s2_scale_reg = susp->s2->scale; + register sample_block_values_type s2_ptr_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_ns_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past the s2 input sample block: */ + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + togo = min(togo, susp->s2_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_ptr_reg = susp->s2_ptr; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + { + double x1 = *s1_ptr_reg++; + double x2 = (s2_scale_reg * *s2_ptr_reg++); + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + } while (--n); /* inner loop */ + + /* using s2_ptr_reg is a bad idea on RS/6000: */ + susp->s2_ptr += togo; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp_took(s2_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_ns_fetch */ + + +void maxv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double s2_pHaSe_iNcR_rEg = susp->s2_pHaSe_iNcR; + register double s2_pHaSe_ReG; + register sample_type s2_x1_sample_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + susp->s2_x1_sample = susp_fetch_sample(s2, s2_ptr, s2_cnt); + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_pHaSe_ReG = susp->s2_pHaSe; + s2_x1_sample_reg = susp->s2_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s2_pHaSe_ReG >= 1.0) { + s2_x1_sample_reg = s2_x2_sample; + /* pick up next sample as s2_x2_sample: */ + susp->s2_ptr++; + susp_took(s2_cnt, 1); + s2_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(s2, s2_ptr, s2_cnt, s2_x2_sample); + } + { + double x1 = *s1_ptr_reg++; + double x2 = + (s2_x1_sample_reg * (1 - s2_pHaSe_ReG) + s2_x2_sample * s2_pHaSe_ReG); + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + s2_pHaSe_ReG += s2_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->s2_pHaSe = s2_pHaSe_ReG; + susp->s2_x1_sample = s2_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_ni_fetch */ + + +void maxv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_DeLtA; + sample_type s2_val; + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s2_pHaSe = 1.0; + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next s2_x2_sample when phase goes past 1.0; */ + /* we use s2_n (computed below) to avoid roundoff errors: */ + if (susp->s2_n <= 0) { + susp->s2_x1_sample = s2_x2_sample; + susp->s2_ptr++; + susp_took(s2_cnt, 1); + susp->s2_pHaSe -= 1.0; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + /* s2_n gets number of samples before phase exceeds 1.0: */ + susp->s2_n = (long) ((1.0 - susp->s2_pHaSe) * + susp->output_per_s2); + } + togo = min(togo, susp->s2_n); + s2_DeLtA = (sample_type) ((s2_x2_sample - susp->s2_x1_sample) * susp->s2_pHaSe_iNcR); + s2_val = (sample_type) (susp->s2_x1_sample * (1.0 - susp->s2_pHaSe) + + s2_x2_sample * susp->s2_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + { + double x1 = *s1_ptr_reg++; + double x2 = s2_val; + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + s2_val += s2_DeLtA; + } while (--n); /* inner loop */ + + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->s2_pHaSe += togo * susp->s2_pHaSe_iNcR; + susp->s2_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_nr_fetch */ + + +void maxv_ss_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + maxv_susp_type susp = (maxv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -60,6 +524,7 @@ void maxv_ss_fetch(register maxv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -71,6 +536,7 @@ void maxv_ss_fetch(register maxv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -93,9 +559,11 @@ void maxv_ss_fetch(register maxv_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -double x1 = (s1_scale_reg * *s1_ptr_reg++); - double x2 = (s2_scale_reg * *s2_ptr_reg++); - *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + { + double x1 = (s1_scale_reg * *s1_ptr_reg++); + double x2 = (s2_scale_reg * *s2_ptr_reg++); + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; } while (--n); /* inner loop */ /* using s2_ptr_reg is a bad idea on RS/6000: */ @@ -124,11 +592,259 @@ double x1 = (s1_scale_reg * *s1_ptr_reg++); } /* maxv_ss_fetch */ -void maxv_toss_fetch(susp, snd_list) - register maxv_susp_type susp; - snd_list_type snd_list; +void maxv_si_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double s2_pHaSe_iNcR_rEg = susp->s2_pHaSe_iNcR; + register double s2_pHaSe_ReG; + register sample_type s2_x1_sample_reg; + register sample_type s1_scale_reg = susp->s1->scale; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_si_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + susp->s2_x1_sample = susp_fetch_sample(s2, s2_ptr, s2_cnt); + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_pHaSe_ReG = susp->s2_pHaSe; + s2_x1_sample_reg = susp->s2_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s2_pHaSe_ReG >= 1.0) { + s2_x1_sample_reg = s2_x2_sample; + /* pick up next sample as s2_x2_sample: */ + susp->s2_ptr++; + susp_took(s2_cnt, 1); + s2_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(s2, s2_ptr, s2_cnt, s2_x2_sample); + } + { + double x1 = (s1_scale_reg * *s1_ptr_reg++); + double x2 = + (s2_x1_sample_reg * (1 - s2_pHaSe_ReG) + s2_x2_sample * s2_pHaSe_ReG); + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + s2_pHaSe_ReG += s2_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->s2_pHaSe = s2_pHaSe_ReG; + susp->s2_x1_sample = s2_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_si_fetch */ + + +void maxv_sr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + maxv_susp_type susp = (maxv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_DeLtA; + sample_type s2_val; + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_type s1_scale_reg = susp->s1->scale; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "maxv_sr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s2_pHaSe = 1.0; + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next s2_x2_sample when phase goes past 1.0; */ + /* we use s2_n (computed below) to avoid roundoff errors: */ + if (susp->s2_n <= 0) { + susp->s2_x1_sample = s2_x2_sample; + susp->s2_ptr++; + susp_took(s2_cnt, 1); + susp->s2_pHaSe -= 1.0; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + /* s2_n gets number of samples before phase exceeds 1.0: */ + susp->s2_n = (long) ((1.0 - susp->s2_pHaSe) * + susp->output_per_s2); + } + togo = min(togo, susp->s2_n); + s2_DeLtA = (sample_type) ((s2_x2_sample - susp->s2_x1_sample) * susp->s2_pHaSe_iNcR); + s2_val = (sample_type) (susp->s2_x1_sample * (1.0 - susp->s2_pHaSe) + + s2_x2_sample * susp->s2_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + { + double x1 = (s1_scale_reg * *s1_ptr_reg++); + double x2 = s2_val; + *out_ptr_reg++ = (sample_type) (x1 > x2 ? x1 : x2); + }; + s2_val += s2_DeLtA; + } while (--n); /* inner loop */ + + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->s2_pHaSe += togo * susp->s2_pHaSe_iNcR; + susp->s2_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* maxv_sr_fetch */ + + +void maxv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + maxv_susp_type susp = (maxv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -151,27 +867,30 @@ void maxv_toss_fetch(susp, snd_list) susp->s2_ptr += n; susp_took(s2_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void maxv_mark(maxv_susp_type susp) +void maxv_mark(snd_susp_type a_susp) { + maxv_susp_type susp = (maxv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->s2); } -void maxv_free(maxv_susp_type susp) +void maxv_free(snd_susp_type a_susp) { + maxv_susp_type susp = (maxv_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->s2); ffree_generic(susp, sizeof(maxv_susp_node), "maxv_free"); } -void maxv_print_tree(maxv_susp_type susp, int n) +void maxv_print_tree(snd_susp_type a_susp, int n) { + maxv_susp_type susp = (maxv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -191,8 +910,25 @@ sound_type snd_make_maxv(sound_type s1, sound_type s2) sample_type scale_factor = 1.0F; time_type t0_min = t0; long lsc; + /* sort commutative signals: (S1 S2) */ + snd_sort_2(&s1, &s2, sr); + falloc_generic(susp, maxv_susp_node, "snd_make_maxv"); - susp->susp.fetch = maxv_ss_fetch; + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(s1, sr); + interp_desc = (interp_desc << 2) + interp_style(s2, sr); + switch (interp_desc) { + case INTERP_nn: susp->susp.fetch = maxv_nn_fetch; break; + case INTERP_ns: susp->susp.fetch = maxv_ns_fetch; break; + case INTERP_ni: susp->susp.fetch = maxv_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = maxv_nr_fetch; break; + case INTERP_ss: susp->susp.fetch = maxv_ss_fetch; break; + case INTERP_si: susp->susp.fetch = maxv_si_fetch; break; + case INTERP_sr: susp->susp.fetch = maxv_sr_fetch; break; + default: snd_badsr(); break; + } + susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -202,8 +938,8 @@ sound_type snd_make_maxv(sound_type s1, sound_type s2) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = maxv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = maxv_toss_fetch; } /* initialize susp state */ @@ -218,11 +954,16 @@ sound_type snd_make_maxv(sound_type s1, sound_type s2) lsc = logical_stop_cnt_cvt(s2); if (susp->susp.log_stop_cnt > lsc) susp->susp.log_stop_cnt = lsc; + susp->started = false; susp->susp.current = 0; susp->s1 = s1; susp->s1_cnt = 0; susp->s2 = s2; susp->s2_cnt = 0; + susp->s2_pHaSe = 0.0; + susp->s2_pHaSe_iNcR = s2->sr / sr; + susp->s2_n = 0; + susp->output_per_s2 = sr / s2->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/offset.c b/lib-src/libnyquist/nyquist/tran/offset.c index 9d62b1e1e..4b2d20b65 100644 --- a/lib-src/libnyquist/nyquist/tran/offset.c +++ b/lib-src/libnyquist/nyquist/tran/offset.c @@ -9,7 +9,7 @@ #include "cext.h" #include "offset.h" -void offset_free(); +void offset_free(snd_susp_type a_susp); typedef struct offset_susp_struct { @@ -24,8 +24,9 @@ typedef struct offset_susp_struct { } offset_susp_node, *offset_susp_type; -void offset_n_fetch(register offset_susp_type susp, snd_list_type snd_list) +void offset_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + offset_susp_type susp = (offset_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void offset_n_fetch(register offset_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void offset_n_fetch(register offset_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,7 @@ void offset_n_fetch(register offset_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *s1_ptr_reg++ + offset_reg; + *out_ptr_reg++ = *s1_ptr_reg++ + offset_reg; } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000: */ @@ -112,8 +115,9 @@ void offset_n_fetch(register offset_susp_type susp, snd_list_type snd_list) } /* offset_n_fetch */ -void offset_s_fetch(register offset_susp_type susp, snd_list_type snd_list) +void offset_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + offset_susp_type susp = (offset_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -142,6 +146,7 @@ void offset_s_fetch(register offset_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -153,6 +158,7 @@ void offset_s_fetch(register offset_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -175,7 +181,7 @@ void offset_s_fetch(register offset_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (s1_scale_reg * *s1_ptr_reg++) + offset_reg; + *out_ptr_reg++ = (s1_scale_reg * *s1_ptr_reg++) + offset_reg; } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000: */ @@ -201,11 +207,9 @@ void offset_s_fetch(register offset_susp_type susp, snd_list_type snd_list) } /* offset_s_fetch */ -void offset_toss_fetch(susp, snd_list) - register offset_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void offset_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + offset_susp_type susp = (offset_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -220,25 +224,28 @@ void offset_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void offset_mark(offset_susp_type susp) +void offset_mark(snd_susp_type a_susp) { + offset_susp_type susp = (offset_susp_type) a_susp; sound_xlmark(susp->s1); } -void offset_free(offset_susp_type susp) +void offset_free(snd_susp_type a_susp) { + offset_susp_type susp = (offset_susp_type) a_susp; sound_unref(susp->s1); ffree_generic(susp, sizeof(offset_susp_node), "offset_free"); } -void offset_print_tree(offset_susp_type susp, int n) +void offset_print_tree(snd_susp_type a_susp, int n) { + offset_susp_type susp = (offset_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -272,8 +279,8 @@ sound_type snd_make_offset(sound_type s1, double offset) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = offset_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = offset_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/oneshot.alg b/lib-src/libnyquist/nyquist/tran/oneshot.alg index a90282e6b..bd1bfc9aa 100644 --- a/lib-src/libnyquist/nyquist/tran/oneshot.alg +++ b/lib-src/libnyquist/nyquist/tran/oneshot.alg @@ -6,10 +6,10 @@ ("long" "oncount" "round(ontime * input->sr)") ("long" "cnt" "0")) (START (MIN input)) - (INNER-LOOP " double x = input; - if (x > lev) cnt = oncount; - cnt--; - output = (cnt >= 0 ? 1.0F : 0.0F);") + (INNER-LOOP "double x = input; + if (x > lev) cnt = oncount; + cnt--; + output = (cnt >= 0 ? 1.0F : 0.0F);") (CONSTANT "lev" "oncount") (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) diff --git a/lib-src/libnyquist/nyquist/tran/oneshot.c b/lib-src/libnyquist/nyquist/tran/oneshot.c index 9b880ba59..a82ec8b42 100644 --- a/lib-src/libnyquist/nyquist/tran/oneshot.c +++ b/lib-src/libnyquist/nyquist/tran/oneshot.c @@ -9,7 +9,7 @@ #include "cext.h" #include "oneshot.h" -void oneshot_free(); +void oneshot_free(snd_susp_type a_susp); typedef struct oneshot_susp_struct { @@ -26,8 +26,9 @@ typedef struct oneshot_susp_struct { } oneshot_susp_node, *oneshot_susp_type; -void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list) +void oneshot_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -57,6 +58,7 @@ void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -68,6 +70,7 @@ void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -92,10 +95,10 @@ void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double x = *input_ptr_reg++; - if (x > lev_reg) cnt_reg = oncount_reg; - cnt_reg--; - *out_ptr_reg++ = (cnt_reg >= 0 ? 1.0F : 0.0F);; + double x = *input_ptr_reg++; + if (x > lev_reg) cnt_reg = oncount_reg; + cnt_reg--; + *out_ptr_reg++ = (cnt_reg >= 0 ? 1.0F : 0.0F);; } while (--n); /* inner loop */ susp->cnt = cnt_reg; @@ -122,8 +125,9 @@ void oneshot_n_fetch(register oneshot_susp_type susp, snd_list_type snd_list) } /* oneshot_n_fetch */ -void oneshot_s_fetch(register oneshot_susp_type susp, snd_list_type snd_list) +void oneshot_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -154,6 +158,7 @@ void oneshot_s_fetch(register oneshot_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -165,6 +170,7 @@ void oneshot_s_fetch(register oneshot_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -189,10 +195,10 @@ void oneshot_s_fetch(register oneshot_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - double x = (input_scale_reg * *input_ptr_reg++); - if (x > lev_reg) cnt_reg = oncount_reg; - cnt_reg--; - *out_ptr_reg++ = (cnt_reg >= 0 ? 1.0F : 0.0F);; + double x = (input_scale_reg * *input_ptr_reg++); + if (x > lev_reg) cnt_reg = oncount_reg; + cnt_reg--; + *out_ptr_reg++ = (cnt_reg >= 0 ? 1.0F : 0.0F);; } while (--n); /* inner loop */ susp->cnt = cnt_reg; @@ -219,11 +225,9 @@ void oneshot_s_fetch(register oneshot_susp_type susp, snd_list_type snd_list) } /* oneshot_s_fetch */ -void oneshot_toss_fetch(susp, snd_list) - register oneshot_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void oneshot_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -238,25 +242,28 @@ void oneshot_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void oneshot_mark(oneshot_susp_type susp) +void oneshot_mark(snd_susp_type a_susp) { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; sound_xlmark(susp->input); } -void oneshot_free(oneshot_susp_type susp) +void oneshot_free(snd_susp_type a_susp) { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(oneshot_susp_node), "oneshot_free"); } -void oneshot_print_tree(oneshot_susp_type susp, int n) +void oneshot_print_tree(snd_susp_type a_susp, int n) { + oneshot_susp_type susp = (oneshot_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -292,8 +299,8 @@ sound_type snd_make_oneshot(sound_type input, double level, double ontime) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = oneshot_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = oneshot_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/osc.alg b/lib-src/libnyquist/nyquist/tran/osc.alg index 370509870..a3e649b83 100644 --- a/lib-src/libnyquist/nyquist/tran/osc.alg +++ b/lib-src/libnyquist/nyquist/tran/osc.alg @@ -14,18 +14,14 @@ input->sr, sr, hz, &susp->ph_incr)") ) ; "((hz * susp->table_len) / sr)") (TERMINATE (AFTER "d")) -(INNER-LOOP " - long table_index = (long) phase; - double x1 = table_ptr[table_index]; - output = (sample_type) (x1 + (phase - table_index) * - (table_ptr[table_index + 1] - x1)); - phase += ph_incr; - while (phase >= table_len) phase -= table_len; -") +(INNER-LOOP "long table_index = (long) phase; + double x1 = table_ptr[table_index]; + output = (sample_type) (x1 + (phase - table_index) * + (table_ptr[table_index + 1] - x1)); + phase += ph_incr; + while (phase >= table_len) phase -= table_len") (CONSTANT "ph_incr" "table_len" "table_ptr") - (SAMPLE-RATE "sr") -(FINALIZATION " table_unref(susp->the_table); -") +(FINALIZATION " table_unref(susp->the_table);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/osc.c b/lib-src/libnyquist/nyquist/tran/osc.c index c2e7ce532..47c8901a7 100644 --- a/lib-src/libnyquist/nyquist/tran/osc.c +++ b/lib-src/libnyquist/nyquist/tran/osc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "osc.h" -void osc_free(); +void osc_free(snd_susp_type a_susp); typedef struct osc_susp_struct { @@ -24,8 +24,9 @@ typedef struct osc_susp_struct { } osc_susp_node, *osc_susp_type; -void osc__fetch(register osc_susp_type susp, snd_list_type snd_list) +void osc__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + osc_susp_type susp = (osc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -51,6 +52,7 @@ void osc__fetch(register osc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -61,14 +63,12 @@ void osc__fetch(register osc_susp_type susp, snd_list_type snd_list) phase_reg = susp->phase; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - long table_index = (long) phase_reg; - double x1 = table_ptr_reg[table_index]; - *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * - (table_ptr_reg[table_index + 1] - x1)); - phase_reg += ph_incr_reg; - while (phase_reg >= table_len_reg) phase_reg -= table_len_reg; -; + long table_index = (long) phase_reg; + double x1 = table_ptr_reg[table_index]; + *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * + (table_ptr_reg[table_index + 1] - x1)); + phase_reg += ph_incr_reg; + while (phase_reg >= table_len_reg) phase_reg -= table_len_reg; } while (--n); /* inner loop */ susp->phase = phase_reg; @@ -86,14 +86,15 @@ void osc__fetch(register osc_susp_type susp, snd_list_type snd_list) } /* osc__fetch */ -void osc_free(osc_susp_type susp) +void osc_free(snd_susp_type a_susp) { + osc_susp_type susp = (osc_susp_type) a_susp; table_unref(susp->the_table); ffree_generic(susp, sizeof(osc_susp_node), "osc_free"); } -void osc_print_tree(osc_susp_type susp, int n) +void osc_print_tree(snd_susp_type a_susp, int n) { } @@ -113,7 +114,7 @@ sound_type snd_make_osc(sound_type input, double step, rate_type sr, double hz, input->sr, sr, hz, &susp->ph_incr); susp->susp.fetch = osc__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = osc_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/partial.c b/lib-src/libnyquist/nyquist/tran/partial.c index 4550f33db..decbd3ef3 100644 --- a/lib-src/libnyquist/nyquist/tran/partial.c +++ b/lib-src/libnyquist/nyquist/tran/partial.c @@ -9,17 +9,27 @@ #include "cext.h" #include "partial.h" -void partial_free(); +void partial_free(snd_susp_type a_susp); typedef struct partial_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; boolean logically_stopped; sound_type env; long env_cnt; sample_block_values_type env_ptr; + /* support for interpolation of env */ + sample_type env_x1_sample; + double env_pHaSe; + double env_pHaSe_iNcR; + + /* support for ramp between samples of env */ + double output_per_env; + long env_n; + long phase; long ph_incr; } partial_susp_node, *partial_susp_type; @@ -28,8 +38,9 @@ typedef struct partial_susp_struct { #include "sine.h" -void partial_n_fetch(register partial_susp_type susp, snd_list_type snd_list) +void partial_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + partial_susp_type susp = (partial_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -58,6 +69,7 @@ void partial_n_fetch(register partial_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -69,6 +81,7 @@ void partial_n_fetch(register partial_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -92,7 +105,7 @@ void partial_n_fetch(register partial_susp_type susp, snd_list_type snd_list) env_ptr_reg = susp->env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * *env_ptr_reg++; + *out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * *env_ptr_reg++; phase_reg += ph_incr_reg; phase_reg &= SINE_TABLE_MASK;; } while (--n); /* inner loop */ @@ -121,8 +134,9 @@ void partial_n_fetch(register partial_susp_type susp, snd_list_type snd_list) } /* partial_n_fetch */ -void partial_s_fetch(register partial_susp_type susp, snd_list_type snd_list) +void partial_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + partial_susp_type susp = (partial_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -152,6 +166,7 @@ void partial_s_fetch(register partial_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -163,6 +178,7 @@ void partial_s_fetch(register partial_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -186,7 +202,7 @@ void partial_s_fetch(register partial_susp_type susp, snd_list_type snd_list) env_ptr_reg = susp->env_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * (env_scale_reg * *env_ptr_reg++); + *out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * (env_scale_reg * *env_ptr_reg++); phase_reg += ph_incr_reg; phase_reg &= SINE_TABLE_MASK;; } while (--n); /* inner loop */ @@ -215,11 +231,245 @@ void partial_s_fetch(register partial_susp_type susp, snd_list_type snd_list) } /* partial_s_fetch */ -void partial_toss_fetch(susp, snd_list) - register partial_susp_type susp; - snd_list_type snd_list; +void partial_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + partial_susp_type susp = (partial_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type env_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register long phase_reg; + register long ph_incr_reg; + register double env_pHaSe_iNcR_rEg = susp->env_pHaSe_iNcR; + register double env_pHaSe_ReG; + register sample_type env_x1_sample_reg; + falloc_sample_block(out, "partial_i_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(env, env_ptr, env_cnt); + susp->env_x1_sample = susp_fetch_sample(env, env_ptr, env_cnt); + } + + susp_check_term_log_samples(env, env_ptr, env_cnt); + env_x2_sample = susp_current_sample(env, env_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + phase_reg = susp->phase; + ph_incr_reg = susp->ph_incr; + env_pHaSe_ReG = susp->env_pHaSe; + env_x1_sample_reg = susp->env_x1_sample; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (env_pHaSe_ReG >= 1.0) { + env_x1_sample_reg = env_x2_sample; + /* pick up next sample as env_x2_sample: */ + susp->env_ptr++; + susp_took(env_cnt, 1); + env_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(env, env_ptr, env_cnt, env_x2_sample); + } + *out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * + (env_x1_sample_reg * (1 - env_pHaSe_ReG) + env_x2_sample * env_pHaSe_ReG); + phase_reg += ph_incr_reg; + phase_reg &= SINE_TABLE_MASK;; + env_pHaSe_ReG += env_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->phase = (susp->phase + susp->ph_incr * togo) & SINE_TABLE_MASK; + susp->env_pHaSe = env_pHaSe_ReG; + susp->env_x1_sample = env_x1_sample_reg; + out_ptr += togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* partial_i_fetch */ + + +void partial_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + partial_susp_type susp = (partial_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type env_DeLtA; + sample_type env_val; + sample_type env_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register long phase_reg; + register long ph_incr_reg; + falloc_sample_block(out, "partial_r_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->env_pHaSe = 1.0; + } + + susp_check_term_log_samples(env, env_ptr, env_cnt); + env_x2_sample = susp_current_sample(env, env_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* grab next env_x2_sample when phase goes past 1.0; */ + /* we use env_n (computed below) to avoid roundoff errors: */ + if (susp->env_n <= 0) { + susp->env_x1_sample = env_x2_sample; + susp->env_ptr++; + susp_took(env_cnt, 1); + susp->env_pHaSe -= 1.0; + susp_check_term_log_samples(env, env_ptr, env_cnt); + env_x2_sample = susp_current_sample(env, env_ptr); + /* env_n gets number of samples before phase exceeds 1.0: */ + susp->env_n = (long) ((1.0 - susp->env_pHaSe) * + susp->output_per_env); + } + togo = min(togo, susp->env_n); + env_DeLtA = (sample_type) ((env_x2_sample - susp->env_x1_sample) * susp->env_pHaSe_iNcR); + env_val = (sample_type) (susp->env_x1_sample * (1.0 - susp->env_pHaSe) + + env_x2_sample * susp->env_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + phase_reg = susp->phase; + ph_incr_reg = susp->ph_incr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT] * env_val; + phase_reg += ph_incr_reg; + phase_reg &= SINE_TABLE_MASK;; + env_val += env_DeLtA; + } while (--n); /* inner loop */ + + susp->phase = (susp->phase + susp->ph_incr * togo) & SINE_TABLE_MASK; + out_ptr += togo; + susp->env_pHaSe += togo * susp->env_pHaSe_iNcR; + susp->env_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* partial_r_fetch */ + + +void partial_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + partial_susp_type susp = (partial_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -234,25 +484,28 @@ void partial_toss_fetch(susp, snd_list) susp->env_ptr += n; susp_took(env_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void partial_mark(partial_susp_type susp) +void partial_mark(snd_susp_type a_susp) { + partial_susp_type susp = (partial_susp_type) a_susp; sound_xlmark(susp->env); } -void partial_free(partial_susp_type susp) +void partial_free(snd_susp_type a_susp) { + partial_susp_type susp = (partial_susp_type) a_susp; sound_unref(susp->env); ffree_generic(susp, sizeof(partial_susp_node), "partial_free"); } -void partial_print_tree(partial_susp_type susp, int n) +void partial_print_tree(snd_susp_type a_susp, int n) { + partial_susp_type susp = (partial_susp_type) a_susp; indent(n); stdputstr("env:"); sound_print_tree_1(susp->env, n); @@ -271,11 +524,19 @@ sound_type snd_make_partial(rate_type sr, double hz, sound_type env) susp->phase = 0; susp->ph_incr = round((hz * SINE_TABLE_LEN) * (1 << SINE_TABLE_SHIFT) / sr); + /* make sure no sample rate is too high */ + if (env->sr > sr) { + sound_unref(env); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(env, sr); switch (interp_desc) { case INTERP_n: susp->susp.fetch = partial_n_fetch; break; case INTERP_s: susp->susp.fetch = partial_s_fetch; break; + case INTERP_i: susp->susp.fetch = partial_i_fetch; break; + case INTERP_r: susp->susp.fetch = partial_r_fetch; break; default: snd_badsr(); break; } @@ -287,8 +548,8 @@ sound_type snd_make_partial(rate_type sr, double hz, sound_type env) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = partial_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = partial_toss_fetch; } /* initialize susp state */ @@ -300,9 +561,14 @@ sound_type snd_make_partial(rate_type sr, double hz, sound_type env) susp->susp.name = "partial"; susp->logically_stopped = false; susp->susp.log_stop_cnt = logical_stop_cnt_cvt(env); + susp->started = false; susp->susp.current = 0; susp->env = env; susp->env_cnt = 0; + susp->env_pHaSe = 0.0; + susp->env_pHaSe_iNcR = env->sr / sr; + susp->env_n = 0; + susp->output_per_env = sr / env->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/pluck.alg b/lib-src/libnyquist/nyquist/tran/pluck.alg index 6bd342f46..84cb2bc78 100644 --- a/lib-src/libnyquist/nyquist/tran/pluck.alg +++ b/lib-src/libnyquist/nyquist/tran/pluck.alg @@ -124,7 +124,7 @@ void pluck_initialize(sample_type *shiftreg, sample_type *array, (SAMPLE-RATE "sr") (NOT-REGISTER shiftreg) (TERMINATE (AFTER "d")) -(INNER-LOOP " sample_type sum = (sample_type) +(INNER-LOOP "sample_type sum = (sample_type) ((*i1++ * x2) + (*i2++ * x3) + (*i3++ * stretch) - (*i4++ * cons)); /* wrap pointers around shift register if necessary */ @@ -137,8 +137,7 @@ void pluck_initialize(sample_type *shiftreg, sample_type *array, *i4 = (sample_type) (sum * loss); /* deliver sample */ - output = sum; -") + output = sum") (FINALIZATION " free(susp->shiftreg);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/pluck.c b/lib-src/libnyquist/nyquist/tran/pluck.c index 267e98c03..4822a71ee 100644 --- a/lib-src/libnyquist/nyquist/tran/pluck.c +++ b/lib-src/libnyquist/nyquist/tran/pluck.c @@ -9,7 +9,7 @@ #include "cext.h" #include "pluck.h" -void pluck_free(); +void pluck_free(snd_susp_type a_susp); typedef struct pluck_susp_struct { @@ -115,8 +115,9 @@ void pluck_initialize(sample_type *shiftreg, sample_type *array, shiftreg[len + 1] = 0; } -void pluck__fetch(register pluck_susp_type susp, snd_list_type snd_list) +void pluck__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + pluck_susp_type susp = (pluck_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -148,6 +149,7 @@ void pluck__fetch(register pluck_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -178,7 +180,6 @@ void pluck__fetch(register pluck_susp_type susp, snd_list_type snd_list) /* deliver sample */ *out_ptr_reg++ = sum; -; } while (--n); /* inner loop */ susp->i1 = i1_reg; @@ -199,14 +200,15 @@ void pluck__fetch(register pluck_susp_type susp, snd_list_type snd_list) } /* pluck__fetch */ -void pluck_free(pluck_susp_type susp) +void pluck_free(snd_susp_type a_susp) { + pluck_susp_type susp = (pluck_susp_type) a_susp; free(susp->shiftreg); ffree_generic(susp, sizeof(pluck_susp_node), "pluck_free"); } -void pluck_print_tree(pluck_susp_type susp, int n) +void pluck_print_tree(snd_susp_type a_susp, int n) { } @@ -236,7 +238,7 @@ sound_type snd_make_pluck(rate_type sr, double hz, time_type t0, time_type d, do susp->len, susp->cons); susp->susp.fetch = pluck__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = pluck_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/prod.c b/lib-src/libnyquist/nyquist/tran/prod.c index dc2be08b0..1e9424dac 100644 --- a/lib-src/libnyquist/nyquist/tran/prod.c +++ b/lib-src/libnyquist/nyquist/tran/prod.c @@ -9,11 +9,12 @@ #include "cext.h" #include "prod.h" -void prod_free(); +void prod_free(snd_susp_type a_susp); typedef struct prod_susp_struct { snd_susp_node susp; + boolean started; long terminate_cnt; boolean logically_stopped; sound_type s1; @@ -22,11 +23,21 @@ typedef struct prod_susp_struct { sound_type s2; long s2_cnt; sample_block_values_type s2_ptr; + + /* support for interpolation of s2 */ + sample_type s2_x1_sample; + double s2_pHaSe; + double s2_pHaSe_iNcR; + + /* support for ramp between samples of s2 */ + double output_per_s2; + long s2_n; } prod_susp_node, *prod_susp_type; -void prod_nn_fetch(register prod_susp_type susp, snd_list_type snd_list) +void prod_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + prod_susp_type susp = (prod_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -58,6 +69,7 @@ void prod_nn_fetch(register prod_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -69,6 +81,7 @@ void prod_nn_fetch(register prod_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -91,7 +104,7 @@ void prod_nn_fetch(register prod_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *s1_ptr_reg++ * *s2_ptr_reg++; + *out_ptr_reg++ = *s1_ptr_reg++ * *s2_ptr_reg++; } while (--n); /* inner loop */ /* using s2_ptr_reg is a bad idea on RS/6000: */ @@ -120,11 +133,249 @@ void prod_nn_fetch(register prod_susp_type susp, snd_list_type snd_list) } /* prod_nn_fetch */ -void prod_toss_fetch(susp, snd_list) - register prod_susp_type susp; - snd_list_type snd_list; +void prod_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { - long final_count = susp->susp.toss_cnt; + prod_susp_type susp = (prod_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double s2_pHaSe_iNcR_rEg = susp->s2_pHaSe_iNcR; + register double s2_pHaSe_ReG; + register sample_type s2_x1_sample_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "prod_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + susp->s2_x1_sample = susp_fetch_sample(s2, s2_ptr, s2_cnt); + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s2_pHaSe_ReG = susp->s2_pHaSe; + s2_x1_sample_reg = susp->s2_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + if (s2_pHaSe_ReG >= 1.0) { + s2_x1_sample_reg = s2_x2_sample; + /* pick up next sample as s2_x2_sample: */ + susp->s2_ptr++; + susp_took(s2_cnt, 1); + s2_pHaSe_ReG -= 1.0; + susp_check_term_log_samples_break(s2, s2_ptr, s2_cnt, s2_x2_sample); + } + *out_ptr_reg++ = *s1_ptr_reg++ * + (s2_x1_sample_reg * (1 - s2_pHaSe_ReG) + s2_x2_sample * s2_pHaSe_ReG); + s2_pHaSe_ReG += s2_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->s2_pHaSe = s2_pHaSe_ReG; + susp->s2_x1_sample = s2_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* prod_ni_fetch */ + + +void prod_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + prod_susp_type susp = (prod_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type s2_DeLtA; + sample_type s2_val; + sample_type s2_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "prod_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->s2_pHaSe = 1.0; + } + + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next s2_x2_sample when phase goes past 1.0; */ + /* we use s2_n (computed below) to avoid roundoff errors: */ + if (susp->s2_n <= 0) { + susp->s2_x1_sample = s2_x2_sample; + susp->s2_ptr++; + susp_took(s2_cnt, 1); + susp->s2_pHaSe -= 1.0; + susp_check_term_log_samples(s2, s2_ptr, s2_cnt); + s2_x2_sample = susp_current_sample(s2, s2_ptr); + /* s2_n gets number of samples before phase exceeds 1.0: */ + susp->s2_n = (long) ((1.0 - susp->s2_pHaSe) * + susp->output_per_s2); + } + togo = min(togo, susp->s2_n); + s2_DeLtA = (sample_type) ((s2_x2_sample - susp->s2_x1_sample) * susp->s2_pHaSe_iNcR); + s2_val = (sample_type) (susp->s2_x1_sample * (1.0 - susp->s2_pHaSe) + + s2_x2_sample * susp->s2_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + *out_ptr_reg++ = *s1_ptr_reg++ * s2_val; + s2_val += s2_DeLtA; + } while (--n); /* inner loop */ + + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->s2_pHaSe += togo * susp->s2_pHaSe_iNcR; + susp->s2_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* prod_nr_fetch */ + + +void prod_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + prod_susp_type susp = (prod_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -147,27 +398,30 @@ void prod_toss_fetch(susp, snd_list) susp->s2_ptr += n; susp_took(s2_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void prod_mark(prod_susp_type susp) +void prod_mark(snd_susp_type a_susp) { + prod_susp_type susp = (prod_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->s2); } -void prod_free(prod_susp_type susp) +void prod_free(snd_susp_type a_susp) { + prod_susp_type susp = (prod_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->s2); ffree_generic(susp, sizeof(prod_susp_node), "prod_free"); } -void prod_print_tree(prod_susp_type susp, int n) +void prod_print_tree(snd_susp_type a_susp, int n) { + prod_susp_type susp = (prod_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -201,7 +455,17 @@ sound_type snd_make_prod(sound_type s1, sound_type s2) else if (s2->sr < sr) { s2->scale = scale_factor; scale_factor = 1.0F; } falloc_generic(susp, prod_susp_node, "snd_make_prod"); - susp->susp.fetch = prod_nn_fetch; + + /* select a susp fn based on sample rates */ + interp_desc = (interp_desc << 2) + interp_style(s1, sr); + interp_desc = (interp_desc << 2) + interp_style(s2, sr); + switch (interp_desc) { + case INTERP_nn: susp->susp.fetch = prod_nn_fetch; break; + case INTERP_ni: susp->susp.fetch = prod_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = prod_nr_fetch; break; + default: snd_badsr(); break; + } + susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -211,8 +475,8 @@ sound_type snd_make_prod(sound_type s1, sound_type s2) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = prod_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = prod_toss_fetch; } /* initialize susp state */ @@ -227,11 +491,16 @@ sound_type snd_make_prod(sound_type s1, sound_type s2) lsc = logical_stop_cnt_cvt(s2); if (susp->susp.log_stop_cnt > lsc) susp->susp.log_stop_cnt = lsc; + susp->started = false; susp->susp.current = 0; susp->s1 = s1; susp->s1_cnt = 0; susp->s2 = s2; susp->s2_cnt = 0; + susp->s2_pHaSe = 0.0; + susp->s2_pHaSe_iNcR = s2->sr / sr; + susp->s2_n = 0; + susp->output_per_s2 = sr / s2->sr; return sound_create((snd_susp_type)susp, t0, sr, scale_factor); } diff --git a/lib-src/libnyquist/nyquist/tran/pwl.alg b/lib-src/libnyquist/nyquist/tran/pwl.alg index e9f66db19..3f244d833 100644 --- a/lib-src/libnyquist/nyquist/tran/pwl.alg +++ b/lib-src/libnyquist/nyquist/tran/pwl.alg @@ -74,7 +74,7 @@ out: togo = 0; /* indicate termination */ togo = min(nn, togo); } ") - (INNER-LOOP "output = (sample_type) lvl; lvl += incr;") + (INNER-LOOP "output = (sample_type) lvl; lvl += incr") (MAINTAIN ("lvl" "susp->lvl += susp->incr * togo")) (CONSTANT "incr") (TERMINATE COMPUTED) diff --git a/lib-src/libnyquist/nyquist/tran/pwl.c b/lib-src/libnyquist/nyquist/tran/pwl.c index 09681cd4f..7546e01f8 100644 --- a/lib-src/libnyquist/nyquist/tran/pwl.c +++ b/lib-src/libnyquist/nyquist/tran/pwl.c @@ -9,7 +9,7 @@ #include "cext.h" #include "pwl.h" -void pwl_free(); +void pwl_free(snd_susp_type a_susp); typedef struct pwl_susp_struct { @@ -74,8 +74,9 @@ boolean compute_incr(pwl_susp_type susp, long *n, long cur) } -void pwl__fetch(register pwl_susp_type susp, snd_list_type snd_list) +void pwl__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + pwl_susp_type susp = (pwl_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -113,7 +114,7 @@ out: togo = 0; /* indicate termination */ lvl_reg = susp->lvl; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) lvl_reg; lvl_reg += incr_reg;; + *out_ptr_reg++ = (sample_type) lvl_reg; lvl_reg += incr_reg; } while (--n); /* inner loop */ susp->lvl += susp->incr * togo; @@ -131,19 +132,21 @@ out: togo = 0; /* indicate termination */ } /* pwl__fetch */ -void pwl_mark(pwl_susp_type susp) +void pwl_mark(snd_susp_type a_susp) { + pwl_susp_type susp = (pwl_susp_type) a_susp; if (susp->bpt_ptr) mark(susp->bpt_ptr); } -void pwl_free(pwl_susp_type susp) +void pwl_free(snd_susp_type a_susp) { + pwl_susp_type susp = (pwl_susp_type) a_susp; ffree_generic(susp, sizeof(pwl_susp_node), "pwl_free"); } -void pwl_print_tree(pwl_susp_type susp, int n) +void pwl_print_tree(snd_susp_type a_susp, int n) { } diff --git a/lib-src/libnyquist/nyquist/tran/quantize.alg b/lib-src/libnyquist/nyquist/tran/quantize.alg index fc268bd29..51047b2a2 100644 --- a/lib-src/libnyquist/nyquist/tran/quantize.alg +++ b/lib-src/libnyquist/nyquist/tran/quantize.alg @@ -3,8 +3,15 @@ (ARGUMENTS ("sound_type" "s1") ("long" "steps")) (INTERNAL-SCALING s1) (START (MIN s1)) - (STATE ("double" "factor" "s1->scale * steps; scale_factor = (sample_type) (1.0 / steps);")) - (INNER-LOOP "register long xx = (long) (s1 * factor); output = (float) xx;") + (STATE ("double" "factor" "s1->scale * steps; + scale_factor = (sample_type) (1.0 / steps);")) + (INNER-LOOP "{ +\t\tfloat x = s1 * factor; +\t\tlong xx; +\t\tx = (x > 0.0F ? x + 0.5 : x - 0.5); +\t\txx = (long) x; +\t\toutput = (float) xx; +\t }") (TERMINATE (MIN s1)) (CONSTANT "factor") (LOGICAL-STOP (MIN s1)) diff --git a/lib-src/libnyquist/nyquist/tran/quantize.c b/lib-src/libnyquist/nyquist/tran/quantize.c index cf919a6d3..c7ac6d123 100644 --- a/lib-src/libnyquist/nyquist/tran/quantize.c +++ b/lib-src/libnyquist/nyquist/tran/quantize.c @@ -9,7 +9,7 @@ #include "cext.h" #include "quantize.h" -void quantize_free(); +void quantize_free(snd_susp_type a_susp); typedef struct quantize_susp_struct { @@ -24,8 +24,9 @@ typedef struct quantize_susp_struct { } quantize_susp_node, *quantize_susp_type; -void quantize_n_fetch(register quantize_susp_type susp, snd_list_type snd_list) +void quantize_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + quantize_susp_type susp = (quantize_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void quantize_n_fetch(register quantize_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void quantize_n_fetch(register quantize_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,13 @@ void quantize_n_fetch(register quantize_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -register long xx = (long) (*s1_ptr_reg++ * factor_reg); *out_ptr_reg++ = (float) xx;; + { + float x = *s1_ptr_reg++ * factor_reg; + long xx; + x = (x > 0.0F ? x + 0.5 : x - 0.5); + xx = (long) x; + *out_ptr_reg++ = (float) xx; + }; } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000: */ @@ -112,11 +121,9 @@ register long xx = (long) (*s1_ptr_reg++ * factor_reg); *out_ptr_reg++ = (float) } /* quantize_n_fetch */ -void quantize_toss_fetch(susp, snd_list) - register quantize_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void quantize_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + quantize_susp_type susp = (quantize_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -131,25 +138,28 @@ void quantize_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void quantize_mark(quantize_susp_type susp) +void quantize_mark(snd_susp_type a_susp) { + quantize_susp_type susp = (quantize_susp_type) a_susp; sound_xlmark(susp->s1); } -void quantize_free(quantize_susp_type susp) +void quantize_free(snd_susp_type a_susp) { + quantize_susp_type susp = (quantize_susp_type) a_susp; sound_unref(susp->s1); ffree_generic(susp, sizeof(quantize_susp_node), "quantize_free"); } -void quantize_print_tree(quantize_susp_type susp, int n) +void quantize_print_tree(snd_susp_type a_susp, int n) { + quantize_susp_type susp = (quantize_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -161,11 +171,11 @@ sound_type snd_make_quantize(sound_type s1, long steps) register quantize_susp_type susp; rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, quantize_susp_node, "snd_make_quantize"); - susp->factor = s1->scale * steps; scale_factor = (sample_type) (1.0 / steps);; + susp->factor = s1->scale * steps; + scale_factor = (sample_type) (1.0 / steps);; susp->susp.fetch = quantize_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ @@ -175,8 +185,8 @@ sound_type snd_make_quantize(sound_type s1, long steps) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = quantize_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = quantize_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/recip.c b/lib-src/libnyquist/nyquist/tran/recip.c index 36dd83214..0a826b4b5 100644 --- a/lib-src/libnyquist/nyquist/tran/recip.c +++ b/lib-src/libnyquist/nyquist/tran/recip.c @@ -9,7 +9,7 @@ #include "cext.h" #include "recip.h" -void recip_free(); +void recip_free(snd_susp_type a_susp); typedef struct recip_susp_struct { @@ -24,8 +24,9 @@ typedef struct recip_susp_struct { } recip_susp_node, *recip_susp_type; -void recip_n_fetch(register recip_susp_type susp, snd_list_type snd_list) +void recip_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + recip_susp_type susp = (recip_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void recip_n_fetch(register recip_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void recip_n_fetch(register recip_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,7 @@ void recip_n_fetch(register recip_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) (scale_reg / *s1_ptr_reg++); + *out_ptr_reg++ = (sample_type) (scale_reg / *s1_ptr_reg++); } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000: */ @@ -112,11 +115,9 @@ void recip_n_fetch(register recip_susp_type susp, snd_list_type snd_list) } /* recip_n_fetch */ -void recip_toss_fetch(susp, snd_list) - register recip_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void recip_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + recip_susp_type susp = (recip_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -131,25 +132,28 @@ void recip_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void recip_mark(recip_susp_type susp) +void recip_mark(snd_susp_type a_susp) { + recip_susp_type susp = (recip_susp_type) a_susp; sound_xlmark(susp->s1); } -void recip_free(recip_susp_type susp) +void recip_free(snd_susp_type a_susp) { + recip_susp_type susp = (recip_susp_type) a_susp; sound_unref(susp->s1); ffree_generic(susp, sizeof(recip_susp_node), "recip_free"); } -void recip_print_tree(recip_susp_type susp, int n) +void recip_print_tree(snd_susp_type a_susp, int n) { + recip_susp_type susp = (recip_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -161,11 +165,10 @@ sound_type snd_make_recip(sound_type s1) register recip_susp_type susp; rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, recip_susp_node, "snd_make_recip"); - susp->scale = 1.0 / s1->scale; + susp->scale = (1.0 / s1->scale); susp->susp.fetch = recip_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ @@ -175,8 +178,8 @@ sound_type snd_make_recip(sound_type s1) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = recip_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = recip_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/reson.alg b/lib-src/libnyquist/nyquist/tran/reson.alg index bc73cc326..5a4f9188d 100644 --- a/lib-src/libnyquist/nyquist/tran/reson.alg +++ b/lib-src/libnyquist/nyquist/tran/reson.alg @@ -17,7 +17,7 @@ ("double" "y2" "0.0")) (CONSTANT "c1" "c2" "c3") (INNER-LOOP "{ double y0 = c1 * s + c2 * y1 - c3 * y2; - output = (sample_type) y0; - y2 = y1; y1 = y0; }") + output = (sample_type) y0; + y2 = y1; y1 = y0; }") ) diff --git a/lib-src/libnyquist/nyquist/tran/reson.c b/lib-src/libnyquist/nyquist/tran/reson.c index c20aa3bbc..986cd7f50 100644 --- a/lib-src/libnyquist/nyquist/tran/reson.c +++ b/lib-src/libnyquist/nyquist/tran/reson.c @@ -9,7 +9,7 @@ #include "cext.h" #include "reson.h" -void reson_free(); +void reson_free(snd_susp_type a_susp); typedef struct reson_susp_struct { @@ -31,8 +31,9 @@ typedef struct reson_susp_struct { } reson_susp_node, *reson_susp_type; -void reson_n_fetch(register reson_susp_type susp, snd_list_type snd_list) +void reson_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + reson_susp_type susp = (reson_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -64,6 +65,7 @@ void reson_n_fetch(register reson_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -75,6 +77,7 @@ void reson_n_fetch(register reson_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -101,9 +104,9 @@ void reson_n_fetch(register reson_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * *s_ptr_reg++ + c2_reg * y1_reg - c3_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s_ptr_reg++ + c2_reg * y1_reg - c3_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -131,8 +134,9 @@ void reson_n_fetch(register reson_susp_type susp, snd_list_type snd_list) } /* reson_n_fetch */ -void reson_s_fetch(register reson_susp_type susp, snd_list_type snd_list) +void reson_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + reson_susp_type susp = (reson_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -165,6 +169,7 @@ void reson_s_fetch(register reson_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -176,6 +181,7 @@ void reson_s_fetch(register reson_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -202,9 +208,9 @@ void reson_s_fetch(register reson_susp_type susp, snd_list_type snd_list) s_ptr_reg = susp->s_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * (s_scale_reg * *s_ptr_reg++) + c2_reg * y1_reg - c3_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * (s_scale_reg * *s_ptr_reg++) + c2_reg * y1_reg - c3_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -232,11 +238,9 @@ void reson_s_fetch(register reson_susp_type susp, snd_list_type snd_list) } /* reson_s_fetch */ -void reson_toss_fetch(susp, snd_list) - register reson_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void reson_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + reson_susp_type susp = (reson_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -251,25 +255,28 @@ void reson_toss_fetch(susp, snd_list) susp->s_ptr += n; susp_took(s_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void reson_mark(reson_susp_type susp) +void reson_mark(snd_susp_type a_susp) { + reson_susp_type susp = (reson_susp_type) a_susp; sound_xlmark(susp->s); } -void reson_free(reson_susp_type susp) +void reson_free(snd_susp_type a_susp) { + reson_susp_type susp = (reson_susp_type) a_susp; sound_unref(susp->s); ffree_generic(susp, sizeof(reson_susp_node), "reson_free"); } -void reson_print_tree(reson_susp_type susp, int n) +void reson_print_tree(snd_susp_type a_susp, int n) { + reson_susp_type susp = (reson_susp_type) a_susp; indent(n); stdputstr("s:"); sound_print_tree_1(susp->s, n); @@ -312,8 +319,8 @@ sound_type snd_make_reson(sound_type s, double hz, double bw, int normalization) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = reson_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = reson_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/resoncv.alg b/lib-src/libnyquist/nyquist/tran/resoncv.alg index 8ad5c6407..fa41b6c15 100644 --- a/lib-src/libnyquist/nyquist/tran/resoncv.alg +++ b/lib-src/libnyquist/nyquist/tran/resoncv.alg @@ -2,7 +2,6 @@ (NAME "resoncv") (ARGUMENTS ("sound_type" "s1") ("double" "hz") ("sound_type" "bw") ("int" "normalization")) -(INLINE-INTERPOLATION T) (INTERNAL-SCALING s1) (ALWAYS-SCALE bw) (START (MAX s1 bw)) @@ -30,6 +29,6 @@ (CONSTANT "c1" "c2" "c3co" "coshz" "normalization" "scale1") (FORCE-INTO-REGISTER normalization coshz scale1) (INNER-LOOP "{ double y0 = c1 * s1 + c2 * y1 - c3co * y2; - output = (sample_type) y0; - y2 = y1; y1 = y0; }") + output = (sample_type) y0; + y2 = y1; y1 = y0; }") ) diff --git a/lib-src/libnyquist/nyquist/tran/resoncv.c b/lib-src/libnyquist/nyquist/tran/resoncv.c index 77a8eb4c5..8ecc5c1d0 100644 --- a/lib-src/libnyquist/nyquist/tran/resoncv.c +++ b/lib-src/libnyquist/nyquist/tran/resoncv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "resoncv.h" -void resoncv_free(); +void resoncv_free(snd_susp_type a_susp); typedef struct resoncv_susp_struct { @@ -44,8 +44,9 @@ typedef struct resoncv_susp_struct { } resoncv_susp_node, *resoncv_susp_type; -void resoncv_ns_fetch(register resoncv_susp_type susp, snd_list_type snd_list) +void resoncv_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -86,6 +87,7 @@ void resoncv_ns_fetch(register resoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -97,6 +99,7 @@ void resoncv_ns_fetch(register resoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -138,9 +141,9 @@ void resoncv_ns_fetch(register resoncv_susp_type susp, snd_list_type snd_list) c1_reg = (normalization_reg == 0 ? 1.0 : (normalization_reg == 1 ? omc3 * sqrt(1.0 - c2_reg * c2_reg / c3t4) : sqrt(c3p1 * c3p1 - c2_reg * c2_reg) * omc3 / c3p1)) * scale1_reg; -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -171,8 +174,9 @@ void resoncv_ns_fetch(register resoncv_susp_type susp, snd_list_type snd_list) } /* resoncv_ns_fetch */ -void resoncv_ni_fetch(register resoncv_susp_type susp, snd_list_type snd_list) +void resoncv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -228,6 +232,7 @@ void resoncv_ni_fetch(register resoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -239,6 +244,7 @@ void resoncv_ni_fetch(register resoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -281,18 +287,18 @@ void resoncv_ni_fetch(register resoncv_susp_type susp, snd_list_type snd_list) bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); + c3co_reg = exp(bw_x1_sample_reg); c3p1 = c3co_reg + 1.0; c3t4 = c3co_reg * 4.0; omc3 = 1.0 - c3co_reg; - c2_reg = susp->c2 = c3t4 * coshz_reg / c3p1; - c1_reg = susp->c1 = (normalization_reg == 0 ? 1.0 : + c2_reg = c3t4 * coshz_reg / c3p1; + c1_reg = (normalization_reg == 0 ? 1.0 : (normalization_reg == 1 ? omc3 * sqrt(1.0 - c2_reg * c2_reg / c3t4) : sqrt(c3p1 * c3p1 - c2_reg * c2_reg) * omc3 / c3p1)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -324,8 +330,9 @@ void resoncv_ni_fetch(register resoncv_susp_type susp, snd_list_type snd_list) } /* resoncv_ni_fetch */ -void resoncv_nr_fetch(register resoncv_susp_type susp, snd_list_type snd_list) +void resoncv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -392,6 +399,7 @@ void resoncv_nr_fetch(register resoncv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -403,6 +411,7 @@ void resoncv_nr_fetch(register resoncv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -432,9 +441,9 @@ void resoncv_nr_fetch(register resoncv_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -464,11 +473,9 @@ void resoncv_nr_fetch(register resoncv_susp_type susp, snd_list_type snd_list) } /* resoncv_nr_fetch */ -void resoncv_toss_fetch(susp, snd_list) - register resoncv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void resoncv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -491,27 +498,30 @@ void resoncv_toss_fetch(susp, snd_list) susp->bw_ptr += n; susp_took(bw_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void resoncv_mark(resoncv_susp_type susp) +void resoncv_mark(snd_susp_type a_susp) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->bw); } -void resoncv_free(resoncv_susp_type susp) +void resoncv_free(snd_susp_type a_susp) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->bw); ffree_generic(susp, sizeof(resoncv_susp_node), "resoncv_free"); } -void resoncv_print_tree(resoncv_susp_type susp, int n) +void resoncv_print_tree(snd_susp_type a_susp, int n) { + resoncv_susp_type susp = (resoncv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -541,6 +551,12 @@ sound_type snd_make_resoncv(sound_type s1, double hz, sound_type bw, int normali susp->y2 = 0.0; bw->scale = (sample_type) (bw->scale * (-PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (bw->sr > sr) { + sound_unref(bw); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(bw, sr); @@ -565,8 +581,8 @@ sound_type snd_make_resoncv(sound_type s1, double hz, sound_type bw, int normali /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = resoncv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = resoncv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/resonvc.alg b/lib-src/libnyquist/nyquist/tran/resonvc.alg index 74945b877..1abaea7ea 100644 --- a/lib-src/libnyquist/nyquist/tran/resonvc.alg +++ b/lib-src/libnyquist/nyquist/tran/resonvc.alg @@ -2,7 +2,6 @@ (NAME "resonvc") (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz") ("double" "bw") ("int" "normalization")) -(INLINE-INTERPOLATION T) (INTERNAL-SCALING s1) (ALWAYS-SCALE hz) (START (MAX s1 hz)) @@ -28,6 +27,6 @@ (CONSTANT "c1" "c2" "c3co" "c3p1" "c3t4" "omc3" "normalization" "scale1") (FORCE-INTO-REGISTER c3t4 c3p1 normalization omc3 scale1) (INNER-LOOP "{ double y0 = c1 * s1 + c2 * y1 - c3co * y2; - output = (sample_type) y0; - y2 = y1; y1 = y0; }") + output = (sample_type) y0; + y2 = y1; y1 = y0; }") ) diff --git a/lib-src/libnyquist/nyquist/tran/resonvc.c b/lib-src/libnyquist/nyquist/tran/resonvc.c index a84e5a52f..97e7741ec 100644 --- a/lib-src/libnyquist/nyquist/tran/resonvc.c +++ b/lib-src/libnyquist/nyquist/tran/resonvc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "resonvc.h" -void resonvc_free(); +void resonvc_free(snd_susp_type a_susp); typedef struct resonvc_susp_struct { @@ -46,8 +46,9 @@ typedef struct resonvc_susp_struct { } resonvc_susp_node, *resonvc_susp_type; -void resonvc_ns_fetch(register resonvc_susp_type susp, snd_list_type snd_list) +void resonvc_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -90,6 +91,7 @@ void resonvc_ns_fetch(register resonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -101,6 +103,7 @@ void resonvc_ns_fetch(register resonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -137,9 +140,9 @@ void resonvc_ns_fetch(register resonvc_susp_type susp, snd_list_type snd_list) c1_reg = (normalization_reg == 0 ? scale1_reg : (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -170,8 +173,9 @@ void resonvc_ns_fetch(register resonvc_susp_type susp, snd_list_type snd_list) } /* resonvc_ns_fetch */ -void resonvc_ni_fetch(register resonvc_susp_type susp, snd_list_type snd_list) +void resonvc_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -222,6 +226,7 @@ void resonvc_ni_fetch(register resonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -233,6 +238,7 @@ void resonvc_ni_fetch(register resonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -274,14 +280,14 @@ void resonvc_ni_fetch(register resonvc_susp_type susp, snd_list_type snd_list) hz_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz, hz_ptr, hz_cnt, hz_x1_sample_reg); hz_x1_sample_reg = susp_current_sample(hz, hz_ptr); - c2_reg = susp->c2 = c3t4_reg * cos(hz_x1_sample_reg) / c3p1_reg; - c1_reg = susp->c1 = (normalization_reg == 0 ? scale1_reg : + c2_reg = c3t4_reg * cos(hz_x1_sample_reg) / c3p1_reg; + c1_reg = (normalization_reg == 0 ? scale1_reg : (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; hz_pHaSe_ReG += hz_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -313,8 +319,9 @@ void resonvc_ni_fetch(register resonvc_susp_type susp, snd_list_type snd_list) } /* resonvc_ni_fetch */ -void resonvc_nr_fetch(register resonvc_susp_type susp, snd_list_type snd_list) +void resonvc_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz_val; int togo; @@ -376,6 +383,7 @@ void resonvc_nr_fetch(register resonvc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -387,6 +395,7 @@ void resonvc_nr_fetch(register resonvc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -418,9 +427,9 @@ void resonvc_nr_fetch(register resonvc_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->y1 = y1_reg; @@ -450,11 +459,9 @@ void resonvc_nr_fetch(register resonvc_susp_type susp, snd_list_type snd_list) } /* resonvc_nr_fetch */ -void resonvc_toss_fetch(susp, snd_list) - register resonvc_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void resonvc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -477,27 +484,30 @@ void resonvc_toss_fetch(susp, snd_list) susp->hz_ptr += n; susp_took(hz_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void resonvc_mark(resonvc_susp_type susp) +void resonvc_mark(snd_susp_type a_susp) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz); } -void resonvc_free(resonvc_susp_type susp) +void resonvc_free(snd_susp_type a_susp) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz); ffree_generic(susp, sizeof(resonvc_susp_node), "resonvc_free"); } -void resonvc_print_tree(resonvc_susp_type susp, int n) +void resonvc_print_tree(snd_susp_type a_susp, int n) { + resonvc_susp_type susp = (resonvc_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -529,6 +539,12 @@ sound_type snd_make_resonvc(sound_type s1, sound_type hz, double bw, int normali susp->y2 = 0.0; hz->scale = (sample_type) (hz->scale * (PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (hz->sr > sr) { + sound_unref(hz); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz, sr); @@ -553,8 +569,8 @@ sound_type snd_make_resonvc(sound_type s1, sound_type hz, double bw, int normali /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = resonvc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = resonvc_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/resonvv.alg b/lib-src/libnyquist/nyquist/tran/resonvv.alg index 4f6f42905..6af598dbd 100644 --- a/lib-src/libnyquist/nyquist/tran/resonvv.alg +++ b/lib-src/libnyquist/nyquist/tran/resonvv.alg @@ -2,7 +2,7 @@ (NAME "resonvv") (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz1") ("sound_type" "bw") ("int" "normalization")) -(INLINE-INTERPOLATION T) +(LINEAR s1) (ALWAYS-SCALE hz1 bw) (START (MAX s1 hz1 bw)) (TERMINATE (MIN s1 hz1 bw)) @@ -42,6 +42,6 @@ "normalization" "scale1") (FORCE-INTO-REGISTER recompute) ;c3t4 c3p1 normalization omc3 scale1 (INNER-LOOP "{ double y0 = c1 * s1 + c2 * y1 - c3co * y2; - output = (sample_type) y0; - y2 = y1; y1 = y0; }") + output = (sample_type) y0; + y2 = y1; y1 = y0; }") ) diff --git a/lib-src/libnyquist/nyquist/tran/resonvv.c b/lib-src/libnyquist/nyquist/tran/resonvv.c index 3b2aca944..45934152c 100644 --- a/lib-src/libnyquist/nyquist/tran/resonvv.c +++ b/lib-src/libnyquist/nyquist/tran/resonvv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "resonvv.h" -void resonvv_free(); +void resonvv_free(snd_susp_type a_susp); typedef struct resonvv_susp_struct { @@ -60,8 +60,9 @@ typedef struct resonvv_susp_struct { } resonvv_susp_node, *resonvv_susp_type; -void resonvv_nss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nss_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -112,6 +113,7 @@ void resonvv_nss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -123,6 +125,7 @@ void resonvv_nss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -172,9 +175,9 @@ void resonvv_nss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->recompute = recompute_reg; @@ -209,8 +212,9 @@ void resonvv_nss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nss_fetch */ -void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nsi_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -270,6 +274,7 @@ void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -281,6 +286,7 @@ void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -325,11 +331,11 @@ void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); recompute_reg = true; @@ -340,9 +346,9 @@ void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -378,8 +384,9 @@ void resonvv_nsi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nsi_fetch */ -void resonvv_nsr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nsr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -450,6 +457,7 @@ void resonvv_nsr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -461,6 +469,7 @@ void resonvv_nsr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -504,9 +513,9 @@ void resonvv_nsr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->recompute = recompute_reg; @@ -540,8 +549,9 @@ void resonvv_nsr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nsr_fetch */ -void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nis_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -598,6 +608,7 @@ void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -609,6 +620,7 @@ void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -653,8 +665,8 @@ void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); c3p1_reg = c3co_reg + 1.0; @@ -668,9 +680,9 @@ void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -706,8 +718,9 @@ void resonvv_nis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nis_fetch */ -void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nii_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -768,6 +781,7 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -779,6 +793,7 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -824,8 +839,8 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } if (bw_pHaSe_ReG >= 1.0) { /* fixup-depends bw */ @@ -835,11 +850,11 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; @@ -848,9 +863,9 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -886,8 +901,9 @@ void resonvv_nii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nii_fetch */ -void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nir_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type bw_val; int togo; @@ -959,6 +975,7 @@ void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -970,6 +987,7 @@ void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1013,8 +1031,8 @@ void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) hz1_pHaSe_ReG -= 1.0; susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; + coshz_reg = cos(hz1_x1_sample_reg); + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; @@ -1023,9 +1041,9 @@ void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -1060,8 +1078,9 @@ void resonvv_nir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nir_fetch */ -void resonvv_nrs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nrs_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; int togo; @@ -1129,6 +1148,7 @@ void resonvv_nrs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1140,6 +1160,7 @@ void resonvv_nrs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1186,9 +1207,9 @@ void resonvv_nrs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->recompute = recompute_reg; @@ -1222,8 +1243,9 @@ void resonvv_nrs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nrs_fetch */ -void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nri_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; int togo; @@ -1295,6 +1317,7 @@ void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1306,6 +1329,7 @@ void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1349,11 +1373,11 @@ void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) bw_pHaSe_ReG -= 1.0; susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; + c3co_reg = exp(bw_x1_sample_reg); + c3p1_reg = c3co_reg + 1.0; + c3t4_reg = c3co_reg * 4.0; + omc3_reg = 1.0 - c3co_reg; + recompute_reg = true; } if (recompute_reg) { recompute_reg = false; @@ -1362,9 +1386,9 @@ void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; } -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -1399,8 +1423,9 @@ void resonvv_nri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nri_fetch */ -void resonvv_nrr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) +void resonvv_nrr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz1_val; sample_type bw_val; @@ -1484,6 +1509,7 @@ void resonvv_nrr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -1495,6 +1521,7 @@ void resonvv_nrr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -1522,9 +1549,9 @@ void resonvv_nrr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; + { double y0 = c1_reg * *s1_ptr_reg++ + c2_reg * y1_reg - c3co_reg * y2_reg; + *out_ptr_reg++ = (sample_type) y0; + y2_reg = y1_reg; y1_reg = y0; }; } while (--n); /* inner loop */ susp->recompute = recompute_reg; @@ -1557,1517 +1584,9 @@ void resonvv_nrr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) } /* resonvv_nrr_fetch */ -void resonvv_sss_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register sample_type bw_scale_reg = susp->bw->scale; - register sample_block_values_type bw_ptr_reg; - register sample_type hz1_scale_reg = susp->hz1->scale; - register sample_block_values_type hz1_ptr_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_sss_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past the hz1 input sample block: */ - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - togo = min(togo, susp->hz1_cnt); - - /* don't run past the bw input sample block: */ - susp_check_term_samples(bw, bw_ptr, bw_cnt); - togo = min(togo, susp->bw_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_ptr_reg = susp->bw_ptr; - hz1_ptr_reg = susp->hz1_ptr; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); - c3p1_reg = c3co_reg + 1.0; - c3t4_reg = c3co_reg * 4.0; - omc3_reg = 1.0 - c3co_reg; - recompute_reg = true; - coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); - recompute_reg = true; - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - } while (--n); /* inner loop */ - - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - /* using bw_ptr_reg is a bad idea on RS/6000: */ - susp->bw_ptr += togo; - /* using hz1_ptr_reg is a bad idea on RS/6000: */ - susp->hz1_ptr += togo; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp_took(hz1_cnt, togo); - susp_took(bw_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_sss_fetch */ - - -void resonvv_ssi_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register double bw_pHaSe_iNcR_rEg = susp->bw_pHaSe_iNcR; - register double bw_pHaSe_ReG; - register sample_type bw_x1_sample_reg; - register sample_type hz1_scale_reg = susp->hz1->scale; - register sample_block_values_type hz1_ptr_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_ssi_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past the hz1 input sample block: */ - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - togo = min(togo, susp->hz1_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_pHaSe_ReG = susp->bw_pHaSe; - bw_x1_sample_reg = susp->bw_x1_sample; - hz1_ptr_reg = susp->hz1_ptr; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - if (bw_pHaSe_ReG >= 1.0) { -/* fixup-depends bw */ - /* pick up next sample as bw_x1_sample: */ - susp->bw_ptr++; - susp_took(bw_cnt, 1); - bw_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); - bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; - } - coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); - recompute_reg = true; - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; - } while (--n); /* inner loop */ - - togo -= n; - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - susp->bw_pHaSe = bw_pHaSe_ReG; - susp->bw_x1_sample = bw_x1_sample_reg; - /* using hz1_ptr_reg is a bad idea on RS/6000: */ - susp->hz1_ptr += togo; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp_took(hz1_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_ssi_fetch */ - - -void resonvv_ssr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - sample_type bw_val; - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register sample_type hz1_scale_reg = susp->hz1->scale; - register sample_block_values_type hz1_ptr_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_ssr_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp->bw_pHaSe = 1.0; - } - - susp_check_term_samples(bw, bw_ptr, bw_cnt); - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past the hz1 input sample block: */ - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - togo = min(togo, susp->hz1_cnt); - - /* grab next bw_x1_sample when phase goes past 1.0; */ - /* use bw_n (computed below) to avoid roundoff errors: */ - if (susp->bw_n <= 0) { - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->bw_pHaSe -= 1.0; - /* bw_n gets number of samples before phase exceeds 1.0: */ - susp->bw_n = (long) ((1.0 - susp->bw_pHaSe) * - susp->output_per_bw); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - togo = min(togo, susp->bw_n); - bw_val = susp->bw_x1_sample; - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - hz1_ptr_reg = susp->hz1_ptr; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - coshz_reg = cos((hz1_scale_reg * *hz1_ptr_reg++)); - recompute_reg = true; - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - } while (--n); /* inner loop */ - - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - /* using hz1_ptr_reg is a bad idea on RS/6000: */ - susp->hz1_ptr += togo; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp_took(hz1_cnt, togo); - susp->bw_pHaSe += togo * susp->bw_pHaSe_iNcR; - susp->bw_n -= togo; - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_ssr_fetch */ - - -void resonvv_sis_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register sample_type bw_scale_reg = susp->bw->scale; - register sample_block_values_type bw_ptr_reg; - register double hz1_pHaSe_iNcR_rEg = susp->hz1_pHaSe_iNcR; - register double hz1_pHaSe_ReG; - register sample_type hz1_x1_sample_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_sis_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - } - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past the bw input sample block: */ - susp_check_term_samples(bw, bw_ptr, bw_cnt); - togo = min(togo, susp->bw_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_ptr_reg = susp->bw_ptr; - hz1_pHaSe_ReG = susp->hz1_pHaSe; - hz1_x1_sample_reg = susp->hz1_x1_sample; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - if (hz1_pHaSe_ReG >= 1.0) { -/* fixup-depends hz1 */ - /* pick up next sample as hz1_x1_sample: */ - susp->hz1_ptr++; - susp_took(hz1_cnt, 1); - hz1_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); - hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; - } - c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); - c3p1_reg = c3co_reg + 1.0; - c3t4_reg = c3co_reg * 4.0; - omc3_reg = 1.0 - c3co_reg; - recompute_reg = true; - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; - } while (--n); /* inner loop */ - - togo -= n; - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - /* using bw_ptr_reg is a bad idea on RS/6000: */ - susp->bw_ptr += togo; - susp->hz1_pHaSe = hz1_pHaSe_ReG; - susp->hz1_x1_sample = hz1_x1_sample_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp_took(bw_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_sis_fetch */ - - -void resonvv_sii_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register double bw_pHaSe_iNcR_rEg = susp->bw_pHaSe_iNcR; - register double bw_pHaSe_ReG; - register sample_type bw_x1_sample_reg; - register double hz1_pHaSe_iNcR_rEg = susp->hz1_pHaSe_iNcR; - register double hz1_pHaSe_ReG; - register sample_type hz1_x1_sample_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_sii_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_pHaSe_ReG = susp->bw_pHaSe; - bw_x1_sample_reg = susp->bw_x1_sample; - hz1_pHaSe_ReG = susp->hz1_pHaSe; - hz1_x1_sample_reg = susp->hz1_x1_sample; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - if (hz1_pHaSe_ReG >= 1.0) { -/* fixup-depends hz1 */ - /* pick up next sample as hz1_x1_sample: */ - susp->hz1_ptr++; - susp_took(hz1_cnt, 1); - hz1_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); - hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; - } - if (bw_pHaSe_ReG >= 1.0) { -/* fixup-depends bw */ - /* pick up next sample as bw_x1_sample: */ - susp->bw_ptr++; - susp_took(bw_cnt, 1); - bw_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); - bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; - } - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; - bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; - } while (--n); /* inner loop */ - - togo -= n; - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - susp->bw_pHaSe = bw_pHaSe_ReG; - susp->bw_x1_sample = bw_x1_sample_reg; - susp->hz1_pHaSe = hz1_pHaSe_ReG; - susp->hz1_x1_sample = hz1_x1_sample_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_sii_fetch */ - - -void resonvv_sir_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - sample_type bw_val; - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register double hz1_pHaSe_iNcR_rEg = susp->hz1_pHaSe_iNcR; - register double hz1_pHaSe_ReG; - register sample_type hz1_x1_sample_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_sir_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - susp->bw_pHaSe = 1.0; - } - - susp_check_term_samples(bw, bw_ptr, bw_cnt); - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* grab next bw_x1_sample when phase goes past 1.0; */ - /* use bw_n (computed below) to avoid roundoff errors: */ - if (susp->bw_n <= 0) { - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->bw_pHaSe -= 1.0; - /* bw_n gets number of samples before phase exceeds 1.0: */ - susp->bw_n = (long) ((1.0 - susp->bw_pHaSe) * - susp->output_per_bw); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - togo = min(togo, susp->bw_n); - bw_val = susp->bw_x1_sample; - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - hz1_pHaSe_ReG = susp->hz1_pHaSe; - hz1_x1_sample_reg = susp->hz1_x1_sample; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - if (hz1_pHaSe_ReG >= 1.0) { -/* fixup-depends hz1 */ - /* pick up next sample as hz1_x1_sample: */ - susp->hz1_ptr++; - susp_took(hz1_cnt, 1); - hz1_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(hz1, hz1_ptr, hz1_cnt, hz1_x1_sample_reg); - hz1_x1_sample_reg = susp_current_sample(hz1, hz1_ptr); - coshz_reg = susp->coshz = cos(hz1_x1_sample_reg); - recompute_reg = susp->recompute = true; - } - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - hz1_pHaSe_ReG += hz1_pHaSe_iNcR_rEg; - } while (--n); /* inner loop */ - - togo -= n; - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - susp->hz1_pHaSe = hz1_pHaSe_ReG; - susp->hz1_x1_sample = hz1_x1_sample_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp->bw_pHaSe += togo * susp->bw_pHaSe_iNcR; - susp->bw_n -= togo; - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_sir_fetch */ - - -void resonvv_srs_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - sample_type hz1_val; - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register sample_type bw_scale_reg = susp->bw->scale; - register sample_block_values_type bw_ptr_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_srs_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp->hz1_pHaSe = 1.0; - } - - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* grab next hz1_x1_sample when phase goes past 1.0; */ - /* use hz1_n (computed below) to avoid roundoff errors: */ - if (susp->hz1_n <= 0) { - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->hz1_pHaSe -= 1.0; - /* hz1_n gets number of samples before phase exceeds 1.0: */ - susp->hz1_n = (long) ((1.0 - susp->hz1_pHaSe) * - susp->output_per_hz1); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - } - togo = min(togo, susp->hz1_n); - hz1_val = susp->hz1_x1_sample; - /* don't run past the bw input sample block: */ - susp_check_term_samples(bw, bw_ptr, bw_cnt); - togo = min(togo, susp->bw_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_ptr_reg = susp->bw_ptr; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - c3co_reg = exp((bw_scale_reg * *bw_ptr_reg++)); - c3p1_reg = c3co_reg + 1.0; - c3t4_reg = c3co_reg * 4.0; - omc3_reg = 1.0 - c3co_reg; - recompute_reg = true; - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - } while (--n); /* inner loop */ - - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - /* using bw_ptr_reg is a bad idea on RS/6000: */ - susp->bw_ptr += togo; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp->hz1_pHaSe += togo * susp->hz1_pHaSe_iNcR; - susp->hz1_n -= togo; - susp_took(bw_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_srs_fetch */ - - -void resonvv_sri_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - sample_type hz1_val; - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double scale1_reg; - register double c3co_reg; - register double c3p1_reg; - register double c3t4_reg; - register double omc3_reg; - register double coshz_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register int normalization_reg; - register double y1_reg; - register double y2_reg; - register double bw_pHaSe_iNcR_rEg = susp->bw_pHaSe_iNcR; - register double bw_pHaSe_ReG; - register sample_type bw_x1_sample_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_sri_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp->hz1_pHaSe = 1.0; - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* grab next hz1_x1_sample when phase goes past 1.0; */ - /* use hz1_n (computed below) to avoid roundoff errors: */ - if (susp->hz1_n <= 0) { - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->hz1_pHaSe -= 1.0; - /* hz1_n gets number of samples before phase exceeds 1.0: */ - susp->hz1_n = (long) ((1.0 - susp->hz1_pHaSe) * - susp->output_per_hz1); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - } - togo = min(togo, susp->hz1_n); - hz1_val = susp->hz1_x1_sample; - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - scale1_reg = susp->scale1; - c3co_reg = susp->c3co; - c3p1_reg = susp->c3p1; - c3t4_reg = susp->c3t4; - omc3_reg = susp->omc3; - coshz_reg = susp->coshz; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - normalization_reg = susp->normalization; - y1_reg = susp->y1; - y2_reg = susp->y2; - bw_pHaSe_ReG = susp->bw_pHaSe; - bw_x1_sample_reg = susp->bw_x1_sample; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - if (bw_pHaSe_ReG >= 1.0) { -/* fixup-depends bw */ - /* pick up next sample as bw_x1_sample: */ - susp->bw_ptr++; - susp_took(bw_cnt, 1); - bw_pHaSe_ReG -= 1.0; - susp_check_term_samples_break(bw, bw_ptr, bw_cnt, bw_x1_sample_reg); - bw_x1_sample_reg = susp_current_sample(bw, bw_ptr); - c3co_reg = susp->c3co = exp(bw_x1_sample_reg); - c3p1_reg = susp->c3p1 = c3co_reg + 1.0; - c3t4_reg = susp->c3t4 = c3co_reg * 4.0; - omc3_reg = susp->omc3 = 1.0 - c3co_reg; - recompute_reg = susp->recompute = true; - } - if (recompute_reg) { - recompute_reg = false; - c2_reg = c3t4_reg * coshz_reg / c3p1_reg; - c1_reg = (normalization_reg == 0 ? 1.0 : - (normalization_reg == 1 ? omc3_reg * sqrt(1.0 - c2_reg * c2_reg / c3t4_reg) : - sqrt(c3p1_reg * c3p1_reg - c2_reg * c2_reg) * omc3_reg / c3p1_reg)) * scale1_reg; - } -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - bw_pHaSe_ReG += bw_pHaSe_iNcR_rEg; - } while (--n); /* inner loop */ - - togo -= n; - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - susp->bw_pHaSe = bw_pHaSe_ReG; - susp->bw_x1_sample = bw_x1_sample_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp->hz1_pHaSe += togo * susp->hz1_pHaSe_iNcR; - susp->hz1_n -= togo; - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_sri_fetch */ - - -void resonvv_srr_fetch(register resonvv_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - sample_type hz1_val; - sample_type bw_val; - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register double c3co_reg; - register double c2_reg; - register double c1_reg; - register boolean recompute_reg; - register double y1_reg; - register double y2_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "resonvv_srr_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - /* make sure sounds are primed with first values */ - if (!susp->started) { - susp->started = true; - susp->hz1_pHaSe = 1.0; - susp->bw_pHaSe = 1.0; - } - - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - - susp_check_term_samples(bw, bw_ptr, bw_cnt); - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* grab next hz1_x1_sample when phase goes past 1.0; */ - /* use hz1_n (computed below) to avoid roundoff errors: */ - if (susp->hz1_n <= 0) { - susp_check_term_samples(hz1, hz1_ptr, hz1_cnt); - susp->hz1_x1_sample = susp_fetch_sample(hz1, hz1_ptr, hz1_cnt); - susp->hz1_pHaSe -= 1.0; - /* hz1_n gets number of samples before phase exceeds 1.0: */ - susp->hz1_n = (long) ((1.0 - susp->hz1_pHaSe) * - susp->output_per_hz1); - susp->coshz = cos(susp->hz1_x1_sample); - susp->recompute = true; - } - togo = min(togo, susp->hz1_n); - hz1_val = susp->hz1_x1_sample; - /* grab next bw_x1_sample when phase goes past 1.0; */ - /* use bw_n (computed below) to avoid roundoff errors: */ - if (susp->bw_n <= 0) { - susp_check_term_samples(bw, bw_ptr, bw_cnt); - susp->bw_x1_sample = susp_fetch_sample(bw, bw_ptr, bw_cnt); - susp->bw_pHaSe -= 1.0; - /* bw_n gets number of samples before phase exceeds 1.0: */ - susp->bw_n = (long) ((1.0 - susp->bw_pHaSe) * - susp->output_per_bw); - susp->c3co = exp(susp->bw_x1_sample); - susp->c3p1 = susp->c3co + 1.0; - susp->c3t4 = susp->c3co * 4.0; - susp->omc3 = 1.0 - susp->c3co; - susp->recompute = true; - } - togo = min(togo, susp->bw_n); - bw_val = susp->bw_x1_sample; - if (susp->recompute) { - susp->recompute = false; - susp->c2 = susp->c3t4 * susp->coshz / susp->c3p1; - susp->c1 = (susp->normalization == 0 ? 1.0 : - (susp->normalization == 1 ? susp->omc3 * sqrt(1.0 - susp->c2 * susp->c2 / susp->c3t4) : - sqrt(susp->c3p1 * susp->c3p1 - susp->c2 * susp->c2) * susp->omc3 / susp->c3p1)) * susp->scale1; - } - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - c3co_reg = susp->c3co; - c2_reg = susp->c2; - c1_reg = susp->c1; - recompute_reg = susp->recompute; - y1_reg = susp->y1; - y2_reg = susp->y2; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ -{ double y0 = c1_reg * (s1_scale_reg * *s1_ptr_reg++) + c2_reg * y1_reg - c3co_reg * y2_reg; - *out_ptr_reg++ = (sample_type) y0; - y2_reg = y1_reg; y1_reg = y0; }; - } while (--n); /* inner loop */ - - susp->recompute = recompute_reg; - susp->y1 = y1_reg; - susp->y2 = y2_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - susp->hz1_pHaSe += togo * susp->hz1_pHaSe_iNcR; - susp->hz1_n -= togo; - susp->bw_pHaSe += togo * susp->bw_pHaSe_iNcR; - susp->bw_n -= togo; - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* resonvv_srr_fetch */ - - -void resonvv_toss_fetch(susp, snd_list) - register resonvv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void resonvv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -3098,20 +1617,22 @@ void resonvv_toss_fetch(susp, snd_list) susp->bw_ptr += n; susp_took(bw_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void resonvv_mark(resonvv_susp_type susp) +void resonvv_mark(snd_susp_type a_susp) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz1); sound_xlmark(susp->bw); } -void resonvv_free(resonvv_susp_type susp) +void resonvv_free(snd_susp_type a_susp) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz1); sound_unref(susp->bw); @@ -3119,8 +1640,9 @@ void resonvv_free(resonvv_susp_type susp) } -void resonvv_print_tree(resonvv_susp_type susp, int n) +void resonvv_print_tree(snd_susp_type a_susp, int n) { + resonvv_susp_type susp = (resonvv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -3143,6 +1665,13 @@ sound_type snd_make_resonvv(sound_type s1, sound_type hz1, sound_type bw, int no int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + /* combine scale factors of linear inputs (S1) */ + scale_factor *= s1->scale; + s1->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (s1->sr < sr) { s1->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, resonvv_susp_node, "snd_make_resonvv"); susp->scale1 = s1->scale; susp->c3co = 0.0; @@ -3159,6 +1688,16 @@ sound_type snd_make_resonvv(sound_type s1, sound_type hz1, sound_type bw, int no hz1->scale = (sample_type) (hz1->scale * (PI2 / s1->sr)); bw->scale = (sample_type) (bw->scale * (-PI2 / s1->sr));; + /* make sure no sample rate is too high */ + if (hz1->sr > sr) { + sound_unref(hz1); + snd_badsr(); + } + if (bw->sr > sr) { + sound_unref(bw); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz1, sr); @@ -3180,22 +1719,6 @@ sound_type snd_make_resonvv(sound_type s1, sound_type hz1, sound_type bw, int no case INTERP_nrs: susp->susp.fetch = resonvv_nrs_fetch; break; case INTERP_nri: susp->susp.fetch = resonvv_nri_fetch; break; case INTERP_nrr: susp->susp.fetch = resonvv_nrr_fetch; break; - case INTERP_snn: /* handled below */ - case INTERP_sns: /* handled below */ - case INTERP_ssn: /* handled below */ - case INTERP_sss: susp->susp.fetch = resonvv_sss_fetch; break; - case INTERP_sni: /* handled below */ - case INTERP_ssi: susp->susp.fetch = resonvv_ssi_fetch; break; - case INTERP_snr: /* handled below */ - case INTERP_ssr: susp->susp.fetch = resonvv_ssr_fetch; break; - case INTERP_sin: /* handled below */ - case INTERP_sis: susp->susp.fetch = resonvv_sis_fetch; break; - case INTERP_sii: susp->susp.fetch = resonvv_sii_fetch; break; - case INTERP_sir: susp->susp.fetch = resonvv_sir_fetch; break; - case INTERP_srn: /* handled below */ - case INTERP_srs: susp->susp.fetch = resonvv_srs_fetch; break; - case INTERP_sri: susp->susp.fetch = resonvv_sri_fetch; break; - case INTERP_srr: susp->susp.fetch = resonvv_srr_fetch; break; default: snd_badsr(); break; } @@ -3209,8 +1732,8 @@ sound_type snd_make_resonvv(sound_type s1, sound_type hz1, sound_type bw, int no /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = resonvv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = resonvv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/sampler.alg b/lib-src/libnyquist/nyquist/tran/sampler.alg index cc5fad786..1ac9469b3 100644 --- a/lib-src/libnyquist/nyquist/tran/sampler.alg +++ b/lib-src/libnyquist/nyquist/tran/sampler.alg @@ -1,31 +1,46 @@ (SAMPLER-ALG (NAME "sampler") (ARGUMENTS ("sound_type" "s") ("double" "step") ("double" "loop_start") - ("rate_type" "sr") ("double" "hz") ("time_type" "t0") ("sound_type" "s_fm") - ("long" "npoints")) + ("rate_type" "sr") ("double" "hz") ("time_type" "t0") + ("sound_type" "s_fm") ("long" "npoints")) (TABLE "s") (NOT-IN-INNER-LOOP "s") (STATE ("double" "loop_to" "loop_start * s->sr") ("table_type" "the_table" "sound_to_table(s)") ("sample_type *" "table_ptr" "susp->the_table->samples") - ("double" "table_len" "susp->the_table->length; - { long index = (long) susp->loop_to; - double frac = susp->loop_to - index; - if (index > round(susp->table_len) || - index < 0) { - index = 0; - frac = 0; - } - susp->table_ptr[round(susp->table_len)] = /* copy interpolated start to last entry */ - (sample_type) (susp->table_ptr[index] * (1.0 - frac) + - susp->table_ptr[index + 1] * frac);}") + ("double" "table_len" "susp->the_table->length;") ("double" "phase" "0.0") ("double" "ph_incr" "(s->sr / sr) * hz / step_to_hz(step); - s_fm->scale = (sample_type) (s_fm->scale * (susp->ph_incr / hz))") ) + s_fm->scale = (sample_type) (s_fm->scale * (susp->ph_incr / hz)); + /* make sure parameters are ok + * the table must have samples + * the loop_start must be before the end of the table + * ph_incr must be positive + * sr should be positive + */ + { long index = (long) susp->loop_to; + double frac = susp->loop_to - index; + if (susp->the_table->length <= 1) { + xlfail(\"sampler table length <= 1\"); + } + if (index > round(susp->table_len) - 2 || + index < 0) { + xlfail(\"sampler loop start not within samples\"); + } + if (susp->ph_incr <= 0) { + xlfail(\"sampler phase increment <= 0\"); + } + if (sr <= 0) { + xlfail(\"sampler sample rate <= 0\"); + } + /* copy interpolated start to last entry */ + susp->table_ptr[round(susp->table_len)] = + (sample_type) (susp->table_ptr[index] * (1.0 - frac) + + susp->table_ptr[index + 1] * frac);}") + ) (ALWAYS-SCALE s_fm) -(INLINE-INTERPOLATION T) ; so that modulation can be low frequency (STEP-FUNCTION s_fm) (TERMINATE (MIN s_fm)) (LOGICAL-STOP (MIN s_fm)) @@ -41,9 +56,7 @@ /* watch out for negative frequencies! */ if (phase < 0) phase = 0") (CONSTANT "ph_incr" "table_len" "table_ptr" "loop_to") - (SAMPLE-RATE "sr") -(FINALIZATION " table_unref(susp->the_table); -") +(FINALIZATION " table_unref(susp->the_table);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/sampler.c b/lib-src/libnyquist/nyquist/tran/sampler.c index 2ba3ed389..133a652bc 100644 --- a/lib-src/libnyquist/nyquist/tran/sampler.c +++ b/lib-src/libnyquist/nyquist/tran/sampler.c @@ -9,7 +9,7 @@ #include "cext.h" #include "sampler.h" -void sampler_free(); +void sampler_free(snd_susp_type a_susp); typedef struct sampler_susp_struct { @@ -39,8 +39,9 @@ typedef struct sampler_susp_struct { } sampler_susp_node, *sampler_susp_type; -void sampler_s_fetch(register sampler_susp_type susp, snd_list_type snd_list) +void sampler_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sampler_susp_type susp = (sampler_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -73,6 +74,7 @@ void sampler_s_fetch(register sampler_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -84,6 +86,7 @@ void sampler_s_fetch(register sampler_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -112,7 +115,7 @@ void sampler_s_fetch(register sampler_susp_type susp, snd_list_type snd_list) if (n) do { /* the inner sample computation loop */ long table_index; double x1; -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -146,8 +149,9 @@ table_index = (long) phase_reg; } /* sampler_s_fetch */ -void sampler_i_fetch(register sampler_susp_type susp, snd_list_type snd_list) +void sampler_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sampler_susp_type susp = (sampler_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -184,6 +188,7 @@ void sampler_i_fetch(register sampler_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -195,6 +200,7 @@ void sampler_i_fetch(register sampler_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -233,7 +239,7 @@ void sampler_i_fetch(register sampler_susp_type susp, snd_list_type snd_list) susp_check_term_log_samples_break(s_fm, s_fm_ptr, s_fm_cnt, s_fm_x1_sample_reg); s_fm_x1_sample_reg = susp_current_sample(s_fm, s_fm_ptr); } -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -268,8 +274,9 @@ table_index = (long) phase_reg; } /* sampler_i_fetch */ -void sampler_r_fetch(register sampler_susp_type susp, snd_list_type snd_list) +void sampler_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sampler_susp_type susp = (sampler_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type s_fm_val; int togo; @@ -317,6 +324,7 @@ void sampler_r_fetch(register sampler_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -328,6 +336,7 @@ void sampler_r_fetch(register sampler_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -355,7 +364,7 @@ void sampler_r_fetch(register sampler_susp_type susp, snd_list_type snd_list) if (n) do { /* the inner sample computation loop */ long table_index; double x1; -table_index = (long) phase_reg; + table_index = (long) phase_reg; x1 = table_ptr_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (phase_reg - table_index) * (table_ptr_reg[table_index + 1] - x1)); @@ -388,11 +397,9 @@ table_index = (long) phase_reg; } /* sampler_r_fetch */ -void sampler_toss_fetch(susp, snd_list) - register sampler_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void sampler_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + sampler_susp_type susp = (sampler_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -407,26 +414,29 @@ void sampler_toss_fetch(susp, snd_list) susp->s_fm_ptr += n; susp_took(s_fm_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void sampler_mark(sampler_susp_type susp) +void sampler_mark(snd_susp_type a_susp) { + sampler_susp_type susp = (sampler_susp_type) a_susp; sound_xlmark(susp->s_fm); } -void sampler_free(sampler_susp_type susp) +void sampler_free(snd_susp_type a_susp) { + sampler_susp_type susp = (sampler_susp_type) a_susp; table_unref(susp->the_table); sound_unref(susp->s_fm); ffree_generic(susp, sizeof(sampler_susp_node), "sampler_free"); } -void sampler_print_tree(sampler_susp_type susp, int n) +void sampler_print_tree(snd_susp_type a_susp, int n) { + sampler_susp_type susp = (sampler_susp_type) a_susp; indent(n); stdputstr("s_fm:"); sound_print_tree_1(susp->s_fm, n); @@ -445,20 +455,41 @@ sound_type snd_make_sampler(sound_type s, double step, double loop_start, rate_t susp->loop_to = loop_start * s->sr; susp->the_table = sound_to_table(s); susp->table_ptr = susp->the_table->samples; - susp->table_len = susp->the_table->length; - { long index = (long) susp->loop_to; - double frac = susp->loop_to - index; - if (index > round(susp->table_len) || - index < 0) { - index = 0; - frac = 0; - } - susp->table_ptr[round(susp->table_len)] = /* copy interpolated start to last entry */ - (sample_type) (susp->table_ptr[index] * (1.0 - frac) + - susp->table_ptr[index + 1] * frac);}; + susp->table_len = susp->the_table->length;; susp->phase = 0.0; susp->ph_incr = (s->sr / sr) * hz / step_to_hz(step); s_fm->scale = (sample_type) (s_fm->scale * (susp->ph_incr / hz)); + /* make sure parameters are ok + * the table must have samples + * the loop_start must be before the end of the table + * ph_incr must be positive + * sr should be positive + */ + { long index = (long) susp->loop_to; + double frac = susp->loop_to - index; + if (susp->the_table->length <= 1) { + xlfail("sampler table length <= 1"); + } + if (index > round(susp->table_len) - 2 || + index < 0) { + xlfail("sampler loop start not within samples"); + } + if (susp->ph_incr <= 0) { + xlfail("sampler phase increment <= 0"); + } + if (sr <= 0) { + xlfail("sampler sample rate <= 0"); + } + /* copy interpolated start to last entry */ + susp->table_ptr[round(susp->table_len)] = + (sample_type) (susp->table_ptr[index] * (1.0 - frac) + + susp->table_ptr[index + 1] * frac);}; + + /* make sure no sample rate is too high */ + if (s_fm->sr > sr) { + sound_unref(s_fm); + snd_badsr(); + } /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s_fm, sr); @@ -478,8 +509,8 @@ sound_type snd_make_sampler(sound_type s, double step, double loop_start, rate_t /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = sampler_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = sampler_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/scale.c b/lib-src/libnyquist/nyquist/tran/scale.c index cc011a935..bd995f780 100644 --- a/lib-src/libnyquist/nyquist/tran/scale.c +++ b/lib-src/libnyquist/nyquist/tran/scale.c @@ -9,7 +9,7 @@ #include "cext.h" #include "scale.h" -void normalize_free(); +void normalize_free(snd_susp_type a_susp); typedef struct normalize_susp_struct { @@ -24,8 +24,9 @@ typedef struct normalize_susp_struct { } normalize_susp_node, *normalize_susp_type; -void normalize_n_fetch(register normalize_susp_type susp, snd_list_type snd_list) +void normalize_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + normalize_susp_type susp = (normalize_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -53,6 +54,7 @@ void normalize_n_fetch(register normalize_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,6 +66,7 @@ void normalize_n_fetch(register normalize_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -86,7 +89,7 @@ void normalize_n_fetch(register normalize_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = *s1_ptr_reg++ * scale_reg; + *out_ptr_reg++ = *s1_ptr_reg++ * scale_reg; } while (--n); /* inner loop */ /* using s1_ptr_reg is a bad idea on RS/6000: */ @@ -112,11 +115,9 @@ void normalize_n_fetch(register normalize_susp_type susp, snd_list_type snd_list } /* normalize_n_fetch */ -void normalize_toss_fetch(susp, snd_list) - register normalize_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void normalize_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + normalize_susp_type susp = (normalize_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -131,25 +132,28 @@ void normalize_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void normalize_mark(normalize_susp_type susp) +void normalize_mark(snd_susp_type a_susp) { + normalize_susp_type susp = (normalize_susp_type) a_susp; sound_xlmark(susp->s1); } -void normalize_free(normalize_susp_type susp) +void normalize_free(snd_susp_type a_susp) { + normalize_susp_type susp = (normalize_susp_type) a_susp; sound_unref(susp->s1); ffree_generic(susp, sizeof(normalize_susp_node), "normalize_free"); } -void normalize_print_tree(normalize_susp_type susp, int n) +void normalize_print_tree(snd_susp_type a_susp, int n) { + normalize_susp_type susp = (normalize_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -161,7 +165,6 @@ sound_type snd_make_normalize(sound_type s1) register normalize_susp_type susp; rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, normalize_susp_node, "snd_make_normalize"); @@ -175,8 +178,8 @@ sound_type snd_make_normalize(sound_type s1) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = normalize_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = normalize_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/shape.alg b/lib-src/libnyquist/nyquist/tran/shape.alg index ad6d60312..b4e94769e 100644 --- a/lib-src/libnyquist/nyquist/tran/shape.alg +++ b/lib-src/libnyquist/nyquist/tran/shape.alg @@ -1,7 +1,7 @@ (SHAPE-ALG (NAME "shape") (ARGUMENTS ("sound_type" "sin") ("sound_type" "fn") - ("double" "origin")) + ("double" "origin")) (START (MIN sin)) (TABLE "fn") (NOT-IN-INNER-LOOP "fn") @@ -10,11 +10,10 @@ ("double" "origin" "origin") ("table_type" "the_table" "sound_to_table(fn)") ("sample_type *" "fcn_table" "susp->the_table->samples") - ("double" "table_len" "susp->the_table->length") ) + ("double" "table_len" "susp->the_table->length") ) (TERMINATE (MIN sin)) (LOGICAL-STOP (MIN sin)) - (INNER-LOOP " - register double offset, x1; + (INNER-LOOP "register double offset, x1; register long table_index; register double phase = sin; if (phase > 1.0) phase = 1.0; @@ -31,9 +30,8 @@ } x1 = fcn_table[table_index]; output = (sample_type) (x1 + (offset - table_index) * - (fcn_table[table_index + 1] - x1)); - ") + (fcn_table[table_index + 1] - x1))") (ALWAYS-SCALE sin) (CONSTANT "table_len" "time_to_index" "origen" "fcn_table" "the_table") - (FINALIZATION "table_unref(susp->the_table);") + (FINALIZATION "table_unref(susp->the_table);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/shape.c b/lib-src/libnyquist/nyquist/tran/shape.c index 1df83c402..b2381653c 100644 --- a/lib-src/libnyquist/nyquist/tran/shape.c +++ b/lib-src/libnyquist/nyquist/tran/shape.c @@ -9,7 +9,7 @@ #include "cext.h" #include "shape.h" -void shape_free(); +void shape_free(snd_susp_type a_susp); typedef struct shape_susp_struct { @@ -28,8 +28,9 @@ typedef struct shape_susp_struct { } shape_susp_node, *shape_susp_type; -void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) +void shape_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + shape_susp_type susp = (shape_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -61,6 +62,7 @@ void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -72,6 +74,7 @@ void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -97,7 +100,6 @@ void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) sin_ptr_reg = susp->sin_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - register double offset, x1; register long table_index; register double phase = (sin_scale_reg * *sin_ptr_reg++); @@ -116,7 +118,6 @@ void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) x1 = fcn_table_reg[table_index]; *out_ptr_reg++ = (sample_type) (x1 + (offset - table_index) * (fcn_table_reg[table_index + 1] - x1)); - ; } while (--n); /* inner loop */ susp->origin = origin_reg; @@ -143,11 +144,9 @@ void shape_s_fetch(register shape_susp_type susp, snd_list_type snd_list) } /* shape_s_fetch */ -void shape_toss_fetch(susp, snd_list) - register shape_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void shape_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + shape_susp_type susp = (shape_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -162,25 +161,29 @@ void shape_toss_fetch(susp, snd_list) susp->sin_ptr += n; susp_took(sin_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void shape_mark(shape_susp_type susp) +void shape_mark(snd_susp_type a_susp) { + shape_susp_type susp = (shape_susp_type) a_susp; sound_xlmark(susp->sin); } -void shape_free(shape_susp_type susp) +void shape_free(snd_susp_type a_susp) { -table_unref(susp->the_table); sound_unref(susp->sin); + shape_susp_type susp = (shape_susp_type) a_susp; +table_unref(susp->the_table); + sound_unref(susp->sin); ffree_generic(susp, sizeof(shape_susp_node), "shape_free"); } -void shape_print_tree(shape_susp_type susp, int n) +void shape_print_tree(snd_susp_type a_susp, int n) { + shape_susp_type susp = (shape_susp_type) a_susp; indent(n); stdputstr("sin:"); sound_print_tree_1(susp->sin, n); @@ -192,7 +195,6 @@ sound_type snd_make_shape(sound_type sin, sound_type fn, double origin) register shape_susp_type susp; rate_type sr = sin->sr; time_type t0 = sin->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, shape_susp_node, "snd_make_shape"); @@ -210,8 +212,8 @@ sound_type snd_make_shape(sound_type sin, sound_type fn, double origin) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = shape_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = shape_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/sine.alg b/lib-src/libnyquist/nyquist/tran/sine.alg index e00afde65..883c6482c 100644 --- a/lib-src/libnyquist/nyquist/tran/sine.alg +++ b/lib-src/libnyquist/nyquist/tran/sine.alg @@ -6,7 +6,7 @@ (TERMINATE (AFTER "d")) (INNER-LOOP "output = sine_table[phase >> SINE_TABLE_SHIFT]; phase += ph_incr; - phase &= SINE_TABLE_MASK;") + phase &= SINE_TABLE_MASK") (MAINTAIN ("phase" "susp->phase = (susp->phase + susp->ph_incr * togo) & SINE_TABLE_MASK")) (CONSTANT "ph_incr") diff --git a/lib-src/libnyquist/nyquist/tran/sine.c b/lib-src/libnyquist/nyquist/tran/sine.c index c84d85fb1..993adc5c2 100644 --- a/lib-src/libnyquist/nyquist/tran/sine.c +++ b/lib-src/libnyquist/nyquist/tran/sine.c @@ -9,7 +9,7 @@ #include "cext.h" #include "sine.h" -void sine_free(); +void sine_free(snd_susp_type a_susp); typedef struct sine_susp_struct { @@ -31,8 +31,9 @@ void sine_init() } -void sine__fetch(register sine_susp_type susp, snd_list_type snd_list) +void sine__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sine_susp_type susp = (sine_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -56,6 +57,7 @@ void sine__fetch(register sine_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -64,9 +66,9 @@ void sine__fetch(register sine_susp_type susp, snd_list_type snd_list) ph_incr_reg = susp->ph_incr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT]; + *out_ptr_reg++ = sine_table[phase_reg >> SINE_TABLE_SHIFT]; phase_reg += ph_incr_reg; - phase_reg &= SINE_TABLE_MASK;; + phase_reg &= SINE_TABLE_MASK; } while (--n); /* inner loop */ susp->phase = (susp->phase + susp->ph_incr * togo) & SINE_TABLE_MASK; @@ -84,13 +86,14 @@ void sine__fetch(register sine_susp_type susp, snd_list_type snd_list) } /* sine__fetch */ -void sine_free(sine_susp_type susp) +void sine_free(snd_susp_type a_susp) { + sine_susp_type susp = (sine_susp_type) a_susp; ffree_generic(susp, sizeof(sine_susp_node), "sine_free"); } -void sine_print_tree(sine_susp_type susp, int n) +void sine_print_tree(snd_susp_type a_susp, int n) { } @@ -106,7 +109,7 @@ sound_type snd_make_sine(time_type t0, double hz, rate_type sr, time_type d) susp->ph_incr = round(((hz * SINE_TABLE_LEN) * (1 << SINE_TABLE_SHIFT) / sr)); susp->susp.fetch = sine__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = sine_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/siosc.alg b/lib-src/libnyquist/nyquist/tran/siosc.alg index 2ec46904c..bdc262372 100644 --- a/lib-src/libnyquist/nyquist/tran/siosc.alg +++ b/lib-src/libnyquist/nyquist/tran/siosc.alg @@ -87,11 +87,10 @@ long siosc_table_update(siosc_susp_type susp, long cur) ) (ALWAYS-SCALE s_fm) -(INLINE-INTERPOLATION T) ; so that modulation can be low frequency (STEP-FUNCTION s_fm) (TERMINATE (MIN s_fm)) (LOGICAL-STOP (MIN s_fm)) -(INNER-LOOP-LOCALS " long table_index; +(INNER-LOOP-LOCALS " long table_index; double xa, xb; ") @@ -106,7 +105,7 @@ long siosc_table_update(siosc_susp_type susp, long cur) togo = min(n, togo); ") -(INNER-LOOP " table_index = (long) phase; +(INNER-LOOP "table_index = (long) phase; xa = table_a_samps[table_index]; xb = table_b_samps[table_index]; output = (sample_type) @@ -122,10 +121,8 @@ long siosc_table_update(siosc_susp_type susp, long cur) while (phase < 0) phase += table_len") (CONSTANT "ph_incr" "table_len" "table_ptr" "table_a_samps" "table_b_samps" "ampslope" "table_a_ptr" "table_b_ptr_ptr") - (SAMPLE-RATE "sr") (FINALIZATION " table_unref(susp->table_a_ptr); - table_unref(susp->table_b_ptr_ptr); -") + table_unref(susp->table_b_ptr_ptr);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/siosc.c b/lib-src/libnyquist/nyquist/tran/siosc.c index f4a0b44fc..09083f6e0 100644 --- a/lib-src/libnyquist/nyquist/tran/siosc.c +++ b/lib-src/libnyquist/nyquist/tran/siosc.c @@ -9,7 +9,7 @@ #include "cext.h" #include "siosc.h" -void siosc_free(); +void siosc_free(snd_susp_type a_susp); typedef struct siosc_susp_struct { @@ -102,8 +102,9 @@ long siosc_table_update(siosc_susp_type susp, long cur) } -void siosc_s_fetch(register siosc_susp_type susp, snd_list_type snd_list) +void siosc_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + siosc_susp_type susp = (siosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -139,6 +140,7 @@ void siosc_s_fetch(register siosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -150,6 +152,7 @@ void siosc_s_fetch(register siosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -186,9 +189,9 @@ void siosc_s_fetch(register siosc_susp_type susp, snd_list_type snd_list) s_fm_ptr_reg = susp->s_fm_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double xa, xb; - table_index = (long) phase_reg; + table_index = (long) phase_reg; xa = table_a_samps_reg[table_index]; xb = table_b_samps_reg[table_index]; *out_ptr_reg++ = (sample_type) @@ -230,8 +233,9 @@ void siosc_s_fetch(register siosc_susp_type susp, snd_list_type snd_list) } /* siosc_s_fetch */ -void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) +void siosc_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + siosc_susp_type susp = (siosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -271,6 +275,7 @@ void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -282,6 +287,7 @@ void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -319,7 +325,7 @@ void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) s_fm_x1_sample_reg = susp->s_fm_x1_sample; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double xa, xb; if (s_fm_pHaSe_ReG >= 1.0) { /* fixup-depends s_fm */ @@ -330,7 +336,7 @@ void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) susp_check_term_log_samples_break(s_fm, s_fm_ptr, s_fm_cnt, s_fm_x1_sample_reg); s_fm_x1_sample_reg = susp_current_sample(s_fm, s_fm_ptr); } - table_index = (long) phase_reg; + table_index = (long) phase_reg; xa = table_a_samps_reg[table_index]; xb = table_b_samps_reg[table_index]; *out_ptr_reg++ = (sample_type) @@ -373,8 +379,9 @@ void siosc_i_fetch(register siosc_susp_type susp, snd_list_type snd_list) } /* siosc_i_fetch */ -void siosc_r_fetch(register siosc_susp_type susp, snd_list_type snd_list) +void siosc_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + siosc_susp_type susp = (siosc_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type s_fm_val; int togo; @@ -425,6 +432,7 @@ void siosc_r_fetch(register siosc_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -436,6 +444,7 @@ void siosc_r_fetch(register siosc_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -471,9 +480,9 @@ void siosc_r_fetch(register siosc_susp_type susp, snd_list_type snd_list) ampslope_reg = susp->ampslope; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - long table_index; + long table_index; double xa, xb; - table_index = (long) phase_reg; + table_index = (long) phase_reg; xa = table_a_samps_reg[table_index]; xb = table_b_samps_reg[table_index]; *out_ptr_reg++ = (sample_type) @@ -514,11 +523,9 @@ void siosc_r_fetch(register siosc_susp_type susp, snd_list_type snd_list) } /* siosc_r_fetch */ -void siosc_toss_fetch(susp, snd_list) - register siosc_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void siosc_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + siosc_susp_type susp = (siosc_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -533,19 +540,21 @@ void siosc_toss_fetch(susp, snd_list) susp->s_fm_ptr += n; susp_took(s_fm_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void siosc_mark(siosc_susp_type susp) +void siosc_mark(snd_susp_type a_susp) { + siosc_susp_type susp = (siosc_susp_type) a_susp; if (susp->lis) mark(susp->lis); sound_xlmark(susp->s_fm); } -void siosc_free(siosc_susp_type susp) +void siosc_free(snd_susp_type a_susp) { + siosc_susp_type susp = (siosc_susp_type) a_susp; table_unref(susp->table_a_ptr); table_unref(susp->table_b_ptr_ptr); sound_unref(susp->s_fm); @@ -553,8 +562,9 @@ void siosc_free(siosc_susp_type susp) } -void siosc_print_tree(siosc_susp_type susp, int n) +void siosc_print_tree(snd_susp_type a_susp, int n) { + siosc_susp_type susp = (siosc_susp_type) a_susp; indent(n); stdputstr("s_fm:"); sound_print_tree_1(susp->s_fm, n); @@ -587,6 +597,12 @@ sound_type snd_make_siosc(LVAL lis, rate_type sr, double hz, time_type t0, sound susp->ph_incr = hz * susp->table_len / sr; s_fm->scale = (sample_type) (s_fm->scale * (susp->table_len / sr)); + /* make sure no sample rate is too high */ + if (s_fm->sr > sr) { + sound_unref(s_fm); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s_fm, sr); switch (interp_desc) { @@ -605,8 +621,8 @@ sound_type snd_make_siosc(LVAL lis, rate_type sr, double hz, time_type t0, sound /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = siosc_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = siosc_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/slope.alg b/lib-src/libnyquist/nyquist/tran/slope.alg index 7b0cb2bb6..b3180243a 100644 --- a/lib-src/libnyquist/nyquist/tran/slope.alg +++ b/lib-src/libnyquist/nyquist/tran/slope.alg @@ -8,8 +8,8 @@ (DELAY 1) (START (MIN input)) (INNER-LOOP "{ register sample_type x = input; -output = (sample_type) ((x - prev) * scale); -prev = x;}") + output = (sample_type) ((x - prev) * scale); + prev = x;}") (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) ) diff --git a/lib-src/libnyquist/nyquist/tran/slope.c b/lib-src/libnyquist/nyquist/tran/slope.c index 2ed584686..0eec69eda 100644 --- a/lib-src/libnyquist/nyquist/tran/slope.c +++ b/lib-src/libnyquist/nyquist/tran/slope.c @@ -9,7 +9,7 @@ #include "cext.h" #include "slope.h" -void slope_free(); +void slope_free(snd_susp_type a_susp); typedef struct slope_susp_struct { @@ -25,8 +25,9 @@ typedef struct slope_susp_struct { } slope_susp_node, *slope_susp_type; -void slope_n_fetch(register slope_susp_type susp, snd_list_type snd_list) +void slope_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + slope_susp_type susp = (slope_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -55,6 +56,7 @@ void slope_n_fetch(register slope_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -66,6 +68,7 @@ void slope_n_fetch(register slope_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -89,9 +92,9 @@ void slope_n_fetch(register slope_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ register sample_type x = *input_ptr_reg++; -*out_ptr_reg++ = (sample_type) ((x - prev_reg) * scale_reg); -prev_reg = x;}; + { register sample_type x = *input_ptr_reg++; + *out_ptr_reg++ = (sample_type) ((x - prev_reg) * scale_reg); + prev_reg = x;}; } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -118,11 +121,9 @@ prev_reg = x;}; } /* slope_n_fetch */ -void slope_toss_fetch(susp, snd_list) - register slope_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void slope_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + slope_susp_type susp = (slope_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -137,25 +138,28 @@ void slope_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void slope_mark(slope_susp_type susp) +void slope_mark(snd_susp_type a_susp) { + slope_susp_type susp = (slope_susp_type) a_susp; sound_xlmark(susp->input); } -void slope_free(slope_susp_type susp) +void slope_free(snd_susp_type a_susp) { + slope_susp_type susp = (slope_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(slope_susp_node), "slope_free"); } -void slope_print_tree(slope_susp_type susp, int n) +void slope_print_tree(snd_susp_type a_susp, int n) { + slope_susp_type susp = (slope_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -167,7 +171,6 @@ sound_type snd_make_slope(sound_type input) register slope_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, slope_susp_node, "snd_make_slope"); @@ -183,8 +186,8 @@ sound_type snd_make_slope(sound_type input) /* Toss an extra 1 samples to make up for internal buffering: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 1.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = slope_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = slope_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/sqrt.alg b/lib-src/libnyquist/nyquist/tran/sqrt.alg index 5c392a345..f00618fca 100644 --- a/lib-src/libnyquist/nyquist/tran/sqrt.alg +++ b/lib-src/libnyquist/nyquist/tran/sqrt.alg @@ -3,7 +3,9 @@ (ARGUMENTS ("sound_type" "input")) (ALWAYS-SCALE input) (START (MIN input)) - (INNER-LOOP "{ sample_type i = input; if (i < 0) i = 0; output = (sample_type) sqrt(i); }") + (INNER-LOOP "{ sample_type i = input; + if (i < 0) i = 0; + output = (sample_type) sqrt(i); }") (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) ) diff --git a/lib-src/libnyquist/nyquist/tran/sqrt.c b/lib-src/libnyquist/nyquist/tran/sqrt.c index 66b2ae71b..c15509d23 100644 --- a/lib-src/libnyquist/nyquist/tran/sqrt.c +++ b/lib-src/libnyquist/nyquist/tran/sqrt.c @@ -9,7 +9,7 @@ #include "cext.h" #include "sqrt.h" -void sqrt_free(); +void sqrt_free(snd_susp_type a_susp); typedef struct sqrt_susp_struct { @@ -22,8 +22,9 @@ typedef struct sqrt_susp_struct { } sqrt_susp_node, *sqrt_susp_type; -void sqrt_s_fetch(register sqrt_susp_type susp, snd_list_type snd_list) +void sqrt_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + sqrt_susp_type susp = (sqrt_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -51,6 +52,7 @@ void sqrt_s_fetch(register sqrt_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -62,6 +64,7 @@ void sqrt_s_fetch(register sqrt_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -83,7 +86,9 @@ void sqrt_s_fetch(register sqrt_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -{ sample_type i = (input_scale_reg * *input_ptr_reg++); if (i < 0) i = 0; *out_ptr_reg++ = (sample_type) sqrt(i); }; + { sample_type i = (input_scale_reg * *input_ptr_reg++); + if (i < 0) i = 0; + *out_ptr_reg++ = (sample_type) sqrt(i); }; } while (--n); /* inner loop */ /* using input_ptr_reg is a bad idea on RS/6000: */ @@ -109,11 +114,9 @@ void sqrt_s_fetch(register sqrt_susp_type susp, snd_list_type snd_list) } /* sqrt_s_fetch */ -void sqrt_toss_fetch(susp, snd_list) - register sqrt_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void sqrt_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + sqrt_susp_type susp = (sqrt_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -128,25 +131,28 @@ void sqrt_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void sqrt_mark(sqrt_susp_type susp) +void sqrt_mark(snd_susp_type a_susp) { + sqrt_susp_type susp = (sqrt_susp_type) a_susp; sound_xlmark(susp->input); } -void sqrt_free(sqrt_susp_type susp) +void sqrt_free(snd_susp_type a_susp) { + sqrt_susp_type susp = (sqrt_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(sqrt_susp_node), "sqrt_free"); } -void sqrt_print_tree(sqrt_susp_type susp, int n) +void sqrt_print_tree(snd_susp_type a_susp, int n) { + sqrt_susp_type susp = (sqrt_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -158,7 +164,6 @@ sound_type snd_make_sqrt(sound_type input) register sqrt_susp_type susp; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, sqrt_susp_node, "snd_make_sqrt"); @@ -171,8 +176,8 @@ sound_type snd_make_sqrt(sound_type input) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = sqrt_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = sqrt_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/stkchorus.alg b/lib-src/libnyquist/nyquist/tran/stkchorus.alg index 3e3e19a5e..4a17e8671 100644 --- a/lib-src/libnyquist/nyquist/tran/stkchorus.alg +++ b/lib-src/libnyquist/nyquist/tran/stkchorus.alg @@ -1,21 +1,17 @@ (STKCHORUS-ALG (NAME "stkchorus") -(ARGUMENTS ("sound_type" "s1")("double" "baseDelay")("double" "depth")("double" "freq") - ("double" "mix")("rate_type" "sr")) -(STATE ("struct stkEffect *" "mych" "initStkChorus(baseDelay, depth, freq, round(sr)); +(ARGUMENTS ("sound_type" "s1") ("double" "baseDelay") ("double" "depth") + ("double" "freq") ("double" "mix")) +(STATE ("struct stkEffect *" "mych" + "initStkChorus(baseDelay, depth, freq, round(sr)); stkEffectSetMix(susp->mych, mix)")) +(LINEAR s1) (START (MIN s1)) (TERMINATE (MIN s1)) (LOGICAL-STOP (MIN s1)) -(NOT-IN-INNER-LOOP "mych" "baseDelay" "depth" "freq" "mix" "sr") -(SAMPLE-RATE "sr") -(SUPPORT-FUNCTIONS " - #include \"stkint.h\" -") -(INNER-LOOP " - output = (sample_type) (stkEffectTick(mych, s1)) -") -(FINALIZATION " - deleteStkEffect(susp->mych); -") -) \ No newline at end of file +(NOT-IN-INNER-LOOP "mych" "baseDelay" "depth" "freq" "mix") +(SAMPLE-RATE (MAX s1)) +(SUPPORT-FUNCTIONS "#include \"stkint.h\"\n") +(INNER-LOOP "output = (sample_type) (stkEffectTick(mych, s1))") +(FINALIZATION " deleteStkEffect(susp->mych);\n") +) diff --git a/lib-src/libnyquist/nyquist/tran/stkchorus.c b/lib-src/libnyquist/nyquist/tran/stkchorus.c index a66fc07cc..3edda5aff 100644 --- a/lib-src/libnyquist/nyquist/tran/stkchorus.c +++ b/lib-src/libnyquist/nyquist/tran/stkchorus.c @@ -9,7 +9,7 @@ #include "cext.h" #include "stkchorus.h" -void stkchorus_free(); +void stkchorus_free(snd_susp_type a_susp); typedef struct stkchorus_susp_struct { @@ -23,12 +23,12 @@ typedef struct stkchorus_susp_struct { struct stkEffect *mych; } stkchorus_susp_node, *stkchorus_susp_type; - - #include "stkint.h" +#include "stkint.h" -void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list) +void stkchorus_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + stkchorus_susp_type susp = (stkchorus_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -56,6 +56,7 @@ void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -67,6 +68,7 @@ void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -89,9 +91,7 @@ void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, *s1_ptr_reg++)) -; + *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, *s1_ptr_reg++)); } while (--n); /* inner loop */ susp->mych = mych_reg; @@ -118,103 +118,9 @@ void stkchorus_n_fetch(register stkchorus_susp_type susp, snd_list_type snd_list } /* stkchorus_n_fetch */ -void stkchorus_s_fetch(register stkchorus_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct stkEffect * mych_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "stkchorus_s_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - mych_reg = susp->mych; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, (s1_scale_reg * *s1_ptr_reg++))) -; - } while (--n); /* inner loop */ - - susp->mych = mych_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* stkchorus_s_fetch */ - - -void stkchorus_toss_fetch(susp, snd_list) - register stkchorus_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void stkchorus_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + stkchorus_susp_type susp = (stkchorus_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -229,53 +135,53 @@ void stkchorus_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void stkchorus_mark(stkchorus_susp_type susp) +void stkchorus_mark(snd_susp_type a_susp) { + stkchorus_susp_type susp = (stkchorus_susp_type) a_susp; sound_xlmark(susp->s1); } -void stkchorus_free(stkchorus_susp_type susp) +void stkchorus_free(snd_susp_type a_susp) { - - deleteStkEffect(susp->mych); + stkchorus_susp_type susp = (stkchorus_susp_type) a_susp; + deleteStkEffect(susp->mych); sound_unref(susp->s1); ffree_generic(susp, sizeof(stkchorus_susp_node), "stkchorus_free"); } -void stkchorus_print_tree(stkchorus_susp_type susp, int n) +void stkchorus_print_tree(snd_susp_type a_susp, int n) { + stkchorus_susp_type susp = (stkchorus_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); } -sound_type snd_make_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix, rate_type sr) +sound_type snd_make_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix) { register stkchorus_susp_type susp; - /* sr specified as input parameter */ + rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + /* combine scale factors of linear inputs (S1) */ + scale_factor *= s1->scale; + s1->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (s1->sr < sr) { s1->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, stkchorus_susp_node, "snd_make_stkchorus"); susp->mych = initStkChorus(baseDelay, depth, freq, round(sr)); stkEffectSetMix(susp->mych, mix); - - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(s1, sr); - switch (interp_desc) { - case INTERP_n: susp->susp.fetch = stkchorus_n_fetch; break; - case INTERP_s: susp->susp.fetch = stkchorus_s_fetch; break; - default: snd_badsr(); break; - } - + susp->susp.fetch = stkchorus_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -284,8 +190,8 @@ stkEffectSetMix(susp->mych, mix); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = stkchorus_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = stkchorus_toss_fetch; } /* initialize susp state */ @@ -304,8 +210,8 @@ stkEffectSetMix(susp->mych, mix); } -sound_type snd_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix, rate_type sr) +sound_type snd_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix) { sound_type s1_copy = sound_copy(s1); - return snd_make_stkchorus(s1_copy, baseDelay, depth, freq, mix, sr); + return snd_make_stkchorus(s1_copy, baseDelay, depth, freq, mix); } diff --git a/lib-src/libnyquist/nyquist/tran/stkchorus.h b/lib-src/libnyquist/nyquist/tran/stkchorus.h index 5bbd13a22..b970f1f70 100644 --- a/lib-src/libnyquist/nyquist/tran/stkchorus.h +++ b/lib-src/libnyquist/nyquist/tran/stkchorus.h @@ -1,3 +1,3 @@ -sound_type snd_make_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix, rate_type sr); -sound_type snd_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix, rate_type sr); - /* LISP: (snd-stkchorus SOUND ANYNUM ANYNUM ANYNUM ANYNUM ANYNUM) */ +sound_type snd_make_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix); +sound_type snd_stkchorus(sound_type s1, double baseDelay, double depth, double freq, double mix); + /* LISP: (snd-stkchorus SOUND ANYNUM ANYNUM ANYNUM ANYNUM) */ diff --git a/lib-src/libnyquist/nyquist/tran/stkpitshift.alg b/lib-src/libnyquist/nyquist/tran/stkpitshift.alg index 0c7b2ac84..7b950bf7a 100644 --- a/lib-src/libnyquist/nyquist/tran/stkpitshift.alg +++ b/lib-src/libnyquist/nyquist/tran/stkpitshift.alg @@ -1,20 +1,17 @@ (STKPITSHIFT-ALG (NAME "stkpitshift") -(ARGUMENTS ("sound_type" "s1")("double" "shift")("double" "mix")("rate_type" "sr")) +(ARGUMENTS ("sound_type" "s1") ("double" "shift") ("double" "mix")) (STATE ("struct stkEffect *" "mych" "initStkPitShift(shift, round(sr)); stkEffectSetMix(susp->mych, mix)")) +(ALWAYS-SCALE s1) (START (MIN s1)) (TERMINATE (MIN s1)) (LOGICAL-STOP (MIN s1)) (NOT-IN-INNER-LOOP "mych" "shift" "mix" "sr") -(SAMPLE-RATE "sr") +(SAMPLE-RATE (MAX s1)) (SUPPORT-FUNCTIONS " - #include \"stkint.h\" +#include \"stkint.h\" ") -(INNER-LOOP " - output = (sample_type) (stkEffectTick(mych, s1)) -") -(FINALIZATION " - deleteStkEffect(susp->mych); -") -) \ No newline at end of file +(INNER-LOOP "output = (sample_type) (stkEffectTick(mych, s1))") +(FINALIZATION " deleteStkEffect(susp->mych);\n") +) diff --git a/lib-src/libnyquist/nyquist/tran/stkpitshift.c b/lib-src/libnyquist/nyquist/tran/stkpitshift.c index 586bab443..383956e92 100644 --- a/lib-src/libnyquist/nyquist/tran/stkpitshift.c +++ b/lib-src/libnyquist/nyquist/tran/stkpitshift.c @@ -9,7 +9,7 @@ #include "cext.h" #include "stkpitshift.h" -void stkpitshift_free(); +void stkpitshift_free(snd_susp_type a_susp); typedef struct stkpitshift_susp_struct { @@ -24,102 +24,12 @@ typedef struct stkpitshift_susp_struct { } stkpitshift_susp_node, *stkpitshift_susp_type; - #include "stkint.h" +#include "stkint.h" -void stkpitshift_n_fetch(register stkpitshift_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct stkEffect * mych_reg; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "stkpitshift_n_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - mych_reg = susp->mych; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, *s1_ptr_reg++)) -; - } while (--n); /* inner loop */ - - susp->mych = mych_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* stkpitshift_n_fetch */ - - -void stkpitshift_s_fetch(register stkpitshift_susp_type susp, snd_list_type snd_list) +void stkpitshift_s_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + stkpitshift_susp_type susp = (stkpitshift_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -148,6 +58,7 @@ void stkpitshift_s_fetch(register stkpitshift_susp_type susp, snd_list_type snd_ if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -159,6 +70,7 @@ void stkpitshift_s_fetch(register stkpitshift_susp_type susp, snd_list_type snd_ * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -181,9 +93,7 @@ void stkpitshift_s_fetch(register stkpitshift_susp_type susp, snd_list_type snd_ s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, (s1_scale_reg * *s1_ptr_reg++))) -; + *out_ptr_reg++ = (sample_type) (stkEffectTick(mych_reg, (s1_scale_reg * *s1_ptr_reg++))); } while (--n); /* inner loop */ susp->mych = mych_reg; @@ -210,11 +120,9 @@ void stkpitshift_s_fetch(register stkpitshift_susp_type susp, snd_list_type snd_ } /* stkpitshift_s_fetch */ -void stkpitshift_toss_fetch(susp, snd_list) - register stkpitshift_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void stkpitshift_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + stkpitshift_susp_type susp = (stkpitshift_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -229,53 +137,46 @@ void stkpitshift_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void stkpitshift_mark(stkpitshift_susp_type susp) +void stkpitshift_mark(snd_susp_type a_susp) { + stkpitshift_susp_type susp = (stkpitshift_susp_type) a_susp; sound_xlmark(susp->s1); } -void stkpitshift_free(stkpitshift_susp_type susp) +void stkpitshift_free(snd_susp_type a_susp) { - - deleteStkEffect(susp->mych); + stkpitshift_susp_type susp = (stkpitshift_susp_type) a_susp; + deleteStkEffect(susp->mych); sound_unref(susp->s1); ffree_generic(susp, sizeof(stkpitshift_susp_node), "stkpitshift_free"); } -void stkpitshift_print_tree(stkpitshift_susp_type susp, int n) +void stkpitshift_print_tree(snd_susp_type a_susp, int n) { + stkpitshift_susp_type susp = (stkpitshift_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); } -sound_type snd_make_stkpitshift(sound_type s1, double shift, double mix, rate_type sr) +sound_type snd_make_stkpitshift(sound_type s1, double shift, double mix) { register stkpitshift_susp_type susp; - /* sr specified as input parameter */ + rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, stkpitshift_susp_node, "snd_make_stkpitshift"); susp->mych = initStkPitShift(shift, round(sr)); stkEffectSetMix(susp->mych, mix); - - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(s1, sr); - switch (interp_desc) { - case INTERP_n: susp->susp.fetch = stkpitshift_n_fetch; break; - case INTERP_s: susp->susp.fetch = stkpitshift_s_fetch; break; - default: snd_badsr(); break; - } - + susp->susp.fetch = stkpitshift_s_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -284,8 +185,8 @@ stkEffectSetMix(susp->mych, mix); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = stkpitshift_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = stkpitshift_toss_fetch; } /* initialize susp state */ @@ -304,8 +205,8 @@ stkEffectSetMix(susp->mych, mix); } -sound_type snd_stkpitshift(sound_type s1, double shift, double mix, rate_type sr) +sound_type snd_stkpitshift(sound_type s1, double shift, double mix) { sound_type s1_copy = sound_copy(s1); - return snd_make_stkpitshift(s1_copy, shift, mix, sr); + return snd_make_stkpitshift(s1_copy, shift, mix); } diff --git a/lib-src/libnyquist/nyquist/tran/stkpitshift.h b/lib-src/libnyquist/nyquist/tran/stkpitshift.h index ff9c16ec3..1fc2ef33c 100644 --- a/lib-src/libnyquist/nyquist/tran/stkpitshift.h +++ b/lib-src/libnyquist/nyquist/tran/stkpitshift.h @@ -1,3 +1,3 @@ -sound_type snd_make_stkpitshift(sound_type s1, double shift, double mix, rate_type sr); -sound_type snd_stkpitshift(sound_type s1, double shift, double mix, rate_type sr); - /* LISP: (snd-stkpitshift SOUND ANYNUM ANYNUM ANYNUM) */ +sound_type snd_make_stkpitshift(sound_type s1, double shift, double mix); +sound_type snd_stkpitshift(sound_type s1, double shift, double mix); + /* LISP: (snd-stkpitshift SOUND ANYNUM ANYNUM) */ diff --git a/lib-src/libnyquist/nyquist/tran/stkrev.alg b/lib-src/libnyquist/nyquist/tran/stkrev.alg index b4704ade5..49f102172 100644 --- a/lib-src/libnyquist/nyquist/tran/stkrev.alg +++ b/lib-src/libnyquist/nyquist/tran/stkrev.alg @@ -1,20 +1,16 @@ (STKREV-ALG (NAME "stkrev") -(ARGUMENTS ("int" "rev_type")("sound_type" "s1")("time_type" "trev")("double" "mix")("rate_type" "sr")) +(ARGUMENTS ("int" "rev_type") ("sound_type" "s1") ("time_type" "trev") + ("double" "mix")) (STATE ("struct stkEffect *" "myrv" "initStkEffect(rev_type, trev, round(sr)); -stkEffectSetMix(susp->myrv, mix)")) + stkEffectSetMix(susp->myrv, mix)")) +(LINEAR s1) (START (MIN s1)) (TERMINATE (MIN s1)) (LOGICAL-STOP (MIN s1)) (NOT-IN-INNER-LOOP "myrv" "trev") -(SAMPLE-RATE "sr") -(SUPPORT-FUNCTIONS " - #include \"stkint.h\" -") -(INNER-LOOP " - output = (sample_type) (stkEffectTick(myrv, s1)) -") -(FINALIZATION " - deleteStkEffect(susp->myrv); -") -) \ No newline at end of file +(SAMPLE-RATE (MAX s1)) +(SUPPORT-FUNCTIONS "#include \"stkint.h\"\n") +(INNER-LOOP "output = (sample_type) (stkEffectTick(myrv, s1))") +(FINALIZATION " deleteStkEffect(susp->myrv);\n") +) diff --git a/lib-src/libnyquist/nyquist/tran/stkrev.c b/lib-src/libnyquist/nyquist/tran/stkrev.c index 36490d7c4..7537bf86e 100644 --- a/lib-src/libnyquist/nyquist/tran/stkrev.c +++ b/lib-src/libnyquist/nyquist/tran/stkrev.c @@ -9,7 +9,7 @@ #include "cext.h" #include "stkrev.h" -void stkrev_free(); +void stkrev_free(snd_susp_type a_susp); typedef struct stkrev_susp_struct { @@ -23,12 +23,12 @@ typedef struct stkrev_susp_struct { struct stkEffect *myrv; } stkrev_susp_node, *stkrev_susp_type; - - #include "stkint.h" +#include "stkint.h" -void stkrev_n_fetch(register stkrev_susp_type susp, snd_list_type snd_list) +void stkrev_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + stkrev_susp_type susp = (stkrev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -56,6 +56,7 @@ void stkrev_n_fetch(register stkrev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -67,6 +68,7 @@ void stkrev_n_fetch(register stkrev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -89,9 +91,7 @@ void stkrev_n_fetch(register stkrev_susp_type susp, snd_list_type snd_list) s1_ptr_reg = susp->s1_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(myrv_reg, *s1_ptr_reg++)) -; + *out_ptr_reg++ = (sample_type) (stkEffectTick(myrv_reg, *s1_ptr_reg++)); } while (--n); /* inner loop */ susp->myrv = myrv_reg; @@ -118,103 +118,9 @@ void stkrev_n_fetch(register stkrev_susp_type susp, snd_list_type snd_list) } /* stkrev_n_fetch */ -void stkrev_s_fetch(register stkrev_susp_type susp, snd_list_type snd_list) -{ - int cnt = 0; /* how many samples computed */ - int togo; - int n; - sample_block_type out; - register sample_block_values_type out_ptr; - - register sample_block_values_type out_ptr_reg; - - register struct stkEffect * myrv_reg; - register sample_type s1_scale_reg = susp->s1->scale; - register sample_block_values_type s1_ptr_reg; - falloc_sample_block(out, "stkrev_s_fetch"); - out_ptr = out->samples; - snd_list->block = out; - - while (cnt < max_sample_block_len) { /* outer loop */ - /* first compute how many samples to generate in inner loop: */ - /* don't overflow the output sample block: */ - togo = max_sample_block_len - cnt; - - /* don't run past the s1 input sample block: */ - susp_check_term_log_samples(s1, s1_ptr, s1_cnt); - togo = min(togo, susp->s1_cnt); - - /* don't run past terminate time */ - if (susp->terminate_cnt != UNKNOWN && - susp->terminate_cnt <= susp->susp.current + cnt + togo) { - togo = susp->terminate_cnt - (susp->susp.current + cnt); - if (togo == 0) break; - } - - - /* don't run past logical stop time */ - if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { - int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); - /* break if to_stop == 0 (we're at the logical stop) - * AND cnt > 0 (we're not at the beginning of the - * output block). - */ - if (to_stop < togo) { - if (to_stop == 0) { - if (cnt) { - togo = 0; - break; - } else /* keep togo as is: since cnt == 0, we - * can set the logical stop flag on this - * output block - */ - susp->logically_stopped = true; - } else /* limit togo so we can start a new - * block at the LST - */ - togo = to_stop; - } - } - - n = togo; - myrv_reg = susp->myrv; - s1_ptr_reg = susp->s1_ptr; - out_ptr_reg = out_ptr; - if (n) do { /* the inner sample computation loop */ - - *out_ptr_reg++ = (sample_type) (stkEffectTick(myrv_reg, (s1_scale_reg * *s1_ptr_reg++))) -; - } while (--n); /* inner loop */ - - susp->myrv = myrv_reg; - /* using s1_ptr_reg is a bad idea on RS/6000: */ - susp->s1_ptr += togo; - out_ptr += togo; - susp_took(s1_cnt, togo); - cnt += togo; - } /* outer loop */ - - /* test for termination */ - if (togo == 0 && cnt == 0) { - snd_list_terminate(snd_list); - } else { - snd_list->block_len = cnt; - susp->susp.current += cnt; - } - /* test for logical stop */ - if (susp->logically_stopped) { - snd_list->logically_stopped = true; - } else if (susp->susp.log_stop_cnt == susp->susp.current) { - susp->logically_stopped = true; - } -} /* stkrev_s_fetch */ - - -void stkrev_toss_fetch(susp, snd_list) - register stkrev_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void stkrev_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + stkrev_susp_type susp = (stkrev_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -229,53 +135,53 @@ void stkrev_toss_fetch(susp, snd_list) susp->s1_ptr += n; susp_took(s1_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void stkrev_mark(stkrev_susp_type susp) +void stkrev_mark(snd_susp_type a_susp) { + stkrev_susp_type susp = (stkrev_susp_type) a_susp; sound_xlmark(susp->s1); } -void stkrev_free(stkrev_susp_type susp) +void stkrev_free(snd_susp_type a_susp) { - - deleteStkEffect(susp->myrv); + stkrev_susp_type susp = (stkrev_susp_type) a_susp; + deleteStkEffect(susp->myrv); sound_unref(susp->s1); ffree_generic(susp, sizeof(stkrev_susp_node), "stkrev_free"); } -void stkrev_print_tree(stkrev_susp_type susp, int n) +void stkrev_print_tree(snd_susp_type a_susp, int n) { + stkrev_susp_type susp = (stkrev_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); } -sound_type snd_make_stkrev(int rev_type, sound_type s1, time_type trev, double mix, rate_type sr) +sound_type snd_make_stkrev(int rev_type, sound_type s1, time_type trev, double mix) { register stkrev_susp_type susp; - /* sr specified as input parameter */ + rate_type sr = s1->sr; time_type t0 = s1->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; + /* combine scale factors of linear inputs (S1) */ + scale_factor *= s1->scale; + s1->scale = 1.0F; + + /* try to push scale_factor back to a low sr input */ + if (s1->sr < sr) { s1->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, stkrev_susp_node, "snd_make_stkrev"); susp->myrv = initStkEffect(rev_type, trev, round(sr)); -stkEffectSetMix(susp->myrv, mix); - - /* select a susp fn based on sample rates */ - interp_desc = (interp_desc << 2) + interp_style(s1, sr); - switch (interp_desc) { - case INTERP_n: susp->susp.fetch = stkrev_n_fetch; break; - case INTERP_s: susp->susp.fetch = stkrev_s_fetch; break; - default: snd_badsr(); break; - } - + stkEffectSetMix(susp->myrv, mix); + susp->susp.fetch = stkrev_n_fetch; susp->terminate_cnt = UNKNOWN; /* handle unequal start times, if any */ if (t0 < s1->t0) sound_prepend_zeros(s1, t0); @@ -284,8 +190,8 @@ stkEffectSetMix(susp->myrv, mix); /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = stkrev_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = stkrev_toss_fetch; } /* initialize susp state */ @@ -304,8 +210,8 @@ stkEffectSetMix(susp->myrv, mix); } -sound_type snd_stkrev(int rev_type, sound_type s1, time_type trev, double mix, rate_type sr) +sound_type snd_stkrev(int rev_type, sound_type s1, time_type trev, double mix) { sound_type s1_copy = sound_copy(s1); - return snd_make_stkrev(rev_type, s1_copy, trev, mix, sr); + return snd_make_stkrev(rev_type, s1_copy, trev, mix); } diff --git a/lib-src/libnyquist/nyquist/tran/stkrev.h b/lib-src/libnyquist/nyquist/tran/stkrev.h index 09926c667..5a71e4ff6 100644 --- a/lib-src/libnyquist/nyquist/tran/stkrev.h +++ b/lib-src/libnyquist/nyquist/tran/stkrev.h @@ -1,3 +1,3 @@ -sound_type snd_make_stkrev(int rev_type, sound_type s1, time_type trev, double mix, rate_type sr); -sound_type snd_stkrev(int rev_type, sound_type s1, time_type trev, double mix, rate_type sr); - /* LISP: (snd-stkrev FIXNUM SOUND ANYNUM ANYNUM ANYNUM) */ +sound_type snd_make_stkrev(int rev_type, sound_type s1, time_type trev, double mix); +sound_type snd_stkrev(int rev_type, sound_type s1, time_type trev, double mix); + /* LISP: (snd-stkrev FIXNUM SOUND ANYNUM ANYNUM) */ diff --git a/lib-src/libnyquist/nyquist/tran/tapf.alg b/lib-src/libnyquist/nyquist/tran/tapf.alg index 90175e054..ea276ed87 100644 --- a/lib-src/libnyquist/nyquist/tran/tapf.alg +++ b/lib-src/libnyquist/nyquist/tran/tapf.alg @@ -2,10 +2,9 @@ (NAME "tapf") (ARGUMENTS ("sound_type" "s1") ("double" "offset") ("sound_type" "vardelay") ("double" "maxdelay")) -(INLINE-INTERPOLATION T) (STEP-FUNCTION "vardelay") (INTERNAL-SCALING vardelay) -(ALWAYS-SCALE s1) +;(ALWAYS-SCALE s1) (START (MAX s1 vardelay)) (TERMINATE (MIN s1 vardelay)) (LOGICAL-STOP (MIN s1)) @@ -20,30 +19,28 @@ (CONSTANT "maxdelay" "offset" "vdscale" "buffer") (INNER-LOOP-LOCALS " long phase; ") -(INNER-LOOP " phase = (long) (vardelay * vdscale + offset); - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay) phase = maxdelay; - phase = index - phase; - /* now phase is a location in the buffer (before modulo) */ - - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer[index++] = s1; - if (index >= bufflen) { - index = 0; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen; - output = (sample_type) (buffer[phase]);") -(FINALIZATION " free(susp->buffer); -") +(INNER-LOOP "phase = (long) (vardelay * vdscale + offset); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay) phase = maxdelay; + phase = index - phase; + /* now phase is a location in the buffer (before modulo) */ + + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer[index++] = s1; + if (index >= bufflen) { + index = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen; + output = (sample_type) (buffer[phase])") +(FINALIZATION " free(susp->buffer);\n") ) - diff --git a/lib-src/libnyquist/nyquist/tran/tapf.c b/lib-src/libnyquist/nyquist/tran/tapf.c index c7c4556de..365eaba96 100644 --- a/lib-src/libnyquist/nyquist/tran/tapf.c +++ b/lib-src/libnyquist/nyquist/tran/tapf.c @@ -9,7 +9,7 @@ #include "cext.h" #include "tapf.h" -void tapf_free(); +void tapf_free(snd_susp_type a_susp); typedef struct tapf_susp_struct { @@ -42,8 +42,458 @@ typedef struct tapf_susp_struct { } tapf_susp_node, *tapf_susp_type; -void tapf_sn_fetch(register tapf_susp_type susp, snd_list_type snd_list) +void tapf_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapf_susp_type susp = (tapf_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register long maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register sample_block_values_type vardelay_ptr_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapf_nn_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past the vardelay input sample block: */ + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + togo = min(togo, susp->vardelay_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + vardelay_ptr_reg = susp->vardelay_ptr; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + long phase; + phase = (long) (*vardelay_ptr_reg++ * vdscale_reg + offset_reg); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); + } while (--n); /* inner loop */ + + susp->bufflen = bufflen_reg; + susp->index = index_reg; + /* using vardelay_ptr_reg is a bad idea on RS/6000: */ + susp->vardelay_ptr += togo; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp_took(vardelay_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapf_nn_fetch */ + + +void tapf_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapf_susp_type susp = (tapf_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type vardelay_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register long maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register double vardelay_pHaSe_iNcR_rEg = susp->vardelay_pHaSe_iNcR; + register double vardelay_pHaSe_ReG; + register sample_type vardelay_x1_sample_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapf_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + susp->vardelay_x1_sample = (susp->vardelay_cnt--, *(susp->vardelay_ptr)); + } + + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + vardelay_pHaSe_ReG = susp->vardelay_pHaSe; + vardelay_x1_sample_reg = susp->vardelay_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + long phase; + if (vardelay_pHaSe_ReG >= 1.0) { + vardelay_x1_sample_reg = vardelay_x2_sample; + /* pick up next sample as vardelay_x2_sample: */ + susp->vardelay_ptr++; + susp_took(vardelay_cnt, 1); + vardelay_pHaSe_ReG -= 1.0; + susp_check_term_samples_break(vardelay, vardelay_ptr, vardelay_cnt, vardelay_x2_sample); + } + phase = (long) ( + (vardelay_x1_sample_reg * (1 - vardelay_pHaSe_ReG) + vardelay_x2_sample * vardelay_pHaSe_ReG) * vdscale_reg + offset_reg); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); + vardelay_pHaSe_ReG += vardelay_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->bufflen = bufflen_reg; + susp->index = index_reg; + susp->vardelay_pHaSe = vardelay_pHaSe_ReG; + susp->vardelay_x1_sample = vardelay_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapf_ni_fetch */ + + +void tapf_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapf_susp_type susp = (tapf_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type vardelay_DeLtA; + sample_type vardelay_val; + sample_type vardelay_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register long maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapf_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->vardelay_pHaSe = 1.0; + } + + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next vardelay_x2_sample when phase goes past 1.0; */ + /* we use vardelay_n (computed below) to avoid roundoff errors: */ + if (susp->vardelay_n <= 0) { + susp->vardelay_x1_sample = vardelay_x2_sample; + susp->vardelay_ptr++; + susp_took(vardelay_cnt, 1); + susp->vardelay_pHaSe -= 1.0; + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + /* vardelay_n gets number of samples before phase exceeds 1.0: */ + susp->vardelay_n = (long) ((1.0 - susp->vardelay_pHaSe) * + susp->output_per_vardelay); + } + togo = min(togo, susp->vardelay_n); + vardelay_DeLtA = (sample_type) ((vardelay_x2_sample - susp->vardelay_x1_sample) * susp->vardelay_pHaSe_iNcR); + vardelay_val = (sample_type) (susp->vardelay_x1_sample * (1.0 - susp->vardelay_pHaSe) + + vardelay_x2_sample * susp->vardelay_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + long phase; + phase = (long) (vardelay_val * vdscale_reg + offset_reg); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); + vardelay_val += vardelay_DeLtA; + } while (--n); /* inner loop */ + + susp->bufflen = bufflen_reg; + susp->index = index_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->vardelay_pHaSe += togo * susp->vardelay_pHaSe_iNcR; + susp->vardelay_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapf_nr_fetch */ + + +void tapf_sn_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapf_susp_type susp = (tapf_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -82,6 +532,7 @@ void tapf_sn_fetch(register tapf_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -93,6 +544,7 @@ void tapf_sn_fetch(register tapf_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -122,29 +574,29 @@ void tapf_sn_fetch(register tapf_susp_type susp, snd_list_type snd_list) out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ long phase; - phase = (long) (*vardelay_ptr_reg++ * vdscale_reg + offset_reg); - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg >= bufflen_reg) { - index_reg = 0; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - *out_ptr_reg++ = (sample_type) (buffer_reg[phase]);; + phase = (long) (*vardelay_ptr_reg++ * vdscale_reg + offset_reg); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); } while (--n); /* inner loop */ susp->bufflen = bufflen_reg; @@ -175,8 +627,9 @@ void tapf_sn_fetch(register tapf_susp_type susp, snd_list_type snd_list) } /* tapf_sn_fetch */ -void tapf_si_fetch(register tapf_susp_type susp, snd_list_type snd_list) +void tapf_si_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapf_susp_type susp = (tapf_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type vardelay_x2_sample; int togo; @@ -224,6 +677,7 @@ void tapf_si_fetch(register tapf_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -235,6 +689,7 @@ void tapf_si_fetch(register tapf_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -273,30 +728,30 @@ void tapf_si_fetch(register tapf_susp_type susp, snd_list_type snd_list) vardelay_pHaSe_ReG -= 1.0; susp_check_term_samples_break(vardelay, vardelay_ptr, vardelay_cnt, vardelay_x2_sample); } - phase = (long) ( + phase = (long) ( (vardelay_x1_sample_reg * (1 - vardelay_pHaSe_ReG) + vardelay_x2_sample * vardelay_pHaSe_ReG) * vdscale_reg + offset_reg); - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg >= bufflen_reg) { - index_reg = 0; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - *out_ptr_reg++ = (sample_type) (buffer_reg[phase]);; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); vardelay_pHaSe_ReG += vardelay_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -328,8 +783,9 @@ void tapf_si_fetch(register tapf_susp_type susp, snd_list_type snd_list) } /* tapf_si_fetch */ -void tapf_sr_fetch(register tapf_susp_type susp, snd_list_type snd_list) +void tapf_sr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapf_susp_type susp = (tapf_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type vardelay_DeLtA; sample_type vardelay_val; @@ -393,6 +849,7 @@ void tapf_sr_fetch(register tapf_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -404,6 +861,7 @@ void tapf_sr_fetch(register tapf_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -432,29 +890,29 @@ void tapf_sr_fetch(register tapf_susp_type susp, snd_list_type snd_list) out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ long phase; - phase = (long) (vardelay_val * vdscale_reg + offset_reg); - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg >= bufflen_reg) { - index_reg = 0; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - *out_ptr_reg++ = (sample_type) (buffer_reg[phase]);; + phase = (long) (vardelay_val * vdscale_reg + offset_reg); + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg >= bufflen_reg) { + index_reg = 0; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + *out_ptr_reg++ = (sample_type) (buffer_reg[phase]); vardelay_val += vardelay_DeLtA; } while (--n); /* inner loop */ @@ -485,11 +943,9 @@ void tapf_sr_fetch(register tapf_susp_type susp, snd_list_type snd_list) } /* tapf_sr_fetch */ -void tapf_toss_fetch(susp, snd_list) - register tapf_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void tapf_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + tapf_susp_type susp = (tapf_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -512,19 +968,21 @@ void tapf_toss_fetch(susp, snd_list) susp->vardelay_ptr += n; susp_took(vardelay_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void tapf_mark(tapf_susp_type susp) +void tapf_mark(snd_susp_type a_susp) { + tapf_susp_type susp = (tapf_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->vardelay); } -void tapf_free(tapf_susp_type susp) +void tapf_free(snd_susp_type a_susp) { + tapf_susp_type susp = (tapf_susp_type) a_susp; free(susp->buffer); sound_unref(susp->s1); sound_unref(susp->vardelay); @@ -532,8 +990,9 @@ void tapf_free(tapf_susp_type susp) } -void tapf_print_tree(tapf_susp_type susp, int n) +void tapf_print_tree(snd_susp_type a_susp, int n) { + tapf_susp_type susp = (tapf_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -560,17 +1019,23 @@ sound_type snd_make_tapf(sound_type s1, double offset, sound_type vardelay, doub susp->index = susp->bufflen; susp->buffer = (sample_type *) calloc(susp->bufflen + 1, sizeof(sample_type)); + /* make sure no sample rate is too high */ + if (vardelay->sr > sr) { + sound_unref(vardelay); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(vardelay, sr); switch (interp_desc) { case INTERP_ns: /* handled below */ - case INTERP_nn: /* handled below */ + case INTERP_nn: susp->susp.fetch = tapf_nn_fetch; break; + case INTERP_ni: susp->susp.fetch = tapf_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = tapf_nr_fetch; break; case INTERP_ss: /* handled below */ case INTERP_sn: susp->susp.fetch = tapf_sn_fetch; break; - case INTERP_ni: /* handled below */ case INTERP_si: susp->susp.fetch = tapf_si_fetch; break; - case INTERP_nr: /* handled below */ case INTERP_sr: susp->susp.fetch = tapf_sr_fetch; break; default: snd_badsr(); break; } @@ -584,8 +1049,8 @@ sound_type snd_make_tapf(sound_type s1, double offset, sound_type vardelay, doub /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = tapf_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = tapf_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/tapv.alg b/lib-src/libnyquist/nyquist/tran/tapv.alg index e71b3e5da..6592b05a1 100644 --- a/lib-src/libnyquist/nyquist/tran/tapv.alg +++ b/lib-src/libnyquist/nyquist/tran/tapv.alg @@ -2,9 +2,7 @@ (NAME "tapv") (ARGUMENTS ("sound_type" "s1") ("double" "offset") ("sound_type" "vardelay") ("double" "maxdelay")) -(INLINE-INTERPOLATION T) (INTERNAL-SCALING vardelay) -(ALWAYS-SCALE s1) (START (MAX s1 vardelay)) (TERMINATE (MIN s1 vardelay)) (LOGICAL-STOP (MIN s1)) @@ -20,34 +18,33 @@ (INNER-LOOP-LOCALS " double phase; long i; ") -(INNER-LOOP " phase = vardelay * vdscale + offset; - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay) phase = maxdelay; - phase = (double) index - phase; - /* now phase is a location in the buffer (before modulo) */ - - /* Time out to update the buffer: - * this is a tricky buffer: buffer[0] == buffer[bufflen] - * the logical length is bufflen, but the actual length - * is bufflen + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer[index++] = s1; - if (index > bufflen) { - buffer[0] = buffer[bufflen]; - index = 1; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen; - i = (long) phase; /* put integer part in i */ - phase -= (double) i; /* put fractional part in phase */ - output = (sample_type) (buffer[i] * (1.0 - phase) + - buffer[i + 1] * phase);") -(FINALIZATION " free(susp->buffer); -") +(INNER-LOOP "phase = vardelay * vdscale + offset; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay) phase = maxdelay; + phase = (double) index - phase; + /* now phase is a location in the buffer (before modulo) */ + + /* Time out to update the buffer: + * this is a tricky buffer: buffer[0] == buffer[bufflen] + * the logical length is bufflen, but the actual length + * is bufflen + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer[index++] = s1; + if (index > bufflen) { + buffer[0] = buffer[bufflen]; + index = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + output = (sample_type) (buffer[i] * (1.0 - phase) + + buffer[i + 1] * phase)") +(FINALIZATION " free(susp->buffer);\n") ) diff --git a/lib-src/libnyquist/nyquist/tran/tapv.c b/lib-src/libnyquist/nyquist/tran/tapv.c index c7e555c19..bb83d7721 100644 --- a/lib-src/libnyquist/nyquist/tran/tapv.c +++ b/lib-src/libnyquist/nyquist/tran/tapv.c @@ -9,7 +9,7 @@ #include "cext.h" #include "tapv.h" -void tapv_free(); +void tapv_free(snd_susp_type a_susp); typedef struct tapv_susp_struct { @@ -42,8 +42,473 @@ typedef struct tapv_susp_struct { } tapv_susp_node, *tapv_susp_type; -void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list) +void tapv_nn_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapv_susp_type susp = (tapv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register double maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register sample_block_values_type vardelay_ptr_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapv_nn_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past the vardelay input sample block: */ + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + togo = min(togo, susp->vardelay_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + vardelay_ptr_reg = susp->vardelay_ptr; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + double phase; + long i; + phase = *vardelay_ptr_reg++ * vdscale_reg + offset_reg; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); + } while (--n); /* inner loop */ + + susp->bufflen = bufflen_reg; + susp->index = index_reg; + /* using vardelay_ptr_reg is a bad idea on RS/6000: */ + susp->vardelay_ptr += togo; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp_took(vardelay_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapv_nn_fetch */ + + +void tapv_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapv_susp_type susp = (tapv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type vardelay_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register double maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register double vardelay_pHaSe_iNcR_rEg = susp->vardelay_pHaSe_iNcR; + register double vardelay_pHaSe_ReG; + register sample_type vardelay_x1_sample_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapv_ni_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + susp->vardelay_x1_sample = (susp->vardelay_cnt--, *(susp->vardelay_ptr)); + } + + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + vardelay_pHaSe_ReG = susp->vardelay_pHaSe; + vardelay_x1_sample_reg = susp->vardelay_x1_sample; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + double phase; + long i; + if (vardelay_pHaSe_ReG >= 1.0) { + vardelay_x1_sample_reg = vardelay_x2_sample; + /* pick up next sample as vardelay_x2_sample: */ + susp->vardelay_ptr++; + susp_took(vardelay_cnt, 1); + vardelay_pHaSe_ReG -= 1.0; + susp_check_term_samples_break(vardelay, vardelay_ptr, vardelay_cnt, vardelay_x2_sample); + } + phase = + (vardelay_x1_sample_reg * (1 - vardelay_pHaSe_ReG) + vardelay_x2_sample * vardelay_pHaSe_ReG) * vdscale_reg + offset_reg; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); + vardelay_pHaSe_ReG += vardelay_pHaSe_iNcR_rEg; + } while (--n); /* inner loop */ + + togo -= n; + susp->bufflen = bufflen_reg; + susp->index = index_reg; + susp->vardelay_pHaSe = vardelay_pHaSe_ReG; + susp->vardelay_x1_sample = vardelay_x1_sample_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapv_ni_fetch */ + + +void tapv_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapv_susp_type susp = (tapv_susp_type) a_susp; + int cnt = 0; /* how many samples computed */ + sample_type vardelay_DeLtA; + sample_type vardelay_val; + sample_type vardelay_x2_sample; + int togo; + int n; + sample_block_type out; + register sample_block_values_type out_ptr; + + register sample_block_values_type out_ptr_reg; + + register double offset_reg; + register double vdscale_reg; + register double maxdelay_reg; + register long bufflen_reg; + register long index_reg; + register sample_type * buffer_reg; + register sample_block_values_type s1_ptr_reg; + falloc_sample_block(out, "tapv_nr_fetch"); + out_ptr = out->samples; + snd_list->block = out; + + /* make sure sounds are primed with first values */ + if (!susp->started) { + susp->started = true; + susp->vardelay_pHaSe = 1.0; + } + + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + + while (cnt < max_sample_block_len) { /* outer loop */ + /* first compute how many samples to generate in inner loop: */ + /* don't overflow the output sample block: */ + togo = max_sample_block_len - cnt; + + /* don't run past the s1 input sample block: */ + susp_check_term_log_samples(s1, s1_ptr, s1_cnt); + togo = min(togo, susp->s1_cnt); + + /* grab next vardelay_x2_sample when phase goes past 1.0; */ + /* we use vardelay_n (computed below) to avoid roundoff errors: */ + if (susp->vardelay_n <= 0) { + susp->vardelay_x1_sample = vardelay_x2_sample; + susp->vardelay_ptr++; + susp_took(vardelay_cnt, 1); + susp->vardelay_pHaSe -= 1.0; + susp_check_term_samples(vardelay, vardelay_ptr, vardelay_cnt); + vardelay_x2_sample = *(susp->vardelay_ptr); + /* vardelay_n gets number of samples before phase exceeds 1.0: */ + susp->vardelay_n = (long) ((1.0 - susp->vardelay_pHaSe) * + susp->output_per_vardelay); + } + togo = min(togo, susp->vardelay_n); + vardelay_DeLtA = (sample_type) ((vardelay_x2_sample - susp->vardelay_x1_sample) * susp->vardelay_pHaSe_iNcR); + vardelay_val = (sample_type) (susp->vardelay_x1_sample * (1.0 - susp->vardelay_pHaSe) + + vardelay_x2_sample * susp->vardelay_pHaSe); + + /* don't run past terminate time */ + if (susp->terminate_cnt != UNKNOWN && + susp->terminate_cnt <= susp->susp.current + cnt + togo) { + togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ + if (togo == 0) break; + } + + + /* don't run past logical stop time */ + if (!susp->logically_stopped && susp->susp.log_stop_cnt != UNKNOWN) { + int to_stop = susp->susp.log_stop_cnt - (susp->susp.current + cnt); + /* break if to_stop == 0 (we're at the logical stop) + * AND cnt > 0 (we're not at the beginning of the + * output block). + */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ + if (to_stop < togo) { + if (to_stop == 0) { + if (cnt) { + togo = 0; + break; + } else /* keep togo as is: since cnt == 0, we + * can set the logical stop flag on this + * output block + */ + susp->logically_stopped = true; + } else /* limit togo so we can start a new + * block at the LST + */ + togo = to_stop; + } + } + + n = togo; + offset_reg = susp->offset; + vdscale_reg = susp->vdscale; + maxdelay_reg = susp->maxdelay; + bufflen_reg = susp->bufflen; + index_reg = susp->index; + buffer_reg = susp->buffer; + s1_ptr_reg = susp->s1_ptr; + out_ptr_reg = out_ptr; + if (n) do { /* the inner sample computation loop */ + double phase; + long i; + phase = vardelay_val * vdscale_reg + offset_reg; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = *s1_ptr_reg++; + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); + vardelay_val += vardelay_DeLtA; + } while (--n); /* inner loop */ + + susp->bufflen = bufflen_reg; + susp->index = index_reg; + /* using s1_ptr_reg is a bad idea on RS/6000: */ + susp->s1_ptr += togo; + out_ptr += togo; + susp_took(s1_cnt, togo); + susp->vardelay_pHaSe += togo * susp->vardelay_pHaSe_iNcR; + susp->vardelay_n -= togo; + cnt += togo; + } /* outer loop */ + + /* test for termination */ + if (togo == 0 && cnt == 0) { + snd_list_terminate(snd_list); + } else { + snd_list->block_len = cnt; + susp->susp.current += cnt; + } + /* test for logical stop */ + if (susp->logically_stopped) { + snd_list->logically_stopped = true; + } else if (susp->susp.log_stop_cnt == susp->susp.current) { + susp->logically_stopped = true; + } +} /* tapv_nr_fetch */ + + +void tapv_sn_fetch(snd_susp_type a_susp, snd_list_type snd_list) +{ + tapv_susp_type susp = (tapv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -82,6 +547,7 @@ void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -93,6 +559,7 @@ void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -123,33 +590,33 @@ void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list) if (n) do { /* the inner sample computation loop */ double phase; long i; - phase = *vardelay_ptr_reg++ * vdscale_reg + offset_reg; - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = (double) index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg > bufflen_reg) { - buffer_reg[0] = buffer_reg[bufflen_reg]; - index_reg = 1; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - i = (long) phase; /* put integer part in i */ - phase -= (double) i; /* put fractional part in phase */ - *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + - buffer_reg[i + 1] * phase);; + phase = *vardelay_ptr_reg++ * vdscale_reg + offset_reg; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); } while (--n); /* inner loop */ susp->bufflen = bufflen_reg; @@ -180,8 +647,9 @@ void tapv_sn_fetch(register tapv_susp_type susp, snd_list_type snd_list) } /* tapv_sn_fetch */ -void tapv_si_fetch(register tapv_susp_type susp, snd_list_type snd_list) +void tapv_si_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapv_susp_type susp = (tapv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type vardelay_x2_sample; int togo; @@ -229,6 +697,7 @@ void tapv_si_fetch(register tapv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -240,6 +709,7 @@ void tapv_si_fetch(register tapv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -279,34 +749,34 @@ void tapv_si_fetch(register tapv_susp_type susp, snd_list_type snd_list) vardelay_pHaSe_ReG -= 1.0; susp_check_term_samples_break(vardelay, vardelay_ptr, vardelay_cnt, vardelay_x2_sample); } - phase = + phase = (vardelay_x1_sample_reg * (1 - vardelay_pHaSe_ReG) + vardelay_x2_sample * vardelay_pHaSe_ReG) * vdscale_reg + offset_reg; - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = (double) index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg > bufflen_reg) { - buffer_reg[0] = buffer_reg[bufflen_reg]; - index_reg = 1; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - i = (long) phase; /* put integer part in i */ - phase -= (double) i; /* put fractional part in phase */ - *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + - buffer_reg[i + 1] * phase);; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); vardelay_pHaSe_ReG += vardelay_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -338,8 +808,9 @@ void tapv_si_fetch(register tapv_susp_type susp, snd_list_type snd_list) } /* tapv_si_fetch */ -void tapv_sr_fetch(register tapv_susp_type susp, snd_list_type snd_list) +void tapv_sr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tapv_susp_type susp = (tapv_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type vardelay_DeLtA; sample_type vardelay_val; @@ -403,6 +874,7 @@ void tapv_sr_fetch(register tapv_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -414,6 +886,7 @@ void tapv_sr_fetch(register tapv_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -443,33 +916,33 @@ void tapv_sr_fetch(register tapv_susp_type susp, snd_list_type snd_list) if (n) do { /* the inner sample computation loop */ double phase; long i; - phase = vardelay_val * vdscale_reg + offset_reg; - /* now phase should give number of samples of delay */ - if (phase < 0) phase = 0; - else if (phase > maxdelay_reg) phase = maxdelay_reg; - phase = (double) index_reg - phase; - /* now phase is a location in the buffer_reg (before modulo) */ - - /* Time out to update the buffer_reg: - * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] - * the logical length is bufflen_reg, but the actual length - * is bufflen_reg + 1 to allow for a repeated sample at the - * end. This allows for efficient interpolation. - */ - buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); - if (index_reg > bufflen_reg) { - buffer_reg[0] = buffer_reg[bufflen_reg]; - index_reg = 1; - } - - /* back to the phase calculation: - * use conditional instead of modulo - */ - if (phase < 0) phase += bufflen_reg; - i = (long) phase; /* put integer part in i */ - phase -= (double) i; /* put fractional part in phase */ - *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + - buffer_reg[i + 1] * phase);; + phase = vardelay_val * vdscale_reg + offset_reg; + /* now phase should give number of samples of delay */ + if (phase < 0) phase = 0; + else if (phase > maxdelay_reg) phase = maxdelay_reg; + phase = (double) index_reg - phase; + /* now phase is a location in the buffer_reg (before modulo) */ + + /* Time out to update the buffer_reg: + * this is a tricky buffer_reg: buffer_reg[0] == buffer_reg[bufflen_reg] + * the logical length is bufflen_reg, but the actual length + * is bufflen_reg + 1 to allow for a repeated sample at the + * end. This allows for efficient interpolation. + */ + buffer_reg[index_reg++] = (s1_scale_reg * *s1_ptr_reg++); + if (index_reg > bufflen_reg) { + buffer_reg[0] = buffer_reg[bufflen_reg]; + index_reg = 1; + } + + /* back to the phase calculation: + * use conditional instead of modulo + */ + if (phase < 0) phase += bufflen_reg; + i = (long) phase; /* put integer part in i */ + phase -= (double) i; /* put fractional part in phase */ + *out_ptr_reg++ = (sample_type) (buffer_reg[i] * (1.0 - phase) + + buffer_reg[i + 1] * phase); vardelay_val += vardelay_DeLtA; } while (--n); /* inner loop */ @@ -500,11 +973,9 @@ void tapv_sr_fetch(register tapv_susp_type susp, snd_list_type snd_list) } /* tapv_sr_fetch */ -void tapv_toss_fetch(susp, snd_list) - register tapv_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void tapv_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + tapv_susp_type susp = (tapv_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -527,19 +998,21 @@ void tapv_toss_fetch(susp, snd_list) susp->vardelay_ptr += n; susp_took(vardelay_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void tapv_mark(tapv_susp_type susp) +void tapv_mark(snd_susp_type a_susp) { + tapv_susp_type susp = (tapv_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->vardelay); } -void tapv_free(tapv_susp_type susp) +void tapv_free(snd_susp_type a_susp) { + tapv_susp_type susp = (tapv_susp_type) a_susp; free(susp->buffer); sound_unref(susp->s1); sound_unref(susp->vardelay); @@ -547,8 +1020,9 @@ void tapv_free(tapv_susp_type susp) } -void tapv_print_tree(tapv_susp_type susp, int n) +void tapv_print_tree(snd_susp_type a_susp, int n) { + tapv_susp_type susp = (tapv_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -575,17 +1049,23 @@ sound_type snd_make_tapv(sound_type s1, double offset, sound_type vardelay, doub susp->index = susp->bufflen; susp->buffer = (sample_type *) calloc(susp->bufflen + 1, sizeof(sample_type)); + /* make sure no sample rate is too high */ + if (vardelay->sr > sr) { + sound_unref(vardelay); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(vardelay, sr); switch (interp_desc) { case INTERP_ns: /* handled below */ - case INTERP_nn: /* handled below */ + case INTERP_nn: susp->susp.fetch = tapv_nn_fetch; break; + case INTERP_ni: susp->susp.fetch = tapv_ni_fetch; break; + case INTERP_nr: susp->susp.fetch = tapv_nr_fetch; break; case INTERP_ss: /* handled below */ case INTERP_sn: susp->susp.fetch = tapv_sn_fetch; break; - case INTERP_ni: /* handled below */ case INTERP_si: susp->susp.fetch = tapv_si_fetch; break; - case INTERP_nr: /* handled below */ case INTERP_sr: susp->susp.fetch = tapv_sr_fetch; break; default: snd_badsr(); break; } @@ -599,8 +1079,8 @@ sound_type snd_make_tapv(sound_type s1, double offset, sound_type vardelay, doub /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = tapv_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = tapv_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/tone.c b/lib-src/libnyquist/nyquist/tran/tone.c index a4c2e04e5..2dd094e44 100644 --- a/lib-src/libnyquist/nyquist/tran/tone.c +++ b/lib-src/libnyquist/nyquist/tran/tone.c @@ -9,7 +9,7 @@ #include "cext.h" #include "tone.h" -void tone_free(); +void tone_free(snd_susp_type a_susp); typedef struct tone_susp_struct { @@ -26,8 +26,9 @@ typedef struct tone_susp_struct { } tone_susp_node, *tone_susp_type; -void tone_n_fetch(register tone_susp_type susp, snd_list_type snd_list) +void tone_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tone_susp_type susp = (tone_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -57,6 +58,7 @@ void tone_n_fetch(register tone_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -68,6 +70,7 @@ void tone_n_fetch(register tone_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -92,7 +95,7 @@ void tone_n_fetch(register tone_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) (prev_reg = c1_reg * *input_ptr_reg++ + c2_reg * prev_reg); + *out_ptr_reg++ = (sample_type) (prev_reg = c1_reg * *input_ptr_reg++ + c2_reg * prev_reg); } while (--n); /* inner loop */ susp->prev = prev_reg; @@ -119,11 +122,9 @@ void tone_n_fetch(register tone_susp_type susp, snd_list_type snd_list) } /* tone_n_fetch */ -void tone_toss_fetch(susp, snd_list) - register tone_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void tone_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + tone_susp_type susp = (tone_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -138,25 +139,28 @@ void tone_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void tone_mark(tone_susp_type susp) +void tone_mark(snd_susp_type a_susp) { + tone_susp_type susp = (tone_susp_type) a_susp; sound_xlmark(susp->input); } -void tone_free(tone_susp_type susp) +void tone_free(snd_susp_type a_susp) { + tone_susp_type susp = (tone_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(tone_susp_node), "tone_free"); } -void tone_print_tree(tone_susp_type susp, int n) +void tone_print_tree(snd_susp_type a_susp, int n) { + tone_susp_type susp = (tone_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -169,7 +173,6 @@ sound_type snd_make_tone(sound_type input, double hz) double b; rate_type sr = input->sr; time_type t0 = input->t0; - int interp_desc = 0; sample_type scale_factor = 1.0F; time_type t0_min = t0; falloc_generic(susp, tone_susp_node, "snd_make_tone"); @@ -186,8 +189,8 @@ sound_type snd_make_tone(sound_type input, double hz) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = tone_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = tone_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/tonev.alg b/lib-src/libnyquist/nyquist/tran/tonev.alg index c7ba37e65..b0e5122ce 100644 --- a/lib-src/libnyquist/nyquist/tran/tonev.alg +++ b/lib-src/libnyquist/nyquist/tran/tonev.alg @@ -1,7 +1,6 @@ (TONEV-ALG (NAME "tonev") (ARGUMENTS ("sound_type" "s1") ("sound_type" "hz")) -(INLINE-INTERPOLATION T) (INTERNAL-SCALING s1) (ALWAYS-SCALE hz) (START (MAX s1 hz)) @@ -19,6 +18,6 @@ ("c1" "hz" "(1.0 - c2) * scale1")) (CONSTANT "c1" "c2" "b" "scale1") (FORCE-INTO-REGISTER scale1) -(INNER-LOOP " output = (sample_type) (prev = c1 * s1 + c2 * prev)") +(INNER-LOOP "output = (sample_type) (prev = c1 * s1 + c2 * prev)") ) diff --git a/lib-src/libnyquist/nyquist/tran/tonev.c b/lib-src/libnyquist/nyquist/tran/tonev.c index 689d322bc..990fab16a 100644 --- a/lib-src/libnyquist/nyquist/tran/tonev.c +++ b/lib-src/libnyquist/nyquist/tran/tonev.c @@ -9,7 +9,7 @@ #include "cext.h" #include "tonev.h" -void tonev_free(); +void tonev_free(snd_susp_type a_susp); typedef struct tonev_susp_struct { @@ -40,8 +40,9 @@ typedef struct tonev_susp_struct { } tonev_susp_node, *tonev_susp_type; -void tonev_ns_fetch(register tonev_susp_type susp, snd_list_type snd_list) +void tonev_ns_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tonev_susp_type susp = (tonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -78,6 +79,7 @@ void tonev_ns_fetch(register tonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -89,6 +91,7 @@ void tonev_ns_fetch(register tonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -149,8 +152,9 @@ void tonev_ns_fetch(register tonev_susp_type susp, snd_list_type snd_list) } /* tonev_ns_fetch */ -void tonev_ni_fetch(register tonev_susp_type susp, snd_list_type snd_list) +void tonev_ni_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tonev_susp_type susp = (tonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -195,6 +199,7 @@ void tonev_ni_fetch(register tonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -206,6 +211,7 @@ void tonev_ni_fetch(register tonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -243,8 +249,8 @@ void tonev_ni_fetch(register tonev_susp_type susp, snd_list_type snd_list) susp_check_term_samples_break(hz, hz_ptr, hz_cnt, hz_x1_sample_reg); hz_x1_sample_reg = susp_current_sample(hz, hz_ptr); b = 2.0 - cos(hz_x1_sample_reg); - c2_reg = susp->c2 = b - sqrt((b * b) - 1.0); - c1_reg = susp->c1 = (1.0 - c2_reg) * scale1_reg; + c2_reg = b - sqrt((b * b) - 1.0); + c1_reg = (1.0 - c2_reg) * scale1_reg; } *out_ptr_reg++ = (sample_type) (prev_reg = c1_reg * *s1_ptr_reg++ + c2_reg * prev_reg); hz_pHaSe_ReG += hz_pHaSe_iNcR_rEg; @@ -277,8 +283,9 @@ void tonev_ni_fetch(register tonev_susp_type susp, snd_list_type snd_list) } /* tonev_ni_fetch */ -void tonev_nr_fetch(register tonev_susp_type susp, snd_list_type snd_list) +void tonev_nr_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + tonev_susp_type susp = (tonev_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type hz_val; int togo; @@ -334,6 +341,7 @@ void tonev_nr_fetch(register tonev_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -345,6 +353,7 @@ void tonev_nr_fetch(register tonev_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -399,11 +408,9 @@ void tonev_nr_fetch(register tonev_susp_type susp, snd_list_type snd_list) } /* tonev_nr_fetch */ -void tonev_toss_fetch(susp, snd_list) - register tonev_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void tonev_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + tonev_susp_type susp = (tonev_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -426,27 +433,30 @@ void tonev_toss_fetch(susp, snd_list) susp->hz_ptr += n; susp_took(hz_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void tonev_mark(tonev_susp_type susp) +void tonev_mark(snd_susp_type a_susp) { + tonev_susp_type susp = (tonev_susp_type) a_susp; sound_xlmark(susp->s1); sound_xlmark(susp->hz); } -void tonev_free(tonev_susp_type susp) +void tonev_free(snd_susp_type a_susp) { + tonev_susp_type susp = (tonev_susp_type) a_susp; sound_unref(susp->s1); sound_unref(susp->hz); ffree_generic(susp, sizeof(tonev_susp_node), "tonev_free"); } -void tonev_print_tree(tonev_susp_type susp, int n) +void tonev_print_tree(snd_susp_type a_susp, int n) { + tonev_susp_type susp = (tonev_susp_type) a_susp; indent(n); stdputstr("s1:"); sound_print_tree_1(susp->s1, n); @@ -472,6 +482,12 @@ sound_type snd_make_tonev(sound_type s1, sound_type hz) susp->prev = 0.0; hz->scale = (sample_type) (hz->scale * (PI2 / s1->sr)); + /* make sure no sample rate is too high */ + if (hz->sr > sr) { + sound_unref(hz); + snd_badsr(); + } + /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(s1, sr); interp_desc = (interp_desc << 2) + interp_style(hz, sr); @@ -496,8 +512,8 @@ sound_type snd_make_tonev(sound_type s1, sound_type hz) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = tonev_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = tonev_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/translate-stk.lsp b/lib-src/libnyquist/nyquist/tran/translate-stk.lsp deleted file mode 100644 index 15bf23aa6..000000000 --- a/lib-src/libnyquist/nyquist/tran/translate-stk.lsp +++ /dev/null @@ -1,13 +0,0 @@ -(translate "stkrev") -(translate "stkpitshift") -(translate "stkchorus") -(translate "instrbow") -(translate "instrbowedfreq") -(translate "instrbanded") -(translate "instrmandolin") -(translate "instrsitar") -(translate "instrmodalbar") -(translate "instrflute") -(translate "instrflutefreq") -(translate "instrfluteall") - diff --git a/lib-src/libnyquist/nyquist/tran/translate.lsp b/lib-src/libnyquist/nyquist/tran/translate.lsp index 2fc81b7bd..00ed4b51a 100644 --- a/lib-src/libnyquist/nyquist/tran/translate.lsp +++ b/lib-src/libnyquist/nyquist/tran/translate.lsp @@ -48,6 +48,7 @@ (defun mb () (translate "buzz")) (defun mal () (translate "alpass")) (defun macv () (translate "alpasscv")) +(defun mavc () (translate "alpassvc")) (defun mavv () (translate "alpassvv")) (defun mf () (translate "follow")) (defun mfas () (translate "fromarraystream")) @@ -111,26 +112,41 @@ (defun mpl () (translate "pluck")) (defun icl () (translate "instrclar")) (defun isx () (translate "instrsax")) +(defun ifl () (translate "instrflute")) (defun icla () (translate "instrclarall")) (defun isxa () (translate "instrsaxall")) +(defun ifla () (translate "instrfluteall")) (defun iclf () (translate "instrclarfreq")) (defun isxf () (translate "instrsaxfreq")) +(defun iflf () (translate "instrflutefreq")) (defun mla () (translate "allpoles")) (defun mlr () (translate "lpreson")) +(defun ibf () (translate "instrbowedfreq")) +(defun mib () (translate "instrbow")) +(defun mps () (translate "stkpitshift")) +(defun mcho () (translate "stkchorus")) +(defun mrv () (translate "stkrev")) +(defun mbd () (translate "instrbanded")) +(defun mmd () (translate "instrmandolin")) +(defun mst () (translate "instrsitar")) +(defun mmb () (translate "instrmodalbar")) + -(defun mstk () (icl) (isx) (icla) (isxa) (iclf) (isxf)) +(defun mstk () (icl) (isx) (ifl) (icla) (isxa) (ifla) (iclf) (isxf) (iflf) + (ibf) (mib) (mps) (mcho) (mrv) (mbd) (mmd) (mst) (mmb)) (defun mfmfb () (translate "fmfb") (translate "fmfbv")) (defun m () (mf) (mp) (mc) (mcl) (mg) ;;;;;; (mr) (msfr) (md) + (meqb) (mm) (ms) (msh) (mpw) (ma) (mb) (mde) (mdcv) (mi) (mu) (ml) (mlo) (mo) (mof) (mam) (mfm) (mw) (msl) (mt) (mat) (mre) (mrec) - (mar) (mtv) (mta) (mtf) (matv) (mrvc) (mrcv) (marvc) (marcv) - (mrvv) (marvv) (me) (msa) (msio) (mq) (mcg) (mifft) - (mfas) (mfo) (mct) (mal) (mos) (mch) (mbq) (mpl) - (mabs) (msqrt) (macv) (mavv) ; (mcv) must be managed by hand - (mstk) (mla) (mlr) (load "translate-stk") (mfmfb)) + (mar) (mtv) (mta) (mtf) (matv) (mrvc) (mrcv) (marvc) (marcv) + (mrvv) (marvv) (me) (msa) (msio) (mq) (mcg) (mifft) + (mfas) (mfo) (mct) (mal) (mos) (mch) (mbq) (mpl) + (mabs) (msqrt) (macv) (mavc) (mavv) ; (mcv) must be managed by hand + (mstk) (mla) (mlr) (mfmfb)) ; call this when you change writesusp.lsp: "N"ew "S"usp (defun ns () (ls) (m)) @@ -195,7 +211,7 @@ "#ifndef mips\n" "#include \"stdlib.h\"\n" "#endif\n" - "#include \"xlisp.h\"\n" + "#include \"xlisp.h\"\n" "#include \"sound.h\"\n\n" "#include \"falloc.h\"\n" "#include \"cext.h\"\n" @@ -239,7 +255,7 @@ (print-strings header-list stream) (format stream "#include \"~A\"~%" (get-slot alg 'hfile)) (display "code-gen: printed header") - (format stream "~%void ~A_free();~%" name) + (format stream "~%void ~A_free(snd_susp_type a_susp);~%" name) (setf interpolation-list (make-interpolation-list alg)) (display "code-gen: " interpolation-list) (put-slot alg interpolation-list 'interpolation-list) @@ -377,10 +393,12 @@ ;; (unless the algorithm is the up-sample algorithm, a special case ;; (defun interp-check (alg spec) - (or *INLINE-INTERPOLATION* - (get alg 'inline-interpolation) - (and (not (member 'INTERP spec)) - (not (member 'RAMP spec))))) + (let ((ili *INLINE-INTERPOLATION*) + (ili-spec (get alg 'inline-interpolation))) + (if ili-spec (setf ili t)) + (if (eq ili-spec 'no) (setf ili nil)) + (or ili (and (not (member 'INTERP spec)) + (not (member 'RAMP spec)))))) (print 'interp-check) @@ -661,19 +679,21 @@ (defun sr-check (alg spec) (let ((sample-rate (get-slot alg 'sample-rate)) (sound-args (get-slot alg 'sound-args)) - (result t)) + (result nil)) ;; if expression given, then anything is ok - (cond ((stringp sample-rate) t) - ;; if (MAX ...) expression given, then one of signals must be NONE or SCALE - ((and (listp sample-rate) (eq (car sample-rate) 'MAX)) - (dolist (sig (cdr sample-rate)) ; for all sig in max list ... - (cond ((not (spec-is-none-or-scale sig sound-args spec)) - (setf result nil)))) - result) - ;; if no expression given, then one signal must be NONE or SCALE - ((or (member 'NONE spec) (member 'SCALE spec)) t) - ;; o.w. return false - (t nil)))) + (cond ((stringp sample-rate) + t) + ;; if (MAX ...) expression given, then one of signals + ;; must be NONE or SCALE + ((and (listp sample-rate) (eq (car sample-rate) 'MAX)) + (dolist (sig (cdr sample-rate)) ; for all sig in max list ... + (cond ((spec-is-none-or-scale sig sound-args spec) + (setf result t)))) + result) + ;; if no expression given, then one signal must be NONE or SCALE + ((or (member 'NONE spec) (member 'SCALE spec)) t) + ;; o.w. return false + (t nil)))) ;;**************** diff --git a/lib-src/libnyquist/nyquist/tran/upsample.alg b/lib-src/libnyquist/nyquist/tran/upsample.alg index 82aaca3cd..d066805bb 100644 --- a/lib-src/libnyquist/nyquist/tran/upsample.alg +++ b/lib-src/libnyquist/nyquist/tran/upsample.alg @@ -8,11 +8,4 @@ (LINEAR input) (TERMINATE (MIN input)) (LOGICAL-STOP (MIN input)) - (TYPE-CHECK -" if (input->sr > sr) { - sound_unref(input); - xlfail(\"snd-up: output sample rate must be higher than input\"); - } -") ) - diff --git a/lib-src/libnyquist/nyquist/tran/upsample.c b/lib-src/libnyquist/nyquist/tran/upsample.c index a83c678ba..370735312 100644 --- a/lib-src/libnyquist/nyquist/tran/upsample.c +++ b/lib-src/libnyquist/nyquist/tran/upsample.c @@ -9,7 +9,7 @@ #include "cext.h" #include "upsample.h" -void up_free(); +void up_free(snd_susp_type a_susp); typedef struct up_susp_struct { @@ -32,8 +32,9 @@ typedef struct up_susp_struct { } up_susp_node, *up_susp_type; -void up_n_fetch(register up_susp_type susp, snd_list_type snd_list) +void up_n_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + up_susp_type susp = (up_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -60,6 +61,7 @@ void up_n_fetch(register up_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -71,6 +73,7 @@ void up_n_fetch(register up_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -92,7 +95,7 @@ void up_n_fetch(register up_susp_type susp, snd_list_type snd_list) input_ptr_reg = susp->input_ptr; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) *input_ptr_reg++; + *out_ptr_reg++ = (sample_type) *input_ptr_reg++; } while (--n); /* inner loop */ /* using input_ptr_reg is a bad idea on RS/6000: */ @@ -118,8 +121,9 @@ void up_n_fetch(register up_susp_type susp, snd_list_type snd_list) } /* up_n_fetch */ -void up_i_fetch(register up_susp_type susp, snd_list_type snd_list) +void up_i_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + up_susp_type susp = (up_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type input_x2_sample; int togo; @@ -155,6 +159,7 @@ void up_i_fetch(register up_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -166,6 +171,7 @@ void up_i_fetch(register up_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -196,7 +202,7 @@ void up_i_fetch(register up_susp_type susp, snd_list_type snd_list) input_pHaSe_ReG -= 1.0; susp_check_term_log_samples_break(input, input_ptr, input_cnt, input_x2_sample); } -*out_ptr_reg++ = (sample_type) + *out_ptr_reg++ = (sample_type) (input_x1_sample_reg * (1 - input_pHaSe_ReG) + input_x2_sample * input_pHaSe_ReG); input_pHaSe_ReG += input_pHaSe_iNcR_rEg; } while (--n); /* inner loop */ @@ -224,8 +230,9 @@ void up_i_fetch(register up_susp_type susp, snd_list_type snd_list) } /* up_i_fetch */ -void up_r_fetch(register up_susp_type susp, snd_list_type snd_list) +void up_r_fetch(snd_susp_type a_susp, snd_list_type snd_list) { + up_susp_type susp = (up_susp_type) a_susp; int cnt = 0; /* how many samples computed */ sample_type input_DeLtA; sample_type input_val; @@ -277,6 +284,7 @@ void up_r_fetch(register up_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } @@ -288,6 +296,7 @@ void up_r_fetch(register up_susp_type susp, snd_list_type snd_list) * AND cnt > 0 (we're not at the beginning of the * output block). */ + if (to_stop < 0) to_stop = 0; /* avoids rounding errors */ if (to_stop < togo) { if (to_stop == 0) { if (cnt) { @@ -308,7 +317,7 @@ void up_r_fetch(register up_susp_type susp, snd_list_type snd_list) n = togo; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) input_val; + *out_ptr_reg++ = (sample_type) input_val; input_val += input_DeLtA; } while (--n); /* inner loop */ @@ -334,11 +343,9 @@ void up_r_fetch(register up_susp_type susp, snd_list_type snd_list) } /* up_r_fetch */ -void up_toss_fetch(susp, snd_list) - register up_susp_type susp; - snd_list_type snd_list; -{ - long final_count = susp->susp.toss_cnt; +void up_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + { + up_susp_type susp = (up_susp_type) a_susp; time_type final_time = susp->susp.t0; long n; @@ -353,25 +360,28 @@ void up_toss_fetch(susp, snd_list) susp->input_ptr += n; susp_took(input_cnt, n); susp->susp.fetch = susp->susp.keep_fetch; - (*(susp->susp.fetch))(susp, snd_list); + (*(susp->susp.fetch))(a_susp, snd_list); } -void up_mark(up_susp_type susp) +void up_mark(snd_susp_type a_susp) { + up_susp_type susp = (up_susp_type) a_susp; sound_xlmark(susp->input); } -void up_free(up_susp_type susp) +void up_free(snd_susp_type a_susp) { + up_susp_type susp = (up_susp_type) a_susp; sound_unref(susp->input); ffree_generic(susp, sizeof(up_susp_node), "up_free"); } -void up_print_tree(up_susp_type susp, int n) +void up_print_tree(snd_susp_type a_susp, int n) { + up_susp_type susp = (up_susp_type) a_susp; indent(n); stdputstr("input:"); sound_print_tree_1(susp->input, n); @@ -393,11 +403,13 @@ sound_type snd_make_up(rate_type sr, sound_type input) /* try to push scale_factor back to a low sr input */ if (input->sr < sr) { input->scale = scale_factor; scale_factor = 1.0F; } + falloc_generic(susp, up_susp_node, "snd_make_up"); + + /* make sure no sample rate is too high */ if (input->sr > sr) { sound_unref(input); - xlfail("snd-up: output sample rate must be higher than input"); + snd_badsr(); } - falloc_generic(susp, up_susp_node, "snd_make_up"); /* select a susp fn based on sample rates */ interp_desc = (interp_desc << 2) + interp_style(input, sr); @@ -416,8 +428,8 @@ sound_type snd_make_up(rate_type sr, sound_type input) /* how many samples to toss before t0: */ susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + 0.5); if (susp->susp.toss_cnt > 0) { - susp->susp.keep_fetch = susp->susp.fetch; - susp->susp.fetch = up_toss_fetch; + susp->susp.keep_fetch = susp->susp.fetch; + susp->susp.fetch = up_toss_fetch; } /* initialize susp state */ diff --git a/lib-src/libnyquist/nyquist/tran/white.alg b/lib-src/libnyquist/nyquist/tran/white.alg index 8fc3832b6..7de50b218 100644 --- a/lib-src/libnyquist/nyquist/tran/white.alg +++ b/lib-src/libnyquist/nyquist/tran/white.alg @@ -3,7 +3,7 @@ (ARGUMENTS ("time_type" "t0") ("rate_type" "sr") ("time_type" "d")) (STATE ) (TERMINATE (AFTER "d")) -(INNER-LOOP "output = (sample_type) (rand() * rand_scale - 1.0);") +(INNER-LOOP "output = (sample_type) (rand() * rand_scale - 1.0)") (SAMPLE-RATE "sr") (SUPPORT-HEADER " /* CHANGE LOG diff --git a/lib-src/libnyquist/nyquist/tran/white.c b/lib-src/libnyquist/nyquist/tran/white.c index a411562cf..739450480 100644 --- a/lib-src/libnyquist/nyquist/tran/white.c +++ b/lib-src/libnyquist/nyquist/tran/white.c @@ -9,7 +9,7 @@ #include "cext.h" #include "white.h" -void white_free(); +void white_free(snd_susp_type a_susp); typedef struct white_susp_struct { @@ -18,8 +18,9 @@ typedef struct white_susp_struct { } white_susp_node, *white_susp_type; -void white__fetch(register white_susp_type susp, snd_list_type snd_list) +void white__fetch(snd_susp_type a_susp, snd_list_type snd_list) { + white_susp_type susp = (white_susp_type) a_susp; int cnt = 0; /* how many samples computed */ int togo; int n; @@ -41,13 +42,14 @@ void white__fetch(register white_susp_type susp, snd_list_type snd_list) if (susp->terminate_cnt != UNKNOWN && susp->terminate_cnt <= susp->susp.current + cnt + togo) { togo = susp->terminate_cnt - (susp->susp.current + cnt); + if (togo < 0) togo = 0; /* avoids rounding errros */ if (togo == 0) break; } n = togo; out_ptr_reg = out_ptr; if (n) do { /* the inner sample computation loop */ -*out_ptr_reg++ = (sample_type) (rand() * rand_scale - 1.0);; + *out_ptr_reg++ = (sample_type) (rand() * rand_scale - 1.0); } while (--n); /* inner loop */ out_ptr += togo; @@ -64,13 +66,14 @@ void white__fetch(register white_susp_type susp, snd_list_type snd_list) } /* white__fetch */ -void white_free(white_susp_type susp) +void white_free(snd_susp_type a_susp) { + white_susp_type susp = (white_susp_type) a_susp; ffree_generic(susp, sizeof(white_susp_node), "white_free"); } -void white_print_tree(white_susp_type susp, int n) +void white_print_tree(snd_susp_type a_susp, int n) { } @@ -84,7 +87,7 @@ sound_type snd_make_white(time_type t0, rate_type sr, time_type d) falloc_generic(susp, white_susp_node, "snd_make_white"); susp->susp.fetch = white__fetch; - susp->terminate_cnt = round((d) * sr); + susp->terminate_cnt = check_terminate_cnt(round((d) * sr)); /* initialize susp state */ susp->susp.free = white_free; susp->susp.sr = sr; diff --git a/lib-src/libnyquist/nyquist/tran/writemake.lsp b/lib-src/libnyquist/nyquist/tran/writemake.lsp index 52468c52b..00df735e2 100644 --- a/lib-src/libnyquist/nyquist/tran/writemake.lsp +++ b/lib-src/libnyquist/nyquist/tran/writemake.lsp @@ -101,14 +101,14 @@ (defun check-for-no-interpolation-1 (encoding index interpolation-rationale stream) (cond ((= index (length encoding)) - (display "check-for-no-interpolation output" encoding) + ; (display "check-for-no-interpolation output" encoding) ; see if we need a newline (*cfni-output* is initially nil) (if *cfni-output* (format stream "/* handled below */~%")) (setf *cfni-output* t) (format stream " case INTERP_~A: " encoding)) (t (let ((ch (char encoding index))) - (display "cfni" index ch) + ; (display "cfni" index ch) (cond ((eql ch #\s) (let ((new-encoding (strcat (subseq encoding 0 index) "n" @@ -198,11 +198,14 @@ (sound-names (get-slot alg 'sound-names)) (xlisp-pointers (get-slot alg 'xlisp-pointers))) ;---------------- - ; void NAME_mark(NAME_susp_type susp) + ; void NAME_mark(snd_susp_type a_susp) ; { + ; NAME_susp_type susp = (NAME_susp_type) a_susp; ; *WATCH*: printf("NAME_mark(%x)\n", susp); ;---------------- - (format stream "~%~%void ~A_mark(~A_susp_type susp)~%{~%" name name) + (format stream "~%~%void ~A_mark(snd_susp_type a_susp)~%{~%" name) + (format stream " ~A_susp_type susp = (~A_susp_type) a_susp;~%" + name name) (if *WATCH* (format stream " printf(\"~A_mark(%x)\\n\", susp);~%" name)) @@ -235,6 +238,73 @@ (print 'write-mark) +;; in-set-of-srate-determiners +;; +;; We want to make sure no input has a sample rate higher than the output +;; sample rate. A test is generated, but sometimes the test is not +;; necessary. In particular, if the output sample rate is the max of +;; some input sample rates, we don't have to test those input sample rates. +;; This function tells whether the output sample rate is known to be as +;; high as that of name. This is true when name is an element of a MAX +;; expression in the SAMPLE-RATE property. +;; +;; name is one of sound-names +(defun in-set-of-srate-determiners (name sr) + (display "in-set-of-srate-determiners" name sr) + (or (null sr) ; no SAMPLE-RATE spec, so take max of all sounds + (and (listp sr) (eq (car sr) 'MAX) ; explicit max expression + (member name (cdr sr) :test + #'(lambda (x y) (string-equal x (symbol-to-name y))))))) + + +;;************ +;; out-of-line-interpolation -- determine if input sound should be +;; interpolated using snd_up() unit generator +;; +;; Interpolate out-of-line if inline-interpolation is false either +;; by default or by specification +;; If out-of-line-interpolation is true, then the signal should be +;; either scaled internally or always scaled. Otherwise, we'll generate +;; an extra implementation for scaling (S) vs non-scaling (N) which is +;; a real waste given that we're willing to run a separate unit generator +;; to do up-sampling. Therefore, this will raise an error. +;;************ + +(defun out-of-line-interpolation (alg name) + (let ((ili *INLINE-INTERPOLATION*) + (ili-spec (get alg 'inline-interpolation))) + (if ili-spec (setf ili t)) + (if (eq ili-spec 'no) (setf ili nil)) + ;(display "out-of-line-interpolation" alg ili name + ; (get alg 'ALWAYS-SCALE) (get alg 'INTERNAL-SCALING)) +; (cond ((and (not ili) ;; make sure always scaled in some way +; (not (member name (get alg 'LINEAR) :test +; #'(lambda (x y) (string-equal x (symbol-to-name y))))) +; (not (member name (get alg 'ALWAYS-SCALE) :test +; #'(lambda (x y) (string-equal x (symbol-to-name y))))) +; (not (member name (get alg 'INTERNAL-SCALING) :test +; #'(lambda (x y) (string-equal x (symbol-to-name y)))))) +; (error (format nil "~A is not always scaled" name)))) + (not ili))) + +;; a signal needs out-of-line scaling if out-of-line interpolation is +;; in effect and there is no built-in scaling (ALWAYS-SCALE or +;; INTERNAL-SCALING) +;; +(defun needs-out-of-line-scaling (alg name) + (let ((ili *INLINE-INTERPOLATION*) + (ili-spec (get alg 'inline-interpolation))) + (if ili-spec (setf ili t)) + (if (eq ili-spec 'no) (setf ili nil)) + (and (not ili) + (not (member name (get alg 'LINEAR) :test + #'(lambda (x y) (string-equal x (symbol-to-name y))))) + (not (member name (get alg 'ALWAYS-SCALE) :test + #'(lambda (x y) (string-equal x (symbol-to-name y))))) + (not (member name (get alg 'INTERNAL-SCALING) :test + #'(lambda (x y) (string-equal x (symbol-to-name y)))))))) + + ;;************ ;; write-make ;; @@ -266,10 +336,13 @@ (start (get-slot alg 'start))) ;-------------------- - ; void NAME_free(NAME_susp_type susp) + ; void NAME_free(snd_susp_type a_susp) ; { + ; NAME_susp_type susp = (NAME_susp_type) a_susp; ;---------------- - (format stream "~%~%void ~A_free(~A_susp_type susp)~%{~%" + (format stream "~%~%void ~A_free(snd_susp_type a_susp)~%{~%" + name) + (format stream " ~A_susp_type susp = (~A_susp_type) a_susp;~%" name name) ;---------------- @@ -294,11 +367,15 @@ name name) ;-------------------- - ; void NAME_print_tree(NAME_susp_type susp, int n) + ; void NAME_print_tree(snd_susp_type a_susp, int n) ; { + ; NAME_susp_type susp = (NAME_susp_type) a_susp; ;---------------- - (format stream "~%~%void ~A_print_tree(~A_susp_type susp, int n)~%{~%" + (format stream "~%~%void ~A_print_tree(snd_susp_type a_susp, int n)~%{~%" name name) + (cond (sound-names + (format stream " ~A_susp_type susp = (~A_susp_type) a_susp;~%" + name name))) ;---------------- ; for each sound argument: ; @@ -362,7 +439,7 @@ ;-------------------- ; int interp_desc = 0; ;-------------------- - (cond (interpolation-list + (cond ((< 1 (length interpolation-list)) (format stream " int interp_desc = 0;~%"))) ;-------------------- @@ -437,7 +514,7 @@ ;------------------- ; insert TYPE-CHECK code here ;------------------- - (display "write-make" type-check) + ; (display "write-make" type-check) (if type-check (format stream type-check)) @@ -465,6 +542,49 @@ (format stream " ~A~A = ~A;~%" prefix (cadr state) (caddr state)))) + ;--------------------- + ; /* make sure no sample rate is too high */ + ; if (***->sr > sr) { + ; sound_unref(***); + ; snd_badsr(); + ; } [maybe there will be an else part here] + ;--------------------- + ; where *** is any sound input that is not in the max clause of + ; the SAMPLE-RATE attribute + ; + (setf first-time t) + (dolist (name sound-names) + (let (too-high-test ;; did we test for sr too high (follow with else) + (srate-determiner (in-set-of-srate-determiners name sr))) + (cond ((not srate-determiner) + (cond (first-time + (setf first-time nil) + (format stream + "~% /* make sure no sample rate is too high */~%"))) + (format stream " if (~A->sr > sr) {~%" name) + (format stream " sound_unref(~A);~%" name) + (format stream " snd_badsr();~%" name) + (format stream " }") + (setf too-high-test t) + ;--------------------- + ; Add this if signal needs out-of-line resampling + ; else if (***->sr < sr) *** = snd_make_up(sr, ***); + ;--------------------- + (cond ((out-of-line-interpolation alg name) + (format stream (if too-high-test " else " " ")) + (format stream "if (~A->sr < sr) " name) + (format stream "~A = snd_make_up(sr, ~A);" name name))) + (format stream "~%"))) + ;--------------------- + ; Add this if signal needs out-of-line rescaling + ; if (***->scale != 1.0) *** = snd_make_normalize(***); + ;--------------------- + (cond ((needs-out-of-line-scaling alg name) + (format t "WARNING: out-of-line scaling possible for ~A\n" name) + (format stream " if (~A->scale != 1.0F) " name) + (format stream "~A = snd_make_normalize(~A);~%" name name))))) + + ; (display "write-make select implementation" interpolation-list) ; if we have a choice of implementations, select one (cond ((< 1 (length interpolation-list)) @@ -522,18 +642,18 @@ (cond ((eq (car terminate) 'AT) (let ((time-expr (cadr terminate))) ;---------------- - ; susp->terminate_cnt = round(((TIME-EXPR) - t0) * sr); + ; susp->terminate_cnt = check_terminate_cnt(round(((TIME-EXPR) - t0) * sr)); ;---------------- (format stream - " susp->terminate_cnt = round(((~A) - t0) * sr);~%" + " susp->terminate_cnt = check_terminate_cnt(round(((~A) - t0) * sr));~%" time-expr))) ((eq (car terminate) 'AFTER) (let ((dur-expr (cadr terminate))) ;---------------- - ; susp->terminate_cnt = round((DUR-EXPR) * sr); + ; susp->terminate_cnt = check_terminate_cnt(round((DUR-EXPR) * sr)); ;---------------- (format stream - " susp->terminate_cnt = round((~A) * sr);~%" + " susp->terminate_cnt = check_terminate_cnt(round((~A) * sr));~%" dur-expr))) (t ;---------------- @@ -582,9 +702,9 @@ (format stream " susp->susp.toss_cnt = (long) ((t0 - t0_min) * sr + ~A.5);\n" (if delay delay 0)) (format stream " if (susp->susp.toss_cnt > 0) {\n") - (format stream "\tsusp->susp.keep_fetch = susp->susp.fetch;\n") - (format stream "\tsusp->susp.fetch = ~A_toss_fetch;~%" name) -; (format stream "\tt0 = t0_min;~% }\n\n"))) + (format stream " susp->susp.keep_fetch = susp->susp.fetch;\n") + (format stream " susp->susp.fetch = ~A_toss_fetch;~%" name) +; (format stream " t0 = t0_min;~% }\n\n"))) (format stream " }\n\n"))) ;-------------------- @@ -772,7 +892,7 @@ (defun write-sample-rate (stream sr sound-names arguments) ;; if sr is "sr" and "sr" is a parameter, then do nothing: - (display "write-sample-rate: " sr sound-names arguments) + ; (display "write-sample-rate: " sr sound-names arguments) (cond ( (and (equal sr "sr") (is-argument "sr" arguments)) ;--------------------- @@ -782,7 +902,7 @@ ) ;; else if sample rate is specified, use it to initialize sr: ((stringp sr) - (display "write-sample-rate: using specified sr" sr) + ; (display "write-sample-rate: using specified sr" sr) ;--------------------- ; rate_type sr = ; ;--------------------- @@ -832,7 +952,7 @@ (defun write-start-time (stream start arguments) ;; if t0 is "t0" and "t0" is a parameter, then do nothing: - (display "write-start time:" start arguments) + ; (display "write-start time:" start arguments) (cond ((is-argument "t0" arguments) ;--------------------- ; /* t0 specified as input parameter */ @@ -873,7 +993,7 @@ (defun is-table (alg snd) (dolist (table (get-slot alg 'table)) (cond ((equal snd table) - (display "is-table" snd table) + ; (display "is-table" snd table) (return t))))) diff --git a/lib-src/libnyquist/nyquist/tran/writesusp.lsp b/lib-src/libnyquist/nyquist/tran/writesusp.lsp index 77595f64b..4d5062c87 100644 --- a/lib-src/libnyquist/nyquist/tran/writesusp.lsp +++ b/lib-src/libnyquist/nyquist/tran/writesusp.lsp @@ -121,8 +121,8 @@ (caddr dep) name var-name)))) (t (setf fixup-code - (format nil "~A\t\t~A_reg = susp->~A = ~A;~%" - fixup-code (car dep) (car dep) + (format nil "~A\t\t~A_reg = ~A;~%" + fixup-code (car dep) (fixup-substitutions alg (caddr dep) name var-name)))))))) (put-slot alg fixup-code 'fixup-code))) @@ -346,28 +346,32 @@ ;--------------------------- ; non-ANSI: - ; void NAME__fetch(susp, snd_list) - ; register pwl_susp_type susp; + ; void NAME__fetch(a_susp, snd_list) + ; register pwl_susp_type a_susp; ; snd_list_type snd_list; ; { ; ANSI: - ; void NAME__fetch(register susp_type susp, snd_list_type snd_list) + ; void NAME__fetch(snd_susp_type a_susp, + ; snd_list_type snd_list) ; { ;--------------------------- (setf fn-name (format nil "~A_~A_fetch" name encoding)) (cond (*ANSI* (format stream - "~%~%void ~A(register ~A_susp_type susp, snd_list_type snd_list)~%{~%" - fn-name name)) + "~%~%void ~A(snd_susp_type a_susp, snd_list_type snd_list)~%{~%" + fn-name)) (t (format stream - "~%~%void ~A(susp, snd_list)~% register ~A_susp_type susp;~%~A~%" - fn-name name " snd_list_type snd_list;\n{"))) + "~%~%void ~A(a_susp, snd_list)~% snd_susp_type a_susp;~%~A~%" + fn-name " snd_list_type snd_list;\n{"))) ;----------------------------- + ; NAME_susp_type susp = (NAME_susp_type) a_susp; ; int cnt = 0; /* how many samples computed */ ;----------------------------- + (format stream " ~A_susp_type susp = (~A_susp_type) a_susp;~%" + name name) (format stream " int cnt = 0; /* how many samples computed */~%") (dotimes (n (length interp)) @@ -433,7 +437,8 @@ "\t " stmt "\n")))))) ; this computes some additional declarations - (compute-inner-loop alg (strcat loop-prefix joint-depend inner-loop)) + (compute-inner-loop alg (strcat loop-prefix joint-depend + " " inner-loop)) ; make the declarations (print-strings (get-slot alg 'register-decl) stream) @@ -671,10 +676,10 @@ ; ; /* don't run past terminate time */ ; if (susp->terminate_cnt != UNKNOWN && - ; susp->terminate_cnt <= susp->susp.current) { - ; int to_stop = (susp->terminate_cnt + max_sample_block_len) - - ; (susp->susp.current + cnt); - ; if (to_stop < togo && ((togo = to_stop) == 0)) break; + ; susp->terminate_cnt <= susp->susp.current + cnt + togo) { + ; togo = susp->terminate_cnt - (susp->susp.current + cnt); + ; if (togo < 0) togo = 0; // avoids rounding errors + ; if (togo == 0) break; ; } ;---------------- (cond ((terminate-check-needed terminate alg) @@ -683,6 +688,7 @@ "\tif (susp->terminate_cnt != UNKNOWN &&\n" "\t susp->terminate_cnt <= susp->susp.current + cnt + togo) {\n" "\t togo = susp->terminate_cnt - (susp->susp.current + cnt);\n" + "\t if (togo < 0) togo = 0; /* avoids rounding errros */\n" "\t if (togo == 0) break;\n" "\t}\n\n") stream))) @@ -697,6 +703,7 @@ ; * AND cnt > 0 (we're not at the beginning of the ; * output block). ; */ + ; if (to_stop < 0) to_stop = 0; // avoids rounding errors ; if (to_stop < togo) { ; if (to_stop == 0) { ; if (cnt) { @@ -723,6 +730,7 @@ "\t * AND cnt > 0 (we're not at the beginning of the\n" "\t * output block).\n" "\t */\n" + "\t if (to_stop < 0) to_stop = 0; /* avoids rounding errors */\n" "\t if (to_stop < togo) {\n" "\t\tif (to_stop == 0) {\n" "\t\t if (cnt) {\n" diff --git a/lib-src/libnyquist/nyquist/tran/writetoss.lsp b/lib-src/libnyquist/nyquist/tran/writetoss.lsp index acc8e0a24..dfcb66e8c 100644 --- a/lib-src/libnyquist/nyquist/tran/writetoss.lsp +++ b/lib-src/libnyquist/nyquist/tran/writetoss.lsp @@ -11,19 +11,30 @@ ;; register ALG_susp_type susp; ;; snd_list_type snd_list; ;; { +; (format stream "~%~%void ~A_toss_fetch(susp, snd_list)~%" alg-name) +; (format stream " register ~A_susp_type susp;~%" alg-name) +; (format stream " snd_list_type snd_list;~%{~%") + ;;--------OR------ + ;; void ALG_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list) + ;; { + ;; ALG_susp_type susp = (ALG_susp_type) a_susp; + (format stream + "~%~%void ~A_toss_fetch(snd_susp_type a_susp, snd_list_type snd_list)~%" + alg-name) + (format stream " {~% ~A_susp_type susp = (~A_susp_type) a_susp;~%" + alg-name alg-name) + ;;---------------- ;; long final_count = susp->susp.toss_cnt); ;; time_type final_time = susp->susp.t0; ;; FORMERLY, THIS WAS: ;; time_type final_time = susp->susp.t0 + final_count / susp->susp.sr; ;; long n; ;;---------------- - (format stream "~%~%void ~A_toss_fetch(susp, snd_list)~%" alg-name) - (format stream " register ~A_susp_type susp;~%" alg-name) - (format stream " snd_list_type snd_list;~%{~%") + (if *watch* + (format stream + " long final_count = susp->susp.toss_cnt;~%")) (format stream - " long final_count = susp->susp.toss_cnt;~%") - (format stream -" time_type final_time = susp->susp.t0;~%") + " time_type final_time = susp->susp.t0;~%") (format stream " long n;~%~%") (cond (*watch* @@ -77,9 +88,9 @@ ;;---------------- ;; susp->susp.fetch = susp->susp.keep_fetch; - ;; (*(susp->susp.fetch))(susp, snd_list); + ;; (*(susp->susp.fetch))(a_susp, snd_list); ;; } ;;---------------- (format stream " susp->susp.fetch = susp->susp.keep_fetch;~%") - (format stream " (*(susp->susp.fetch))(susp, snd_list);~%") + (format stream " (*(susp->susp.fetch))(a_susp, snd_list);~%") (format stream "}~%"))) diff --git a/lib-src/libnyquist/nyquist/xlisp/extern.c b/lib-src/libnyquist/nyquist/xlisp/extern.c index 6a4295f41..20d2aaae0 100644 --- a/lib-src/libnyquist/nyquist/xlisp/extern.c +++ b/lib-src/libnyquist/nyquist/xlisp/extern.c @@ -56,11 +56,11 @@ struct xtype_desc_struct desc_table[NTYPES]; /**/ xtype_desc create_desc( char *type_name, /* the type string name */ - void (*fm)(), /* method to free instances of the type */ - void (*pm)(), /* method to print instances of the type */ - void (*sm)(), /* method to save instances of the type */ - unsigned char * (*rm)(), /* method to restore instances of the type */ - void (*mm)()) /* method to mark instances of the type for GC */ + void (*fm)(void*), /* method to free instances of the type */ + void (*pm)(void*, void*), /* method to print instances of the type */ + void (*sm)(FILE*, void*), /* method to save instances of the type */ + unsigned char * (*rm)(FILE*), /* method to restore instances of the type */ + void (*mm)(void*)) /* method to mark instances of the type for GC */ { xtype_desc td; /* the new type descriptor */ if (extindex >= NTYPES) xlfail("insufficient type desc space"); diff --git a/lib-src/libnyquist/nyquist/xlisp/extern.h b/lib-src/libnyquist/nyquist/xlisp/extern.h index 702119038..42fe8366e 100644 --- a/lib-src/libnyquist/nyquist/xlisp/extern.h +++ b/lib-src/libnyquist/nyquist/xlisp/extern.h @@ -1,6 +1,6 @@ -xtype_desc create_desc(char *type_name, void (*fm)(), void (*pm)(), - void (*sm)(), unsigned char * (*rm)(), void (*mm)()); +xtype_desc create_desc(char *type_name, void (*fm)(void*), void (*pm)(void*, void*), + void (*sm)(FILE*, void*), unsigned char * (*rm)(FILE*), void (*mm)(void*)); int exttypep(LVAL x, LVAL type_sym); diff --git a/lib-src/libnyquist/nyquist/xlisp/security.c b/lib-src/libnyquist/nyquist/xlisp/security.c new file mode 100644 index 000000000..8a5c26599 --- /dev/null +++ b/lib-src/libnyquist/nyquist/xlisp/security.c @@ -0,0 +1,172 @@ +/* security.c -- manage access to files and audio */ +/* Roger B. Dannenberg + * July 2014 + */ + +#include +#include +#include +#include + +static void find_full_path(const char *filename, char *fullname); +static int in_tree(const char *fullname, char *secure_read_path); +static int full_name(const char *filename); +static int file_sep(char c); + +/* run_time_limit is a feature to shut down infinite loops + * calls to oscheck are counted. These occur at around 66Hz + * on a 2010 vintage laptop, so a value of 66 is roughly 1 CPU + * second of computation. The rate fluctuates depending on + * the computation, so it is a very rough guide, but then if + * you are restricting CPU time, you'll probably want to pad + * the expected time by a factor of at least 2, so hopefully + * exact numbers are not important. The default is 0, meaning + * no limit. Set the limit from the command line with -L. + * Read the current run time by calling (GET-RUN-TIME) + */ +int run_time_limit = 0; + +/* memory_limit is a feature to shut down rampant memory + * allocation which tends to lead to thrashing on a virtual + * (memory) machine. The number is roughly the number of + * megabytes of sample and cons cell memory that can be + * allocated. The default is 0 which means no limit. + */ +int memory_limit = 0; + +/* run_time is the current run time -- incremented by oscheck() */ +int run_time = 0; + +/* secure_read_path is NULL if reading any file is permitted + * o.w. secure_read_path is a semicolon-separated list of + * paths to directory trees that are readable + */ +char *secure_read_path = NULL; + +/* safe_write_path is NULL if writing any file is permitted + * o.w. safe_write_path is a semicolon-separated list of + * paths to directory tress that are writeable + */ +char *safe_write_path = NULL; + +/* ok_to_open - true if it is OK to open the file under + * the security model implied by secure_read_path + * and safe_write_path + */ +int ok_to_open(const char *filename, const char *mode) +{ + char fullname[STRMAX]; + if (index(mode, 'r')) { /* asking for read permission */ + if (secure_read_path) { /* filename must be in path */ + find_full_path(filename, fullname); + if (!in_tree(fullname, secure_read_path)) return FALSE; + } + } + if (index(mode, 'w')) { /* asking for write permission */ + if (safe_write_path) { /* filename must be in path */ + find_full_path(filename, fullname); + if (!in_tree(fullname, safe_write_path)) return FALSE; + } + } + return TRUE; +} + + +/* find_full_path - find full path corresponding to filename */ +/**/ +void find_full_path(const char *filename, char *fullname) +{ + if (full_name(filename)) { + strncpy(fullname, filename, STRMAX); + fullname[STRMAX - 1] = 0; + return; + } + if (!getcwd(fullname, STRMAX)) { + /* something is really wrong. Pretend we found a + cwd that will not match anything */ + goto error; + } + /* see if we need a separator (probably) */ + int len = strlen(fullname); + if (!file_sep(fullname[len - 1])) { + fullname[len++] = '/'; + if (len >= STRMAX) goto error; + } + /* append filename to fullname */ + strncpy(fullname + len, filename, STRMAX - len); + fullname[STRMAX - 1] = 0; /* just in case of overflow */ + /* if windows, replace \ with / to simplify the rest */ + char *loc = fullname; + if (os_pathchar != '/') { + while ((loc = index(loc, os_pathchar))) { + *loc = '/'; + } + } + /* strip out .. and . */ + while ((loc = strstr(fullname, "/.."))) { + /* back up to separator */ + if (loc == fullname) goto error; + char *loc2 = loc - 1; + while (*loc2 != '/') { + loc2--; + if (loc2 <= fullname) goto error; + } + /* now loc2 points to /parent/.., and loc points to /.. */ + /* copy from beyond /.. to loc2 */ + memmove(loc2, loc, strlen(loc) + 1); + } + return; + error: + strcpy(fullname, "//////"); + return; +} + + +static int file_sep(char c) +{ + return (c == os_pathchar || c == '/'); +} + + +/* full_name - test if filename is a full path */ +/**/ +static int full_name(const char *filename) +{ + if (!filename) return FALSE; + if (filename[0] == os_pathchar) return TRUE; + /* windows allows '/' instead of '\' */ + if (filename[0] == '/') return TRUE; + if (strlen(filename) > 2 && + isalpha(filename[0]) && + filename[1] == ':') return TRUE; + return FALSE; +} + + +static int in_tree(const char *fullname, char *secure_read_path) +{ + /* fullname is in a tree if a path in secure_read_path + is a prefix of fullname + Algorithm: extract each path, check for prefix + */ + char path[STRMAX]; + while (secure_read_path && *secure_read_path) { + /* skip over separator */ + while (*secure_read_path == os_sepchar || + *secure_read_path == ';') secure_read_path++; + /* find next directory and copy into path*/ + path[0] = 0; + int i = 0; + while (*secure_read_path && (*secure_read_path != os_sepchar && + *secure_read_path != ';')) { + path[i++] = *secure_read_path++; + } + path[i] = 0; + /* see if directory is a prefix of fullname */ + if (strstr(fullname, path) == fullname) { + return TRUE; + } + } + return FALSE; +} + diff --git a/lib-src/libnyquist/nyquist/xlisp/xlbfun.c b/lib-src/libnyquist/nyquist/xlisp/xlbfun.c index cfdea508a..21039a96f 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlbfun.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlbfun.c @@ -603,10 +603,7 @@ LVAL xcleanup(void) { xllastarg(); xlcleanup(); - /* this point will never be reached because xlcleanup() does a - longjmp(). The return is added to avoid false positive - error messages from static analyzers and compilers */ - return (NIL); + /* compiler might (wrongly) complain there is no return value */ } /* xtoplevel - special form 'top-level' */ @@ -615,7 +612,7 @@ LVAL xtoplevel(void) xllastarg(); xltoplevel(); /* this point will never be reached because xltoplevel() does a - longjmp(). The return is added to avoid false positive + _longjmp(). The return is added to avoid false positive error messages from static analyzers and compilers */ return (NIL); } @@ -625,7 +622,7 @@ LVAL xcontinue(void) { xllastarg(); xlcontinue(); - return (NIL); + return (NIL); } /* xevalhook - eval hook function */ diff --git a/lib-src/libnyquist/nyquist/xlisp/xlcont.c b/lib-src/libnyquist/nyquist/xlisp/xlcont.c index 1bc1e8fae..6389bd301 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlcont.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlcont.c @@ -651,7 +651,7 @@ LOCAL LVAL prog(int pflag) /* establish a new execution context */ xlbegin(&cntxt,CF_RETURN,NIL); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else { @@ -824,7 +824,7 @@ LVAL xloop(void) /* establish a new execution context */ xlbegin(&cntxt,CF_RETURN,NIL); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else for (argv = xlargv, argc = xlargc; ; xlargv = argv, xlargc = argc) @@ -876,7 +876,7 @@ LOCAL LVAL doloop(int pflag) /* establish a new execution context */ xlbegin(&cntxt,CF_RETURN,NIL); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else { @@ -936,7 +936,7 @@ LVAL xdolist(void) /* establish a new execution context */ xlbegin(&cntxt,CF_RETURN,NIL); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else { @@ -982,13 +982,14 @@ LVAL xdotimes(void) argv = xlargv; argc = xlargc; + /* establish a new execution context */ + xlbegin(&cntxt,CF_RETURN,NIL); + /* initialize the local environment */ xlenv = xlframe(xlenv); xlbind(sym,NIL); - /* establish a new execution context */ - xlbegin(&cntxt,CF_RETURN,NIL); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else { @@ -1030,7 +1031,7 @@ LVAL xblock(void) /* execute the block */ xlbegin(&cntxt,CF_RETURN,name); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; else for (val = NIL; moreargs(); ) @@ -1064,7 +1065,7 @@ LVAL xcatch(void) xlbegin(&cntxt,CF_THROW,tag); /* check for 'throw' */ - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = xlvalue; /* otherwise, evaluate the remainder of the arguments */ @@ -1115,7 +1116,7 @@ LVAL xunwindprotect(void) /* evaluate the protected expression */ xlbegin(&cntxt,CF_UNWIND,NIL); - if ((sts = setjmp(cntxt.c_jmpbuf))) { + if ((sts = _setjmp(cntxt.c_jmpbuf))) { target = xltarget; mask = xlmask; val = xlvalue; @@ -1154,7 +1155,7 @@ LVAL xerrset(void) xlbegin(&cntxt,CF_ERROR,flag); /* check for error */ - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) val = NIL; /* otherwise, evaluate the expression */ @@ -1304,7 +1305,7 @@ LOCAL void tagbody(void) argv = xlargv; /* check for a 'go' */ - if (setjmp(cntxt.c_jmpbuf)) { + if (_setjmp(cntxt.c_jmpbuf)) { cntxt.c_xlargc = argc; cntxt.c_xlargv = argv; } diff --git a/lib-src/libnyquist/nyquist/xlisp/xldbug.c b/lib-src/libnyquist/nyquist/xlisp/xldbug.c index 5467e669d..9063d1f88 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xldbug.c +++ b/lib-src/libnyquist/nyquist/xlisp/xldbug.c @@ -15,24 +15,25 @@ /* forward declarations */ FORWARD LVAL stacktop(void); -FORWARD LOCAL void breakloop(char *hdr, char *cmsg, char *emsg, LVAL arg, int cflag); +FORWARD LOCAL void breakloop(const char *hdr, const char *cmsg, + const char *emsg, LVAL arg, int cflag); /* xlabort - xlisp serious error handler */ -void xlabort(char *emsg) +void xlabort(const char *emsg) { xlsignal(emsg,s_unbound); - xlerrprint("error",(char *) NULL,emsg,s_unbound); + xlerrprint("error",(const char *) NULL,emsg,s_unbound); xlbrklevel(); } /* xlbreak - enter a break loop */ -void xlbreak(char *emsg, LVAL arg) +void xlbreak(const char *emsg, LVAL arg) { breakloop("break","return from BREAK",emsg,arg,TRUE); } /* xlfail - xlisp error handler */ -void xlfail(char *emsg) +void xlfail(const char *emsg) { xlerror(emsg,s_unbound); } @@ -56,7 +57,7 @@ void close_loadingfiles() } /* xlerror - handle a fatal error */ -void xlerror(char *emsg, LVAL arg) +void xlerror(const char *emsg, LVAL arg) { close_loadingfiles(); if (getvalue(s_breakenable) != NIL) @@ -69,7 +70,7 @@ void xlerror(char *emsg, LVAL arg) } /* xlcerror - handle a recoverable error */ -void xlcerror(char *cmsg, char *emsg, LVAL arg) +void xlcerror(const char *cmsg, const char *emsg, LVAL arg) { if (getvalue(s_breakenable) != NIL) breakloop("error",cmsg,emsg,arg,TRUE); @@ -81,7 +82,7 @@ void xlcerror(char *cmsg, char *emsg, LVAL arg) } /* xlerrprint - print an error message */ -void xlerrprint(char *hdr, char *cmsg, char *emsg, LVAL arg) +void xlerrprint(const char *hdr, const char *cmsg, const char *emsg, LVAL arg) { /* print the error message */ sprintf(buf,"%s: %s",hdr,emsg); @@ -105,7 +106,8 @@ void xlerrprint(char *hdr, char *cmsg, char *emsg, LVAL arg) } /* breakloop - the debug read-eval-print loop */ -LOCAL void breakloop(char *hdr, char *cmsg, char *emsg, LVAL arg, int cflag) +LOCAL void breakloop(const char *hdr, const char *cmsg, + const char *emsg, LVAL arg, int cflag) { LVAL expr,val; XLCONTEXT cntxt; @@ -134,7 +136,7 @@ LOCAL void breakloop(char *hdr, char *cmsg, char *emsg, LVAL arg, int cflag) for (type = 0; type == 0; ) { /* setup the continue trap */ - if ((type = setjmp(cntxt.c_jmpbuf))) + if ((type = _setjmp(cntxt.c_jmpbuf))) switch (type) { case CF_CLEANUP: continue; diff --git a/lib-src/libnyquist/nyquist/xlisp/xldmem.c b/lib-src/libnyquist/nyquist/xlisp/xldmem.c index cc363cb9d..4656b9aa0 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xldmem.c +++ b/lib-src/libnyquist/nyquist/xlisp/xldmem.c @@ -129,7 +129,7 @@ LVAL new_string(int size) } /* cvsymbol - convert a string to a symbol */ -LVAL cvsymbol(char *pname) +LVAL cvsymbol(const char *pname) { /* pname points to a global buffer space. This is ok unless you have * a gc hook that writes things and therefore uses the buffer. Then @@ -701,7 +701,7 @@ LVAL xrestore(void) /* return directly to the top level */ stdputstr("[ returning to the top level ]\n"); - longjmp(top_level,1); + _longjmp(top_level,1); } #endif diff --git a/lib-src/libnyquist/nyquist/xlisp/xldmem.h b/lib-src/libnyquist/nyquist/xlisp/xldmem.h index 1710f1ffd..14b0bd651 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xldmem.h +++ b/lib-src/libnyquist/nyquist/xlisp/xldmem.h @@ -156,11 +156,11 @@ typedef struct xtype_desc_struct { char *type_name; struct node *type_symbol; - void (*free_meth)(); - void (*print_meth)(); - void (*save_meth)(); - unsigned char * (*restore_meth)(); - void (*mark_meth)(); + void (*free_meth)(void*); + void (*print_meth)(void*, void*); + void (*save_meth)(FILE*, void*); + unsigned char * (*restore_meth)(FILE*); + void (*mark_meth)(void*); } *xtype_desc; /* node structure */ @@ -211,5 +211,9 @@ typedef struct segment { struct node sg_nodes[1]; } SEGMENT; -extern xtype_desc create_desc(); /* initialize a type descriptor */ - +/* initialize a type descriptor */ +extern xtype_desc create_desc(char *type_name, void (*fm)(void*), + void (*pm)(void*, void*), + void (*sm)(FILE*, void*), + unsigned char * (*rm)(FILE*), + void (*mm)(void*)); diff --git a/lib-src/libnyquist/nyquist/xlisp/xleval.c b/lib-src/libnyquist/nyquist/xlisp/xleval.c index d708d147d..f60560f49 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xleval.c +++ b/lib-src/libnyquist/nyquist/xlisp/xleval.c @@ -461,7 +461,7 @@ LOCAL LVAL evfun(LVAL fun, int argc, LVAL *argv) xlbegin(&cntxt,CF_RETURN,name); /* execute the block */ - if (name && setjmp(cntxt.c_jmpbuf)) + if (name && _setjmp(cntxt.c_jmpbuf)) val = xlvalue; else for (val = NIL, cptr = getbody(fun); consp(cptr); cptr = cdr(cptr)) diff --git a/lib-src/libnyquist/nyquist/xlisp/xlfio.c b/lib-src/libnyquist/nyquist/xlisp/xlfio.c index 9e6df8480..086fa3c4b 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlfio.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlfio.c @@ -19,13 +19,13 @@ /* do some sanity checking: */ #ifndef XL_BIG_ENDIAN #ifndef XL_LITTLE_ENDIAN -configuration error -- either XL_BIG_ or XL_LITTLE_ENDIAN must be defined +#error configuration error -- either XL_BIG_ or XL_LITTLE_ENDIAN must be defined in xlisp.h #endif #endif #ifdef XL_BIG_ENDIAN #ifdef XL_LITTLE_ENDIAN -configuration error -- both XL_BIG_ and XL_LITTLE_ENDIAN are defined! +#error configuration error -- both XL_BIG_ and XL_LITTLE_ENDIAN are defined! #endif #endif @@ -655,7 +655,7 @@ LVAL xformat(void) case '\n': case '\r': /* mac may read \r -- this should be ignored */ - if (*fmt == '\r') *fmt++; + if (*fmt == '\r') fmt++; while (*fmt && *fmt != '\n' && isspace(*fmt)) ++fmt; break; @@ -699,17 +699,17 @@ LOCAL LVAL getstroutput(LVAL stream) LVAL xlistdir(void) { - char *path; + const char *path; LVAL result = NULL; LVAL *tail; - /* get the path */ + /* get the path, converting unsigned char * to char * */ path = (char *)getstring(xlgetfname()); /* try to start listing */ if (osdir_list_start(path)) { - char *filename; + const char *filename; xlsave1(result); tail = &result; - while (filename = osdir_list_next()) { + while ((filename = osdir_list_next())) { *tail = cons(NIL, NIL); rplaca(*tail, cvstring(filename)); tail = &cdr(*tail); diff --git a/lib-src/libnyquist/nyquist/xlisp/xlftab.c b/lib-src/libnyquist/nyquist/xlisp/xlftab.c index 559b37f8a..cdc44ec9c 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlftab.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlftab.c @@ -4,8 +4,6 @@ Permission is granted for unrestricted non-commercial use HISTORY -23-Apr-11 Dannenberg/Crook - EXIT instruction removed by using NULL for funtab[195].fd_name. 23-Apr-03 Mazzoni Eliminated some compiler warnings 1-Apr-88 Dale Amon at CSD @@ -359,7 +357,7 @@ FUNDEF funtab[] = { /* end of functions specific to xldmem.c */ { "TYPE-OF", S, xtype }, /* 194 */ -{ NULL, S, xexit }, /* 195 */ /* fd_name used to be "EXIT" */ +{ "EXIT", S, xexit }, /* 195 */ #ifdef PEEK_AND_POKE { "PEEK", S, xpeek }, /* 196 */ { "POKE", S, xpoke }, /* 197 */ @@ -488,6 +486,7 @@ FUNDEF funtab[] = { { "GET-USER", S, xget_user }, /* 306 */ { "FIND-IN-XLISP-PATH", S, xfind_in_xlisp_path }, /* 307 */ { "GET-ENV", S, xget_env }, /* 308 */ +{ "GET-RUN-TIME", S, xgetruntime }, /* 309 */ #ifdef MACINTOSH #include "macptrs.h" diff --git a/lib-src/libnyquist/nyquist/xlisp/xlimage.c b/lib-src/libnyquist/nyquist/xlisp/xlimage.c index f26075a0e..da43b2b9d 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlimage.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlimage.c @@ -11,7 +11,7 @@ /* external variables */ extern LVAL obarray,s_gchook,s_gcflag; -extern long nnodes,nfree,total; +extern long nnodes,nfree; extern int anodes,nsegs,gccalls; extern struct segment *segs,*lastseg,*fixseg,*charseg; extern XLCONTEXT *xlcontext; @@ -34,7 +34,7 @@ LOCAL void readnode(int type, LVAL node); /* xlisave - save the memory image */ -int xlisave(char *fname) +int xlisave(const char *fname) { char fullname[STRMAX+1]; unsigned char *cp; @@ -132,7 +132,7 @@ int xlisave(char *fname) } /* xlirestore - restore a saved memory image */ -int xlirestore(char *fname) +int xlirestore(const char *fname) { extern FUNDEF funtab[]; char fullname[STRMAX+1]; @@ -398,7 +398,7 @@ LOCAL OFFTYPE cvoptr(LVAL p) /* pointer not within any segment */ xlerror("bad pointer found during image save",p); /* this point will never be reached because xlerror() does a - longjmp(). The return is added to avoid false positive + _longjmp(). The return is added to avoid false positive error messages from static analyzers and compilers */ return ((OFFTYPE)NIL); } diff --git a/lib-src/libnyquist/nyquist/xlisp/xlio.c b/lib-src/libnyquist/nyquist/xlisp/xlio.c index 8ee2ca09d..d9ef582ac 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlio.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlio.c @@ -71,7 +71,7 @@ void xlungetc(LVAL fptr, int ch) LVAL lptr; /* check for ungetc from nil */ - if (fptr == NIL) + if (fptr == NIL || ch == EOF) ; /* otherwise, check for ungetc to a stream */ @@ -85,7 +85,7 @@ void xlungetc(LVAL fptr, int ch) } /* otherwise, it must be a file */ - else if (fptr) + else setsavech(fptr,ch); } @@ -190,7 +190,7 @@ void stdprint(LVAL expr) } /* stdputstr - print a string to *standard-output* */ -void stdputstr(char *str) +void stdputstr(const char *str) { xlputstr(getvalue(s_stdout),str); } @@ -209,7 +209,7 @@ void errprint(LVAL expr) } /* errputstr - print a string to *error-output* */ -void errputstr(char *str) +void errputstr(const const char *str) { xlputstr(getvalue(s_stderr),str); } @@ -222,7 +222,7 @@ void dbgprint(LVAL expr) } /* dbgputstr - print a string to *debug-io* */ -void dbgputstr(char *str) +void dbgputstr(const char *str) { xlputstr(getvalue(s_debugio),str); } @@ -234,7 +234,7 @@ void trcprin1(LVAL expr) } /* trcputstr - print a string to *trace-output* */ -void trcputstr(char *str) +void trcputstr(const char *str) { xlputstr(getvalue(s_traceout),str); } diff --git a/lib-src/libnyquist/nyquist/xlisp/xlisp.c b/lib-src/libnyquist/nyquist/xlisp/xlisp.c index 9fba0c082..cae255fcd 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlisp.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlisp.c @@ -4,7 +4,6 @@ Permission is granted for unrestricted non-commercial use */ /* CHANGELOG: - 23 Apr 11 (Dannenberg/Crook) xlrand() now retuns zero on zero range. 8 Oct 90 (Dannenberg) changed main() to xlisp_main_init and xlisp_main. made xlisp run as a module that evaluates expressions and retains state @@ -77,12 +76,12 @@ long random() { /* xlrand - return next random number in sequence */ long xlrand (long range) { - if (range == 0) return 0; + if (range == 0) return 0; #ifdef USE_RAND - return rand() % range; + return rand() % range; #endif #ifdef USE_RANDOM - return random() % range; + return random() % range; #endif } @@ -117,6 +116,22 @@ void xlisp_main_init(int argc, char *argv[]) case 'V': verbose = TRUE; break; + case 'r': + case 'R': + secure_read_path = &argv[i][2]; + break; + case 'w': + case 'W': + safe_write_path = &argv[i][2]; + break; + case 'l': + case 'L': + run_time_limit = atoi(&argv[i][2]); + break; + case 'm': + case 'M': + memory_limit = atoi(&argv[i][2]); + break; } #endif @@ -125,9 +140,9 @@ void xlisp_main_init(int argc, char *argv[]) /* setup initialization error handler */ xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,(LVAL)1); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) xlfatal("fatal initialization error"); - if (setjmp(top_level)) + if (_setjmp(top_level)) xlfatal("RESTORE not allowed during initialization"); /* initialize xlisp */ @@ -149,17 +164,17 @@ void xlisp_main_init(int argc, char *argv[]) } /* load "init.lsp" */ - if (setjmp(cntxt.c_jmpbuf) == 0) { + if (_setjmp(cntxt.c_jmpbuf) == 0) { xlload("init.lsp",TRUE,FALSE); } /* load any files mentioned on the command line */ - if (setjmp(cntxt.c_jmpbuf) == 0) + if (_setjmp(cntxt.c_jmpbuf) == 0) for (i = 1; i < argc; i++) if (argv[i][0] != '-' && !xlload(argv[i],TRUE,verbose)) xlerror("can't load file",cvstring(argv[i])); xlend(&cntxt); - if (setjmp(top_level)) + if (_setjmp(top_level)) xlfatal("RESTORE not allowed out of read-eval-print loop"); } @@ -173,7 +188,7 @@ LVAL xlisp_eval(LVAL expr) if (in_a_context == FALSE) { /* create an execution context */ xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,s_true); - if (setjmp(cntxt.c_jmpbuf)) { + if (_setjmp(cntxt.c_jmpbuf)) { setvalue(s_evalhook,NIL); setvalue(s_applyhook,NIL); xltrcindent = 0; @@ -207,7 +222,7 @@ void xlisp_main() in_a_context = TRUE; /* target for restore */ - if (setjmp(top_level)) + if (_setjmp(top_level)) xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,s_true); /* protect some pointers */ @@ -217,7 +232,7 @@ void xlisp_main() for (xl_main_loop = TRUE; xl_main_loop;) { /* setup the error return */ - if (setjmp(cntxt.c_jmpbuf)) { + if (_setjmp(cntxt.c_jmpbuf)) { setvalue(s_evalhook,NIL); setvalue(s_applyhook,NIL); xltrcindent = 0; @@ -283,7 +298,7 @@ void xlevsave(LVAL expr) } /* xlfatal - print a fatal error message and exit */ -void xlfatal(char *msg) +void xlfatal(const char *msg) { oserror(msg); xlisp_wrapup(); diff --git a/lib-src/libnyquist/nyquist/xlisp/xlisp.h b/lib-src/libnyquist/nyquist/xlisp/xlisp.h index 579f34f3c..316f9820b 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlisp.h +++ b/lib-src/libnyquist/nyquist/xlisp/xlisp.h @@ -18,23 +18,7 @@ HISTORY - RBD 16apr04 */ #include #include - -/* On the Mac, using _setjmp()/_longjmp() can speed up execution - quite a bit. */ -#if defined(__APPLE__) - -#define setjmp slow_setjmp -#define longjmp slow_longjmp #include -#undef setjmp -#undef longjmp -#define setjmp _setjmp -#define longjmp _longjmp - -#else -#include -#endif - /* NNODES number of nodes to allocate in each request (1000) */ /* EDEPTH evaluation stack depth (2000) */ @@ -259,7 +243,9 @@ extern long ptrtoabs(); characters, so I picked a bigger value. -RBD */ #define HSIZE 1499 /* symbol hash table size */ -#define SAMPLE 1000 /* control character sample rate */ +#define SAMPLE 50000 /* control character sample rate */ +/* Jul 2014: Under Xcode, debug, 2.4 GHz Intel Core i7: oscheck rate is + about 66Hz */ /* function table offsets for the initialization functions */ #define FT_RMHASH 0 @@ -400,7 +386,7 @@ typedef struct { typedef struct context { int c_flags; /* context type flags */ LVAL c_expr; /* expression (type dependant) */ - jmp_buf c_jmpbuf; /* longjmp context */ + jmp_buf c_jmpbuf; /* _longjmp context */ struct context *c_xlcontext; /* old value of xlcontext */ LVAL **c_xlstack; /* old value of xlstack */ LVAL *c_xlargv; /* old value of xlargv */ @@ -448,8 +434,8 @@ extern int gsnumber; /* additional prototypes */ -extern FILE *osaopen (char *name, char *mode); -extern FILE *osbopen (char *name, char *mode); +extern FILE *osaopen (const char *name, const char *mode); +extern FILE *osbopen (const char *name, const char *mode); #ifdef __MWERKS__ /* macfun.c */ @@ -482,7 +468,7 @@ LVAL xrdnohang(void); /* for extern.c */ -void inval_caches(); +void inval_caches(void); /* for xlbfun.c */ @@ -585,22 +571,23 @@ LVAL xuntrace(void); /* xldbug.c */ -void xlabort(char *emsg); -void xlbreak(char *emsg, LVAL arg); -void xlfail(char *emsg); -void xlerror(char *emsg, LVAL arg); -void xlcerror(char *cmsg, char *emsg, LVAL arg); -void xlerrprint(char *hdr, char *cmsg, char *emsg, LVAL arg); +void xlabort(const char *emsg); +void xlbreak(const char *emsg, LVAL arg); +void xlfail(const char *emsg); +void xlerror(const char *emsg, LVAL arg); +void xlcerror(const char *cmsg, const char *emsg, LVAL arg); +void xlerrprint(const char *hdr, const char *cmsg, const char *emsg, LVAL arg); void xlbaktrace(int n); void xldinit(void); void close_loadingfiles(void); /* xldmem.c */ +extern long total; /* total bytes allocated by xlisp */ LVAL cons(LVAL x, LVAL y); LVAL cvstring(const char *str); LVAL new_string(int size); -LVAL cvsymbol(char *pname); +LVAL cvsymbol(const char *pname); LVAL cvsubr(LVAL (*fcn)(void), int type, int offset); LVAL cvfile(FILE *fp); LVAL cvfixnum(FIXTYPE n); @@ -673,8 +660,8 @@ LVAL xlistdir(void); /* xlimage.c */ -int xlisave(char *fname); -int xlirestore(char *fname); +int xlisave(const char *fname); +int xlirestore(const char *fname); /* xlinit.c */ @@ -692,14 +679,14 @@ void xlputc(LVAL fptr, int ch); void xloutflush(LVAL fptr); void xlflush(void); void stdprint(LVAL expr); -void stdputstr(char *str); -void stdflush(); +void stdputstr(const char *str); +void stdflush(void); void errprint(LVAL expr); -void errputstr(char *str); +void errputstr(const char *str); void dbgprint(LVAL expr); -void dbgputstr(char *str); +void dbgputstr(const char *str); void trcprin1(LVAL expr); -void trcputstr(char *str); +void trcputstr(const char *str); /* xlisp.c */ @@ -707,7 +694,7 @@ long xlrand(long range); double xlrealrand(void); void xlrdsave(LVAL expr); void xlevsave(LVAL expr); -void xlfatal(char *msg); +void xlfatal(const char *msg); void xlisp_main_init(int, char **); void xlisp_main(void); void xlisp_wrapup(void); @@ -720,7 +707,7 @@ void xlend(XLCONTEXT *cptr); void xlgo(LVAL label); void xlreturn(LVAL name, LVAL val); void xlthrow(LVAL tag, LVAL val); -void xlsignal(char *emsg, LVAL arg); +void xlsignal(const char *emsg, LVAL arg); void xltoplevel(void); void xlbrklevel(void); void xlcleanup(void); @@ -838,9 +825,9 @@ LVAL xgtr(void); LVAL xsend(void); LVAL xsendsuper(void); -LVAL xlclass(char *name, int vcnt); -void xladdivar(LVAL cls, char *var); -void xladdmsg(LVAL cls, char *msg, int offset); +LVAL xlclass(const char *name, int vcnt); +void xladdivar(LVAL cls, const char *var); +void xladdmsg(LVAL cls, const char *msg, int offset); int xlobgetvalue(LVAL pair, LVAL sym, LVAL *pval); int xlobsetvalue(LVAL pair, LVAL sym, LVAL val); LVAL obisnew(void); @@ -863,13 +850,13 @@ LVAL xpp(void); void xlprint(LVAL fptr, LVAL vptr, int flag); void xlterpri(LVAL fptr); -void xlputstr(LVAL fptr, char *str); -void putatm(LVAL fptr, char *tag, LVAL val); +void xlputstr(LVAL fptr, const char *str); +void putatm(LVAL fptr, const char *tag, LVAL val); /* xlread.c */ -int xlload(char *fname, int vflag, int pflag); +int xlload(const char *fname, int vflag, int pflag); int xlread(LVAL fptr, LVAL *pval, int rflag); int readone(LVAL fptr, LVAL *pval); LVAL rmhash(void); @@ -941,14 +928,14 @@ LVAL xinfo(void); /* xlsubr.c */ -LVAL xlsubr(char *sname, int type, LVAL (*fcn)(void), int offset); +LVAL xlsubr(const char *sname, int type, LVAL (*fcn)(void), int offset); int xlgetkeyarg(LVAL key, LVAL *pval); void xltest(LVAL *pfcn, int *ptresult); int xlgkfixnum(LVAL key, LVAL *pval); /* argument list parsing functions */ extern LVAL xlgetfile(void); /* get a file/stream argument */ extern LVAL xlgetfname(void); /* get a filename argument */ -int needsextension(char *name); +int needsextension(const char *name); /* error reporting functions (don't *really* return at all) */ extern LVAL xlbadtype(LVAL arg); /* report "bad argument type" error */ extern LVAL xltoofew(void); /* report "too few arguments" error */ @@ -960,8 +947,8 @@ int lval_equal(LVAL arg1, LVAL arg2); /* xlsym.c */ -LVAL xlenter(char *name); /* enter a symbol */ -LVAL xlmakesym(char *name); /* make an uninterned symbol */ +LVAL xlenter(const char *name); /* enter a symbol */ +LVAL xlmakesym(const char *name); /* make an uninterned symbol */ LVAL xlgetvalue(LVAL sym); /* get value of a symbol (checked) */ LVAL xlxgetvalue(LVAL sym); /* get value of a symbol */ void xlsetvalue(LVAL sym, LVAL val); @@ -971,7 +958,7 @@ void xlsetfunction(LVAL sym, LVAL val); LVAL xlgetprop(LVAL sym, LVAL prp); void xlputprop(LVAL sym, LVAL val, LVAL prp); void xlremprop(LVAL sym, LVAL prp); -int hash(char *str, int len); +int hash(const char *str, int len); void xlsinit(void); LVAL findprop(LVAL sym, LVAL prp); @@ -986,14 +973,24 @@ LVAL xexit(void); LVAL xpeek(void); LVAL xpoke(void); LVAL xaddrs(void); +LVAL xgetruntime(void); /* macstuff, unixstuff, winstuff */ extern const char os_pathchar; extern const char os_sepchar; -void osinit(char *banner); -void oserror(char *msg); +/* security.c */ +extern char *secure_read_path; +extern char *safe_write_path; +extern int run_time_limit; +extern int run_time; +extern int memory_limit; +#define SAFE_NYQUIST (safe_write_path != NULL) +int ok_to_open(const char *filename, const char *mode); + +void osinit(const char *banner); +void oserror(const char *msg); void osfinish(void); int osclose(FILE *fp); void osflush(void); @@ -1002,22 +999,22 @@ int osaputc(int ch, FILE *fp); void osoutflush(FILE *fp); int osbputc(int ch, FILE *fp); void ostputc(int ch); -void ostoutflush(); +void ostoutflush(void); int osagetc(FILE *fp); int osbgetc(FILE *fp); int ostgetc(void); void ossymbols(void); LVAL xlinfo(void); LVAL xsetdir(void); -int osdir_list_start(char *path); -char *osdir_list_next(); -void osdir_list_finish(); -LVAL xosc_enable(); -LVAL xget_temp_path(); -LVAL xfind_in_xlisp_path(); +int osdir_list_start(const char *path); +const char *osdir_list_next(void); +void osdir_list_finish(void); +LVAL xosc_enable(void); +LVAL xget_temp_path(void); +LVAL xfind_in_xlisp_path(void); /* These are now implemented in path.c -dmazzoni */ -const char *return_xlisp_path(); +const char *return_xlisp_path(void); const char *find_in_xlisp_path(const char *fname); void set_xlisp_path(const char *p); diff --git a/lib-src/libnyquist/nyquist/xlisp/xljump.c b/lib-src/libnyquist/nyquist/xlisp/xljump.c index 14a941a54..817305f40 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xljump.c +++ b/lib-src/libnyquist/nyquist/xlisp/xljump.c @@ -10,7 +10,7 @@ extern XLCONTEXT *xlcontext,*xltarget; extern LVAL xlvalue,xlenv,xlfenv,xldenv; extern int xlmask; -LOCAL void findandjump(int mask, char *error); +LOCAL void findandjump(int mask, const char *error); /* xlbegin - beginning of an execution context */ @@ -83,7 +83,7 @@ void xlthrow(LVAL tag, LVAL val) } /* xlsignal - signal an error */ -void xlsignal(char *emsg, LVAL arg) +void xlsignal(const char *emsg, LVAL arg) { XLCONTEXT *cptr; @@ -148,11 +148,11 @@ void xljump(XLCONTEXT *target, int mask, LVAL val) xlvalue = val; /* call the handler */ - longjmp(xlcontext->c_jmpbuf,mask); + _longjmp(xlcontext->c_jmpbuf,mask); } /* findandjump - find a target context frame and jump to it */ -LOCAL void findandjump(int mask, char *error) +LOCAL void findandjump(int mask, const char *error) { XLCONTEXT *cptr; diff --git a/lib-src/libnyquist/nyquist/xlisp/xlobj.c b/lib-src/libnyquist/nyquist/xlisp/xlobj.c index 23a821402..e5164107f 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlobj.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlobj.c @@ -59,7 +59,7 @@ LVAL xsendsuper(void) } /* xlclass - define a class */ -LVAL xlclass(char *name, int vcnt) +LVAL xlclass(const char *name, int vcnt) { LVAL sym,cls; @@ -80,13 +80,13 @@ LVAL xlclass(char *name, int vcnt) } /* xladdivar - enter an instance variable */ -void xladdivar(LVAL cls, char *var) +void xladdivar(LVAL cls, const char *var) { setivar(cls,IVARS,cons(xlenter(var),getivar(cls,IVARS))); } /* xladdmsg - add a message to a class */ -void xladdmsg(LVAL cls, char *msg, int offset) +void xladdmsg(LVAL cls, const char *msg, int offset) { extern FUNDEF funtab[]; LVAL mptr; @@ -402,7 +402,7 @@ LOCAL LVAL evmethod(LVAL obj, LVAL msgcls, LVAL method) xlbegin(&cntxt,CF_RETURN,name); /* execute the block */ - if (name && setjmp(cntxt.c_jmpbuf)) + if (name && _setjmp(cntxt.c_jmpbuf)) val = xlvalue; else for (cptr = getbody(method); consp(cptr); cptr = cdr(cptr)) diff --git a/lib-src/libnyquist/nyquist/xlisp/xlprin.c b/lib-src/libnyquist/nyquist/xlisp/xlprin.c index 60339befb..a9e356f70 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlprin.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlprin.c @@ -25,7 +25,7 @@ extern FUNDEF funtab[]; extern char buf[]; LOCAL void putsymbol(LVAL fptr, char *str, int escflag); -LOCAL void putsubr(LVAL fptr, char *tag, LVAL val); +LOCAL void putsubr(LVAL fptr, const char *tag, LVAL val); LOCAL void putfixnum(LVAL fptr, FIXTYPE n); LOCAL void putflonum(LVAL fptr, FLOTYPE n); LOCAL void putchcode(LVAL fptr, int ch, int escflag); @@ -130,7 +130,7 @@ void xlterpri(LVAL fptr) } /* xlputstr - output a string */ -void xlputstr(LVAL fptr, char *str) +void xlputstr(LVAL fptr, const char *str) { while (*str) xlputc(fptr,*str++); @@ -242,7 +242,7 @@ LOCAL void putqstring(LVAL fptr, LVAL str) } /* putatm - output an atom */ -void putatm(LVAL fptr, char *tag, LVAL val) +void putatm(LVAL fptr, const char *tag, LVAL val) { sprintf(buf,"#<%s: #",tag); xlputstr(fptr,buf); sprintf(buf,AFMT,(long unsigned int)val); xlputstr(fptr,buf); @@ -250,7 +250,7 @@ void putatm(LVAL fptr, char *tag, LVAL val) } /* putsubr - output a subr/fsubr */ -LOCAL void putsubr(LVAL fptr, char *tag, LVAL val) +LOCAL void putsubr(LVAL fptr, const char *tag, LVAL val) { sprintf(buf,"#<%s-%s: #",tag,funtab[getoffset(val)].fd_name); xlputstr(fptr,buf); diff --git a/lib-src/libnyquist/nyquist/xlisp/xlread.c b/lib-src/libnyquist/nyquist/xlisp/xlread.c index c97047ca9..6dea64711 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlread.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlread.c @@ -79,7 +79,7 @@ extern FILE *read_by_xlisp; /* xlload - load a file of xlisp expressions */ -int xlload(char *fname, int vflag, int pflag) +int xlload(const char *fname, int vflag, int pflag) { char fullname[STRMAX+1]; #ifdef WINDOWS @@ -111,7 +111,7 @@ int xlload(char *fname, int vflag, int pflag) } } if (strcmp(fullname, "*.*") == 0) { - char *name = getfilename(NULL, "lsp", "r", "Load file"); + const char *name = getfilename(NULL, "lsp", "r", "Load file"); if (name) { strcpy(fullname, name); strcpy(save_file_name, name); @@ -183,7 +183,7 @@ int xlload(char *fname, int vflag, int pflag) /* read, evaluate and possibly print each expression in the file */ xlbegin(&cntxt,CF_ERROR,s_true); - if (setjmp(cntxt.c_jmpbuf)) + if (_setjmp(cntxt.c_jmpbuf)) sts = FALSE; #ifdef DEBUG_INPUT if (read_by_xlisp) { @@ -336,7 +336,7 @@ int readone(LVAL fptr, LVAL *pval) else { xlerror("illegal character",cvfixnum((FIXTYPE)ch)); /* this point will never be reached because xlerror() does a - longjmp(). The return is added to avoid false positive + _longjmp(). The return is added to avoid false positive error messages from static analyzers and compilers */ return (FALSE); } diff --git a/lib-src/libnyquist/nyquist/xlisp/xlsubr.c b/lib-src/libnyquist/nyquist/xlisp/xlsubr.c index cc729ef2b..9e73842a8 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlsubr.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlsubr.c @@ -15,7 +15,7 @@ extern LVAL k_test,k_tnot,s_eql; /* xlsubr - define a builtin function */ -LVAL xlsubr(char *sname, int type, LVAL (*fcn)(void), int offset) +LVAL xlsubr(const char *sname, int type, LVAL (*fcn)(void), int offset) { LVAL sym; sym = xlenter(sname); @@ -97,9 +97,9 @@ LVAL xlgetfname(void) } /* needsextension - check if a filename needs an extension */ -int needsextension(char *name) +int needsextension(const char *name) { - char *p; + const char *p; /* check for an extension */ for (p = &name[strlen(name)]; --p >= &name[0]; ) diff --git a/lib-src/libnyquist/nyquist/xlisp/xlsym.c b/lib-src/libnyquist/nyquist/xlisp/xlsym.c index 8932377b8..f2272029f 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlsym.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlsym.c @@ -153,7 +153,7 @@ LOCAL void test_one_env(LVAL environment, int i, char *s) /* xlenter - enter a symbol into the obarray */ -LVAL xlenter(char *name) +LVAL xlenter(const char *name) { LVAL sym,array; int i; @@ -181,7 +181,7 @@ LVAL xlenter(char *name) } /* xlmakesym - make a new symbol node */ -LVAL xlmakesym(char *name) +LVAL xlmakesym(const char *name) { LVAL sym; sym = cvsymbol(name); @@ -345,7 +345,7 @@ LVAL findprop(LVAL sym, LVAL prp) } /* hash - hash a symbol name string */ -int hash(char *str, int len) +int hash(const char *str, int len) { int i; for (i = 0; *str; ) diff --git a/lib-src/libnyquist/nyquist/xlisp/xlsys.c b/lib-src/libnyquist/nyquist/xlisp/xlsys.c index 99a1b4ed7..2d5293cb3 100644 --- a/lib-src/libnyquist/nyquist/xlisp/xlsys.c +++ b/lib-src/libnyquist/nyquist/xlisp/xlsys.c @@ -69,12 +69,12 @@ LVAL xget_env(void) /* xload - read and evaluate expressions from a file */ LVAL xload(void) { - unsigned char *name; + const char *name; int vflag,pflag; LVAL arg; - /* get the file name */ - name = getstring(xlgetfname()); + /* get the file name, converting unsigned char to char */ + name = (const char *) getstring(xlgetfname()); /* get the :verbose flag */ if (xlgetkeyarg(k_verbose,&arg)) @@ -89,7 +89,7 @@ LVAL xload(void) pflag = FALSE; /* load the file */ - return (xlload((char *) name, vflag, pflag) ? s_true : NIL); + return (xlload(name, vflag, pflag) ? s_true : NIL); } /* xtranscript - open or close a transcript file */ @@ -221,7 +221,7 @@ LVAL xaddrs(void) /* return the address of the node */ return (cvfixnum((FIXTYPE)val)); } -#endif PEEK_AND_POKE +#endif /* PEEK_AND_POKE */ /* xprofile - turn profiling on and off */ LVAL xprofile() @@ -248,7 +248,11 @@ FILE *read_by_xlisp = NULL; LVAL xstartrecordio() { + to_input_buffer = NULL; + if (ok_to_open("to-input-buffer.txt", "w")) to_input_buffer = fopen("to-input-buffer.txt", "w"); + read_by_xlisp = NULL; + if (ok_to_open("read-by-xlisp.txt", "w")) read_by_xlisp = fopen("read-by-xlisp.txt", "w"); if (!to_input_buffer || !read_by_xlisp) { return NIL; @@ -268,4 +272,9 @@ LVAL xstoprecordio() #endif - +/* xgetruntime - get current run_time */ +LVAL xgetruntime(void) +{ + /* return the value at that address */ + return cvfixnum((FIXTYPE) run_time); +} diff --git a/nyquist/bug.lsp b/nyquist/bug.lsp deleted file mode 100644 index 9a8a79128..000000000 --- a/nyquist/bug.lsp +++ /dev/null @@ -1,55 +0,0 @@ -; 6 -32 8 -32 pumped too much noise, picked up student answer too -; 3 -30 4 -30 pumped too much noise too -(setf m (compress-map 2 -12 2 -24 :limit t :transition 2)) -(s-save (scale 0.005 m) ny:all "map.wav") - -(defun t1 () (print (s-save (clip (let (y) - (setf y (compress (s-read "c:\\rbd\\garlan.aif") m 0.1 0.1)) - (setf y (agc y 6.0 2.0 2.0)) - y) 1.0) ny:all "compress.wav" :bits 8))) - -(defun t2 () (print (s-save (clip (let (y) - (setf y (compress (s-read "denoise.wav") m 0.1 0.1)) - (setf y (agc y 6.0 2.0 2.0)) - y) 1.0) ny:all "compden8.wav" :bits 8))) - -;(print (play (clip (scale 1.0 (compress (s-read "c:\\rbd\\garlan.aif") m 0.1 0.1)) 1.0))) -;(print (play (clip (agc (s-read "c:\\rbd\\garlan.aif") 6.0 2.0 2.0) 1.0))) -;(setf sil (s-read "..\\..\\garlan.aif" :time-offset 7.655 :dur 1.165)) -;(setf soft (s-read "..\\..\\garlan.aif" :time-offset 15.64 :dur .11)) - -; (play (compress sil m 0.1 0.1)) - -; (s-save (snd-oneshot (s-read ".\\orig.wav") 0.990 0.1) ny:all "oneshot.wav") - -(defun square (x) (* x x)) - -;; region for low-pass will be *soften-width* wide, with -;; *soften-crossfade* seconds of cross-fade -(setf *soften-width* 0.02) -(setf *soften-crossfade* 0.002) - -(defun soften-clipping (snd) - (let (clip-region) - (setf clip-region (snd-oneshot (prod snd snd) - (square (/ 126.0 127.0)) *soften-width*)) - (setf clip-region (snd-chase clip-region - *soften-crossfade* *soften-crossfade*)) - (setf snd (seq (s-rest 0.01) (cue (scale 0.99 snd)))) - ; (vector (prod snd clip-region) snd) - (prod snd clip-region) - )) - -(sound-off) - -(defun tes () - (let (snd) - (setf snd (s-read "..\\..\\intro.aif")) - (play (soften-clipping snd)))) - -(tes) - - - - - diff --git a/nyquist/dspprims.lsp b/nyquist/dspprims.lsp index 67eb8f645..4015c8e59 100644 --- a/nyquist/dspprims.lsp +++ b/nyquist/dspprims.lsp @@ -93,21 +93,8 @@ (error "feedback-delay with variable delay is not implemented")) -;; NYQ::DELAYCV -- coerce sample rates and call snd-delaycv -;; -(defun nyq:delaycv (the-snd delay feedback) - (display "delaycv" the-snd delay feedback) - (let ((the-snd-srate (snd-srate the-snd)) - (feedback-srate (snd-srate feedback))) - (cond ((> the-snd-srate feedback-srate) - (setf feedback (snd-up the-snd-srate feedback))) - ((< the-snd-srate feedback-srate) - (format t "Warning: down-sampling feedback in feedback-delay/comb~%") - (setf feedback (snd-down the-snd-srate feedback)))) - (snd-delaycv the-snd delay feedback))) - (setf feedback-delay-implementations - (vector #'snd-delay #'snd-delay-error #'nyq:delaycv #'snd-delay-error)) + (vector #'snd-delay #'snd-delay-error #'snd-delaycv #'snd-delay-error)) ;; NYQ:FEEDBACK-DELAY -- single channel delay @@ -130,29 +117,9 @@ (defun snd-alpassvv (snd delay feedback min-hz) (error "snd-alpassvv (ALPASS with variable decay and feedback) is not implemented"))) -(defun snd-alpass-4 (snd delay feedback min-hz) - (snd-alpass snd delay feedback)) - -(defun snd-alpasscv-4 (the-snd delay feedback min-hz) - (display "snd-alpasscv-4" (snd-srate the-snd) (snd-srate feedback)) - (let ((the-snd-srate (snd-srate the-snd)) - (feedback-srate (snd-srate feedback))) - (cond ((> the-snd-srate feedback-srate) - (setf feedback (snd-up the-snd-srate feedback))) - ((< the-snd-srate feedback-srate) - (format t "Warning: down-sampling feedback in alpass~%") - (setf feedback (snd-down the-snd-srate feedback)))) - ;(display "snd-alpasscv-4 after cond" (snd-srate the-snd) (snd-srate feedback)) - (snd-alpasscv the-snd delay feedback))) - - -(defun snd-alpassvv-4 (the-snd delay feedback min-hz) - ;(display "snd-alpassvv-4" (snd-srate the-snd) (snd-srate feedback)) - (let ((the-snd-srate (snd-srate the-snd)) - (delay-srate (snd-srate delay)) - (feedback-srate (snd-srate feedback)) - max-delay) +(defun nyq:alpassvv (the-snd delay feedback min-hz) + (let (max-delay) (cond ((or (not (numberp min-hz)) (<= min-hz 0)) (error "alpass needs numeric (>0) 4th parameter (min-hz) when delay is variable"))) @@ -164,23 +131,22 @@ (* max-delay 0.5))) ; now delay is between 0 and max-delay, so we won't crash nyquist when ; we call snd-alpassvv, which doesn't test for out-of-range data - (cond ((> the-snd-srate feedback-srate) - (setf feedback (snd-up the-snd-srate feedback))) - ((< the-snd-srate feedback-srate) - (format t "Warning: down-sampling feedback in alpass~%") - (setf feedback (snd-down the-snd-srate feedback)))) - (cond ((> the-snd-srate delay-srate) - (setf delay (snd-up the-snd-srate delay))) - ((< the-snd-srate delay-srate) - (format t "Warning: down-sampling delay in alpass~%") - (setf delay (snd-down the-snd-srate delay)))) - (display "snd-alpassvv-4 after cond" (snd-srate the-snd) (snd-srate feedback)) (snd-alpassvv the-snd delay feedback max-delay))) -(setf alpass-implementations - (vector #'snd-alpass-4 #'snd-alpass-error - #'snd-alpasscv-4 #'snd-alpassvv-4)) +;; NYQ:SND-ALPASS -- ignores min-hz argument and calls snd-alpass +;; +(defun nyq:snd-alpass (snd delay feedback min-hz) + (snd-alpass snd delay feedback)) + +;; NYQ:SND-ALPASSCV -- ignores min-hz argument and calls snd-alpasscv +;; +(defun nyq:snd-alpasscv (snd delay feedback min-hz) + (snd-alpasscv snd delay feedback)) + +(setf alpass-implementations + (vector #'nyq:snd-alpass #'snd-alpass-error + #'nyq:snd-alpasscv #'nyq:alpassvv)) ;; NYQ:ALPASS1 -- single channel alpass @@ -246,7 +212,7 @@ (floor 0.01) (threshold 0.01)) (let ((rms (lp (mult snd snd) (/ *control-srate* 10.0)))) (setf threshold (* threshold threshold)) - (mult snd (gate rms lookahead risetime falltime floor threshold)))) + (mult snd (gate rms floor risetime falltime lookahead threshold)))) ;; QUANTIZE -- quantize a sound @@ -342,9 +308,11 @@ ; convenient biquad: normalize a0, and use zero initial conditions. (defun nyq:biquad (x b0 b1 b2 a0 a1 a2) + (if (< a0 1.0) + (error (format t "a0 < 1 (unstable parameter) in biquad~%"))) (let ((a0r (/ 1.0 a0))) (snd-biquad x (* a0r b0) (* a0r b1) (* a0r b2) - (* a0r a1) (* a0r a2) 0 0))) + (* a0r a1) (* a0r a2) 0 0))) (defun biquad (x b0 b1 b2 a0 a1 a2) @@ -364,8 +332,9 @@ ;; NYQ:LOWPASS2 -- operates on single channel (defun nyq:lowpass2 (x hz q) - (if (or (> hz (/ (snd-srate x) 2.0))(< hz 0)) - (error "frequency out of range" hz)) + (if (or (> hz (* 0.5 (snd-srate x))) + (< hz 0)) + (error "cutoff frequency out of range" hz)) (let* ((w (* 2.0 Pi (/ hz (snd-srate x)))) (cw (cos w)) (sw (sin w)) @@ -383,8 +352,9 @@ (multichan-expand #'nyq:highpass2 x hz q)) (defun nyq:highpass2 (x hz q) - (if (or (> hz (/ (snd-srate x) 2.0))(< hz 0)) - (error "frequency out of range" hz)) + (if (or (> hz (* 0.5 (snd-srate x))) + (< hz 0)) + (error "cutoff frequency out of range" hz)) (let* ((w (* 2.0 Pi (/ hz (snd-srate x)))) (cw (cos w)) (sw (sin w)) @@ -574,8 +544,9 @@ (extract (/ lookahead (snd-srate sound)) 10000 (snd-follow sound floor risetime falltime lookahead))) -(defun gate (sound floor risetime falltime lookahead threshold) - (setf lookahead (round (* lookahead (snd-srate sound)))) - (setf lookahead (/ lookahead (snd-srate sound))) - (extract lookahead 10000 - (snd-gate sound lookahead risetime falltime floor threshold))) +; Note: gate implementation moved to nyquist.lsp +;(defun gate (sound floor risetime falltime lookahead threshold) +; (setf lookahead (round (* lookahead (snd-srate sound)))) +; (setf lookahead (/ lookahead (snd-srate sound))) +; (extract lookahead 10000 +; (snd-gate sound lookahead risetime falltime floor threshold))) diff --git a/nyquist/fileio.lsp b/nyquist/fileio.lsp index b5803abf5..6408d6059 100644 --- a/nyquist/fileio.lsp +++ b/nyquist/fileio.lsp @@ -13,17 +13,25 @@ ;; needed (let ((current (setdir "."))) (setf *default-sf-dir* - (or (setdir "c:\\tmp\\") - (setdir "c:\\temp\\") - (setdir "d:\\tmp\\") - (setdir "d:\\temp\\") - (setdir "e:\\tmp\\") - (setdir "e:\\temp\\") + (or (setdir "c:\\tmp\\" nil) + (setdir "c:\\temp\\" nil) + (setdir "d:\\tmp\\" nil) + (setdir "d:\\temp\\" nil) + (setdir "e:\\tmp\\" nil) + (setdir "e:\\temp\\" nil) (get-temp-path))) (format t "Set *default-sf-dir* to \"~A\" in fileio.lsp~%" *default-sf-dir*) (setdir current)))) +;; if the steps above fail, then *default-sf-dir* might be "" (especially +;; on windows), and the current directory could be read-only on Vista and +;; Windows 7. Therefore, the Nyquist IDE will subsequently call +;; suggest-default-sf-dir with Java's idea of a valid temp directory. +;; If *default-sf-dir* is the empty string (""), this will set the variable: +(defun suggest-default-sf-dir (path) + (cond ((equal *default-sf-dir* "") (setf *default-sf-dir* path)))) + ;; s-save -- saves a file (setf NY:ALL 1000000000) ; 1GIG constant for maxlen (defmacro s-save (expression &optional (maxlen NY:ALL) filename @@ -69,6 +77,7 @@ (t (error "unexpected value in multichannel-max" snd)))) + ;; AUTONORM -- look ahead to find peak and normalize sound to 80% ;; (defun autonorm (snd) @@ -89,10 +98,20 @@ (t snd)))) +(init-global *clipping-threshold* (/ 127.0 128.0)) + (defmacro s-save-autonorm (expression &rest arglist) `(let ((peak (s-save (autonorm ,expression) ,@arglist))) + (when (and *clipping-error* (> peak *clipping-threshold*)) + (format t "s-save-autonorm peak ~A from ~A~%" peak ,expression) + (error "clipping")) (autonorm-update peak))) +;; If the amplitude exceeds *clipping-threshold*, an error will +;; be raised if *clipping-error* is set. +;; +(init-global *clipping-error* nil) + ;; The "AutoNorm" facility: when you play something, the Nyquist play ;; command will automatically compute what normalization factor you ;; should have used. If you play the same thing again, the normalization @@ -113,6 +132,7 @@ ;; (init-global *autonorm-type* 'lookahead) (init-global *autonorm-max-samples* 1000000) ; default is 4MB buffer + ;; (defun autonorm-on () (setf *autonorm* 1.0) @@ -127,6 +147,17 @@ (setf *autonorm* 1.0) (format t "AutoNorm feature is off.~%")) +(defun explain-why-autonorm-failed () + (format t "~A~A~A~A~A~A" + " *autonorm-type* is LOOKAHEAD and your sound got\n" + " louder after the lookahead period, resulting in\n" + " too large a scale factor and clipping. Consider\n" + " setting *autonorm-type* to 'PREVIOUS. Alternatively,\n" + " try turning off autonorm, e.g. \"exec autonorm-off()\"\n" + " or in Lisp mode, (autonorm-off), and scale your sound\n" + " as follows.\n")) + + ;; AUTONORM-UPDATE -- called with true peak to report and prepare ;; ;; after saving/playing a file, we have the true peak. This along @@ -146,20 +177,31 @@ (cond ((> peak 1.0) (format t "*** CLIPPING DETECTED! ***~%"))) (cond ((and *autonormflag* (> peak 0.0)) - (setf *autonorm-previous-peak* (/ peak *autonorm*)) + (setf *autonorm-previous-peak* (/ peak *autonorm*)) (setf *autonorm* (/ *autonorm-target* *autonorm-previous-peak*)) (format t "AutoNorm: peak was ~A,~%" *autonorm-previous-peak*) (format t " peak after normalization was ~A,~%" peak) - (format t (if (eq *autonorm-type* 'PREVIOUS) - " new normalization factor is ~A~%" - " suggested normalization factor is ~A~%") - *autonorm*)) + (cond ((eq *autonorm-type* 'PREVIOUS) + (cond ((zerop *autonorm*) + (setf *autonorm* 1.0))) + (format t " new normalization factor is ~A~%" *autonorm*)) + ((eq *autonorm-type* 'LOOKAHEAD) + (cond ((> peak 1.0) + (explain-why-autonorm-failed))) + (format t " suggested manual normalization factor is ~A~%" + *autonorm*)) + (t + (format t + " unexpected value for *autonorm-type*, reset to LOOKAHEAD\n") + (setf *autonorm-type* 'LOOKAHEAD)))) (t (format t "Peak was ~A,~%" peak) - (format t " suggested normalization factor is ~A~%" - (/ *autonorm-target* peak))) + (cond ((> peak 0.0) + (format t " suggested normalization factor is ~A~%" + (/ *autonorm-target* peak)))))) peak - )) + ) + ;; s-read -- reads a file (defun s-read (filename &key (time-offset 0) (srate *sound-srate*) @@ -272,18 +314,21 @@ (defun sound-on () (setf *soundenable* t)) (defun sound-off () (setf *soundenable* nil)) +(defun coterm (snd1 snd2) + (multichan-expand #'snd-coterm snd1 snd2)) + (defmacro s-add-to (expr maxlen filename &optional (time-offset 0.0)) `(let ((ny:fname (soundfilename ,filename)) ny:peak ny:input (ny:offset ,time-offset)) (format t "Adding sound to ~A at offset ~A~%" ny:fname ,time-offset) (setf ny:peak (snd-overwrite '(let ((ny:addend ,expr)) - (sum (snd-coterm + (sum (coterm (s-read ny:fname :time-offset ny:offset) ny:addend) ny:addend)) - ,maxlen ny:fname ny:offset SND-HEAD-NONE 0 0 0)) + ,maxlen ny:fname ny:offset SND-HEAD-NONE 0 0 0 0.0)) (format t "Duration written: ~A~%" (car *rslt*)) ny:peak)) @@ -291,11 +336,11 @@ (defmacro s-overwrite (expr maxlen filename &optional (time-offset 0.0)) `(let ((ny:fname (soundfilename ,filename)) (ny:peak 0.0) - ny:input ny:rslt ny:offset) - (format t "Overwriting ~A at offset ~A~%" ny:fname ,time-offset) + ny:input ny:rslt (ny:offset ,time-offset)) + (format t "Overwriting ~A at offset ~A~%" ny:fname ny:offset) (setf ny:offset (s-read-byte-offset ny:rslt)) - (setf ny:peak (snd-overwrite `,expr ,maxlen ny:fname ,time-offset - 0, 0, 0, 0)) + (setf ny:peak (snd-overwrite `,expr ,maxlen ny:fname ny:offset + SND-HEAD-NONE 0 0 0 0.0)) (format t "Duration written: ~A~%" (car *rslt*)) ny:peak)) diff --git a/nyquist/misc.lsp b/nyquist/misc.lsp index bd695d1a1..6ac521612 100644 --- a/nyquist/misc.lsp +++ b/nyquist/misc.lsp @@ -30,11 +30,46 @@ (defmacro init-global (symb expr) `(if (boundp ',symb) ,symb (setf ,symb ,expr))) -; enable or disable breaks -(defun bkon () (setq *breakenable* T)) -(defun bkoff () (setq *breakenable* NIL)) +; controlling breaks and tracebacks: +; XLISP and SAL behave differently, so there are four(!) flags: +; *sal-traceback* -- print SAL traceback on error in SAL mode +; Typically you want this on always. +; *sal-break* -- allow break (to XLISP prompt) on error when in SAL mode +; (overrides *sal-traceback*) Typically, you do not want +; this unless you need to see exactly where an error happened +; or the bug is in XLISP source code called from SAL. +; *xlisp-break* -- allow break on error when in XLISP mode +; Typically, you want this on. +; *xlisp-traceback* -- print XLISP traceback on error in XLISP mode +; Typically, you do not want this because the full +; stack can be long and tedious. + +(setf *sal-mode* nil) + +(setf *sal-traceback* t + *sal-break* nil + *xlisp-break* t + *xlisp-traceback* nil) + +(defun sal-tracenable (flag) (setf *sal-traceback* flag)) +(defun sal-breakenable (flag) + (setf *sal-break* flag) + (if *sal-mode* (setf *breakenable* flag))) +(defun xlisp-breakenable (flag) + (setf *xlisp-break* flag) + (if (not *sal-mode*) (setf *breakenable* flag))) +(defun xlisp-tracenable (flag) + (setf *xlisp-traceback* flag) + (if flag (setf *xlisp-break* t)) + (cond ((not *sal-mode*) + (if flag (setf *breakenable* t)) + (setf *tracenable* flag)))) + + +; enable or disable breaks +(defun bkon () (xlisp-breakenable t)) +(defun bkoff () (xlisp-breakenable nil)) -(bkon) ;; (grindef 'name) - pretty print a function ;; @@ -98,8 +133,11 @@ (cond (*loadingfiles* (setf fullpath (car *loadingfiles*)) (dotimes (i (length fullpath)) - (cond ((equal (char fullpath i) *file-separator*) + ;; search for "/" (and on windows, also "\") in path: + (cond ((or (equal (char fullpath i) *file-separator*) + (equal (char fullpath i) #\/)) (setf n i)))) + ;; trim off filename (after last separator char in path (setf fullpath (subseq fullpath 0 (1+ n))) ;; REMOVED SUPPORT FOR MAC OS-9 AND BELOW -RBD @@ -148,7 +186,9 @@ (setf file-name `(strcat (current-path) ,file-name))) (path (setf file-name `(strcat ,path ,file-name)))) + ; (display "require-from" file-name) `(if (fboundp (quote ,fn-symbol)) t - (load ,file-name))) + ;; search for either .lsp or .sal file + (sal-load ,file-name))) diff --git a/nyquist/nyinit.lsp b/nyquist/nyinit.lsp index c1ae2cd46..6560334d5 100644 --- a/nyquist/nyinit.lsp +++ b/nyquist/nyinit.lsp @@ -10,6 +10,7 @@ (load "seqfnint.lsp" :verbose NIL) (load "dspprims.lsp" :verbose NIL) +(load "velocity.lsp" :verbose NIL) ; linear-to-vel etc (load "nyquist.lsp" :verbose NIL) (load "follow.lsp" :verbose NIL) @@ -30,8 +31,8 @@ (setf *WATCH* NIL) (format t "~%Nyquist -- A Language for Sound Synthesis and Composition~%") -(format t " Copyright (c) 1991,1992,1995,2007-2009 by Roger B. Dannenberg~%") -(format t " Version 3.03~%~%") +(format t " Copyright (c) 1991,1992,1995,2007-2012 by Roger B. Dannenberg~%") +(format t " Version 3.09~%~%") ;(setf *gc-flag* t) diff --git a/nyquist/nyquist.lsp b/nyquist/nyquist.lsp index 3c7fe535b..c4f4eb689 100644 --- a/nyquist/nyquist.lsp +++ b/nyquist/nyquist.lsp @@ -153,28 +153,35 @@ functions assume durations are always positive."))) (setf *TABLE* *SINE-TABLE*) +(defun calculate-hz (pitch what) + (let ((hz (step-to-hz (+ pitch (get-transpose)))) + (octaves 0)) + (cond ((> hz (/ *SOUND-SRATE* 2)) + (format t "Warning: ~A frequency (~A hz) will alias at current sample rate (~A hz).\n" + what hz *SOUND-SRATE*) + (while (> hz *SOUND-SRATE*) + (setf octaves (1+ octaves) + hz (* hz 0.5))) + (cond ((> octaves 0) + (format t "Warning: ~A frequency reduced by ~A octaves to ~A hz (which will still alias).\n" + what octaves hz))))) + hz)) + + ;; AMOSC ;; (defun amosc (pitch modulation &optional (sound *table*) (phase 0.0)) (let ((modulation-srate (snd-srate modulation)) - (hz (step-to-hz (+ pitch (get-transpose))))) - (cond ((> *SOUND-SRATE* modulation-srate) - (setf modulation (snd-up *SOUND-SRATE* modulation))) - ((< *SOUND-SRATE* modulation-srate) - (format t "Warning: down-sampling AM modulation in amosc~%") - (setf modulation (snd-down *SOUND-SRATE* modulation)))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: amosc frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) + (hz (calculate-hz pitch "amosc"))) (scale-db (get-loud) (snd-amosc - (car sound) ; samples for table - (cadr sound) ; step represented by table - *SOUND-SRATE* ; output sample rate - hz ; output hz - (local-to-global 0) ; starting time - modulation ; modulation - phase)))) ; phase + (car sound) ; samples for table + (cadr sound) ; step represented by table + *SOUND-SRATE* ; output sample rate + hz ; output hz + (local-to-global 0) ; starting time + modulation ; modulation + phase)))) ; phase ;; FMOSC @@ -185,22 +192,16 @@ functions assume durations are always positive."))) ;; (defun fmosc (pitch modulation &optional (sound *table*) (phase 0.0)) (let ((modulation-srate (snd-srate modulation)) - (hz (step-to-hz (+ pitch (get-transpose))))) - (cond ((< *SOUND-SRATE* modulation-srate) - (format t "Warning: down-sampling FM modulation in fmosc~%") - (setf modulation (snd-down *SOUND-SRATE* modulation)))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: fmosc nominal frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) + (hz (calculate-hz pitch "fmosc"))) (scale-db (get-loud) (snd-fmosc - (car sound) ; samples for table - (cadr sound) ; step represented by table - *SOUND-SRATE* ; output sample rate - hz ; output hz - (local-to-global 0) ; starting time - modulation ; modulation - phase)))) ; phase + (car sound) ; samples for table + (cadr sound) ; step represented by table + *SOUND-SRATE* ; output sample rate + hz ; output hz + (local-to-global 0) ; starting time + modulation ; modulation + phase)))) ; phase ;; FMFB @@ -208,10 +209,7 @@ functions assume durations are always positive."))) ;; this code is based on FMOSC above ;; (defun fmfb (pitch index &optional dur) - (let ((hz (step-to-hz (+ pitch (get-transpose))))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format "Warning: fmfb nominal frequency (~A hz) will alias at current sample rate (~A hz).~%" - hz *SOUND-SRATE*))) + (let ((hz (calculate-hz pitch "fmfb"))) (setf dur (get-duration dur)) (cond ((soundp index) (ny:fmfbv hz index)) (t @@ -236,13 +234,10 @@ functions assume durations are always positive."))) ;; (defun buzz (n pitch modulation) (let ((modulation-srate (snd-srate modulation)) - (hz (step-to-hz (+ pitch (get-transpose))))) + (hz (calculate-hz pitch "buzz nominal"))) (cond ((< *SOUND-SRATE* modulation-srate) (format t "Warning: down-sampling modulation in buzz~%") (setf modulation (snd-down *SOUND-SRATE* modulation)))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: buzz nominal frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) (setf n (max n 1)) ; avoid divide by zero problem (scale-db (get-loud) (snd-buzz n ; number of harmonics @@ -333,20 +328,16 @@ loop ;; (defun siosc (pitch modulation breakpoints) (let ((modulation-srate (snd-srate modulation)) - (hz (step-to-hz (+ pitch (get-transpose))))) + (hz (calculate-hz pitch "siosc nominal"))) (cond ((< *SOUND-SRATE* modulation-srate) (format t "Warning: down-sampling FM modulation in siosc~%") (setf modulation (snd-down *SOUND-SRATE* modulation)))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: siosc nominal frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) - (scale-db (get-loud) - (snd-siosc - (siosc-breakpoints breakpoints) ; tables - *SOUND-SRATE* ; output sample rate - hz ; output hz - (local-to-global 0) ; starting time - modulation)))) ; modulation + (scale-db (get-loud) + (snd-siosc (siosc-breakpoints breakpoints) ; tables + *SOUND-SRATE* ; output sample rate + hz ; output hz + (local-to-global 0) ; starting time + modulation)))) ; modulation ;; LFO -- freq &optional duration sound phase) @@ -393,12 +384,7 @@ loop (defun osc (pitch &optional (duration 1.0) (sound *TABLE*) (phase 0.0)) (let ((d (get-duration duration)) - (hz (step-to-hz (+ pitch (get-transpose))))) - ;(display "osc" *warp* global-start global-stop actual-dur - ; (get-transpose)) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: osc frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) + (hz (calculate-hz pitch "osc"))) (set-logical-stop (scale-db (get-loud) (snd-osc @@ -415,10 +401,7 @@ loop ;; PARTIAL -- sine osc with built-in envelope scaling ;; (defun partial (steps env) - (let ((hz (step-to-hz (+ steps (get-transpose))))) - (cond ((> hz (/ *sound-srate* 2)) - (format t "Warning: partial frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *sound-srate*))) + (let ((hz (calculate-hz steps "partial"))) (scale-db (get-loud) (snd-partial *sound-srate* hz (force-srate *sound-srate* env))))) @@ -429,15 +412,12 @@ loop (defun sampler (pitch modulation &optional (sample *table*) (npoints 2)) (let ((samp (car sample)) - (samp-pitch (cadr sample)) - (samp-loop-start (caddr sample)) - (hz (step-to-hz (+ pitch (get-transpose))))) + (samp-pitch (cadr sample)) + (samp-loop-start (caddr sample)) + (hz (calculate-hz pitch "sampler nominal"))) ; make a waveform table look like a sample with no attack: (cond ((not (numberp samp-loop-start)) (setf samp-loop-start 0.0))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: sampler nominal frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) (scale-db (get-loud) (snd-sampler samp ; samples for table @@ -453,11 +433,8 @@ loop ;; SINE -- simple sine oscillator ;; (defun sine (steps &optional (duration 1.0)) - (let ((hz (step-to-hz (+ steps (get-transpose)))) + (let ((hz (calculate-hz steps "sine")) (d (get-duration duration))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: sine frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) (set-logical-stop (scale-db (get-loud) (snd-sine *rslt* hz *sound-srate* d)) @@ -470,11 +447,8 @@ loop ;; ("time_type" "d") ("double" "final_amp")) ;; (defun pluck (steps &optional (duration 1.0) (final-amp 0.001)) - (let ((hz (step-to-hz (+ steps (get-transpose)))) + (let ((hz (calculate-hz steps "pluck")) (d (get-duration duration))) - (cond ((> hz (/ *SOUND-SRATE* 2)) - (format t "Warning: pluck frequency (~A hz) will alias at current sample rate (~A hz).\n" - hz *SOUND-SRATE*))) (set-logical-stop (scale-db (get-loud) (snd-pluck *SOUND-SRATE* hz *rslt* d final-amp)) @@ -549,12 +523,29 @@ loop ;; (defmacro at-abs (x s) `(progv '(*WARP*) - (if (warp-function *WARP*) - (list (list (sref-inverse (warp-function *WARP*) ,x) - (warp-stretch *WARP*) - (warp-function *WARP*))) - (list (list ,x (warp-stretch *WARP*) NIL))) - ,s)) + (if (warp-function *WARP*) + (list (list (sref-inverse (warp-function *WARP*) ,x) + (warp-stretch *WARP*) + (warp-function *WARP*))) + (list (list ,x (warp-stretch *WARP*) NIL))) + ;; issue warning if sound starts in the past + (check-t0 ,s ',s))) + +(defun check-t0 (s src) + (let (flag t0 (now (local-to-global 0))) + (cond ((arrayp s) + (dotimes (i (length s)) + (setf t0 (snd-t0 (aref s i)))) + (if (< t0 now) (setf flag t0))) + (t + (setf t0 (snd-t0 s)) + (if (< t0 now) (setf flag t0)))) + (if flag + (format t "Warning: cannot go back in time to ~A, sound came from ~A~%" + flag src)) + ; (display "check-t0" t0 now src) + ; return s whether or not warning was reported + s)) ;; (CLIP S1 VALUE) - clip maximum amplitude to value ; @@ -674,11 +665,25 @@ loop ; extract - start is stretched and shifted as is stop ; result is shifted to start at local time zero (defun extract (start stop sound) - (snd-xform sound (snd-srate sound) (local-to-global 0) - (local-to-global start) (local-to-global stop) 1.0)) + (extract-abs (local-to-global start) (local-to-global stop) sound + (local-to-global 0))) -(defun extract-abs (start stop sound) - (snd-xform sound (snd-srate sound) 0 start stop 1.0)) +; extract-abs - return sound between start and stop +; start-time is optional (to aid the implementation of +; extract) and gives the start time of the result, normally 0. +; There is a problem if sound t0 is not equal to start-time. +; E.g. if sound was created with AT, its t0 might be +; in the future, but snd-xform works by first shifting +; t0 to local time zero, so we need to be very careful. +; The solution is that if t0 > start_time, subtract the difference +; from start and stop to shift them appropriately. +(defun extract-abs (start stop sound &optional (start-time 0)) + (let ((t0 (snd-t0 sound)) offset) + (cond ((/= t0 start-time) + (setf offset (- t0 start-time)) + (setf start (- start offset)) + (setf stop (- stop offset)))) + (snd-xform sound (snd-srate sound) start-time start stop 1.0))) (defun local-to-global (local-time) @@ -1341,22 +1346,14 @@ loop ; (defun nyq:prod-2-sounds (s1 s2) (cond ((numberp s1) - (cond ((numberp s2) - (* s1 s2)) - (t - (scale s1 s2)))) - ((numberp s2) - (scale s2 s1)) - (t - (let ((s1sr (snd-srate s1)) - (s2sr (snd-srate s2))) -; (display "nyq:prod-2-sounds" s1sr s2sr) - (cond ((> s1sr s2sr) - (snd-prod s1 (snd-up s1sr s2))) - ((< s1sr s2sr) - (snd-prod (snd-up s2sr s1) s2)) - (t - (snd-prod s1 s2))))))) + (cond ((numberp s2) + (* s1 s2)) + (t + (scale s1 s2)))) + ((numberp s2) + (scale s2 s1)) + (t + (snd-prod s1 s2)))) ;; RAMP -- linear ramp from 0 to x @@ -1434,14 +1431,8 @@ loop (snd-maxv s1 (snd-const s2 (local-to-global 0.0) (snd-srate s1) (get-duration 1.0)))) (t - (let ((s1sr (snd-srate s1)) - (s2sr (snd-srate s2))) - (cond ((> s1sr s2sr) - (snd-maxv s1 (snd-up s1sr s2))) - ((< s1sr s2sr) - (snd-maxv (snd-up s2sr s1) s2)) - (t - (snd-maxv s1 s2))))))) + (snd-maxv s1 s2)))) + (defun s-min (s1 s2) (setf s1 (nyq:coerce-to s1 s2)) @@ -1472,14 +1463,8 @@ loop (snd-minv s1 (snd-const s2 (local-to-global 0.0) (snd-srate s1) (get-duration 1.0)))) (t - (let ((s1sr (snd-srate s1)) - (s2sr (snd-srate s2))) - (cond ((> s1sr s2sr) - (snd-minv s1 (snd-up s1sr s2))) - ((< s1sr s2sr) - (snd-minv (snd-up s2sr s1) s2)) - (t - (snd-minv s1 s2))))))) + (snd-minv s1 s2)))) + (defun snd-minv (s1 s2) (scale -1.0 (snd-maxv (scale -1.0 s1) (scale -1.0 s2)))) @@ -1682,8 +1667,8 @@ loop ;;; operations on sounds -(defun diff (x &optional y) - (cond (y (sum x (prod -1 y))) +(defun diff (x &rest y) + (cond (y (sum x (prod -1 (car y)))) (t (prod -1 x)))) ; compare-shape is a shape table -- origin 1. diff --git a/nyquist/sal-parse.lsp b/nyquist/sal-parse.lsp index 34730080d..326c94ec1 100644 --- a/nyquist/sal-parse.lsp +++ b/nyquist/sal-parse.lsp @@ -51,8 +51,8 @@ (:/ "/" /) (:% "%" rem) (:^ "^" expt) - (:= "=" eql) ; equality and assigment - (:!= "!=" not-eql) + (:= "=" sal-equal) ; equality and assigment + (:!= "!=" not-sal-equal) (:< "<" <) (:> ">" >) (:<= "<=" <=) ; leq and assignment minimization @@ -1419,7 +1419,7 @@ ((eq op '/=) (setq expr `(/ ,vref ,expr))) ((eq op '&=) (setq expr `(nconc ,vref (list ,expr)))) ((eq op '@=) (setq expr `(cons ,expr ,vref))) - ((eq op '^=) (setq expr `(nconc ,vref (copy-list ,expr)))) + ((eq op '^=) (setq expr `(nconc ,vref (append ,expr nil)))) ((eq op '<=) (setq expr `(min ,vref ,expr))) ((eq op '>=) (setq expr `(max ,vref ,expr))) (t (errexit (format nil "unknown assigment operator ~A" op)))) @@ -1605,7 +1605,7 @@ (and term-test (member (car term-test) '(>= >)))) (setf binding (list id init (list '1+ id)))) (t ; loop goes down because of "above" or "downto" - (display "for step" term-test) + ; (display "for step" term-test) (setf binding (list id init (list '1- id))))) (setf binding (list binding))) (t diff --git a/nyquist/sal.lsp b/nyquist/sal.lsp index adb39e787..47781024d 100644 --- a/nyquist/sal.lsp +++ b/nyquist/sal.lsp @@ -198,14 +198,15 @@ (defparameter *sal-print-list* t) -(defun sal-printer (x &key (stream *standard-output*) (add-space t)) +(defun sal-printer (x &key (stream *standard-output*) (add-space t) + (in-list nil)) (let ((*print-case* ':downcase)) (cond ((and (consp x) *sal-print-list*) (write-char #\{ stream) (do ((items x (cdr items))) ((null items)) (sal-printer (car items) :stream stream - :add-space (cdr items)) + :add-space (cdr items) :in-list t) (cond ((cdr items) (cond ((not (consp (cdr items))) (princ " " stream) @@ -214,6 +215,7 @@ (write-char #\} stream)) ((not x) (princ "#f" stream) ) ((eq x t) (princ "#t" stream)) + (in-list (prin1 x stream)) (t (princ x stream))) (if add-space (write-char #\space stream)))) @@ -224,9 +226,14 @@ (apply #'format t string args)) +;; sal-print has been modified from the original SAL to print items separated +;; by spaces (no final trailing space) and followed by a newline. (defun sal-print (&rest args) + (do ((items args (cdr items))) + ((null items)) + ;; add space unless we are at the last element + (funcall *sal-printer* (car items) :add-space (cdr items))) (terpri) - (mapc *sal-printer* args) (values)) (defmacro keyword (sym) @@ -319,7 +326,7 @@ (cond ((null fullpath) (format t "sal-load: could not find ~A~%" filename)) (t - (return (generic-loader filename verbose print))))))) + (return (generic-loader fullpath verbose print))))))) ;; GENERIC-LOADER -- load a sal or lsp file based on extension @@ -455,10 +462,12 @@ ;; function called in sal programs to exit the sal read-compile-run-print loop (defun sal-exit () (setf *sal-exit* t)) +(setf *sal-call-stack* nil) + ;; read-eval-print loop for sal commands (defun sal () - (progv '(*breakenable* *tracenable* *sal-exit*) - (list *sal-xlispbreak* *sal-xlispbreak* nil) + (progv '(*breakenable* *tracenable* *sal-exit* *sal-mode*) + (list *sal-break* nil nil t) (let (input line) (setf *sal-call-stack* nil) (read-line) ; read the newline after the one the user @@ -478,9 +487,14 @@ (setf input (subseq input 1))) (sal-compile input t nil "") (sal-trace-exit)) - (princ "Returning to Lisp ...\n") - t ; return value - ))) + (princ "Returning to Lisp ...\n"))) + ;; in case *xlisp-break* or *xlisp-traceback* was set from SAL, impose + ;; them here + (cond ((not *sal-mode*) + (setf *breakenable* *xlisp-break*) + (setf *tracenable* *xlisp-traceback*))) + t) + (defun sal-error-output (stack) @@ -514,44 +528,48 @@ ;; otherwise, returns a list (PROGN p1 p2 p3 ...) where pn are lisp ;; expressions ;; -(defun sal-compile (input eval-flag multiple-statements filename) +;; Note: replaced local variables here with "local" names to avoid +;; collisions with globals that compiled code might try to use: +;; eval uses local bindings, not global ones +;; +(defun sal-compile (sal:input sal:evflag sal:mult-stmts sal:filename) ;; save some globals because eval could call back recursively (progv '(*sal-tokens* *sal-input* *sal-input-text*) '(nil nil nil) - (let (output remainder rslt stack) - (setf stack *sal-call-stack*) + (let (sal:output sal:remainder sal:rslt sal:stack) + (setf sal:stack *sal-call-stack*) ;; if first input char is "(", then eval as a lisp expression: - ;(display "sal-compile" input)(setf *sal-compiler-debug* t) - (cond ((input-starts-with-open-paren input) - ;(print "input is lisp expression") + ;(display "sal-compile" sal:input)(setf *sal-compiler-debug* t) + (cond ((input-starts-with-open-paren sal:input) + ;(print "sal:input is lisp expression") (errset - (print (eval (read (make-string-input-stream input)))) t)) + (print (eval (read (make-string-input-stream sal:input)))) t)) (t ;; compile SAL expression(s): (loop - (setf output (sal-parse nil nil input multiple-statements - filename)) - (cond ((first output) ; successful parse - (setf remainder *sal-tokens*) - (setf output (second output)) + (setf sal:output (sal-parse nil nil sal:input sal:mult-stmts + sal:filename)) + (cond ((first sal:output) ; successful parse + (setf sal:remainder *sal-tokens*) + (setf sal:output (second sal:output)) (when *sal-compiler-debug* (terpri) - (pprint output)) - (cond (eval-flag ;; evaluate the compiled code - (cond ((null (errset (eval output) t)) - (sal-error-output stack) + (pprint sal:output)) + (cond (sal:evflag ;; evaluate the compiled code + (cond ((null (errset (eval sal:output) t)) + (sal-error-output sal:stack) (return)))) ;; stop on error (t - (push output rslt))) + (push sal:output sal:rslt))) ;(display "sal-compile after eval" - ; remainder *sal-tokens*) + ; sal:remainder *sal-tokens*) ;; if there are statements left over, maybe compile again - (cond ((and multiple-statements remainder) - ;; move remainder to input and iterate - (setf input remainder)) + (cond ((and sal:mult-stmts sal:remainder) + ;; move sal:remainder to sal:input and iterate + (setf sal:input sal:remainder)) ;; see if we've compiled everything - ((and (not eval-flag) (not remainder)) - (return (cons 'progn (reverse rslt)))) - ;; if eval but no more input, return - ((not remainder) + ((and (not sal:evflag) (not sal:remainder)) + (return (cons 'progn (reverse sal:rslt)))) + ;; if eval but no more sal:input, return + ((not sal:remainder) (return)))) (t ; error encountered (return))))))))) @@ -568,3 +586,10 @@ (and (stringp input) (> (length input) i) (eq (char input i) #\()))) + +(defun sal-equal (a b) + (or (and (numberp a) (numberp b) (= a b)) + (equal a b))) + +(defun not-sal-equal (a b) + (not (sal-equal a b))) diff --git a/nyquist/seq.lsp b/nyquist/seq.lsp index 947c63eaf..4d6000960 100644 --- a/nyquist/seq.lsp +++ b/nyquist/seq.lsp @@ -209,7 +209,48 @@ ;; (2) EVAL is used on each event, so events cannot refer to parameters ;; or local variables ;; +;; If score events are very closely spaced (< 1020 samples), the block +;; overlap can cause a ripple effect where to complete one block of the +;; output, you have to compute part of the next score event, but then +;; it in turn computes part of the next score event, and so on, until +;; the stack overflows (if you have 1000's of events). +;; +;; This is really a fundamental problem in Nyquist because blocks are +;; not aligned. To work around the problem (but not totally solve it) +;; scores are evaluated up to a length of 100. If there are more than +;; 100 score events, we form a balanced tree of adders so that maybe +;; we will end up with a lot of sound in memory, but at least the +;; stack will not overflow. Generally, we should not end up with more +;; than 100 times as many blocks as we would like, but since the +;; normal space required is O(1), we're still using constant space + +;; a small constant * log(score-length). +;; +(setf MAX-LINEAR-SCORE-LEN 100) (defun timed-seq (score) + (let ((len (length score)) + pair) + (cond ((< len MAX-LINEAR-SCORE-LEN) + (timed-seq-linear score)) + (t ;; split the score -- divide and conquer + (setf pair (score-split score (/ len 2))) + (sum (timed-seq (car pair)) (timed-seq (cdr pair))))))) + +;; score-split -- helper function: split score into two, with n elements +;; in the first part; returns a dotted pair +(defun score-split (score n) + ;; do the split without recursion to avoid stack overflow + ;; algorithm: modify the list destructively to get the first + ;; half. Copy it. Reassemble the list. + (let (pair last front back) + (setf last (nthcdr (1- n) score)) + (setf back (cdr last)) + (rplacd last nil) + (setf front (append score nil)) ; shallow copy + (rplacd last back) + (cons front back))) + + +(defun timed-seq-linear (score) ; check to insure that times are strictly increasing and >= 0 and stretches are >= 0 (let ((start-time 0) error-msg) (dolist (event score) diff --git a/nyquist/sndfnint.lsp b/nyquist/sndfnint.lsp index 83c897cde..383b055a1 100644 --- a/nyquist/sndfnint.lsp +++ b/nyquist/sndfnint.lsp @@ -39,6 +39,8 @@ (setf snd-head-CAF 19) (setf snd-head-raw 20) + + (setf snd-head-OGG 21) (setf snd-head-channels 1) @@ -77,6 +79,8 @@ (setf snd-mode-DPCM 10) (setf snd-mode-msadpcm 11) + + (setf snd-mode-vorbis 12) (SETF MAX-STOP-TIME 10E20) diff --git a/nyquist/stk.lsp b/nyquist/stk.lsp index 6ba7e55ef..10c84d6a2 100644 --- a/nyquist/stk.lsp +++ b/nyquist/stk.lsp @@ -131,13 +131,13 @@ (snd-sitar *rslt* (step-to-hz step) d *sound-srate*))) (defun nyq:nrev (snd rev-time mix) - (snd-stkrev 0 snd rev-time mix *sound-srate*)) + (snd-stkrev 0 snd rev-time mix)) (defun nyq:jcrev (snd rev-time mix) - (snd-stkrev 1 snd rev-time mix *sound-srate*)) + (snd-stkrev 1 snd rev-time mix)) (defun nyq:prcrev (snd rev-time mix) - (snd-stkrev 2 snd rev-time mix *sound-srate*)) + (snd-stkrev 2 snd rev-time mix)) (defun nrev (snd rev-time mix) (multichan-expand #'nyq:nrev snd rev-time mix)) @@ -149,13 +149,13 @@ (multichan-expand #'nyq:prcrev snd rev-time mix)) (defun nyq:chorus (snd depth freq mix &optional (base-delay 6000)) - (snd-stkchorus snd base-delay depth freq mix *sound-srate*)) + (snd-stkchorus snd base-delay depth freq mix)) (defun stkchorus (snd depth freq mix &optional (base-delay 6000)) (multichan-expand #'nyq:chorus snd depth freq mix base-delay)) (defun nyq:pitshift (snd shift mix) - (snd-stkpitshift snd shift mix *sound-srate*)) + (snd-stkpitshift snd shift mix)) (defun pitshift (snd shift mix) (multichan-expand #'nyq:pitshift snd shift mix)) diff --git a/nyquist/test.lsp b/nyquist/test.lsp new file mode 100644 index 000000000..3bacbc62a --- /dev/null +++ b/nyquist/test.lsp @@ -0,0 +1,43 @@ + +(defun ss () (osc c5)) + +(defun tt () (stretch 2 (snd-tapv (ss) 1.1 (scale *d* (lfo 10)) 2.2))) +(setf *d* .01) + +(defun g () (play (tt))) + +;(set-sound-srate 10) +;(set-control-srate 10) +(defun rr () (stretch 10 (ramp))) +(defun ll () (stretch 10 (lfo .5))) +(defun xx () (snd-tapv (rr) 1.1 (ll) 2.2)) +(defun h () (snd-samples (xx) 150)) + +(defun chorus (sound maxdepth depth rate saturation) + (let ((modulation (prod depth (stretch-abs 10000.0 (general-lfo rate)))) + (offset (/ maxdepth 2.0)) + chor) + (setf chor (snd-tapv sound offset modulation maxdepth)) + (sum (prod chor saturation) (prod (seq (s-rest offset) sound) + (sum 1.0 (prod -1.0 saturation)))))) + + +(set-sound-srate 22050.0) + +(defun f () + (chorus (s-read "runtime\\ah.wav") .1 .1 1 .5)) + +(defun e () + (seq (s-rest .05) (chorus (s-read "rpd.wav") .07 .07 .7 .5))) + +(defun d () (sum (e) (f))) + +(defun rou () (s-read "round.wav" :time-offset 1.18 :dur (- 8.378 1.18))) + +(defun rou4 () (sim (rou) + (at *rd* (rou)) + (at (* *rd* 2) (rou)) + (at (* *rd* 3) (rou)))) + + + diff --git a/nyquist/upic.sal b/nyquist/upic.sal new file mode 100644 index 000000000..87b433d18 --- /dev/null +++ b/nyquist/upic.sal @@ -0,0 +1,53 @@ +;; upic.sal -- play upic data +;; + +define function upic(data) + begin + if data then + ;; use reverse to make a copy of data since sort is destructive + return upic-curve(sort(reverse(data), quote(upic-compare))) + else + return s-rest() + end + + +define function upic-compare(a, b) + return third(a) < third(b) + + +define function upic-curve(data) + begin + with curve = first(data), + waveform = first(curve), + envelope = second(curve), + points = cddr(curve), + from-time = first(points), + to-time = nth(length(points) - 2, points), + dur = to-time - from-time, + next = rest(data), + next-start, snd + ;; shift curve to start at t = 0 + loop + with relpoints + while points + set relpoints @= first(points) - from-time + set relpoints @= second(points) + set points = cddr(points) + finally set points = cdr(reverse(relpoints)) + end + set snd = hzosc(pwlv-list(points), symbol-value(waveform)) * + (funcall(envelope) ~ dur) + if next then + begin + set next-start = third(first(next)) + ;; display "curve", from-time, dur + set snd = seq(set-logical-stop(snd, next-start - from-time), + upic-curve(next)) + end + return snd + end + + +define function upic-env() + return env(0.01, 0.01, 0.01, 1, 1, 1) + diff --git a/nyquist/velocity.lsp b/nyquist/velocity.lsp new file mode 100644 index 000000000..aa5226d63 --- /dev/null +++ b/nyquist/velocity.lsp @@ -0,0 +1,24 @@ +;; velocity.lsp -- conversion routines for MIDI velocity +;; +;; Roger B. Dannenberg +;; July, 2012 + + +(defun db-to-vel (x &optional float) + (linear-to-vel (db-to-linear x) float)) + + +(defun linear-to-vel (x &optional float) + (setf x (/ (- (sqrt (abs x)) 0.0239372) 0.00768553)) + (cond (float x) + (t + (setf x (round x)) + (max 1 (min 127 x))))) + + +(defun vel-to-db (v) + (linear-to-db (vel-to-linear v))) + + +(defun vel-to-linear (v) + (power (+ (* v 0.00768553) 0.0239372) 2)) diff --git a/nyquist/xm.lsp b/nyquist/xm.lsp index dfb01b1af..725bb87f7 100644 --- a/nyquist/xm.lsp +++ b/nyquist/xm.lsp @@ -1375,7 +1375,9 @@ pattern argument (by default). `(let (sg:seq (sg:start ,score-begin) sg:ioi (sg:score-len ,score-len) (sg:score-dur ,score-dur) (sg:count 0) (sg:save ,save) - (sg:begin ,score-begin) (sg:end ,score-end)) + (sg:begin ,score-begin) (sg:end ,score-end) sg:det-end) + ;; sg:det-end is a flag that tells us to determine the end time + (cond ((null sg:end) (setf sg:end 0 sg:det-end t))) ;; make sure at least one of score-len, score-dur is present (loop (cond ((or (and sg:score-len (<= sg:score-len sg:count)) @@ -1392,17 +1394,19 @@ pattern argument (by default). (format t "get-seq trace at ~A stretch ~A: ~A~%" sg:start sg:dur (car sg:seq)))) (incf sg:count) - (setf sg:start ,next-expr)) + (setf sg:start ,next-expr) + ;; end time of score will be max over start times of the next note + ;; this bases the score duration on ioi's rather than durs. But + ;; if user specified sg:end, sg:det-end is false and we do not + ;; try to compute sg:end. + (cond ((and sg:det-end (> sg:start sg:end)) + (setf sg:end sg:start)))) (setf sg:seq (reverse sg:seq)) ;; avoid sorting a sorted list -- XLisp's quicksort can overflow the ;; stack if the list is sorted because (apparently) the pivot points ;; are not random. (cond ((not (score-sorted sg:seq)) (setf sg:seq (bigsort sg:seq #'event-before)))) - (cond ((and sg:seq (null sg:end)) - (setf sg:end (event-end (car (last sg:seq))))) - ((null sg:end) - (setf sg:end 0))) (push (list 0 0 (list 'SCORE-BEGIN-END ,score-begin sg:end)) sg:seq) (cond (sg:save (set sg:save sg:seq))) sg:seq))) @@ -1625,12 +1629,23 @@ pattern argument (by default). ;; SCORE-SORT -- sort a score into time order ;; +;; If begin-end exists, preserve it. If not, compute +;; it from the sorted score. +;; (defun score-sort (score &optional (copy-flag t)) - (setf score (score-must-have-begin-end score)) - (let ((begin-end (car score))) - (setf score (cdr score)) - (if copy-flag (setf score (append score nil))) - (cons begin-end (bigsort score #'event-before)))) + (let* ((score1 (score-must-have-begin-end score)) + (begin-end (car score1)) + ;; if begin-end already existed, then it will + ;; be the first of score. Otherwise, one must + ;; have been generated above by score-must-have-begin-end + ;; in which case we should create it again after sorting. + (needs-begin-end (not (eq begin-end (first score))))) + (setf score1 (cdr score1)) ;; don't include begin-end in sort. + (if copy-flag (setf score1 (append score1 nil))) + (setf score1 (bigsort score1 #'event-before)) + (if needs-begin-end (score-must-have-begin-end score1) + (cons begin-end score1)) + )) ;; PUSH-SORT -- insert an event in (reverse) sorted order @@ -1762,14 +1777,26 @@ pattern argument (by default). from-time to-time)) (cdr score))))) + +;; Get the second element of params (the value field) and turn it +;; into a numeric value if possible (by looking up a global variable +;; binding). This allows scores to say C4 instead of 60. +;; +(defun get-numeric-value (params) + (let ((v (cadr params))) + (cond ((and (symbolp v) (boundp v) (numberp (symbol-value v))) + (setf v (symbol-value v)))) + v)) + (defun params-transpose (params keyword amount) (cond ((null params) nil) - ((and (eq keyword (car params)) - (numberp (cadr params))) - (cons (car params) - (cons (+ amount (cadr params)) - (cddr params)))) + ((eq keyword (car params)) + (let ((v (get-numeric-value params))) + (cond ((numberp v) + (setf v (+ v amount)))) + (cons (car params) + (cons v (cddr params))))) (t (cons (car params) (cons (cadr params) (params-transpose (cddr params) keyword amount)))))) @@ -1789,11 +1816,12 @@ pattern argument (by default). (defun params-scale (params keyword amount) (cond ((null params) nil) - ((and (eq keyword (car params)) - (numberp (cadr params))) - (cons (car params) - (cons (* amount (cadr params)) - (cddr params)))) + ((eq keyword (car params)) + (let ((v (get-numeric-value params))) + (cond ((numberp v) + (setf v (* v amount)))) + (cons (car params) + (cons v (cddr params))))) (t (cons (car params) (cons (cadr params) (params-scale (cddr params) keyword amount)))))) @@ -2124,6 +2152,18 @@ pattern argument (by default). (t nil)))) +;; SCORE-READ -- read a standard MIDI file to a score +;; +(defun score-read (filename) + (let ((seq (seq-create)) + (file (open filename))) + (cond (file + (seq-read seq file) + (close file) + (score-from-seq seq)) + (t nil)))) + + ;; SET-PROGRAM-TO -- a helper function to set a list value (defun set-program-to (lis index value default) ;; if length or lis <= index, extend the lis with default @@ -2167,8 +2207,12 @@ exit (return (score-sort score)))) -(defun score-write-smf (score filename &optional programs) - (let ((file (open-binary filename :direction :output)) +(defun score-write (score filename &optional programs) + (score-write-smf score filename programs t)) + +(defun score-write-smf (score filename &optional programs as-adagio) + (let ((file (if as-adagio (open filename :direction :output) + (open-binary filename :direction :output))) (seq (seq-create)) (chan 1)) (cond (file @@ -2199,7 +2243,7 @@ exit (seq-insert-note seq (round (* time 1000)) 0 (1+ chan) (round pitch) (round (* dur 1000)) (round vel)))))) - (seq-write-smf seq file) + (if as-adagio (seq-write seq file) (seq-write-smf seq file)) (close file)))))