Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Audio Output in Simulink with Real-Time Windows

Subject: Audio Output in Simulink with Real-Time Windows

From: Spencer

Date: 13 May, 2013 21:03:11

Message: 1 of 7

Hello,

       I'm currently using Windows Real-Time Target to connect to a CAN communication device in Simulink. A user manipulates a device 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, a popular song) to let the user know they achieved their goal without the experimenter interacting with them. Is there any way to output a sound over my computer's audio hardware when I'm connected with the Real-Time Windows Kernel?

I've tried using the "To Audio Device" block, but I am unable to build my model when the block is used. The error returned does not explain the conflict; "Error(s) encountered while building model" is all it says. I have also tried using "MATLAB Function" blocks with the "beep" command ( using coder.extrinsic('beep') ) . This works when I am not in "external mode", but when I am communicating with our system with the external mode the beep no longer plays.

Any help would be greatly appreciated.

Thanks,
Spencer

Subject: Audio Output in Simulink with Real-Time Windows

From: Spencer

Date: 14 May, 2013 16:03:10

Message: 2 of 7

Anyone?

Subject: Audio Output in Simulink with Real-Time Windows

From: Jan Houska

Date: 15 May, 2013 14:11:05

Message: 3 of 7

Hi Spencer,

Spencer wrote:
> I'm currently using Windows Real-Time Target to connect to a CAN
> communication device in Simulink. A user manipulates a device 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, a popular song) to let the user know they achieved their
> goal without the experimenter interacting with them. Is there any way to
> output a sound over my computer's audio hardware when I'm connected with
> the Real-Time Windows Kernel?
> I've tried using the "To Audio Device" block, but I am unable to build
> my model when the block is used. The error returned does not explain the
> conflict; "Error(s) encountered while building model" is all it says. I
> have also tried using "MATLAB Function" blocks with the "beep" command (
> using coder.extrinsic('beep') ) . This works when I am not in "external
> mode", but when I am communicating with our system with the external
> mode the beep no longer plays.
> Any help would be greatly appreciated.

The real-time kernel of Real-Time Windows Target has no access to the
audio device in your computer. That's why you cannot beep from the
compiled real-time code. The real-time kernel and your host operating
system (Windows) are two separate environments that just happen to run
on the same computer.

So, while you cannot beep on the target, you can still beep on the host.
  To do that, please write a MATLAB Level 1 S-function that has no
outputs and beeps based on a condition on its input (e.g. 0 do not beep,
1 beeps). Such S-functions do not compile to real-time and continue to
run on the host, so they can contain any MATLAB function including
"beep". You can also write a MATLAB Level 2 S-function if you prefer,
but in that case please do not forget to set the SimViewingDevice flag,
otherwise the block will try to compile.

If you are interested in an example please send me a message to the
address below, I will not post code here.

Best Regards, Jan


--
Jan Houska HUMUSOFT s.r.o.
houska@humusoft.com Pobrezni 20
http://www.humusoft.com 186 00 Praha 8
tel: ++ 420 284 011 730 Czech Republic
fax: ++ 420 284 011 740

Subject: Audio Output in Simulink with Real-Time Windows

From: Spencer

Date: 15 May, 2013 18:30:14

Message: 4 of 7

Jan,

           Thank you. I managed to get a level 1 S-function that will play a sound through the host as you indicated. I could not manage to get a Level 2 S-function to work however. Do you set the flag by placing the:
SetSimViewingDevice(true);
command in the "setup" function? I play around with it or a bit but I am still getting an error when I build my system. Either way, thanks again because my Level 1 version is working.

Spencer

Subject: Audio Output in Simulink with Real-Time Windows

From: Jan Houska

Date: 16 May, 2013 03:39:58

Message: 5 of 7

Hi Spencer,

Spencer wrote:
> Jan,
> Thank you. I managed to get a level 1 S-function that will
> play a sound through the host as you indicated. I could not manage to
> get a Level 2 S-function to work however. Do you set the flag by placing
> the:
> SetSimViewingDevice(true);
> command in the "setup" function? I play around with it or a bit but I am
> still getting an error when I build my system. Either way, thanks again
> because my Level 1 version is working.
> Spencer

yes, you do "block.SetSimViewingDevice(true);" in "setup(block)". Please
note that you cannot have any outputs - this is the second important
condition for SimViewingDevice. If the S-function is set up correctly,
it should not build at all, so the build errors you get indicate that
the S-function is not recognized as SimViewingDevice.

Best Regards, Jan


--
Jan Houska HUMUSOFT s.r.o.
houska@humusoft.com Pobrezni 20
http://www.humusoft.com 186 00 Praha 8
tel: ++ 420 284 011 730 Czech Republic
fax: ++ 420 284 011 740

Subject: Audio Output in Simulink with Real-Time Windows

From: Cornelis

Date: 18 Nov, 2013 22:29:07

Message: 6 of 7

Dear Spencer, dear Jan

when you say a sound, does that mean any sound?
What I try to implement -while running a simulink model in external mode- is triggering a function call like for instance: play(player). [as in: load handel; player = audioplayer(y, Fs); play(player)]

Based on what you say in this thread I thought it might be possible to: i) preload the player object, ii) build a real-time windows target model (external mode)that, iii) using a s-function that after triggering (e.g. u>0 ) plays the player object.

Unfortunately I'm struggling with the whole S-function concept so it's difficult for me to assess if this would be possible at all?

Any suggestions would be most appreciated!
Many thanks
regards
Cornelis

Subject: Audio Output in Simulink with Real-Time Windows

From: frah87

Date: 22 May, 2014 00:16:52

Message: 7 of 7

Hi,
I am trying to generate sounds while executing a model in real time windows target.
I read you figured this problem out by writing a MATLAB Level 1 S-function.
Could you give me some details? What do I have to do to write this function?
(I have to hear a beep when the input is one and no beep when the input is zero).
Thank you very much.
Regards,
Francesca

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us