Skip to content

Commit

Permalink
sfx: use POSIX I/O functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Jul 19, 2020
1 parent 7a93f44 commit 2d6e4e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ void guiIntroLoop(void)
// Start playing sound
sfxPlay(SFX_BOOT);
// Calculate transition delay
tFadeDelayEnd = clock() + (sfxGetSoundDuration(SFX_BOOT) - fadeDuration) * CLOCKS_PER_SEC / 1000;
tFadeDelayEnd = clock() + (sfxGetSoundDuration(SFX_BOOT) - fadeDuration) * (CLOCKS_PER_SEC / 1000);
}

if (gInitComplete && clock() >= tFadeDelayEnd)
Expand Down
17 changes: 8 additions & 9 deletions src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,30 @@ static int sfx_initialized = 0;
//Returns 0 if the specified file was read. The sfxEffect structure will not be updated unless the file is successfully read.
static int sfxRead(const char *full_path, struct sfxEffect *sfx)
{
FILE *adpcm;
int adpcm;
void *buffer;
int ret, size;

LOG("SFX: sfxRead('%s')\n", full_path);

adpcm = fopen(full_path, "rb");
if (adpcm == NULL) {
adpcm = open(full_path, O_RDONLY);
if (adpcm < 0) {
LOG("SFX: %s: Failed to open adpcm file %s\n", __FUNCTION__, full_path);
return -ENOENT;
}

fseek(adpcm, 0, SEEK_END);
size = ftell(adpcm);
rewind(adpcm);
size = lseek(adpcm, 0, SEEK_END);
lseek(adpcm, 0L, SEEK_SET);

buffer = memalign(64, size);
if (buffer == NULL) {
LOG("SFX: Failed to allocate memory for SFX\n");
fclose(adpcm);
close(adpcm);
return -ENOMEM;
}

ret = fread(buffer, 1, size, adpcm);
fclose(adpcm);
ret = read(adpcm, buffer, size);
close(adpcm);

if (ret != size) {
LOG("SFX: Failed to read SFX: %d (expected %d)\n", ret, size);
Expand Down

0 comments on commit 2d6e4e0

Please sign in to comment.