473,800 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(fr equency, 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 5505
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(in t, int) method overload. So it seems
that the Console.Beep(in t, 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(in t, 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(in t, 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****@microsof t.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(in t, int) method overload. So it seems
that the Console.Beep(in t, 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(in t, 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(in t, 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****@microsof t.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
1674
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 sound libraries (PySonic, Audiere, pygame), as well as any number of command line .wav file players. For differing reasons, none of these were suitable. Two possiblities are: (a) Convert the mono .WAV file to a stereo .WAV file that plays out of...
19
56721
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 least, SHOULD make the computer speaker beep. I know that whether the computer speaker actually beeps or not is largely dependent on the OS I'm using. But I'm not so much concerned about that (at this stage). I just want to know if ANSI C++...
5
4071
by: a.dheeraj.kumar | last post by:
How to play wav files through the internal speaker?
9
8436
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 nosound(). Is there anything similar for Linux? I know I can make a simple beep with '\a', but that's not what I need. If not, can someone please show me how to do this with the /dev/audio device?
1
1830
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 asked to fill out an anonymous survey assessing the overall effectiveness of the seminar (on a scale of 1-10) in addition to giving a 1-10 rating for each speaker and associated content at the event. I'd like to set it up so that I can enter in...
9
1219
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 to exist. Still, just in case... Thx,
10
2471
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, making a click-sound on each keypress. On Unix/Linux/MacOSX systems, you can hear this click by typing ^g (control g) into a shell/terminal. This is also the click made by ^g when it is typed in Emacs, or when Emacs signals an error.
3
5296
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 speaker. I m using c++ for programming and windows Xp Sp2 as OS. Can some one please guide that how to send data directly to speaker. Your quick reply is highly appreciable. Thank you, NIraj Shah
2
2267
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 itself (the PC) does not have speakers connected and do not want to attach any speakers. Has anyone ever found some code that detects a Windows Message (WM_) or otherwise some kind of a hook that detects when a query is complete in Studio Express? ...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.