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
This commit is contained in:
Ozkan Sezer 2012-06-25 12:50:09 +00:00
parent d6e28185d9
commit 7b589b31a6
8 changed files with 58 additions and 59 deletions

View file

@ -55,6 +55,7 @@ typedef struct
int submission_chunk; /* don't mix less than this # */ int submission_chunk; /* don't mix less than this # */
int samplepos; /* in mono samples */ int samplepos; /* in mono samples */
int samplebits; int samplebits;
int signed8; /* device opened for S8 format? (e.g. Amiga AHI) */
int speed; int speed;
unsigned char *buffer; unsigned char *buffer;
} dma_t; } dma_t;
@ -117,6 +118,7 @@ void SND_Spatialize (channel_t *ch);
/* music stream support */ /* music stream support */
void S_RawSamples(int samples, int rate, int width, int channels, byte * data, float volume); 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 */ /* initializes cycling through a DMA buffer and returns information on it */
qboolean SNDDMA_Init(dma_t *dma); qboolean SNDDMA_Init(dma_t *dma);

View file

@ -541,7 +541,7 @@ void S_ClearBuffer (void)
s_rawend = 0; s_rawend = 0;
if (shm->samplebits == 8) if (shm->samplebits == 8 && !shm->signed8)
clear = 0x80; clear = 0x80;
else else
clear = 0; clear = 0;
@ -656,6 +656,8 @@ S_RawSamples (from QuakeII)
Streaming music support. Byte swapping Streaming music support. Byte swapping
of data must be handled by the codec. 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) 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; int intVolume;
if (s_rawend < paintedtime) if (s_rawend < paintedtime)
{
s_rawend = paintedtime; s_rawend = paintedtime;
}
scale = (float) rate / shm->speed; scale = (float) rate / shm->speed;
intVolume = (int) (256 * volume); 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++) for (i = 0; ; i++)
{ {
src = i * scale; src = i * scale;
if (src >= samples) if (src >= samples)
{
break; break;
}
dst = s_rawend & (MAX_RAW_SAMPLES - 1); dst = s_rawend & (MAX_RAW_SAMPLES - 1);
s_rawend++; s_rawend++;
s_rawsamples [dst].left = ((short *) data)[src * 2] * intVolume; 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++) for (i = 0; ; i++)
{ {
src = i * scale; src = i * scale;
if (src >= samples) if (src >= samples)
{
break; break;
}
dst = s_rawend & (MAX_RAW_SAMPLES - 1); dst = s_rawend & (MAX_RAW_SAMPLES - 1);
s_rawend++; s_rawend++;
s_rawsamples [dst].left = ((short *) data)[src] * intVolume; 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++) for (i = 0; ; i++)
{ {
src = i * scale; src = i * scale;
if (src >= samples) if (src >= samples)
{
break; break;
}
dst = s_rawend & (MAX_RAW_SAMPLES - 1); dst = s_rawend & (MAX_RAW_SAMPLES - 1);
s_rawend++; s_rawend++;
// s_rawsamples [dst].left = ((char *) data)[src * 2] * intVolume; // s_rawsamples [dst].left = ((signed char *) data)[src * 2] * intVolume;
// s_rawsamples [dst].right = ((char *) data)[src * 2 + 1] * intVolume; // s_rawsamples [dst].right = ((signed 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 = (((byte *) data)[src * 2] - 128) * intVolume; s_rawsamples [dst].left = (((byte *) data)[src * 2] - 128) * intVolume;
s_rawsamples [dst].right = (((byte *) data)[src * 2 + 1] - 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++) for (i = 0; ; i++)
{ {
src = i * scale; src = i * scale;
if (src >= samples) if (src >= samples)
{
break; break;
}
dst = s_rawend & (MAX_RAW_SAMPLES - 1); dst = s_rawend & (MAX_RAW_SAMPLES - 1);
s_rawend++; 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].left = (((byte *) data)[src] - 128) * intVolume;
s_rawsamples [dst].right = (((byte *) data)[src] - 128) * intVolume; s_rawsamples [dst].right = (((byte *) data)[src] - 128) * intVolume;
} }

View file

@ -117,7 +117,7 @@ static void S_TransferPaintBuffer (int endtime)
out_idx = (out_idx + 1) & out_mask; out_idx = (out_idx + 1) & out_mask;
} }
} }
else if (shm->samplebits == 8) else if (shm->samplebits == 8 && !shm->signed8)
{ {
unsigned char *out = shm->buffer; unsigned char *out = shm->buffer;
while (count--) while (count--)
@ -132,6 +132,21 @@ static void S_TransferPaintBuffer (int endtime)
out_idx = (out_idx + 1) & out_mask; 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;
}
}
} }

View file

@ -8,7 +8,7 @@
* functions were adapted from the GPL-licensed libid3tag library, see at * functions were adapted from the GPL-licensed libid3tag library, see at
* http://www.underbit.com/products/mad/. Adapted to Quake and Hexen II * http://www.underbit.com/products/mad/. Adapted to Quake and Hexen II
* game engines by O.Sezer : * game engines by O.Sezer :
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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 * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/ */
#include "quakedef.h" #include "quakedef.h"

View file

@ -1,9 +1,8 @@
/* /*
* MP3 decoding support using libmpg123, loosely based on an SDL_mixer * 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 * See: http://bubu.lv/changeset/4/public/libs/SDL/generated/SDL_mixer
* *
* Copyright (C) 2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2011-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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 * 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., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/ */
#include "quakedef.h" #include "quakedef.h"
@ -31,8 +29,8 @@
#include <errno.h> #include <errno.h>
#include <mpg123.h> #include <mpg123.h>
#if !defined(MPG123_API_VERSION) || (MPG123_API_VERSION < 25) #if !defined(MPG123_API_VERSION) || (MPG123_API_VERSION < 24)
#error minimum required libmpg123 version is 1.12.0 (api version 25) #error minimum required libmpg123 version is 1.12.0 (api version 24)
#endif /* MPG123_API_VERSION */ #endif /* MPG123_API_VERSION */
/* Private data */ /* Private data */

View file

@ -1,36 +1,32 @@
/* /*
snd_sdl.c * snd_sdl.c - SDL audio driver for Hexen II: Hammer of Thyrion (uHexen2)
SDL audio driver for Hexen II: Hammer of Thyrion, based on the * based on implementations found in the quakeforge and ioquake3 projects.
implementations found in the quakeforge and quake3-icculus.org *
projects. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005-2012 O.Sezer <sezero@users.sourceforge.net>
Copyright (C) 1999-2005 Id Software, Inc. *
Copyright (C) 2005-2011 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
This program is free software; you can redistribute it and/or * the Free Software Foundation; either version 2 of the License, or (at
modify it under the terms of the GNU General Public License * your option) any later version.
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
This program is distributed in the hope that it will be useful, * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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.
*
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.,
You should have received a copy of the GNU General Public License * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
along with this program; if not, write to: */
Free Software Foundation, Inc.
51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "quakedef.h" #include "quakedef.h"
#include "SDL.h" #include "SDL.h"
static int buffersize; static int buffersize;
static void paint_audio (void *unused, Uint8 *stream, int len) static void paint_audio (void *unused, Uint8 *stream, int len)
{ {
int pos, tobufend; int pos, tobufend;
@ -110,6 +106,7 @@ qboolean SNDDMA_Init (dma_t *dma)
/* Make sure we can support the audio format */ /* Make sure we can support the audio format */
switch (obtained.format) switch (obtained.format)
{ {
case AUDIO_S8: /* maybe needed by AHI */
case AUDIO_U8: case AUDIO_U8:
case AUDIO_S16SYS: case AUDIO_S16SYS:
/* Supported */ /* Supported */
@ -126,6 +123,7 @@ qboolean SNDDMA_Init (dma_t *dma)
/* Fill the audio DMA information block */ /* Fill the audio DMA information block */
shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */ shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */
shm->signed8 = (obtained.format == AUDIO_S8);
if (obtained.freq != tmp) if (obtained.freq != tmp)
Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp); Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp);
shm->speed = obtained.freq; shm->speed = obtained.freq;

View file

@ -2,7 +2,7 @@
* Ogg/Vorbis streaming music support, loosely based on several open source * Ogg/Vorbis streaming music support, loosely based on several open source
* Quake engine based projects with many modifications. * Quake engine based projects with many modifications.
* *
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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 (long (*)(void *)) FS_ftell
}; };
#define OV_OPEN_CALLBACKS ov_open_callbacks
static qboolean S_OGG_CodecInitialize (void) static qboolean S_OGG_CodecInitialize (void)
{ {
return true; return true;
@ -84,7 +86,7 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
return NULL; return NULL;
ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File)); 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) if (res != 0)
{ {
Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n", Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n",

View file

@ -3,7 +3,7 @@
* *
* Copyright (C) 1999-2005 Id Software, Inc. * Copyright (C) 1999-2005 Id Software, Inc.
* Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com> * Copyright (C) 2005 Stuart Dalton <badcdev@gmail.com>
* Copyright (C) 2010-2011 O.Sezer <sezero@users.sourceforge.net> * Copyright (C) 2010-2012 O.Sezer <sezero@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by