4
$\begingroup$

Audio objects backed by in-memory data (not files) seem to contain a RawArray.

Is there a way to get the AudioData as an appropriate-type RawArray?


It could be done by forcing a change of representation, such as passing through MathLink, Uncompress[Compress[...], Hold], or similar. None of these is fast.

It could be done by just using AudioData and re-packing the result into a RawArray. This wasted memory. The typical audio representation uses 16-bit integers. Converting this to 64-bit integers or reals increases the storage requirements by a factor of 4.


Motivation:

Currently, there is no direct way to exchange Audio objects with C code through LibraryLink, but there is a way to send/receive RawArrays.

This is not a problem for the similar Image/Image3D (also likely backed by RawArray) because that is directly supported by LibraryLink (MImage).

RawArrays can be converted to Audio using Audio[ra, ...].

$\endgroup$
  • $\begingroup$ Is there no way to unpack it with AudioData and then convert to RawArray? $\endgroup$ – bill s Nov 11 '17 at 15:16
  • 3
    $\begingroup$ Something like Audio`InternalAudioData? $\endgroup$ – ilian Nov 11 '17 at 16:21
3
$\begingroup$

The internal function Audio`InternalAudioData could be used to accomplish this, subject to the usual caveats concerning undocumented functionality.

Audio`InternalAudioData[Audio[{1, 2, 3, 4}]]

(* RawArray["Real32", <1, 4>] *)

Audio`InternalAudioData[Audio["ExampleData/car.mp3"]]

(* RawArray["Real32", <1, 328320>] *)
$\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.