aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-05-26 14:09:07 +0000
committerMax Horn2009-05-26 14:09:07 +0000
commit7050c5065f875ef3a41312671ad4020444d7db87 (patch)
tree53bb1cbf838a2fd2ed296a18766d60fc934333c8
parent1d00cc5df09dd5fcacd3ea007b45ab33e6332e77 (diff)
downloadscummvm-rg350-7050c5065f875ef3a41312671ad4020444d7db87.tar.gz
scummvm-rg350-7050c5065f875ef3a41312671ad4020444d7db87.tar.bz2
scummvm-rg350-7050c5065f875ef3a41312671ad4020444d7db87.zip
SCI: removed realtime and polled player, as well as the sfx/device dir, after discussion with Walter
svn-id: r40913
-rw-r--r--engines/sci/module.mk3
-rw-r--r--engines/sci/sfx/core.cpp2
-rw-r--r--engines/sci/sfx/device/alsa-midi.cpp213
-rw-r--r--engines/sci/sfx/device/camd-midi.cpp150
-rw-r--r--engines/sci/sfx/device/devices.cpp78
-rw-r--r--engines/sci/sfx/device/unixraw-midi.cpp90
-rw-r--r--engines/sci/sfx/player/polled.cpp393
-rw-r--r--engines/sci/sfx/player/polled.h49
-rw-r--r--engines/sci/sfx/player/realtime.cpp256
-rw-r--r--engines/sci/sfx/player/realtime.h50
-rw-r--r--engines/sci/sfx/sequencer.h1
11 files changed, 0 insertions, 1285 deletions
diff --git a/engines/sci/module.mk b/engines/sci/module.mk
index 239637b975..1f04c0ebc3 100644
--- a/engines/sci/module.mk
+++ b/engines/sci/module.mk
@@ -62,10 +62,7 @@ MODULE_OBJS = \
sfx/core.o \
sfx/iterator.o \
sfx/songlib.o \
- sfx/device/devices.o \
sfx/player/new_player.o \
- sfx/player/polled.o \
- sfx/player/realtime.o \
sfx/seq/gm.o \
sfx/seq/instrument-map.o \
sfx/seq/map-mt32-to-gm.o \
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
index cbf32049a2..f542d86ae4 100644
--- a/engines/sci/sfx/core.cpp
+++ b/engines/sci/sfx/core.cpp
@@ -28,8 +28,6 @@
#include "sci/tools.h"
#include "sci/sfx/core.h"
#include "sci/sfx/player/new_player.h"
-#include "sci/sfx/player/polled.h"
-#include "sci/sfx/player/realtime.h"
#include "sci/sfx/sci_midi.h"
#include "common/system.h"
diff --git a/engines/sci/sfx/device/alsa-midi.cpp b/engines/sci/sfx/device/alsa-midi.cpp
deleted file mode 100644
index 0041e4a3c8..0000000000
--- a/engines/sci/sfx/device/alsa-midi.cpp
+++ /dev/null
@@ -1,213 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-#include <sfx_engine.h>
-#include "../device.h"
-#ifdef HAVE_ALSA
-
-#include <alsa/asoundlib.h>
-
-namespace Sci {
-
-#define SCI_ALSA_MIDI_VERSION "0.1"
-
-static snd_midi_event_t *parser = NULL;
-static snd_seq_t *seq = NULL;
-static int queue = -1;
-static int delta = 0;
-static int port_out = -1;
-static int port_nr = 128;
-static int subport_nr = 0;
-
-static const char *seq_name = "default";
-
-static void _set_tempo(void) {
- int resolution = 60;
- int tempo = 1;
- snd_seq_queue_tempo_t *queue_tempo;
-
- snd_seq_queue_tempo_malloc(&queue_tempo);
-
- memset(queue_tempo, 0, snd_seq_queue_tempo_sizeof());
- snd_seq_queue_tempo_set_ppq(queue_tempo, resolution);
- snd_seq_queue_tempo_set_tempo(queue_tempo, 1000000 / tempo);
-
- snd_seq_set_queue_tempo(seq, queue, queue_tempo);
-
- snd_seq_queue_tempo_free(queue_tempo);
-
-#if 0
- int tempo = 1000000 / 60;
- snd_seq_queue_tempo_t *queue_tempo;
-
- snd_seq_queue_tempo_malloc(&queue_tempo);
- snd_seq_queue_tempo_set_tempo(queue_tempo, tempo);
- snd_seq_queue_tempo_set_ppq(queue_tempo, 1);
- snd_seq_set_queue_tempo(seq, queue, queue_tempo);
- snd_seq_queue_tempo_free(queue_tempo);
-#endif
-}
-
-
-static Common::Error am_subscribe_to_ports(void) {
- if ((port_out = snd_seq_connect_to(seq, port_out, port_nr, subport_nr)) < 0) {
- fprintf(stderr, "[SFX] Could not connect to ALSA sequencer port: %s\n", snd_strerror(port_out));
- return Common::kUnknownError;
- }
- return Common::kNoError;
-}
-
-
-static Common::Error aminit(midi_writer_t *self) {
- int err;
-
- snd_midi_event_new(4096, &parser);
- snd_midi_event_init(parser);
-
- sciprintf("[SFX] Initialising ALSA MIDI backend, v%s\n", SCI_ALSA_MIDI_VERSION);
-
- if (snd_seq_open(&seq, seq_name, SND_SEQ_OPEN_OUTPUT, SND_SEQ_NONBLOCK)) {
- fprintf(stderr, "[SFX] Failed to open ALSA MIDI sequencer '%s' for output\n",
- seq_name);
- return Common::kUnknownError;
- }
-
- if ((port_out = snd_seq_create_simple_port(seq, "FreeSCI",
- SND_SEQ_PORT_CAP_WRITE |
- SND_SEQ_PORT_CAP_SUBS_WRITE |
- SND_SEQ_PORT_CAP_READ,
- SND_SEQ_PORT_TYPE_MIDI_GENERIC)) < 0) {
- fprintf(stderr, "[SFX] Could not create ALSA sequencer port\n");
- return Common::kUnknownError;
- }
-
- if (am_subscribe_to_ports())
- return Common::kUnknownError;
-
- queue = snd_seq_alloc_queue(seq);
- _set_tempo();
-
- snd_seq_start_queue(seq, queue, NULL);
-
- if ((err = snd_seq_drain_output(seq))) {
- fflush(NULL);
- fprintf(stderr, "[SFX] Error while draining: %s\n",
- snd_strerror(err));
- return Common::kUnknownError;
- }
-
- return Common::kNoError;
-}
-
-static Common::Error amsetopt(midi_writer_t *self, char *name, char *value) {
- return Common::kUnknownError;
-}
-
-
-static Common::Error amwrite(midi_writer_t *self, unsigned char *buf, int len) {
- snd_seq_event_t evt;
-
-#if 0
- {
- int i;
- fprintf(stderr, "[MID] ");
- for (i = 0; i < len; i++)
- fprintf(stderr, " %02x", buf[i]);
- fprintf(stderr, "\n");
- }
-#endif
-
- snd_seq_ev_clear(&evt);
- snd_seq_ev_set_source(&evt, port_out);
- snd_seq_ev_set_subs(&evt); /* Broadcast to all subscribers */
-
- snd_midi_event_encode(parser, buf, len, &evt);
- snd_seq_ev_schedule_tick(&evt, queue, 0, delta);
-
- snd_seq_event_output_direct(seq, &evt);
-
-#if 0
- {
- snd_seq_queue_status_t *status;
- snd_seq_queue_status_malloc(&status);
-
- snd_seq_get_queue_status(seq, queue, status);
- //snd_seq_tick_time_t snd_seq_queue_status_get_tick_time(const snd_seq_queue_status_t *info);
- fprintf(stderr, "Queue at %d/%d\n", delta, snd_seq_queue_status_get_tick_time(status));
-
- snd_seq_queue_status_free(status);
- }
-#endif
-
-
- return Common::kNoError;
-}
-
-static void amdelay(midi_writer_t *self, int ticks) {
- delta += ticks;
-}
-
-static void amreset_timer(midi_writer_t *self) {
- snd_seq_drain_output(seq);
- snd_seq_stop_queue(seq, queue, NULL);
-
-
- {
- snd_seq_event_t evt;
- snd_seq_ev_clear(&evt);
- snd_seq_ev_set_source(&evt, port_out);
- snd_seq_ev_set_subs(&evt); /* Broadcast to all subscribers */
-
- snd_seq_ev_set_queue_pos_tick(&evt, queue, 0);
-
- snd_seq_event_output_direct(seq, &evt);
- }
- delta = 0;
-
-
-
- snd_seq_start_queue(seq, queue, NULL);
-}
-
-static void amclose(midi_writer_t *self) {
- snd_midi_event_free(parser);
- parser = NULL;
-}
-
-
-midi_writer_t sfx_device_midi_alsa = {
- "alsa",
- aminit,
- amsetopt,
- amwrite,
- amdelay,
- NULL,
- amreset_timer,
- amclose,
-};
-
-} // End of namespace Sci
-
-#endif
diff --git a/engines/sci/sfx/device/camd-midi.cpp b/engines/sci/sfx/device/camd-midi.cpp
deleted file mode 100644
index 26e3db6520..0000000000
--- a/engines/sci/sfx/device/camd-midi.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#ifdef HAVE_PROTO_CAMD_H
-
-#include "sfx_engine.h"
-#include "../device.h"
-
-#include <proto/camd.h>
-#include <proto/dos.h>
-#include <proto/exec.h>
-#include <proto/intuition.h>
-#include <stdio.h>
-
-namespace Sci {
-
-#define SWAP_BYTES
-#define FILL_BYTES
-
-#define SCI_CAMD_MIDI_VERSION "0.1"
-#define SYSEX_PREFIX 0xf0
-
-static const char *devicename = "via686.out.0";
-
-struct Library *CamdBase = NULL;
-struct CamdIFace *ICamd = NULL;
-static struct MidiLink *midi_link = NULL;
-static struct MidiNode *midi_node = NULL;
-
-#define ABORT(m) { \
- if (CamdBase) \
- IExec->CloseLibrary(CamdBase); \
- sciprintf("[SFX] CAMD driver: "); \
- sciprintf(m); \
- sciprintf("\n"); \
- return Common::kUnknownError; \
- }
-
-static Common::Error camd_init(midi_writer_t *self) {
- sciprintf("[SFX] Initialising CAMD raw MIDI backend, v%s\n", SCI_CAMD_MIDI_VERSION);
-
- CamdBase = IExec->OpenLibrary("camd.library", 36L);
- if (!CamdBase)
- ABORT("Could not open 'camd.library'");
-
- ICamd = (struct CamdIFace *) IExec->GetInterface(CamdBase, "main", 1, NULL);
- if (!ICamd)
- ABORT("Error while retrieving CAMD interface\n");
-
- midi_node = ICamd->CreateMidi(MIDI_MsgQueue, 0L, MIDI_SysExSize, 4096L, MIDI_Name, "freesci", TAG_END);
- if (!midi_node)
- ABORT("Could not create CAMD MIDI node");
-
- midi_link = ICamd->AddMidiLink(midi_node, MLTYPE_Sender, MLINK_Location, devicename, TAG_END);
- if (!midi_link)
- ABORT(("Could not create CAMD MIDI link to '%s'", devicename));
-
- sciprintf("[SFX] CAMD initialisation completed\n");
-
- return Common::kNoError;
-}
-
-static Common::Error camd_set_option(midi_writer_t *self, char *name, char *value) {
- return Common::kUnknownError;
-}
-
-#define MAX_MIDI_LEN 3
-
-static Common::Error camd_write(midi_writer_t *self, unsigned char *buffer, int len) {
- if (len == 0)
- return Common::kNoError;
-
- if (buffer[0] == SYSEX_PREFIX) {
- /* Must send this as a SysEx */
- ICamd->PutSysEx(midi_link, buffer);
- } else {
- ULONG data = 0l;
- int i;
- int readlen = (len > MAX_MIDI_LEN) ? MAX_MIDI_LEN : len;
-
- for (i = 0; i < readlen; i++)
- if (len >= i) {
- data <<= 8;
- data |= buffer[i];
- }
- data <<= (8 * (sizeof(ULONG) - readlen));
-
- if (len > MAX_MIDI_LEN)
- sciprintf("[SFX] Warning: Truncated MIDI message to fit CAMD format (sent %d: %02x %02x %02x, real length %d)\n",
- MAX_MIDI_LEN, buffer[0], buffer[1], buffer[2], len);
-
- ICamd->PutMidi(midi_link, data);
- }
-
- return Common::kNoError;
-}
-
-static void camd_delay(midi_writer_t *self, int ticks) {
-}
-
-static void camd_reset_timer(midi_writer_t *self) {
-}
-
-static void camd_close(midi_writer_t *self) {
-#ifdef NO_OP
- return;
-#endif
- if (CamdBase)
- IExec->CloseLibrary(CamdBase);
-}
-
-midi_writer_t sfx_device_midi_camd = {
- "camd-midi",
- &camd_init,
- &camd_set_option,
- &camd_write,
- &camd_delay,
- NULL,
- &camd_reset_timer,
- &camd_close
-};
-
-} // End of namespace Sci
-
-#endif /* HAVE_PROTO_CAMD_H */
diff --git a/engines/sci/sfx/device/devices.cpp b/engines/sci/sfx/device/devices.cpp
deleted file mode 100644
index c4a9f4808f..0000000000
--- a/engines/sci/sfx/device/devices.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-#include "common/scummsys.h"
-#include "sci/sfx/device.h"
-
-#include "sci/tools.h"
-
-namespace Sci {
-
-static struct _midi_device *devices_midi[] = {
- NULL
-};
-
-static struct _midi_device *devices_opl2[] = {
- NULL
-};
-
-
-/** -- **/
-
-struct _midi_device **devices[] = {
- NULL, /* No device */
- devices_midi,
- devices_opl2,
-};
-
-void *sfx_find_device(int type, char *name) {
- struct _midi_device *dev = NULL;
- int i = 0;
-
- if (!type)
- return NULL;
-
- if (!name) {
- dev = devices[type][0];
- } else {
- while (devices[type][i] && !strcmp(name, devices[type][i]->name))
- ++i;
-
- dev = devices[type][i];
- }
-
- if (dev) {
- if (dev->init(dev)) {
- fprintf(stderr, "[SFX] Opening device '%s' failed\n", dev->name);
- return NULL;
- }
-
- return dev;
- };
-
- return NULL;
-}
-
-} // End of namespace Sci
diff --git a/engines/sci/sfx/device/unixraw-midi.cpp b/engines/sci/sfx/device/unixraw-midi.cpp
deleted file mode 100644
index bc9e8b7427..0000000000
--- a/engines/sci/sfx/device/unixraw-midi.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-#include <sfx_engine.h>
-#include "../device.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-namespace Sci {
-
-#define SCI_UNIXRAW_MIDI_VERSION "0.1"
-
-#ifndef O_SYNC
-# define O_SYNC 0
-#endif
-
-static int fd;
-static const char *devicename = "/dev/midi";
-
-static Common::Error unixraw_init(midi_writer_t *self) {
- sciprintf("[SFX] Initialising UNIX raw MIDI backend, v%s\n", SCI_UNIXRAW_MIDI_VERSION);
-
- fd = open(devicename, O_WRONLY | O_SYNC);
-
- if (!IS_VALID_FD(fd)) {
- sciprintf("[SFX] Failed to open %s\n", devicename);
- return Common::kUnknownError;
- }
-
- return Common::kNoError;
-}
-
-static Common::Error unixraw_set_option(midi_writer_t *self, char *name, char *value) {
- return Common::kUnknownError;
-}
-
-static Common::Error unixraw_write(midi_writer_t *self, unsigned char *buffer, int len) {
- if (write(fd, buffer, len) != len) {
- sciprintf("[SFX] MIDI write error\n");
- return Common::kUnknownError;
- }
- return Common::kNoError;
-}
-
-static void unixraw_delay(midi_writer_t *self, int ticks) {
-}
-
-static void unixraw_reset_timer(midi_writer_t *self) {
-}
-
-static void unixraw_close(midi_writer_t *self) {
- close(fd);
-}
-
-midi_writer_t sfx_device_midi_unixraw = {
- "unixraw-midi",
- &unixraw_init,
- &unixraw_set_option,
- &unixraw_write,
- &unixraw_delay,
- NULL,
- &unixraw_reset_timer,
- &unixraw_close
-};
-
-} // End of namespace Sci
diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp
deleted file mode 100644
index 5ec4e3e5e2..0000000000
--- a/engines/sci/sfx/player/polled.cpp
+++ /dev/null
@@ -1,393 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-/* Polled player, mostly for PCM-based thingies (which _can_ poll, after all) */
-
-#include "common/util.h"
-#include "common/file.h"
-#include "sci/sfx/player/polled.h"
-#include "sci/sfx/softseq.h"
-#include "sci/sfx/iterator.h"
-
-#include "sound/audiostream.h"
-#include "sound/mixer.h"
-
-namespace Sci {
-
-// TODO: Turn the following static vars into member vars
-static SongIterator *play_it;
-static int play_paused = 0;
-static sfx_softseq_t *seq;
-static int volume = 100;
-static Audio::Timestamp new_timestamp;
-static int new_song = 0;
-
-/* The time counter is used to determine how close to the end of a tick we are.
-** For each frame played, it is decreased by 60. */
-#define TIME_INC 60
-static int time_counter = 0;
-
-void PolledPlayer::tell_synth(int buf_nr, byte *buf) {
- seq->handle_command(seq, buf[0], buf_nr - 1, buf + 1);
-}
-
-
-class PolledPlayerAudioStream : public Audio::AudioStream {
-protected:
- enum FeedMode {
- FEED_MODE_ALIVE,
- FEED_MODE_IDLE,
- FEED_MODE_RESTART
- };
-
- /* Whether feed is alive or dead. */
- FeedMode _mode;
-
- /* Blank gap in frames. */
- int _gap;
-
- /* Audio format. */
- sfx_pcm_config_t _conf;
-
- /* Timestamp of next frame requested by stream driver. */
- Audio::Timestamp _time;
-
-public:
- PolledPlayerAudioStream(sfx_pcm_config_t conf)
- : _conf(conf),
- _time(g_system->getMillis(), conf.rate) {
-
- _mode = FEED_MODE_ALIVE;
- _gap = 0;
- }
-
- ~PolledPlayerAudioStream() {
- }
-
- virtual int readBuffer(int16 *buffer, const int numSamples);
-
- virtual bool isStereo() const { return _conf.stereo; }
- virtual int getRate() const { return _conf.rate; }
-
- virtual bool endOfData() const { return false; }
-
-protected:
- void queryTimestamp();
-};
-
-
-void PolledPlayerAudioStream::queryTimestamp() {
- Audio::Timestamp stamp;
-
- if (!new_song) {
- _mode = FEED_MODE_IDLE;
- } else {
- // Otherwise, we have a timestamp:
- stamp = new_timestamp;
- new_song = 0;
-
- _gap = stamp.frameDiff(_time);
- if (_gap >= 0)
- _mode = FEED_MODE_ALIVE;
- else {
- // FIXME: I don't quite understand what FEED_MODE_RESTART is for.
- // The original DC mixer seemed to just stop and restart the stream.
- // But why? To catch up with lagging sound?
- //
- // Walter says the following:
- // "The FEED_MODE_RESTART might be there to re-sync after a debugger
- // session where time passes for the mixer but not for the engine.
- // I may have added this as a workaround for not being able to come
- // up with a convenient way to implement mixer->pause() and mixer->resume()
- // on DC."
- // That makes some sense. However, maybe it is sufficient to just
- // go to FEED_MODE_ALIVE ? With the current code, the player will
- // permanently get stuck in FEED_MODE_RESTART if we ever get here...
- _mode = FEED_MODE_RESTART;
- _time = Audio::Timestamp(g_system->getMillis(), _conf.rate);
- _gap = stamp.frameDiff(_time);
-
- if (_gap < 0)
- _gap = 0;
- }
- }
-}
-
-static void U8_to_S16(byte *buf, int samples) {
- for (int i = samples - 1; i >= 0; i--) {
- buf[i * 2 + 1] = buf[i] - 0x80;
- buf[i * 2] = 0;
- }
-}
-
-static int ppf_poll(int frame_size, byte *dest, int size);
-
-int PolledPlayerAudioStream::readBuffer(int16 *buffer, const int numSamples) {
- // FIXME: If ScummVM's mixer supported timestamps, then it would pass them
- // as a parameter to this function. But currently, it doesn't. Therefore, we
- // create a fake timestamp based on the current time. For comparison, a real
- // timestamp could be adjusted for pauses in sound processing. And it would
- // be synced for all audio streams.
- Audio::Timestamp timestamp(g_system->getMillis(), _conf.rate);
- _time = timestamp;
-
- const int channels = _conf.stereo == SFX_PCM_MONO ? 1 : 2;
- const int frames_req = numSamples / channels;
- int frames_recv = 0;
-
- while (frames_req != frames_recv) {
- int frames = 0;
- int frames_left = frames_req - frames_recv;
- byte *buf_pos = ((byte *)buffer) + frames_recv * channels * 2;
-
- if (_mode == FEED_MODE_IDLE)
- queryTimestamp();
-
- if (_mode == FEED_MODE_IDLE) {
- frames = frames_left;
- memset(buf_pos, 0, frames * channels * 2);
-
- } else if (_gap) {
- frames = MIN(_gap, frames_left);
- _gap -= frames;
- memset(buf_pos, 0, frames * channels * 2);
-
- } else {
- frames = ppf_poll(channels * ((_conf.format & SFX_PCM_FORMAT_16) ? 2 : 1), buf_pos, frames_left);
-
- if (_conf.format == SFX_PCM_FORMAT_U8)
- U8_to_S16(buf_pos, frames * channels);
-
- if (frames < frames_left)
- _mode = FEED_MODE_IDLE;
- }
-
- frames_recv += frames;
- _time = _time.addFrames(frames);
- }
-
- return numSamples;
-}
-
-/*----------------------*/
-/* Mixer implementation */
-/*----------------------*/
-static int ppf_poll(int frame_size, byte *dest, int size) {
- int written = 0;
- byte buf[4];
- int buf_nr;
-
- if (!play_it)
- return 0;
-
- if (play_paused)
- return 0;
-
- while (written < size) {
- int can_play;
- int do_play;
-
- while (time_counter <= TIME_INC) {
- int next_stat = songit_next(&play_it,
- &(buf[0]), &buf_nr,
- IT_READER_MASK_ALL
- | IT_READER_MAY_FREE
- | IT_READER_MAY_CLEAN);
-
- switch (next_stat) {
- case SI_PCM:
- sfx_play_iterator_pcm(play_it, 0);
- break;
-
- case SI_FINISHED:
- delete play_it;
- play_it = NULL;
- return written; /* We're done... */
-
- case SI_IGNORE:
- case SI_LOOP:
- case SI_RELATIVE_CUE:
- case SI_ABSOLUTE_CUE:
- break; /* Boooring... .*/
-
- case 0: /* MIDI command */
-
- seq->handle_command(seq, buf[0], buf_nr - 1, buf + 1);
- break;
-
- default:
- time_counter += next_stat * seq->pcm_conf.rate;
- }
- }
-
- can_play = time_counter / TIME_INC;
- do_play = (can_play > (size - written)) ? (size - written) : can_play;
-
- time_counter -= do_play * TIME_INC;
-
- seq->poll(seq, dest + written * frame_size, do_play);
- written += do_play;
- }
-
- return size; /* Apparently, we wrote all that was requested */
-}
-
-/*=======================*/
-/* Player implementation */
-/*=======================*/
-
-
-/*--------------------*/
-/* API implementation */
-/*--------------------*/
-
-Common::Error PolledPlayer::init(ResourceManager *resmgr, int expected_latency) {
- if (!g_system->getMixer()->isReady())
- return Common::kUnknownError;
-
- Resource *res = NULL, *res2 = NULL;
-
- /* FIXME Temporary hack to detect Amiga games. */
- if (!Common::File::exists("bank.001"))
- seq = sfx_find_softseq(NULL);
- else
- seq = sfx_find_softseq("amiga");
-
- if (!seq) {
- sciprintf("[sfx:seq:polled] Initialisation failed: Could not find software sequencer\n");
- return Common::kUnknownError;
- }
-
- if (seq->patch_nr != SFX_SEQ_PATCHFILE_NONE) {
- res = resmgr->findResource(kResourceTypePatch, seq->patch_nr, 0);
- }
-
- if (seq->patch2_nr != SFX_SEQ_PATCHFILE_NONE) {
- res2 = resmgr->findResource(kResourceTypePatch, seq->patch2_nr, 0);
- }
-
- if (seq->init(seq,
- (res) ? res->data : NULL,
- (res) ? res->size : 0,
- (res2) ? res2->data : NULL,
- (res2) ? res2->size : 0)) {
- sciprintf("[sfx:seq:polled] Initialisation failed: Sequencer '%s', v%s failed to initialise\n",
- seq->name, seq->version);
- return Common::kUnknownError;
- }
-
- seq->set_volume(seq, volume);
-
- // FIXME: Keep a SoundHandle and use that to stop the feed in the exit method
- PolledPlayerAudioStream *newStream = new PolledPlayerAudioStream(seq->pcm_conf);
- // FIXME: Is this sound type appropriate?
- g_system->getMixer()->playInputStream(Audio::Mixer::kSFXSoundType, 0, newStream);
-
- this->polyphony = seq->polyphony;
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::add_iterator(SongIterator *it, uint32 start_time) {
- SongIterator *old = play_it;
-
- SIMSG_SEND(it, SIMSG_SET_PLAYMASK(seq->playmask));
- SIMSG_SEND(it, SIMSG_SET_RHYTHM(seq->play_rhythm));
-
- if (play_it == NULL)
- seq->allstop(seq);
-
- play_it = sfx_iterator_combine(play_it, it);
-
- seq->set_volume(seq, volume);
-
- /* The check must happen HERE, and not at the beginning of the
- function, to avoid a race condition with the mixer. */
- if (old == NULL) {
- new_timestamp = Audio::Timestamp(start_time, seq->pcm_conf.rate);
- /* ASAP otherwise */
- time_counter = 0;
- new_song = 1;
- }
-
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::stop() {
- SongIterator *it = play_it;
-
- play_it = NULL;
- warning("[play] Now stopping it %p", (void *)it);
- delete it;
-
- seq->allstop(seq);
-
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::iterator_message(const SongIterator::Message &msg) {
- if (!play_it)
- return Common::kUnknownError;
-
- songit_handle_message(&play_it, msg);
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::pause() {
- play_paused = 1;
- seq->set_volume(seq, 0);
-
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::resume() {
- if (!play_it) {
- play_paused = 0;
- return Common::kNoError; /* Nothing to resume */
- }
-
- if (play_paused)
- new_song = 1; /* Fake starting a new song, re-using the old
- ** time stamp (now long in the past) to indicate
- ** resuming ASAP */
-
- play_paused = 0;
- seq->set_volume(seq, volume);
- return Common::kNoError;
-}
-
-Common::Error PolledPlayer::exit() {
- seq->exit(seq);
- delete play_it;
- play_it = NULL;
-
- return Common::kNoError;
-}
-
-PolledPlayer::PolledPlayer() {
- name = "polled";
- version = "0.1";
-}
-
-} // End of namespace Sci
diff --git a/engines/sci/sfx/player/polled.h b/engines/sci/sfx/player/polled.h
deleted file mode 100644
index f3485aae8e..0000000000
--- a/engines/sci/sfx/player/polled.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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 SCI_SFX_SFX_PLAYER_POLLED_H
-#define SCI_SFX_SFX_PLAYER_POLLED_H
-
-#include "sci/sfx/player.h"
-
-namespace Sci {
-
-class PolledPlayer : public SfxPlayer {
-public:
- PolledPlayer();
-
- virtual Common::Error init(ResourceManager *resmgr, int expected_latency);
- virtual Common::Error add_iterator(SongIterator *it, uint32 start_time);
- virtual Common::Error stop();
- virtual Common::Error iterator_message(const SongIterator::Message &msg);
- virtual Common::Error pause();
- virtual Common::Error resume();
- virtual Common::Error exit();
- virtual void tell_synth(int buf_nr, byte *buf);
-};
-
-} // End of namespace Sci
-
-#endif
diff --git a/engines/sci/sfx/player/realtime.cpp b/engines/sci/sfx/player/realtime.cpp
deleted file mode 100644
index 85c6ffe0cc..0000000000
--- a/engines/sci/sfx/player/realtime.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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$
- *
- */
-
-/* OK... 'realtime' may be a little too euphemistic, as this one just
-** prays for some reasonable amount of soft real-time, but it's close
-** enough, I guess. */
-
-#include "sci/tools.h"
-#include "sci/sfx/player/realtime.h"
-#include "sci/sfx/sequencer.h"
-#include "sci/sfx/iterator.h"
-#include "sci/sfx/core.h"
-
-#include "common/system.h"
-
-namespace Sci {
-
-/* Playing mechanism */
-
-static inline int delta_time(const uint32 comp, const uint32 base) {
- return long(comp) - long(base);
-}
-
-// TODO: Turn the following static vars into member vars
-static sfx_sequencer_t *seq;
-
-static SongIterator *play_it = NULL;
-static uint32 play_last_time;
-static uint32 play_pause_started; /* Beginning of the last pause */
-static uint32 play_pause_counter; /* Last point in time to mark a
- ** play position augmentation */
-static int play_paused = 0;
-static int play_it_done = 0;
-static int play_writeahead = 0;
-static int play_moredelay = 0;
-
-static void play_song(SongIterator *it, uint32 *wakeup_time, int writeahead_time) {
- unsigned char buf[8];
- int result;
-
- if (play_paused) {
- uint32 ct = g_system->getMillis();
-
- *wakeup_time += delta_time(play_pause_counter, ct);
-
- play_pause_counter = ct;
- } else
- /* Not paused: */
- while (play_it && delta_time(*wakeup_time, g_system->getMillis())
- < writeahead_time) {
- int delay;
-
- switch ((delay = songit_next(&(play_it),
- &(buf[0]), &result,
- IT_READER_MASK_ALL
- | IT_READER_MAY_FREE
- | IT_READER_MAY_CLEAN))) {
-
- case SI_FINISHED:
- play_it_done = 1;
- return;
-
- case SI_IGNORE:
- case SI_LOOP:
- case SI_RELATIVE_CUE:
- case SI_ABSOLUTE_CUE:
- break;
-
- case SI_PCM:
- sfx_play_iterator_pcm(play_it, 0);
- break;
-
- case 0:
- seq->event(buf[0], result - 1, buf + 1);
-
- break;
-
- default:
- play_moredelay = delay - 1;
- *wakeup_time += delay * 1000 / SFX_TICKS_PER_SEC;
- if (seq->delay)
- seq->delay(delay);
- }
- }
-}
-
-void RealtimePlayer::tell_synth(int buf_nr, byte *buf) {
- seq->event(buf[0], buf_nr - 1, buf + 1);
-}
-
-void RealtimePlayer::maintenance() {
- if (play_it && !play_it_done) {
- if (!play_moredelay) {
- int delta = delta_time(play_last_time, g_system->getMillis());
-
- if (delta < 0) {
- play_writeahead -= (int)((double)delta * 1.2); /* Adjust upwards */
- } else if (delta > 15) {
- play_writeahead -= 3; /* Adjust downwards */
- }
- } else
- --play_moredelay;
-
- if (play_writeahead < seq->min_write_ahead_ms)
- play_writeahead = seq->min_write_ahead_ms;
-
- play_song(play_it, &play_last_time, play_writeahead);
- }
-}
-
-static Resource *find_patch(ResourceManager *resmgr, const char *seq_name, int patchfile) {
- Resource *res = NULL;
-
- if (patchfile != SFX_SEQ_PATCHFILE_NONE) {
- res = resmgr->findResource(kResourceTypePatch, patchfile, 0);
- if (!res) {
- warning("[SFX] " __FILE__": patch.%03d requested by sequencer (%s), but not found",
- patchfile, seq_name);
- }
- }
-
- return res;
-}
-
-/* API implementation */
-
-Common::Error RealtimePlayer::init(ResourceManager *resmgr, int expected_latency) {
- Resource *res = NULL, *res2 = NULL;
- void *seq_dev = NULL;
-
- seq = sfx_find_sequencer(NULL);
-
- if (!seq) {
- warning("[SFX] " __FILE__": Could not find sequencer");
- return Common::kUnknownError;
- }
-
- this->polyphony = seq->polyphony;
-
- res = find_patch(resmgr, seq->name, seq->patchfile);
- res2 = find_patch(resmgr, seq->name, seq->patchfile2);
-
- if (seq->device)
- seq_dev = sfx_find_device(seq->device, NULL);
-
- if (seq->open(res ? res->size : 0,
- res ? res->data : NULL,
- res2 ? res2->size : 0,
- res2 ? res2->data : NULL,
- seq_dev)) {
- warning("[SFX] " __FILE__": Sequencer failed to initialize");
- return Common::kUnknownError;
- }
-
- play_writeahead = expected_latency;
- if (play_writeahead < seq->min_write_ahead_ms)
- play_writeahead = seq->min_write_ahead_ms;
-
- play_writeahead *= 1; /* milliseconds */
-
- if (seq->reset_timer)
- seq->reset_timer(0);
-
- return Common::kNoError;
-}
-
-Common::Error RealtimePlayer::add_iterator(SongIterator *it, uint32 start_time) {
- if (seq->reset_timer) /* Restart timer counting if possible */
- seq->reset_timer(start_time);
-
- SIMSG_SEND(it, SIMSG_SET_PLAYMASK(seq->playmask));
- SIMSG_SEND(it, SIMSG_SET_RHYTHM(seq->play_rhythm));
-
- play_last_time = start_time;
- play_it = sfx_iterator_combine(play_it, it);
- play_it_done = 0;
- play_moredelay = 0;
-
- return Common::kNoError;
-}
-
-Common::Error RealtimePlayer::stop(void) {
- SongIterator *it = play_it;
-
- play_it = NULL;
-
- delete it;
- if (seq && seq->allstop)
- seq->allstop();
-
- return Common::kNoError;
-}
-
-Common::Error RealtimePlayer::iterator_message(const SongIterator::Message &msg) {
- if (!play_it)
- return Common::kUnknownError;
-
- songit_handle_message(&play_it, msg);
- return Common::kNoError;
-}
-
-Common::Error RealtimePlayer::pause(void) {
- play_pause_started = g_system->getMillis();
- // Also, indicate that we haven't modified the time counter yet
- play_pause_counter = play_pause_started;
-
- play_paused = 1;
- if (!seq->allstop) {
- sciprintf("[SFX] Cannot suspend sequencer, sound will continue for a bit\n");
- return Common::kNoError;
- } else
- return seq->allstop();
-}
-
-Common::Error RealtimePlayer::resume(void) {
- play_paused = 0;
- return Common::kNoError;
-}
-
-Common::Error RealtimePlayer::exit(void) {
- if (seq->close()) {
- warning("[SFX] Sequencer reported error on close");
- return Common::kUnknownError;
- }
-
- return Common::kNoError;
-}
-
-RealtimePlayer::RealtimePlayer() {
- name = "realtime";
- version = "0.1";
-}
-
-} // End of namespace Sci
diff --git a/engines/sci/sfx/player/realtime.h b/engines/sci/sfx/player/realtime.h
deleted file mode 100644
index 3aeeb6e1e7..0000000000
--- a/engines/sci/sfx/player/realtime.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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 SCI_SFX_SFX_PLAYER_REALTIME_H
-#define SCI_SFX_SFX_PLAYER_REALTIME_H
-
-#include "sci/sfx/player.h"
-
-namespace Sci {
-
-class RealtimePlayer : public SfxPlayer {
-public:
- RealtimePlayer();
-
- virtual Common::Error init(ResourceManager *resmgr, int expected_latency);
- virtual Common::Error add_iterator(SongIterator *it, uint32 start_time);
- virtual Common::Error stop();
- virtual Common::Error iterator_message(const SongIterator::Message &msg);
- virtual Common::Error pause();
- virtual Common::Error resume();
- virtual Common::Error exit();
- virtual void maintenance();
- virtual void tell_synth(int buf_nr, byte *buf);
-};
-
-} // End of namespace Sci
-
-#endif
diff --git a/engines/sci/sfx/sequencer.h b/engines/sci/sfx/sequencer.h
index ba9edcdad7..70b1c73453 100644
--- a/engines/sci/sfx/sequencer.h
+++ b/engines/sci/sfx/sequencer.h
@@ -30,7 +30,6 @@
#include "common/scummsys.h"
#include "common/error.h"
-#include "sci/sfx/device.h"
namespace Sci {