adamstark/AudioFile

Set sample rate does not change number of samples

sahi1422 opened this issue · 2 comments

Changing the sample rate does not change the total number of samples, it changes the duration of audio instead.

Code

    AudioFile<double> audioFile;
    audioFile.load(inputAudioFile);
    cout << "Summary before changing sample rate\n";
    audioFile.printSummary();
    audioFile.setSampleRate(16000);
    cout << "\n\nSummary after changing sample rate\n";
    audioFile.printSummary();

Output

Summary before changing sample rate
|======================================|
Num Channels: 2
Num Samples Per Channel: 2880000
Sample Rate: 48000
Bit Depth: 16
Length in Seconds: 60
|======================================|


Summary after changing sample rate
|======================================|
Num Channels: 2
Num Samples Per Channel: 2880000
Sample Rate: 16000
Bit Depth: 16
Length in Seconds: 180
|======================================|

Expected behavior is that Num Samples Per Channel should get one third.

Hi there,

The behaviour of the library is correct - this is an audio file library, not a sample rate re-sampling library. The setSampleRate() function changes the sample rate that your audio file will interpret the samples at.

I would love to add re-sampling functionality to this, but it's a little down the road at the moment - it's on my list... :)

Thanks!
Adam

@adamstark , thanks for the update.