player.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "player.h"
  22. #include "opl.h"
  23. /***** CPlayer *****/
  24. const unsigned short CPlayer::note_table[12] =
  25. {363, 385, 408, 432, 458, 485, 514, 544, 577, 611, 647, 686};
  26. const unsigned char CPlayer::op_table[9] =
  27. {0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12};
  28. CPlayer::CPlayer(Copl *newopl)
  29. : opl(newopl) {
  30. }
  31. CPlayer::~CPlayer() {
  32. }
  33. unsigned long CPlayer::songlength(int subsong) {
  34. Copl tempopl;
  35. Copl *saveopl = opl;
  36. float slength = 0.0f;
  37. // save original OPL from being overwritten
  38. opl = &tempopl;
  39. // get song length
  40. rewind(subsong);
  41. while (update() && slength < 600000) // song length limit: 10 minutes
  42. slength += 1000.0f / getrefresh();
  43. rewind(subsong);
  44. // restore original OPL and return
  45. opl = saveopl;
  46. return (unsigned long)slength;
  47. }
  48. void CPlayer::seek(unsigned long ms) {
  49. float pos = 0.0f;
  50. rewind();
  51. while (pos < ms && update()) // seek to new position
  52. pos += 1000/getrefresh();
  53. }