annotate pwpzax/zaxplay.c @ 80:d2121ed6e67e

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Aug 2012 06:17:39 +0300
parents 561fa061caf6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
2 * PWP music player. Uses libSDL for audio output.
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 *
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
4 * compile: gcc -O3 -o zaxplay zaxplay.c `sdl-config --libs --cflags`
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
6 * run: zaxplay <tunenum>
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 *
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 */
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <stdio.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <stdlib.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <string.h>
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
13 #include <SDL.h>
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <math.h>
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 typedef struct
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 char*title;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 int numchans;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 int tempo;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 unsigned char*patord;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 unsigned char*tracks;
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
24 } pwpmusic;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #include "Final_Isi.h"
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #include "Future_Moottori.h"
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #include "Go_Mazzembly.h"
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 #include "Ikuisuus.h"
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
31 static const pwpmusic *tunes[] = {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
32 &Final_Isi, &Future_Moottori, &Go_Mazzembly, &Ikuisuus
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
33 };
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
34 static const int ntunes = sizeof(tunes) / sizeof(tunes[0]);
27
0eba27fee6da Const fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
35 const pwpmusic *tune;
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
36
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 struct {
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
39 struct {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
40 int wvlgt;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
41 int wvleft;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 int wvphase;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 int wvlgt1;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 }ch[3];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 int freq;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 } pwpgb;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48 #define pwplib_volume 64
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
49 #define pwplib_sound_off(c) gb_sound(c,0,0,0)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
50 #define pwplib_sound_n(c,n) p gb_sound(c,n,128,128)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
51 #define pwplib_sound_nv(c,n,v) gb_sound(c,n,v,128)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
52 #define pwplib_sound_nvr(c,n,v,r) gb_sound(c,n,v,r)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
54 void gb_sound(int chan,int freq,int volume,int ratio)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 if(volume&&freq){
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57 int wvlgt=
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 ((double)(pwpgb.freq*12)/pow(1.059465,freq/256.0));
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 if(ratio<1)ratio=1;else if(ratio>255)ratio=255;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
61
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
62 pwpgb.ch[chan].wvlgt=(wvlgt*ratio)>>7;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
63 pwpgb.ch[chan].wvlgt1=2*pwpgb.ch[chan].wvlgt-wvlgt;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 pwpgb.ch[chan].wvleft=pwpgb.ch[chan].wvlgt/(chan+2);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66 pwpgb.ch[chan].wvphase=volume;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
67 }else{
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
68 pwpgb.ch[chan].wvphase=0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
69 pwpgb.ch[chan].wvleft=pwpgb.ch[chan].wvlgt=32123;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
70 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 }
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
73 void gb_init(int freq)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
74 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75 int i;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
76 pwpgb.freq = freq;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
77 for(i=0;i<3;i++)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 gb_sound(i,0,0,0);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
79 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
80
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 void gb_gen1chan(char*d,int l,int freq)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 int ph=128*256;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 while(l--){
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 *d++=64+((ph>>8)&0x80);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 ph+=freq;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 #define ch pwpgb.ch
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
92 void gb_beepemu(char*d,int l)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 static int pf=0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 int
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 fq0=ch[0].wvlgt,
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 fq1=ch[1].wvlgt,
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 fq2=ch[2].wvlgt,fq;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 if(ch[0].wvphase==0)fq0=32768;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 if(ch[1].wvphase==0)fq1=32768;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 if(ch[2].wvphase==0)fq2=32768;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 if(fq0>fq1){int tmp=fq0;fq0=fq1;fq1=tmp;}
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 if(fq0>fq2){int tmp=fq0;fq0=fq2;fq2=tmp;}
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 if(fq1>fq2){int tmp=fq1;fq1=fq2;fq2=tmp;}
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 if(pf&1){
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 if(pf&2)fq=fq1;else fq=fq2;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 if(!fq)fq=fq0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }else{
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 fq=fq0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 if(fq==32768){fq=fq1;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 if(fq==32768)fq=fq2;}
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 if(fq==32768)memset(d,128,l);else
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 fq=(65536*256)/fq;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 gb_gen1chan(d,l,fq);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 pf++;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
123 void gb_genwave(char*d,int l)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 {
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 int remain=0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 l<<=8;
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
128 while(l)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
129 {
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 int min=ch[0].wvleft,w,sum;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 w=ch[1].wvleft;if(w<min)min=w;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 w=ch[2].wvleft;if(w<min)min=w;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 sum=ch[0].wvphase+ch[1].wvphase+ch[2].wvphase+128;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 if(sum<0)sum=0;else if(sum>255)sum=255;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 if(min>l)min=l; l-=min;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 memset(d,sum,(min+remain)>>8);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 d+=((min+remain)>>8);
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 remain=(min+remain)&255;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {int i=0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 for(;i<3;i++){
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 w=ch[i].wvleft-=min;
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
145 if(!w)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
146 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
147 ch[i].wvleft=ch[i].wvlgt1;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
148 ch[i].wvlgt1=ch[i].wvlgt;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
149 ch[i].wvlgt=ch[i].wvleft;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 ch[i].wvphase=0-ch[i].wvphase;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 }
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
152 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
153 }
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
158 struct {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
159 int ord,patt,row;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
160 int tick,tempo;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161 int frag, curr, freq;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
162 } player;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
165 void player_set_tempo(int tempo)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 {
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 player.tempo = tempo;
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
168 player.frag = (player.freq * tempo) / 73;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
171 void player_newnote()
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 {
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
173 int c=0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
174
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
175 for(;c<tune->numchans;c++)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
176 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
177 int note=tune->tracks[(player.patt * tune->numchans + c) * 64 + player.row];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
178 if(note==254)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
179 pwplib_sound_nv(c,0,0);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
180 else
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
181 if(note!=255)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
182 pwplib_sound_nv(c,(note-5)<<8,pwplib_volume);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
183 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
184 player.row++;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
185 if(player.row==64)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
186 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
187 player.row=0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
188 player.ord++;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
189 player.patt=tune->patord[player.ord];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
190
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
191 if(player.patt>128)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
192 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
193 if(player.patt==255)player.ord=0;else
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
194 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
195 if(player.patt==254)player.tempo=4;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
196 player.ord++;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
197 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
198 player.patt=tune->patord[player.ord];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
199 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
200 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
201 }
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
203 void player_render_cb(void *udata, Uint8 * buf, int len)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
204 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
205 (void) udata;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
206 while (len > 0) {
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
207 if (player.curr >= len) {
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
208 player.curr -= len;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
209 gb_genwave((char *)buf, len);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
210 len = 0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
211 } else {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
212 gb_genwave((char *)buf, player.curr);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
213 buf += player.curr;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
214 len -= player.curr;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
215 player.curr = player.frag;
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
216 player_newnote();
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
217 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
218 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
219 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
220
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
221 static void sdlaudio_close(void)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
222 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
223 fprintf(stderr, "* Closing audio.\n");
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
224 SDL_CloseAudio();
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
225 SDL_Quit();
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
80
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
228 int main(int argc, char *argv[])
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
230 SDL_Event event;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
231 SDL_AudioSpec fmt;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
232 int i;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
233
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
234 /* Settings */
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
235 fmt.freq = 44100;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
236 fmt.format = AUDIO_U8;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
237 fmt.channels = 1;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
238 fmt.samples = 2048;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
239 fmt.callback = player_render_cb;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
240
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
241 if (argc != 2)
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 {
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
243 fprintf(stderr, "Usage: %s <tunenum 0..%d>\n",
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
244 argv[0], ntunes - 1);
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 return 0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
248 i = atoi(argv[1]);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
249 if (i < 0 || i >= ntunes) i = rand() % ntunes;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
250 tune = tunes[i];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
251
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
252 fprintf(stderr,
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
253 "Tune #%d: '%s'\n"
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
254 "Tempo: %d\n"
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
255 "Channels: %d\n",
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
256 i, tune->title, tune->tempo, tune->numchans);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
257
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
258 if (SDL_Init(SDL_INIT_AUDIO) != 0)
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
259 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
260 fprintf(stderr, "* SDL could not be initialized.\n");
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
261 return 1;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
262 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
263
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
264 fprintf(stderr, "* SDL audio request %d, %d, %d -> %d\n",
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
265 fmt.freq, fmt.format, fmt.channels, fmt.samples);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
266
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
267 if (SDL_OpenAudio(&fmt, NULL) < 0)
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
268 {
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
269 fprintf(stderr, "* SDL: Could not get desired audio format.\n");
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
270 return 1;
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 }
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
273 fprintf(stderr, "* SDL audio initialized %d, %d, %d -> %d\n",
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
274 fmt.freq, fmt.format, fmt.channels, fmt.samples);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
275
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
276 atexit(sdlaudio_close);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
277
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
278 gb_init(fmt.freq);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
279 player.freq = fmt.freq;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
280 player.row = player.ord = 0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
281 player.patt = tune->patord[0];
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
282 player.tick = 0;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
283 player_set_tempo(tune->tempo);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
284 player.curr = player.frag;
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
285
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
286 SDL_PauseAudio(0);
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
287
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
288
80
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
289 while (SDL_WaitEvent(&event) >= 0)
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
290 {
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
291 switch (event.type)
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
292 {
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
293 case SDL_QUIT:
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
294 fprintf(stderr, "* Quitting\n");
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
295 exit(0);
d2121ed6e67e Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
296 break;
14
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
297 }
cf56b64a3c11 Prototyping of a improved zaxplay with SDL audio output. Does not work as intended yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
298 }
37
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
299
561fa061caf6 Fix the audio rendering callback function, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
300 sdlaudio_close();
0
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 return 0;
acb5694e93d9 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 }