是否有好的KERNEL32哔声(板载蜂鸣声)? [英] Are there nice kernel32 beep sounds (onboard beep)?

查看:153
本文介绍了是否有好的KERNEL32哔声(板载蜂鸣声)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人发现的哔哔声一个很好的结合,实际上听起来像音乐。

这是如何调用该方法。

 函数[DllImport(Kernel32.dll中)]
公共静态外部布尔蜂鸣(UInt32的频率,持续时间UInt32的);
// ...
//调用
蜂鸣(2000,400);

我第一次尝试:

 为(INT J = 1; J< 20; J ++)
    {
        的for(int i = 1; I< = 10;我++)
        {
            Console.Beep(300 * I,200);
        }
    }


解决方案

您可以玩的下面这个简单的使用PROGRAMM演奏旋律蜂鸣

 使用系统;
使用System.Runtime.InteropServices;类MelodyPlayer
{
    常量双ConcertPitch = 440.0;    注级
    {
        函数[DllImport(Kernel32.dll中)]
        公共静态外部布尔蜂鸣(UInt32的频率,持续时间UInt32的);        公共const int的C = -888;
        公共const int的CSHARP = -798;
        公共const int的DFlat = CSHARP;
        公共const int的D = -696;
        公共const int的DSharp = -594;
        公共const int的EFlat = DSharp;
        公共const int的E = -498;
        公共const int的F = -390;
        公共const int的FSharp = -300;
        公共const int的GFlat = FSharp;
        公共const int的G = -192;
        公共const int的GSharp = -96;
        公共const int的AFlat = GSharp;
        公共const int的A = 0;
        公共const int的ASharp = 108;
        公共const int的BFlat = ASharp;
        公共const int的B = 204;        公众诠释键{搞定;组; }
        公众诠释倍频{搞定;组; }
        公共UINT时间{搞定;组; }        公众注意(INT键,诠释八度,UINT持续时间)
        {
            this.Key =键;
            this.Octave =八度;
            this.Duration =持续时间;
        }        公共UINT频率
        {
            得到
            {
                双因子= Math.Pow(2.0,1.0 / 1200.0);
                返回((UINT)(MelodyPlayer.ConcertPitch * Math.Pow(因子,this.Key + this.Octave * 1200.0)));
            }
        }        公共无效播放()
        {
            蜂鸣(this.Frequency,this.Duration);
        }
    }    静态无效的主要(字串[] args)
    {
        注意:[] =旋律注意新[] {
            新的注(Note.C,0,100)
            新的注(Note.C,0,100)
            新的注(Note.D,0,100)
            新的注(Note.E,0,100)
            新的注(Note.F,0,100)
            新的注(Note.G,0,100)
            新的注(Note.A,0,100)
            新的注(Note.B,0,100)
            新的注意事项(Note.C,1,100)
            新的注意事项(Note.D,1,100)
            新的注意事项(Note.E,1,100)
            新的注意事项(Note.F,1,100)
            新的注意事项(Note.G,1,100)
            新的注意事项(Note.A,1,100)
            新的注意事项(Note.B,1,100)
            新的注(Note.C,2,100)
        };        的foreach(在音乐VAR注)
        {
            note.Play();
        }
    }
}

对于那些有兴趣:此使用威克麦斯特音律并计算基础上的Cent 值。

I was wondering if anybody found a nice combination of beeps, that actually sounds like music.

This is how to call the method.

[DllImport("Kernel32.dll")]
public static extern bool Beep(UInt32 frequency, UInt32 duration);
// ... 
// call
Beep(2000, 400);

My first attempt:

    for (int j = 1; j < 20; j++)
    {
        for (int i = 1; i <= 10; i++)
        {
            Console.Beep(300 * i, 200);
        }            
    }

解决方案

You can play around with the following simple programm to play melodies using Beep:

using System;
using System.Runtime.InteropServices;

class MelodyPlayer
{
    const double ConcertPitch = 440.0;

    class Note
    {
        [DllImport("Kernel32.dll")]
        public static extern bool Beep(UInt32 frequency, UInt32 duration);

        public const int C = -888;
        public const int CSharp = -798;
        public const int DFlat = CSharp;
        public const int D = -696;
        public const int DSharp = -594;
        public const int EFlat = DSharp;
        public const int E = -498;
        public const int F = -390;
        public const int FSharp = -300;
        public const int GFlat = FSharp;
        public const int G = -192;
        public const int GSharp = -96;
        public const int AFlat = GSharp;
        public const int A = 0;
        public const int ASharp = 108;
        public const int BFlat = ASharp;
        public const int B = 204;

        public int Key { get; set; }
        public int Octave { get; set; }
        public uint Duration { get; set; }

        public Note(int key, int octave, uint duration)
        {
            this.Key = key;
            this.Octave = octave;
            this.Duration = duration;
        }

        public uint Frequency
        {
            get
            {
                double factor = Math.Pow(2.0, 1.0 / 1200.0);
                return ((uint)(MelodyPlayer.ConcertPitch * Math.Pow(factor, this.Key + this.Octave * 1200.0)));
            }
        }

        public void Play()
        {
            Beep(this.Frequency, this.Duration);
        }
    }

    static void Main(string[] args)
    {
        Note[] melody = new Note[] {
            new Note(Note.C, 0, 100),
            new Note(Note.C, 0, 100),
            new Note(Note.D, 0, 100),
            new Note(Note.E, 0, 100),
            new Note(Note.F, 0, 100),
            new Note(Note.G, 0, 100),
            new Note(Note.A, 0, 100),
            new Note(Note.B, 0, 100),
            new Note(Note.C, 1, 100),
            new Note(Note.D, 1, 100),
            new Note(Note.E, 1, 100),
            new Note(Note.F, 1, 100),
            new Note(Note.G, 1, 100),
            new Note(Note.A, 1, 100),
            new Note(Note.B, 1, 100),
            new Note(Note.C, 2, 100)
        };

        foreach (var note in melody)
        {
            note.Play();
        }
    }
}

For those that are interested: This used a Werckmeister temperament and calculates the frequencies based on the Cent values defined for this temperament.

这篇关于是否有好的KERNEL32哔声(板载蜂鸣声)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆