469,631 Members | 1,225 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

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 35862
I got beeping now. Is it possible to output a note like that?
Thanks.

using System;
using System.Collections.Generic;
using System.ComponentModel;
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()
{
InitializeComponent();
}

private void Form1_Load(object 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(200, 300);

Console.Beep((int)523.2, 300);
Console.Beep((int)523.2, 300);
Console.Beep((int)523.2, 300);
// Play the sound associated with the Asterisk event
SystemSounds.Asterisk.Play();
}
}
}
Dec 4 '07 #2
"Slickuser" <sl*********@gmail.comwrote in message
news:0f**********************************@e10g2000 prf.googlegroups.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*********@gmail.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*********@nnowslpianmk.comwrote:
>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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Askari | last post: by
1 post views Thread by Ron Provost | last post: by
1 post views Thread by Lam | last post: by
7 posts views Thread by Udhay | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.