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 "3dc.h"
|
||||||
#include "inline.h"
|
#include "inline.h"
|
||||||
//#include "smacker.h"
|
#include "bink.h"
|
||||||
#include "avp_menus.h"
|
#include "avp_menus.h"
|
||||||
#include "avp_intro.h"
|
#include "avp_intro.h"
|
||||||
extern int NormalFrameTime;
|
extern int NormalFrameTime;
|
||||||
|
@ -23,20 +23,22 @@ void Show_ARebellionGame(void);
|
||||||
void Show_AvPLogo(void);
|
void Show_AvPLogo(void);
|
||||||
extern void ShowSplashScreens(void);
|
extern void ShowSplashScreens(void);
|
||||||
extern void Show_WinnerScreen(void);
|
extern void Show_WinnerScreen(void);
|
||||||
extern void PlayBinkedFMV(char *filenamePtr);
|
|
||||||
extern void DrawMainMenusBackdrop(void);
|
extern void DrawMainMenusBackdrop(void);
|
||||||
extern void FadedScreen(int alpha);
|
extern void FadedScreen(int alpha);
|
||||||
|
|
||||||
void StartMenuMusic(void)
|
void StartMenuMusic(void)
|
||||||
{
|
{
|
||||||
|
StartMusicBink("FMVs/IntroSound.smk", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayMenuMusic(void)
|
void PlayMenuMusic(void)
|
||||||
{
|
{
|
||||||
|
PlayMusicBink(127);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndMenuMusic(void)
|
void EndMenuMusic(void)
|
||||||
{
|
{
|
||||||
|
EndMusicBink();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeWantAnIntro(void)
|
void WeWantAnIntro(void)
|
||||||
|
|
23
src/bink.c
23
src/bink.c
|
@ -280,13 +280,16 @@ static int DecodeAudioFrame(struct binkMovie* aMovie)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return 0 iff we have reached the end of file.
|
||||||
static int ReadPacket(struct binkMovie* aMovie)
|
static int ReadPacket(struct binkMovie* aMovie)
|
||||||
{
|
{
|
||||||
// Read from file if no packet is buffered.
|
// Read from file if no packet is buffered.
|
||||||
if (!aMovie->packet.buf && av_read_frame(aMovie->context, &aMovie->packet) < 0) {
|
if (!aMovie->packet.buf && av_read_frame(aMovie->context, &aMovie->packet) < 0) {
|
||||||
// No more packets in file.
|
// No more packets in file.
|
||||||
if (aMovie->looping) {
|
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);
|
return ReadPacket(aMovie);
|
||||||
} else {
|
} else {
|
||||||
// Drain buffered frames.
|
// Drain buffered frames.
|
||||||
|
@ -299,7 +302,7 @@ static int ReadPacket(struct binkMovie* aMovie)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the (possibly buffered) packet to decoder.
|
// Send the (possibly buffered) packet to decoder.
|
||||||
int ret = AVERROR(EAGAIN);
|
int ret = 0;
|
||||||
if (aMovie->packet.stream_index == aMovie->videoStream)
|
if (aMovie->packet.stream_index == aMovie->videoStream)
|
||||||
ret = avcodec_send_packet(aMovie->videoContext, &aMovie->packet);
|
ret = avcodec_send_packet(aMovie->videoContext, &aMovie->packet);
|
||||||
else if (aMovie->packet.stream_index == aMovie->audioStream)
|
else if (aMovie->packet.stream_index == aMovie->audioStream)
|
||||||
|
@ -349,7 +352,8 @@ static int BinkStartMovie(struct binkMovie* aMovie, const char* aFilename,
|
||||||
continue;
|
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->videoContext = context;
|
||||||
aMovie->videoStream = i;
|
aMovie->videoStream = i;
|
||||||
aMovie->videoFrame = av_frame_alloc();
|
aMovie->videoFrame = av_frame_alloc();
|
||||||
|
@ -478,18 +482,15 @@ int PlayMusicBink(int volume)
|
||||||
if (!musicMovie.context)
|
if (!musicMovie.context)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (musicMovie.audioStream < 0 || !musicMovie.alInited)
|
if (musicMovie.audioStream < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
alSourcef(musicMovie.alSource, AL_GAIN, PlatVolumeToGain(volume));
|
||||||
for (int i = 0; i < musicMovie.context->nb_streams * AUDIO_FRAMES; i++) {
|
if (BinkUpdateMovie(&musicMovie) >= 0) {
|
||||||
int processedBuffers = 0;
|
ProcessAudio(&musicMovie);
|
||||||
alGetSourcei(musicMovie.alSource, AL_BUFFERS_PROCESSED, &processedBuffers);
|
return 1;
|
||||||
if (processedBuffers + musicMovie.alNumFreeBuffers > 0)
|
|
||||||
if (!ReadPacket(&musicMovie))
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndMusicBink()
|
void EndMusicBink()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue