annotate tests/plrtest.c @ 2530:aacf3bd1cceb

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 16 May 2020 06:38:52 +0300
parents 186cf6a7d634
children 9807ae37ad69
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
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
23 void printRow(FILE * fh, const JSSPattern * pat, const int row)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
25 const JSSNote *note = &(pat->data[pat->nchannels * row]);
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
26 int width = pat->nchannels < 5 ? pat->nchannels : 5;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
28 fprintf(fh, "%.2x: ", row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
30 for (int channel = 0; channel < width; channel++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 {
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
32 switch (note->note)
0
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 case jsetNotSet:
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
35 fprintf(fh, "... ");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 case jsetNoteOff:
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
38 fprintf(fh, "=== ");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 default:
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
41 fprintf(fh, "%s%d ",
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
42 patNoteTable[note->note % 12],
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
43 note->note / 12);
0
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 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
47 if (note->instrument != jsetNotSet)
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
48 fprintf(fh, "%.2x ", note->instrument + 1);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 else
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
50 fprintf(fh, ".. ");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
52 if (note->volume == jsetNotSet)
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
53 fprintf(fh, ".. ");
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
54 else
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
55 if (note->volume >= 0x00 && note->volume <= 0x40)
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
56 fprintf(fh, "%.2x ", note->volume);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
59 char ch;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
60 switch (note->volume & 0xf0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
62 case 0x50: ch = '-'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
63 case 0x60: ch = '+'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
64 case 0x70: ch = '/'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
65 case 0x80: ch = '\\'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
66 case 0x90: ch = 'S'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
67 case 0xa0: ch = 'V'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
68 case 0xb0: ch = 'P'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
69 case 0xc0: ch = '<'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
70 case 0xd0: ch = '>'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
71 case 0xe0: ch = 'M'; break;
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
72 default: ch = '?'; break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
74 fprintf(fh, "%c%x ",
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
75 ch, note->volume & 0x0f);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
78 if (note->effect >= 0 && note->effect < jmpNMODEffectTable)
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
79 fprintf(fh, "%c", jmpMODEffectTable[note->effect]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 else
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
81 fprintf(fh, "%c", note->effect == jsetNotSet ? '.' : '?');
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
83 if (note->param != jsetNotSet)
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
84 fprintf(fh, "%.2x|", note->param);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 else
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
86 fprintf(fh, "..|");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
88 note++;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
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 void audioCallback(void *userdata, Uint8 *stream, int len)
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 JSSMixer *d = (JSSMixer *) userdata;
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 if (d != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 jvmRenderAudio(d, stream, len / jvmGetSampleSize(d));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
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
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 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 {
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
106 SDL_AudioSpec afmt;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
107 DMResource *file = NULL;
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
108 char *inFilename = NULL;
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
109 int res = -1;
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
110 JSSModule *mod = NULL;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
111 JSSMixer *dev = NULL;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
112 JSSPlayer *plr = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 if (argc > 1)
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
115 inFilename = argv[1];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 // Open the files
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
118 if (inFilename == NULL)
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
119 res = dmf_open_stdio_stream(stdin, &file);
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
120 else
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
121 res = dmf_open_stdio(inFilename, "rb", &file);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
122
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
123 if (res != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
125 dmErrorMsg("Error opening input file '%s': %s\n",
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
126 inFilename, dmErrorStr(res));
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
127 goto exit;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
129
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 // Initialize miniJSS
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
131 printf("Initializing miniJSS\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 jssInit();
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 // Read module file
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
135 printf("Reading file: %s\n", inFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 #ifdef JSS_SUP_XM
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
137 if (mod == NULL)
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
138 {
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
139 printf("* Trying XM...\n");
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
140 dmfreset(file);
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
141 if ((res = jssLoadXM(file, &mod, TRUE)) == DMERR_OK)
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
142 {
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
143 dmfreset(file);
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
144 res = jssLoadXM(file, &mod, FALSE);
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
145 }
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
146 }
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
147 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 #ifdef JSS_SUP_JSSMOD
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
149 if (mod == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
151 printf("* Trying JSSMOD ...\n");
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
152 dmfreset(file);
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
153 if ((res = jssLoadJSSMOD(file, &mod, TRUE)) == DMERR_OK)
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
154 {
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
155 dmfreset(file);
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
156 res = jssLoadJSSMOD(file, &mod, FALSE);
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
157 }
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
158 }
794
319792b2af4a Fix non-fallback loading of JSSMod.
Matti Hamalainen <ccr@tnsp.org>
parents: 793
diff changeset
159 #endif
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
160 dmf_close(file);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
162 // Check for errors, we still might have some data tho
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
163 if (res != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
165 dmErrorMsg(
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
166 "Error loading module file: %s\n",
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
167 dmErrorStr(res));
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)
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
172 {
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
173 res = dmError(DMERR_INIT_FAIL,
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
174 "Could not load module file.\n");
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
175 goto exit;
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
176 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
178 // Try to convert it
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
179 if ((res = 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
180 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
181 dmErrorMsg("Could not convert module for playing: %s\n",
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
182 dmErrorStr(res));
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
183 goto exit;
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
184 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 // Initialize SDL audio
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
187 afmt.freq = 48000;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
188 afmt.format = AUDIO_S16SYS;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
189 afmt.channels = 2;
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
190
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 // Initialize mixing device
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
192 printf("Initializing miniJSS mixer with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
193 JSS_AUDIO_S16, afmt.channels, afmt.freq);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
195 dev = jvmInit(JSS_AUDIO_S16, afmt.channels, afmt.freq, JMIX_AUTO);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
196 if (dev == NULL)
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
197 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
198 res = dmError(DMERR_INIT_FAIL,
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
199 "jvmInit() returned NULL\n");
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
200 goto exit;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
202
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
203 afmt.samples = afmt.freq / 4;
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
204 afmt.callback = audioCallback;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
205 afmt.userdata = (void *) dev;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 // Open the audio device
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
208
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
209 fprintf(stderr,
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
210 "Trying to init SDL with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
211 afmt.format, afmt.channels, afmt.freq);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
212
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
213 if (SDL_OpenAudio(&afmt, NULL) < 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
215 res = dmError(DMERR_INIT_FAIL,
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
216 "Couldn't open audio: %s\n",
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
217 SDL_GetError());
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
218 goto exit;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
220
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 // Initialize player
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
222 if ((plr = jmpInit(dev)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 {
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
224 res = dmError(DMERR_INIT_FAIL,
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
225 "jmpInit() returned NULL\n");
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
226 goto exit;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
228
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 // Initialize playing
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
230 jvmSetCallback(dev, jmpExec, plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
231 jmpSetModule(plr, mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
232 jmpPlayOrder(plr, 0);
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
233 jvmSetGlobalVol(dev, 100);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 // okay, main loop here ... "play" module and print out info
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 printf("----------------------------------------------------\n");
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
237 SDL_LockAudio();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 SDL_PauseAudio(0);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
239 SDL_UnlockAudio();
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
240 BOOL playing = TRUE;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
241 while (playing)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 {
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
243 JSSPattern *pattern = NULL;
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
244 int currRow, prevRow;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
245
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
246 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
247 currRow = prevRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
248 JSS_UNLOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
249
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
250 while (currRow == prevRow && playing)
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
251 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
252 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
253 currRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
254 playing = plr->isPlaying;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
255 pattern = plr->pattern;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
256 JSS_UNLOCK(plr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 SDL_Delay(50);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
258 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
260 if (playing && pattern != NULL)
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
261 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
262 printRow(stdout, pattern, currRow);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
263 printf("\n");
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
264 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
266
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 printf("----------------------------------------------------\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
269 exit:
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
270 SDL_LockAudio();
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
271 SDL_PauseAudio(1);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
272 jmpClose(plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
273 jvmClose(dev);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
274 jssFreeModule(mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
275 SDL_UnlockAudio();
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
276
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
277 SDL_Quit();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
69
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
279 jssClose();
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
280
2530
aacf3bd1cceb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
281 return res;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 }