ScummVM API documentation
u6m.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_SOUND_ADPLUG_U6M
23 #define NUVIE_SOUND_ADPLUG_U6M
24 
25 #include "ultima/nuvie/sound/adplug/adplug_player.h"
26 #include "common/stack.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 class Cu6mPlayer: public CPlayer {
32 public:
33  static CPlayer *factory(Copl *newopl);
34 
35  Cu6mPlayer(Copl *newopl) : CPlayer(newopl), song_data(0), driver_active(false),
36  songend(false), song_pos(0), loop_position(0), read_delay(0), played_ticks(0) {
37  ARRAYCLEAR(channel_freq);
38  }
39 
40  ~Cu6mPlayer() override;
41 
42 
43 
44  bool load(const Common::Path &filename) override;
45  bool update() override;
46  void rewind(int subsong) override;
47  float getrefresh() override;
48 
49  Std::string gettype() override {
50  return Std::string("Ultima 6 Music");
51  };
52 
53 
54 protected:
55 
56  struct byte_pair {
57  unsigned char lo;
58  unsigned char hi;
59  };
60 
61  struct subsong_info { // information about a subsong
62  int continue_pos;
63  int subsong_repetitions;
64  int subsong_start;
65  };
66 
67  struct data_block { //
68  long size;
69  unsigned char *data;
70  };
71 
72 
73  // class variables
74  long played_ticks;
75 
76  unsigned char *song_data; // the uncompressed .m file (the "song")
77  bool driver_active; // flag to prevent reentrancy
78  bool songend; // indicates song end
79  int song_pos; // current offset within the song
80  int loop_position; // position of the loop point
81  int read_delay; // delay (in timer ticks) before further song data is read
82  Common::Stack<subsong_info> subsong_stack;
83 
84  int instrument_offsets[9]; // offsets of the adlib instrument data
85  // vibrato ("vb")
86  unsigned char vb_current_value[9];
87  unsigned char vb_double_amplitude[9];
88  unsigned char vb_multiplier[9];
89  unsigned char vb_direction_flag[9];
90  // mute factor ("mf") = not(volume)
91  unsigned char carrier_mf[9];
92  signed char carrier_mf_signed_delta[9];
93  unsigned char carrier_mf_mod_delay_backup[9];
94  unsigned char carrier_mf_mod_delay[9];
95  // frequency
96  byte_pair channel_freq[9]; // adlib freq settings for each channel
97  signed char channel_freq_signed_delta[9];
98 
99  // protected functions used by update()
100  void command_loop();
101  unsigned char read_song_byte();
102  signed char read_signed_song_byte();
103  void dec_clip(int &);
104  byte_pair expand_freq_byte(unsigned char);
105  void set_adlib_freq(int channel, byte_pair freq_word);
106  void set_adlib_freq_no_update(int channel, byte_pair freq_word);
107  void set_carrier_mf(int channel, unsigned char mute_factor);
108  void set_modulator_mf(int channel, unsigned char mute_factor);
109  void freq_slide(int channel);
110  void vibrato(int channel);
111  void mf_slide(int channel);
112 
113  void command_0(int channel);
114  void command_1(int channel);
115  void command_2(int channel);
116  void command_3(int channel);
117  void command_4(int channel);
118  void command_5(int channel);
119  void command_6(int channel);
120  void command_7(int channel);
121  void command_81();
122  void command_82();
123  void command_83();
124  void command_85();
125  void command_86();
126  void command_E();
127  void command_F();
128 
129  void out_adlib(unsigned char adlib_register, unsigned char adlib_data);
130  void out_adlib_opcell(int channel, bool carrier, unsigned char adlib_register, unsigned char out_byte);
131 
132 };
133 
134 } // End of namespace Nuvie
135 } // End of namespace Ultima
136 
137 #endif
void ARRAYCLEAR(T(&array) [N], const T &value=T())
Definition: util.h:101
Definition: u6m.h:31
Definition: path.h:52
Definition: opl.h:30
Definition: detection.h:27
Definition: string.h:30
Definition: adplug_player.h:35
Definition: stack.h:102