Synth.cpp
 All Data Structures Namespaces Files Functions Variables Macros
test.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 
6 #include "teensy/synth.h"
7 #include "teensy/voice.h"
8 #include "teensy/tests.h"
9 
10 #define NUM_VOICES 8
11 
12 FILE *outf, *gp_outf;
13 int t;
16 extern uint32_t tune[];
17 
18 int main(int argc, char *argv[])
19 {
20  if (argc == 2 && strncmp(argv[1], "-t", 2) == 0) {
21  return run_tests();
22  }
23 
24  synth_ary[0] = &s;
25  use_synth_array(synth_ary, NUM_VOICES);
26  use_synth(0);
27 
28  gp_outf = fopen("foo.gp", "w");
29 
30  outf = fopen("foo.py", "w");
31  fprintf(outf, "sampfreq = %lf\n", (double) SAMPLING_RATE);
32  fprintf(outf, "samples = [\n");
33 
34  for (int i = 0; i < NUM_VOICES; i++) {
35  s.add(new NoisyVoice());
36  // s.add(new TwoSquaresVoice());
37  // s.add(new SimpleVoice());
38  }
39 
40  for (t = 0; 1; t++) {
41  int32_t y;
42  uint32_t msecs = (1000 * t) / SAMPLING_RATE;
43  if (play_tune(tune, msecs)) break;
44  s.compute_sample();
45  ASSERT(s.get_sample((uint32_t *) &y) == 0);
46  fprintf(outf, "%u,\n", (uint16_t) (y << 6));
47 
48  /* Numbers for Gnuplot */
49  fprintf(gp_outf, "%d %d\n", t, (int) y);
50  }
51 
52  fprintf(outf, "]\n");
53  fclose(outf);
54  fclose(gp_outf);
55 }
#define ASSERT(cond)
Definition: synth.h:27
FILE * outf
Definition: test.cpp:12
Definition: synth.h:58
Definition: synth.h:126
void compute_sample(void)
Definition: synth.cpp:145
FILE * gp_outf
Definition: test.cpp:12
ISynth * synth_ary[NUM_VOICES]
Definition: test.cpp:15
void add(IVoice *voice)
Definition: synth.h:146
#define SAMPLING_RATE
Definition: synth.h:24
void use_synth_array(ISynth **s, uint8_t _num_synths)
Definition: synth.cpp:39
int t
Definition: test.cpp:13
uint8_t play_tune(uint32_t *tune, uint32_t msecs)
Definition: synth.cpp:51
int8_t run_tests(void)
Definition: tests.cpp:24
Synth s
Definition: test.cpp:14
void use_synth(uint8_t i)
Definition: synth.cpp:29
uint32_t tune[]
Definition: tune.cpp:3
int main(int argc, char *argv[])
Definition: test.cpp:18
Synthesizer modules and supporting functions.
#define NUM_VOICES
Definition: test.cpp:10
uint8_t get_sample(uint32_t *x)
Definition: synth.h:156