3
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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}}

$\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.