mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 13:33:02 +01:00
use mixer for ride music
This commit is contained in:
@@ -34,7 +34,11 @@ audio_device *gAudioDevices = NULL;
|
||||
rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
rct_vehicle_sound_params *gVehicleSoundParamsListEnd;
|
||||
void* gMusicChannels[4];
|
||||
rct_ride_music gRideMusicList[AUDIO_MAX_RIDE_MUSIC];
|
||||
rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
||||
rct_ride_music_params *gRideMusicParamsListEnd;
|
||||
void *gCrowdSoundChannel = 0;
|
||||
void *gTitleMusicChannel = 0;
|
||||
|
||||
void audio_init(int i)
|
||||
{
|
||||
@@ -1543,7 +1547,7 @@ void start_title_music()
|
||||
if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) && RCT2_GLOBAL(0x009AF59D, uint8) & 1 && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 1) {
|
||||
if (!RCT2_GLOBAL(0x009AF600, uint8)) {
|
||||
#ifdef USE_MIXER
|
||||
gMusicChannels[3] = Mixer_Play_Music(PATH_ID_CSS17);
|
||||
gTitleMusicChannel = Mixer_Play_Music(PATH_ID_CSS17);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int result = sound_channel_load_file2(3, (char*)get_file_path(PATH_ID_CSS17), 0);
|
||||
@@ -1598,12 +1602,16 @@ void stop_other_sounds()
|
||||
void stop_ride_music()
|
||||
{
|
||||
if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
for (int i = 0; i < AUDIO_MAX_RIDE_MUSIC; i++) {
|
||||
rct_ride_music* ride_music = &gRideMusicList[i];//&RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
if (ride_music->rideid != (uint8)-1) {
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Stop_Channel(ride_music->sound_channel);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_stop(i);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
}
|
||||
@@ -1619,9 +1627,9 @@ void stop_crowd_sound()
|
||||
if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) {
|
||||
if (RCT2_GLOBAL(0x009AF5FC, uint32) != 1) {
|
||||
#ifdef USE_MIXER
|
||||
if (gMusicChannels[2]) {
|
||||
Mixer_Stop_Channel(gMusicChannels[2]);
|
||||
gMusicChannels[2] = 0;
|
||||
if (gCrowdSoundChannel) {
|
||||
Mixer_Stop_Channel(gCrowdSoundChannel);
|
||||
gCrowdSoundChannel = 0;
|
||||
}
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
@@ -1642,9 +1650,9 @@ void stop_title_music()
|
||||
if (RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) {
|
||||
if (RCT2_GLOBAL(0x009AF600, uint8) != 0) {
|
||||
#ifdef USE_MIXER
|
||||
if (gMusicChannels[3]) {
|
||||
Mixer_Stop_Channel(gMusicChannels[3]);
|
||||
gMusicChannels[3] = 0;
|
||||
if (gTitleMusicChannel) {
|
||||
Mixer_Stop_Channel(gTitleMusicChannel);
|
||||
gTitleMusicChannel = 0;
|
||||
}
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
@@ -1705,7 +1713,7 @@ void audio_init1()
|
||||
void audio_init2(int device)
|
||||
{
|
||||
audio_close();
|
||||
for (int i = 0; i < countof(gVehicleSoundList)/*7*/; i++) {
|
||||
for (int i = 0; i < AUDIO_MAX_VEHICLE_SOUNDS/*7*/; i++) {
|
||||
rct_vehicle_sound* vehicle_sound = &gVehicleSoundList[i];
|
||||
//rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i];
|
||||
vehicle_sound->id = 0xFFFF;
|
||||
@@ -1740,8 +1748,8 @@ void audio_init2(int device)
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (successtimer) {
|
||||
RCT2_GLOBAL(0x009AF284, uint32) |= (1 << 0);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
for (int i = 0; i < AUDIO_MAX_RIDE_MUSIC; i++) {
|
||||
rct_ride_music* ride_music = &gRideMusicList[i];//&RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ extern int gAudioDeviceCount;
|
||||
extern audio_device *gAudioDevices;
|
||||
|
||||
#define AUDIO_MAX_VEHICLE_SOUNDS 14
|
||||
#define AUDIO_MAX_RIDE_MUSIC 2
|
||||
|
||||
void audio_init();
|
||||
void audio_quit();
|
||||
@@ -132,9 +133,11 @@ typedef struct {
|
||||
typedef struct {
|
||||
uint8 rideid;
|
||||
uint8 tuneid;
|
||||
uint16 volume; //0x2
|
||||
uint16 pan; //0x4
|
||||
sint16 volume; //0x2
|
||||
sint16 pan; //0x4
|
||||
uint16 freq; //0x6
|
||||
// added to openrct2:
|
||||
void* sound_channel;
|
||||
} rct_ride_music;
|
||||
|
||||
typedef struct {
|
||||
@@ -147,7 +150,11 @@ typedef struct {
|
||||
extern rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern rct_vehicle_sound_params *gVehicleSoundParamsListEnd;
|
||||
extern void* gMusicChannels[4];
|
||||
extern rct_ride_music gRideMusicList[AUDIO_MAX_RIDE_MUSIC];
|
||||
extern rct_ride_music_params gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC];
|
||||
extern rct_ride_music_params *gRideMusicParamsListEnd;
|
||||
extern void *gCrowdSoundChannel;
|
||||
extern void *gTitleMusicChannel;
|
||||
|
||||
void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel);
|
||||
int CALLBACK audio_timer_callback(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
|
||||
|
||||
@@ -205,6 +205,7 @@ Channel::Channel()
|
||||
SetPan(0.5f);
|
||||
done = true;
|
||||
stopping = false;
|
||||
stream = 0;
|
||||
}
|
||||
|
||||
Channel::~Channel()
|
||||
@@ -260,6 +261,21 @@ bool Channel::IsPlaying()
|
||||
return !done;
|
||||
}
|
||||
|
||||
unsigned long Channel::GetOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool Channel::SetOffset(unsigned long offset)
|
||||
{
|
||||
if (stream && offset < stream->Length()) {
|
||||
int samplesize = stream->Format()->channels * stream->Format()->BytesPerSample();
|
||||
Channel::offset = (offset / samplesize) * samplesize;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Mixer::Init(const char* device)
|
||||
{
|
||||
Close();
|
||||
@@ -281,7 +297,7 @@ void Mixer::Init(const char* device)
|
||||
css1samples[i].Convert(format); // convert to audio output format, saves some cpu usage but requires a bit more memory, optional
|
||||
css1streams[i].SetSource_Sample(css1samples[i]);
|
||||
}
|
||||
effectbuffer = new uint8[(have.samples * format.BytesPerSample() * format.channels) + 200];
|
||||
effectbuffer = new uint8[(have.samples * format.BytesPerSample() * format.channels)];
|
||||
SDL_PauseAudioDevice(deviceid, 0);
|
||||
}
|
||||
|
||||
@@ -361,7 +377,7 @@ void SDLCALL Mixer::Callback(void* arg, uint8* stream, int length)
|
||||
void Mixer::MixChannel(Channel& channel, uint8* data, int length)
|
||||
{
|
||||
if (channel.stream && !channel.done) {
|
||||
AudioFormat channelformat = *channel.stream->Format();
|
||||
AudioFormat streamformat = *channel.stream->Format();
|
||||
int loaded = 0;
|
||||
SDL_AudioCVT cvt;
|
||||
cvt.len_ratio = 1;
|
||||
@@ -373,19 +389,20 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length)
|
||||
if (format.format == AUDIO_S16SYS) {
|
||||
rate = channel.rate;
|
||||
}
|
||||
int samplestoread = (int)ceil((samples - samplesloaded) * rate);
|
||||
int samplestoread = (int)((samples - samplesloaded) * rate);
|
||||
int lengthloaded = 0;
|
||||
if (channel.offset < channel.stream->Length()) {
|
||||
bool mustconvert = false;
|
||||
if (MustConvert(*channel.stream)) {
|
||||
if (SDL_BuildAudioCVT(&cvt, channelformat.format, channelformat.channels, channelformat.freq, Mixer::format.format, Mixer::format.channels, Mixer::format.freq) == -1) {
|
||||
if (SDL_BuildAudioCVT(&cvt, streamformat.format, streamformat.channels, streamformat.freq, Mixer::format.format, Mixer::format.channels, Mixer::format.freq) == -1) {
|
||||
break;
|
||||
}
|
||||
mustconvert = true;
|
||||
}
|
||||
|
||||
const uint8* datastream = 0;
|
||||
int readfromstream = (channel.stream->GetSome(channel.offset, &datastream, (int)(((samplestoread) * samplesize) / cvt.len_ratio)) / channelformat.BytesPerSample()) * channelformat.BytesPerSample();
|
||||
int toread = (int)(samplestoread / cvt.len_ratio) * samplesize;
|
||||
int readfromstream = (channel.stream->GetSome(channel.offset, &datastream, toread));
|
||||
if (readfromstream == 0) {
|
||||
break;
|
||||
}
|
||||
@@ -395,9 +412,10 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length)
|
||||
const uint8* tomix = 0;
|
||||
|
||||
if (mustconvert) {
|
||||
// tofix: there seems to be an issue with converting audio using SDL_ConvertAudio in the callback vs preconverted, can cause pops and static depending on sample rate and channels
|
||||
if (Convert(cvt, datastream, readfromstream, &dataconverted)) {
|
||||
tomix = dataconverted;
|
||||
lengthloaded = (cvt.len_cvt / samplesize) * samplesize;
|
||||
lengthloaded = cvt.len_cvt;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -408,12 +426,18 @@ void Mixer::MixChannel(Channel& channel, uint8* data, int length)
|
||||
|
||||
bool effectbufferloaded = false;
|
||||
if (rate != 1 && format.format == AUDIO_S16SYS) {
|
||||
int in_len = (int)(ceil((double)lengthloaded / samplesize));
|
||||
int out_len = samples + 20; // needs some extra, otherwise resampler sometimes doesn't process all the input samples
|
||||
int in_len = (int)((double)lengthloaded / samplesize);
|
||||
int out_len = samples;
|
||||
if (!channel.resampler) {
|
||||
channel.resampler = speex_resampler_init(format.channels, format.freq, format.freq, 0, 0);
|
||||
}
|
||||
speex_resampler_set_rate(channel.resampler, format.freq, (int)(format.freq * (1 / rate)));
|
||||
if (readfromstream == toread) {
|
||||
// use buffer lengths for conversion ratio so that it fits exactly
|
||||
speex_resampler_set_rate(channel.resampler, in_len, samples - samplesloaded);
|
||||
} else {
|
||||
// reached end of stream so we cant use buffer length as resampling ratio
|
||||
speex_resampler_set_rate(channel.resampler, format.freq, (int)(format.freq * (1 / rate)));
|
||||
}
|
||||
speex_resampler_process_interleaved_int(channel.resampler, (const spx_int16_t*)tomix, (spx_uint32_t*)&in_len, (spx_int16_t*)effectbuffer, (spx_uint32_t*)&out_len);
|
||||
effectbufferloaded = true;
|
||||
tomix = effectbuffer;
|
||||
@@ -612,6 +636,16 @@ int Mixer_Channel_IsPlaying(void* channel)
|
||||
return ((Channel*)channel)->IsPlaying();
|
||||
}
|
||||
|
||||
unsigned long Mixer_Channel_GetOffset(void* channel)
|
||||
{
|
||||
return ((Channel*)channel)->GetOffset();
|
||||
}
|
||||
|
||||
int Mixer_Channel_SetOffset(void* channel, unsigned long offset)
|
||||
{
|
||||
return ((Channel*)channel)->SetOffset(offset);
|
||||
}
|
||||
|
||||
void* Mixer_Play_Music(int pathid)
|
||||
{
|
||||
if (gMixer.LoadMusic(pathid)) {
|
||||
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
void SetVolume(int volume);
|
||||
void SetPan(float pan);
|
||||
bool IsPlaying();
|
||||
unsigned long GetOffset();
|
||||
bool SetOffset(unsigned long offset);
|
||||
|
||||
friend class Mixer;
|
||||
|
||||
@@ -154,6 +156,8 @@ void Mixer_Channel_Volume(void* channel, int volume);
|
||||
void Mixer_Channel_Pan(void* channel, float pan);
|
||||
void Mixer_Channel_Rate(void* channel, double rate);
|
||||
int Mixer_Channel_IsPlaying(void* channel);
|
||||
unsigned long Mixer_Channel_GetOffset(void* channel);
|
||||
int Mixer_Channel_SetOffset(void* channel, unsigned long offset);
|
||||
void* Mixer_Play_Music(int pathid);
|
||||
|
||||
static int DStoMixerVolume(int volume) { return (int)(SDL_MIX_MAXVOLUME * (SDL_pow(10, (float)volume / 2000))); };
|
||||
|
||||
@@ -1822,7 +1822,7 @@ void window_update_viewport_ride_music()
|
||||
rct_viewport *viewport;
|
||||
rct_window *w;
|
||||
|
||||
RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*) = (rct_ride_music_params*)0x009AF430;
|
||||
gRideMusicParamsListEnd = &gRideMusicParamsList[0];//RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*) = (rct_ride_music_params*)0x009AF430;
|
||||
RCT2_GLOBAL(0x00F438A4, rct_viewport*) = (rct_viewport*)-1;
|
||||
|
||||
for (w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
|
||||
|
||||
@@ -974,8 +974,8 @@ void peep_update_crowd_noise()
|
||||
// Mute crowd noise
|
||||
if (RCT2_GLOBAL(0x009AF5FC, uint32) != 1) {
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Stop_Channel(gMusicChannels[2]);
|
||||
gMusicChannels[2] = 0;
|
||||
Mixer_Stop_Channel(gCrowdSoundChannel);
|
||||
gCrowdSoundChannel = 0;
|
||||
#else
|
||||
sound_channel_stop(2); //RCT2_CALLPROC_1(0x00401A05, int, 2);
|
||||
#endif
|
||||
@@ -994,9 +994,11 @@ void peep_update_crowd_noise()
|
||||
if (RCT2_GLOBAL(0x009AF5FC, uint32) == 1) {
|
||||
// Load and play crowd noise
|
||||
#ifdef USE_MIXER
|
||||
gMusicChannels[2] = Mixer_Play_Music(PATH_ID_CSS2);
|
||||
if (gMusicChannels[2]) {
|
||||
Mixer_Channel_Volume(gMusicChannels[2], DStoMixerVolume(volume));
|
||||
if (!gCrowdSoundChannel) {
|
||||
gCrowdSoundChannel = Mixer_Play_Music(PATH_ID_CSS2);
|
||||
}
|
||||
if (gCrowdSoundChannel) {
|
||||
Mixer_Channel_Volume(gCrowdSoundChannel, DStoMixerVolume(volume));
|
||||
RCT2_GLOBAL(0x009AF5FC, uint32) = volume;
|
||||
}
|
||||
#else
|
||||
@@ -1009,7 +1011,7 @@ void peep_update_crowd_noise()
|
||||
// Alter crowd noise volume
|
||||
if (RCT2_GLOBAL(0x009AF5FC, uint32) != volume) {
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Channel_Volume(gMusicChannels[2], DStoMixerVolume(volume));
|
||||
Mixer_Channel_Volume(gCrowdSoundChannel, DStoMixerVolume(volume));
|
||||
#else
|
||||
sound_channel_set_volume(2, volume);//RCT2_CALLPROC_2(0x00401AD3, int, int, 2, volume);
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <windows.h>
|
||||
#include "../addresses.h"
|
||||
#include "../audio/audio.h"
|
||||
#include "../audio/mixer.h"
|
||||
#include "../game.h"
|
||||
#include "../input.h"
|
||||
#include "../interface/window.h"
|
||||
@@ -2384,40 +2385,48 @@ int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint
|
||||
if (!RCT2_GLOBAL(0x009AAC6D, uint8)) {
|
||||
panx = 0;
|
||||
}
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
rct_ride_music* ride_music = &gRideMusicList[0];//&RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
uint32 a1;
|
||||
while (ride_music->rideid != rideIndex || ride_music->tuneid != *tuneId) {
|
||||
ride_music++;
|
||||
channel++;
|
||||
if (channel >= 2) {
|
||||
if (channel >= AUDIO_MAX_RIDE_MUSIC) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[*tuneId];
|
||||
a1 = position + ride_music_info->var_4;
|
||||
goto label51;
|
||||
}
|
||||
}
|
||||
#ifdef USE_MIXER
|
||||
int playing = Mixer_Channel_IsPlaying(gRideMusicList[channel].sound_channel);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int playing = sound_channel_is_playing(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
if (!playing) {
|
||||
*tuneId = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
#ifdef USE_MIXER
|
||||
a1 = Mixer_Channel_GetOffset(gRideMusicList[channel].sound_channel);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
a1 = sub_401B46(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
label51:
|
||||
if (a1 < RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[*tuneId].var_0) {
|
||||
position = a1;
|
||||
rct_ride_music_params* ride_music_params = RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*);
|
||||
if (ride_music_params < (rct_ride_music_params*)0x009AF46C/*ride_music_params list end*/) {
|
||||
rct_ride_music_params* ride_music_params = gRideMusicParamsListEnd;//RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*);
|
||||
if (ride_music_params < &gRideMusicParamsList[AUDIO_MAX_RIDE_MUSIC]/*(rct_ride_music_params*)0x009AF46C*/) {
|
||||
ride_music_params->rideid = rideIndex;
|
||||
ride_music_params->tuneid = *tuneId;
|
||||
ride_music_params->offset = a1;
|
||||
ride_music_params->volume = v32;
|
||||
ride_music_params->pan = panx;
|
||||
ride_music_params->freq = RCT2_GLOBAL(0x009AF47C, uint16);
|
||||
RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)++;
|
||||
gRideMusicParamsListEnd++;//RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)++;
|
||||
}
|
||||
} else {
|
||||
*tuneId = 0xFF;
|
||||
@@ -2454,8 +2463,8 @@ void ride_music_update_final()
|
||||
while (1) {
|
||||
int v8 = 0;
|
||||
int v9 = 1;
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
rct_ride_music_params* ride_music_params = &gRideMusicParamsList[0];//&RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < gRideMusicParamsListEnd/*RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)*/) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[ride_music_params->tuneid];
|
||||
if (RCT2_ADDRESS(0x009AA0B1, uint8*)[ride_music_info->pathid]) { // file_on_cdrom[]
|
||||
@@ -2476,8 +2485,8 @@ void ride_music_update_final()
|
||||
while (1) {
|
||||
int v8 = 0;
|
||||
int v9 = 1;
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
rct_ride_music_params* ride_music_params = &gRideMusicParamsList[0];//&RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < gRideMusicParamsListEnd/*RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)*/) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
v8++;
|
||||
if (v9 >= ride_music_params->volume) {
|
||||
@@ -2494,36 +2503,44 @@ void ride_music_update_final()
|
||||
}
|
||||
|
||||
// stop currently playing music that is not in music params list or not playing?
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
rct_ride_music* ride_music = &gRideMusicList[0];//&RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
do {
|
||||
if (ride_music->rideid != (uint8)-1) {
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
rct_ride_music_params* ride_music_params = &gRideMusicParamsList[0];//&RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < gRideMusicParamsListEnd/*RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)*/) {
|
||||
if (ride_music_params->rideid == ride_music->rideid && ride_music_params->tuneid == ride_music->tuneid) {
|
||||
#ifdef USE_MIXER
|
||||
int isplaying = Mixer_Channel_IsPlaying(gRideMusicList[channel].sound_channel);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int v16 = sound_channel_is_playing(channel);
|
||||
int isplaying = sound_channel_is_playing(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (v16) {
|
||||
#endif
|
||||
if (isplaying) {
|
||||
goto label32;
|
||||
}
|
||||
break;
|
||||
}
|
||||
ride_music_params++;
|
||||
}
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Stop_Channel(gRideMusicList[channel].sound_channel);
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_stop(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
label32:
|
||||
ride_music++;
|
||||
channel++;
|
||||
} while(channel < 2);
|
||||
} while(channel < AUDIO_MAX_RIDE_MUSIC);
|
||||
|
||||
for (rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params); ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*); ride_music_params++) {
|
||||
for (rct_ride_music_params* ride_music_params = &gRideMusicParamsList[0]/*&RCT2_GLOBAL(0x009AF430, rct_ride_music_params)*/; ride_music_params < gRideMusicParamsListEnd/*RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)*/; ride_music_params++) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
rct_ride_music* ride_music = &gRideMusicList[0];//&RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
while (ride_music_params->rideid != ride_music->rideid || ride_music_params->tuneid != ride_music->tuneid) {
|
||||
if (ride_music->rideid == (uint8)-1) {
|
||||
@@ -2531,8 +2548,29 @@ void ride_music_update_final()
|
||||
}
|
||||
ride_music++;
|
||||
channel++;
|
||||
if (channel >= 2) {
|
||||
if (channel >= AUDIO_MAX_RIDE_MUSIC) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[ride_music_params->tuneid];
|
||||
#ifdef USE_MIXER
|
||||
rct_ride_music* ride_music = &gRideMusicList[ebx];
|
||||
ride_music->sound_channel = Mixer_Play_Music(ride_music_info->pathid);
|
||||
if (ride_music->sound_channel) {
|
||||
ride_music->volume = ride_music_params->volume;
|
||||
ride_music->pan = ride_music_params->pan;
|
||||
ride_music->freq = ride_music_params->freq;
|
||||
ride_music->rideid = ride_music_params->rideid;
|
||||
ride_music->tuneid = ride_music_params->tuneid;
|
||||
Mixer_Channel_Volume(ride_music->sound_channel, DStoMixerVolume(ride_music->volume));
|
||||
Mixer_Channel_Pan(ride_music->sound_channel, DStoMixerPan(ride_music->pan));
|
||||
Mixer_Channel_Rate(ride_music->sound_channel, DStoMixerRate(ride_music->freq));
|
||||
int offset = ride_music_params->offset - 10000;
|
||||
if (offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
Mixer_Channel_SetOffset(ride_music->sound_channel, offset);
|
||||
} else {
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = 0;
|
||||
}
|
||||
#else
|
||||
const char* filename = get_file_path(ride_music_info->pathid);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 3;
|
||||
HANDLE hfile = osinterface_file_open(filename);
|
||||
@@ -2563,7 +2601,7 @@ void ride_music_update_final()
|
||||
sub_401AF3(ebx, get_file_path(ride_music_info->pathid), 1, 0);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
}
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[ebx];
|
||||
rct_ride_music* ride_music = &gRideMusicList[ebx];//&RCT2_ADDRESS(0x009AF46C, rct_ride_music)[ebx];
|
||||
ride_music->volume = ride_music_params->volume;
|
||||
ride_music->pan = ride_music_params->pan;
|
||||
ride_music->freq = ride_music_params->freq;
|
||||
@@ -2574,27 +2612,40 @@ void ride_music_update_final()
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ride_music_params->volume != ride_music->volume) {
|
||||
ride_music->volume = ride_music_params->volume;
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Channel_Volume(ride_music->sound_channel, DStoMixerVolume(ride_music->volume));
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_volume(channel, ride_music_params->volume);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
}
|
||||
if (ride_music_params->pan != ride_music->pan) {
|
||||
ride_music->pan = ride_music_params->pan;
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Channel_Pan(ride_music->sound_channel, DStoMixerPan(ride_music->pan));
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_pan(channel, ride_music_params->pan);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
}
|
||||
if (ride_music_params->freq != ride_music->freq) {
|
||||
ride_music->freq = ride_music_params->freq;
|
||||
#ifdef USE_MIXER
|
||||
Mixer_Channel_Rate(ride_music->sound_channel, DStoMixerRate(ride_music->freq));
|
||||
#else
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_frequency(channel, ride_music_params->freq);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ static const rct_weather_transition* climate_transitions[4];
|
||||
// Sound data
|
||||
static int _rainVolume = 1;
|
||||
static rct_sound _rainSoundInstance;
|
||||
static void* _rainSoundChannel;
|
||||
static void* _rainSoundChannel = 0;
|
||||
static unsigned int _lightningTimer, _thunderTimer;
|
||||
static rct_sound _thunderSoundInstance[MAX_THUNDER_INSTANCES];
|
||||
static void* _thunderSoundChannels[MAX_THUNDER_INSTANCES];
|
||||
@@ -218,7 +218,9 @@ static void climate_update_rain_sound()
|
||||
if (_rainVolume == 1) {
|
||||
// Start playing the rain sound
|
||||
#ifdef USE_MIXER
|
||||
_rainSoundChannel = Mixer_Play_Effect(SOUND_RAIN_1, MIXER_LOOP_INFINITE, DStoMixerVolume(-4000), 0.5f, 1, 0);
|
||||
if (!_rainSoundChannel) {
|
||||
_rainSoundChannel = Mixer_Play_Effect(SOUND_RAIN_1, MIXER_LOOP_INFINITE, DStoMixerVolume(-4000), 0.5f, 1, 0);
|
||||
}
|
||||
#else
|
||||
if (sound_prepare(SOUND_RAIN_1, &_rainSoundInstance, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)))
|
||||
sound_play(&_rainSoundInstance, 1, -4000, 0, 0);
|
||||
@@ -250,6 +252,7 @@ static void climate_update_rain_sound()
|
||||
#ifdef USE_MIXER
|
||||
if (_rainSoundChannel) {
|
||||
Mixer_Stop_Channel(_rainSoundChannel);
|
||||
_rainSoundChannel = 0;
|
||||
}
|
||||
#else
|
||||
sound_stop(&_rainSoundInstance);
|
||||
|
||||
Reference in New Issue
Block a user