1 #define DR_WAV_IMPLEMENTATION
2 #include "../../dr_wav.h"
4 #include "../common/dr_common.c"
8 typedef SNDFILE* (* pfn_sf_open_virtual)(SF_VIRTUAL_IO* sfvirtual,
int mode, SF_INFO* sfinfo,
void* user_data);
11 typedef sf_count_t (*
pfn_sf_readf_int) (SNDFILE *sndfile,
int *ptr, sf_count_t frames);
14 typedef sf_count_t (*
pfn_sf_seek) (SNDFILE *sndfile, sf_count_t frames,
int whence);
27 const char* pFileNames[] = {
30 "libsndfile-1-x64.dll",
32 "libsndfile-1-x86.dll",
45 for (i = 0; i <
sizeof(pFileNames)/
sizeof(pFileNames[0]); i += 1) {
82 size_t fileSizeInBytes;
142 SF_VIRTUAL_IO callbacks;
144 if (pFilePath ==
NULL || pSndFile ==
NULL) {
174 if (pSndFile ==
NULL) {
184 if (pSndFile ==
NULL || pBufferOut ==
NULL) {
189 if ((pSndFile->
info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT) {
192 while (totalFramesRead < framesToRead) {
194 drwav_uint64 framesRemaining = framesToRead - totalFramesRead;
196 drwav_uint64 framesToReadThisIteration =
sizeof(temp)/
sizeof(temp[0]) / pSndFile->
info.channels;
197 if (framesToReadThisIteration > framesRemaining) {
198 framesToReadThisIteration = framesRemaining;
205 totalFramesRead += framesReadThisIteration;
206 pBufferOut += framesReadThisIteration*pSndFile->
info.channels;
209 if (framesReadThisIteration < framesToReadThisIteration) {
214 return totalFramesRead;
215 }
else if ((pSndFile->
info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_DOUBLE) {
218 while (totalFramesRead < framesToRead) {
220 drwav_uint64 framesRemaining = framesToRead - totalFramesRead;
222 drwav_uint64 framesToReadThisIteration =
sizeof(temp)/
sizeof(temp[0]) / pSndFile->
info.channels;
223 if (framesToReadThisIteration > framesRemaining) {
224 framesToReadThisIteration = framesRemaining;
231 totalFramesRead += framesReadThisIteration;
232 pBufferOut += framesReadThisIteration*pSndFile->
info.channels;
235 if (framesReadThisIteration < framesToReadThisIteration) {
240 return totalFramesRead;
248 if (pSndFile ==
NULL || pBufferOut ==
NULL) {
257 if (pSndFile ==
NULL || pBufferOut ==
NULL) {
262 if ((pSndFile->
info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT) {
265 while (totalFramesRead < framesToRead) {
267 drwav_uint64 framesRemaining = framesToRead - totalFramesRead;
269 drwav_uint64 framesToReadThisIteration =
sizeof(temp)/
sizeof(temp[0]) / pSndFile->
info.channels;
270 if (framesToReadThisIteration > framesRemaining) {
271 framesToReadThisIteration = framesRemaining;
278 totalFramesRead += framesReadThisIteration;
279 pBufferOut += framesReadThisIteration*pSndFile->
info.channels;
282 if (framesReadThisIteration < framesToReadThisIteration) {
287 return totalFramesRead;
288 }
else if ((pSndFile->
info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_DOUBLE) {
291 while (totalFramesRead < framesToRead) {
293 drwav_uint64 framesRemaining = framesToRead - totalFramesRead;
295 drwav_uint64 framesToReadThisIteration =
sizeof(temp)/
sizeof(temp[0]) / pSndFile->
info.channels;
296 if (framesToReadThisIteration > framesRemaining) {
297 framesToReadThisIteration = framesRemaining;
304 totalFramesRead += framesReadThisIteration;
305 pBufferOut += framesReadThisIteration*pSndFile->
info.channels;
308 if (framesReadThisIteration < framesToReadThisIteration) {
313 return totalFramesRead;
321 if (pSndFile ==
NULL) {
325 return libsndfile__sf_seek(pSndFile->
pHandle, (sf_count_t)targetPCMFrameIndex, SF_SEEK_SET) == (sf_count_t)targetPCMFrameIndex;