本文整理汇总了C#中NAudio.Wave.WaveFileWriter.WriteData方法的典型用法代码示例。如果您正苦于以下问题:C# WaveFileWriter.WriteData方法的具体用法?C# WaveFileWriter.WriteData怎么用?C# WaveFileWriter.WriteData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveFileWriter
的用法示例。
在下文中一共展示了WaveFileWriter.WriteData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrimWavFile
private static void TrimWavFile(WaveFileReader reader, WaveFileWriter writer, int startPos, int endPos) {
reader.Position = startPos;
byte[] buffer = new byte[1024];
while (reader.Position < endPos) {
int bytesRequired = (int)(endPos - reader.Position);
if (bytesRequired > 0) {
int bytesToRead = Math.Min(bytesRequired, buffer.Length);
int bytesRead = reader.Read(buffer, 0, bytesToRead);
if (bytesRead > 0) {
writer.WriteData(buffer, 0, bytesRead);
}
}
}
}
示例2: CreateWaveFile
/// <summary>
/// Creates a Wave file by reading all the data from a WaveStream
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="stream">The source WaveStream</param>
public static void CreateWaveFile(string filename, WaveStream stream)
{
using (WaveFileWriter writer = new WaveFileWriter(filename, stream.WaveFormat))
{
byte[] buffer = new byte[stream.GetReadSize(4000)];
while (true)
{
int bytesRead = stream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
writer.WriteData(buffer, 0, bytesRead);
}
}
}
示例3: ApplyAutoTune
public static void ApplyAutoTune(string fileToProcess, string tempFile, AutoTuneSettings autotuneSettings)
{
using (WaveFileReader reader = new WaveFileReader(fileToProcess))
{
IWaveProvider stream32 = new Wave16toIeeeProvider(reader);
IWaveProvider streamEffect = new AutoTuneWaveProvider(stream32, autotuneSettings);
IWaveProvider stream16 = new WaveIeeeTo16Provider(streamEffect);
using (WaveFileWriter converted = new WaveFileWriter(tempFile, stream16.WaveFormat))
{
// buffer length needs to be a power of 2 for FFT to work nicely
// however, make the buffer too long and pitches aren't detected fast enough
// successful buffer sizes: 8192, 4096, 2048, 1024
// (some pitch detection algorithms need at least 2048)
byte[] buffer = new byte[8192];
int bytesRead;
do
{
bytesRead = stream16.Read(buffer, 0, buffer.Length);
converted.WriteData(buffer, 0, bytesRead);
} while (bytesRead != 0 && converted.Length < reader.Length);
}
}
}
示例4: ConvertSample
XSample ConvertSample(int count, SSampleHeader sh, byte [] sample, Zone izone)
{
// Indices in sf2 are numbers of samples, not byte length. So double them.
var xs = new XSample ();
xs.Extension = ".wav";
xs.LoopStart =(sh.StartLoop - sh.Start);
xs.LoopEnd = (sh.EndLoop - sh.Start);
int sampleModes = izone.SampleModes ();
xs.LoopMode = sampleModes == 0 ? InstrumentSampleLoopMode.Off : InstrumentSampleLoopMode.Forward;
xs.Name = String.Format ("Sample{0:D02} ({1})", count, sh.SampleName);
xs.BaseNote = (sbyte) izone.OverridingRootKey ();
// xs.Volume = (izone.VelocityRange () & 0xFF00 >> 8); // low range
if (xs.BaseNote == 0)
xs.BaseNote = (sbyte) sh.OriginalPitch;
//Console.WriteLine ("{0} ({1}/{2}/{3}/{4}) {5}:{6}:{7}:{8}", xs.Name, sh.Start, sh.StartLoop, sh.EndLoop, sh.End, sh.SampleRate != 0xAC44 ? sh.SampleRate.ToString () : "", sh.OriginalPitch != 60 ? sh.OriginalPitch.ToString () : "", sh.PitchCorrection != 0 ? sh.PitchCorrection.ToString () : "", sampleModes);
xs.FileName = xs.Name + ".wav";
var ms = new MemoryStream ();
var wfw = new WaveFileWriter (ms, new WaveFormat ((int) sh.SampleRate, 16, 1));
wfw.WriteData (sample, 2 * (int) sh.Start, 2 * (int) (sh.End - sh.Start));
wfw.Close ();
xs.Buffer = ms.ToArray ();
return xs;
}
示例5: ExportWAVBtnClick
void ExportWAVBtnClick(object sender, EventArgs e)
{
if(saveFileDialog1.ShowDialog() == DialogResult.OK) {
byte[] buf = MakeByteBuf();
WaveFileWriter wfw = new WaveFileWriter(saveFileDialog1.FileName, new WaveFormat(samplingRate, 8, 1));
wfw.WriteData(buf, 0, buf.Length);
wfw.Close();
}
}
示例6: processWave
/// <summary>
/// Load wave file and change its tempo, pitch and rate and save it to another file
/// </summary>
static void processWave(string fileIn, string fileOut, float newTempo, float newPitch, float newRate)
{
WaveFileReader reader = new WaveFileReader(fileIn);
int numChannels = reader.WaveFormat.Channels;
if (numChannels > 2)
throw new Exception("SoundTouch supports only mono or stereo.");
int sampleRate = reader.WaveFormat.SampleRate;
int bitPerSample = reader.WaveFormat.BitsPerSample;
const int BUFFER_SIZE = 1024 * 16;
SoundStretcher stretcher = new SoundStretcher(sampleRate, numChannels);
WaveFileWriter writer = new WaveFileWriter(fileOut, new WaveFormat(sampleRate, 16, numChannels));
stretcher.Tempo = newTempo;
stretcher.Pitch = newPitch;
stretcher.Rate = newRate;
byte[] buffer = new byte[BUFFER_SIZE];
short[] buffer2 = null;
if (bitPerSample != 16 && bitPerSample != 8)
{
throw new Exception("Not implemented yet.");
}
if (bitPerSample == 8)
{
buffer2 = new short[BUFFER_SIZE];
}
bool finished = false;
while (true)
{
int bytesRead = 0;
if (!finished)
{
bytesRead = reader.Read(buffer, 0, BUFFER_SIZE);
if (bytesRead == 0)
{
finished = true;
stretcher.Flush();
}
else
{
if (bitPerSample == 16)
{
stretcher.PutSamplesFromBuffer(buffer, 0, bytesRead);
}
else if (bitPerSample == 8)
{
for (int i = 0; i < BUFFER_SIZE; i++)
buffer2[i] = (short)((buffer[i] - 128) * 256);
stretcher.PutSamples(buffer2);
}
}
}
bytesRead = stretcher.ReceiveSamplesToBuffer(buffer, 0, BUFFER_SIZE);
writer.WriteData(buffer, 0, bytesRead);
if (finished && bytesRead == 0)
break;
}
reader.Close();
writer.Close();
}