Summary of the problem: When exporting data as an audio file (AIFF/WAV etc.), there appears to be unwanted scaling and offset in the data such that the minimum and maximum values are forced to be -1 and +1. This issue has been tested with AIFFs and WAVs on Mathematica versions 10.1 and 10.2. This issue is not observed when exporting the data as a MAT file for example, nor does it exist when exporting as an AIFF/WAV in Mathematica

Generating a sample waveform

fS = 44100;
n = Range[0, fS/2];
sampleWaveForm = Sin[2 Pi 1/fS n];

Plotting it

ListPlot[sampleWaveForm, Joined -> True, PlotRange -> All]

enter image description here

Exporting it as an AIFF

Export["/Users/username/Desktop/sampleWaveForm.aiff", Sound[SampledSoundList[sampleWaveForm, fS]], "AudioEncoding" -> "Integer24"];

Importing it as is

importedWaveForm = Import["/Users/username/Desktop/sampleWaveForm.aiff", "AIFF", "AudioEncoding" -> "Integer24"][[1, 1, 1]];

Plotting imported AIFF

ListPlot[importedWaveForm, Joined -> True, PlotRange -> All]

enter image description here

We see in the image above that the waveform is scaled by a factor of 2, and then offset by -1.

Question: Am I doing something incorrectly (like missing an Export[] setting), or is this a bug in Mathematica 10.x? If it is a bug, is anyone aware of it and is there a way to work around it?


The export uses the internal function System`Convert`AudioDump`ExportAudio which contains the code:

samples = Rescale[samples, {Min[samples], Max[samples]}, {-1, 1}]

A simple workaround is to temporarily alter the behaviour of Rescale while exporting:

Block[{Rescale = #1 &}, Export[...]]
  • 1
    $\begingroup$ Thank you! I created the linked question because I tried exporting using ListPlay which allows specification of a PlayRange, and thought it would help identify the Export[] function as the place where the rescaling was occurring (as opposed to the Sound[] or SampledSoundList[] functions). It was also a little frustrating to not be able to export AIFFs from Mathematica all of a sudden and thought I would re-post in the hopes that it would trigger a response. I wonder why exporting AIFFs has been made this way when exporting in Mathematica 9 was so straightforward. I have deleted that post. $\endgroup$
    – Rahul
    Mar 29 '16 at 7:25

Your Answer

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

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