2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2006 Simon Peter, <dn.tlp@gmx.net>, et al.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * u6m.h - Ultima 6 Music Player by Marc Winterrowd.
20 * This code extends the Adlib Winamp plug-in by Simon Peter <dn.tlp@gmx.net>
27 #define default_dict_size 4096 // because maximum codeword size == 12 bits
28 #define max_codeword_length 12 // maximum codeword length in bits
30 class Cu6mPlayer: public CPlayer
33 static CPlayer *factory(Copl *newopl);
35 Cu6mPlayer(Copl *newopl) : CPlayer(newopl), song_data(0)
42 if(song_data) delete[] song_data;
45 bool load(const std::string &filename, const CFileProvider &fp);
47 void rewind(int subsong);
52 return std::string("Ultima 6 Music");
63 struct subsong_info // information about a subsong
66 int subsong_repetitions;
70 struct dict_entry // dictionary entry
85 // The actual number of dictionary entries allocated
86 // is (dictionary_size-256), because there are 256 roots
87 // that do not need to be stored.
88 int contains; // number of entries currently in the dictionary
89 int dict_size; // max number of entries that will fit into the dictionary
90 dict_entry* dictionary;
93 MyDict(); // use dictionary size of 4096
94 MyDict(int); // let the caller specify a dictionary size
96 void reset(); // re-initializes the dictionary
97 void add(unsigned char, int);
98 unsigned char get_root(int);
99 int get_codeword(int);
106 unsigned char* song_data; // the uncompressed .m file (the "song")
107 bool driver_active; // flag to prevent reentrancy
108 bool songend; // indicates song end
109 int song_pos; // current offset within the song
110 int loop_position; // position of the loop point
111 int read_delay; // delay (in timer ticks) before further song data is read
112 std::stack<subsong_info> subsong_stack;
114 int instrument_offsets[9]; // offsets of the adlib instrument data
116 unsigned char vb_current_value[9];
117 unsigned char vb_double_amplitude[9];
118 unsigned char vb_multiplier[9];
119 unsigned char vb_direction_flag[9];
120 // mute factor ("mf") = not(volume)
121 unsigned char carrier_mf[9];
122 signed char carrier_mf_signed_delta[9];
123 unsigned char carrier_mf_mod_delay_backup[9];
124 unsigned char carrier_mf_mod_delay[9];
126 byte_pair channel_freq[9]; // adlib freq settings for each channel
127 signed char channel_freq_signed_delta[9];
129 // protected functions used by update()
131 unsigned char read_song_byte();
132 signed char read_signed_song_byte();
134 byte_pair expand_freq_byte(unsigned char);
135 void set_adlib_freq(int channel,byte_pair freq_word);
136 void set_adlib_freq_no_update(int channel,byte_pair freq_word);
137 void set_carrier_mf(int channel,unsigned char mute_factor);
138 void set_modulator_mf(int channel,unsigned char mute_factor);
139 void freq_slide(int channel);
140 void vibrato(int channel);
141 void mf_slide(int channel);
143 void command_0(int channel);
144 void command_1(int channel);
145 void command_2(int channel);
146 void command_3(int channel);
147 void command_4(int channel);
148 void command_5(int channel);
149 void command_6(int channel);
150 void command_7(int channel);
159 void out_adlib(unsigned char adlib_register, unsigned char adlib_data);
160 void out_adlib_opcell(int channel, bool carrier, unsigned char adlib_register, unsigned char out_byte);
162 // protected functions used by load()
163 bool lzw_decompress(data_block source, data_block dest);
164 int get_next_codeword (long& bits_read, unsigned char *source, int codeword_size);
165 void output_root(unsigned char root, unsigned char *destination, long& position);
166 void get_string(int codeword, MyDict& dictionary, std::stack<unsigned char>& root_stack);