source: buchla-68k/orig/BUCHLA/PTOFTAB.C@ 73dd55f

Last change on this file since 73dd55f was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.8 KB
Line 
1/*
2 =============================================================================
3 ptoftab.c -- generate a pitch to frequency table
4 Written by: D.N. Lynx Crowe -- see VER below for version
5 =============================================================================
6*/
7
8#define VER "Version 2 - 1987-12-19" /* version ID string */
9
10#define DEBUGIT 0
11
12#define FILEOUT "PTOFTAB.OUT" /* output file name */
13#define MAXPIT 10960L /* maximum pitch (cents) = C9 */
14
15#include "stdio.h"
16#include "math.h"
17#include "stddefs.h"
18
19double j;
20double m;
21double kj;
22double kl;
23double km;
24
25FILE *fp;
26
27/*
28
29*/
30
31main()
32{
33 register long i, k;
34 register unsigned long n;
35
36 printf("Buchla 700 Pitch to Frequency Table Generator %s\n", VER);
37
38 if (NULL EQ (fp = fopen(FILEOUT, "wa"))) { /* open output file */
39
40 printf("ERROR: Unable to open [%s] for output.\n", FILEOUT);
41 exit(1);
42 }
43
44 kj = (double)MAXPIT / (double)1200.0;
45 kl = pow((double)2.0, kj);
46 km = ((double)10.0 / kl);
47
48#if DEBUGIT
49 printf("Using km = %12.8f, kl = %12.8f, kj = %12.8f\n", km, kl, kj);
50#endif
51
52 printf("Writing output to [%s] ...\n", FILEOUT);
53 fprintf(fp, "/* Pitch to Frequency */\n\nunsigned ptoftab[] = {\n\n");
54
55 for (i = 0L; i < 256L; i++) {
56
57 k = i << 6;
58 j = (double)((k LE MAXPIT) ? k : MAXPIT) / (double)1200.0;
59 m = km * pow((double)2.0, j) * (double)2.0;
60 n = (unsigned long)((m > (double)10.0 ? (double)10.0 : m)
61 * (double)100.0) << 5;
62
63 fprintf(fp, "\t0x%04.4x%c\t/* %3d: %10.5f %6d %10.5f */\n",
64 (0x0000FFFFL & n), (i < 255L ? ',' : ' '), i, m, k, j);
65
66#if DEBUGIT
67 printf("%3d: m = %10.5f, n = $%04.4x, k = %6d, j = %10.5f\n",
68 i, m, (0x0000FFFFL & n), k, j);
69#endif
70 }
71
72 fprintf(fp, "};\n");
73 fclose(fp); /* close the file */
74 printf("\nProgram complete.\n"); /* say we're done */
75 exit(0); /* go away */
76}
Note: See TracBrowser for help on using the repository browser.