I try to use the expression:

Spectrogram[Sound[SoundNote[{"C", "E", "G", "C5"}, 10, "Vibraphone"]]]

to plot the spectrogram of a SoundNote. But Spectrogram symbol do not support SoundNote. I tried Play and EmitSound but they all do not work. I think Spectrogram need a list of raw bytes of sound, how can I convert SoundNote sound to raw bytes?

Any ideas? Thanks.

  • 2
    $\begingroup$ The problem is that SoundNote generates a MIDI event so I believe the sound will need to be played by the (operating) system and recorded, or otherwise converted with a software synthesizer. I don't know how to do this from within Mathematica but I shall think about it. Possibly useful: en.wikipedia.org/wiki/FluidSynth $\endgroup$
    – Mr.Wizard
    Commented Jan 4, 2015 at 12:20
  • $\begingroup$ @Mr.Wizard Can we do anything useful with this? $\endgroup$
    – Sektor
    Commented Jan 4, 2015 at 13:00
  • $\begingroup$ @Sektor I am not familiar with that command but the output is probably still MIDI program data only in numeric form. $\endgroup$
    – Mr.Wizard
    Commented Jan 4, 2015 at 13:06
  • $\begingroup$ @Mr.Wizard Yup, it is; Byte. I was wondering if you were aware of some internal happy power :D $\endgroup$
    – Sektor
    Commented Jan 4, 2015 at 13:08
  • 1
    $\begingroup$ Thanks Mr.Wizard, Sektor. This is a good idea. 1.Export SoundNote to mid file. 2.Use software synthesizer generate wav file. 3. Import wav to MMA. The software synthesizer TiMidity++ can do this. $\endgroup$
    – Bob Young
    Commented Jan 6, 2015 at 2:03

1 Answer 1

sound = Sound[SoundNote[{"C", "E", "G", "C5"}, 10]];

data = First@AudioData@sound;(*get audio samples*)
sampleRate = AudioSampleRate@sound;(*get sampleRate*)

you can hear the sound again.

Sound@SampledSoundList[data, QuantityMagnitude[sampleRate]]

enter image description here

And you can view it spectrogram.

Spectrogram[data, 2048, SampleRate -> QuantityMagnitude[sampleRate]]

enter image description here

In short,you can use the code to deal with it.

 Spectrogram[First@AudioData@#, 2048, SampleRate -> QuantityMagnitude[AudioSampleRate@#]] &
     @Sound[SoundNote[{"C", "E", "G", "C5"}, 10]]


This code is shorter.

Spectrogram@Audio@Sound[SoundNote[{"C", "E", "G", "C5"}, 10]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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