mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2025-02-27 05:31:27 +00:00
heavily customized version of DUMB (Dynamic Universal Music Bibliotheque). It has been slightly modified by me: * Added support for Ogg Vorbis-compressed samples in XM files ala FMOD. * Removed excessive mallocs from the replay core. * Rerolled the loops in resample.c. Unrolling them made the object file ~250k large while providing little benefit. Even at ~100k, I think it's still larger than it ought to be, but I'll live with it for now. Other than that, it's essentially the same thing you'd hear in foobar2000, minus some subsong detection features. Release builds of the library look like they might even be slightly faster than FMOD, which is a plus. - Fixed: Timidity::font_add() did not release the file reader it created. - Fixed: The SF2 loader did not free the sample headers in its destructor. SVN r995 (trunk)
107 lines
2.6 KiB
C
107 lines
2.6 KiB
C
/* _______ ____ __ ___ ___
|
|
* \ _ \ \ / \ / \ \ / / ' ' '
|
|
* | | \ \ | | || | \/ | . .
|
|
* | | | | | | || ||\ /| |
|
|
* | | | | | | || || \/ | | ' ' '
|
|
* | | | | | | || || | | . .
|
|
* | |_/ / \ \__// || | |
|
|
* /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
|
|
* / \
|
|
* / . \
|
|
* readduh.c - Code to read a DUH from an open / / \ \
|
|
* file. | < / \_
|
|
* | \/ /\ /
|
|
* By entheh. \_ / > /
|
|
* | \ / /
|
|
* | ' /
|
|
* \__/
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dumb.h"
|
|
#include "internal/dumb.h"
|
|
|
|
|
|
|
|
static DUH_SIGNAL *read_signal(DUH *duh, DUMBFILE *f)
|
|
{
|
|
DUH_SIGNAL *signal;
|
|
int32 type;
|
|
|
|
signal = malloc(sizeof(*signal));
|
|
|
|
if (!signal)
|
|
return NULL;
|
|
|
|
type = dumbfile_mgetl(f);
|
|
if (dumbfile_error(f)) {
|
|
free(signal);
|
|
return NULL;
|
|
}
|
|
|
|
signal->desc = _dumb_get_sigtype_desc(type);
|
|
if (!signal->desc) {
|
|
free(signal);
|
|
return NULL;
|
|
}
|
|
|
|
if (signal->desc->load_sigdata) {
|
|
signal->sigdata = (*signal->desc->load_sigdata)(duh, f);
|
|
if (!signal->sigdata) {
|
|
free(signal);
|
|
return NULL;
|
|
}
|
|
} else
|
|
signal->sigdata = NULL;
|
|
|
|
return signal;
|
|
}
|
|
|
|
|
|
|
|
/* read_duh(): reads a DUH from an already open DUMBFILE, and returns its
|
|
* pointer, or null on error. The file is not closed.
|
|
*/
|
|
DUH *DUMBEXPORT read_duh(DUMBFILE *f)
|
|
{
|
|
DUH *duh;
|
|
int i;
|
|
|
|
if (dumbfile_mgetl(f) != DUH_SIGNATURE)
|
|
return NULL;
|
|
|
|
duh = malloc(sizeof(*duh));
|
|
if (!duh)
|
|
return NULL;
|
|
|
|
duh->length = dumbfile_igetl(f);
|
|
if (dumbfile_error(f) || duh->length <= 0) {
|
|
free(duh);
|
|
return NULL;
|
|
}
|
|
|
|
duh->n_signals = dumbfile_igetl(f);
|
|
if (dumbfile_error(f) || duh->n_signals <= 0) {
|
|
free(duh);
|
|
return NULL;
|
|
}
|
|
|
|
duh->signal = malloc(sizeof(*duh->signal) * duh->n_signals);
|
|
if (!duh->signal) {
|
|
free(duh);
|
|
return NULL;
|
|
}
|
|
|
|
for (i = 0; i < duh->n_signals; i++)
|
|
duh->signal[i] = NULL;
|
|
|
|
for (i = 0; i < duh->n_signals; i++) {
|
|
if (!(duh->signal[i] = read_signal(duh, f))) {
|
|
unload_duh(duh);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
return duh;
|
|
}
|