# Audio sample data from a Sound object

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.

-

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

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

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

rate = 8192

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

NMaximize[f[x], x]

{0.859436, {x -> 4.94378}}

-