annotate minijss/jssmod.c @ 1163:aa3738b121d1

Bump copyright years.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 07:19:05 +0200
parents e466d10dae6d
children 848a88ce7a57
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 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * miniJSS - Module structure and handling routines
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
1163
aa3738b121d1 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 1129
diff changeset
4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "jssmod.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <string.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 #ifndef JSS_LIGHT
948
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
11
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
12 /* Take given data until maxlen reached, make a string.
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
13 * Basically a bit like strndup(), except end marker byte
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
14 * can be specified.
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 */
948
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
16 char *jssASCIItoStr(const char * src, const char endByte, const size_t len)
0
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 size_t i, k;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 char *res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
948
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
21 for (i = 0; src[i] && i < len; i++);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
948
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
23 if ((res = dmMalloc(i + 1)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
948
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
26 for (k = 0; src[k] != endByte && k < i; k++)
698ee83bac98 Constify & cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
27 res[k] = src[k];
0
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 res[k] = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 return res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 }
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 /* Encodes a given 8-bit sample
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 */
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 BOOL jssEncodeSample8(Uint8 * data, const size_t len, const int ops)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
39 size_t count = len;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 Sint8 t, value = 0;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
41
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 while (count--)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 t = *data;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
45
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 if (ops & jsampFlipSign)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 t ^= 0x80;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 if (ops & jsampDelta)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 int n = t - value;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 value = t;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 t = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
55
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 *(data++) = t;
0
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 /* Decodes a given 16-bit sample
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 */
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 BOOL jssEncodeSample16(Uint16 * data, const size_t len, const int ops)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 // "Split" the 16-bit samples into 8-bit halves
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 if (ops & jsampSplit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 // Allocate temporary processing buffer
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 size_t count, bufSize = len * sizeof(Sint16);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 Uint8 *bp1, *bp2;
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
73 Sint16 *sdata, *tmpBuf = dmMalloc(bufSize);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 if (tmpBuf == NULL) return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 sdata = tmpBuf;
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
77 bp1 = (Uint8 *) data;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 bp2 = bp1 + len;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
79 count = len;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 while (count--)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
83 Sint16 t = (*sdata++);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 *bp1++ = t >> 8;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 *bp2++ = t & 0xff;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
87
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
88 memcpy(data, tmpBuf, bufSize);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 dmFree(tmpBuf);
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
90
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 return jssEncodeSample8((Uint8 *) data, bufSize, ops);
0
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 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
95 Sint16 t, p, value = 0, *sdata = (Sint16 *) data;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
96 size_t count = len;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
97
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
98 while (count--)
0
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 if (ops & jsampSwapEndianess)
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 p = *sdata;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8);
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
104 }
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
105 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 t = *sdata;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
107
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 if (ops & jsampDelta)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 int n = t - value;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 value = t;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 t = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
114
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 if (ops & jsampFlipSign)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 t ^= 0x8000;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
117
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 *(sdata++) = t;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
44
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
123
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 /* Decodes a given 8-bit sample
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 */
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
129 int jssDecodeSample8(Uint8 * data, const size_t len, const int ops)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
131 size_t count = len;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 Sint8 t, value = 0;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
133
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
134 while (count--)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
136 t = *data;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
137
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 if (ops & jsampDelta)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 t = value = t + value;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
140
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 if (ops & jsampFlipSign)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 t ^= 0x80;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
143
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144 *(data++) = t;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
146 return DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 /* Decodes a given 16-bit sample
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 */
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
152 int jssDecodeSample16(Uint16 * data, const size_t len, const int ops)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 if (ops & jsampSplit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
156 size_t count, bufSize = len * sizeof(Uint16);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 Uint8 *bp1, *bp2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 Sint16 *tmpBuf, *sdata;
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
159 int ret;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
160
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
161 if ((ret = jssDecodeSample8((Uint8 *) data, bufSize, ops)) != DMERR_OK)
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
162 return ret;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
163
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
164 if ((tmpBuf = dmMalloc(bufSize)) == NULL)
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
165 return DMERR_MALLOC;
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
166
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 memcpy(tmpBuf, data, bufSize);
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
168
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
169 sdata = (Sint16 *) data;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 bp1 = (Uint8 *) tmpBuf;
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
171 bp2 = bp1 + len;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
172 count = len;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
173 while (count--)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 *sdata++ = (*bp1++ << 8) | (*bp2++ & 0xff);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
177
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 dmFree(tmpBuf);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 {
43
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
182 Sint16 t, p, value = 0, *sdata = (Sint16 *) data;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
183 size_t count = len;
048536ad01e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
184 while (count--)
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 if (ops & jsampSwapEndianess)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 p = *sdata;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 t = ((p >> 8) & 0xff) | ((p & 0xff) << 8);
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
190 }
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
191 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 t = *sdata;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
193
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 if (ops & jsampDelta)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 t = value = t + value;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
196
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 if (ops & jsampFlipSign)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 t ^= 0x8000;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
199
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 *(sdata++) = t;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 }
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
203 return DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
206
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
207 /* Convert sample data from U8 to S16
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
208 */
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
209 int jssConvertSampleTo16(void **dst, void * src, const size_t len)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
210 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
211 size_t count = len;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
212 Uint8 *in = (Uint8 *) src;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
213 Sint16 *out;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
214
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
215 if ((*dst = out = dmMalloc(sizeof(Sint16) * len)) == NULL)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
216 return DMERR_MALLOC;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
217
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
218 while (count--)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
219 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
220 *(out++) = (*(in++) * 256) - 32768;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
221 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
222
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
223 return DMERR_OK;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
224 }
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
225
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
226
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
227 /* Converts the given module in preparation for playing it.
56
8725853609db Remove the floating point mixing .. it wasn't so good idea after all.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
228 * This involves sample format conversion (8 to 16 bit, etc.)
49
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
229 *
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
230 * NOTICE! The converted module can only be saved in JSSMOD
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
231 * format, but this is not recommended.
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
232 */
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
233 int jssConvertModuleForPlaying(JSSModule *module)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
234 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
235 int i;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
236 if (module == NULL)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
237 return DMERR_NULLPTR;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
238
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
239 // Convert instruments
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
240 for (i = 0; i < module->ninstruments; i++)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
241 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
242 JSSInstrument *inst = module->instruments[i];
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
243 if (inst != NULL && inst->data != NULL)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
244 {
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
245 int res;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
246 void *data = NULL;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
247
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
248 if (inst->flags & jsf16bit)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
249 continue;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
250
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
251 if ((res = jssConvertSampleTo16(&data, inst->data, inst->size)) != DMERR_OK)
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
252 return res;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
253
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
254 inst->flags |= jsf16bit;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
255 dmFree(inst->data);
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
256 inst->data = data;
033c660c25f5 Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
257 }
44
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
258 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
259
44
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
260 return DMERR_OK;
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
261 }
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
262
064d1d1d5b0f Add new functions, jssConvertSampleFromFP() and jssConvertSampleToFP().
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
263
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 /* Allocates a new module structure or returns errorvalue if failed.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 * Memory is allocated only for the basic structure. Sample- and pattern
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 * areas must be allocated separately with appropriate routines.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 JSSModule *jssAllocateModule(void)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 JSSModule *module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 // Allocate module structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 module = dmMalloc0(sizeof(JSSModule));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 if (module == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 // Initialize structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 for (i = 0; i < jsetNChannels; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 module->defPanning[i] = jchPanMiddle;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 for (i = 0; i < jsetMaxOrders; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 module->orderList[i] = jsetOrderEnd;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 // Allocate mutex
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 #ifdef JSS_SUP_THREADS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 module->mutex = dmCreateMutex();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 return module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 /* Frees a given module structure, freeing all memory areas
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 * that were allocated for it (including patterns, samples, etc.)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 int jssFreeModule(JSSModule * module)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 if (module == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 return DMERR_NULLPTR;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
303
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 // Free strings
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 #ifndef JSS_LIGHT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 dmFree(module->moduleName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 dmFree(module->trackerName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 // Free patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 for (i = 0; i < module->npatterns; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
313 if (module->patterns[i] != NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 JSSPattern *pat = module->patterns[i];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 dmFree(pat->data);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 dmFree(pat);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 module->patterns[i] = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321
286
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
322 // Free the "empty" pattern
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
323 JSSPattern *pat = module->patterns[jsetMaxPatterns];
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
324 if (pat != NULL)
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
325 {
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
326 dmFree(pat->data);
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
327 dmFree(pat);
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
328 module->patterns[i] = NULL;
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
329 }
a17e54015bd9 Fix a small memory leak, the special "empty" pattern was not being freed.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
330
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 // Free instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 for (i = 0; i < module->ninstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 {
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
334 if (module->instruments[i] != NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 JSSInstrument *inst = module->instruments[i];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 #ifndef JSS_LIGHT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 dmFree(inst->desc);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 dmFree(inst->data);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 dmFree(inst);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 module->instruments[i] = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 // Free extended instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 for (i = 0; i < module->nextInstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 {
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
349 if (module->extInstruments[i] != NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 JSSExtInstrument *ext = module->extInstruments[i];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 #ifndef JSS_LIGHT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 dmFree(ext->desc);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 dmFree(ext);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 module->extInstruments[i] = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 // Free mutex
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 #ifdef JSS_SUP_THREADS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 dmDestroyMutex(module->mutex);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 #endif
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
364
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 // Free the module structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 memset(module, 0, sizeof(JSSModule));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 dmFree(module);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 /* Allocates and initializes a internal pattern structure.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 */
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
375 JSSPattern *jssAllocatePattern(const int nrows, const int nchannels)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 {
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
377 int row, chn;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 JSSPattern *res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 JSSNote *pnote;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 // Check arguments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 if (nrows <= 0 || nchannels <= 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%i or nchannels=%i.\n", nrows, nchannels);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 // Allocate a pattern structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 res = dmMalloc0(sizeof(JSSPattern));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 if (res == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern structure.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 // Allocate notedata
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 res->data = dmCalloc(nrows * nchannels, sizeof(JSSNote));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 if (res->data == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 dmFree(res);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%i, nchannels=%i).\n", nrows,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 nchannels);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 // Initialize
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 res->nrows = nrows;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 res->nchannels = nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 pnote = res->data;
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
404 for (row = 0; row < nrows; row++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 {
743
b136ddc4070b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
406 for (chn = 0; chn < nchannels; chn++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 pnote->note = pnote->instrument = pnote->volume =
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 pnote->effect = pnote->param = jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 pnote++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 // OK, return pointer to struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 return res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 /* Allocates and initializes internal "normal" instrument structure.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 JSSInstrument *jssAllocateInstrument(void)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 JSSInstrument *res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 // Allocate a instrument structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 res = dmMalloc0(sizeof(JSSInstrument));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 if (res == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 return res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 /* Allocates and initializes "extended" instrument structure.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 JSSExtInstrument *jssAllocateExtInstrument(void)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 JSSExtInstrument *res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 // Allocate a instrument structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 res = dmMalloc0(sizeof(JSSExtInstrument));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 if (res == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 res->sNumForNotes[i] = jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
451
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 return res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 }