- Writing a MATLAB Level 1 S-function without any outputs, such that it triggers a beep in response to an input condition. Such an S function will not be subjected to real-time compilation and continually run on the host. As a result, it can contain any suitable MATLAB function/code that supports the beep audio output.
- Deploying a Level 2 S-function without any outputs, while ensuring that the ‘SetSimViewingDevice’ Flag is set beforehand.
Audio output in Simulink Real Time with Windows
5 views (last 30 days)
Show older comments
Hello,
I'm currently using a Target machine which connects to my computer and also via CAN to a robot. I am using Simulink (version 2019b) in external mode (fixed step auto solver, target file slrt.tlc, inherited) to run C-code on the target machine. A user manipulates the robot and our model determines whether or not a specific task is achieved. When the task is achieved I need the Simulink model to output any noise (a beep, a ding, a gong) to let the user know they achieved their goal without the experimenter interacting with them. At the moment I have a Simulink model with a Stateflow chart which has the output of 1 when the task is achieved and the sound should be played. Is there any way to output a sound over my computer's audio hardware when I use the external mode in Simulink?
I tried struggeled using an S-function which just beeps on the host and is not compiled. How do I have to write this function? And how can I tell Simulink to continue to run on the host?
0 Comments
Answers (1)
Swathi
on 13 Sep 2022
I discern that the objective was to output a sound (audio response) over the computer's audio hardware (while connected with the Real-Time Windows Kernel), whenever the output of the Simulink model is ‘1’ as an indication that the task has been achieved.
The intent was to use the audio output (a beep/ding/gong, or a popular song) to serve as an automated acknowledgement to the user by avoiding experimenter interaction(s). It is noted that using the ‘To Audio Device’ block and the ‘MATLAB Function’ block yields the expected output only while not communicating with the system using the external mode.
The reason an audio output (‘beep’ for instance) cannot be received from the compiled real-time code is mainly because the ‘real-time kernel’ of Real-time Windows Target will not have access to the audio device connected to the system/computer. This is since the real-time kernel and the host OS (Windows) are two distinct environments that run on the same system/computer but are mutually exclusive.
However, it is possible to have a ‘beep’ output on the host by any one of these methods -
0 Comments
See Also
Categories
Find more on Code Generation and Deployment in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!