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 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);

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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 <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
* 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"

View File

@ -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 <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
* 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 <errno.h>
#include <mpg123.h>
#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 */

View File

@ -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 <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:
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 <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"
#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;

View File

@ -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 <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
* 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",

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1999-2005 Id Software, Inc.
* 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
* it under the terms of the GNU General Public License as published by