feat: C# Fur Elise player using Windows Beep API

This commit is contained in:
2026-09-21 10:58:32 +08:00
commit 7ece384453
5 changed files with 221 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
# FurElise C#
用 C# 控制台程序在 Windows 上演奏贝多芬《致爱丽丝》(Für Elise)。
## 原理
- 使用 Windows 内核 API `kernel32!Beep(frequency, duration)` 发声
- 乐谱数据用 `(音名, 时值)` 数组描述,`R` 表示休止
- 音名映射到平均律频率(如 `A4=440``E5=659``Ds5=622`
## 运行
### 方式 A:已编译程序
```powershell
dotnet FurElise.dll
# 或
.\FurElise.exe
```
### 方式 B:源码直接编译(.NET 10 csc
```powershell
$refDir = "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\10.0.12\ref\net10.0"
$refs = (Get-ChildItem "$refDir\*.dll" | ForEach-Object { "-r:`"$($_.FullName)`"" }) -join ' '
dotnet exec "C:\Program Files\dotnet\sdk\10.0.401\Roslyn\bincore\csc.dll" `
-nologo -t:exe -out:FurElise.dll $refs Program.cs
# 复制 runtimeconfig.json 后
dotnet FurElise.dll
```
### 方式 Cdotnet run(需可用的 SDK/NuGet
```powershell
dotnet run --project FurElise.csproj
```
## 参数
| 参数 | 说明 | 默认 |
|------|------|------|
| `--dry-run` | 只打印音符与频率,不发声 | 关 |
| `--bpm <n>` | 速度(四分音符 BPM | 72 |
| `--loops <n>` | 重复次数 | 1 |
| `--help` | 帮助 | |
示例:
```powershell
.\FurElise.exe --dry-run
.\FurElise.exe --bpm 90 --loops 2
```
## 说明
- 仅 Windows(依赖 `Beep` API);无声卡驱动策略时部分环境可能无声音
- 旋律为主题段落的简化编配,适合教学演示
- 请勿在文章/仓库中提交站点账号密码
## License
MIT