fix audio saving being totally wrong

This commit is contained in:
tildearrow 2022-06-28 22:08:24 -05:00
parent be933b2d2c
commit 8c8ad7f5ab
2 changed files with 13 additions and 2 deletions

View file

@ -19,6 +19,7 @@
#include "sfWrapper.h" #include "sfWrapper.h"
#include "../fileutils.h" #include "../fileutils.h"
#include "sndfile.h"
sf_count_t _vioGetSize(void* user) { sf_count_t _vioGetSize(void* user) {
return ((SFWrapper*)user)->ioGetSize(); return ((SFWrapper*)user)->ioGetSize();
@ -41,7 +42,14 @@ sf_count_t _vioTell(void* user) {
} }
sf_count_t SFWrapper::ioGetSize() { sf_count_t SFWrapper::ioGetSize() {
return (sf_count_t)len; sf_count_t ret=(sf_count_t)len;
if (fileMode==SFM_WRITE || fileMode==SFM_RDWR) {
ssize_t lastTell=ftell(f);
fseek(f,0,SEEK_END);
ret=(sf_count_t)ftell(f);
fseek(f,lastTell,SEEK_SET);
}
return ret;
} }
sf_count_t SFWrapper::ioSeek(sf_count_t offset, int whence) { sf_count_t SFWrapper::ioSeek(sf_count_t offset, int whence) {
@ -108,5 +116,6 @@ SNDFILE* SFWrapper::doOpen(const char* path, int mode, SF_INFO* sfinfo) {
} }
sf=sf_open_virtual(&vio,mode,sfinfo,this); sf=sf_open_virtual(&vio,mode,sfinfo,this);
if (sf!=NULL) fileMode=mode;
return sf; return sf;
} }

View file

@ -35,6 +35,7 @@ class SFWrapper {
size_t len; size_t len;
SF_VIRTUAL_IO vio; SF_VIRTUAL_IO vio;
SNDFILE* sf; SNDFILE* sf;
int fileMode;
public: public:
sf_count_t ioGetSize(); sf_count_t ioGetSize();
@ -48,7 +49,8 @@ class SFWrapper {
SFWrapper(): SFWrapper():
f(NULL), f(NULL),
len(0), len(0),
sf(NULL) {} sf(NULL),
fileMode(0) {}
}; };
#endif #endif