HYPNO: added support for playing stereo music in boyz

This commit is contained in:
neuromancer 2022-06-16 21:44:32 +02:00
parent ffb8e5a7e2
commit 0cf636343c
7 changed files with 274 additions and 239 deletions

View File

@ -530,7 +530,8 @@ void HypnoEngine::runArcade(ArcadeShooting *arc) {
if (_music.empty() && !arc->music.empty()) {
_music = _soundPath + arc->music;
_musicRate = arc->musicRate;
playSound(_music, 0, _musicRate); // music loop forever
_musicStereo = arc->musicStereo;
playSound(_music, 0, _musicRate, _musicStereo); // music loop forever
}
if (needsUpdate) {

View File

@ -376,6 +376,7 @@ public:
type = CodeLevel;
musicRate = 22050;
playMusicDuringIntro = false;
musicStereo = false;
}
virtual ~Level() {} // needed to make Level polymorphic
LevelType type;
@ -386,6 +387,7 @@ public:
bool playMusicDuringIntro;
Filename music;
uint32 musicRate;
bool musicStereo;
};
class Scene : public Level {

File diff suppressed because it is too large Load Diff

View File

@ -50,32 +50,42 @@ using namespace Hypno;
void parseSN(const char *sn, const char *path, const char *enc, const char *flag) {
uint32 sampleRate = 11025;
bool stereo = false;
if (Common::String("22K") == enc || Common::String("22k") == enc)
sampleRate = 22050;
else if (HYPNO_ARC_default_sound_rate > 0)
sampleRate = HYPNO_ARC_default_sound_rate;
if (Common::String("STEREO") == flag)
stereo = true;
if (Common::String("S0") == sn) {
g_parsedArc->music = path;
g_parsedArc->musicRate = sampleRate;
g_parsedArc->musicStereo = stereo;
} else if (Common::String("S1") == sn) {
g_parsedArc->shootSound = path;
g_parsedArc->shootSoundRate = sampleRate;
assert(!stereo);
} else if (Common::String("S2") == sn) {
g_parsedArc->hitSound = path;
g_parsedArc->hitSoundRate = sampleRate;
assert(!stereo);
} else if (Common::String("S4") == sn) {
g_parsedArc->enemySound = path;
g_parsedArc->enemySoundRate = sampleRate;
assert(!stereo);
} else if (Common::String("S5") == sn) {
g_parsedArc->additionalSound = path;
g_parsedArc->additionalSoundRate = sampleRate;
assert(!stereo);
} else if (Common::String("S7") == sn) {
g_parsedArc->noAmmoSound = path;
g_parsedArc->noAmmoSoundRate = sampleRate;
assert(!stereo);
} else if (Common::String("S8") == sn) {
g_parsedArc->additionalSound = path;
g_parsedArc->additionalSoundRate = sampleRate;
assert(!stereo);
}
debugC(1, kHypnoDebugParser, "SN %s", path);
}

View File

@ -32,6 +32,7 @@
#include "common/savefile.h"
#include "common/str.h"
#include "common/system.h"
#include "common/substream.h"
#include "common/timer.h"
#include "engines/advancedDetector.h"
#include "engines/util.h"
@ -54,8 +55,8 @@ HypnoEngine::HypnoEngine(OSystem *syst, const ADGameDescription *gd)
_playerFrameIdx(0), _playerFrameSep(0), _refreshConversation(false),
_countdown(0), _timerStarted(false), _score(0), _bonus(0), _lives(0),
_defaultCursor(""), _defaultCursorIdx(0), _skipDefeatVideo(false),
_background(nullptr), _masks(nullptr), _musicRate(0), _skipNextVideo(false),
_additionalVideo(nullptr), _ammo(0), _maxAmmo(0),
_background(nullptr), _masks(nullptr), _musicRate(0), _musicStereo(false),
_additionalVideo(nullptr), _ammo(0), _maxAmmo(0), _skipNextVideo(false),
_doNotStopSounds(false), _screenW(0), _screenH(0) { // Every games initializes its own resolution
_rnd = new Common::RandomSource("hypno");
_checkpoint = "";
@ -540,14 +541,24 @@ void HypnoEngine::skipVideo(MVideo &video) {
// Sound handling
void HypnoEngine::playSound(const Common::String &filename, uint32 loops, uint32 sampleRate) {
void HypnoEngine::playSound(const Common::String &filename, uint32 loops, uint32 sampleRate, bool stereo) {
debugC(1, kHypnoDebugMedia, "%s(%s, %d, %d)", __FUNCTION__, filename.c_str(), loops, sampleRate);
Common::String name = convertPath(filename);
Audio::LoopingAudioStream *stream = nullptr;
Common::File *file = new Common::File();
if (file->open(name)) {
stream = new Audio::LoopingAudioStream(Audio::makeRawStream(file, sampleRate, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES), loops);
uint32 flags = Audio::FLAG_UNSIGNED;
Common::SeekableSubReadStream *sub;
if (stereo) {
sub = new Common::SeekableSubReadStream(file, 0, file->size() - (file->size() % 2), DisposeAfterUse::YES);
flags = flags | Audio::FLAG_STEREO;
} else {
sub = new Common::SeekableSubReadStream(file, 0, file->size(), DisposeAfterUse::YES);
}
stream = new Audio::LoopingAudioStream(Audio::makeRawStream(sub, sampleRate, flags, DisposeAfterUse::YES), loops);
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream, -1, Audio::Mixer::kMaxChannelVolume);
} else {
if (!_prefixDir.empty())

View File

@ -237,8 +237,9 @@ public:
Filename _soundPath;
Filename _music;
int _musicRate;
bool _musicStereo;
bool _doNotStopSounds;
void playSound(const Filename &filename, uint32 loops, uint32 sampleRate = 22050);
void playSound(const Filename &filename, uint32 loops, uint32 sampleRate = 22050, bool stereo = false);
void stopSound();
// Arcade

View File

@ -127,7 +127,7 @@ extern int HYPNO_ARC_debug;
#if ! defined HYPNO_ARC_STYPE && ! defined HYPNO_ARC_STYPE_IS_DECLARED
union HYPNO_ARC_STYPE
{
#line 85 "engines/hypno/grammar_arc.y"
#line 95 "engines/hypno/grammar_arc.y"
char *s; /* string value */
int i; /* integer value */