Subversion Repositories eduke32

Rev

Rev 8580 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8580 Rev 8783
Line 65... Line 65...
65
    return KeepPlaying;
65
    return KeepPlaying;
66
}
66
}
67
67
68
int MV_PlayXMP3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int angle, int distance, int priority, fix16_t volume, intptr_t callbackval)
68
int MV_PlayXMP3D(char *ptr, uint32_t length, int loophow, int pitchoffset, int angle, int distance, int priority, fix16_t volume, intptr_t callbackval)
69
{
69
{
70
    int left;
-
 
71
    int right;
-
 
72
    int mid;
-
 
73
    int vol;
-
 
74
    int status;
-
 
75
-
 
76
    if (!MV_Installed)
70
    if (!MV_Installed)
77
        return MV_SetErrorCode(MV_NotInstalled);
71
        return MV_SetErrorCode(MV_NotInstalled);
78
72
79
    if (distance < 0)
73
    if (distance < 0)
80
    {
74
    {
81
        distance  = -distance;
75
        distance  = -distance;
82
        angle    += MV_NUMPANPOSITIONS / 2;
76
        angle    += MV_NUMPANPOSITIONS / 2;
83
    }
77
    }
84
78
85
    vol = MIX_VOLUME(distance);
79
    int vol = MIX_VOLUME(distance);
86
80
87
    // Ensure angle is within 0 - 127
81
    // Ensure angle is within 0 - 127
88
    angle &= MV_MAXPANPOSITION;
82
    angle &= MV_MAXPANPOSITION;
89
83
90
    left  = MV_PanTable[angle][vol].left;
84
    int left  = MV_PanTable[angle][vol].left;
91
    right = MV_PanTable[angle][vol].right;
85
    int right = MV_PanTable[angle][vol].right;
92
    mid   = max( 0, 255 - distance );
86
    int mid   = max( 0, 255 - distance );
93
-
 
94
    status = MV_PlayXMP(ptr, length, loophow, -1, pitchoffset, mid, left, right, priority, volume, callbackval);
-
 
95
87
96
    return status;
88
    return MV_PlayXMP(ptr, length, loophow, -1, pitchoffset, mid, left, right, priority, volume, callbackval);
97
}
89
}
98
90
99
int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
91
int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitchoffset, int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
100
{
92
{
101
    VoiceNode   *voice;
-
 
102
    xmp_data * xmpd = 0;
-
 
103
    int retval;
-
 
104
-
 
105
    UNREFERENCED_PARAMETER(loopend);
93
    UNREFERENCED_PARAMETER(loopend);
106
94
107
    if (!MV_Installed)
95
    if (!MV_Installed)
108
        return MV_SetErrorCode(MV_NotInstalled);
96
        return MV_SetErrorCode(MV_NotInstalled);
109
97
110
    xmpd = (xmp_data *)Xcalloc(1, sizeof(xmp_data));
98
    auto xmpd = (xmp_data *)Xcalloc(1, sizeof(xmp_data));
111
    if (!xmpd)
99
    if (!xmpd)
112
        return MV_SetErrorCode(MV_InvalidFile);
100
        return MV_SetErrorCode(MV_InvalidFile);
113
101
114
    xmpd->ptr = ptr;
102
    xmpd->ptr = ptr;
115
    xmpd->length = length;
103
    xmpd->length = length;
Line 118... Line 106...
118
    {
106
    {
119
        Xfree(xmpd);
107
        Xfree(xmpd);
120
        return MV_SetErrorCode(MV_InvalidFile);
108
        return MV_SetErrorCode(MV_InvalidFile);
121
    }
109
    }
122
110
123
    if ((retval = xmp_load_module_from_memory(xmpd->context, ptr, length)) != 0)
111
    int const xmp_status = xmp_load_module_from_memory(xmpd->context, ptr, length);
-
 
112
-
 
113
    if (xmp_status)
124
    {
114
    {
-
 
115
        xmp_free_context(xmpd->context);
125
        Xfree(xmpd);
116
        Xfree(xmpd);
126
        MV_Printf("MV_PlayXMP: xmp_load_module_from_memory failed (%i)\n", retval);
117
        MV_Printf("MV_PlayXMP: xmp_load_module_from_memory failed (%i)\n", xmp_status);
127
        return MV_SetErrorCode(MV_InvalidFile);
118
        return MV_SetErrorCode(MV_InvalidFile);
128
    }
119
    }
129
120
130
    // Request a voice from the voice pool
121
    // Request a voice from the voice pool
131
    voice = MV_AllocVoice(priority);
122
    auto voice = MV_AllocVoice(priority);
132
    if (voice == nullptr)
123
    if (voice == nullptr)
133
    {
124
    {
134
        xmp_release_module(xmpd->context);
125
        xmp_release_module(xmpd->context);
135
        xmp_free_context(xmpd->context);
126
        xmp_free_context(xmpd->context);
136
        Xfree(xmpd);
127
        Xfree(xmpd);
Line 248... Line 239...
248
// KEEPINSYNC libxmp-lite/src/*_load.c
239
// KEEPINSYNC libxmp-lite/src/*_load.c
249
240
250
static int it_test_memory(char const *ptr, uint32_t ptrlength)
241
static int it_test_memory(char const *ptr, uint32_t ptrlength)
251
{
242
{
252
    static char const it_magic[] = "IMPM";
243
    static char const it_magic[] = "IMPM";
253
-
 
254
    if (ptrlength < sizeof(it_magic)-1 ||
-
 
255
        memcmp(ptr, it_magic, sizeof(it_magic)-1))
244
    return !!(ptrlength < sizeof(it_magic) - 1 || Bmemcmp(ptr, it_magic, sizeof(it_magic) - 1));
256
        return -1;
-
 
257
-
 
258
    return 0;
-
 
259
}
245
}
260
246
261
static int mod_test_memory(char const *ptr, uint32_t ptrlength)
247
static int mod_test_memory(char const *ptr, uint32_t ptrlength)
262
{
248
{
263
    if (ptrlength < 1084)
249
    if (ptrlength < 1084)
264
        return -1;
250
        return -1;
265
251
266
    char const * const buf = ptr + 1080;
252
    char const * const buf = ptr + 1080;
267
253
268
    if (!strncmp(buf + 2, "CH", 2) && isdigit((int)buf[0]) && isdigit((int)buf[1]))
254
    if (!Bstrncmp(buf + 2, "CH", 2) && isdigit((int)buf[0]) && isdigit((int)buf[1]))
269
    {
255
    {
270
        int i = (buf[0] - '0') * 10 + buf[1] - '0';
256
        int i = (buf[0] - '0') * 10 + buf[1] - '0';
271
        if (i > 0 && i <= 32)
257
        if (i > 0 && i <= 32)
272
            return 0;
258
            return 0;
273
    }
259
    }
274
260
275
    if (!strncmp(buf + 1, "CHN", 3) && isdigit((int)*buf))
261
    if (!Bstrncmp(buf + 1, "CHN", 3) && isdigit((int)*buf))
276
    {
262
    {
277
        if (*buf >= '0' && *buf <= '9')
263
        if (*buf >= '0' && *buf <= '9')
278
            return 0;
264
            return 0;
279
    }
265
    }
280
266
281
    if (!memcmp(buf, "M.K.", 4))
267
    if (!Bmemcmp(buf, "M.K.", 4))
282
        return 0;
268
        return 0;
283
269
284
    return -1;
270
    return -1;
285
}
271
}
286
272
287
static int s3m_test_memory(char const *ptr, uint32_t ptrlength)
273
static int s3m_test_memory(char const *ptr, uint32_t ptrlength)
288
{
274
{
289
    static char const s3m_magic[] = "SCRM";
275
    static char const s3m_magic[] = "SCRM";
290
    #define s3m_magic_offset 44
276
    #define s3m_magic_offset 44
291
277
292
    if (ptrlength < s3m_magic_offset + sizeof(s3m_magic)-1 ||
278
    return !!(ptrlength < s3m_magic_offset + sizeof(s3m_magic)-1 ||
293
        memcmp(ptr + s3m_magic_offset, s3m_magic, sizeof(s3m_magic)-1) ||
279
        Bmemcmp(ptr + s3m_magic_offset, s3m_magic, sizeof(s3m_magic)-1) ||
294
        ptr[29] != 0x10)
280
        ptr[29] != 0x10);
295
        return -1;
-
 
296
-
 
297
    return 0;
-
 
298
}
281
}
299
282
300
static int xm_test_memory(char const *ptr, uint32_t ptrlength)
283
static int xm_test_memory(char const *ptr, uint32_t ptrlength)
301
{
284
{
302
    static char const xm_magic[] = "Extended Module: ";
285
    static char const xm_magic[] = "Extended Module: ";
303
-
 
304
    if (ptrlength < sizeof(xm_magic)-1 ||
-
 
305
        memcmp(ptr, xm_magic, sizeof(xm_magic)-1))
286
    return !!(ptrlength < sizeof(xm_magic) - 1 || Bmemcmp(ptr, xm_magic, sizeof(xm_magic) - 1));
306
        return -1;
-
 
307
-
 
308
    return 0;
-
 
309
}
287
}
310
288
311
static int mtm_test_memory(char const *ptr, uint32_t ptrlength)
289
static int mtm_test_memory(char const *ptr, uint32_t ptrlength)
312
{
290
{
313
    static char const mtm_magic[] = "MTM\x10";
291
    static char const mtm_magic[] = "MTM\x10";
314
-
 
315
    if (ptrlength < sizeof(mtm_magic)-1 ||
-
 
316
        memcmp(ptr, mtm_magic, sizeof(mtm_magic)-1))
292
    return !!(ptrlength < sizeof(mtm_magic) - 1 || Bmemcmp(ptr, mtm_magic, sizeof(mtm_magic) - 1));
317
        return -1;
-
 
318
-
 
319
    return 0;
-
 
320
}
293
}
321
294
322
int MV_IdentifyXMP(char const *ptr, uint32_t ptrlength)
295
int MV_IdentifyXMP(char const *ptr, uint32_t ptrlength)
323
{
296
{
324
    static decltype(mod_test_memory) * const module_test_functions[] =
297
    static decltype(mod_test_memory) * const module_test_functions[] =