1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi:tw=80:et:ts=2:sts=2 3 // 4 // ----------------------------------------------------------------------- 5 // 6 // This file is part of RLVM, a RealLive virtual machine clone. 7 // 8 // ----------------------------------------------------------------------- 9 // 10 // Copyright (C) 2009 Elliot Glaysher 11 // 12 // This program is free software; you can redistribute it and/or modify 13 // it under the terms of the GNU General Public License as published by 14 // the Free Software Foundation; either version 3 of the License, or 15 // (at your option) any later version. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of the GNU General Public License 23 // along with this program; if not, write to the Free Software 24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 25 // ----------------------------------------------------------------------- 26 27 #ifndef SRC_SYSTEMS_BASE_VOICE_CACHE_H_ 28 #define SRC_SYSTEMS_BASE_VOICE_CACHE_H_ 29 30 #include <memory> 31 32 #include "lru_cache.hpp" 33 34 class SoundSystem; 35 class VoiceArchive; 36 class VoiceSample; 37 38 class VoiceCache { 39 public: 40 explicit VoiceCache(SoundSystem& sound_system); 41 ~VoiceCache(); 42 43 std::shared_ptr<VoiceSample> Find(int id); 44 45 private: 46 // Searches for a file archive of voices. 47 std::shared_ptr<VoiceArchive> FindArchive(int file_no) const; 48 49 // Searches for an unarchived ogg or mp3 file. 50 std::shared_ptr<VoiceSample> FindUnpackedSample(int file_no, 51 int index) const; 52 53 SoundSystem& sound_system_; 54 55 // A mapping between a file id number and the underlying file object. 56 LRUCache<int, std::shared_ptr<VoiceArchive>> file_cache_; 57 }; // class VoiceCache 58 59 #endif // SRC_SYSTEMS_BASE_VOICE_CACHE_H_ 60