ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

sinetables.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Based on eos' sine tables
00024 
00025 #include "common/scummsys.h"
00026 #include "common/sinetables.h"
00027 
00028 namespace Common {
00029 
00030 SineTable::SineTable(int nPoints) {
00031     assert((nPoints >= 16) && (nPoints <= 65536)); // log2 space is in [4,16]
00032     assert(nPoints % 4 == 0);
00033 
00034     _nPoints = nPoints;
00035     _radResolution = 2.0 * M_PI / _nPoints;
00036     _refSize = _nPoints / 4;
00037     _tableEOS = new float[_nPoints / 2];
00038     _table = new float[_nPoints];
00039 
00040     for (int i = 0; i < _nPoints; i++)
00041         _table[i] = sin(i * _radResolution);
00042 
00043     // Table contains sin(2*pi*i/_nPoints) for 0<=i<_nPoints/4,
00044     // followed by _nPoints/2<=i<3_nPoints/4
00045     for (int i = 0; i < _nPoints / 4; i++)
00046         _tableEOS[i] = sin(i * _radResolution);
00047 
00048     for (int i = 0; i < _nPoints / 4; i++)
00049         _tableEOS[_nPoints / 4 + i] = -_tableEOS[i];
00050 }
00051 
00052 float SineTable::at(int index) const {
00053     assert((index >= 0) && (index < _nPoints));
00054     return _table[index];
00055 }
00056 
00057 float SineTable::atLegacy(int index) const { 
00058     assert((index >= 0) && (index < _nPoints));
00059     if (index < _refSize)
00060         // [0,pi/2)
00061         return _tableEOS[index];
00062     if (index == _refSize)
00063         // pi/2
00064         return 1.0f; // sin(pi/2) = 1.0 
00065     if ((index > _refSize) && (index < 2 * _refSize))
00066         // (pi/2,pi)
00067         return _tableEOS[2 * _refSize - index];
00068     if ((index >= 2 * _refSize) && (index < 3 * _refSize))
00069         // [pi,3/2pi)
00070         return -_tableEOS[index - 2 * _refSize];
00071     if ((index > 3 * _refSize) && (index < _nPoints))
00072         // (3/2pi,2pi)
00073         return -_tableEOS[_nPoints - index];
00074     return -1.0f; // sin(3pi/2) = -1.0
00075 }
00076 
00077 SineTable::~SineTable() {
00078     delete[] _tableEOS;
00079     delete[] _table;
00080 }
00081 
00082 } // End of namespace Common


Generated on Sat May 25 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge