472,993 Members | 3,191 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 5430
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan Green | last post by:
I am writing a Python script that uses the win32all winsound package to play a .wav file. I the sound come out of the left hand speaker, but not the right hand speaker. I've look at some Python...
19
by: Anon Email | last post by:
Hi everyone, Let's see, now. This question is about the capabilities of ANSI C++. I want to write and compile code in ANSI C++ that, when compiled, will make the computer speaker beep; or, at...
5
by: a.dheeraj.kumar | last post by:
How to play wav files through the internal speaker?
9
by: jgcrawford | last post by:
G'day, I'm writing a ringtone manager for nokia ringtones and I'd like to be able to play the ringtone on the PC speaker. I've had some success in DOS with turbo C and its sound(), delay() and...
1
by: puttypapyrus | last post by:
I am having trouble designing the tables and establishing relationships for a survey database for the purpose of evaluating speakers for a variety of events. After every event, the attendants are...
9
by: skip | last post by:
Got a note about a new page on the Python Wiki: http://wiki.python.org/moin/Selcuk_Altun I suspect it's junk since it doesn't seem to mention Python and the website it mentions doesn't seem...
10
by: gentsquash | last post by:
Can javascript (easily) produce a click from the PC-speaker? This is the speaker that is (well, used to be) directly on the CPU-card and was -I believe- intended to give feedback to the typist,...
3
by: Niraj Shah | last post by:
Dear All, In my application, i want to capture live audio data and send them to speaker. I can able store captured audio data in file but my application requirement is to send data directly to...
2
by: UpsideDownTire | last post by:
Hi, I am running SQL 2005 Server with SQL Server Management Studio Express 2005. I am aware of the option "Play the Windows default beep when a query batch completes". However, the machine...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.