aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx/softseq/pcspeaker.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2009-02-15 11:39:07 +0000
committerEugene Sandulenko2009-02-15 11:39:07 +0000
commite241843bec22600ab4ef98e7a085e82aac73fc93 (patch)
tree61a793884d3462e1feb80e80f202d8816d0c8ec4 /engines/sci/sfx/softseq/pcspeaker.cpp
parente9f742806362a84ffdb176a7414318dd2ab4df89 (diff)
downloadscummvm-rg350-e241843bec22600ab4ef98e7a085e82aac73fc93.tar.gz
scummvm-rg350-e241843bec22600ab4ef98e7a085e82aac73fc93.tar.bz2
scummvm-rg350-e241843bec22600ab4ef98e7a085e82aac73fc93.zip
- Remove some unneeded files
- Mass rename .c to .cpp svn-id: r38227
Diffstat (limited to 'engines/sci/sfx/softseq/pcspeaker.cpp')
-rw-r--r--engines/sci/sfx/softseq/pcspeaker.cpp184
1 files changed, 184 insertions, 0 deletions
diff --git a/engines/sci/sfx/softseq/pcspeaker.cpp b/engines/sci/sfx/softseq/pcspeaker.cpp
new file mode 100644
index 0000000000..727b1f9e5a
--- /dev/null
+++ b/engines/sci/sfx/softseq/pcspeaker.cpp
@@ -0,0 +1,184 @@
+/***************************************************************************
+ soft-pcspeaker.c Copyright (C) 2004 Christoph Reichenbach
+
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public Licence as
+ published by the Free Software Foundaton; either version 2 of the
+ Licence, or (at your option) any later version.
+
+ It is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ merchantibility or fitness for a particular purpose. See the
+ GNU General Public Licence for more details.
+
+ You should have received a copy of the GNU General Public Licence
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+
+ Please contact the maintainer for any program-related bug reports or
+ inquiries.
+
+ Current Maintainer:
+
+ Christoph Reichenbach (CR) <jameson@linuxgames.com>
+
+***************************************************************************/
+/* PC speaker software sequencer for FreeSCI */
+
+#include "sci/sfx/softseq.h"
+#include "sci/include/sci_midi.h"
+
+#define FREQUENCY 94020
+
+static int volume = 0x0600;
+static int note = 0; /* Current halftone, or 0 if off */
+static int freq_count = 0;
+
+extern sfx_softseq_t sfx_softseq_pcspeaker;
+/* Forward-declare the sequencer we are defining here */
+
+
+static int
+sps_set_option(sfx_softseq_t *self, char *name, char *value)
+{
+ return SFX_ERROR;
+}
+
+static int
+sps_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2,
+ int patch2_len)
+{
+ return SFX_OK;
+}
+
+static void
+sps_exit(sfx_softseq_t *self)
+{
+}
+
+static void
+sps_event(sfx_softseq_t *self, byte command, int argc, byte *argv)
+{
+#if 0
+ fprintf(stderr, "Note [%02x : %02x %02x]\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0);
+#endif
+
+ switch (command & 0xf0) {
+
+ case 0x80:
+ if (argv[0] == note)
+ note = 0;
+ break;
+
+ case 0x90:
+ if (!argv[1]) {
+ if (argv[0] == note)
+ note = 0;
+ } else
+ note = argv[0];
+ /* Ignore velocity otherwise; we just use the global one */
+ break;
+
+ case 0xb0:
+ if (argv[1] == SCI_MIDI_CHANNEL_NOTES_OFF)
+ note = 0;
+ break;
+
+ default:
+#if DEBUG
+ fprintf(stderr, "[SFX:PCM-PC] Unused MIDI command %02x %02x %02x\n", command, argc?argv[0] : 0, (argc > 1)? argv[1] : 0);
+#endif
+ break; /* ignore */
+ }
+}
+
+#define BASE_NOTE 129 /* A10 */
+#define BASE_OCTAVE 10 /* A10, as I said */
+
+static int
+freq_table[12] = { /* A4 is 440Hz, halftone map is x |-> ** 2^(x/12) */
+ 28160, /* A10 */
+ 29834,
+ 31608,
+ 33488,
+ 35479,
+ 37589,
+ 39824,
+ 42192,
+ 44701,
+ 47359,
+ 50175,
+ 53159
+};
+
+
+void
+sps_poll(sfx_softseq_t *self, byte *dest, int len)
+{
+ int halftone_delta = note - BASE_NOTE;
+ int oct_diff = ((halftone_delta + BASE_OCTAVE * 12) / 12) - BASE_OCTAVE;
+ int halftone_index = (halftone_delta + (12*100)) % 12 ;
+ int freq = (!note)? 0 : freq_table[halftone_index] / (1 << (-oct_diff));
+ gint16 *buf = (gint16 *) dest;
+
+ int i;
+ for (i = 0; i < len; i++) {
+ if (note) {
+ freq_count += freq;
+ while (freq_count >= (FREQUENCY << 1))
+ freq_count -= (FREQUENCY << 1);
+
+ if (freq_count - freq < 0) {
+ /* Unclean rising edge */
+ int l = volume << 1;
+ buf[i] = -volume + (l*freq_count)/freq;
+ } else if (freq_count >= FREQUENCY
+ && freq_count - freq < FREQUENCY) {
+ /* Unclean falling edge */
+ int l = volume << 1;
+ buf[i] = volume - (l*(freq_count - FREQUENCY))/freq;
+ } else {
+ if (freq_count < FREQUENCY)
+ buf[i] = volume;
+ else
+ buf[i] = -volume;
+ }
+ } else
+ buf[i] = 0;
+ }
+
+}
+
+void
+sps_volume(sfx_softseq_t *self, int new_volume)
+{
+ volume = new_volume << 4;
+}
+
+void
+sps_allstop(sfx_softseq_t *self)
+{
+ note = 0;
+}
+
+sfx_softseq_t sfx_softseq_pcspeaker = {
+ "pc-speaker",
+ "0.3",
+ sps_set_option,
+ sps_init,
+ sps_exit,
+ sps_volume,
+ sps_event,
+ sps_poll,
+ sps_allstop,
+ NULL,
+ SFX_SEQ_PATCHFILE_NONE,
+ SFX_SEQ_PATCHFILE_NONE,
+ 0x20, /* PC speaker channel only */
+ 0, /* No rhythm channel */
+ 1, /* # of voices */
+ {FREQUENCY, SFX_PCM_MONO, SFX_PCM_FORMAT_S16_NATIVE}
+};