implement PlayFile function so campaigns play at right volume

This commit is contained in:
nehalmistry 2003-04-02 00:27:41 +00:00
parent 59ff9da854
commit 79e3e81076
5 changed files with 51 additions and 35 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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;