aboutsummaryrefslogtreecommitdiff
path: root/sound/mods/protracker.h
diff options
context:
space:
mode:
authorEugene Sandulenko2006-10-16 22:20:46 +0000
committerEugene Sandulenko2006-10-16 22:20:46 +0000
commit7282e24d3bec5aaa598c6602da18f05783b5abaa (patch)
treeb2177e5fc5434513d7b6aa023086e79d85a65ede /sound/mods/protracker.h
parent0a51fbb326afe2604a457eef907a6901b06b7152 (diff)
downloadscummvm-rg350-7282e24d3bec5aaa598c6602da18f05783b5abaa.tar.gz
scummvm-rg350-7282e24d3bec5aaa598c6602da18f05783b5abaa.tar.bz2
scummvm-rg350-7282e24d3bec5aaa598c6602da18f05783b5abaa.zip
Add WIP (not yet plugged in) Protracker modules player
svn-id: r24351
Diffstat (limited to 'sound/mods/protracker.h')
-rw-r--r--sound/mods/protracker.h155
1 files changed, 155 insertions, 0 deletions
diff --git a/sound/mods/protracker.h b/sound/mods/protracker.h
new file mode 100644
index 0000000000..6f8bc0bf44
--- /dev/null
+++ b/sound/mods/protracker.h
@@ -0,0 +1,155 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2006 The ScummVM project
+ * Based on code by madmoose
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program 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 General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __SOUND_MODS_PROTRACKER_H__
+#define __SOUND_MODS_PROTRACKER_H__
+
+#include "common/stdafx.h"
+#include "common/system.h"
+
+#include "sound/mods/module.h"
+
+namespace Modules {
+
+class SoundBuffer {
+ private:
+ int _capacity;
+ int _size;
+ int16 *_data;
+
+public:
+ SoundBuffer() {
+ _size = 0;
+ _capacity = 8192;
+ _data = (int16 *)malloc(_capacity * sizeof(int16));
+ assert(_data);
+ }
+
+ ~SoundBuffer() {
+ free(_data);
+ }
+
+ int size() {
+ return _size;
+ }
+
+ int16 *getEnd() {
+ return _data + _size;
+ }
+
+ void ensureCapacity(int len) {
+ if (_size + len > _capacity) {
+ do {
+ _capacity *= 2;
+ } while (_size + len > _capacity);
+
+ _data = (int16 *)realloc(_data, _capacity * sizeof(int16));
+ assert(_data);
+ memset(_data + _size, 0, len);
+ }
+ }
+
+ void finish(int len) {
+ _size += len;
+ }
+
+ void pop(int16 *dest, int len) {
+ assert(_size >= len);
+ memcpy(dest, _data, len * sizeof(int16));
+ memmove(_data, _data + len, (_size - len) * sizeof(int16));
+ _size -= len;
+ }
+};
+
+class ProtrackerPlayer {
+ OSystem *_system;
+ Module *_module;
+
+ SoundBuffer *_buf;
+ double _generatedSamplesOverflow;
+
+ int _tick;
+ int _row;
+ int _pos;
+
+ int _patternDelay;
+
+ int _speed;
+ int _bpm;
+
+ // For effect 0xB - Jump To Pattern;
+ bool _hasJumpToPattern;
+ int _jumpToPattern;
+
+ // For effect 0xD - PatternBreak;
+ bool _hasPatternBreak;
+ int _skiprow;
+
+ // For effect 0xE6 - Pattern Loop
+ bool _hasPatternLoop;
+ int _patternLoopCount;
+ int _patternLoopRow;
+
+ struct {
+ byte sample;
+ uint16 period;
+ double offset;
+
+ byte vol;
+
+ // For effect 0x3 - Porta to note
+ uint16 portaToNote;
+ byte portaToNoteSpeed;
+
+ // For effect 0x4 - Vibrato
+ int vibrato;
+ byte vibratoPos;
+ byte vibratoSpeed;
+ byte vibratoDepth;
+ } _track[4];
+
+public:
+ ProtrackerPlayer() : _system(NULL), _module(NULL) { };
+
+ void init(OSystem *system);
+
+ void start();
+ void pause();
+ void stop();
+
+ void loadModule(const char *fn);
+
+ void mix(byte *buf, int len);
+
+private:
+ void generateSound();
+
+ void updateRow();
+ void updateEffects();
+
+ static void audioCallback(void *param, byte *buf, int len);
+};
+
+} // End of namespace Modules
+
+#endif