如何将提示/标记写入.NET中的WAV文件 [英] How to write cues/markers to a WAV file in .NET

查看:91
本文介绍了如何将提示/标记写入.NET中的WAV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#将提示(即基于时间的标记,而不是类似ID3的标记)写入WAV文件.似乎免费的.NET音频库(例如NAudio和Bass.NET)不支持此功能.

I'd like write cues (i.e. time-based markers, not ID3-like tags) to a WAV file with C#. It seems that the free .NET audio libraries such as NAudio and Bass.NET don't support this.

我已经找到了 Cue工具的来源,但是它完全没有文档记录,而且相对复杂.有其他选择吗?

I've found the source of Cue Tools, but it's entirely undocumented and relatively complex. Any alternatives?

推荐答案

以下是一个链接,解释了WAV文件中cue块的格式:

Here's a link that explains the format of a cue chunk in a WAV file:

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

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

Because a WAV file uses the RIFF format, you can simply append the cue chunk to the end of an existing WAV file. To do this in .Net, you would open a System.IO.FileStream object, using the constructor that takes a path and a FileMode (you would use FileMode.Append for this purpose). You would then create a BinaryWriter from your FileStream, and use it to write the cue chunk itself.

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

Here is a rough code sample to append a cue chunk with a single cue point to the end of a WAV file:

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#编写代码.

Note: I have never used or tested this code, so I am not sure if it works quite right. It is just intended to give you a rough idea of how to write this in C#.

这篇关于如何将提示/标记写入.NET中的WAV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆