Added graph making, used 32-bit float samples.
[aftubes.git] / main.c
blob2b271cc266d0df50ebc8a03d2eb0b52c548616af
1 #include "stdio.h"
2 #include "soundout.h"
3 #include "wavefile.h"
4 #include "effects.h"
5 #include "graph.h"
7 int main(int argc, char **argv)
9 struct graph _graph, *graph = &_graph;
10 struct graphnode *node;
11 struct aformat af;
12 struct effect *ef1;
14 if (graph_create(graph)){
15 fprintf(stderr, "cannot create graph\n");
16 return 1;
19 ///// create wave file source /////
21 ef1 = wavefile_source_create("/home/aoe/reflections.wav");
22 if (!ef1){
23 fprintf(stderr, "cannot open wave file\n");
24 graph_destroy(graph);
25 return 1;
28 node = graphnode_create();
29 if (!node){
30 fprintf(stderr, "cannot create graph node\n");
31 ef1->vtab->destroy(ef1);
32 graph_destroy(graph);
33 return 1;
36 node->ef = ef1;
37 graph_append_node(graph, node);
39 ///// create a distortion effect (turn volume down!) /////
41 ef1 = distortion_create();
42 if (!ef1){
43 fprintf(stderr, "cannot create distortion effect\n");
44 graph_destroy(graph);
45 return 1;
48 node = graphnode_create();
49 if (!node){
50 fprintf(stderr, "cannot create graph node\n");
51 ef1->vtab->destroy(ef1);
52 graph_destroy(graph);
53 return 1;
56 node->ef = ef1;
57 graph_append_node(graph, node);
59 ///// create a silly effect (turn volume down!) /////
61 ef1 = silly_effect_create();
62 if (!ef1){
63 fprintf(stderr, "cannot create distortion effect\n");
64 graph_destroy(graph);
65 return 1;
68 node = graphnode_create();
69 if (!node){
70 fprintf(stderr, "cannot create graph node\n");
71 ef1->vtab->destroy(ef1);
72 graph_destroy(graph);
73 return 1;
76 node->ef = ef1;
77 graph_append_node(graph, node);
79 ///// create the play sink /////
81 af.srate = 44100;
82 af.bits = 16;
83 af.channels = 2;
84 ef1 = play_sink_create(&af);
85 if (!ef1){
86 fprintf(stderr, "cannot open /dev/dsp\n");
87 graph_destroy(graph);
88 return 1;
91 node = graphnode_create();
92 if (!node){
93 fprintf(stderr, "cannot create graph node\n");
94 ef1->vtab->destroy(ef1);
95 graph_destroy(graph);
96 return 1;
99 node->ef = ef1;
100 graph_append_node(graph, node);
102 // run the graph.
103 // Hold your ears!
104 for (;;){
105 if (graph_run(graph, 4410)){
106 break;
110 return 0;