]> 4ch.mooo.com Git - 16.git/blob - 16/adplug/adplug-2.2.1/src/player.cpp
Please enter the commit message for your changes. Lines starting
[16.git] / 16 / adplug / adplug-2.2.1 / src / player.cpp
1 /*
2  * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3  * Copyright (C) 1999 - 2007 Simon Peter, <dn.tlp@gmx.net>, et al.
4  * 
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.
9  * 
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.
14  * 
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
18  *
19  * player.cpp - Replayer base class, by Simon Peter <dn.tlp@gmx.net>
20  */
21
22 #include "player.h"
23 #include "adplug.h"
24 #include "silentopl.h"
25
26 /***** CPlayer *****/
27
28 const unsigned short CPlayer::note_table[12] =
29   {363, 385, 408, 432, 458, 485, 514, 544, 577, 611, 647, 686};
30
31 const unsigned char CPlayer::op_table[9] =
32   {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12};
33
34 CPlayer::CPlayer(Copl *newopl)
35   : opl(newopl), db(CAdPlug::database)
36 {
37 }
38
39 CPlayer::~CPlayer()
40 {
41 }
42
43 unsigned long CPlayer::songlength(int subsong)
44 {
45   CSilentopl    tempopl;
46   Copl          *saveopl = opl;
47   float         slength = 0.0f;
48
49   // save original OPL from being overwritten
50   opl = &tempopl;
51
52   // get song length
53   rewind(subsong);
54   while(update() && slength < 600000)   // song length limit: 10 minutes
55     slength += 1000.0f / getrefresh();
56   rewind(subsong);
57
58   // restore original OPL and return
59   opl = saveopl;
60   return (unsigned long)slength;
61 }
62
63 void CPlayer::seek(unsigned long ms)
64 {
65   float pos = 0.0f;
66
67   rewind();
68   while(pos < ms && update())           // seek to new position
69     pos += 1000/getrefresh();
70 }