Implement music in menus
This commit is contained in:
parent
5b9a0e939c
commit
0fd40ff481
2 changed files with 16 additions and 13 deletions
|
@ -3,7 +3,7 @@ extern "C"
|
|||
{
|
||||
#include "3dc.h"
|
||||
#include "inline.h"
|
||||
//#include "smacker.h"
|
||||
#include "bink.h"
|
||||
#include "avp_menus.h"
|
||||
#include "avp_intro.h"
|
||||
extern int NormalFrameTime;
|
||||
|
@ -23,20 +23,22 @@ void Show_ARebellionGame(void);
|
|||
void Show_AvPLogo(void);
|
||||
extern void ShowSplashScreens(void);
|
||||
extern void Show_WinnerScreen(void);
|
||||
extern void PlayBinkedFMV(char *filenamePtr);
|
||||
extern void DrawMainMenusBackdrop(void);
|
||||
extern void FadedScreen(int alpha);
|
||||
|
||||
void StartMenuMusic(void)
|
||||
{
|
||||
StartMusicBink("FMVs/IntroSound.smk", true);
|
||||
}
|
||||
|
||||
void PlayMenuMusic(void)
|
||||
{
|
||||
PlayMusicBink(127);
|
||||
}
|
||||
|
||||
void EndMenuMusic(void)
|
||||
{
|
||||
EndMusicBink();
|
||||
}
|
||||
|
||||
void WeWantAnIntro(void)
|
||||
|
|
23
src/bink.c
23
src/bink.c
|
@ -280,13 +280,16 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Return 0 iff we have reached the end of file.
|
||||
static int ReadPacket(struct binkMovie* aMovie)
|
||||
{
|
||||
// Read from file if no packet is buffered.
|
||||
if (!aMovie->packet.buf && av_read_frame(aMovie->context, &aMovie->packet) < 0) {
|
||||
// No more packets in file.
|
||||
if (aMovie->looping) {
|
||||
av_seek_frame(aMovie->context, -1, 0, 0);
|
||||
// This needs ffmpeg≥4.4 to work for smacker files.
|
||||
if (avformat_seek_file(aMovie->context, -1, 0, 0, 0, 0) < 0)
|
||||
return 0;
|
||||
return ReadPacket(aMovie);
|
||||
} else {
|
||||
// Drain buffered frames.
|
||||
|
@ -299,7 +302,7 @@ static int ReadPacket(struct binkMovie* aMovie)
|
|||
}
|
||||
|
||||
// Send the (possibly buffered) packet to decoder.
|
||||
int ret = AVERROR(EAGAIN);
|
||||
int ret = 0;
|
||||
if (aMovie->packet.stream_index == aMovie->videoStream)
|
||||
ret = avcodec_send_packet(aMovie->videoContext, &aMovie->packet);
|
||||
else if (aMovie->packet.stream_index == aMovie->audioStream)
|
||||
|
@ -349,7 +352,8 @@ static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (aMovie->videoStream < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
// Music files may contain a video stream, we just ignore it.
|
||||
if (!aMusicFlag && aMovie->videoStream < 0 && context->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
aMovie->videoContext = context;
|
||||
aMovie->videoStream = i;
|
||||
aMovie->videoFrame = av_frame_alloc();
|
||||
|
@ -478,19 +482,16 @@ int PlayMusicBink(int volume)
|
|||
if (!musicMovie.context)
|
||||
return 1;
|
||||
|
||||
if (musicMovie.audioStream < 0 || !musicMovie.alInited)
|
||||
if (musicMovie.audioStream < 0)
|
||||
return 1;
|
||||
|
||||
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
||||
for (int i = 0; i < musicMovie.context->nb_streams * AUDIO_FRAMES; i++) {
|
||||
int processedBuffers = 0;
|
||||
alGetSourcei(musicMovie.alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
||||
if (processedBuffers + musicMovie.alNumFreeBuffers > 0)
|
||||
if (!ReadPacket(&musicMovie))
|
||||
return 0;
|
||||
}
|
||||
if (BinkUpdateMovie(&musicMovie) >= 0) {
|
||||
ProcessAudio(&musicMovie);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EndMusicBink()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue