mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
Inlined some common stuff for speed.
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@4 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
8cc4d7d934
commit
b3633585e1
@ -100,7 +100,7 @@ VGMSTREAM * init_vgmstream_adx(const char * const filename) {
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].streamfile = open_streamfile(filename);
|
||||
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,18*0x400);
|
||||
if (!vgmstream->ch[i].streamfile) goto fail;
|
||||
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
@ -149,4 +149,3 @@ void decode_adx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
|
||||
stream->adpcm_history1_32 = hist1;
|
||||
stream->adpcm_history2_32 = hist2;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "interleave.h"
|
||||
#include "adx.h"
|
||||
|
||||
void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
|
||||
int samples_written=0;
|
||||
|
@ -39,15 +39,8 @@ void close_streamfile(STREAMFILE * streamfile) {
|
||||
free(streamfile);
|
||||
}
|
||||
|
||||
size_t read_streamfile(uint8_t * dest, off_t offset, size_t length, STREAMFILE * streamfile) {
|
||||
size_t read_the_rest(uint8_t * dest, off_t offset, size_t length, STREAMFILE * streamfile) {
|
||||
size_t length_read_total=0;
|
||||
if (!streamfile || !dest || length<=0) return 0;
|
||||
|
||||
/* if entire request is within the buffer */
|
||||
if (offset >= streamfile->offset && offset+length <= streamfile->offset+streamfile->validsize) {
|
||||
memcpy(dest,streamfile->buffer+(offset-streamfile->offset),length);
|
||||
return length;
|
||||
}
|
||||
|
||||
/* is the beginning at least there? */
|
||||
if (offset >= streamfile->offset && offset < streamfile->offset+streamfile->validsize) {
|
||||
@ -107,35 +100,3 @@ size_t get_streamfile_size(STREAMFILE * streamfile) {
|
||||
fseeko(streamfile->infile,0,SEEK_END);
|
||||
return ftello(streamfile->infile);
|
||||
}
|
||||
|
||||
int16_t read_16bitLE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[2];
|
||||
|
||||
if (read_streamfile(buf,offset,2,streamfile)!=2) return -1;
|
||||
return get_16bitLE(buf);
|
||||
}
|
||||
int16_t read_16bitBE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[2];
|
||||
|
||||
if (read_streamfile(buf,offset,2,streamfile)!=2) return -1;
|
||||
return get_16bitBE(buf);
|
||||
}
|
||||
int32_t read_32bitLE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[4];
|
||||
|
||||
if (read_streamfile(buf,offset,4,streamfile)!=4) return -1;
|
||||
return get_32bitLE(buf);
|
||||
}
|
||||
int32_t read_32bitBE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[4];
|
||||
|
||||
if (read_streamfile(buf,offset,4,streamfile)!=4) return -1;
|
||||
return get_32bitBE(buf);
|
||||
}
|
||||
|
||||
int8_t read_8bit(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[1];
|
||||
|
||||
if (read_streamfile(buf,offset,1,streamfile)!=1) return -1;
|
||||
return buf[0];
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
#include "streamtypes.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifndef _STREAMFILE_H
|
||||
#define _STREAMFILE_H
|
||||
@ -36,11 +37,24 @@ STREAMFILE * open_streamfile_buffer(const char * const filename, size_t buffersi
|
||||
/* close a file, destroy the STREAMFILE object */
|
||||
void close_streamfile(STREAMFILE * streamfile);
|
||||
|
||||
/* */
|
||||
size_t read_the_rest(uint8_t * dest, off_t offset, size_t length, STREAMFILE * streamfile);
|
||||
|
||||
/* read from a file
|
||||
*
|
||||
* returns number of bytes read
|
||||
*/
|
||||
size_t read_streamfile(uint8_t * dest, off_t offset, size_t length, STREAMFILE * streamfile);
|
||||
static inline size_t read_streamfile(uint8_t * dest, off_t offset, size_t length, STREAMFILE * streamfile) {
|
||||
if (!streamfile || !dest || length<=0) return 0;
|
||||
|
||||
/* if entire request is within the buffer */
|
||||
if (offset >= streamfile->offset && offset+length <= streamfile->offset+streamfile->validsize) {
|
||||
memcpy(dest,streamfile->buffer+(offset-streamfile->offset),length);
|
||||
return length;
|
||||
}
|
||||
|
||||
return read_the_rest(dest,offset,length,streamfile);
|
||||
}
|
||||
|
||||
/* return file size */
|
||||
size_t get_streamfile_size(STREAMFILE * streamfile);
|
||||
@ -48,10 +62,36 @@ size_t get_streamfile_size(STREAMFILE * streamfile);
|
||||
/* Sometimes you just need an int, and we're doing the buffering.
|
||||
* Note, however, that if these fail to read they'll return -1,
|
||||
* so that should not be a valid value or there should be some backup. */
|
||||
int16_t read_16bitLE(off_t offset, STREAMFILE * streamfile);
|
||||
int16_t read_16bitBE(off_t offset, STREAMFILE * streamfile);
|
||||
int32_t read_32bitLE(off_t offset, STREAMFILE * streamfile);
|
||||
int32_t read_32bitBE(off_t offset, STREAMFILE * streamfile);
|
||||
int8_t read_8bit(off_t offset, STREAMFILE * streamfile);
|
||||
static inline int16_t read_16bitLE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[2];
|
||||
|
||||
if (read_streamfile(buf,offset,2,streamfile)!=2) return -1;
|
||||
return get_16bitLE(buf);
|
||||
}
|
||||
static inline int16_t read_16bitBE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[2];
|
||||
|
||||
if (read_streamfile(buf,offset,2,streamfile)!=2) return -1;
|
||||
return get_16bitBE(buf);
|
||||
}
|
||||
static inline int32_t read_32bitLE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[4];
|
||||
|
||||
if (read_streamfile(buf,offset,4,streamfile)!=4) return -1;
|
||||
return get_32bitLE(buf);
|
||||
}
|
||||
static inline int32_t read_32bitBE(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[4];
|
||||
|
||||
if (read_streamfile(buf,offset,4,streamfile)!=4) return -1;
|
||||
return get_32bitBE(buf);
|
||||
}
|
||||
|
||||
static inline int8_t read_8bit(off_t offset, STREAMFILE * streamfile) {
|
||||
uint8_t buf[1];
|
||||
|
||||
if (read_streamfile(buf,offset,1,streamfile)!=1) return -1;
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -26,13 +26,16 @@ static inline int32_t get_32bitLE(uint8_t * p) {
|
||||
}
|
||||
|
||||
/* signed nibbles come up a lot */
|
||||
static int nibble_to_int[16] = {0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1};
|
||||
|
||||
static inline int get_high_nibble_signed(int n) {
|
||||
return ((n&0x70)-(n&0x80))>>4;
|
||||
/*return ((n&0x70)-(n&0x80))>>4;*/
|
||||
return nibble_to_int[n>>4];
|
||||
}
|
||||
|
||||
static inline int get_low_nibble_signed(int n) {
|
||||
return (n&7)-(n&8);
|
||||
/*return (n&7)-(n&8);*/
|
||||
return nibble_to_int[n&0xf];
|
||||
}
|
||||
|
||||
/* return true for a good sample rate */
|
||||
@ -43,7 +46,7 @@ int check_sample_rate(int32_t sr);
|
||||
*/
|
||||
const char * filename_extension(const char * filename);
|
||||
|
||||
static inline int16_t clamp16(int32_t val) {
|
||||
static inline int clamp16(int32_t val) {
|
||||
if (val>32767) return 32767;
|
||||
if (val<-32768) return -32768;
|
||||
return val;
|
||||
|
@ -1,4 +1,4 @@
|
||||
CFLAGS=-lm
|
||||
CFLAGS=-lm -O3
|
||||
|
||||
test: test.c ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/fmt/adx.c ../src/fmt/interleave.c
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user