From 7b589b31a6d21a82cd4fe32605db4596a31cf6e5 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 25 Jun 2012 12:50:09 +0000 Subject: [PATCH] updated snd bits from uhexen2. added signed 8 bit format support to the mixer. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@688 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/q_sound.h | 2 ++ Quake/snd_dma.c | 29 +++++++-------------------- Quake/snd_mix.c | 17 +++++++++++++++- Quake/snd_mp3.c | 3 +-- Quake/snd_mpg123.c | 8 +++----- Quake/snd_sdl.c | 50 ++++++++++++++++++++++------------------------ Quake/snd_vorbis.c | 6 ++++-- Quake/snd_wave.c | 2 +- 8 files changed, 58 insertions(+), 59 deletions(-) diff --git a/Quake/q_sound.h b/Quake/q_sound.h index 71ca7ac4..ace02814 100644 --- a/Quake/q_sound.h +++ b/Quake/q_sound.h @@ -55,6 +55,7 @@ typedef struct int submission_chunk; /* don't mix less than this # */ int samplepos; /* in mono samples */ int samplebits; + int signed8; /* device opened for S8 format? (e.g. Amiga AHI) */ int speed; unsigned char *buffer; } dma_t; @@ -117,6 +118,7 @@ void SND_Spatialize (channel_t *ch); /* music stream support */ void S_RawSamples(int samples, int rate, int width, int channels, byte * data, float volume); + /* Expects data in signed 16 bit, or unsigned 8 bit format. */ /* initializes cycling through a DMA buffer and returns information on it */ qboolean SNDDMA_Init(dma_t *dma); diff --git a/Quake/snd_dma.c b/Quake/snd_dma.c index c9614fa1..2c4d57d0 100644 --- a/Quake/snd_dma.c +++ b/Quake/snd_dma.c @@ -541,7 +541,7 @@ void S_ClearBuffer (void) s_rawend = 0; - if (shm->samplebits == 8) + if (shm->samplebits == 8 && !shm->signed8) clear = 0x80; else clear = 0; @@ -656,6 +656,8 @@ S_RawSamples (from QuakeII) Streaming music support. Byte swapping of data must be handled by the codec. +Expects data in signed 16 bit, or unsigned +8 bit format. =================== */ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, float volume) @@ -666,9 +668,7 @@ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, f int intVolume; if (s_rawend < paintedtime) - { s_rawend = paintedtime; - } scale = (float) rate / shm->speed; intVolume = (int) (256 * volume); @@ -678,12 +678,8 @@ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, f for (i = 0; ; i++) { src = i * scale; - if (src >= samples) - { break; - } - dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; s_rawsamples [dst].left = ((short *) data)[src * 2] * intVolume; @@ -695,12 +691,8 @@ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, f for (i = 0; ; i++) { src = i * scale; - if (src >= samples) - { break; - } - dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; s_rawsamples [dst].left = ((short *) data)[src] * intVolume; @@ -714,17 +706,12 @@ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, f for (i = 0; ; i++) { src = i * scale; - if (src >= samples) - { break; - } - dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; - // s_rawsamples [dst].left = ((char *) data)[src * 2] * intVolume; - // s_rawsamples [dst].right = ((char *) data)[src * 2 + 1] * intVolume; - /* the above doesn't work for me with U8, only the unsigned ones below do */ + // s_rawsamples [dst].left = ((signed char *) data)[src * 2] * intVolume; + // s_rawsamples [dst].right = ((signed char *) data)[src * 2 + 1] * intVolume; s_rawsamples [dst].left = (((byte *) data)[src * 2] - 128) * intVolume; s_rawsamples [dst].right = (((byte *) data)[src * 2 + 1] - 128) * intVolume; } @@ -736,14 +723,12 @@ void S_RawSamples (int samples, int rate, int width, int channels, byte *data, f for (i = 0; ; i++) { src = i * scale; - if (src >= samples) - { break; - } - dst = s_rawend & (MAX_RAW_SAMPLES - 1); s_rawend++; + // s_rawsamples [dst].left = ((signed char *) data)[src] * intVolume; + // s_rawsamples [dst].right = ((signed char *) data)[src] * intVolume; s_rawsamples [dst].left = (((byte *) data)[src] - 128) * intVolume; s_rawsamples [dst].right = (((byte *) data)[src] - 128) * intVolume; } diff --git a/Quake/snd_mix.c b/Quake/snd_mix.c index d1e1292c..ef6ffc6f 100644 --- a/Quake/snd_mix.c +++ b/Quake/snd_mix.c @@ -117,7 +117,7 @@ static void S_TransferPaintBuffer (int endtime) out_idx = (out_idx + 1) & out_mask; } } - else if (shm->samplebits == 8) + else if (shm->samplebits == 8 && !shm->signed8) { unsigned char *out = shm->buffer; while (count--) @@ -132,6 +132,21 @@ static void S_TransferPaintBuffer (int endtime) out_idx = (out_idx + 1) & out_mask; } } + else if (shm->samplebits == 8) /* S8 format, e.g. with Amiga AHI */ + { + signed char *out = (signed char *) shm->buffer; + while (count--) + { + val = *p >> 8; + p+= step; + if (val > 0x7fff) + val = 0x7fff; + else if (val < (short)0x8000) + val = (short)0x8000; + out[out_idx] = (val >> 8); + out_idx = (out_idx + 1) & out_mask; + } + } } diff --git a/Quake/snd_mp3.c b/Quake/snd_mp3.c index 27c84f6c..29f13ae5 100644 --- a/Quake/snd_mp3.c +++ b/Quake/snd_mp3.c @@ -8,7 +8,7 @@ * functions were adapted from the GPL-licensed libid3tag library, see at * http://www.underbit.com/products/mad/. Adapted to Quake and Hexen II * game engines by O.Sezer : - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * 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 @@ -24,7 +24,6 @@ * 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" diff --git a/Quake/snd_mpg123.c b/Quake/snd_mpg123.c index 9a4d6896..b9c3a4c8 100644 --- a/Quake/snd_mpg123.c +++ b/Quake/snd_mpg123.c @@ -1,9 +1,8 @@ /* * MP3 decoding support using libmpg123, loosely based on an SDL_mixer - * plugin found at http://bubu.lv/ * See: http://bubu.lv/changeset/4/public/libs/SDL/generated/SDL_mixer * - * Copyright (C) 2011 O.Sezer + * Copyright (C) 2011-2012 O.Sezer * * 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 @@ -19,7 +18,6 @@ * 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" @@ -31,8 +29,8 @@ #include #include -#if !defined(MPG123_API_VERSION) || (MPG123_API_VERSION < 25) -#error minimum required libmpg123 version is 1.12.0 (api version 25) +#if !defined(MPG123_API_VERSION) || (MPG123_API_VERSION < 24) +#error minimum required libmpg123 version is 1.12.0 (api version 24) #endif /* MPG123_API_VERSION */ /* Private data */ diff --git a/Quake/snd_sdl.c b/Quake/snd_sdl.c index f43b021b..8f1ccc20 100644 --- a/Quake/snd_sdl.c +++ b/Quake/snd_sdl.c @@ -1,36 +1,32 @@ /* - snd_sdl.c - SDL audio driver for Hexen II: Hammer of Thyrion, based on the - implementations found in the quakeforge and quake3-icculus.org - projects. - - Copyright (C) 1999-2005 Id Software, Inc. - Copyright (C) 2005-2011 O.Sezer - - 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: - - Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301 USA -*/ + * snd_sdl.c - SDL audio driver for Hexen II: Hammer of Thyrion (uHexen2) + * based on implementations found in the quakeforge and ioquake3 projects. + * + * Copyright (C) 1999-2005 Id Software, Inc. + * Copyright (C) 2005-2012 O.Sezer + * + * 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" #include "SDL.h" static int buffersize; + static void paint_audio (void *unused, Uint8 *stream, int len) { int pos, tobufend; @@ -110,6 +106,7 @@ qboolean SNDDMA_Init (dma_t *dma) /* Make sure we can support the audio format */ switch (obtained.format) { + case AUDIO_S8: /* maybe needed by AHI */ case AUDIO_U8: case AUDIO_S16SYS: /* Supported */ @@ -126,6 +123,7 @@ qboolean SNDDMA_Init (dma_t *dma) /* Fill the audio DMA information block */ shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */ + shm->signed8 = (obtained.format == AUDIO_S8); if (obtained.freq != tmp) Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp); shm->speed = obtained.freq; diff --git a/Quake/snd_vorbis.c b/Quake/snd_vorbis.c index cd33f2c8..bbc94bd8 100644 --- a/Quake/snd_vorbis.c +++ b/Quake/snd_vorbis.c @@ -2,7 +2,7 @@ * Ogg/Vorbis streaming music support, loosely based on several open source * Quake engine based projects with many modifications. * - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * 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 @@ -63,6 +63,8 @@ static const ov_callbacks ovc_qfs = (long (*)(void *)) FS_ftell }; +#define OV_OPEN_CALLBACKS ov_open_callbacks + static qboolean S_OGG_CodecInitialize (void) { return true; @@ -84,7 +86,7 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename) return NULL; ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File)); - res = ov_open_callbacks(&stream->fh, ovFile, NULL, 0, ovc_qfs); + res = OV_OPEN_CALLBACKS(&stream->fh, ovFile, NULL, 0, ovc_qfs); if (res != 0) { Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n", diff --git a/Quake/snd_wave.c b/Quake/snd_wave.c index 3d3e781e..1f09c4d3 100644 --- a/Quake/snd_wave.c +++ b/Quake/snd_wave.c @@ -3,7 +3,7 @@ * * Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 2005 Stuart Dalton - * Copyright (C) 2010-2011 O.Sezer + * Copyright (C) 2010-2012 O.Sezer * * 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