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

cosinetables.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' cosine tables
00024 
00025 #include "common/cosinetables.h"
00026 #include "common/scummsys.h"
00027 
00028 namespace Common {
00029 
00030 CosineTable::CosineTable(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] = cos(i * _radResolution);
00042 
00043     // Table contains cos(2*pi*i/_nPoints) for 0<=i<=_nPoints/4,
00044     // followed by 3_nPoints/4<=i<_nPoints
00045     for (int i = 0; i <= _nPoints / 4; i++)
00046         _tableEOS[i] = cos(i * _radResolution);
00047 
00048     for (int i = 1; i < _nPoints / 4; i++)
00049         _tableEOS[_nPoints / 2 - i] = _tableEOS[i]; 
00050 }
00051 
00052 float CosineTable::at(int index) const {
00053     assert((index >= 0) && (index < _nPoints));
00054     return _table[index];
00055 }
00056 
00057 float CosineTable::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) && (index < 2 * _refSize))
00063         // (pi/2,pi)
00064         return -_tableEOS[2 * _refSize - index];
00065     if ((index >= 2 * _refSize) && (index < 3 * _refSize))
00066         // [pi,3/2pi)
00067         return -_tableEOS[index - 2 * _refSize];
00068     if ((index > 3 * _refSize) && (index < _nPoints))
00069         // (3/2pi,2pi)
00070         return _tableEOS[_nPoints - index];
00071     return 0.0f; // cos(pi/2) and cos(3pi/2) = 0
00072 }
00073 
00074 CosineTable::~CosineTable() {
00075     delete[] _tableEOS;
00076     delete[] _table;
00077 }
00078 
00079 } // End of namespace Common


Generated on Sat Feb 23 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge