head 1.2; access; symbols pkgsrc-2013Q2:1.2.0.50 pkgsrc-2013Q2-base:1.2 pkgsrc-2012Q4:1.2.0.48 pkgsrc-2012Q4-base:1.2 pkgsrc-2011Q4:1.2.0.46 pkgsrc-2011Q4-base:1.2 pkgsrc-2011Q2:1.2.0.44 pkgsrc-2011Q2-base:1.2 pkgsrc-2009Q4:1.2.0.42 pkgsrc-2009Q4-base:1.2 pkgsrc-2008Q4:1.2.0.40 pkgsrc-2008Q4-base:1.2 pkgsrc-2008Q3:1.2.0.38 pkgsrc-2008Q3-base:1.2 cube-native-xorg:1.2.0.36 cube-native-xorg-base:1.2 pkgsrc-2008Q2:1.2.0.34 pkgsrc-2008Q2-base:1.2 pkgsrc-2008Q1:1.2.0.32 pkgsrc-2008Q1-base:1.2 pkgsrc-2007Q4:1.2.0.30 pkgsrc-2007Q4-base:1.2 pkgsrc-2007Q3:1.2.0.28 pkgsrc-2007Q3-base:1.2 pkgsrc-2007Q2:1.2.0.26 pkgsrc-2007Q2-base:1.2 pkgsrc-2007Q1:1.2.0.24 pkgsrc-2007Q1-base:1.2 pkgsrc-2006Q4:1.2.0.22 pkgsrc-2006Q4-base:1.2 pkgsrc-2006Q3:1.2.0.20 pkgsrc-2006Q3-base:1.2 pkgsrc-2006Q2:1.2.0.18 pkgsrc-2006Q2-base:1.2 pkgsrc-2006Q1:1.2.0.16 pkgsrc-2006Q1-base:1.2 pkgsrc-2005Q4:1.2.0.14 pkgsrc-2005Q4-base:1.2 pkgsrc-2005Q3:1.2.0.12 pkgsrc-2005Q3-base:1.2 pkgsrc-2005Q2:1.2.0.10 pkgsrc-2005Q2-base:1.2 pkgsrc-2005Q1:1.2.0.8 pkgsrc-2005Q1-base:1.2 pkgsrc-2004Q4:1.2.0.6 pkgsrc-2004Q4-base:1.2 pkgsrc-2004Q3:1.2.0.4 pkgsrc-2004Q3-base:1.2 pkgsrc-2004Q2:1.2.0.2 pkgsrc-2004Q2-base:1.2 pkgsrc-base:1.1.1.1 TNF:1.1.1; locks; strict; comment @# @; 1.2 date 2004.05.28.11.09.44; author dillo; state dead; branches; next 1.1; 1.1 date 2004.05.14.15.42.15; author dillo; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2004.05.14.15.42.15; author dillo; state Exp; branches; next ; desc @@ 1.2 log @raw has been discontinued by its author, distfile no longer available @ text @$NetBSD: patch-af,v 1.1 2004/05/14 15:42:15 dillo Exp $ This includes sound-20040508.diff from the master site. --- mixer.cpp.orig Sun May 9 21:04:46 2004 +++ mixer.cpp @@@@ -0,0 +1,117 @@@@ +/* Raw - Another World Interpreter + * Copyright (C) 2004 Gregory Montoir + * + * 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. + */ + +#include "mixer.h" +#include "systemstub.h" + + +static int8 addclamp(int a, int b) { + int add = a + b; + if (add < -128) { + add = -128; + } + else if (add > 127) { + add = 127; + } + return (int8)add; +} + +Mixer::Mixer(SystemStub *stub) + : _stub(stub) { +} + +void Mixer::init() { + memset(_channels, 0, sizeof(_channels)); + _stub->startAudio(Mixer::mixCallback, this); +} + +void Mixer::free() { + _stub->stopAudio(); +} + +void Mixer::playChannel(uint8 channel, const MixerChunk *mc, uint16 freq, uint8 volume) { + debug(DBG_SND, "Mixer::playChannel(%d, %d, %d)", channel, freq, volume); + assert(channel < NUM_CHANNELS); + _stub->lockAudio(); + MixerChannel *ch = &_channels[channel]; + ch->active = true; + ch->volume = volume; + ch->chunk = *mc; + ch->chunkPos = 0; + ch->chunkInc = (freq << 8) / _stub->getOutputSampleRate(); + _stub->unlockAudio(); +} + +void Mixer::stopChannel(uint8 channel) { + debug(DBG_SND, "Mixer::stopChannel(%d)", channel); + assert(channel < NUM_CHANNELS); + _stub->lockAudio(); + _channels[channel].active = false; + _stub->unlockAudio(); +} + +void Mixer::stopAll() { + debug(DBG_SND, "Mixer::stopAll()"); + _stub->lockAudio(); + for (uint8 i = 0; i < NUM_CHANNELS; ++i) { + _channels[i].active = false; + } + _stub->unlockAudio(); +} + +void Mixer::mix(int8 *buf, int len) { + memset(buf, 0, len); + for (uint8 i = 0; i < NUM_CHANNELS; ++i) { + MixerChannel *ch = &_channels[i]; + if (ch->active) { + int8 *pBuf = buf; + for (int j = 0; j < len; ++j, ++pBuf) { + uint16 p1, p2; + uint16 ilc = (ch->chunkPos & 0xFF); + p1 = ch->chunkPos >> 8; + ch->chunkPos += ch->chunkInc; + if (ch->chunk.loopLen != 0) { + if (p1 == ch->chunk.loopPos + ch->chunk.loopLen - 1) { + debug(DBG_SND, "Looping sample on channel %d", i); + ch->chunkPos = p2 = ch->chunk.loopPos; + } else { + p2 = p1 + 1; + } + } else { + if (p1 == ch->chunk.len - 1) { + debug(DBG_SND, "Stopping sample on channel %d", i); + ch->active = false; + break; + } else { + p2 = p1 + 1; + } + } + // interpolate + int8 b1 = *(int8 *)(ch->chunk.data + p1); + int8 b2 = *(int8 *)(ch->chunk.data + p2); + int8 b = (int8)((b1 * (0xFF - ilc) + b2 * ilc) >> 8); + // set volume and clamp + *pBuf = addclamp(*pBuf, (int)b * ch->volume / 0x40); + } + } + } +} + +void Mixer::mixCallback(void *param, uint8 *buf, int len) { + ((Mixer *)param)->mix((int8 *)buf, len); +} @ 1.1 log @Initial revision @ text @d1 1 a1 1 $NetBSD$ @ 1.1.1.1 log @initial import of raw 0.1.0: raw is a rewrite of the engine used in the action/adventure game Another World/Out of this World released for DOS and Amiga. This program is designed as a cross-platform replacement for the original executable and uses the SDL library. You will need the data files from the DOS version of the game to play. @ text @@