annotate tests/plrtest.c @ 2298:b5abfff07ca9

Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and dmGrowBufConstCopyOffsSize().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Jul 2019 10:54:16 +0300
parents 186cf6a7d634
children aacf3bd1cceb
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;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 int result = -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)
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1603
diff changeset
119 result = dmf_open_stdio_stream(stdin, &file);
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
120 else
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1603
diff changeset
121 result = dmf_open_stdio(inFilename, "rb", &file);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
122
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
123 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 {
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 667
diff changeset
125 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
126 inFilename, result, dmErrorStr(result));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 return 1;
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 fprintf(stderr, "Initializing miniJSS\n");
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
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
134
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 // Read module file
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
136 dmMsg(1, "Reading file: %s\n", inFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 #ifdef JSS_SUP_XM
797
f066e9dccf29 Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
138 result = jssLoadXM(file, &mod, TRUE);
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
139 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 #ifdef JSS_SUP_JSSMOD
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
141 dmfreset(file);
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
142 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 {
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 730
diff changeset
144 dmMsg(1, "* Trying JSSMOD ...\n");
797
f066e9dccf29 Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
145 result = jssLoadJSSMOD(file, &mod, TRUE);
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)
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
148 result = jssLoadJSSMOD(file, &mod, FALSE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 }
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
150 else
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
151 {
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
152 dmMsg(2, "* Trying XM...\n");
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
153 result = jssLoadXM(file, &mod, FALSE);
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
154 }
794
319792b2af4a Fix non-fallback loading of JSSMod.
Matti Hamalainen <ccr@tnsp.org>
parents: 793
diff changeset
155 #endif
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
156 dmf_close(file);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
158 // 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
159 if (result != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 {
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
161 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
162 result, dmErrorStr(result));
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
163 }
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
164
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
165 // Check if we have anything
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
166 if (mod == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 return 3;
1204
0d173edbabe2 Do the file probing stuff here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
168
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
170 // Try to convert it
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
171 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
172 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
173 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
174 result, dmErrorStr(result));
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
175 return 3;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
176 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 // Initialize SDL audio
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
179 afmt.freq = 48000;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
180 afmt.format = AUDIO_S16SYS;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
181 afmt.channels = 2;
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
182
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 // Initialize mixing device
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 fprintf(stderr, "Initializing miniJSS mixer with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
185 JSS_AUDIO_S16, afmt.channels, afmt.freq);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
187 dev = jvmInit(JSS_AUDIO_S16, afmt.channels, afmt.freq, JMIX_AUTO);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
188 if (dev == NULL)
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
189 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 fprintf(stderr, "jvmInit() returned NULL\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 return 3;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
193
303
2b5472173355 Fix buffer length.
Matti Hamalainen <ccr@tnsp.org>
parents: 292
diff changeset
194 afmt.samples = afmt.freq / 4;
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
195 afmt.callback = audioCallback;
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
196 afmt.userdata = (void *) dev;
0
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 // Open the audio device
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 fprintf(stderr, "Trying to init SDL with: %d, %d, %d\n",
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
200 afmt.format, afmt.channels, afmt.freq);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
201
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
202 if (SDL_OpenAudio(&afmt, NULL) < 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 return 4;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
207
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 // Initialize player
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
209 if ((plr = jmpInit(dev)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 fprintf(stderr, "jmpInit() returned NULL\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 return 4;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
214
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 // Initialize playing
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
216 jvmSetCallback(dev, jmpExec, plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
217 jmpSetModule(plr, mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
218 jmpPlayOrder(plr, 0);
1603
2d7511e61403 Cleanup plrtest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1204
diff changeset
219 jvmSetGlobalVol(dev, 100);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 // okay, main loop here ... "play" module and print out info
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 printf("----------------------------------------------------\n");
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
223 SDL_LockAudio();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 SDL_PauseAudio(0);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
225 SDL_UnlockAudio();
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
226 BOOL playing = TRUE;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
227 while (playing)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 {
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
229 JSSPattern *pattern = NULL;
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
230 int currRow, prevRow;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
231
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
232 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
233 currRow = prevRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
234 JSS_UNLOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
235
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
236 while (currRow == prevRow && playing)
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
237 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
238 JSS_LOCK(plr);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
239 currRow = plr->row;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
240 playing = plr->isPlaying;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
241 pattern = plr->pattern;
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
242 JSS_UNLOCK(plr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 SDL_Delay(50);
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
244 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
793
21ad08cdf408 Fix a potential NULL pointer usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
246 if (playing && pattern != NULL)
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
247 {
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
248 printRow(stdout, pattern, currRow);
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
249 printf("\n");
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
250 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
252
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 printf("----------------------------------------------------\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
292
43312a36811f Improve locking.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
255 SDL_LockAudio();
67
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
256 SDL_PauseAudio(1);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
257 jmpClose(plr);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
258 jvmClose(dev);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
259 jssFreeModule(mod);
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
260 SDL_UnlockAudio();
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
261
b51c7fc264ab Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
262 SDL_Quit();
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
69
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
264 jssClose();
7b97df6f8a97 Add jssClose() in the shutdown.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
265
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 }