diff --git a/src/game/intro.cpp b/src/game/intro.cpp index ff16d3f01..353aaca43 100644 --- a/src/game/intro.cpp +++ b/src/game/intro.cpp @@ -385,6 +385,8 @@ global void ShowIntro(const Intro *intro) TextLines* scrolling_text; TextLines* objectives_text[MAX_OBJECTIVES]; int old_video_sync; + int soundfree; + int soundout; UseContinueButton=1; InitContinueButton(455*VideoWidth/640,440*VideoHeight/480); @@ -437,7 +439,11 @@ global void ShowIntro(const Intro *intro) #ifdef WITH_SOUND PlaySectionMusic(PlaySectionBriefing); #endif - if( intro->VoiceFile[0] ) { + soundfree = -1; + soundout = -1; + if ( intro->VoiceFile[0] ) { + soundfree = NextFreeChannel; + soundout = NextSoundRequestOut; PlayFile(intro->VoiceFile[0]); } @@ -456,8 +462,10 @@ global void ShowIntro(const Intro *intro) IntroNoEvent=1; c=0; while( 1 ) { - if( !PlayingMusic && stage<MAX_BRIEFING_VOICES && - intro->VoiceFile[stage] ) { + if( (!Channels[soundfree].Command) && stage<MAX_BRIEFING_VOICES && + (soundout != NextSoundRequestOut) && intro->VoiceFile[stage] ) { + soundfree = NextFreeChannel; + soundout = NextSoundRequestOut; PlayFile(intro->VoiceFile[stage]); ++stage; } diff --git a/src/include/sound.h b/src/include/sound.h index 5528e2495..d2b1014a0 100644 --- a/src/include/sound.h +++ b/src/include/sound.h @@ -159,7 +159,7 @@ extern void InitSoundClient(void); extern void PlaySectionMusic(PlaySectionType section); /// Play a sample file -extern void PlayFile(const char* name); +extern void PlayFile(char* name); /// Play a music file extern void PlayMusic(const char* name); /// Stop music playing diff --git a/src/include/sound_server.h b/src/include/sound_server.h index d9aeb1e43..667d0d764 100644 --- a/src/include/sound_server.h +++ b/src/include/sound_server.h @@ -187,6 +187,21 @@ typedef struct _sound_request { #define MAX_SOUND_REQUESTS 32 /// maximal number of sound requests +#define MaxChannels 16 /// How many channels are supported + + /// Channels for sound effects and unit speach +typedef struct _sound_channel_ +{ + unsigned char Command; /// channel command + int Point; /// point into sample + Sample* Sample; /// sample to play + Origin Source; /// unit playing + unsigned char Volume; /// Volume of this channel + SoundId Sound; /// The sound currently played + /// stereo location of sound (-128 left, 0 center, 127 right) + signed char Stereo; +} SoundChannel; + /** ** Play audio flags. */ @@ -219,6 +234,14 @@ extern int NextSoundRequestIn; /// FIFO index out extern int NextSoundRequestOut; +#define ChannelFree 0 /// channel is free +#define ChannelPlay 3 /// channel is playing + + /// All possible sound channels +extern SoundChannel Channels[MaxChannels]; + /// Next free channel +extern int NextFreeChannel; + #ifdef USE_THREAD /// are we using a sound thread? (default is zero -> no thread) extern int WithSoundThread; diff --git a/src/sound/music.cpp b/src/sound/music.cpp index 2c812f6e9..4297c93ff 100644 --- a/src/sound/music.cpp +++ b/src/sound/music.cpp @@ -608,15 +608,19 @@ global void PlayMusic(const char* name) /** ** Play a sound file. ** -** Currenly a synomy for PlayMusi +** Currenly a synonym for PlayMusic ** ** @param name Name of sound file, format is automatic detected. -** Names starting with ':' control the cdrom. */ -global void PlayFile(const char* name) +global void PlayFile(char* name) { - MusicOff = 0; - PlayMusic(name); + SoundId id; + if (SoundIdForName("dynamic-sound")) { + id = RegisterSound(&name, 1); + } else { + id = MakeSound("dynamic-sound", &name, 1); + } + PlayGameSound(id, MaxSampleVolume); } #endif // } WITH_SOUND diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp index f9a1f7fb1..374e8c1ab 100644 --- a/src/sound/sound_server.cpp +++ b/src/sound/sound_server.cpp @@ -347,31 +347,6 @@ local int MixSampleToStereo32(Sample* sample,int index,unsigned char volume, return ri; } -/*---------------------------------------------------------------------------- --- Channels and other internal variables -----------------------------------------------------------------------------*/ - -#define MaxChannels 16 /// How many channels are supported - - /// Channels for sound effects and unit speach -typedef struct _sound_channel_ -{ - unsigned char Command; /// channel command - int Point; /// point into sample - Sample* Sample; /// sample to play - Origin Source; /// unit playing - unsigned char Volume; /// Volume of this channel - SoundId Sound; /// The sound currently played - /// stereo location of sound (-128 left, 0 center, 127 right) - signed char Stereo; -} SoundChannel; - -#define ChannelFree 0 /// channel is free -#define ChannelPlay 3 /// channel is playing - -/* -** All possible sound channels. -*/ global SoundChannel Channels[MaxChannels]; global int NextFreeChannel; @@ -815,7 +790,13 @@ local Sample* LoadSample(const char* name) Sample* sample; char* buf; - buf = strdcat3(FreeCraftLibPath, "/sounds/", name); + // FIXME: find a better way to detect sound not in sound dir + if (strstr(name, "campaign")) { + buf = strdcat3(FreeCraftLibPath, "/", name); + } else { + buf = strdcat3(FreeCraftLibPath, "/sounds/", name); + } + if ((sample = LoadWav(buf, PlayAudioLoadInMemory))) { free(buf); return sample;