473,805 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# .NET play note frequency (sound)

I want to play a note in C# .NET giving a frequency like the one show
below.

Is it possible?

C 261.6
C# 277.2
D 293.7
D# 311.1
E 329.6
F 349.2
F# 370.0
G 392.0
G# 415.3
A 440.0
A# 466.2
B 493.9
C 523.2

I looked at this and it doesn't work.
I can't added in kernerl32.dll (it saying it's not an assembly or
com )

http://groups.google.com/group/micro...aff62f79d041c1
Dec 4 '07 #1
5 37586
I got beeping now. Is it possible to output a note like that?
Thanks.

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Media;

namespace sound12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{
// Play a beep with default frequency
// and duration (800 and 200, respectively)
Console.Beep();

// Play a beep with frequency as 200 and duration as 300
Console.Beep(20 0, 300);

Console.Beep((i nt)523.2, 300);
Console.Beep((i nt)523.2, 300);
Console.Beep((i nt)523.2, 300);
// Play the sound associated with the Asterisk event
SystemSounds.As terisk.Play();
}
}
}
Dec 4 '07 #2
"Slickuser" <sl*********@gm ail.comwrote in message
news:0f******** *************** ***********@e10 g2000prf.google groups.com...
>I want to play a note in C# .NET giving a frequency like the one show
below.

Is it possible?

C 261.6
C# 277.2
D 293.7
D# 311.1
E 329.6
F 349.2
F# 370.0
G 392.0
G# 415.3
A 440.0
A# 466.2
B 493.9
C 523.2

I looked at this and it doesn't work.
I can't added in kernerl32.dll (it saying it's not an assembly or
com )
You don't add a reference the kernel32.dll, you just copy/paste the code as
is.
>
http://groups.google.com/group/micro...aff62f79d041c1

Dec 4 '07 #3
On Mon, 03 Dec 2007 19:45:12 -0800, Slickuser <sl*********@gm ail.com>
wrote:
I got beeping now. Is it possible to output a note like that?
Thanks.
I don't believe that .NET has any built-in API to do anything like that.
The closest you could come is the SoundPlayer, and all that will do is
play a fixed WAV file. You can create the WAV format file in memory as a
MemoryStream, but you have to have the complete data ahead of time so that
the header of the WAV data is properly initialized.

I suppose if that's sufficient, then you could in fact do it that way.
Obviously if you know in advance which notes you want to play, you could
do that. But then, if you knew the notes far enough in advance, you could
just create the necessary WAV file and include it as a resource in your
application. :)

As for alternatives, even in Win32 I'm not aware of a tone-generator type
API that would take a frequency and play a note. However, it's not
difficult to generate the necessary wave forms and play them through a
streaming API. You can use either DirectSound or the WinMM API for that.

Pete
Dec 4 '07 #4
On Mon, 03 Dec 2007 20:02:44 -0800, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
>I got beeping now. Is it possible to output a note like that?
Thanks.

I don't believe that .NET has any built-in API to do anything like that.
[...]

As for alternatives, even in Win32 I'm not aware of a tone-generator
type API that would take a frequency and play a note. However, it's not
difficult to generate the necessary wave forms and play them through a
streaming API. You can use either DirectSound or the WinMM API for that.
And just to clarify, I'm assuming that for some reason Console.Beep()
isn't doing what you want, since you got it to work but are still asking
the question. It's not exactly the best thing for stringing a bunch of
notes together, and I'm guessing that's what you're running into.

Reading what I wrote above, I realize that there's a strong implication in
my post that you can't generate a tone by frequency at all. I practically
said that in so many words. Duh...obviously that's not true, and not what
I meant. Sorry for the confusion. I be having trouble words to put
together this night. :)

Anyway, if the Beep() method does do what you want, I'm not sure what
question is left. And if it doesn't, well...either way, maybe you could
be more explicit about what additional advice you need.

Pete
Dec 4 '07 #5
Another approach would be to use the AudioLab component suite from
www.mitov.com. It includes a tone generator which generates sine, triangle
or rectangle waveforms with any frequency you like.

The whole suite is extremely good (usual disclaimer).

SteveT

Dec 4 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4417
by: Askari | last post by:
Hi, I search how do for play more that one sound in same time with Python. Actually, I use the module "winsound" and I can play/stop a sound but can't play more that one sound in same time. :-( Askari Note : All sounds are in files on my hard disk
1
4302
by: Ron Provost | last post by:
Hello, I'm developing a piece of software to assist illiteraate adults to learn to read. I'm trying to figure out how, if possible, to make audio playback asynchrnous but still controllable. I'm using python 2.4 with pymedia on XP. I started out with the example in the tutorials section of the pymedia website. The pymedia docs imply to me that playback using Output's play() method should already be asynchronous and controllable. I...
1
8011
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be" sound instead playing the file (same code works fine in a windows application written in c# , that mean there is nothing wrong with my sound card.) thanks ----------------------------------------------------------------------------...
3
10642
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with Windows, and they play fine outside of my app. This code works, but has the random "scratching" problem: private static void PlayResource(string audioRes) { // Get the resource into a stream
2
2703
by: Krish06 | last post by:
Hi Friends, i just need to measure the frequency and ampitude from sound.. in my pro i create a sine wave(i set freq 1000hz,amptitude200) and i passed that wave sound to my pc thru microphone,here i need to receive the sound to my program and the same time i need to dispaly the frequency,amptitude(1000hz,200) in my program..so i need to measure freq,and amptitude from the incoming sound..using directx i can record the sound as wav file but...
7
4060
by: Udhay | last post by:
How to get the frequency of an audio file and how to separate the low and high frequency of an audio file
5
2164
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to play the sound. It works perfectly well in Windows XP, but when I move my application to a Vista machine, the sound does not play... I used a debug statement to confirm that the files are seen in the code but somehow it does not play... If I use...
26
3907
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are almost no posts from the last 3 years: http://groups.google.com/group/comp.lang.javascript/search?group=comp.lang.javascript&q=how+to+play+a+sound+with+Javascript&qt_g=Search+this+group Even after sorting by date, there don't appear any...
8
14953
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to cut and paste code that MSDN recommends for playing a simple wav file from inside an embedded file, like presumeably the 'resources' file .resx is. I want to embed the .wav file in a 'resource file' since I don't want the user storing the file on...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
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
5544
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...
1
4327
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
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.