DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/BReverbModel.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_B_REVERB_MODEL_H
00019 #define MT32EMU_B_REVERB_MODEL_H
00020 
00021 namespace MT32Emu {
00022 
00023 struct BReverbSettings {
00024         const Bit32u numberOfAllpasses;
00025         const Bit32u * const allpassSizes;
00026         const Bit32u numberOfCombs;
00027         const Bit32u * const combSizes;
00028         const Bit32u * const outLPositions;
00029         const Bit32u * const outRPositions;
00030         const Bit32u * const filterFactors;
00031         const Bit32u * const feedbackFactors;
00032         const Bit32u * const dryAmps;
00033         const Bit32u * const wetLevels;
00034         const Bit32u lpfAmp;
00035 };
00036 
00037 class RingBuffer {
00038 protected:
00039         Bit16s *buffer;
00040         const Bit32u size;
00041         Bit32u index;
00042 
00043 public:
00044         RingBuffer(const Bit32u size);
00045         virtual ~RingBuffer();
00046         Bit32s next();
00047         bool isEmpty() const;
00048         void mute();
00049 };
00050 
00051 class AllpassFilter : public RingBuffer {
00052 public:
00053         AllpassFilter(const Bit32u size);
00054         Bit32s process(const Bit32s in);
00055 };
00056 
00057 class CombFilter : public RingBuffer {
00058 protected:
00059         const Bit32u filterFactor;
00060         Bit32u feedbackFactor;
00061 
00062 public:
00063         CombFilter(const Bit32u size, const Bit32u useFilterFactor);
00064         virtual void process(const Bit32s in); // Actually, no need to make it virtual, but for sure
00065         Bit32s getOutputAt(const Bit32u outIndex) const;
00066         void setFeedbackFactor(const Bit32u useFeedbackFactor);
00067 };
00068 
00069 class DelayWithLowPassFilter : public CombFilter {
00070         Bit32u amp;
00071 
00072 public:
00073         DelayWithLowPassFilter(const Bit32u useSize, const Bit32u useFilterFactor, const Bit32u useAmp);
00074         void process(const Bit32s in);
00075         void setFeedbackFactor(const Bit32u) {}
00076 };
00077 
00078 class TapDelayCombFilter : public CombFilter {
00079         Bit32u outL;
00080         Bit32u outR;
00081 
00082 public:
00083         TapDelayCombFilter(const Bit32u useSize, const Bit32u useFilterFactor);
00084         void process(const Bit32s in);
00085         Bit32s getLeftOutput() const;
00086         Bit32s getRightOutput() const;
00087         void setOutputPositions(const Bit32u useOutL, const Bit32u useOutR);
00088 };
00089 
00090 class BReverbModel : public ReverbModel {
00091         AllpassFilter **allpasses;
00092         CombFilter **combs;
00093 
00094         const BReverbSettings &currentSettings;
00095         const bool tapDelayMode;
00096         Bit32u dryAmp;
00097         Bit32u wetLevel;
00098         void mute();
00099 
00100 public:
00101         BReverbModel(const ReverbMode mode);
00102         ~BReverbModel();
00103         void open();
00104         void close();
00105         void setParameters(Bit8u time, Bit8u level);
00106         void process(const float *inLeft, const float *inRight, float *outLeft, float *outRight, unsigned long numSamples);
00107         bool isActive() const;
00108 };
00109 
00110 }
00111 
00112 #endif