0
$\begingroup$

If I export a sound object export sound

and then I import the same sound

import

I have a different data array. The errors seem to have a certain regularity. They are all multiples of the same value:

errors

Why does it happen? How can I get the same data?

First of all, thank you for the answers.

The raw data are here.

The code is as follows:

datiU2 = Import["https://pastebin.com/raw/sWmUzT9a", "List"];
datiU3 = SetPrecision[datiU2*2^-15, 16];
S1 = Sound[ListPlay[datiU3, SampleRate -> 44100, SampleDepth -> 16, 
    PlayRange -> {-1, 1}]];
dataS1 = List @@ S1[[1]];
dataS1[[1]][[1, 1 ;; 10]]
SetPrecision[
Export["OKDC.wav", S1, "AudioEncoding" -> "Integer16"], 16];
S11 = SetPrecision[Import["OKDC.wav"], 16];
dataS11 = SetPrecision[List @@ S11[[1]], 16];
dataS11[[1]][[1, 1 ;; 10]]

I added the SetPrecision commands after the first post to make a further attempt. I tried with AudioEncoding-> Integer24 and it does not change anything.

The problem is in the conversion that Mathematica does in command Export because if I read in Python the file "OKDC.wav" exported from Mathematica I see the raw values integer16 and they are different from those calculated in previous code by

dataS1[[1]][[1, 1 ;; 10]]*2^15
$\endgroup$
1
  • 2
    $\begingroup$ Please post the raw data you are using on e.g. Pastebin. Also, please provide code that can be copied by other users; don't force them to retype your code just to help you. $\endgroup$ Mar 7, 2019 at 12:01

1 Answer 1

1
$\begingroup$

You specified that the data was to be saved at 16-bit resolution. This means the accuracy should be about 2^-16 overall. But since the audio is signed, you might expect half that. Observe that

2^-15//N 
0.0000305176

is just about the size mismatch you are encountering. You can decrease this by choosing to save at 24 or 32 bits, e.g., by specifying the option

"AudioEncoding" -> "Integer24"
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.