Message Boards Message Boards

Export audio file without clipping waveform?

Posted 7 years ago

I'm using Mathematica to sonify some data. Using "Play," I can generate the audio within Mathematica and it sounds fantastic. However, when I export it to an audio file, the waveform is clipped and I can hear popping and static-y sounds. I've tried different file formats (.aif, .wav, .flac) and I've tried changing the SampleRate and AudioEncoding. Nothing seems to work. Every time I export it, there is still clipping. I don't understand why it plays perfectly within Mathematica, but doesn't export properly. Any suggestions?

To run the code you will need to download the csv file.

carbonIntensity = 
  Import["/Users/Jackie/Desktop/CarbonSpectrum.csv", {"Data", 
    Range[2, 62], 3}];

carbonFreq = 
  Import["/Users/Jackie/Desktop/CarbonSpectrum.csv", {"Data", 
    Range[2, 62], 4}];

(*Sums together all sinewaves with given frequencies in the csv file*)

carbonSonified = 
  Sum[carbonIntensity[[i]]*Sin[2*\[Pi]*t*carbonFreq[[i]]], {i, 
    1, ((62 - 2) - 1)}];

Play[carbonSonified, {t, 0, 5}]

Export["carbonSonified.wav", %]

In this picture, you can see the top of the wave is flat where it has been clipped.

Close-up of Waveform where Clipping can be seen.

Attachments:
POSTED BY: Jackie Bertone
3 Replies
Posted 7 years ago

Got the same result (OS X) than you but this was fixed just by setting the option PlayRange->All in Play. By default this option is set to Automatic and according to the docs it says "outlying levels are dropped". This is why you observe that some amplitudes are clipped in the exported file.

Now, it is not clear why Mathematica plays it exactly the same with the option set to All or Automatic.

POSTED BY: Chris P
Posted 7 years ago

Hi Neil,

Thanks for replying. I have tried exporting some examples, like the one you posted, and they export fine. I can hear no pops nor can I see any clipping in the picture of the waveform. I'm only having this problem with my code. The code I'm running is somewhat computationally intensive. It takes awhile for it to render the audio file. Could this have anything to do with the export quality? Also, I have noticed that the exported file has a large DC offset (~9%), whereas the DC offset when I exported the example code was nearly zero.

POSTED BY: Jackie Bertone

Jackie,

You need to post Code using the button in the upper left -- Images of code are of little use in helping you. You also don't give your functions so I can't try what you actually are doing. However I tried using one of the Documentation examples:

Play[(2 + Cos[40 t]) Sin[2000 t], {t, 0, 1}]

On a Macintosh and it works fine. I tried exporting the file and reimporting it -- it plays fine. I also played it in Quicktime outside of Mathematica and it plays fine as well. I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract