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

lipsync.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM 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 #include "common/endian.h"
00024 #include "common/stream.h"
00025 
00026 #include "engines/grim/grim.h"
00027 #include "engines/grim/lipsync.h"
00028 #include "engines/grim/resource.h"
00029 #include "engines/grim/debug.h"
00030 
00031 namespace Grim {
00032 
00033 template class ObjectPtr<LipSync>;
00034 
00035 
00036 LipSync::LipSync(const Common::String &filename, Common::SeekableReadStream *data) :
00037         Object(), _fname(filename) {
00038 
00039     if (data->readUint32BE() != MKTAG('L','I','P','!')) {
00040         error("Invalid file format in %s", _fname.c_str());
00041     }
00042 
00043     _numEntries = (data->size() - 8) / 4;
00044 
00045     // There are cases where the lipsync file has no entries
00046     if (_numEntries == 0) {
00047         _entries = nullptr;
00048         return;
00049     }
00050 
00051     data->readUint32LE();
00052     Debug::debug(Debug::Lipsync, "Reading LipSync %s, %d entries\n", filename.c_str(), _numEntries);
00053     _entries = new LipEntry[_numEntries];
00054     for (int i = 0; i < _numEntries; i++) {
00055         _entries[i].frame = data->readUint16LE();
00056         uint16 readPhoneme = data->readUint16LE();
00057         int j;
00058 
00059         // Look for the animation corresponding to the phoneme
00060         for (j = 0; j < _animTableSize; j++) {
00061             if (readPhoneme == _animTable[j].phoneme) {
00062                 _entries[i].anim = _animTable[j].anim;
00063                 break;
00064             }
00065         }
00066 
00067         if (j >= _animTableSize) {
00068             Debug::warning(Debug::Lipsync, "Unknown phoneme: 0x%X in file %s", readPhoneme, _fname.c_str());
00069             _entries[i].anim = 1;
00070         }
00071     }
00072 }
00073 
00074 LipSync::~LipSync() {
00075     delete[] _entries;
00076     g_resourceloader->uncacheLipSync(this);
00077 }
00078 
00079 int LipSync::getAnim(int pos) {
00080     int frame1, frame2;
00081 
00082     for (int i = 0; i < _numEntries; i++) {
00083         frame1 = _entries[i].frame;
00084         if ((i + 1) < _numEntries) {
00085             frame2 = _entries[i + 1].frame;
00086         } else {
00087             frame2 = (unsigned int) - 1L;
00088         }
00089         if ((pos >= frame1) && (pos < frame2)) {
00090             return _entries[i].anim;
00091         }
00092     }
00093 
00094     return -1;
00095 }
00096 
00097 // TODO: Figure out which one is 0x0000, use 0 for now.
00098 const LipSync::PhonemeAnim LipSync::_animTable[] = {
00099     {0x005F, 0}, {0x0251, 1}, {0x0061, 1}, {0x00E6, 1}, {0x028C, 8},
00100     {0x0254, 1}, {0x0259, 1}, {0x0062, 6}, {0x02A7, 2}, {0x0064, 2},
00101     {0x00F0, 5}, {0x025B, 8}, {0x0268, 8}, {0x025A, 9}, {0x025D, 9},
00102     {0x0065, 1}, {0x0066, 4}, {0x0067, 8}, {0x0261, 8}, {0x0068, 8},
00103     {0x026A, 8}, {0x0069, 3}, {0x02A4, 2}, {0x006B, 2}, {0x006C, 5},
00104     {0x026B, 5}, {0x006D, 6}, {0x006E, 8}, {0x014B, 8}, {0x006F, 7},
00105     {0x0070, 6}, {0x0072, 2}, {0x027B, 2}, {0x0279, 2}, {0x0073, 2},
00106     {0x0283, 2}, {0x0074, 2}, {0x027E, 2}, {0x03B8, 5}, {0x028A, 9},
00107     {0x0075, 9}, {0x0076, 4}, {0x0077, 9}, {0x006A, 8}, {0x007A, 2},
00108     {0x0292, 2}, {0x002E, 2}, {0x0000, 0}
00109 };
00110 
00111 const int LipSync::_animTableSize = sizeof(LipSync::_animTable) / sizeof(LipSync::_animTable[0]);
00112 
00113 } // end of namespace Grim


Generated on Sat Oct 19 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge