Hard an brutal reformatting to make it easier to see my changes

This commit is contained in:
sago007
2016-11-27 11:33:18 +01:00
parent 217a26e3c6
commit f5c2b2d71b
3 changed files with 1920 additions and 1505 deletions

View File

@@ -35,7 +35,7 @@ int xmpspeed = 22050; // assume 22050hz unless........
// leilei - XMP // leilei - XMP
xmp_context xmpsong; xmp_context xmpsong;
//int sound_init(int, int); //int sound_init(int, int);
void sound_play(void *, int); void sound_play(void *, int);
@@ -46,13 +46,15 @@ void sound_deinit(void);
extern int samplingrate; // from snd_dma extern int samplingrate; // from snd_dma
void S_XMP_StartSong ( void ){ void S_XMP_StartSong ( void )
{
} }
void S_XMP_EndSong ( void ){ void S_XMP_EndSong ( void )
{
@@ -84,54 +86,53 @@ snd_stream_t *S_XMP_CodecOpenStream(const char *filename)
// Open // Open
snd_stream_t *rv = S_CodecUtilOpen(filename, &xmp_codec); snd_stream_t *rv = S_CodecUtilOpen(filename, &xmp_codec);
if(!rv) if(!rv) {
return NULL; return NULL;
}
// Com_Printf("OPENSTREAM %s\n", filename); // Com_Printf("OPENSTREAM %s\n", filename);
{ {
fileHandle_t file; fileHandle_t file;
// Try to open the file // Try to open the file
FS_FOpenFileRead(filename, &file, qtrue); FS_FOpenFileRead(filename, &file, qtrue);
if(!file) if(!file) {
{ Com_Printf( S_COLOR_RED "ERROR: No.\"%s\"\n",filename);
Com_Printf( S_COLOR_RED "ERROR: No.\"%s\"\n",filename); return NULL;
return NULL; }
}
// Allocate some memory // Allocate some memory
long thelength = FS_ReadFile(filename, NULL); long thelength = FS_ReadFile(filename, NULL);
void *buffer = Hunk_AllocateTempMemory(thelength); void *buffer = Hunk_AllocateTempMemory(thelength);
if(!buffer) if(!buffer) {
{ FS_FCloseFile(file);
FS_FCloseFile(file); Com_Printf( S_COLOR_RED "ERROR: Out of memory reading \"%s\"\n", filename);
Com_Printf( S_COLOR_RED "ERROR: Out of memory reading \"%s\"\n", filename); return NULL;
return NULL; }
}
FS_Read(buffer, thelength, file); FS_Read(buffer, thelength, file);
// OK! // OK!
struct xmp_module_info mi; struct xmp_module_info mi;
xmpsong = xmp_create_context(); xmpsong = xmp_create_context();
int itsloaded = 0; int itsloaded = 0;
itsloaded = xmp_load_module_from_memory(xmpsong, buffer, 0); itsloaded = xmp_load_module_from_memory(xmpsong, buffer, 0);
// Free our memory and close the file. // Free our memory and close the file.
Hunk_FreeTempMemory(buffer); Hunk_FreeTempMemory(buffer);
FS_FCloseFile(file); // unfortunately these do not help with the leak FS_FCloseFile(file); // unfortunately these do not help with the leak
if (itsloaded == 0) if (itsloaded == 0)
itsloaded = xmp_start_player(xmpsong, xmpspeed, 0); // TODO: do sample rate of the mixer. itsloaded = xmp_start_player(xmpsong, xmpspeed, 0); // TODO: do sample rate of the mixer.
if (itsloaded == 0){ if (itsloaded == 0) {
// Com_Printf("XMP loaded our buffer of the file %s which is %i long \n", filename, thelength); // Com_Printf("XMP loaded our buffer of the file %s which is %i long \n", filename, thelength);
xmp_get_module_info(xmpsong, &mi); xmp_get_module_info(xmpsong, &mi);
// Com_Printf("Song Name: %s\n", mi.mod->name); // Com_Printf("Song Name: %s\n", mi.mod->name);
@@ -176,15 +177,13 @@ int S_XMP_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
// buffer handling // buffer handling
struct xmp_module_info mi; struct xmp_module_info mi;
struct xmp_frame_info fi; struct xmp_frame_info fi;
// check if input is valid // check if input is valid
if(!(stream && buffer)) if(!(stream && buffer)) {
{
return 0; return 0;
} }
if(bytes <= 0) if(bytes <= 0) {
{
return 0; return 0;
} }
@@ -193,18 +192,16 @@ int S_XMP_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
char* bufPtr = buffer; char* bufPtr = buffer;
// cycle until we have the requested or all available bytes read // cycle until we have the requested or all available bytes read
while(-1) while(-1) {
{
int yeah=xmp_play_buffer(xmpsong, buffer, bytesLeft, 0); int yeah=xmp_play_buffer(xmpsong, buffer, bytesLeft, 0);
if (yeah == 0){ // if we can play it... if (yeah == 0) { // if we can play it...
xmp_get_frame_info(xmpsong, &fi); xmp_get_frame_info(xmpsong, &fi);
int c = fi.buffer_size; int c = fi.buffer_size;
// no more bytes are left // no more bytes are left
if(c <= 0) if(c <= 0) {
{
break; break;
} }
@@ -214,15 +211,12 @@ int S_XMP_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
xmp_get_module_info(xmpsong, &mi); xmp_get_module_info(xmpsong, &mi);
// we have enough bytes // we have enough bytes
if(bytesLeft <= 0) if(bytesLeft <= 0) {
{
break; break;
} }
} }
else // if we can't play it JUST STOP OK else { // if we can't play it JUST STOP OK
{
break; break;
} }
} }
@@ -230,8 +224,7 @@ int S_XMP_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
} }
snd_codec_t xmp_codec = snd_codec_t xmp_codec = {
{
"umx", "umx",
S_XMP_CodecLoad, S_XMP_CodecLoad,
S_XMP_CodecOpenStream, S_XMP_CodecOpenStream,
@@ -240,8 +233,7 @@ snd_codec_t xmp_codec =
NULL NULL
}; };
snd_codec_t xmp_mod_codec = snd_codec_t xmp_mod_codec = {
{
"mod", "mod",
S_XMP_CodecLoad, S_XMP_CodecLoad,
S_XMP_CodecOpenStream, S_XMP_CodecOpenStream,
@@ -250,8 +242,7 @@ snd_codec_t xmp_mod_codec =
NULL NULL
}; };
snd_codec_t xmp_it_codec = snd_codec_t xmp_it_codec = {
{
"it", "it",
S_XMP_CodecLoad, S_XMP_CodecLoad,
S_XMP_CodecOpenStream, S_XMP_CodecOpenStream,
@@ -260,8 +251,7 @@ snd_codec_t xmp_it_codec =
NULL NULL
}; };
snd_codec_t xmp_s3m_codec = snd_codec_t xmp_s3m_codec = {
{
"s3m", "s3m",
S_XMP_CodecLoad, S_XMP_CodecLoad,
S_XMP_CodecOpenStream, S_XMP_CodecOpenStream,
@@ -270,8 +260,7 @@ snd_codec_t xmp_s3m_codec =
NULL NULL
}; };
snd_codec_t xmp_xm_codec = snd_codec_t xmp_xm_codec = {
{
"xm", "xm",
S_XMP_CodecLoad, S_XMP_CodecLoad,
S_XMP_CodecOpenStream, S_XMP_CodecOpenStream,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff