471,357 Members | 1,237 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

C#/WPF and Internal Speaker

Hello,

This is for a WPF (3.5) application.

We have a requirement to produce sounds on an internal speaker (in the case
that no external sound device is available).

I know of Console.Beep(frequency, duration), but I wondered if there is a
better, more controllable way. Basically, the user will be toggling a
(hardware) switch on and off. When it is on, we need to play a tone, and
when it's off, we need to stop playing the tone.

We can use a series of short Beeps, but there will be a gap between each
beep, and the beep will need to run its entire duration (in other words, it
won't stop immediately when the switch is turned off).

Thanks,
WtS
Jun 27 '08 #1
4 5296
Hi Wonko,

Firstly, there's a Win32 API function "Beep" which generates simple tones
on the speaker. The function is synchronous; it performs an alertable wait
and does not return control to its caller until the sound finishes.

The definition of this function is as follows:
BOOL Beep(
DWORD dwFreq,
DWORD dwDuration
);

It's similar to the Console.Beep(int, int) method overload. So it seems
that the Console.Beep(int, int) method overload is the wrapper method of
the Beep function.

Secondly, we could use the command "net stop beep" to silence the tone.
When the Console.Beep(int, int) method is being executed and we execute the
command "net stop beep" during the beep, the command window outputs the
following text:
The Beep service is stopping...

Only after the Console.Beep finishes the execution, the command window
outputs the following text:
The Beep service was stopped successfully.

As we can see, the beep service cannot be stopped when the tone is being
used. Only after the tone is free, the beep service can be stopped. So this
is a hardware design and this behavior is by design. And IMO, there's no
better and more controllable method or function than the Console.Beep
method since the Control.Beep is already the wrapper of the Beep function.

As for your question, I suggest that you use a series of short beeps by
calling the Console.Beep(int, int). For example:
for (int i = 0 ; i < 10; i++)
{
Console.Beep(80, 500);
}

Thus, the entire beep will last for 5 seconds. But if you silence the tone
during the beep, the beep will be stopped more promptly.

Hope I make myself clear.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #2
Hi Linda,

Thanks for the feedback. That is the preliminary design of that part of my
app - I was just wondering if there was a "better" way, or a more .NET way
that I wasn't aware of.

Thanks again for the help,
WtS

"Linda Liu[MSFT]" wrote:
Hi Wonko,

Firstly, there's a Win32 API function "Beep" which generates simple tones
on the speaker. The function is synchronous; it performs an alertable wait
and does not return control to its caller until the sound finishes.

The definition of this function is as follows:
BOOL Beep(
DWORD dwFreq,
DWORD dwDuration
);

It's similar to the Console.Beep(int, int) method overload. So it seems
that the Console.Beep(int, int) method overload is the wrapper method of
the Beep function.

Secondly, we could use the command "net stop beep" to silence the tone.
When the Console.Beep(int, int) method is being executed and we execute the
command "net stop beep" during the beep, the command window outputs the
following text:
The Beep service is stopping...

Only after the Console.Beep finishes the execution, the command window
outputs the following text:
The Beep service was stopped successfully.

As we can see, the beep service cannot be stopped when the tone is being
used. Only after the tone is free, the beep service can be stopped. So this
is a hardware design and this behavior is by design. And IMO, there's no
better and more controllable method or function than the Console.Beep
method since the Control.Beep is already the wrapper of the Beep function.

As for your question, I suggest that you use a series of short beeps by
calling the Console.Beep(int, int). For example:
for (int i = 0 ; i < 10; i++)
{
Console.Beep(80, 500);
}

Thus, the entire beep will last for 5 seconds. But if you silence the tone
during the beep, the beep will be stopped more promptly.

Hope I make myself clear.

If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #3
Wonko the Sane wrote:
Hi Linda,

Thanks for the feedback. That is the preliminary design of that part
of my app - I was just wondering if there was a "better" way, or a
more .NET way that I wasn't aware of.
The "better" way is to install a sound driver for the PC speaker, then use
any streaming audio API like DirectSound.
Jun 27 '08 #4
Hi Ben,

Certainly, but only if such a driver is available.

WtS

"Ben Voigt [C++ MVP]" wrote:
Wonko the Sane wrote:
Hi Linda,

Thanks for the feedback. That is the preliminary design of that part
of my app - I was just wondering if there was a "better" way, or a
more .NET way that I wasn't aware of.

The "better" way is to install a sound driver for the PC speaker, then use
any streaming audio API like DirectSound.
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Anon Email | last post: by
5 posts views Thread by a.dheeraj.kumar | last post: by
9 posts views Thread by jgcrawford | last post: by
10 posts views Thread by gentsquash | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.