From d4056662a4c70bf2817d470694a3506bb35f0b7f Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 9 Mar 2007 22:50:48 +0000 Subject: Move the pcsound library to the top level, alongside textscreen. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 849 --- pcsound/pcsound_sdl.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 pcsound/pcsound_sdl.c (limited to 'pcsound/pcsound_sdl.c') diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c new file mode 100644 index 00000000..50820394 --- /dev/null +++ b/pcsound/pcsound_sdl.c @@ -0,0 +1,179 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2007 Simon Howard +// +// 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., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// PC speaker interface. +// +//----------------------------------------------------------------------------- + +#include +#include + +#include "SDL.h" +#include "SDL_mixer.h" + +#include "pcsound.h" + +#define SQUARE_WAVE_AMP 0x2000 + +static pcsound_callback_func callback; + +// Output sound format + +static int mixing_freq; +static Uint16 mixing_format; +static int mixing_channels; + +// Currently playing sound +// current_remaining is the number of remaining samples that must be played +// before we invoke the callback to get the next frequency. + +static int current_remaining; +static int current_freq; + +static int phase_offset = 0; + +// Mixer function that does the PC speaker emulation + +static void PCSound_Mix_Callback(void *udata, Uint8 *stream, int len) +{ + Sint16 *leftptr; + Sint16 *rightptr; + Sint16 this_value; + int oldfreq; + int i; + int nsamples; + + // Number of samples is quadrupled, because of 16-bit and stereo + + nsamples = len / 4; + + leftptr = (Sint16 *) stream; + rightptr = ((Sint16 *) stream) + 1; + + // Fill the output buffer + + for (i=0; i