4
$\begingroup$

This question already has an answer here:

I use recorded data from an acquisition system in a wav file containing 6 channels, all data are encoded with 2 bytes in Integer 16. I can Import the *.wav data file and get all data in a Sound object within {-32768,32767} range. When I Export the same file in a wav file (using the same Sound object to store the data) and reopen it immediately using the same Import function, I have a discrepancy in the data: they are different from the initial data (with a scale factor and an offset). I suppose there existsome fancy option to keep the same amplitude normalization before and after record but a am a bit lost in the arcane of Export and Import function. Can anybody suggest a solution to read and record the same wav file unaltered?

u1 = Import["AcqDev_0_6ch[ai0to5]_2500kHz_ai_000.wav"];
Export["AcqDev_0_6ch[ai0to5]_2500kHz_ai_same_000.wav", u1]
u2 = Import["AcqDev_0_6ch[ai0to5]_2500kHz_ai_same_000.wav"];

Below the 100000 first samples shown for channel 1 extracted in the sound object u1 and u2

{u1[[1, 1, 1, ;; 100000]], u2[[1, 1, 1, ;; 100000]]} // ListPlot

enter image description here

And the relationship between the 2 sets of data: a linear scaling & offet:

Transpose@{u1[[1, 1, 1, ;; 100000]], u2[[1, 1, 1, ;; 100000]]} //ListPlot

enter image description here

$\endgroup$

marked as duplicate by Yves Klett, user9660, Community Jul 2 '16 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Christian, take a look at this previous discussion, which I think could apply to your situation as well: Audio export issues. $\endgroup$ – MarcoB Jul 1 '16 at 13:36
  • $\begingroup$ @MarcoB: thanks, the workaround you posted in Audio export issues worked well. $\endgroup$ – Christian Néel Jul 1 '16 at 15:19
6
$\begingroup$

As stated above, and based on MarcoB comments, I tested the workaround proposed by Simon Woods in Audio export issues, and it works:

u1 = Import["AcqDev_0_6ch[ai0to5]_2500kHz_ai_000.wav"];
Block[{Rescale = #1 &}, Export["AcqDev_0_6ch[ai0to5]_2500kHz_ai_rot000.wav", u1]]
u2 = Import["AcqDev_0_6ch[ai0to5]_2500kHz_ai_rot000.wav"];

Below are the first 100,000 samples (they are superimposed, so I added a 0.01 vertical offset to separate them on the graph):

{u1[[1, 1, 1, ;; 100000]], 0.01 + u2[[1, 1, 1, ;; 100000]]} // ListPlot

comparison with original and re-imported wave files

And the relationship between the two sets of data is now unitary:

Transpose@{u1[[1, 1, 1, ;; 100000]], u2[[1, 1, 1, ;; 100000]]} //ListPlot

relationship between the exported and re-imported data

$\endgroup$
  • $\begingroup$ Thank you for posting this followup! I owe you an upvote, but I'm fresh out of votes for today. I hope others will show you some love in the meantime (hint hint :-) $\endgroup$ – MarcoB Jul 1 '16 at 15:48
  • $\begingroup$ Missing upvote applied! $\endgroup$ – MarcoB Jul 3 '16 at 4:01

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