有好听的 kernel32 蜂鸣声(板载蜂鸣声)吗?

发布于 2024-09-11 20:18:04 字数 418 浏览 14 评论 0原文

我想知道是否有人找到了一种很好的蜂鸣声组合,这实际上听起来像音乐。

这就是方法的调用方法。

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

我的第一次尝试:

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

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);
        }            
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

锦爱 2024-09-18 20:18:04

您可以使用以下简单的程序来使用 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();
        }
    }
}

对于那些感兴趣的人:这使用了 Werckmeister 音律 并根据音分< /a> 为此气质定义的值。

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.

探春 2024-09-18 20:18:04

Beep 函数由 QBasic 的 Play 命令封装。该产品在 Google 上获得了很多点击,这是首选。编写代码来翻译 Play 字符串可能比复制粘贴更有趣。语法是此处描述

The Beep function was wrapped by QBasic's Play command. Lots of Google hits on that one, this was the top selection. Writing the code to translate the Play string could make this a bit more interesting than copy-paste. The syntax is described here.

国粹 2024-09-18 20:18:04

还有System.Console.Beep

There is also System.Console.Beep.

悸初 2024-09-18 20:18:04

检查 Google 中的单音铃声,然后使用十六进制编辑器打开该文件,然后对歌曲进行逆向工程。如果您的程序能够读取原始文件并将其即时转换为蜂鸣声,那就加分了。

Check Google for Monophonic Ring-tones then open the file with a hex editor and reverse engineer the songs. Bonus points if your program will read in the original file and translate it to the beeps on the fly.

你没皮卡萌 2024-09-18 20:18:04

曾经有一个声音驱动程序将 PC 扬声器用作 PCM 音频设备(声卡)

There used to be a sound driver that would use the PC Speaker as a PCM audio device (sound card)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文