Subversion Repositories eduke32

Rev

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

Rev 8782 Rev 8783
Line 193... Line 193...
193
}
193
}
194
194
195
int FX_GetDevice(void) { return ASS_PCMSoundDriver; }
195
int FX_GetDevice(void) { return ASS_PCMSoundDriver; }
196
196
197
197
-
 
198
#define FMT_MAGIC(i, j, k, l) (i + (j << 8) + (k << 16) + (l << 24))
-
 
199
uint32_t constexpr FMT_CDXA_MAGIC = FMT_MAGIC('C','D','X','A');
-
 
200
uint32_t constexpr FMT_FLAC_MAGIC = FMT_MAGIC('f','L','a','C');
-
 
201
uint32_t constexpr FMT_OGG_MAGIC  = FMT_MAGIC('O','g','g','S');
-
 
202
uint32_t constexpr FMT_RIFF_MAGIC = FMT_MAGIC('R','I','F','F');
-
 
203
uint32_t constexpr FMT_VOC_MAGIC  = FMT_MAGIC('C','r','e','a');
-
 
204
uint32_t constexpr FMT_WAVE_MAGIC = FMT_MAGIC('W','A','V','E');
-
 
205
#undef FMT_MAGIC
-
 
206
198
static wavefmt_t FX_DetectFormat(char const * const ptr, uint32_t length)
207
static wavefmt_t FX_ReadFmt(char const * const ptr, uint32_t length)
199
{
208
{
200
    if (length < 12)
209
    if (length < 12)
201
        return FMT_UNKNOWN;
210
        return FMT_UNKNOWN;
202
211
203
    wavefmt_t fmt = FMT_UNKNOWN;
212
    auto const ptr32 = (uint32_t const *)ptr;
204
213
205
    switch (B_LITTLE32(*(int const *)ptr))
214
    switch (B_LITTLE32(*ptr32))
206
    {
-
 
207
        case 'C' + ('r' << 8) + ('e' << 16) + ('a' << 24):  // Crea
-
 
208
            fmt = FMT_VOC;
-
 
209
            break;
-
 
210
        case 'O' + ('g' << 8) + ('g' << 16) + ('S' << 24):  // OggS
-
 
211
            fmt = FMT_VORBIS;
-
 
212
            break;
-
 
213
        case 'R' + ('I' << 8) + ('F' << 16) + ('F' << 24):  // RIFF
-
 
214
            switch (B_LITTLE32(*(int const *)(ptr + 8)))
-
 
215
            {
215
    {
216
                case 'C' + ('D' << 8) + ('X' << 16) + ('A' << 24):  // CDXA
-
 
217
                    fmt = FMT_XA;
216
        case FMT_OGG_MAGIC:  return FMT_VORBIS;
218
                    break;
217
        case FMT_VOC_MAGIC:  return FMT_VOC;
219
                case 'W' + ('A' << 8) + ('V' << 16) + ('E' << 24):  // WAVE
-
 
220
                    fmt = FMT_WAV;
218
        case FMT_FLAC_MAGIC: return FMT_FLAC;
221
                    break;
219
        case FMT_RIFF_MAGIC:
222
            }
-
 
223
            break;
-
 
224
        case 'f' + ('L' << 8) + ('a' << 16) + ('C' << 24):  // fLaC
220
            if (B_LITTLE32(ptr32[2]) == FMT_WAVE_MAGIC) return FMT_WAV;
225
            fmt = FMT_FLAC;
221
            if (B_LITTLE32(ptr32[2]) == FMT_CDXA_MAGIC) return FMT_XA;
226
            break;
222
            break;
227
        default:
223
        default:
228
            if (MV_IdentifyXMP(ptr, length))
224
            if (MV_IdentifyXMP(ptr, length)) return FMT_XMP;
229
                fmt = FMT_XMP;
-
 
230
            break;
225
            break;
231
    }
226
    }
232
227
233
    return fmt;
228
    return FMT_UNKNOWN;
234
}
229
}
235
230
-
 
231
static int FX_BadFmt(char *, uint32_t, int, int, int, int, int, int, int, fix16_t, intptr_t) { return MV_SetErrorCode(MV_InvalidFile); }
-
 
232
static int FX_BadFmt3D(char *, uint32_t, int, int, int, int, int, fix16_t, intptr_t)         { return MV_SetErrorCode(MV_InvalidFile); }
-
 
233
236
int FX_Play(char *ptr, uint32_t ptrlength, int loopstart, int loopend, int pitchoffset,
234
int FX_Play(char *ptr, uint32_t ptrlength, int loopstart, int loopend, int pitchoffset,
237
                          int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
235
            int vol, int left, int right, int priority, fix16_t volume, intptr_t callbackval)
238
{
236
{
239
    static constexpr decltype(MV_PlayVOC) *func[] =
-
 
240
    { nullptr, nullptr, MV_PlayVOC, MV_PlayWAV, MV_PlayVorbis, MV_PlayFLAC, MV_PlayXA, MV_PlayXMP };
237
    static constexpr decltype(FX_Play) *func[] = { FX_BadFmt, nullptr, MV_PlayVOC, MV_PlayWAV, MV_PlayVorbis, MV_PlayFLAC, MV_PlayXA, MV_PlayXMP };
241
238
242
    EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
239
    EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
243
240
244
    wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
-
 
245
-
 
246
    int handle =
-
 
247
    (func[fmt]) ? func[fmt](ptr, ptrlength, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval) : -1;
241
    int handle = func[FX_ReadFmt(ptr, ptrlength)](ptr, ptrlength, loopstart, loopend, pitchoffset, vol, left, right, priority, volume, callbackval);
248
242
249
    if (handle <= MV_Ok)
243
    if (handle <= MV_Ok)
250
    {
244
    {
251
        FX_SetErrorCode(FX_MultiVocError);
245
        FX_SetErrorCode(FX_MultiVocError);
252
        handle = FX_Warning;
246
        handle = FX_Warning;
Line 256... Line 250...
256
}
250
}
257
251
258
int FX_Play3D(char *ptr, uint32_t ptrlength, int loophow, int pitchoffset, int angle, int distance,
252
int FX_Play3D(char *ptr, uint32_t ptrlength, int loophow, int pitchoffset, int angle, int distance,
259
                      int priority, fix16_t volume, intptr_t callbackval)
253
              int priority, fix16_t volume, intptr_t callbackval)
260
{
254
{
261
    static constexpr decltype(MV_PlayVOC3D) *func[] =
-
 
262
    { nullptr, nullptr, MV_PlayVOC3D, MV_PlayWAV3D, MV_PlayVorbis3D, MV_PlayFLAC3D, MV_PlayXA3D, MV_PlayXMP3D };
255
    static constexpr decltype(FX_Play3D) *func[] = { FX_BadFmt3D, nullptr, MV_PlayVOC3D, MV_PlayWAV3D, MV_PlayVorbis3D, MV_PlayFLAC3D, MV_PlayXA3D, MV_PlayXMP3D };
263
256
264
    EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
257
    EDUKE32_STATIC_ASSERT(FMT_MAX == ARRAY_SIZE(func));
265
258
266
    wavefmt_t const fmt = FX_DetectFormat(ptr, ptrlength);
-
 
267
-
 
268
    int handle =
-
 
269
    (func[fmt]) ? func[fmt](ptr, ptrlength, loophow, pitchoffset, angle, distance, priority, volume, callbackval) : -1;
259
    int handle = func[FX_ReadFmt(ptr, ptrlength)](ptr, ptrlength, loophow, pitchoffset, angle, distance, priority, volume, callbackval);
270
260
271
    if (handle <= MV_Ok)
261
    if (handle <= MV_Ok)
272
    {
262
    {
273
        FX_SetErrorCode(FX_MultiVocError);
263
        FX_SetErrorCode(FX_MultiVocError);
274
        handle = FX_Warning;
264
        handle = FX_Warning;