MCPcopy Create free account
hub / github.com/Audio4Linux/JDSP4Linux / loadAudioFile

Function loadAudioFile

libjamesdsp/JdspImpResToolbox.c:301–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299 }
300}
301float* loadAudioFile(const char *filename, double targetFs, unsigned int *channels, drwav_uint64 *totalPCMFrameCount, int resampleQuality)
302{
303 unsigned int fs = 1;
304 const char *ext = get_filename_ext(filename);
305 float *pSampleData = 0;
306 if (!strncmp(ext, "wav", 5) || !strncmp(ext, "irs", 5))
307 pSampleData = drwav_open_file_and_read_pcm_frames_f32(filename, channels, &fs, totalPCMFrameCount, 0);
308 if (!strncmp(ext, "flac", 5))
309 pSampleData = drflac_open_file_and_read_pcm_frames_f32(filename, channels, &fs, totalPCMFrameCount, 0);
310 /*if (!strncmp(ext, "mp3", 5))
311 {
312 drmp3_config mp3Conf;
313 pSampleData = drmp3_open_file_and_read_pcm_frames_f32(filename, &mp3Conf, totalPCMFrameCount, 0);
314 *channels = mp3Conf.channels;
315 fs = mp3Conf.sampleRate;
316 }*/
317 if (pSampleData == NULL)
318 {
319 printf("Error opening and reading WAV file");
320 return 0;
321 }
322 // Sanity check
323 if (*channels < 1)
324 {
325 printf("Invalid audio channels count");
326 free(pSampleData);
327 return 0;
328 }
329 if ((*totalPCMFrameCount <= 0) || (*totalPCMFrameCount <= 0))
330 {
331 printf("Invalid audio sample rate / frame count");
332 free(pSampleData);
333 return 0;
334 }
335 double ratio = targetFs / (double)fs;
336 if (ratio != 1.0)
337 {
338 int compressedLen = (int)ceil(*totalPCMFrameCount * ratio);
339 float *tmpBuf = (float*)malloc(compressedLen * *channels * sizeof(float));
340 memset(tmpBuf, 0, compressedLen * *channels * sizeof(float));
341 JamesDSPOfflineResampling(pSampleData, tmpBuf, *totalPCMFrameCount, compressedLen, *channels, ratio, resampleQuality);
342 *totalPCMFrameCount = compressedLen;
343 free(pSampleData);
344 return tmpBuf;
345 }
346 return pSampleData;
347}
348
349float* ReadImpulseResponseToFloat
350(const char* mIRFileName, int targetSampleRate, int* jImpInfo, int convMode, int* javaAdvSetPtr)

Callers 1

Calls 5

get_filename_extFunction · 0.70
ceilFunction · 0.50

Tested by

no test coverage detected