4
$\begingroup$

rawdata = Import["rawdata_10min.wav"] crashes Mathematica when the file is 150 MB, but does not crash Mathematica when the file is 20 MB.

$\endgroup$
  • $\begingroup$ OK, thanks for letting us know. And your question is... ? $\endgroup$ – MarcoB Mar 24 '16 at 18:49
  • 1
    $\begingroup$ The question is how to achieve the import without the crash. @Michael Would you please add that to your question, and can you upload add a link to your data so we can try? $\endgroup$ – M.R. Mar 24 '16 at 18:52
  • $\begingroup$ you could try adding a " ; " after your import line- it's possible that the front end can't handle the graphic/suggesting wav form. $\endgroup$ – Peter Roberge Mar 24 '16 at 20:17
  • $\begingroup$ The ";" works! Thank you very much! $\endgroup$ – Michael B. Heaney Mar 24 '16 at 20:54
7
$\begingroup$

I generated a 150MB WAV file by converting some MP3 in an external program, and then tried to Import it into Mathematica:

FileByteCount[wavfile]/1024^2 // N

(* Out: 167.599 *)

Trying Import[wavfile], Mathematica became unresponsive, then my disk started thrashing, then everything became unresponsive and I had to hard-reboot. Unpleasant.

However, on the next try I noticed that it is NOT actually the importing step that crashes Mathematica, but actually the presentation of the results in the fancy little box format. Silly, uh?

So, for the same file, the following works just fine, and pretty fast too:

importedwav = Import["C:\\Users\\Marco\\Desktop\\Allegri - Miserere.wav"]; // RepeatedTiming
(* Out: {1.7, Null} *)

Head[importedwav]
(* Out: Sound *)

So in short, you can import very large files with no issues, as long as you don't ask the front end to generate the fancy formatted form for Sound, with waveforms and spectrum, which unsurprisingly are very expensive to calculate on a large data file.

Alternatively, if you only care about the data in the WAV file, rather than the Sound object representation, you can import the raw numerical data directly as well:

dataonly = Import["C:\\Users\\Marco\\Desktop\\Allegri - Miserere.wav", {"WAV", "Data"}];

This took roughly 1.4 s on my machine, so it seems to be even faster than generating the Sound object. For a stereo file, you will get a list of two lists, one per channel.

$\endgroup$
  • $\begingroup$ Thanks, that solves my problem!!! $\endgroup$ – Michael B. Heaney Mar 24 '16 at 20:55
  • 2
    $\begingroup$ @Michael I'm glad to hear that. Sometimes Mathematica just tries to be too clever for its own good... $\endgroup$ – MarcoB Mar 24 '16 at 21:03
  • $\begingroup$ Don't forget to report it! $\endgroup$ – P. Fonseca Mar 25 '16 at 6:24
3
$\begingroup$

Did you try increasing the java virtual machine heap size? Doing this:

<< JLink`;
InstallJava[];
ReinstallJava[JVMArguments -> "-Xmx512m"

will do that for you. The variables you want to alter are the numbers in the last section. Set that to the number of MB of RAM you can assign on your machine. Hopefully, that should do it. This works with large files for me, though I rarely work with large .wav files and haven't had this problem with this filetype myself.

$\endgroup$

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.