Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When generating a Sound object by using Sound primitives, like:

Needs["Audio`"]
sound = Sound[ListWaveform[{{1, 1}, {1.496, .7}, {2.501, .3}}, 265, 1]];

how can I get the sample ("amplitude") data which is produced by the Sound primitive at a given sample rate?

Obviously one could export sound to a wav file and re-import it, but how to do it directly? Or let's say: what is the Rasterize function for Sounds, the inverse of ListPlay?

Sorry for this rather simple question, but I have been looking for some time and could not find anything.

share|improve this question

1 Answer 1

Your example evaluates to a SampledSoundFunction[f , n , r ], which

is a sound primitive that represents a sound whose amplitude sampled r times a second is generated by applying the function f to successive integers from 1 to n.

You could extract that function and see if it gives you what you're looking for:

Needs["Audio`"]
sound = Sound[ ListWaveform[{{1, 1}, {1.496, .7}, {2.501, .3}}, 265, 1] ];
sound

enter image description here

func = Cases[sound, _SampledSoundFunction, Infinity][[1]];

Print["rate = " <> ToString@(rate = func[[3]] )]

rate = 8192

f = func[[1]]
Plot[f[x], {x, 0, rate}]

enter image description here

NMaximize[f[x], x]

{0.859436, {x -> 4.94378}}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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