比尔盖子 博客

GRUB 2 里的 play 命令

GRUB 2 中,有个 play 命令,用来让蜂鸣器播放音频。这可不是什么玩法……

它接受无限个参数,对于一个典型的三参数的调用,文档如下

play [tempo] [pitch] [duration] {pitch2 duration2...}

tempo 是全局速度,所有的 pitch 都受到它的影响;pitch 即要播放的音频,单位为赫兹;duration 是持续时间。

为了播放音乐,需要搞清楚一个调用究竟是多长时间。把 play 看作一个函数,接受 tempo 和 duration 两个参数。经过试验:

tempo duration 时间
60 1 1 s
60 2 2 s
30 1 2 s
30 2 4 s
120 1 1/2 s
120 2 1 s

从这里大概可以看出来,

时长 (s) = 60 / t * d

这样,如果使 t = 60000,d 就正好对应于 0.001 s,即一毫秒。这样,就可以轻松的将基于毫秒时长的 Linux 下 beep 调用翻译成 GRUB 2 的 play 调用了。

另外,这还可以用于 sleep。GRUB 2 提供的 sleep 分辨率只有一秒,但使用 play,让 pitch = 0 Hz,就曲线实现了毫秒级的 sleep 命令。

Categories: IT生活, Linux

服务器 SSH 端口再次变更 » « Buffalo WZR-HP-G450H 刷 OpenWRT

5 Comments

  1. 牛逼的比尔盖子啊 😐

  2. rss好像用digg reader订阅不了呢,似乎是没找到

发表评论

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Copyright © 2023 比尔盖子 博客

Theme by Anders NorenUp ↑