我正在使用Naudio并尝试生成一个代码,该代码获取一个音符列表(包括半音或四分音),并通过播放相应波形文件中的单个音符来播放它。 我可以在播放的每个wave文件的末尾听到声音剪辑
我编写的代码正常工作,但是我发现演奏的每个音符结尾处都有声音的剪切。任何建议如何解决这个问题?关于使用圆形缓冲器缓冲波浪然后进行演奏的任何建议?无论如何,我可以从头开始理解和使用naudio的循环缓冲区吗?
在以下代码中为。seeka.ladder是发送到要播放的8个音符的列表。 Eatch音符正在记录,并且根据其偶然的音调(半音或四分之一音调)将相应的音调播放之后
如果需要,我会提供完整的代码。
class Program
{
static void Main(string[] args)
{
var seeka = new Maqam(new Note()
{ Type = NoteType.E,Accedintal=AccedintalType.HBmol }, new int[] { 3, 4, 4, 3, 3, 4, 3 }, new int[] { 4, 4, 2, 4, 4, 4, 2 });
var player = new NotePlayer();
var path = @"C:\Users\ahmad\source\repos\OudPlayBack\OudPlayBack\Resources\"
+ note.Type.ToString().ToLower()+ note.Octave +".wav";
player.play(seeka.ForewardLadder);
}
}
public class NotePlayer
{
private double upOneQuartertone;
private double downOneQuartertone;
private double upOneSemitone;
private double downOneSemitone;
public NotePlayer()
{
upOneQuartertone = Math.Pow(2, 1.0 / 24);
downOneQuartertone = 1.0 / upOneQuartertone;
upOneSemitone = upOneQuartertone * upOneQuartertone;
downOneSemitone = 1 / upOneSemitone;
}
public void Play(Note note, string notePath)
{
var factor = SetFactor(note);
using (var reader = new MediaFoundationReader(notePath))
{
var pitch = new SmbPitchShiftingSampleProvider(reader.ToSampleProvider());
using (var device = new WaveOutEvent())
{
pitch.PitchFactor = (float)factor; // or downOneTone
// just playing the first 10 seconds of the file
device.Init(pitch.Take(TimeSpan.FromMilliseconds(500)));
device.Volume = 1;
device.Play();
var x = 0;
while (device.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(5);
x += 5;
}
Console.WriteLine(x);
}
}
}
public void play(List<Note> score)
{
foreach (var tempnote in score)
{
tempnote.Octave += 1;
var ipath = @"C:\Users\ahmad\source\repos\OudPlayBack\OudPlayBack\Resources\"
+ tempnote.Type.ToString().ToLower() + tempnote.Octave + ".wav";
this.Play(tempnote, ipath);
}
}
private double SetFactor(Note note)
{
double factor = 1.0;
switch (note.Accedintal)
{
case AccedintalType.Bmol:
factor = downOneSemitone;
break;
case AccedintalType.HBmol:
factor = downOneQuartertone;
break;
case AccedintalType.Natural:
break;
case AccedintalType.HDiaz:
factor = upOneQuartertone;
break;
case AccedintalType.Diaz:
factor = upOneSemitone;
break;
default:
break;
}
return factor;
}
}
该程序可以很好地运行并弹奏音符,但是声音上会出现明显的剪裁和混乱。在每个音符的末尾变得如此明显。是因为布置了播放器吗?并开始一个新的?如何解决这个?除了Naudio之外,还有什么更好的方法可以使用soundfonts或任何其他库来做到这一点?