播放圣诞曲调的邮政编码

发布于 2024-07-10 10:44:04 字数 1454 浏览 8 评论 0原文

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

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

发布评论

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

评论(6

弄潮 2024-07-17 10:44:05
PLAY "e4 e4 e2 e4 e4 e2 e4 g4 c4 d4 e2"
PLAY "e4 e4 e2 e4 e4 e2 e4 g4 c4 d4 e2"
ぃ弥猫深巷。 2024-07-17 10:44:05

动态生成 PCM 数据怎么样? PCM - 脉冲编码调制 - 声音只是模拟声音系统上的一堆电压样本。

考虑一下扬声器。 播放声音时,它会振动。 如果您拿一把尺子并以比声音频率更快的速度测量扬声器的位置会怎样? 您将获得波形图片。 这正是 PCM 数据的样子,每个测量值都存储为 8 或 16 位整数。 频率(例如 44khz)是每秒的样本数。 CD 使用 44khz 采样频率和 16 位样本。

DirectSound(在 Windows 上)和 OpenAL(跨平台)是两个库,可用于播放充满 PCM 数据的数据缓冲区。 我过去使用过 DirectSound,不是为了播放数据,而是从麦克风读取数据来获取音量级别。

如果您想为某个音符创建 PCM 样本,您只需计算频率(这里有一个 ),然后将正弦波放入缓冲区中。 您只需将不同的频率相加即可将它们混合在一起(确保总和小于最大音量,以避免削波)

What about generating PCM data on the fly? PCM - Pulse Code Modulated - sound is just a bunch of samples of voltage across an analog sound system.

Think about a speaker. As sound is played, it vibrates. What if you took a ruler and measured the location of the speaker at a rate faster then the frequency of the sound? You would get a picture of a waveform. That's exactly what PCM data looks like, with each measurement stored as an 8 or 16 bit int. The frequency, say 44khz is the number of samples per second. CDs use 44khz sampling frequency and 16 bit samples.

DirectSound (on windows) and OpenAL (cross platform) are two libraries you can use to play databuffers full of PCM data. I've used DirectSound in the past, not to play data but rather to read in data from the microphone to get the volume level.

If you wanted to create a PCM sample for a certain note, you just calculate the frequency (here's a table), and then put a sinewave in your buffer. You can mix different frequencies together just by adding them (make sure the sum is less then the maximum volume, to avoid clipping)

狼性发作 2024-07-17 10:44:05

MIDI 是一个选项,尽管在 PC 上它通常听起来几乎和蜂鸣声一样糟糕。

MIDI is an option, although on a PC it usually sounds almost as bad as beep.

探春 2024-07-17 10:44:04

java 中的“Jingle Bells”(像往常一样臃肿),使用 JFugue,带有管铃和木琴(复调!) :

import org.jfugue.*;

public class JingleBells
{
    public static void main(String[] args)
    {
        Player player = new Player();
        player.play("T170 "+
                    "     V0 I[XYLOPHONE] C4q C4q C3h C4q C4q C3h C3q B3q A3q G3q C4h "+
                    "     V1 I[TUBULAR_BELLS] E5q E5q E5h E5q E5q E5h E5q G5q C5q D5q Eqh "+
                    "     V2 I[XYLOPHONE] G3h     G2q G3q G3h     G3h");
    }
}

"Jingle Bells" in java (bloated as usual), using JFugue, with tubular bells and xylophones (polyphonic!):

import org.jfugue.*;

public class JingleBells
{
    public static void main(String[] args)
    {
        Player player = new Player();
        player.play("T170 "+
                    "     V0 I[XYLOPHONE] C4q C4q C3h C4q C4q C3h C3q B3q A3q G3q C4h "+
                    "     V1 I[TUBULAR_BELLS] E5q E5q E5h E5q E5q E5h E5q G5q C5q D5q Eqh "+
                    "     V2 I[XYLOPHONE] G3h     G2q G3q G3h     G3h");
    }
}
娇女薄笑 2024-07-17 10:44:04

说到“就像嘟嘟声一样糟糕”,如果您有嘟嘟声安装在你的 Linux 机器上,你可以运行以下 shell 脚本(与 Jeremy Ruten 的答案相同):

#!/bin/sh
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 800
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 800
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 783 -l 400
sleep 0.05
beep -f 523 -l 400
sleep 0.05
beep -f 587 -l 400
sleep 0.05
beep -f 659 -l 800

Speaking of "as bad as beep", if you have beep installed on your linux box, you can run the following shell script (in the same vein as Jeremy Ruten's answer):

#!/bin/sh
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 800
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 659 -l 800
sleep 0.05
beep -f 659 -l 400
sleep 0.05
beep -f 783 -l 400
sleep 0.05
beep -f 523 -l 400
sleep 0.05
beep -f 587 -l 400
sleep 0.05
beep -f 659 -l 800
白首有我共你 2024-07-17 10:44:04

是的,您可以播放 midi。

Midi 本身并不对声音进行编码,而是对用于播放音乐的信息进行编码; "

codeplex 上有一个 C# midi 工具包:

声音的质量完全取决于播放它的 MIDI 设备,因此不同计算机的质量会有所不同。

您可以在以下位置找到圣诞节 midi 文件的不错列表: http://www.lockergnome.com/midi/< /a>

Windows Media Player 可以像 Quick Time 一样播放 midi 文件(我相信)。

Yes, you can play midi.

Midi doesn't encode sounds per se, it encodes information used to play music; the pitch, tone, intensity, etc.

There is a C# midi toolkit on codeplex at :http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx

The quality of the sound depends entirely on the midi device used to play it, so it will vary in quality from computer to computer.

You can find a nice list of Christmas midi files at: http://www.lockergnome.com/midi/

Windows Media Player can play midi files as can Quick Time (I believe).

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