Skip to content

Commit

Permalink
Added random changing music track fix from VC PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
Northfear committed Dec 23, 2023
1 parent 62880e4 commit 379721e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 12 additions & 8 deletions common/soundio_openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum
TIMER_TARGET_RESOLUTION = 10, // 10-millisecond target resolution
INVALID_AUDIO_HANDLE = -1,
INVALID_FILE_HANDLE = -1,
OPENAL_BUFFER_COUNT = 2,
OPENAL_BUFFER_COUNT = 3,
};

/*
Expand Down Expand Up @@ -683,7 +683,7 @@ void Maintenance_Callback()
// Work out if we have any space to buffer more data right now.
alGetSourcei(st->OpenALSource, AL_BUFFERS_PROCESSED, &processed_buffers);

while (processed_buffers > 0 && st->MoreSource) {
while (processed_buffers > 0) {
int bytes_copied = Sample_Copy(st,
&st->Source,
&st->Remainder,
Expand All @@ -695,23 +695,27 @@ void Maintenance_Callback()
nullptr,
nullptr);

if (bytes_copied != BUFFER_CHUNK_SIZE) {
st->MoreSource = false;
}

if (bytes_copied > 0) {
ALuint buffer;
alSourceUnqueueBuffers(st->OpenALSource, 1, &buffer);
alBufferData(buffer, st->Format, ChunkBuffer, bytes_copied, st->Frequency);
alSourceQueueBuffers(st->OpenALSource, 1, &buffer);
--processed_buffers;
}

if (bytes_copied != BUFFER_CHUNK_SIZE && st->FilePending == 0) {
st->MoreSource = false;
}

if (bytes_copied != BUFFER_CHUNK_SIZE) {
break;
}
}
} else {
ALint source_status;
alGetSourcei(st->OpenALSource, AL_SOURCE_STATE, &source_status);

if (source_status != AL_PLAYING) {
if (source_status != AL_PLAYING && source_status != AL_PAUSED) {
st->Service = 0;
Stop_Sample(i);
}
Expand Down Expand Up @@ -982,7 +986,7 @@ bool Sample_Status(int index)
ALint val;
alGetSourcei(st->OpenALSource, AL_SOURCE_STATE, &val);

return val == AL_PLAYING;
return val == AL_PLAYING || val == AL_PAUSED;
};

bool Is_Sample_Playing(const void* sample)
Expand Down
9 changes: 7 additions & 2 deletions tiberiandawn/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ void Choose_Side(void)
VQAHandle *gdibrief = 0, *nodbrief = 0;
void const *staticaud, *oldfont;
void const *speechg, *speechn, *speech;
int statichandle, speechhandle, speechplaying = 0;
int statichandle, speechhandle, speechplaying, speechduration = 0;
int oldfontxspacing = FontXSpacing;
int setpalette = 0;
int gdi_start_palette;
int scale_factor = Get_Resolution_Factor() + 1;
CountDownTimerClass speechtimer;

TextPrintBuffer = new GraphicBufferClass(SeenBuff.Get_Width(), SeenBuff.Get_Height(), (void*)NULL);
TextPrintBuffer->Clear();
Expand Down Expand Up @@ -182,7 +183,7 @@ void Choose_Side(void)
while (Get_Mouse_State())
Show_Mouse();

while (endframe != frame || (speechplaying && Is_Sample_Playing(speech))) {
while (endframe != frame || (speechplaying && speechtimer.Time() != 0)) {
Animate_Frame(anim, SysMemPage, frame++);
if (setpalette) {
Wait_Vert_Blank();
Expand Down Expand Up @@ -221,6 +222,7 @@ void Choose_Side(void)
Whom = HOUSE_GOOD;
ScenPlayer = SCEN_PLAYER_GDI;
endframe = 0;
speechduration = Sample_Length(speechg);
speechhandle = Play_Sample(speechg);
speechplaying = true;
speech = speechg;
Expand All @@ -230,10 +232,13 @@ void Choose_Side(void)
endframe = 14;
Whom = HOUSE_BAD;
ScenPlayer = SCEN_PLAYER_NOD;
speechduration = Sample_Length(speechn);
speechhandle = Play_Sample(speechn);
speechplaying = true;
speech = speechn;
}

speechtimer.Set(speechduration);
}
}
}
Expand Down

0 comments on commit 379721e

Please sign in to comment.