3

我想用 C# 将提示(即基于时间的标记,而不是类似 ID3 的标签)写入 WAV 文件。似乎 NAudio 和 Bass.NET 等免费的 .NET 音频库不支持这一点。

我找到了Cue Tools的来源,但它完全没有记录并且相对复杂。有什么选择吗?

4

1 回答 1

3

这是一个解释cueWAV 文件中块格式的链接:

http://www.sonicspot.com/guide/wavefiles.html#cue

因为 WAV 文件使用 RIFF 格式,所以您可以简单地将cue块附加到现有 WAV 文件的末尾。要在 .Net 中执行此操作,您将打开一个System.IO.FileStream对象,使用带有路径和 a 的构造函数FileMode(您将FileMode.Append用于此目的)。BinaryWriter然后,您将从您的中创建一个FileStream,并使用它来编写提示块本身。

这是一个粗略的代码示例,用于将cue带有单个提示点的块附加到 WAV 文件的末尾:

System.IO.FileStream fs = 
    new System.IO.FileStream(@"c:\sample.wav", 
    System.IO.FileMode.Append);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
char[] cue = new char[] { 'c', 'u', 'e', ' ' };
bw.Write(cue, 0, 4); // "cue "
bw.Write((int)28); // chunk size = 4 + (24 * # of cues)
bw.Write((int)1); // # of cues
// first cue point
bw.Write((int)0); // unique ID of first cue
bw.Write((int)0); // position
char[] data = new char[] { 'd', 'a', 't', 'a' };
bw.Write(data, 0, 4); // RIFF ID = "data"
bw.Write((int)0); // chunk start
bw.Write((int)0); // block start
bw.Write((int)500); // sample offset - in a mono, 16-bits-per-sample WAV
// file, this would be the 250th sample from the start of the block
bw.Close();
fs.Dispose();

注意:我从未使用或测试过这段代码,所以我不确定它是否工作得很好。它只是为了让您大致了解如何用 C# 编写它。

于 2009-10-11T14:48:42.540 回答