DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/freeverb/allpass.cpp
00001 // Allpass filter implementation
00002 //
00003 // Written by Jezar at Dreampoint, June 2000
00004 // http://www.dreampoint.co.uk
00005 // This code is public domain
00006 
00007 #include "allpass.h"
00008 
00009 allpass::allpass()
00010 {
00011     bufidx = 0;
00012     buffer = NULL;
00013     bufsize = 0;
00014     feedback = 0.0F;
00015 }
00016 
00017 void allpass::setbuffer(float *buf, int size)
00018 {
00019         buffer = buf;
00020         bufsize = size;
00021 }
00022 
00023 void allpass::mute()
00024 {
00025         for (int i=0; i<bufsize; i++)
00026                 buffer[i]=0;
00027 }
00028 
00029 void allpass::setfeedback(float val)
00030 {
00031         feedback = val;
00032 }
00033 
00034 float allpass::getfeedback()
00035 {
00036         return feedback;
00037 }
00038 
00039 void allpass::deletebuffer()
00040 {
00041         delete[] buffer;
00042         buffer = 0;
00043 }
00044 
00045 
00046 void allpass::saveState( std::ostream &stream )
00047 {
00048         stream.write(reinterpret_cast<const char*>(&feedback), sizeof(feedback) );
00049         stream.write(reinterpret_cast<const char*>(buffer), (std::streamsize)((size_t)bufsize * sizeof(float)) );
00050         stream.write(reinterpret_cast<const char*>(&bufsize), sizeof(bufsize) );
00051         stream.write(reinterpret_cast<const char*>(&bufidx), sizeof(bufidx) );
00052 }
00053 
00054 
00055 void allpass::loadState( std::istream &stream )
00056 {
00057         stream.read(reinterpret_cast<char*>(&feedback), sizeof(feedback) );
00058         stream.read(reinterpret_cast<char*>(buffer), (std::streamsize)((size_t)bufsize * sizeof(float)) );
00059         stream.read(reinterpret_cast<char*>(&bufsize), sizeof(bufsize) );
00060         stream.read(reinterpret_cast<char*>(&bufidx), sizeof(bufidx) );
00061 }