remove wave and xmp codecs, fix platform stuff

master
an 2019-11-25 01:27:51 -05:00
parent 408f1ea5fe
commit b5dcbff08d
6 changed files with 33 additions and 497 deletions

View File

@ -23,7 +23,7 @@ pkg_check_modules(Opus IMPORTED_TARGET opus>=1.3.1
ogg>=1.3.4)
pkg_check_modules(MikMod IMPORTED_TARGET libmikmod>=3.3.11)
add_executable(quake WIN32
set(srcs
source/anorm_dots.h
source/anorms.h
source/arch_def.h
@ -86,7 +86,6 @@ add_executable(quake WIN32
source/menu.h
source/modelgen.h
source/net.h
source/net_bsd.c
source/net_defs.h
source/net_dgrm.c
source/net_dgrm.h
@ -94,9 +93,6 @@ add_executable(quake WIN32
source/net_loop.h
source/net_main.c
source/net_sys.h
source/net_udp.c
source/net_udp.h
source/pl_linux.c
source/platform.h
source/pr_cmds.c
source/pr_comp.h
@ -141,10 +137,6 @@ add_executable(quake WIN32
source/snd_umx.h
source/snd_vorbis.c
source/snd_vorbis.h
source/snd_wave.c
source/snd_wave.h
source/snd_xmp.c
source/snd_xmp.h
source/spritegn.h
source/stb_image_write.h
source/strl_fn.h
@ -155,7 +147,6 @@ add_executable(quake WIN32
source/sv_phys.c
source/sv_user.c
source/sys.h
source/sys_sdl_unix.c
source/vid.h
source/view.c
source/view.h
@ -167,14 +158,36 @@ add_executable(quake WIN32
source/zone.c
source/zone.h)
if(WIN32)
list(APPEND srcs
source/net_win.c
source/net_wins.c
source/net_wins.h
source/net_wipx.c
source/net_wipx.h
source/pl_win.c
source/sys_sdl_win.c)
else()
list(APPEND srcs
source/net_bsd.c
source/net_udp.c
source/net_udp.h
source/pl_linux.c
source/sys_sdl_unix.c)
endif()
add_executable(quake WIN32 ${srcs})
function(agw_checked_library define library)
target_compile_definitions(quake PUBLIC -D${define}=1)
target_link_libraries(quake ${library})
if(${library}_FOUND)
target_compile_definitions(quake PUBLIC -D${define}=1)
target_link_libraries(quake PkgConfig::${library})
endif()
endfunction()
agw_checked_library(USE_CODEC_FLAC PkgConfig::FLAC)
agw_checked_library(USE_CODEC_VORBIS PkgConfig::Vorbis)
agw_checked_library(USE_CODEC_OPUS PkgConfig::Opus)
agw_checked_library(USE_CODEC_MikMod PkgConfig::MikMod)
agw_checked_library(USE_CODEC_FLAC FLAC)
agw_checked_library(USE_CODEC_VORBIS Vorbis)
agw_checked_library(USE_CODEC_OPUS Opus)
agw_checked_library(USE_CODEC_MikMod MikMod)
target_link_libraries(quake m OpenGL::GL PkgConfig::SDL2)

View File

@ -29,9 +29,7 @@
/* headers for individual codecs */
#include "snd_mikmod.h"
#include "snd_xmp.h"
#include "snd_umx.h"
#include "snd_wave.h"
#include "snd_flac.h"
#include "snd_mp3.h"
#include "snd_vorbis.h"
@ -67,23 +65,17 @@ void S_CodecInit (void)
#ifdef USE_CODEC_MIKMOD
S_CodecRegister(&mikmod_codec);
#endif
#ifdef USE_CODEC_XMP
S_CodecRegister(&xmp_codec);
#endif
#ifdef USE_CODEC_WAVE
S_CodecRegister(&wav_codec);
#endif
#ifdef USE_CODEC_FLAC
S_CodecRegister(&flac_codec);
#endif
#ifdef USE_CODEC_MP3
S_CodecRegister(&mp3_codec);
#ifdef USE_CODEC_OPUS
S_CodecRegister(&opus_codec);
#endif
#ifdef USE_CODEC_VORBIS
S_CodecRegister(&vorbis_codec);
#endif
#ifdef USE_CODEC_OPUS
S_CodecRegister(&opus_codec);
#ifdef USE_CODEC_MP3
S_CodecRegister(&mp3_codec);
#endif
codec = codecs;

View File

@ -1,276 +0,0 @@
/*
* WAV streaming music support. Adapted from ioquake3 with changes.
*
* Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "quakedef.h"
#if defined(USE_CODEC_WAVE)
#include "snd_codec.h"
#include "snd_codeci.h"
#include "snd_wave.h"
/*
=================
FGetLittleLong
=================
*/
static int FGetLittleLong (FILE *f)
{
int v;
fread(&v, 1, sizeof(v), f);
return LittleLong(v);
}
/*
=================
FGetLittleShort
=================
*/
static short FGetLittleShort(FILE *f)
{
short v;
fread(&v, 1, sizeof(v), f);
return LittleShort(v);
}
/*
=================
WAV_ReadChunkInfo
=================
*/
static int WAV_ReadChunkInfo(FILE *f, char *name)
{
int len, r;
name[4] = 0;
r = fread(name, 1, 4, f);
if (r != 4)
return -1;
len = FGetLittleLong(f);
if (len < 0)
{
Con_Printf("WAV: Negative chunk length\n");
return -1;
}
return len;
}
/*
=================
WAV_FindRIFFChunk
Returns the length of the data in the chunk, or -1 if not found
=================
*/
static int WAV_FindRIFFChunk(FILE *f, const char *chunk)
{
char name[5];
int len;
while ((len = WAV_ReadChunkInfo(f, name)) >= 0)
{
/* If this is the right chunk, return */
if (!strncmp(name, chunk, 4))
return len;
len = ((len + 1) & ~1); /* pad by 2 . */
/* Not the right chunk - skip it */
fseek(f, len, SEEK_CUR);
}
return -1;
}
/*
=================
WAV_ReadRIFFHeader
=================
*/
static qboolean WAV_ReadRIFFHeader(const char *name, FILE *file, snd_info_t *info)
{
char dump[16];
int wav_format;
int fmtlen = 0;
if (fread(dump, 1, 12, file) < 12 ||
strncmp(dump, "RIFF", 4) != 0 ||
strncmp(&dump[8], "WAVE", 4) != 0)
{
Con_Printf("%s is missing RIFF/WAVE chunks\n", name);
return false;
}
/* Scan for the format chunk */
if ((fmtlen = WAV_FindRIFFChunk(file, "fmt ")) < 0)
{
Con_Printf("%s is missing fmt chunk\n", name);
return false;
}
/* Save the parameters */
wav_format = FGetLittleShort(file);
if (wav_format != WAV_FORMAT_PCM)
{
Con_Printf("%s is not Microsoft PCM format\n", name);
return false;
}
info->channels = FGetLittleShort(file);
info->rate = FGetLittleLong(file);
FGetLittleLong(file);
FGetLittleShort(file);
info->bits = FGetLittleShort(file);
if (info->bits != 8 && info->bits != 16)
{
Con_Printf("%s is not 8 or 16 bit\n", name);
return false;
}
info->width = info->bits / 8;
info->dataofs = 0;
/* Skip the rest of the format chunk if required */
if (fmtlen > 16)
{
fmtlen -= 16;
fseek(file, fmtlen, SEEK_CUR);
}
/* Scan for the data chunk */
if ((info->size = WAV_FindRIFFChunk(file, "data")) < 0)
{
Con_Printf("%s is missing data chunk\n", name);
return false;
}
if (info->channels != 1 && info->channels != 2)
{
Con_Printf("Unsupported number of channels %d in %s\n",
info->channels, name);
return false;
}
info->samples = (info->size / info->width) / info->channels;
if (info->samples == 0)
{
Con_Printf("%s has zero samples\n", name);
return false;
}
return true;
}
/*
=================
S_WAV_CodecOpenStream
=================
*/
static qboolean S_WAV_CodecOpenStream(snd_stream_t *stream)
{
long start = stream->fh.start;
/* Read the RIFF header */
/* The file reads are sequential, therefore no need
* for the FS_*() functions: We will manipulate the
* file by ourselves from now on. */
if (!WAV_ReadRIFFHeader(stream->name, stream->fh.file, &stream->info))
return false;
stream->fh.start = ftell(stream->fh.file); /* reset to data position */
if (stream->fh.start - start + stream->info.size > stream->fh.length)
{
Con_Printf("%s data size mismatch\n", stream->name);
return false;
}
return true;
}
/*
=================
S_WAV_CodecReadStream
=================
*/
int S_WAV_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
{
int remaining = stream->info.size - stream->fh.pos;
int i, samples;
if (remaining <= 0)
return 0;
if (bytes > remaining)
bytes = remaining;
stream->fh.pos += bytes;
fread(buffer, 1, bytes, stream->fh.file);
if (stream->info.width == 2)
{
samples = bytes / 2;
for (i = 0; i < samples; i++)
((short *)buffer)[i] = LittleShort( ((short *)buffer)[i] );
}
return bytes;
}
static void S_WAV_CodecCloseStream (snd_stream_t *stream)
{
S_CodecUtilClose(&stream);
}
static int S_WAV_CodecRewindStream (snd_stream_t *stream)
{
FS_rewind(&stream->fh);
return 0;
}
static qboolean S_WAV_CodecInitialize (void)
{
return true;
}
static void S_WAV_CodecShutdown (void)
{
}
snd_codec_t wav_codec =
{
CODECTYPE_WAVE,
true, /* always available. */
"wav",
S_WAV_CodecInitialize,
S_WAV_CodecShutdown,
S_WAV_CodecOpenStream,
S_WAV_CodecReadStream,
S_WAV_CodecRewindStream,
S_WAV_CodecCloseStream,
NULL
};
#endif /* USE_CODEC_WAVE */

View File

@ -1,13 +0,0 @@
/* WAV streaming music support. */
#if !defined(_SND_WAVE_H_)
#define _SND_WAVE_H_
#if defined(USE_CODEC_WAVE)
extern snd_codec_t wav_codec;
#endif /* USE_CODEC_WAVE */
#endif /* ! _SND_WAVE_H_ */

View File

@ -1,168 +0,0 @@
/* tracker music (module file) decoding support using libxmp >= v4.2.0
* https://sourceforge.net/projects/xmp/
* https://github.com/cmatsuoka/libxmp.git
*
* Copyright (C) 2016 O.Sezer <sezero@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "quakedef.h"
#if defined(USE_CODEC_XMP)
#include "snd_codec.h"
#include "snd_codeci.h"
#include "snd_xmp.h"
#if defined(_WIN32) && defined(XMP_NO_DLL)
#define BUILDING_STATIC
#endif
#include <xmp.h>
#if ((XMP_VERCODE+0) < 0x040200)
#error libxmp version 4.2 or newer is required
#endif
static int S_XMP_StartPlay (snd_stream_t *stream)
{
int fmt = 0;
if (stream->info.channels == 1)
fmt |= XMP_FORMAT_MONO;
if (stream->info.width == 1)
fmt |= XMP_FORMAT_8BIT|XMP_FORMAT_UNSIGNED;
return xmp_start_player((xmp_context)stream->priv, stream->info.rate, fmt);
}
static qboolean S_XMP_CodecInitialize (void)
{
return true;
}
static void S_XMP_CodecShutdown (void)
{
}
static qboolean S_XMP_CodecOpenStream (snd_stream_t *stream)
{
/* need to load the whole file into memory and pass it to libxmp
* using xmp_load_module_from_memory() which requires libxmp >= 4.2.
* libxmp-4.0/4.1 only have xmp_load_module() which accepts a file
* name which isn't good with files in containers like paks, etc. */
xmp_context c;
byte *moddata;
long len;
int mark;
c = xmp_create_context();
if (c == NULL)
return false;
len = FS_filelength (&stream->fh);
mark = Hunk_LowMark();
moddata = (byte *) Hunk_Alloc(len);
FS_fread(moddata, 1, len, &stream->fh);
if (xmp_load_module_from_memory(c, moddata, len) != 0)
{
Con_DPrintf("Could not load module %s\n", stream->name);
goto err1;
}
Hunk_FreeToLowMark(mark); /* free original file data */
stream->priv = c;
if (shm->speed > XMP_MAX_SRATE)
stream->info.rate = 44100;
else if (shm->speed < XMP_MIN_SRATE)
stream->info.rate = 11025;
else stream->info.rate = shm->speed;
stream->info.bits = shm->samplebits;
stream->info.width = stream->info.bits / 8;
stream->info.channels = shm->channels;
if (S_XMP_StartPlay(stream) != 0)
goto err2;
/* percentual left/right channel separation, default is 70. */
if (stream->info.channels == 2)
if (xmp_set_player(c, XMP_PLAYER_MIX, 100) != 0)
goto err3;
/* interpolation type, default is XMP_INTERP_LINEAR */
if (xmp_set_player(c, XMP_PLAYER_INTERP, XMP_INTERP_SPLINE) != 0)
goto err3;
return true;
err3: xmp_end_player(c);
err2: xmp_release_module(c);
err1: xmp_free_context(c);
return false;
}
static int S_XMP_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer)
{
int r;
/* xmp_play_buffer() requires libxmp >= 4.1. it will write
* native-endian pcm data to the buffer. if the data write
* is partial, the rest of the buffer will be zero-filled.
* the last param is the number that the current sequence of
* the song will be looped at max. */
r = xmp_play_buffer((xmp_context)stream->priv, buffer, bytes, 1);
if (r == 0) {
return bytes;
}
if (r == -XMP_END) {
Con_DPrintf("XMP EOF\n");
return 0;
}
return -1;
}
static void S_XMP_CodecCloseStream (snd_stream_t *stream)
{
xmp_context c = (xmp_context)stream->priv;
xmp_end_player(c);
xmp_release_module(c);
xmp_free_context(c);
S_CodecUtilClose(&stream);
}
static int S_XMP_CodecRewindStream (snd_stream_t *stream)
{
int ret;
ret = S_XMP_StartPlay(stream);
if (ret < 0) return ret;
/*ret = xmp_set_position((xmp_context)stream->priv, 0);*/
ret = xmp_seek_time((xmp_context)stream->priv, 0);
if (ret < 0) return ret;
return 0;
}
snd_codec_t xmp_codec =
{
CODECTYPE_MOD,
true, /* always available. */
"s3m",
S_XMP_CodecInitialize,
S_XMP_CodecShutdown,
S_XMP_CodecOpenStream,
S_XMP_CodecReadStream,
S_XMP_CodecRewindStream,
S_XMP_CodecCloseStream,
NULL
};
#endif /* USE_CODEC_XMP */

View File

@ -1,12 +0,0 @@
/* module tracker decoding support using libxmp */
#if !defined(_SND_XMP_H_)
#define _SND_XMP_H_
#if defined(USE_CODEC_XMP)
extern snd_codec_t xmp_codec;
#endif /* USE_CODEC_XMP */
#endif /* ! _SND_XMP_H_ */