0
$\begingroup$

I have an audio audio001 and I need to export/import it so that I can do auto-correlation. Below I used AudioGenerator[{"Sin", 400}] as a simple example:

nbDir = NotebookDirectory[];
audio001 = AudioGenerator[{"Sin", 400}];
Export[StringJoin[nbDir, "audio001.mp3"], audio001];
simpleSampledList = Import[StringJoin[nbDir, "audio001.mp3"], "SampledSoundList"];
numSample1=AudioLength@audio001
numSample2=Dimensions@(simpleSampledList[[1]])

However, I got 44100 for numSample1 and 47232 for numSample2. Why are they different (it is more than 7% so it is a significant difference)? Since I am going to do auto-correlation and find out the period of the signal, I need to know whether I should use numSample1 or numSample2 in my calculation.

Many thanks!

$\endgroup$
  • $\begingroup$ I think MP3 doesn't support arbitrary lengths. The data needs to be padded to an integer multiple of some base length before it can be encoded in MP3. This is why "gapless playback" used to be such a big deal: if a contiguous audio file was split into two, and both encoded to MP3, there would be a glitch at the split boundary due to this padding. There are some informal standards to adding a tag to the MP3 and indicate how long the true data is, to allow gapless playback by players that understand this tag. $\endgroup$ – Szabolcs Aug 20 at 16:08
  • $\begingroup$ BTW if you do data analysis then maybe you should not apply lossy compression like MP3 to your data ... $\endgroup$ – Szabolcs Aug 20 at 16:11
  • $\begingroup$ Thanks! Now I used .wav format and the problem is solved. $\endgroup$ – H42 Aug 20 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.