I would like to acquire and display audio data in a continuous fashion from my sound card using Simulink. The following code does this in Matlab (see below). How can I do this in Simulink?
I am aware of this example, which uses blocks from the DAQ toolbox:
However, I would like to use a user-defined block of some kind rather than the DAQ block. The reason is that I am using this code as a way to learn how to work with data from a different device, and the DAQ block does not work with the other device.
It seems like changing the code to simulink should require 1. using the model callback "InitFcn" to initially trigger a program that creates the ai object and initializes its parameters 2. using some sort of user-defined function block to execute the " data = peekdata(ai,ai.SampleRate); " line, i.e. to get the data. This is where I'm stuck... 3. using the model callback "CloseFcn" to run the final cleanup commands
The problem I'm having with (2) is: The way to do this seems to be a "Matlab Function" block. This requires an input and an output. The output would obviously be what I'm calling "data" in the code below. But what would the input be? And how does this function know about ai? Does not seem to be possible to pass ai in...
Thanks in advance for any help!
ai = analoginput('winsound',0);
ai.SampleRate = 8000;
ai.SamplesPerTrigger = ai.SampleRate*duration;
data = peekdata(ai,ai.SampleRate);