【问题标题】:The end of an audio file that's looping?循环播放的音频文件结束了吗?
【发布时间】:2021-04-16 02:11:01
【问题描述】:

我正在尝试创建一个简单的音频 Looper 来录制我自己的歌曲。对于那些不知道音频 Looper 是什么的人,您首先录制一首歌曲的一层(比如说一段钢琴),然后开始循环该歌曲以在该层之上添加一块吉他。因为我已经知道如何将两者加在一起,所以这不是问题。但是我想保护我每次在该层之上添加的层,所以我必须检查我循环的音频文件是否正在重新启动。使用要添加的图层来保护第二个文件。之后将其混合在一起(因为您不能在 1 个文件中写入 2 个不同的流)并循环。

对于循环,我正在使用 System.Media 的 SoudPlayer 类。

Player = new SoundPlayer(path);
Player.PlayLooping();

int deviceNumber = sourceList.SelectedItems[0].Index;

sourceStream = new NAudio.Wave.WaveIn();
sourceStream.DeviceNumber = deviceNumber;
sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(open.FileName, sourceStream.WaveFormat);

sourceStream.StartRecording();

每次音频文件结束时,录音都应该停止。

提前致谢!

【问题讨论】:

    标签: c# loops naudio soundplayer


    【解决方案1】:

    你需要看看 NAudio documentation。

    我在录制 WAV 时经常添加的一项安全功能是限制 WAV 文件的大小。它们增长迅速,在任何情况下都不能超过 4GB。这里我会要求在 30 秒后停止录制:

    waveIn.DataAvailable += (s, a) =>
    {
        writer.Write(a.Buffer, 0, a.BytesRecorded);
        if (writer.Position > waveIn.WaveFormat.AverageBytesPerSecond * 30)
        {
            waveIn.StopRecording();
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多