Use setvbuf with a 128KiB buffer instead of setbuf (#1)

This commit is contained in:
Maschell 2021-01-01 01:32:17 +01:00 committed by GitHub
parent 4dd847d367
commit 1802fcffa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -83,14 +83,14 @@ public:
{
memset(&m_soundInfo, 0, sizeof(m_soundInfo));
m_buffer = (char*) memalign(0x40, BUFSIZ);
m_buffer = (char*) memalign(0x40, IO_BUFFER_SIZE);
m_fileHandle = fopen(path, "rb");
if (!m_fileHandle) {
return;
}
setbuf(m_fileHandle, m_buffer);
setvbuf(m_fileHandle, m_buffer, _IOFBF, IO_BUFFER_SIZE);
m_pfSound = sf_open_virtual(&vio, SFM_READ, &m_soundInfo, m_fileHandle);
}
@ -177,14 +177,14 @@ public:
{
memset(&m_drWav, 0, sizeof(m_drWav));
m_buffer = (char*) memalign(0x40, BUFSIZ);
m_buffer = (char*) memalign(0x40, IO_BUFFER_SIZE);
m_fileHandle = fopen(path, "rb");
if (!m_fileHandle) {
return;
}
setbuf(m_fileHandle, m_buffer);
setvbuf(m_fileHandle, m_buffer, _IOFBF, IO_BUFFER_SIZE);
if( !drwav_init(&m_drWav, drwav_read_replacement, drwav_seek_replacement, m_fileHandle, NULL) ) {
return;
@ -300,7 +300,7 @@ public:
int channels = 0;
int encoding = 0;
m_buffer = (char*) memalign(0x40, BUFSIZ);
m_buffer = (char*) memalign(0x40, IO_BUFFER_SIZE);
m_fileHandle = fopen(path, "rb");
if (!m_fileHandle) {
@ -308,7 +308,7 @@ public:
return;
}
setbuf(m_fileHandle, m_buffer);
setvbuf(m_fileHandle, m_buffer, _IOFBF, IO_BUFFER_SIZE);
m_bOpened = mpg123_replace_reader_handle(m_pMH, mpg123_read_replacement, mpg123_seek_replacement, NULL) == MPG123_OK
&& mpg123_open_handle(m_pMH, m_fileHandle) == MPG123_OK

View File

@ -91,8 +91,8 @@ found:
if(myfiles[fd].file == nil)
return 0;
#ifdef BUFFER
myfiles[fd].buf = (char*) memalign(0x40, BUFSIZ);
setbuf(myfiles[fd].file, myfiles[fd].buf);
myfiles[fd].buf = (char*) memalign(0x40, IO_BUFFER_SIZE);
setvbuf(myfiles[fd].file, myfiles[fd].buf, _IOFBF, IO_BUFFER_SIZE);
#endif
return fd;
}

View File

@ -135,6 +135,8 @@ enum Config {
NUM_EXPLOSIONS = 48,
};
#define IO_BUFFER_SIZE 128*1024
// We don't expect to compile for PS2 or Xbox
// but it might be interesting for documentation purposes
#define GTA_PC