aboutsummaryrefslogtreecommitdiff
path: root/engines/hugo/sound.cpp
blob: 3673bda7a63c4d62b05f1dbef4fab6a2b0edb6ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* 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$
 *
 */

/*
 * This code is based on original Hugo Trilogy source code
 *
 * Copyright (c) 1989-1995 David P. Gray
 *
 */

/* sound.c - sound effects and music support */

#include "common/system.h"

#include "sound/decoders/raw.h"
#include "sound/audiostream.h"

#include "hugo/hugo.h"
#include "hugo/game.h"
#include "hugo/file.h"
#include "hugo/sound.h"

namespace Hugo {

uint16 SeqID;                                       // Device id of (MIDI) sequencer
uint16 SeqVolID;                                    // Low level id to set midi volume
uint16 WavID = 0;                                   // Device id of waveaudio

//HWAVEOUT hwav;                                    // Handle of waveaudio
//LPWAVEHDR lphdr;                                  // WaveOut structure ptr

SoundHandler::SoundHandler(HugoEngine &vm) : _vm(vm) {
}

void SoundHandler::setMusicVolume() {
	/* Set the FM music volume from config.mvolume (0..100%) */
	warning("STUB: setMusicVolume()");

	// uint32 dwVolume;
	//
	// if (config.music) {
	//  dwVolume = config.mvolume * 0xffffL / 100;  // Convert % to 0..0xffff
	//  dwVolume |= dwVolume << 16;                 // Set volume in both stereo words
	//  midiOutSetVolume(SeqVolID, dwVolume);
	// }
}

void SoundHandler::stopSound() {
	/* Stop any sound that might be playing */
	warning("STUB: stopSound()");

	// waveOutReset(hwav);
	// waveOutUnprepareHeader(hwav, lphdr, sizeof(WAVEHDR));
}

void SoundHandler::stopMusic() {
	/* Stop any tune that might be playing */
	warning("STUB: stopMusic()");
	//mciSendCommand(SeqID, MCI_CLOSE, MCI_WAIT, 0);
}

void SoundHandler::toggleMusic() {
// Turn music on and off
	if (_config.musicFl)
		stopMusic();
	_config.musicFl = !_config.musicFl;
	initSound(RESET);
}

void SoundHandler::toggleSound() {
// Turn digitized sound on and off
	_config.soundFl = !_config.soundFl;
	initSound(RESET);
}

void SoundHandler::playMIDI(sound_pt seq_p, uint16 size) {
// Write supplied midi data to a temp file for MCI interface
// If seq_p is NULL, delete temp file

	warning("STUB: playMIDI()");
}


void SoundHandler::playMusic(int16 tune) {
	/* Read a tune sequence from the sound database and start playing it */
	sound_pt seqPtr;                                // Sequence data from file
	uint16 size;                                    // Size of sequence data

	if (_config.musicFl) {
		_vm.getGameStatus().song = tune;
		seqPtr = _vm.file().getSound(tune, &size);
		playMIDI(seqPtr, size);
	}
}


void SoundHandler::playSound(int16 sound, stereo_t channel, byte priority) {
	/* Produce various sound effects on supplied stereo channel(s) */
	/* Override currently playing sound only if lower or same priority */

	// uint32 dwVolume;                             // Left, right volume of sound
	sound_pt sound_p;                               // Sound data
	uint16 size;                                    // Size of data
	static byte curPriority = 0;                    // Priority of currently playing sound
	//
	/* Sound disabled */
	if (!_config.soundFl || !_vm._mixer->isReady())
		return;
	//
	// // See if last wave still playing - if so, check priority
	// if (waveOutUnprepareHeader(hwav, lphdr, sizeof(WAVEHDR)) == WAVERR_STILLPLAYING)
	//  if (priority < curPriority)                 // Don't override unless priority >= current
	//      return;
	//  else
	//      Stop_sound();
	curPriority = priority;
	//
	/* Get sound data */
	if ((sound_p = _vm.file().getSound(sound, &size)) == NULL)
		return;

	Audio::AudioStream *stream = Audio::makeRawStream(sound_p, size, 11025, Audio::FLAG_UNSIGNED);
	_vm._mixer->playStream(Audio::Mixer::kSpeechSoundType, &_soundHandle, stream);

}

void SoundHandler::initSound(inst_t action) {
	/* Initialize for MCI sound and midi */

	warning("STUB: initSound()");
}

void SoundHandler::pauseSound(bool activeFl, int hTask) {
// Pause and restore music, sound on losing activity to hTask
// Don't stop music if we are parent of new task, i.e. WinHelp()
// or config.music_bkg is TRUE.

//TODO: Is 'hTask' still useful ?

	static bool firstFl = true;
	static bool musicFl, soundFl;

	if (firstFl) {
		firstFl = false;
		musicFl = _config.musicFl;
		soundFl = _config.soundFl;
	}

	// Kill or restore music, sound
	if (activeFl) { // Remember states, reset WinHelp flag
		_config.musicFl = musicFl;
		_config.soundFl = soundFl;
		_vm.getGameStatus().helpFl = false;
	} else {    // Store states and disable
		musicFl = _config.musicFl;
		soundFl = _config.soundFl;

		// Don't disable music during WinHelp() or config.music_bkg
		if (!_vm.getGameStatus().helpFl && !_config.backgroundMusicFl) {
			_config.musicFl = false;
			_config.soundFl = false;
		}
	}
	initSound(RESET);
}

} // end of namespace Hugo