1 /* Created by Eric Fry 2 * Copyright (C) 2011 The Nuvie Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 #ifndef NUVIE_SOUND_ADPLUG_ADPLUG_DECODER_STREAM_H 21 #define NUVIE_SOUND_ADPLUG_ADPLUG_DECODER_STREAM_H 22 23 #include "ultima/shared/std/string.h" 24 #include "ultima/nuvie/sound/adplug/emu_opl.h" 25 #include "ultima/nuvie/sound/adplug/opl.h" 26 #include "ultima/nuvie/sound/adplug/u6m.h" 27 #include "ultima/nuvie/sound/adplug/mid.h" 28 #include "audio/audiostream.h" 29 30 namespace Ultima { 31 namespace Nuvie { 32 33 class U6Lib_n; 34 class U6Lzw; 35 class NuvieIOBuffer; 36 using Std::string; 37 38 class U6AdPlugDecoderStream : public Audio::RewindableAudioStream { 39 public: U6AdPlugDecoderStream()40 U6AdPlugDecoderStream() { 41 opl = NULL; 42 player = NULL; 43 player_refresh_count = 0; 44 } 45 46 U6AdPlugDecoderStream(CEmuopl *o, Std::string filename, uint16 song_num); 47 ~U6AdPlugDecoderStream() override; 48 49 int readBuffer(sint16 *buffer, const int numSamples) override; 50 51 /** Is this a stereo stream? */ isStereo()52 bool isStereo() const override { 53 return true; 54 } 55 56 /** Sample rate of the stream. */ getRate()57 int getRate() const override { 58 return opl->getRate(); 59 } 60 rewind()61 bool rewind() override { 62 if (player) { 63 player->rewind(); //FIXME this would need to be locked if called outside mixer thread. 64 return true; 65 } 66 return false; 67 } 68 69 /** 70 * End of data reached? If this returns true, it means that at this 71 * time there is no data available in the stream. However there may be 72 * more data in the future. 73 * This is used by e.g. a rate converter to decide whether to keep on 74 * converting data or stop. 75 */ endOfData()76 bool endOfData() const override { 77 return false; 78 } 79 private: 80 void update_opl(short *data, int num_samples); 81 protected: 82 83 uint16 samples_left; 84 CEmuopl *opl; 85 CPlayer *player; 86 int player_refresh_count; 87 int interrupt_rate; 88 int interrupt_samples_left; 89 bool is_midi_track; 90 }; 91 92 } // End of namespace Nuvie 93 } // End of namespace Ultima 94 95 #endif 96