Browse Source

Apply sound volume to videos

pull/1164/head
Anders Jenbo 5 years ago
parent
commit
4eb1971ada
  1. 28
      SourceX/storm/storm.cpp

28
SourceX/storm/storm.cpp

@ -335,6 +335,8 @@ void setIniInt(const char *keyname, const char *valuename, int value)
double SVidFrameEnd; double SVidFrameEnd;
double SVidFrameLength; double SVidFrameLength;
char SVidAudioDepth;
double SVidVolume;
BYTE SVidLoop; BYTE SVidLoop;
smk SVidSMK; smk SVidSMK;
SDL_Color SVidPreviousPalette[256]; SDL_Color SVidPreviousPalette[256];
@ -492,8 +494,12 @@ void SVidPlayBegin(const char *filename, int a2, int a3, int a4, int a5, int fla
SDL_zero(audioFormat); SDL_zero(audioFormat);
audioFormat.freq = rate[0]; audioFormat.freq = rate[0];
audioFormat.format = depth[0] == 16 ? AUDIO_S16SYS : AUDIO_U8; audioFormat.format = depth[0] == 16 ? AUDIO_S16SYS : AUDIO_U8;
SVidAudioDepth = depth[0];
audioFormat.channels = channels[0]; audioFormat.channels = channels[0];
SVidVolume = sgOptions.Audio.nSoundVolume - VOLUME_MIN;
SVidVolume /= -VOLUME_MIN;
Mix_CloseAudio(); Mix_CloseAudio();
#if SDL_VERSION_ATLEAST(2, 0, 4) #if SDL_VERSION_ATLEAST(2, 0, 4)
@ -614,6 +620,21 @@ BOOL SVidLoadNextFrame()
return true; return true;
} }
unsigned char *SVidApplyVolume(const unsigned char *raw, unsigned long rawLen)
{
unsigned char *scaled = (unsigned char *)malloc(rawLen);
if (SVidAudioDepth == 16) {
for (unsigned long i = 0; i < rawLen / 2; i++)
((Sint16 *)scaled)[i] = ((Sint16 *)raw)[i] * SVidVolume;
} else {
for (unsigned long i = 0; i < rawLen; i++)
scaled[i] = raw[i] * SVidVolume;
}
return (unsigned char *)scaled;
}
BOOL SVidPlayContinue(void) BOOL SVidPlayContinue(void)
{ {
if (smk_palette_updated(SVidSMK)) { if (smk_palette_updated(SVidSMK)) {
@ -645,14 +666,17 @@ BOOL SVidPlayContinue(void)
} }
if (HaveAudio()) { if (HaveAudio()) {
unsigned long len = smk_get_audio_size(SVidSMK, 0);
unsigned char *audio = SVidApplyVolume(smk_get_audio(SVidSMK, 0), len);
#if SDL_VERSION_ATLEAST(2, 0, 4) #if SDL_VERSION_ATLEAST(2, 0, 4)
if (SDL_QueueAudio(deviceId, smk_get_audio(SVidSMK, 0), smk_get_audio_size(SVidSMK, 0)) <= -1) { if (SDL_QueueAudio(deviceId, audio, len) <= -1) {
SDL_Log(SDL_GetError()); SDL_Log(SDL_GetError());
return false; return false;
} }
#else #else
sVidAudioQueue->Enqueue(smk_get_audio(SVidSMK, 0), smk_get_audio_size(SVidSMK, 0)); sVidAudioQueue->Enqueue(audio, len);
#endif #endif
free(audio);
} }
if (SDL_GetTicks() * 1000 >= SVidFrameEnd) { if (SDL_GetTicks() * 1000 >= SVidFrameEnd) {

Loading…
Cancel
Save