summaryrefslogtreecommitdiff
path: root/plugins/adplug/adplug/a2m.h
blob: 9e032f61828b22002d98aa1b16b3dc4fb8a9e681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
 * Copyright (C) 1999 - 2007 Simon Peter, <dn.tlp@gmx.net>, et al.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * a2m.h - A2M Loader by Simon Peter <dn.tlp@gmx.net>
 */

#ifndef H_ADPLUG_A2MLOADER
#define H_ADPLUG_A2MLOADER

#include "protrack.h"

class Ca2mLoader: public CmodPlayer
{
public:
  static CPlayer *factory(Copl *newopl);

  Ca2mLoader(Copl *newopl): CmodPlayer(newopl)
    { }

  bool load(const std::string &filename, const CFileProvider &fp);
  float getrefresh();

  std::string gettype()
    { return std::string("AdLib Tracker 2"); }
  std::string gettitle()
    { if(*songname) return std::string(songname,1,*songname); else return std::string(); }
  std::string getauthor()
    { if(*author) return std::string(author,1,*author); else return std::string(); }
  unsigned int getinstruments()
    { return 250; }
  std::string getinstrument(unsigned int n)
    { return std::string(instname[n],1,*instname[n]); }

private:

#define ADPLUG_A2M_COPYRANGES		6
#define ADPLUG_A2M_FIRSTCODE		257
#define ADPLUG_A2M_MINCOPY		3
#define ADPLUG_A2M_MAXCOPY		255
#define ADPLUG_A2M_CODESPERRANGE	(ADPLUG_A2M_MAXCOPY - ADPLUG_A2M_MINCOPY + 1)
#define ADPLUG_A2M_MAXCHAR		(ADPLUG_A2M_FIRSTCODE + ADPLUG_A2M_COPYRANGES * ADPLUG_A2M_CODESPERRANGE - 1)
#define ADPLUG_A2M_TWICEMAX		(2 * ADPLUG_A2M_MAXCHAR + 1)

  static const unsigned int MAXFREQ, MINCOPY, MAXCOPY, COPYRANGES,
    CODESPERRANGE, TERMINATE, FIRSTCODE, MAXCHAR, SUCCMAX, TWICEMAX, ROOT,
    MAXBUF, MAXDISTANCE, MAXSIZE;

  static const unsigned short bitvalue[14];
  static const signed short copybits[ADPLUG_A2M_COPYRANGES],
    copymin[ADPLUG_A2M_COPYRANGES];

  void inittree();
  void updatefreq(unsigned short a,unsigned short b);
  void updatemodel(unsigned short code);
  unsigned short inputcode(unsigned short bits);
  unsigned short uncompress();
  void decode();
  unsigned short sixdepak(unsigned short *source,unsigned char *dest,unsigned short size);

  char songname[43], author[43], instname[250][33];

  unsigned short ibitcount, ibitbuffer, ibufcount, obufcount, input_size,
    output_size, leftc[ADPLUG_A2M_MAXCHAR+1], rghtc[ADPLUG_A2M_MAXCHAR+1],
    dad[ADPLUG_A2M_TWICEMAX+1], freq[ADPLUG_A2M_TWICEMAX+1], *wdbuf;
  unsigned char *obuf, *buf;
};

#endif