c++ - writing to a wav file using libsndfile -
i'm having trouble writing short buffer wav file on hd. followed few tutorials, give different ways of doing it. anyway, way implemented reason doesn't work. when try print out result of outfile
, 0
, , nothing written disk. also, tried different paths, , without file name.
update: when change path file name (e.g. hello.wav
, not ~/documents/hello.wav
), printing out outfile
returns memory location such 0x2194000
.
void gilbertanalysis::writewav(float * buffer, int buffersize){ sf_info sfinfo ; sfinfo.channels = 1; sfinfo.samplerate = 44100; sfinfo.format = sf_format_wav | sf_format_pcm_16; const char* path = "~/documents/hello.wav"; sndfile * outfile = sf_open(path, sfm_write, &sfinfo); sf_count_t count = sf_write_float(outfile, &buffer[0], buffersize) ; sf_write_sync(outfile); sf_close(outfile); }
from libsndfile docs:
on success, sf_open function returns non-null pointer should passed first parameter subsequent libsndfile calls dealing audio file. on fail, sf_open function returns null pointer. explanation of error can obtained passing null sf_strerror.
if outfile 0x2194000 , not null, opened file correctly.
try using sf_strerror() see error had when provided full file path , not file name.
Comments
Post a Comment