# Loss of scale factor when reading/recording/rereading data in a WAV file [duplicate]

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


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


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

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

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


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

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


• 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 :-) – MarcoB Jul 1 '16 at 15:48
• Missing upvote applied! – MarcoB Jul 3 '16 at 4:01