Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns » Sound/c/main

Sound/c/main

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns
Filename: Sound/c/main
Read OK:
File size: 2409 bytes
Load address: 0000
Exec address: 0000
File contents
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#define TRACE 0
#include "trace.h"

#include "wimpt.h"
#include "werr.h"
#include "bbc.h"
#include "os.h"
#include "akbd.h"

#include "swis.h"

extern int quickdiv_init(int divisor);
extern int quickdiv(int numerator);
extern int rbbcinc(int r, int k);
extern int div_frac16(int number, int divisor);
extern int mul_frac16(int x, int a);
extern int mul_frac16c(int x, int a);
extern int sqrt_frac16(unsigned int x);
extern int gauss16(void);
extern void sgauss16(int seed);
extern int cos16(int a);
extern int sin16(int a);
extern int exp16(int a);
extern int ln16(int a);
extern int pow16(int a, int b);
extern int acs16(int a);
extern int asn16(int a);
extern int pitch16(int a);

extern char *voice_base;
extern char *wave_base;
extern char *wave_end;

typedef enum {multi, nonmulti} monitor;
monitor monitortype;

#define diff(a,b) ((a)<(b) ? (b)-(a) : (a)-(b))
#define lone 16
#define one (1<<lone)
#define lwts 10
#define wtsize (1<<lwts)
#define sres 1024	/*pitch resolution (corresponds to vertical screen res of picture)*/
#define ltran 256	/*loop limit for transient behaviour*/
#define lasym 64	/*loop limit for asymptotic behaviour*/

int wavetable[wtsize];
int pitch[sres];
char *linlog;
int sampleperiod;

int oldvoice[8];
int voice;

/***********************************************************************************************************/

monitor read_monitor_type(void)
{
  int r2;
  os_swi3r(6, 161,133,0, 0,0,&r2);
  if ((r2/4 & 3) == 1) return multi;
  else return nonmulti;
}

void restore(void)
{
  int v;
  char *err;
  wimpt_complain(os_swi2r(Sound_RemoveVoice, 0, voice, (int *)&err, &v));
  if (v==0) {
    printf("error in restore\n");
    werr(0, err);
  }
  for (v=1; v<=8; v++) wimpt_complain(os_swi2(Sound_AttachVoice, v, oldvoice[v-1]));
  wimpt_complain(os_swi6(Sound_Configure, 1, 0, 0, 0, 0, 0));
  /*wimpt_complain(os_cli("Voices"));*/
}

/*takes a phase increment p and finds the note of closest phase increment from array l (of n elements,
  which stores phase accumulators for notes in last packet) returning the index of that note;
  this is needed to ensure new notes begin their phase from the end phase of the nearest similar note in
  the last packet of sound*/
int nearnote(int p, unsigned int *l, unsigned int n)
{
  int i=0;
  int j=i+n-1;
  int m;
  int p1, p2;
  if (n==0) return 0; /*this shouldn't ever happen!*/
  if (n==1) return i;
  for (;;) {
    if (n==2) {
      p1=(l[i]<<16)>>16;
      p2=(l[j]<<16)>>16;
      return diff(p1,p)<diff(p2,p) ? i : j;
    }
    m = i+n/2;
    p1 = (l[m]<<16)>>16;
    if (p1==p) return m;
    if (p1<p) i=m;
    else j=m;
    n=j+1-i;
  }
}

BOOL init_globals(void)
{
  int s, i;
  int *channel_handler;

  monitortype = read_monitor_type();

  for (s=0; s<wtsize; s++) wavetable[s] = sin16(s << lone+2-lwts);

  /*when converting graph to sound, let vertical component correspond to pitch and vary from
    0x2000 (2 octaves below middle C) to 0x8000 (4 octaves above middle C) - change 0x2000 or 0x6000 below to alter this relation*/
  for (s=0, i=0x2000; s<sres; s++, i+=0x6000/sres) pitch[s] = pitch16(i);

  wimpt_complain(os_swi6r(Sound_Configure, 0, 0, 0, 0, 0, 0, 0, 0, &sampleperiod, (int *)&channel_handler, 0, 0));
  linlog = (char *)channel_handler[2];

  return TRUE;
}

BOOL input_params(int *dur, int *size, int *dres, int *lmin, int *lmax)
{
  double dbl;
  BOOL ok;

  printf("\n\n");
  printf("                  T h e   S o u n d   o f   C h a o s\n\n\n");
  printf("After image/sample generation is complete the sample will play repeatedly.\n\n");
  printf("At that point, use:\n\n");
  printf("  Escape to end this program,\n");
  printf("  Return to re-run it,\n");
  printf("  Left/Right cursor (+shift) to seek out interesting new lambda regions\n");
  printf("  (followed by any other key to resume playing of current sample).\n\n\n");

  do {
    do {
      printf("Please enter sample duration in centiseconds (eg 3000 for a 30s sample; must be at least 100) ");
      scanf("%i", dur);
    } while (*dur<100);
    *size = (*dur*10000)/sampleperiod;
    if (wave_base=malloc(*size), wave_base==0) {
      printf("Can't allocate sample memory of %i bytes - try a shorter duration or quit & increase free memory, then run again!\n", *size);
      ok=FALSE;
    }
    else ok=TRUE;
  } while (!ok);
  wave_end = wave_base+*size;

  do {
    printf("Please enter sample resolution (100-10000, suggest 1000) ");
    scanf("%i", dres);
  } while (*dres<100 || *dres>10000);

  do {
    printf("Please enter lambda min (0-4) ");
    scanf("%Lf", &dbl);
  } while (dbl<0 || dbl>4);
  *lmin = (int)(dbl*one);

  do {
    printf("Please enter lambda max (0-4) ");
    scanf("%Lf", &dbl);
  } while (dbl<=*lmin/65536.0 || dbl>4);
  *lmax = (int)(dbl*one);

  return TRUE;
}

void add_voice(void)
{
  int v;
  wimpt_complain(os_swi2r(Sound_InstallVoice, (int)voice_base, 0, 0, &voice));
  for (v=1; v<=8; v++) wimpt_complain(os_swi2r(Sound_AttachVoice, v, voice, 0, oldvoice+v-1));
  atexit(restore);
  wimpt_complain(os_swi6(Sound_Configure, 1, 0, 0, 0, 0, 0));
  /*wimpt_complain(os_cli("Voices"));*/
}

int main(void)
{
  int size;
  int uservolume, s;
  int sample;
  int i;
  int dur = 6000;  /*total sample length in centiseconds*/
  int dres = 1000; /*sample duration resolution - make sample up of dres packets of sound (corresponds to horizontal screen res of picture)*/
  char selection[sres];
  unsigned int list1[sres], list2[sres], *list, *listold;
  int nnotes, nnotesold;
  int lmin, lmax, l, x;
  int li, le, ldif, lr;
  int q;
  char *p, *pt;
  int pi, pe, pr;
  int sx, si, se, sr;
  int start_time;

  if (!init_globals()) return 0;

  for (;;) {

    bbc_mode(monitortype==multi ? 20 : 12);
    if (!input_params(&dur, &size, &dres, &lmin, &lmax)) return 0;
    ldif	= lmax-lmin;

    list=list1;
    list2[0]=(0<<16)+pitch[0];
    nnotesold=1;
    listold=list2;

    bbc_cls();
    wimpt_complain(os_swi1r(Sound_Volume, 127, &uservolume));
    for (p=pt=wave_base,pi=size/dres,pr=size%dres,pe=-dres, q=0, l=lmin,li=ldif/dres,lr=ldif%dres,le=-dres, sx=0,si=1280/dres,sr=1280%dres,se=-dres;
         q<dres;
         q++, l+=li,le+=2*lr,le>0?(l++,le-=2*dres):0, sx+=si,se+=2*sr,se>0?(sx++,se-=2*dres):0) {
      memset(selection, 0, sres);
      x = one/2;
      for (s=0; s<ltran; s++) x = mul_frac16c(l, mul_frac16c(x, one-x));
      for (s=0; s<lasym; s++) {
        x = mul_frac16c(l, mul_frac16c(x, one-x));
        i = x*sres/one;
        if (i<0) i=0;
        if (i>=sres) i=sres-1;
        selection[i]=255;
        bbc_plot(69,sx,i);
      }
      nnotes=0; /*now we compile our list of pitches for the current value of lambda*/
      for (s=0; s<sres; s++) if (selection[s]) list[nnotes++]=(0<<16)+pitch[s];
      /*it then remains to set the initial phase of each such note from the end phase of the nearest note in the last packet*/
      for (s=0; s<nnotes; s++) list[s] += (listold[nearnote(list[s], listold, nnotesold)]>>16)<<16;
      if (quickdiv_init(nnotes)<0) werr(1, "unexpected quickdiv_init error");
      for (pt+=pi,pe+=2*pr,pe>0?(pt++,pe-=2*dres):0,pt=(pt>wave_end||q==dres-1)?wave_end:pt; p<pt; p++) {
        for (i=0, sample=0; i<nnotes; i++) sample += wavetable[(list[i]+=list[i]<<16) >> 32-lwts];
        sample = quickdiv(sample);
        sample >>= 4;
        if (sample>=4096) sample=4095;
        if (sample<=-4096) sample=-4095;
        *p = linlog[(unsigned int)(sample<<19)>>19];
      }
      nnotesold=nnotes;
      listold=list;
      list = list==list1 ? list2 : list1;
    }
    wimpt_complain(os_swi1(Sound_Volume, uservolume));

    add_voice();
    bbc_cursor(0);

    for (;;) {
      wimpt_complain(os_swi4(Sound_Control, 1, 0x17f, 0x4000, dur/5));
      start_time=clock();
      bbc_gcol(3, 7);
      for (s=0; s<1280; s+=2) {
        bbc_move(s-2, 0);
        bbc_drawby(0, 1024);
        bbc_move(s, 0);
        bbc_drawby(0, 1024);
        wimpt_complain(os_swi2(OS_Byte,4,1));
        if (akbd_pollkey(&i)) {
          wimpt_complain(os_swi4(Sound_Control, 1, 0, 0x4000, 1));
          sx=s;
          x=640;
          if (i!=13) for (;;) {
            if (x!=sx) {
              bbc_move(sx, 0);
              bbc_drawby(0, 1024);
              bbc_move(x, 0);
              bbc_drawby(0, 1024);
              sx=x;
              bbc_tab(0,0);
              printf("lambda = %f            ", ((int)(x*ldif)/1280.0+(int)lmin)/65536.0);
            }
            if (akbd_pollkey(&i)) {
              if (i==136 && x>0) x-=akbd_pollsh()?2:10;
              if (i==137 && x<1278) x+=akbd_pollsh()?2:10;
              if (i!=136 && i!=137) {
                bbc_move(sx, 0);
                bbc_drawby(0, 1024);
                bbc_tab(0,0);
                printf("                       ");
                break;
              }
            }
          }
          break;
        }
        else i=0;
        for (; clock()-start_time < dur*s/1280; );
      }
      if (s==1280) {
        bbc_move(s-2, 0);
        bbc_drawby(0, 1024);
      }
      if (i==13) break;
    }

    restore();
    if (wave_base) free(wave_base);

  }

  return 0;
}
00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
00000010  68 3e 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |h>.#include <std|
00000020  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
00000030  3c 73 74 72 69 6e 67 2e  68 3e 0a 23 69 6e 63 6c  |<string.h>.#incl|
00000040  75 64 65 20 3c 74 69 6d  65 2e 68 3e 0a 23 69 6e  |ude <time.h>.#in|
00000050  63 6c 75 64 65 20 3c 6d  61 74 68 2e 68 3e 0a 0a  |clude <math.h>..|
00000060  23 64 65 66 69 6e 65 20  54 52 41 43 45 20 30 0a  |#define TRACE 0.|
00000070  23 69 6e 63 6c 75 64 65  20 22 74 72 61 63 65 2e  |#include "trace.|
00000080  68 22 0a 0a 23 69 6e 63  6c 75 64 65 20 22 77 69  |h"..#include "wi|
00000090  6d 70 74 2e 68 22 0a 23  69 6e 63 6c 75 64 65 20  |mpt.h".#include |
000000a0  22 77 65 72 72 2e 68 22  0a 23 69 6e 63 6c 75 64  |"werr.h".#includ|
000000b0  65 20 22 62 62 63 2e 68  22 0a 23 69 6e 63 6c 75  |e "bbc.h".#inclu|
000000c0  64 65 20 22 6f 73 2e 68  22 0a 23 69 6e 63 6c 75  |de "os.h".#inclu|
000000d0  64 65 20 22 61 6b 62 64  2e 68 22 0a 0a 23 69 6e  |de "akbd.h"..#in|
000000e0  63 6c 75 64 65 20 22 73  77 69 73 2e 68 22 0a 0a  |clude "swis.h"..|
000000f0  65 78 74 65 72 6e 20 69  6e 74 20 71 75 69 63 6b  |extern int quick|
00000100  64 69 76 5f 69 6e 69 74  28 69 6e 74 20 64 69 76  |div_init(int div|
00000110  69 73 6f 72 29 3b 0a 65  78 74 65 72 6e 20 69 6e  |isor);.extern in|
00000120  74 20 71 75 69 63 6b 64  69 76 28 69 6e 74 20 6e  |t quickdiv(int n|
00000130  75 6d 65 72 61 74 6f 72  29 3b 0a 65 78 74 65 72  |umerator);.exter|
00000140  6e 20 69 6e 74 20 72 62  62 63 69 6e 63 28 69 6e  |n int rbbcinc(in|
00000150  74 20 72 2c 20 69 6e 74  20 6b 29 3b 0a 65 78 74  |t r, int k);.ext|
00000160  65 72 6e 20 69 6e 74 20  64 69 76 5f 66 72 61 63  |ern int div_frac|
00000170  31 36 28 69 6e 74 20 6e  75 6d 62 65 72 2c 20 69  |16(int number, i|
00000180  6e 74 20 64 69 76 69 73  6f 72 29 3b 0a 65 78 74  |nt divisor);.ext|
00000190  65 72 6e 20 69 6e 74 20  6d 75 6c 5f 66 72 61 63  |ern int mul_frac|
000001a0  31 36 28 69 6e 74 20 78  2c 20 69 6e 74 20 61 29  |16(int x, int a)|
000001b0  3b 0a 65 78 74 65 72 6e  20 69 6e 74 20 6d 75 6c  |;.extern int mul|
000001c0  5f 66 72 61 63 31 36 63  28 69 6e 74 20 78 2c 20  |_frac16c(int x, |
000001d0  69 6e 74 20 61 29 3b 0a  65 78 74 65 72 6e 20 69  |int a);.extern i|
000001e0  6e 74 20 73 71 72 74 5f  66 72 61 63 31 36 28 75  |nt sqrt_frac16(u|
000001f0  6e 73 69 67 6e 65 64 20  69 6e 74 20 78 29 3b 0a  |nsigned int x);.|
00000200  65 78 74 65 72 6e 20 69  6e 74 20 67 61 75 73 73  |extern int gauss|
00000210  31 36 28 76 6f 69 64 29  3b 0a 65 78 74 65 72 6e  |16(void);.extern|
00000220  20 76 6f 69 64 20 73 67  61 75 73 73 31 36 28 69  | void sgauss16(i|
00000230  6e 74 20 73 65 65 64 29  3b 0a 65 78 74 65 72 6e  |nt seed);.extern|
00000240  20 69 6e 74 20 63 6f 73  31 36 28 69 6e 74 20 61  | int cos16(int a|
00000250  29 3b 0a 65 78 74 65 72  6e 20 69 6e 74 20 73 69  |);.extern int si|
00000260  6e 31 36 28 69 6e 74 20  61 29 3b 0a 65 78 74 65  |n16(int a);.exte|
00000270  72 6e 20 69 6e 74 20 65  78 70 31 36 28 69 6e 74  |rn int exp16(int|
00000280  20 61 29 3b 0a 65 78 74  65 72 6e 20 69 6e 74 20  | a);.extern int |
00000290  6c 6e 31 36 28 69 6e 74  20 61 29 3b 0a 65 78 74  |ln16(int a);.ext|
000002a0  65 72 6e 20 69 6e 74 20  70 6f 77 31 36 28 69 6e  |ern int pow16(in|
000002b0  74 20 61 2c 20 69 6e 74  20 62 29 3b 0a 65 78 74  |t a, int b);.ext|
000002c0  65 72 6e 20 69 6e 74 20  61 63 73 31 36 28 69 6e  |ern int acs16(in|
000002d0  74 20 61 29 3b 0a 65 78  74 65 72 6e 20 69 6e 74  |t a);.extern int|
000002e0  20 61 73 6e 31 36 28 69  6e 74 20 61 29 3b 0a 65  | asn16(int a);.e|
000002f0  78 74 65 72 6e 20 69 6e  74 20 70 69 74 63 68 31  |xtern int pitch1|
00000300  36 28 69 6e 74 20 61 29  3b 0a 0a 65 78 74 65 72  |6(int a);..exter|
00000310  6e 20 63 68 61 72 20 2a  76 6f 69 63 65 5f 62 61  |n char *voice_ba|
00000320  73 65 3b 0a 65 78 74 65  72 6e 20 63 68 61 72 20  |se;.extern char |
00000330  2a 77 61 76 65 5f 62 61  73 65 3b 0a 65 78 74 65  |*wave_base;.exte|
00000340  72 6e 20 63 68 61 72 20  2a 77 61 76 65 5f 65 6e  |rn char *wave_en|
00000350  64 3b 0a 0a 74 79 70 65  64 65 66 20 65 6e 75 6d  |d;..typedef enum|
00000360  20 7b 6d 75 6c 74 69 2c  20 6e 6f 6e 6d 75 6c 74  | {multi, nonmult|
00000370  69 7d 20 6d 6f 6e 69 74  6f 72 3b 0a 6d 6f 6e 69  |i} monitor;.moni|
00000380  74 6f 72 20 6d 6f 6e 69  74 6f 72 74 79 70 65 3b  |tor monitortype;|
00000390  0a 0a 23 64 65 66 69 6e  65 20 64 69 66 66 28 61  |..#define diff(a|
000003a0  2c 62 29 20 28 28 61 29  3c 28 62 29 20 3f 20 28  |,b) ((a)<(b) ? (|
000003b0  62 29 2d 28 61 29 20 3a  20 28 61 29 2d 28 62 29  |b)-(a) : (a)-(b)|
000003c0  29 0a 23 64 65 66 69 6e  65 20 6c 6f 6e 65 20 31  |).#define lone 1|
000003d0  36 0a 23 64 65 66 69 6e  65 20 6f 6e 65 20 28 31  |6.#define one (1|
000003e0  3c 3c 6c 6f 6e 65 29 0a  23 64 65 66 69 6e 65 20  |<<lone).#define |
000003f0  6c 77 74 73 20 31 30 0a  23 64 65 66 69 6e 65 20  |lwts 10.#define |
00000400  77 74 73 69 7a 65 20 28  31 3c 3c 6c 77 74 73 29  |wtsize (1<<lwts)|
00000410  0a 23 64 65 66 69 6e 65  20 73 72 65 73 20 31 30  |.#define sres 10|
00000420  32 34 09 2f 2a 70 69 74  63 68 20 72 65 73 6f 6c  |24./*pitch resol|
00000430  75 74 69 6f 6e 20 28 63  6f 72 72 65 73 70 6f 6e  |ution (correspon|
00000440  64 73 20 74 6f 20 76 65  72 74 69 63 61 6c 20 73  |ds to vertical s|
00000450  63 72 65 65 6e 20 72 65  73 20 6f 66 20 70 69 63  |creen res of pic|
00000460  74 75 72 65 29 2a 2f 0a  23 64 65 66 69 6e 65 20  |ture)*/.#define |
00000470  6c 74 72 61 6e 20 32 35  36 09 2f 2a 6c 6f 6f 70  |ltran 256./*loop|
00000480  20 6c 69 6d 69 74 20 66  6f 72 20 74 72 61 6e 73  | limit for trans|
00000490  69 65 6e 74 20 62 65 68  61 76 69 6f 75 72 2a 2f  |ient behaviour*/|
000004a0  0a 23 64 65 66 69 6e 65  20 6c 61 73 79 6d 20 36  |.#define lasym 6|
000004b0  34 09 2f 2a 6c 6f 6f 70  20 6c 69 6d 69 74 20 66  |4./*loop limit f|
000004c0  6f 72 20 61 73 79 6d 70  74 6f 74 69 63 20 62 65  |or asymptotic be|
000004d0  68 61 76 69 6f 75 72 2a  2f 0a 0a 69 6e 74 20 77  |haviour*/..int w|
000004e0  61 76 65 74 61 62 6c 65  5b 77 74 73 69 7a 65 5d  |avetable[wtsize]|
000004f0  3b 0a 69 6e 74 20 70 69  74 63 68 5b 73 72 65 73  |;.int pitch[sres|
00000500  5d 3b 0a 63 68 61 72 20  2a 6c 69 6e 6c 6f 67 3b  |];.char *linlog;|
00000510  0a 69 6e 74 20 73 61 6d  70 6c 65 70 65 72 69 6f  |.int sampleperio|
00000520  64 3b 0a 0a 69 6e 74 20  6f 6c 64 76 6f 69 63 65  |d;..int oldvoice|
00000530  5b 38 5d 3b 0a 69 6e 74  20 76 6f 69 63 65 3b 0a  |[8];.int voice;.|
00000540  0a 2f 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |./**************|
00000550  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000005a0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2f 0a 0a  |*************/..|
000005b0  6d 6f 6e 69 74 6f 72 20  72 65 61 64 5f 6d 6f 6e  |monitor read_mon|
000005c0  69 74 6f 72 5f 74 79 70  65 28 76 6f 69 64 29 0a  |itor_type(void).|
000005d0  7b 0a 20 20 69 6e 74 20  72 32 3b 0a 20 20 6f 73  |{.  int r2;.  os|
000005e0  5f 73 77 69 33 72 28 36  2c 20 31 36 31 2c 31 33  |_swi3r(6, 161,13|
000005f0  33 2c 30 2c 20 30 2c 30  2c 26 72 32 29 3b 0a 20  |3,0, 0,0,&r2);. |
00000600  20 69 66 20 28 28 72 32  2f 34 20 26 20 33 29 20  | if ((r2/4 & 3) |
00000610  3d 3d 20 31 29 20 72 65  74 75 72 6e 20 6d 75 6c  |== 1) return mul|
00000620  74 69 3b 0a 20 20 65 6c  73 65 20 72 65 74 75 72  |ti;.  else retur|
00000630  6e 20 6e 6f 6e 6d 75 6c  74 69 3b 0a 7d 0a 0a 76  |n nonmulti;.}..v|
00000640  6f 69 64 20 72 65 73 74  6f 72 65 28 76 6f 69 64  |oid restore(void|
00000650  29 0a 7b 0a 20 20 69 6e  74 20 76 3b 0a 20 20 63  |).{.  int v;.  c|
00000660  68 61 72 20 2a 65 72 72  3b 0a 20 20 77 69 6d 70  |har *err;.  wimp|
00000670  74 5f 63 6f 6d 70 6c 61  69 6e 28 6f 73 5f 73 77  |t_complain(os_sw|
00000680  69 32 72 28 53 6f 75 6e  64 5f 52 65 6d 6f 76 65  |i2r(Sound_Remove|
00000690  56 6f 69 63 65 2c 20 30  2c 20 76 6f 69 63 65 2c  |Voice, 0, voice,|
000006a0  20 28 69 6e 74 20 2a 29  26 65 72 72 2c 20 26 76  | (int *)&err, &v|
000006b0  29 29 3b 0a 20 20 69 66  20 28 76 3d 3d 30 29 20  |));.  if (v==0) |
000006c0  7b 0a 20 20 20 20 70 72  69 6e 74 66 28 22 65 72  |{.    printf("er|
000006d0  72 6f 72 20 69 6e 20 72  65 73 74 6f 72 65 5c 6e  |ror in restore\n|
000006e0  22 29 3b 0a 20 20 20 20  77 65 72 72 28 30 2c 20  |");.    werr(0, |
000006f0  65 72 72 29 3b 0a 20 20  7d 0a 20 20 66 6f 72 20  |err);.  }.  for |
00000700  28 76 3d 31 3b 20 76 3c  3d 38 3b 20 76 2b 2b 29  |(v=1; v<=8; v++)|
00000710  20 77 69 6d 70 74 5f 63  6f 6d 70 6c 61 69 6e 28  | wimpt_complain(|
00000720  6f 73 5f 73 77 69 32 28  53 6f 75 6e 64 5f 41 74  |os_swi2(Sound_At|
00000730  74 61 63 68 56 6f 69 63  65 2c 20 76 2c 20 6f 6c  |tachVoice, v, ol|
00000740  64 76 6f 69 63 65 5b 76  2d 31 5d 29 29 3b 0a 20  |dvoice[v-1]));. |
00000750  20 77 69 6d 70 74 5f 63  6f 6d 70 6c 61 69 6e 28  | wimpt_complain(|
00000760  6f 73 5f 73 77 69 36 28  53 6f 75 6e 64 5f 43 6f  |os_swi6(Sound_Co|
00000770  6e 66 69 67 75 72 65 2c  20 31 2c 20 30 2c 20 30  |nfigure, 1, 0, 0|
00000780  2c 20 30 2c 20 30 2c 20  30 29 29 3b 0a 20 20 2f  |, 0, 0, 0));.  /|
00000790  2a 77 69 6d 70 74 5f 63  6f 6d 70 6c 61 69 6e 28  |*wimpt_complain(|
000007a0  6f 73 5f 63 6c 69 28 22  56 6f 69 63 65 73 22 29  |os_cli("Voices")|
000007b0  29 3b 2a 2f 0a 7d 0a 0a  2f 2a 74 61 6b 65 73 20  |);*/.}../*takes |
000007c0  61 20 70 68 61 73 65 20  69 6e 63 72 65 6d 65 6e  |a phase incremen|
000007d0  74 20 70 20 61 6e 64 20  66 69 6e 64 73 20 74 68  |t p and finds th|
000007e0  65 20 6e 6f 74 65 20 6f  66 20 63 6c 6f 73 65 73  |e note of closes|
000007f0  74 20 70 68 61 73 65 20  69 6e 63 72 65 6d 65 6e  |t phase incremen|
00000800  74 20 66 72 6f 6d 20 61  72 72 61 79 20 6c 20 28  |t from array l (|
00000810  6f 66 20 6e 20 65 6c 65  6d 65 6e 74 73 2c 0a 20  |of n elements,. |
00000820  20 77 68 69 63 68 20 73  74 6f 72 65 73 20 70 68  | which stores ph|
00000830  61 73 65 20 61 63 63 75  6d 75 6c 61 74 6f 72 73  |ase accumulators|
00000840  20 66 6f 72 20 6e 6f 74  65 73 20 69 6e 20 6c 61  | for notes in la|
00000850  73 74 20 70 61 63 6b 65  74 29 20 72 65 74 75 72  |st packet) retur|
00000860  6e 69 6e 67 20 74 68 65  20 69 6e 64 65 78 20 6f  |ning the index o|
00000870  66 20 74 68 61 74 20 6e  6f 74 65 3b 0a 20 20 74  |f that note;.  t|
00000880  68 69 73 20 69 73 20 6e  65 65 64 65 64 20 74 6f  |his is needed to|
00000890  20 65 6e 73 75 72 65 20  6e 65 77 20 6e 6f 74 65  | ensure new note|
000008a0  73 20 62 65 67 69 6e 20  74 68 65 69 72 20 70 68  |s begin their ph|
000008b0  61 73 65 20 66 72 6f 6d  20 74 68 65 20 65 6e 64  |ase from the end|
000008c0  20 70 68 61 73 65 20 6f  66 20 74 68 65 20 6e 65  | phase of the ne|
000008d0  61 72 65 73 74 20 73 69  6d 69 6c 61 72 20 6e 6f  |arest similar no|
000008e0  74 65 20 69 6e 0a 20 20  74 68 65 20 6c 61 73 74  |te in.  the last|
000008f0  20 70 61 63 6b 65 74 20  6f 66 20 73 6f 75 6e 64  | packet of sound|
00000900  2a 2f 0a 69 6e 74 20 6e  65 61 72 6e 6f 74 65 28  |*/.int nearnote(|
00000910  69 6e 74 20 70 2c 20 75  6e 73 69 67 6e 65 64 20  |int p, unsigned |
00000920  69 6e 74 20 2a 6c 2c 20  75 6e 73 69 67 6e 65 64  |int *l, unsigned|
00000930  20 69 6e 74 20 6e 29 0a  7b 0a 20 20 69 6e 74 20  | int n).{.  int |
00000940  69 3d 30 3b 0a 20 20 69  6e 74 20 6a 3d 69 2b 6e  |i=0;.  int j=i+n|
00000950  2d 31 3b 0a 20 20 69 6e  74 20 6d 3b 0a 20 20 69  |-1;.  int m;.  i|
00000960  6e 74 20 70 31 2c 20 70  32 3b 0a 20 20 69 66 20  |nt p1, p2;.  if |
00000970  28 6e 3d 3d 30 29 20 72  65 74 75 72 6e 20 30 3b  |(n==0) return 0;|
00000980  20 2f 2a 74 68 69 73 20  73 68 6f 75 6c 64 6e 27  | /*this shouldn'|
00000990  74 20 65 76 65 72 20 68  61 70 70 65 6e 21 2a 2f  |t ever happen!*/|
000009a0  0a 20 20 69 66 20 28 6e  3d 3d 31 29 20 72 65 74  |.  if (n==1) ret|
000009b0  75 72 6e 20 69 3b 0a 20  20 66 6f 72 20 28 3b 3b  |urn i;.  for (;;|
000009c0  29 20 7b 0a 20 20 20 20  69 66 20 28 6e 3d 3d 32  |) {.    if (n==2|
000009d0  29 20 7b 0a 20 20 20 20  20 20 70 31 3d 28 6c 5b  |) {.      p1=(l[|
000009e0  69 5d 3c 3c 31 36 29 3e  3e 31 36 3b 0a 20 20 20  |i]<<16)>>16;.   |
000009f0  20 20 20 70 32 3d 28 6c  5b 6a 5d 3c 3c 31 36 29  |   p2=(l[j]<<16)|
00000a00  3e 3e 31 36 3b 0a 20 20  20 20 20 20 72 65 74 75  |>>16;.      retu|
00000a10  72 6e 20 64 69 66 66 28  70 31 2c 70 29 3c 64 69  |rn diff(p1,p)<di|
00000a20  66 66 28 70 32 2c 70 29  20 3f 20 69 20 3a 20 6a  |ff(p2,p) ? i : j|
00000a30  3b 0a 20 20 20 20 7d 0a  20 20 20 20 6d 20 3d 20  |;.    }.    m = |
00000a40  69 2b 6e 2f 32 3b 0a 20  20 20 20 70 31 20 3d 20  |i+n/2;.    p1 = |
00000a50  28 6c 5b 6d 5d 3c 3c 31  36 29 3e 3e 31 36 3b 0a  |(l[m]<<16)>>16;.|
00000a60  20 20 20 20 69 66 20 28  70 31 3d 3d 70 29 20 72  |    if (p1==p) r|
00000a70  65 74 75 72 6e 20 6d 3b  0a 20 20 20 20 69 66 20  |eturn m;.    if |
00000a80  28 70 31 3c 70 29 20 69  3d 6d 3b 0a 20 20 20 20  |(p1<p) i=m;.    |
00000a90  65 6c 73 65 20 6a 3d 6d  3b 0a 20 20 20 20 6e 3d  |else j=m;.    n=|
00000aa0  6a 2b 31 2d 69 3b 0a 20  20 7d 0a 7d 0a 0a 42 4f  |j+1-i;.  }.}..BO|
00000ab0  4f 4c 20 69 6e 69 74 5f  67 6c 6f 62 61 6c 73 28  |OL init_globals(|
00000ac0  76 6f 69 64 29 0a 7b 0a  20 20 69 6e 74 20 73 2c  |void).{.  int s,|
00000ad0  20 69 3b 0a 20 20 69 6e  74 20 2a 63 68 61 6e 6e  | i;.  int *chann|
00000ae0  65 6c 5f 68 61 6e 64 6c  65 72 3b 0a 0a 20 20 6d  |el_handler;..  m|
00000af0  6f 6e 69 74 6f 72 74 79  70 65 20 3d 20 72 65 61  |onitortype = rea|
00000b00  64 5f 6d 6f 6e 69 74 6f  72 5f 74 79 70 65 28 29  |d_monitor_type()|
00000b10  3b 0a 0a 20 20 66 6f 72  20 28 73 3d 30 3b 20 73  |;..  for (s=0; s|
00000b20  3c 77 74 73 69 7a 65 3b  20 73 2b 2b 29 20 77 61  |<wtsize; s++) wa|
00000b30  76 65 74 61 62 6c 65 5b  73 5d 20 3d 20 73 69 6e  |vetable[s] = sin|
00000b40  31 36 28 73 20 3c 3c 20  6c 6f 6e 65 2b 32 2d 6c  |16(s << lone+2-l|
00000b50  77 74 73 29 3b 0a 0a 20  20 2f 2a 77 68 65 6e 20  |wts);..  /*when |
00000b60  63 6f 6e 76 65 72 74 69  6e 67 20 67 72 61 70 68  |converting graph|
00000b70  20 74 6f 20 73 6f 75 6e  64 2c 20 6c 65 74 20 76  | to sound, let v|
00000b80  65 72 74 69 63 61 6c 20  63 6f 6d 70 6f 6e 65 6e  |ertical componen|
00000b90  74 20 63 6f 72 72 65 73  70 6f 6e 64 20 74 6f 20  |t correspond to |
00000ba0  70 69 74 63 68 20 61 6e  64 20 76 61 72 79 20 66  |pitch and vary f|
00000bb0  72 6f 6d 0a 20 20 20 20  30 78 32 30 30 30 20 28  |rom.    0x2000 (|
00000bc0  32 20 6f 63 74 61 76 65  73 20 62 65 6c 6f 77 20  |2 octaves below |
00000bd0  6d 69 64 64 6c 65 20 43  29 20 74 6f 20 30 78 38  |middle C) to 0x8|
00000be0  30 30 30 20 28 34 20 6f  63 74 61 76 65 73 20 61  |000 (4 octaves a|
00000bf0  62 6f 76 65 20 6d 69 64  64 6c 65 20 43 29 20 2d  |bove middle C) -|
00000c00  20 63 68 61 6e 67 65 20  30 78 32 30 30 30 20 6f  | change 0x2000 o|
00000c10  72 20 30 78 36 30 30 30  20 62 65 6c 6f 77 20 74  |r 0x6000 below t|
00000c20  6f 20 61 6c 74 65 72 20  74 68 69 73 20 72 65 6c  |o alter this rel|
00000c30  61 74 69 6f 6e 2a 2f 0a  20 20 66 6f 72 20 28 73  |ation*/.  for (s|
00000c40  3d 30 2c 20 69 3d 30 78  32 30 30 30 3b 20 73 3c  |=0, i=0x2000; s<|
00000c50  73 72 65 73 3b 20 73 2b  2b 2c 20 69 2b 3d 30 78  |sres; s++, i+=0x|
00000c60  36 30 30 30 2f 73 72 65  73 29 20 70 69 74 63 68  |6000/sres) pitch|
00000c70  5b 73 5d 20 3d 20 70 69  74 63 68 31 36 28 69 29  |[s] = pitch16(i)|
00000c80  3b 0a 0a 20 20 77 69 6d  70 74 5f 63 6f 6d 70 6c  |;..  wimpt_compl|
00000c90  61 69 6e 28 6f 73 5f 73  77 69 36 72 28 53 6f 75  |ain(os_swi6r(Sou|
00000ca0  6e 64 5f 43 6f 6e 66 69  67 75 72 65 2c 20 30 2c  |nd_Configure, 0,|
00000cb0  20 30 2c 20 30 2c 20 30  2c 20 30 2c 20 30 2c 20  | 0, 0, 0, 0, 0, |
00000cc0  30 2c 20 30 2c 20 26 73  61 6d 70 6c 65 70 65 72  |0, 0, &sampleper|
00000cd0  69 6f 64 2c 20 28 69 6e  74 20 2a 29 26 63 68 61  |iod, (int *)&cha|
00000ce0  6e 6e 65 6c 5f 68 61 6e  64 6c 65 72 2c 20 30 2c  |nnel_handler, 0,|
00000cf0  20 30 29 29 3b 0a 20 20  6c 69 6e 6c 6f 67 20 3d  | 0));.  linlog =|
00000d00  20 28 63 68 61 72 20 2a  29 63 68 61 6e 6e 65 6c  | (char *)channel|
00000d10  5f 68 61 6e 64 6c 65 72  5b 32 5d 3b 0a 0a 20 20  |_handler[2];..  |
00000d20  72 65 74 75 72 6e 20 54  52 55 45 3b 0a 7d 0a 0a  |return TRUE;.}..|
00000d30  42 4f 4f 4c 20 69 6e 70  75 74 5f 70 61 72 61 6d  |BOOL input_param|
00000d40  73 28 69 6e 74 20 2a 64  75 72 2c 20 69 6e 74 20  |s(int *dur, int |
00000d50  2a 73 69 7a 65 2c 20 69  6e 74 20 2a 64 72 65 73  |*size, int *dres|
00000d60  2c 20 69 6e 74 20 2a 6c  6d 69 6e 2c 20 69 6e 74  |, int *lmin, int|
00000d70  20 2a 6c 6d 61 78 29 0a  7b 0a 20 20 64 6f 75 62  | *lmax).{.  doub|
00000d80  6c 65 20 64 62 6c 3b 0a  20 20 42 4f 4f 4c 20 6f  |le dbl;.  BOOL o|
00000d90  6b 3b 0a 0a 20 20 70 72  69 6e 74 66 28 22 5c 6e  |k;..  printf("\n|
00000da0  5c 6e 22 29 3b 0a 20 20  70 72 69 6e 74 66 28 22  |\n");.  printf("|
00000db0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000dc0  20 20 54 20 68 20 65 20  20 20 53 20 6f 20 75 20  |  T h e   S o u |
00000dd0  6e 20 64 20 20 20 6f 20  66 20 20 20 43 20 68 20  |n d   o f   C h |
00000de0  61 20 6f 20 73 5c 6e 5c  6e 5c 6e 22 29 3b 0a 20  |a o s\n\n\n");. |
00000df0  20 70 72 69 6e 74 66 28  22 41 66 74 65 72 20 69  | printf("After i|
00000e00  6d 61 67 65 2f 73 61 6d  70 6c 65 20 67 65 6e 65  |mage/sample gene|
00000e10  72 61 74 69 6f 6e 20 69  73 20 63 6f 6d 70 6c 65  |ration is comple|
00000e20  74 65 20 74 68 65 20 73  61 6d 70 6c 65 20 77 69  |te the sample wi|
00000e30  6c 6c 20 70 6c 61 79 20  72 65 70 65 61 74 65 64  |ll play repeated|
00000e40  6c 79 2e 5c 6e 5c 6e 22  29 3b 0a 20 20 70 72 69  |ly.\n\n");.  pri|
00000e50  6e 74 66 28 22 41 74 20  74 68 61 74 20 70 6f 69  |ntf("At that poi|
00000e60  6e 74 2c 20 75 73 65 3a  5c 6e 5c 6e 22 29 3b 0a  |nt, use:\n\n");.|
00000e70  20 20 70 72 69 6e 74 66  28 22 20 20 45 73 63 61  |  printf("  Esca|
00000e80  70 65 20 74 6f 20 65 6e  64 20 74 68 69 73 20 70  |pe to end this p|
00000e90  72 6f 67 72 61 6d 2c 5c  6e 22 29 3b 0a 20 20 70  |rogram,\n");.  p|
00000ea0  72 69 6e 74 66 28 22 20  20 52 65 74 75 72 6e 20  |rintf("  Return |
00000eb0  74 6f 20 72 65 2d 72 75  6e 20 69 74 2c 5c 6e 22  |to re-run it,\n"|
00000ec0  29 3b 0a 20 20 70 72 69  6e 74 66 28 22 20 20 4c  |);.  printf("  L|
00000ed0  65 66 74 2f 52 69 67 68  74 20 63 75 72 73 6f 72  |eft/Right cursor|
00000ee0  20 28 2b 73 68 69 66 74  29 20 74 6f 20 73 65 65  | (+shift) to see|
00000ef0  6b 20 6f 75 74 20 69 6e  74 65 72 65 73 74 69 6e  |k out interestin|
00000f00  67 20 6e 65 77 20 6c 61  6d 62 64 61 20 72 65 67  |g new lambda reg|
00000f10  69 6f 6e 73 5c 6e 22 29  3b 0a 20 20 70 72 69 6e  |ions\n");.  prin|
00000f20  74 66 28 22 20 20 28 66  6f 6c 6c 6f 77 65 64 20  |tf("  (followed |
00000f30  62 79 20 61 6e 79 20 6f  74 68 65 72 20 6b 65 79  |by any other key|
00000f40  20 74 6f 20 72 65 73 75  6d 65 20 70 6c 61 79 69  | to resume playi|
00000f50  6e 67 20 6f 66 20 63 75  72 72 65 6e 74 20 73 61  |ng of current sa|
00000f60  6d 70 6c 65 29 2e 5c 6e  5c 6e 5c 6e 22 29 3b 0a  |mple).\n\n\n");.|
00000f70  0a 20 20 64 6f 20 7b 0a  20 20 20 20 64 6f 20 7b  |.  do {.    do {|
00000f80  0a 20 20 20 20 20 20 70  72 69 6e 74 66 28 22 50  |.      printf("P|
00000f90  6c 65 61 73 65 20 65 6e  74 65 72 20 73 61 6d 70  |lease enter samp|
00000fa0  6c 65 20 64 75 72 61 74  69 6f 6e 20 69 6e 20 63  |le duration in c|
00000fb0  65 6e 74 69 73 65 63 6f  6e 64 73 20 28 65 67 20  |entiseconds (eg |
00000fc0  33 30 30 30 20 66 6f 72  20 61 20 33 30 73 20 73  |3000 for a 30s s|
00000fd0  61 6d 70 6c 65 3b 20 6d  75 73 74 20 62 65 20 61  |ample; must be a|
00000fe0  74 20 6c 65 61 73 74 20  31 30 30 29 20 22 29 3b  |t least 100) ");|
00000ff0  0a 20 20 20 20 20 20 73  63 61 6e 66 28 22 25 69  |.      scanf("%i|
00001000  22 2c 20 64 75 72 29 3b  0a 20 20 20 20 7d 20 77  |", dur);.    } w|
00001010  68 69 6c 65 20 28 2a 64  75 72 3c 31 30 30 29 3b  |hile (*dur<100);|
00001020  0a 20 20 20 20 2a 73 69  7a 65 20 3d 20 28 2a 64  |.    *size = (*d|
00001030  75 72 2a 31 30 30 30 30  29 2f 73 61 6d 70 6c 65  |ur*10000)/sample|
00001040  70 65 72 69 6f 64 3b 0a  20 20 20 20 69 66 20 28  |period;.    if (|
00001050  77 61 76 65 5f 62 61 73  65 3d 6d 61 6c 6c 6f 63  |wave_base=malloc|
00001060  28 2a 73 69 7a 65 29 2c  20 77 61 76 65 5f 62 61  |(*size), wave_ba|
00001070  73 65 3d 3d 30 29 20 7b  0a 20 20 20 20 20 20 70  |se==0) {.      p|
00001080  72 69 6e 74 66 28 22 43  61 6e 27 74 20 61 6c 6c  |rintf("Can't all|
00001090  6f 63 61 74 65 20 73 61  6d 70 6c 65 20 6d 65 6d  |ocate sample mem|
000010a0  6f 72 79 20 6f 66 20 25  69 20 62 79 74 65 73 20  |ory of %i bytes |
000010b0  2d 20 74 72 79 20 61 20  73 68 6f 72 74 65 72 20  |- try a shorter |
000010c0  64 75 72 61 74 69 6f 6e  20 6f 72 20 71 75 69 74  |duration or quit|
000010d0  20 26 20 69 6e 63 72 65  61 73 65 20 66 72 65 65  | & increase free|
000010e0  20 6d 65 6d 6f 72 79 2c  20 74 68 65 6e 20 72 75  | memory, then ru|
000010f0  6e 20 61 67 61 69 6e 21  5c 6e 22 2c 20 2a 73 69  |n again!\n", *si|
00001100  7a 65 29 3b 0a 20 20 20  20 20 20 6f 6b 3d 46 41  |ze);.      ok=FA|
00001110  4c 53 45 3b 0a 20 20 20  20 7d 0a 20 20 20 20 65  |LSE;.    }.    e|
00001120  6c 73 65 20 6f 6b 3d 54  52 55 45 3b 0a 20 20 7d  |lse ok=TRUE;.  }|
00001130  20 77 68 69 6c 65 20 28  21 6f 6b 29 3b 0a 20 20  | while (!ok);.  |
00001140  77 61 76 65 5f 65 6e 64  20 3d 20 77 61 76 65 5f  |wave_end = wave_|
00001150  62 61 73 65 2b 2a 73 69  7a 65 3b 0a 0a 20 20 64  |base+*size;..  d|
00001160  6f 20 7b 0a 20 20 20 20  70 72 69 6e 74 66 28 22  |o {.    printf("|
00001170  50 6c 65 61 73 65 20 65  6e 74 65 72 20 73 61 6d  |Please enter sam|
00001180  70 6c 65 20 72 65 73 6f  6c 75 74 69 6f 6e 20 28  |ple resolution (|
00001190  31 30 30 2d 31 30 30 30  30 2c 20 73 75 67 67 65  |100-10000, sugge|
000011a0  73 74 20 31 30 30 30 29  20 22 29 3b 0a 20 20 20  |st 1000) ");.   |
000011b0  20 73 63 61 6e 66 28 22  25 69 22 2c 20 64 72 65  | scanf("%i", dre|
000011c0  73 29 3b 0a 20 20 7d 20  77 68 69 6c 65 20 28 2a  |s);.  } while (*|
000011d0  64 72 65 73 3c 31 30 30  20 7c 7c 20 2a 64 72 65  |dres<100 || *dre|
000011e0  73 3e 31 30 30 30 30 29  3b 0a 0a 20 20 64 6f 20  |s>10000);..  do |
000011f0  7b 0a 20 20 20 20 70 72  69 6e 74 66 28 22 50 6c  |{.    printf("Pl|
00001200  65 61 73 65 20 65 6e 74  65 72 20 6c 61 6d 62 64  |ease enter lambd|
00001210  61 20 6d 69 6e 20 28 30  2d 34 29 20 22 29 3b 0a  |a min (0-4) ");.|
00001220  20 20 20 20 73 63 61 6e  66 28 22 25 4c 66 22 2c  |    scanf("%Lf",|
00001230  20 26 64 62 6c 29 3b 0a  20 20 7d 20 77 68 69 6c  | &dbl);.  } whil|
00001240  65 20 28 64 62 6c 3c 30  20 7c 7c 20 64 62 6c 3e  |e (dbl<0 || dbl>|
00001250  34 29 3b 0a 20 20 2a 6c  6d 69 6e 20 3d 20 28 69  |4);.  *lmin = (i|
00001260  6e 74 29 28 64 62 6c 2a  6f 6e 65 29 3b 0a 0a 20  |nt)(dbl*one);.. |
00001270  20 64 6f 20 7b 0a 20 20  20 20 70 72 69 6e 74 66  | do {.    printf|
00001280  28 22 50 6c 65 61 73 65  20 65 6e 74 65 72 20 6c  |("Please enter l|
00001290  61 6d 62 64 61 20 6d 61  78 20 28 30 2d 34 29 20  |ambda max (0-4) |
000012a0  22 29 3b 0a 20 20 20 20  73 63 61 6e 66 28 22 25  |");.    scanf("%|
000012b0  4c 66 22 2c 20 26 64 62  6c 29 3b 0a 20 20 7d 20  |Lf", &dbl);.  } |
000012c0  77 68 69 6c 65 20 28 64  62 6c 3c 3d 2a 6c 6d 69  |while (dbl<=*lmi|
000012d0  6e 2f 36 35 35 33 36 2e  30 20 7c 7c 20 64 62 6c  |n/65536.0 || dbl|
000012e0  3e 34 29 3b 0a 20 20 2a  6c 6d 61 78 20 3d 20 28  |>4);.  *lmax = (|
000012f0  69 6e 74 29 28 64 62 6c  2a 6f 6e 65 29 3b 0a 0a  |int)(dbl*one);..|
00001300  20 20 72 65 74 75 72 6e  20 54 52 55 45 3b 0a 7d  |  return TRUE;.}|
00001310  0a 0a 76 6f 69 64 20 61  64 64 5f 76 6f 69 63 65  |..void add_voice|
00001320  28 76 6f 69 64 29 0a 7b  0a 20 20 69 6e 74 20 76  |(void).{.  int v|
00001330  3b 0a 20 20 77 69 6d 70  74 5f 63 6f 6d 70 6c 61  |;.  wimpt_compla|
00001340  69 6e 28 6f 73 5f 73 77  69 32 72 28 53 6f 75 6e  |in(os_swi2r(Soun|
00001350  64 5f 49 6e 73 74 61 6c  6c 56 6f 69 63 65 2c 20  |d_InstallVoice, |
00001360  28 69 6e 74 29 76 6f 69  63 65 5f 62 61 73 65 2c  |(int)voice_base,|
00001370  20 30 2c 20 30 2c 20 26  76 6f 69 63 65 29 29 3b  | 0, 0, &voice));|
00001380  0a 20 20 66 6f 72 20 28  76 3d 31 3b 20 76 3c 3d  |.  for (v=1; v<=|
00001390  38 3b 20 76 2b 2b 29 20  77 69 6d 70 74 5f 63 6f  |8; v++) wimpt_co|
000013a0  6d 70 6c 61 69 6e 28 6f  73 5f 73 77 69 32 72 28  |mplain(os_swi2r(|
000013b0  53 6f 75 6e 64 5f 41 74  74 61 63 68 56 6f 69 63  |Sound_AttachVoic|
000013c0  65 2c 20 76 2c 20 76 6f  69 63 65 2c 20 30 2c 20  |e, v, voice, 0, |
000013d0  6f 6c 64 76 6f 69 63 65  2b 76 2d 31 29 29 3b 0a  |oldvoice+v-1));.|
000013e0  20 20 61 74 65 78 69 74  28 72 65 73 74 6f 72 65  |  atexit(restore|
000013f0  29 3b 0a 20 20 77 69 6d  70 74 5f 63 6f 6d 70 6c  |);.  wimpt_compl|
00001400  61 69 6e 28 6f 73 5f 73  77 69 36 28 53 6f 75 6e  |ain(os_swi6(Soun|
00001410  64 5f 43 6f 6e 66 69 67  75 72 65 2c 20 31 2c 20  |d_Configure, 1, |
00001420  30 2c 20 30 2c 20 30 2c  20 30 2c 20 30 29 29 3b  |0, 0, 0, 0, 0));|
00001430  0a 20 20 2f 2a 77 69 6d  70 74 5f 63 6f 6d 70 6c  |.  /*wimpt_compl|
00001440  61 69 6e 28 6f 73 5f 63  6c 69 28 22 56 6f 69 63  |ain(os_cli("Voic|
00001450  65 73 22 29 29 3b 2a 2f  0a 7d 0a 0a 69 6e 74 20  |es"));*/.}..int |
00001460  6d 61 69 6e 28 76 6f 69  64 29 0a 7b 0a 20 20 69  |main(void).{.  i|
00001470  6e 74 20 73 69 7a 65 3b  0a 20 20 69 6e 74 20 75  |nt size;.  int u|
00001480  73 65 72 76 6f 6c 75 6d  65 2c 20 73 3b 0a 20 20  |servolume, s;.  |
00001490  69 6e 74 20 73 61 6d 70  6c 65 3b 0a 20 20 69 6e  |int sample;.  in|
000014a0  74 20 69 3b 0a 20 20 69  6e 74 20 64 75 72 20 3d  |t i;.  int dur =|
000014b0  20 36 30 30 30 3b 20 20  2f 2a 74 6f 74 61 6c 20  | 6000;  /*total |
000014c0  73 61 6d 70 6c 65 20 6c  65 6e 67 74 68 20 69 6e  |sample length in|
000014d0  20 63 65 6e 74 69 73 65  63 6f 6e 64 73 2a 2f 0a  | centiseconds*/.|
000014e0  20 20 69 6e 74 20 64 72  65 73 20 3d 20 31 30 30  |  int dres = 100|
000014f0  30 3b 20 2f 2a 73 61 6d  70 6c 65 20 64 75 72 61  |0; /*sample dura|
00001500  74 69 6f 6e 20 72 65 73  6f 6c 75 74 69 6f 6e 20  |tion resolution |
00001510  2d 20 6d 61 6b 65 20 73  61 6d 70 6c 65 20 75 70  |- make sample up|
00001520  20 6f 66 20 64 72 65 73  20 70 61 63 6b 65 74 73  | of dres packets|
00001530  20 6f 66 20 73 6f 75 6e  64 20 28 63 6f 72 72 65  | of sound (corre|
00001540  73 70 6f 6e 64 73 20 74  6f 20 68 6f 72 69 7a 6f  |sponds to horizo|
00001550  6e 74 61 6c 20 73 63 72  65 65 6e 20 72 65 73 20  |ntal screen res |
00001560  6f 66 20 70 69 63 74 75  72 65 29 2a 2f 0a 20 20  |of picture)*/.  |
00001570  63 68 61 72 20 73 65 6c  65 63 74 69 6f 6e 5b 73  |char selection[s|
00001580  72 65 73 5d 3b 0a 20 20  75 6e 73 69 67 6e 65 64  |res];.  unsigned|
00001590  20 69 6e 74 20 6c 69 73  74 31 5b 73 72 65 73 5d  | int list1[sres]|
000015a0  2c 20 6c 69 73 74 32 5b  73 72 65 73 5d 2c 20 2a  |, list2[sres], *|
000015b0  6c 69 73 74 2c 20 2a 6c  69 73 74 6f 6c 64 3b 0a  |list, *listold;.|
000015c0  20 20 69 6e 74 20 6e 6e  6f 74 65 73 2c 20 6e 6e  |  int nnotes, nn|
000015d0  6f 74 65 73 6f 6c 64 3b  0a 20 20 69 6e 74 20 6c  |otesold;.  int l|
000015e0  6d 69 6e 2c 20 6c 6d 61  78 2c 20 6c 2c 20 78 3b  |min, lmax, l, x;|
000015f0  0a 20 20 69 6e 74 20 6c  69 2c 20 6c 65 2c 20 6c  |.  int li, le, l|
00001600  64 69 66 2c 20 6c 72 3b  0a 20 20 69 6e 74 20 71  |dif, lr;.  int q|
00001610  3b 0a 20 20 63 68 61 72  20 2a 70 2c 20 2a 70 74  |;.  char *p, *pt|
00001620  3b 0a 20 20 69 6e 74 20  70 69 2c 20 70 65 2c 20  |;.  int pi, pe, |
00001630  70 72 3b 0a 20 20 69 6e  74 20 73 78 2c 20 73 69  |pr;.  int sx, si|
00001640  2c 20 73 65 2c 20 73 72  3b 0a 20 20 69 6e 74 20  |, se, sr;.  int |
00001650  73 74 61 72 74 5f 74 69  6d 65 3b 0a 0a 20 20 69  |start_time;..  i|
00001660  66 20 28 21 69 6e 69 74  5f 67 6c 6f 62 61 6c 73  |f (!init_globals|
00001670  28 29 29 20 72 65 74 75  72 6e 20 30 3b 0a 0a 20  |()) return 0;.. |
00001680  20 66 6f 72 20 28 3b 3b  29 20 7b 0a 0a 20 20 20  | for (;;) {..   |
00001690  20 62 62 63 5f 6d 6f 64  65 28 6d 6f 6e 69 74 6f  | bbc_mode(monito|
000016a0  72 74 79 70 65 3d 3d 6d  75 6c 74 69 20 3f 20 32  |rtype==multi ? 2|
000016b0  30 20 3a 20 31 32 29 3b  0a 20 20 20 20 69 66 20  |0 : 12);.    if |
000016c0  28 21 69 6e 70 75 74 5f  70 61 72 61 6d 73 28 26  |(!input_params(&|
000016d0  64 75 72 2c 20 26 73 69  7a 65 2c 20 26 64 72 65  |dur, &size, &dre|
000016e0  73 2c 20 26 6c 6d 69 6e  2c 20 26 6c 6d 61 78 29  |s, &lmin, &lmax)|
000016f0  29 20 72 65 74 75 72 6e  20 30 3b 0a 20 20 20 20  |) return 0;.    |
00001700  6c 64 69 66 09 3d 20 6c  6d 61 78 2d 6c 6d 69 6e  |ldif.= lmax-lmin|
00001710  3b 0a 0a 20 20 20 20 6c  69 73 74 3d 6c 69 73 74  |;..    list=list|
00001720  31 3b 0a 20 20 20 20 6c  69 73 74 32 5b 30 5d 3d  |1;.    list2[0]=|
00001730  28 30 3c 3c 31 36 29 2b  70 69 74 63 68 5b 30 5d  |(0<<16)+pitch[0]|
00001740  3b 0a 20 20 20 20 6e 6e  6f 74 65 73 6f 6c 64 3d  |;.    nnotesold=|
00001750  31 3b 0a 20 20 20 20 6c  69 73 74 6f 6c 64 3d 6c  |1;.    listold=l|
00001760  69 73 74 32 3b 0a 0a 20  20 20 20 62 62 63 5f 63  |ist2;..    bbc_c|
00001770  6c 73 28 29 3b 0a 20 20  20 20 77 69 6d 70 74 5f  |ls();.    wimpt_|
00001780  63 6f 6d 70 6c 61 69 6e  28 6f 73 5f 73 77 69 31  |complain(os_swi1|
00001790  72 28 53 6f 75 6e 64 5f  56 6f 6c 75 6d 65 2c 20  |r(Sound_Volume, |
000017a0  31 32 37 2c 20 26 75 73  65 72 76 6f 6c 75 6d 65  |127, &uservolume|
000017b0  29 29 3b 0a 20 20 20 20  66 6f 72 20 28 70 3d 70  |));.    for (p=p|
000017c0  74 3d 77 61 76 65 5f 62  61 73 65 2c 70 69 3d 73  |t=wave_base,pi=s|
000017d0  69 7a 65 2f 64 72 65 73  2c 70 72 3d 73 69 7a 65  |ize/dres,pr=size|
000017e0  25 64 72 65 73 2c 70 65  3d 2d 64 72 65 73 2c 20  |%dres,pe=-dres, |
000017f0  71 3d 30 2c 20 6c 3d 6c  6d 69 6e 2c 6c 69 3d 6c  |q=0, l=lmin,li=l|
00001800  64 69 66 2f 64 72 65 73  2c 6c 72 3d 6c 64 69 66  |dif/dres,lr=ldif|
00001810  25 64 72 65 73 2c 6c 65  3d 2d 64 72 65 73 2c 20  |%dres,le=-dres, |
00001820  73 78 3d 30 2c 73 69 3d  31 32 38 30 2f 64 72 65  |sx=0,si=1280/dre|
00001830  73 2c 73 72 3d 31 32 38  30 25 64 72 65 73 2c 73  |s,sr=1280%dres,s|
00001840  65 3d 2d 64 72 65 73 3b  0a 20 20 20 20 20 20 20  |e=-dres;.       |
00001850  20 20 71 3c 64 72 65 73  3b 0a 20 20 20 20 20 20  |  q<dres;.      |
00001860  20 20 20 71 2b 2b 2c 20  6c 2b 3d 6c 69 2c 6c 65  |   q++, l+=li,le|
00001870  2b 3d 32 2a 6c 72 2c 6c  65 3e 30 3f 28 6c 2b 2b  |+=2*lr,le>0?(l++|
00001880  2c 6c 65 2d 3d 32 2a 64  72 65 73 29 3a 30 2c 20  |,le-=2*dres):0, |
00001890  73 78 2b 3d 73 69 2c 73  65 2b 3d 32 2a 73 72 2c  |sx+=si,se+=2*sr,|
000018a0  73 65 3e 30 3f 28 73 78  2b 2b 2c 73 65 2d 3d 32  |se>0?(sx++,se-=2|
000018b0  2a 64 72 65 73 29 3a 30  29 20 7b 0a 20 20 20 20  |*dres):0) {.    |
000018c0  20 20 6d 65 6d 73 65 74  28 73 65 6c 65 63 74 69  |  memset(selecti|
000018d0  6f 6e 2c 20 30 2c 20 73  72 65 73 29 3b 0a 20 20  |on, 0, sres);.  |
000018e0  20 20 20 20 78 20 3d 20  6f 6e 65 2f 32 3b 0a 20  |    x = one/2;. |
000018f0  20 20 20 20 20 66 6f 72  20 28 73 3d 30 3b 20 73  |     for (s=0; s|
00001900  3c 6c 74 72 61 6e 3b 20  73 2b 2b 29 20 78 20 3d  |<ltran; s++) x =|
00001910  20 6d 75 6c 5f 66 72 61  63 31 36 63 28 6c 2c 20  | mul_frac16c(l, |
00001920  6d 75 6c 5f 66 72 61 63  31 36 63 28 78 2c 20 6f  |mul_frac16c(x, o|
00001930  6e 65 2d 78 29 29 3b 0a  20 20 20 20 20 20 66 6f  |ne-x));.      fo|
00001940  72 20 28 73 3d 30 3b 20  73 3c 6c 61 73 79 6d 3b  |r (s=0; s<lasym;|
00001950  20 73 2b 2b 29 20 7b 0a  20 20 20 20 20 20 20 20  | s++) {.        |
00001960  78 20 3d 20 6d 75 6c 5f  66 72 61 63 31 36 63 28  |x = mul_frac16c(|
00001970  6c 2c 20 6d 75 6c 5f 66  72 61 63 31 36 63 28 78  |l, mul_frac16c(x|
00001980  2c 20 6f 6e 65 2d 78 29  29 3b 0a 20 20 20 20 20  |, one-x));.     |
00001990  20 20 20 69 20 3d 20 78  2a 73 72 65 73 2f 6f 6e  |   i = x*sres/on|
000019a0  65 3b 0a 20 20 20 20 20  20 20 20 69 66 20 28 69  |e;.        if (i|
000019b0  3c 30 29 20 69 3d 30 3b  0a 20 20 20 20 20 20 20  |<0) i=0;.       |
000019c0  20 69 66 20 28 69 3e 3d  73 72 65 73 29 20 69 3d  | if (i>=sres) i=|
000019d0  73 72 65 73 2d 31 3b 0a  20 20 20 20 20 20 20 20  |sres-1;.        |
000019e0  73 65 6c 65 63 74 69 6f  6e 5b 69 5d 3d 32 35 35  |selection[i]=255|
000019f0  3b 0a 20 20 20 20 20 20  20 20 62 62 63 5f 70 6c  |;.        bbc_pl|
00001a00  6f 74 28 36 39 2c 73 78  2c 69 29 3b 0a 20 20 20  |ot(69,sx,i);.   |
00001a10  20 20 20 7d 0a 20 20 20  20 20 20 6e 6e 6f 74 65  |   }.      nnote|
00001a20  73 3d 30 3b 20 2f 2a 6e  6f 77 20 77 65 20 63 6f  |s=0; /*now we co|
00001a30  6d 70 69 6c 65 20 6f 75  72 20 6c 69 73 74 20 6f  |mpile our list o|
00001a40  66 20 70 69 74 63 68 65  73 20 66 6f 72 20 74 68  |f pitches for th|
00001a50  65 20 63 75 72 72 65 6e  74 20 76 61 6c 75 65 20  |e current value |
00001a60  6f 66 20 6c 61 6d 62 64  61 2a 2f 0a 20 20 20 20  |of lambda*/.    |
00001a70  20 20 66 6f 72 20 28 73  3d 30 3b 20 73 3c 73 72  |  for (s=0; s<sr|
00001a80  65 73 3b 20 73 2b 2b 29  20 69 66 20 28 73 65 6c  |es; s++) if (sel|
00001a90  65 63 74 69 6f 6e 5b 73  5d 29 20 6c 69 73 74 5b  |ection[s]) list[|
00001aa0  6e 6e 6f 74 65 73 2b 2b  5d 3d 28 30 3c 3c 31 36  |nnotes++]=(0<<16|
00001ab0  29 2b 70 69 74 63 68 5b  73 5d 3b 0a 20 20 20 20  |)+pitch[s];.    |
00001ac0  20 20 2f 2a 69 74 20 74  68 65 6e 20 72 65 6d 61  |  /*it then rema|
00001ad0  69 6e 73 20 74 6f 20 73  65 74 20 74 68 65 20 69  |ins to set the i|
00001ae0  6e 69 74 69 61 6c 20 70  68 61 73 65 20 6f 66 20  |nitial phase of |
00001af0  65 61 63 68 20 73 75 63  68 20 6e 6f 74 65 20 66  |each such note f|
00001b00  72 6f 6d 20 74 68 65 20  65 6e 64 20 70 68 61 73  |rom the end phas|
00001b10  65 20 6f 66 20 74 68 65  20 6e 65 61 72 65 73 74  |e of the nearest|
00001b20  20 6e 6f 74 65 20 69 6e  20 74 68 65 20 6c 61 73  | note in the las|
00001b30  74 20 70 61 63 6b 65 74  2a 2f 0a 20 20 20 20 20  |t packet*/.     |
00001b40  20 66 6f 72 20 28 73 3d  30 3b 20 73 3c 6e 6e 6f  | for (s=0; s<nno|
00001b50  74 65 73 3b 20 73 2b 2b  29 20 6c 69 73 74 5b 73  |tes; s++) list[s|
00001b60  5d 20 2b 3d 20 28 6c 69  73 74 6f 6c 64 5b 6e 65  |] += (listold[ne|
00001b70  61 72 6e 6f 74 65 28 6c  69 73 74 5b 73 5d 2c 20  |arnote(list[s], |
00001b80  6c 69 73 74 6f 6c 64 2c  20 6e 6e 6f 74 65 73 6f  |listold, nnoteso|
00001b90  6c 64 29 5d 3e 3e 31 36  29 3c 3c 31 36 3b 0a 20  |ld)]>>16)<<16;. |
00001ba0  20 20 20 20 20 69 66 20  28 71 75 69 63 6b 64 69  |     if (quickdi|
00001bb0  76 5f 69 6e 69 74 28 6e  6e 6f 74 65 73 29 3c 30  |v_init(nnotes)<0|
00001bc0  29 20 77 65 72 72 28 31  2c 20 22 75 6e 65 78 70  |) werr(1, "unexp|
00001bd0  65 63 74 65 64 20 71 75  69 63 6b 64 69 76 5f 69  |ected quickdiv_i|
00001be0  6e 69 74 20 65 72 72 6f  72 22 29 3b 0a 20 20 20  |nit error");.   |
00001bf0  20 20 20 66 6f 72 20 28  70 74 2b 3d 70 69 2c 70  |   for (pt+=pi,p|
00001c00  65 2b 3d 32 2a 70 72 2c  70 65 3e 30 3f 28 70 74  |e+=2*pr,pe>0?(pt|
00001c10  2b 2b 2c 70 65 2d 3d 32  2a 64 72 65 73 29 3a 30  |++,pe-=2*dres):0|
00001c20  2c 70 74 3d 28 70 74 3e  77 61 76 65 5f 65 6e 64  |,pt=(pt>wave_end|
00001c30  7c 7c 71 3d 3d 64 72 65  73 2d 31 29 3f 77 61 76  |||q==dres-1)?wav|
00001c40  65 5f 65 6e 64 3a 70 74  3b 20 70 3c 70 74 3b 20  |e_end:pt; p<pt; |
00001c50  70 2b 2b 29 20 7b 0a 20  20 20 20 20 20 20 20 66  |p++) {.        f|
00001c60  6f 72 20 28 69 3d 30 2c  20 73 61 6d 70 6c 65 3d  |or (i=0, sample=|
00001c70  30 3b 20 69 3c 6e 6e 6f  74 65 73 3b 20 69 2b 2b  |0; i<nnotes; i++|
00001c80  29 20 73 61 6d 70 6c 65  20 2b 3d 20 77 61 76 65  |) sample += wave|
00001c90  74 61 62 6c 65 5b 28 6c  69 73 74 5b 69 5d 2b 3d  |table[(list[i]+=|
00001ca0  6c 69 73 74 5b 69 5d 3c  3c 31 36 29 20 3e 3e 20  |list[i]<<16) >> |
00001cb0  33 32 2d 6c 77 74 73 5d  3b 0a 20 20 20 20 20 20  |32-lwts];.      |
00001cc0  20 20 73 61 6d 70 6c 65  20 3d 20 71 75 69 63 6b  |  sample = quick|
00001cd0  64 69 76 28 73 61 6d 70  6c 65 29 3b 0a 20 20 20  |div(sample);.   |
00001ce0  20 20 20 20 20 73 61 6d  70 6c 65 20 3e 3e 3d 20  |     sample >>= |
00001cf0  34 3b 0a 20 20 20 20 20  20 20 20 69 66 20 28 73  |4;.        if (s|
00001d00  61 6d 70 6c 65 3e 3d 34  30 39 36 29 20 73 61 6d  |ample>=4096) sam|
00001d10  70 6c 65 3d 34 30 39 35  3b 0a 20 20 20 20 20 20  |ple=4095;.      |
00001d20  20 20 69 66 20 28 73 61  6d 70 6c 65 3c 3d 2d 34  |  if (sample<=-4|
00001d30  30 39 36 29 20 73 61 6d  70 6c 65 3d 2d 34 30 39  |096) sample=-409|
00001d40  35 3b 0a 20 20 20 20 20  20 20 20 2a 70 20 3d 20  |5;.        *p = |
00001d50  6c 69 6e 6c 6f 67 5b 28  75 6e 73 69 67 6e 65 64  |linlog[(unsigned|
00001d60  20 69 6e 74 29 28 73 61  6d 70 6c 65 3c 3c 31 39  | int)(sample<<19|
00001d70  29 3e 3e 31 39 5d 3b 0a  20 20 20 20 20 20 7d 0a  |)>>19];.      }.|
00001d80  20 20 20 20 20 20 6e 6e  6f 74 65 73 6f 6c 64 3d  |      nnotesold=|
00001d90  6e 6e 6f 74 65 73 3b 0a  20 20 20 20 20 20 6c 69  |nnotes;.      li|
00001da0  73 74 6f 6c 64 3d 6c 69  73 74 3b 0a 20 20 20 20  |stold=list;.    |
00001db0  20 20 6c 69 73 74 20 3d  20 6c 69 73 74 3d 3d 6c  |  list = list==l|
00001dc0  69 73 74 31 20 3f 20 6c  69 73 74 32 20 3a 20 6c  |ist1 ? list2 : l|
00001dd0  69 73 74 31 3b 0a 20 20  20 20 7d 0a 20 20 20 20  |ist1;.    }.    |
00001de0  77 69 6d 70 74 5f 63 6f  6d 70 6c 61 69 6e 28 6f  |wimpt_complain(o|
00001df0  73 5f 73 77 69 31 28 53  6f 75 6e 64 5f 56 6f 6c  |s_swi1(Sound_Vol|
00001e00  75 6d 65 2c 20 75 73 65  72 76 6f 6c 75 6d 65 29  |ume, uservolume)|
00001e10  29 3b 0a 0a 20 20 20 20  61 64 64 5f 76 6f 69 63  |);..    add_voic|
00001e20  65 28 29 3b 0a 20 20 20  20 62 62 63 5f 63 75 72  |e();.    bbc_cur|
00001e30  73 6f 72 28 30 29 3b 0a  0a 20 20 20 20 66 6f 72  |sor(0);..    for|
00001e40  20 28 3b 3b 29 20 7b 0a  20 20 20 20 20 20 77 69  | (;;) {.      wi|
00001e50  6d 70 74 5f 63 6f 6d 70  6c 61 69 6e 28 6f 73 5f  |mpt_complain(os_|
00001e60  73 77 69 34 28 53 6f 75  6e 64 5f 43 6f 6e 74 72  |swi4(Sound_Contr|
00001e70  6f 6c 2c 20 31 2c 20 30  78 31 37 66 2c 20 30 78  |ol, 1, 0x17f, 0x|
00001e80  34 30 30 30 2c 20 64 75  72 2f 35 29 29 3b 0a 20  |4000, dur/5));. |
00001e90  20 20 20 20 20 73 74 61  72 74 5f 74 69 6d 65 3d  |     start_time=|
00001ea0  63 6c 6f 63 6b 28 29 3b  0a 20 20 20 20 20 20 62  |clock();.      b|
00001eb0  62 63 5f 67 63 6f 6c 28  33 2c 20 37 29 3b 0a 20  |bc_gcol(3, 7);. |
00001ec0  20 20 20 20 20 66 6f 72  20 28 73 3d 30 3b 20 73  |     for (s=0; s|
00001ed0  3c 31 32 38 30 3b 20 73  2b 3d 32 29 20 7b 0a 20  |<1280; s+=2) {. |
00001ee0  20 20 20 20 20 20 20 62  62 63 5f 6d 6f 76 65 28  |       bbc_move(|
00001ef0  73 2d 32 2c 20 30 29 3b  0a 20 20 20 20 20 20 20  |s-2, 0);.       |
00001f00  20 62 62 63 5f 64 72 61  77 62 79 28 30 2c 20 31  | bbc_drawby(0, 1|
00001f10  30 32 34 29 3b 0a 20 20  20 20 20 20 20 20 62 62  |024);.        bb|
00001f20  63 5f 6d 6f 76 65 28 73  2c 20 30 29 3b 0a 20 20  |c_move(s, 0);.  |
00001f30  20 20 20 20 20 20 62 62  63 5f 64 72 61 77 62 79  |      bbc_drawby|
00001f40  28 30 2c 20 31 30 32 34  29 3b 0a 20 20 20 20 20  |(0, 1024);.     |
00001f50  20 20 20 77 69 6d 70 74  5f 63 6f 6d 70 6c 61 69  |   wimpt_complai|
00001f60  6e 28 6f 73 5f 73 77 69  32 28 4f 53 5f 42 79 74  |n(os_swi2(OS_Byt|
00001f70  65 2c 34 2c 31 29 29 3b  0a 20 20 20 20 20 20 20  |e,4,1));.       |
00001f80  20 69 66 20 28 61 6b 62  64 5f 70 6f 6c 6c 6b 65  | if (akbd_pollke|
00001f90  79 28 26 69 29 29 20 7b  0a 20 20 20 20 20 20 20  |y(&i)) {.       |
00001fa0  20 20 20 77 69 6d 70 74  5f 63 6f 6d 70 6c 61 69  |   wimpt_complai|
00001fb0  6e 28 6f 73 5f 73 77 69  34 28 53 6f 75 6e 64 5f  |n(os_swi4(Sound_|
00001fc0  43 6f 6e 74 72 6f 6c 2c  20 31 2c 20 30 2c 20 30  |Control, 1, 0, 0|
00001fd0  78 34 30 30 30 2c 20 31  29 29 3b 0a 20 20 20 20  |x4000, 1));.    |
00001fe0  20 20 20 20 20 20 73 78  3d 73 3b 0a 20 20 20 20  |      sx=s;.    |
00001ff0  20 20 20 20 20 20 78 3d  36 34 30 3b 0a 20 20 20  |      x=640;.   |
00002000  20 20 20 20 20 20 20 69  66 20 28 69 21 3d 31 33  |       if (i!=13|
00002010  29 20 66 6f 72 20 28 3b  3b 29 20 7b 0a 20 20 20  |) for (;;) {.   |
00002020  20 20 20 20 20 20 20 20  20 69 66 20 28 78 21 3d  |         if (x!=|
00002030  73 78 29 20 7b 0a 20 20  20 20 20 20 20 20 20 20  |sx) {.          |
00002040  20 20 20 20 62 62 63 5f  6d 6f 76 65 28 73 78 2c  |    bbc_move(sx,|
00002050  20 30 29 3b 0a 20 20 20  20 20 20 20 20 20 20 20  | 0);.           |
00002060  20 20 20 62 62 63 5f 64  72 61 77 62 79 28 30 2c  |   bbc_drawby(0,|
00002070  20 31 30 32 34 29 3b 0a  20 20 20 20 20 20 20 20  | 1024);.        |
00002080  20 20 20 20 20 20 62 62  63 5f 6d 6f 76 65 28 78  |      bbc_move(x|
00002090  2c 20 30 29 3b 0a 20 20  20 20 20 20 20 20 20 20  |, 0);.          |
000020a0  20 20 20 20 62 62 63 5f  64 72 61 77 62 79 28 30  |    bbc_drawby(0|
000020b0  2c 20 31 30 32 34 29 3b  0a 20 20 20 20 20 20 20  |, 1024);.       |
000020c0  20 20 20 20 20 20 20 73  78 3d 78 3b 0a 20 20 20  |       sx=x;.   |
000020d0  20 20 20 20 20 20 20 20  20 20 20 62 62 63 5f 74  |           bbc_t|
000020e0  61 62 28 30 2c 30 29 3b  0a 20 20 20 20 20 20 20  |ab(0,0);.       |
000020f0  20 20 20 20 20 20 20 70  72 69 6e 74 66 28 22 6c  |       printf("l|
00002100  61 6d 62 64 61 20 3d 20  25 66 20 20 20 20 20 20  |ambda = %f      |
00002110  20 20 20 20 20 20 22 2c  20 28 28 69 6e 74 29 28  |      ", ((int)(|
00002120  78 2a 6c 64 69 66 29 2f  31 32 38 30 2e 30 2b 28  |x*ldif)/1280.0+(|
00002130  69 6e 74 29 6c 6d 69 6e  29 2f 36 35 35 33 36 2e  |int)lmin)/65536.|
00002140  30 29 3b 0a 20 20 20 20  20 20 20 20 20 20 20 20  |0);.            |
00002150  7d 0a 20 20 20 20 20 20  20 20 20 20 20 20 69 66  |}.            if|
00002160  20 28 61 6b 62 64 5f 70  6f 6c 6c 6b 65 79 28 26  | (akbd_pollkey(&|
00002170  69 29 29 20 7b 0a 20 20  20 20 20 20 20 20 20 20  |i)) {.          |
00002180  20 20 20 20 69 66 20 28  69 3d 3d 31 33 36 20 26  |    if (i==136 &|
00002190  26 20 78 3e 30 29 20 78  2d 3d 61 6b 62 64 5f 70  |& x>0) x-=akbd_p|
000021a0  6f 6c 6c 73 68 28 29 3f  32 3a 31 30 3b 0a 20 20  |ollsh()?2:10;.  |
000021b0  20 20 20 20 20 20 20 20  20 20 20 20 69 66 20 28  |            if (|
000021c0  69 3d 3d 31 33 37 20 26  26 20 78 3c 31 32 37 38  |i==137 && x<1278|
000021d0  29 20 78 2b 3d 61 6b 62  64 5f 70 6f 6c 6c 73 68  |) x+=akbd_pollsh|
000021e0  28 29 3f 32 3a 31 30 3b  0a 20 20 20 20 20 20 20  |()?2:10;.       |
000021f0  20 20 20 20 20 20 20 69  66 20 28 69 21 3d 31 33  |       if (i!=13|
00002200  36 20 26 26 20 69 21 3d  31 33 37 29 20 7b 0a 20  |6 && i!=137) {. |
00002210  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 62  |               b|
00002220  62 63 5f 6d 6f 76 65 28  73 78 2c 20 30 29 3b 0a  |bc_move(sx, 0);.|
00002230  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002240  62 62 63 5f 64 72 61 77  62 79 28 30 2c 20 31 30  |bbc_drawby(0, 10|
00002250  32 34 29 3b 0a 20 20 20  20 20 20 20 20 20 20 20  |24);.           |
00002260  20 20 20 20 20 62 62 63  5f 74 61 62 28 30 2c 30  |     bbc_tab(0,0|
00002270  29 3b 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |);.             |
00002280  20 20 20 70 72 69 6e 74  66 28 22 20 20 20 20 20  |   printf("     |
00002290  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000022a0  20 20 22 29 3b 0a 20 20  20 20 20 20 20 20 20 20  |  ");.          |
000022b0  20 20 20 20 20 20 62 72  65 61 6b 3b 0a 20 20 20  |      break;.   |
000022c0  20 20 20 20 20 20 20 20  20 20 20 7d 0a 20 20 20  |           }.   |
000022d0  20 20 20 20 20 20 20 20  20 7d 0a 20 20 20 20 20  |         }.     |
000022e0  20 20 20 20 20 7d 0a 20  20 20 20 20 20 20 20 20  |     }.         |
000022f0  20 62 72 65 61 6b 3b 0a  20 20 20 20 20 20 20 20  | break;.        |
00002300  7d 0a 20 20 20 20 20 20  20 20 65 6c 73 65 20 69  |}.        else i|
00002310  3d 30 3b 0a 20 20 20 20  20 20 20 20 66 6f 72 20  |=0;.        for |
00002320  28 3b 20 63 6c 6f 63 6b  28 29 2d 73 74 61 72 74  |(; clock()-start|
00002330  5f 74 69 6d 65 20 3c 20  64 75 72 2a 73 2f 31 32  |_time < dur*s/12|
00002340  38 30 3b 20 29 3b 0a 20  20 20 20 20 20 7d 0a 20  |80; );.      }. |
00002350  20 20 20 20 20 69 66 20  28 73 3d 3d 31 32 38 30  |     if (s==1280|
00002360  29 20 7b 0a 20 20 20 20  20 20 20 20 62 62 63 5f  |) {.        bbc_|
00002370  6d 6f 76 65 28 73 2d 32  2c 20 30 29 3b 0a 20 20  |move(s-2, 0);.  |
00002380  20 20 20 20 20 20 62 62  63 5f 64 72 61 77 62 79  |      bbc_drawby|
00002390  28 30 2c 20 31 30 32 34  29 3b 0a 20 20 20 20 20  |(0, 1024);.     |
000023a0  20 7d 0a 20 20 20 20 20  20 69 66 20 28 69 3d 3d  | }.      if (i==|
000023b0  31 33 29 20 62 72 65 61  6b 3b 0a 20 20 20 20 7d  |13) break;.    }|
000023c0  0a 0a 20 20 20 20 72 65  73 74 6f 72 65 28 29 3b  |..    restore();|
000023d0  0a 20 20 20 20 69 66 20  28 77 61 76 65 5f 62 61  |.    if (wave_ba|
000023e0  73 65 29 20 66 72 65 65  28 77 61 76 65 5f 62 61  |se) free(wave_ba|
000023f0  73 65 29 3b 0a 0a 20 20  7d 0a 0a 20 20 72 65 74  |se);..  }..  ret|
00002400  75 72 6e 20 30 3b 0a 7d  0a                       |urn 0;.}.|
00002409