2
$\begingroup$

I have a Sound created with SoundNote, as follows:

simpleSound = Sound[SoundNote["C"]]

How do I get a list of samples from this?

As a work-around, I tried using Export to write a WAV file and then using Import to get the data out. However, Mathematica won't save the WAV file. I get an error: "Sound contains no data that can be exported to the WAV format."

Most examples focus on making a Sound from a SampledSoundList, but I want to do the opposite.

EDIT> I'm on Mac, so SoundMapper is not available. The only choice for input in Audacity is the microphone.

$\endgroup$
  • 1
    $\begingroup$ The reason this can't be done directly is that SoundNote["C"] is a MIDI sound. So, it doesn't have a uniquely defined waveform equivalent. In rendering this sound every MIDI player will either use its own or the system's standard sound bank to turn this into audible sound and the result is dependent on your environment. Mathematica lets the OS perform the actual playing of the MIDI sounds and never actual generates the corresponding waveform so it doesn't have anything to export. $\endgroup$ – Sjoerd C. de Vries Oct 13 '15 at 21:45
  • $\begingroup$ @Sjoerd. You're right, but I suppose I'm just surprised that Mathematica doesn't have an option / API to use the default sound bank. $\endgroup$ – Jabavu Adams Oct 14 '15 at 14:42
3
$\begingroup$

I searched but found nothing concrete,but you can just do it: You can export to mid file.

simpleSound = Sound[SoundNote["C"]];
Export["sound.mid", simpleSound]

Import to Audacity-Audio Editor,and convert YouTube help video to wav file, than import back to MMA.

wavdata = Import["wavfile.wav", "Data"];
ListLinePlot[Take[Flatten@wavdata, {2000, 3000}], Filling -> Axis, 
PlotStyle -> Orange]

enter image description here

You can use this WEB page to convert files or something else:

$\endgroup$
  • $\begingroup$ It's true: this is one workaround. I dislike that I need to play the audio on my potentially poor speakers while simultaneously recording it (and background noise) on my potentially poor microphone. The data's already in the machine, so I'd prefer to keep it in there, without adding more noise and distortion. $\endgroup$ – Jabavu Adams Oct 14 '15 at 14:44
  • 1
    $\begingroup$ @JabavuAdams.By sound mapper not by the microphone.Yes you need very good audio card. $\endgroup$ – Mariusz Iwaniuk Oct 14 '15 at 21:20
  • $\begingroup$ Ah, I didn't watch that specific video. After watching it, the approach seems good. Unfortunately, I'm on Mac. I'll try this on Win7... $\endgroup$ – Jabavu Adams Oct 20 '15 at 13:03
1
$\begingroup$

Most functions that take an Audio object as an argument also take Sound objects.

To get the sample data:

simpleSound = Sound[SoundNote["C"]]
dat = AudioData[simpleSound]
$\endgroup$
0
$\begingroup$

With Mathematica 11, you can do the exporting and importing both within Mathematica, no external tool required:

simpleSound = Sound[SoundNote["C"]];
Export["/tmp/temp.mp3", simpleSound];
simpleSampledList = Import["/tmp/temp.mp3", "SampledSoundList"]
$\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.