annotate tests/plrtest.c @ 1204:0d173edbabe2

Do the file probing stuff here as well.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 17:00:18 +0200
parents f066e9dccf29
children 2d7511e61403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "jss.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "jssmod.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "jssmix.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "jssplr.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <string.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include <unistd.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <SDL.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 static const char patNoteTable[12][3] =
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 "C-", "C#", "D-",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 "D#", "E-", "F-",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 "F#", "G-", "G#",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 "A-", "A#", "B-"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #define jmpNMODEffectTable (36)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 void printRow(FILE * f, JSSPattern * p, int row)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 int j, k;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 char c;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 JSSNote *n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 if (!p)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 return;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 n = &(p->data[p->nchannels * row]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 fprintf(f, "%.2x: ", row);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 k = p->nchannels < 5 ? p->nchannels : 5;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 for (j = 0; j < k; j++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 switch (n->note)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 case jsetNotSet:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 fprintf(f, "... ");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 case jsetNoteOff:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 fprintf(f, "=== ");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 fprintf(f, "%s%i ", patNoteTable[n->note % 12], n->note / 12);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 if (n->instrument != jsetNotSet)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 fprintf(f, "%.2x ", n->instrument + 1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 fprintf(f, ".. ");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 if (n->volume == jsetNotSet)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 fprintf(f, ".. ");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 else if (n->volume >= 0x00 && n->volume <= 0x40)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 fprintf(f, "%.2x ", n->volume);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 switch (n->volume & 0xf0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 case 0x50: c = '-'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 case 0x60: c = '+'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 case 0x70: c = '/'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 case 0x80: c = '\\'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 case 0x90: c = 'S'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 case 0xa0: c = 'V'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 case 0xb0: c = 'P'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 case 0xc0: c = '<'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 case 0xd0: c = '>'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 case 0xe0: c = 'M'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 default: c = '?'; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 fprintf(f, "%c%x ", c, (n->volume & 0x0f));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if (n->effect >= 0 && n->effect < jmpNMODEffectTable)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 fprintf(f, "%c", jmpMODEffectTable[n->effect]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 else if (n->effect == jsetNotSet)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 fprintf(f, ".");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 fprintf(f, "?");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 if (n->param != jsetNotSet)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 fprintf(f, "%.2x|", n->param);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 fprintf(f, "..|");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 n++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 void audioCallback(void *userdata, Uint8 *stream, int len)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 JSSMixer *d = (JSSMixer *) userdata;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if (d != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 jvmRenderAudio(d, stream, len / jvmGetSampleSize(d));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
111 SDL_AudioSpec afmt;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
112 DMResource *file = NULL;
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
113 char *inFilename = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 int result = -1;
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
115 JSSModule *mod = NULL;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
116 JSSMixer *dev = NULL;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
117 JSSPlayer *plr = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 if (argc > 1)
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
120 inFilename = argv[1];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 // Open the files
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
123 if (inFilename == NULL)
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
124 result = dmf_create_stdio_stream(stdin, &file);
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
125 else
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
126 result = dmf_create_stdio(inFilename, "rb", &file);
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
127
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
128 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 {
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
130 fprintf(stderr, "Error opening input file '%s', #%d: %s\n",
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
131 inFilename, result, dmErrorStr(result));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 return 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 // Initialize miniJSS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 fprintf(stderr, "Initializing miniJSS\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 jssInit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 // Read module file
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
141 dmMsg(1, "Reading file: %s\n", inFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 #ifdef JSS_SUP_XM
797
f066e9dccf29 Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
143 result = jssLoadXM(file, &mod, TRUE);
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
144 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 #ifdef JSS_SUP_JSSMOD
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
146 dmfreset(file);
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
147 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 {
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
149 dmMsg(1, "* Trying JSSMOD ...\n");
797
f066e9dccf29 Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
150 result = jssLoadJSSMOD(file, &mod, TRUE);
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
151 dmfreset(file);
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
152 if (result == DMERR_OK)
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
153 result = jssLoadJSSMOD(file, &mod, FALSE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 }
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
155 else
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
156 {
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
157 dmMsg(2, "* Trying XM...\n");
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
158 result = jssLoadXM(file, &mod, FALSE);
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
159 }
794
319792b2af4a Fix non-fallback loading of JSSMod.
Matti Hamalainen <ccr@tnsp.org>
parents: 793
diff changeset
160 #endif
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
161 dmf_close(file);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
163 // Check for errors, we still might have some data tho
8
fc097f7717df Fix JSSMod loading in viewmod and testpl.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
164 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
166 dmErrorMsg("Error loading module file, %d: %s\n",
8
fc097f7717df Fix JSSMod loading in viewmod and testpl.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 result, dmErrorStr(result));
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
168 }
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
169
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
170 // Check if we have anything
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
171 if (mod == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 return 3;
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
173
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
175 // Try to convert it
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
176 if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
177 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
178 fprintf(stderr, "Could not convert module for playing, %d: %s\n",
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
179 result, dmErrorStr(result));
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
180 return 3;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
181 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 // Initialize SDL audio
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
184 afmt.freq = 48000;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
185 afmt.format = AUDIO_S16SYS;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
186 afmt.channels = 2;
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
187
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 // Initialize mixing device
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 fprintf(stderr, "Initializing miniJSS mixer with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
190 JSS_AUDIO_S16, afmt.channels, afmt.freq);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
192 dev = jvmInit(JSS_AUDIO_S16, afmt.channels, afmt.freq, JMIX_AUTO);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
193 if (dev == NULL)
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
194 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 fprintf(stderr, "jvmInit() returned NULL\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 return 3;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
199 afmt.samples = afmt.freq / 4;
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
200 afmt.callback = audioCallback;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
201 afmt.userdata = (void *) dev;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 // Open the audio device
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 fprintf(stderr, "Trying to init SDL with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
205 afmt.format, afmt.channels, afmt.freq);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
207 if (SDL_OpenAudio(&afmt, NULL) < 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 return 4;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 // Initialize player
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
214 if ((plr = jmpInit(dev)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 fprintf(stderr, "jmpInit() returned NULL\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 return 4;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 // Initialize playing
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
221 jvmSetCallback(dev, jmpExec, plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
222 jmpSetModule(plr, mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
223 jmpPlayOrder(plr, 0);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
224 jvmSetGlobalVol(dev, 60);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 // okay, main loop here ... "play" module and print out info
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 printf("----------------------------------------------------\n");
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
228 SDL_LockAudio();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 SDL_PauseAudio(0);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
230 SDL_UnlockAudio();
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
231 BOOL playing = TRUE;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
232 while (playing)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 {
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
234 JSSPattern *pattern = NULL;
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
235 int currRow, prevRow;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
236
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
237 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
238 currRow = prevRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
239 JSS_UNLOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
240
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
241 while (currRow == prevRow && playing)
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
242 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
243 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
244 currRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
245 playing = plr->isPlaying;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
246 pattern = plr->pattern;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
247 JSS_UNLOCK(plr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 SDL_Delay(50);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
249 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
251 if (playing && pattern != NULL)
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
252 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
253 printRow(stdout, pattern, currRow);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
254 printf("\n");
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
255 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 printf("----------------------------------------------------\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
260 SDL_LockAudio();
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
261 SDL_PauseAudio(1);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
262 jmpClose(plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
263 jvmClose(dev);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
264 jssFreeModule(mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
265 SDL_UnlockAudio();
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
266
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
267 SDL_Quit();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
69
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
269 jssClose();
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
270
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 }