- File operations work on "data/" folder or ".jrf" file
- [NEW] fopenres() works on .jrf resources, fopen on normal files
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "stb_vorbis.c"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include "jfile.h"
|
||||
|
||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
||||
|
||||
@@ -90,7 +91,11 @@ JA_Music JA_LoadMusic(const char* filename) {
|
||||
int chan, samplerate;
|
||||
JA_Music music = new JA_Music_t();
|
||||
|
||||
int fsize;
|
||||
Uint8 *buffer = (Uint8*)file_getfilebuffer(filename, fsize);
|
||||
|
||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||
/*
|
||||
FILE *f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
long fsize = ftell(f);
|
||||
@@ -98,6 +103,7 @@ JA_Music JA_LoadMusic(const char* filename) {
|
||||
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
|
||||
fread(buffer, fsize, 1, f);
|
||||
fclose(f);
|
||||
*/
|
||||
|
||||
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
||||
free(buffer);
|
||||
@@ -168,7 +174,12 @@ JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) {
|
||||
JA_Sound JA_LoadSound(const char* filename) {
|
||||
JA_Sound sound = new JA_Sound_t();
|
||||
SDL_AudioSpec wavSpec;
|
||||
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
|
||||
|
||||
//SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
|
||||
int size;
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size),1, &wavSpec, &sound->buffer, &sound->length);
|
||||
free(buffer);
|
||||
|
||||
SDL_AudioCVT cvt;
|
||||
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||
|
||||
Reference in New Issue
Block a user