diff Alc/alcDedicated.c @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Alc/alcDedicated.c	Tue Oct 25 13:02:31 2011 -0700
     1.3 @@ -0,0 +1,138 @@
     1.4 +/**
     1.5 + * OpenAL cross platform audio library
     1.6 + * Copyright (C) 2011 by Chris Robinson.
     1.7 + * This library is free software; you can redistribute it and/or
     1.8 + *  modify it under the terms of the GNU Library General Public
     1.9 + *  License as published by the Free Software Foundation; either
    1.10 + *  version 2 of the License, or (at your option) any later version.
    1.11 + *
    1.12 + * This library is distributed in the hope that it will be useful,
    1.13 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 + *  Library General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU Library General Public
    1.18 + *  License along with this library; if not, write to the
    1.19 + *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 + *  Boston, MA  02111-1307, USA.
    1.21 + * Or go to http://www.gnu.org/copyleft/lgpl.html
    1.22 + */
    1.23 +
    1.24 +#include "config.h"
    1.25 +
    1.26 +#include <stdlib.h>
    1.27 +
    1.28 +#include "alMain.h"
    1.29 +#include "alFilter.h"
    1.30 +#include "alAuxEffectSlot.h"
    1.31 +#include "alError.h"
    1.32 +#include "alu.h"
    1.33 +
    1.34 +
    1.35 +typedef struct ALdedicatedState {
    1.36 +    // Must be first in all effects!
    1.37 +    ALeffectState state;
    1.38 +
    1.39 +    ALfloat gains[MAXCHANNELS];
    1.40 +} ALdedicatedState;
    1.41 +
    1.42 +
    1.43 +static ALvoid DedicatedDestroy(ALeffectState *effect)
    1.44 +{
    1.45 +    ALdedicatedState *state = (ALdedicatedState*)effect;
    1.46 +    free(state);
    1.47 +}
    1.48 +
    1.49 +static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
    1.50 +{
    1.51 +    (void)effect;
    1.52 +    (void)Device;
    1.53 +    return AL_TRUE;
    1.54 +}
    1.55 +
    1.56 +static ALvoid DedicatedDLGUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot)
    1.57 +{
    1.58 +    ALdedicatedState *state = (ALdedicatedState*)effect;
    1.59 +    ALCdevice *device = Context->Device;
    1.60 +    const ALfloat *SpeakerGain;
    1.61 +    ALfloat Gain;
    1.62 +    ALint pos;
    1.63 +    ALsizei s;
    1.64 +
    1.65 +    pos = aluCart2LUTpos(1.0f, 0.0f);
    1.66 +    SpeakerGain = device->PanningLUT[pos];
    1.67 +
    1.68 +    Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain;
    1.69 +    for(s = 0;s < MAXCHANNELS;s++)
    1.70 +        state->gains[s] = SpeakerGain[s] * Gain;
    1.71 +}
    1.72 +
    1.73 +static ALvoid DedicatedLFEUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot)
    1.74 +{
    1.75 +    ALdedicatedState *state = (ALdedicatedState*)effect;
    1.76 +    ALfloat Gain;
    1.77 +    ALsizei s;
    1.78 +    (void)Context;
    1.79 +
    1.80 +    Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain;
    1.81 +    for(s = 0;s < MAXCHANNELS;s++)
    1.82 +        state->gains[s] = 0.0f;
    1.83 +    state->gains[LFE] = Gain;
    1.84 +}
    1.85 +
    1.86 +static ALvoid DedicatedProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS])
    1.87 +{
    1.88 +    ALdedicatedState *state = (ALdedicatedState*)effect;
    1.89 +    const ALfloat *gains = state->gains;
    1.90 +    ALuint i, s;
    1.91 +    (void)Slot;
    1.92 +
    1.93 +    for(i = 0;i < SamplesToDo;i++)
    1.94 +    {
    1.95 +        ALfloat sample;
    1.96 +
    1.97 +        sample = SamplesIn[i];
    1.98 +        for(s = 0;s < MAXCHANNELS;s++)
    1.99 +            SamplesOut[i][s] = sample * gains[s];
   1.100 +    }
   1.101 +}
   1.102 +
   1.103 +ALeffectState *DedicatedDLGCreate(void)
   1.104 +{
   1.105 +    ALdedicatedState *state;
   1.106 +    ALsizei s;
   1.107 +
   1.108 +    state = malloc(sizeof(*state));
   1.109 +    if(!state)
   1.110 +        return NULL;
   1.111 +
   1.112 +    state->state.Destroy = DedicatedDestroy;
   1.113 +    state->state.DeviceUpdate = DedicatedDeviceUpdate;
   1.114 +    state->state.Update = DedicatedDLGUpdate;
   1.115 +    state->state.Process = DedicatedProcess;
   1.116 +
   1.117 +    for(s = 0;s < MAXCHANNELS;s++)
   1.118 +        state->gains[s] = 0.0f;
   1.119 +
   1.120 +    return &state->state;
   1.121 +}
   1.122 +
   1.123 +ALeffectState *DedicatedLFECreate(void)
   1.124 +{
   1.125 +    ALdedicatedState *state;
   1.126 +    ALsizei s;
   1.127 +
   1.128 +    state = malloc(sizeof(*state));
   1.129 +    if(!state)
   1.130 +        return NULL;
   1.131 +
   1.132 +    state->state.Destroy = DedicatedDestroy;
   1.133 +    state->state.DeviceUpdate = DedicatedDeviceUpdate;
   1.134 +    state->state.Update = DedicatedLFEUpdate;
   1.135 +    state->state.Process = DedicatedProcess;
   1.136 +
   1.137 +    for(s = 0;s < MAXCHANNELS;s++)
   1.138 +        state->gains[s] = 0.0f;
   1.139 +
   1.140 +    return &state->state;
   1.141 +}