1
$\begingroup$

Question

I'll focus on the example

stream=AudioStream@First@$AudioInputDevices 

I can do stream@"Properties" to get a list of info about it. How and where is, for instance, stream@"SampleRate" defined?


*Values

The result of Through[Unevaluated@{OwnValues,DownValues,UpValues}@stream] is

{{stream:>AudioStream[alittlebox]},{},{}} 

so that's not informative.

Associations

FullForm@stream suggests that stream is simply AudioStream@<|"ID"->"blahblah"|>. There's clearly data stored elsewhere.

Boxes

little box

I don't know how to look at the definition the box graphic from above. Is there some way to do this by Unprotecting MakeBoxes and GeneralUtilities`PrintDefinitions or something like that? I suppose the box code which actually contains the numbers would explain a lot.

The string "Audio Input Device" is hardcoded in the box if you expand it. I grepped for it in my installation directory, and found it in SystemFiles/Kernel/SystemResources/MacOSX-x86-64/Audio/ProgrammaticPlayback/AudioStreamBox.mx. It's a binary dump file, so I can't find out much.


I recently edited How to mimic thing["property"] syntax?. It's previous title was basically equivalent to this one, but it's actual question and discussion was more along the lines of reproducing rather than system internals.


Use RemoveAudioStream/@AudioStreams[] to purge the stuff from the system, the function isn't immediately obvious.

$\endgroup$
4
  • $\begingroup$ To et info about the stream, you write e.g.: stream["SampleRate"] $\endgroup$ Commented Mar 5, 2023 at 10:48
  • 2
    $\begingroup$ I think what you are looking for is in SubValues[AudioStream] and FormatValues[AudioStream]. As they are only "syntax" wrappers for other functions you can't learn much about the inner workings, but probably this is good enough to understand how you can create something that behaves the same. For the inner workings: this looks much like it is using some library not written in Mathematica which is accessed with the help of a handle identified by the "ID". Investigating symbols in the Audio`AudioStreamInternals` package might give some clues... $\endgroup$ Commented Mar 5, 2023 at 11:37
  • 3
    $\begingroup$ Use GeneralUtilities`PrintDefinitions[AudioStream] and you will see several definitions of the form AudioStream[...][prop_] := .... That is where the SubValues of AudioStream are defined. $\endgroup$ Commented Mar 5, 2023 at 22:54
  • 1
    $\begingroup$ If you (or developers at WRI) define a function func, you may, at your discretion, define func["Properties"] to be whatever you like. The developers at WRI define it for some objects and not for all. But it has to be defined by your code (or by the internal code in the case system objects. Sometimes it's obj["Methods"], sometimes both are defined, sometimes both are defined and different.). $\endgroup$ Commented Mar 5, 2023 at 23:58

1 Answer 1

1
$\begingroup$

Thanks to Albert Retey, I could investigate a little more.

It turns out all that was needed was TracePrint. Given

myStream = AudioStream@$DefaultAudioInputDevice 

you can call

allstreams=Audio`AudioStreamInternalsDump`$audioStreams; allstreams["External"][myStream@"ID"]["Slow"] 

which yields an association with keys "Status", "Looping", "MaxTime", "BufferSize", etc.

Curiously, "Properties" is not present; I'm not sure how myStream@"Properties" works.

myStream refers to both a "Fast" and "Slow" external stream. Both are present in allstreams, in variables named by the uuid

Audio`AudioStreamInternals`External`streama1ac44be9a354a189cffca59d077a60dfast Audio`AudioStreamInternals`External`streama1ac44be9a354a189cffca59d077a60d 

So, for instance, you can call Names@"Audio`AudioStreamInternals`External`*". Question: what makes it so that the two above variables don't "expand" into associations if they are in an association? I.e.

<|a|> (*Output is <|a|>*) {a} (*Output is {...stuff...}*) 
$\endgroup$
2
  • 3
    $\begingroup$ This doesn't really answer the question. $\endgroup$ Commented Mar 6, 2023 at 13:17
  • 1
    $\begingroup$ Tou state that "all that was needed was `TracePrint``. Please show how you used it to obtain the information you desired. $\endgroup$ Commented Mar 6, 2023 at 20:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.