naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.5k stars 1.1k forks source link

Repeat one ISampleProvider by FollowedBy not work expected. #1095

Open toshiya14 opened 9 months ago

toshiya14 commented 9 months ago
var sampler = this.baseclip.GetSampler();
if (sampler == null)
{
    return null;
}

var restTime = this.Duration - this.baseclip.Duration;
while (restTime > 0)
{
    if (restTime >= this.baseclip.Duration)
    {
        sampler = sampler.FollowedBy(this.baseclip.GetSampler());
    }
    else
    {
        sampler = sampler.FollowedBy(
            this.baseclip.GetSampler().Take(TimeSpan.FromSeconds(restTime))
        );
    }
    restTime -= this.baseclip.Duration;
}
return sampler;

this.baseclip.GetSampler() would returns an ISamplerProvider from AudioFileReader. And the duration of the source audio file is 7 seconds.

After I repeated it to 600 seconds by the codes above. Then I use MediaFoundationEncoder.EncodeToAac with sampler.ToWaveProvider(). The result file is still with the duration of 7 seconds without repeating.