DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/AReverbModel.h
00001 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
00002  * Copyright (C) 2011, 2012, 2013 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
00003  *
00004  *  This program is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 2.1 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef MT32EMU_A_REVERB_MODEL_H
00019 #define MT32EMU_A_REVERB_MODEL_H
00020 
00021 namespace MT32Emu {
00022 
00023 struct AReverbSettings {
00024         const Bit32u * const allpassSizes;
00025         const Bit32u * const combSizes;
00026         const Bit32u * const outLPositions;
00027         const Bit32u * const outRPositions;
00028         const Bit32u * const filterFactor;
00029         const Bit32u * const decayTimes;
00030         const Bit32u * const wetLevels;
00031         const Bit32u lpfAmp;
00032 };
00033 
00034 class RingBuffer {
00035 protected:
00036         float *buffer;
00037         const Bit32u size;
00038         Bit32u index;
00039 
00040 public:
00041         RingBuffer(const Bit32u size);
00042         virtual ~RingBuffer();
00043         float next();
00044         bool isEmpty() const;
00045         void mute();
00046 };
00047 
00048 class AllpassFilter : public RingBuffer {
00049 public:
00050         AllpassFilter(const Bit32u size);
00051         float process(const float in);
00052 };
00053 
00054 class CombFilter : public RingBuffer {
00055         float feedbackFactor;
00056         float filterFactor;
00057 
00058 public:
00059         CombFilter(const Bit32u size);
00060         void process(const float in);
00061         float getOutputAt(const Bit32u outIndex) const;
00062         void setFeedbackFactor(const float useFeedbackFactor);
00063         void setFilterFactor(const float useFilterFactor);
00064 };
00065 
00066 class AReverbModel : public ReverbModel {
00067         AllpassFilter **allpasses;
00068         CombFilter **combs;
00069 
00070         const AReverbSettings &currentSettings;
00071         float lpfAmp;
00072         float wetLevel;
00073         void mute();
00074 
00075 public:
00076         AReverbModel(const ReverbMode mode);
00077         ~AReverbModel();
00078         void open();
00079         void close();
00080         void setParameters(Bit8u time, Bit8u level);
00081         void process(const float *inLeft, const float *inRight, float *outLeft, float *outRight, unsigned long numSamples);
00082         bool isActive() const;
00083 };
00084 
00085 }
00086 
00087 #endif