小编hos*_*ein的帖子

如何从实时流中播放音频

我有一个程序可以产生应该同时播放的音频信号.为此,我在每100 ms周期内播放100 ms的音频流间隔.但是我在每个100毫秒音频流的开始和结束时都有不需要的信号(因为DC),因此即使信号值相同,输出声音也不平滑.我的代码附在下面.请帮助我做一些正确的实时音频.

using System;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using System.IO;

namespace TestSound
{
    class CSound : Form
    {
        const int HEADER_SIZE = 44;
        const bool FLAG_STEREO = true;
        const short BITS_PER_SAMPLE = 16;
        const int SAMPLE_RATE = 44100;

        int numberOfSamples;
        MemoryStream stream;
        BinaryWriter writer;
        Device ApplicationDevice = null;
        SecondaryBuffer buffer = null;
        BufferDescription description;

        public CSound()
        {
            try
            {
                ApplicationDevice = new Device();
            }
            catch
            {
                MessageBox.Show("Unable to create sound device.");
                ApplicationDevice = null;
                return;
            }
            ApplicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
            description …
Run Code Online (Sandbox Code Playgroud)

c# multimedia

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

multimedia ×1