Skip to content

Commit

Permalink
wip: save timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Jul 19, 2023
1 parent b79954a commit 4518944
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/game/savegame/savegame_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info)

int16_t load_track = json_object_get_int(root_obj, "music_track", -1);

int32_t timestamp_arr[2];
int64_t timestamp_arr[2];
timestamp_arr[0] = json_object_get_int(root_obj, "music_timestamp1", -1);
timestamp_arr[1] = json_object_get_int(root_obj, "music_timestamp2", -1);
LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]);
Expand Down Expand Up @@ -1308,7 +1308,7 @@ void Savegame_BSON_SaveToFile(MYFILE *fp, GAME_INFO *game_info)
if (save_track) {
save_timestamp = Music_GetTimestamp(Music_CurrentTrack());
}
int *timestamp_arr = (int *)&save_timestamp;
int64_t *timestamp_arr = (int64_t *)&save_timestamp;
json_object_append_int(root_obj, "music_timestamp1", timestamp_arr[0]);
json_object_append_int(root_obj, "music_timestamp2", timestamp_arr[1]);
LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]);
Expand Down
8 changes: 7 additions & 1 deletion src/specific/s_audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,14 @@ int64_t S_Audio_StreamGetTimestamp(int sound_id)
LOG_DEBUG("Getting timestamp for sound_id %d.", sound_id);
SDL_LockAudioDevice(g_AudioDeviceID);
AUDIO_STREAM_SOUND *stream = &m_StreamSounds[sound_id];
return stream->av.frame->best_effort_timestamp;
int64_t timestamp = 0;
int ret = avcodec_receive_frame(stream->av.codec_ctx, stream->av.frame);
if (ret >= 0) {
timestamp = stream->av.frame->best_effort_timestamp;
}
SDL_UnlockAudioDevice(g_AudioDeviceID);
LOG_DEBUG("Timestamp: %d.", timestamp);
return timestamp;
}

return -1;
Expand Down

0 comments on commit 4518944

Please sign in to comment.