降噪和压缩的音频流 [英] Noise reduction and compression in streaming audio

查看:185
本文介绍了降噪和压缩的音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望能帮到你。我记录从麦克风音频并通过网络实时流式传输的。该样品的质量是11025hz,8位,单声道。虽然有小的延迟(1秒),它的伟大工程。我所需要的帮助是我想现在实现降噪和压缩,使声音更安静,使用更少的带宽。音频样本存储在字节[],这我送/采用Socket接收的C#阵列。

hope you can help. I am recording audio from a microphone and streaming it live across a network. The quality of the samples is 11025hz, 8 bit, mono. Although there is a small delay (1 second), it works great. What I need help with is I am trying to now implement noise reduction and compression, to make the audio quieter and use less bandwidth. The audio samples are stored in a C# array of bytes[], which I am sending/receiving using Socket.

任何人都可以建议如何在C#中,实施压缩和降低噪音?我不介意使用第三方库,只要它是免费的(LGPL许可证等),可以从C#中使用。不过,我宁愿实际工作的源代码示例。预先感谢您有任何建议。

Could anyone suggest how, in C#, to implement compression and noise reduction? I do not mind using a third party library as long as it is free (LGPL license, etc) and can be utilized from C#. However, I would prefer actual working source code examples. Thanks in advance for any suggestion you have.

更新:

我改变了位大小从8位音频16比特音频和噪音问题是固定的。 Apprarently从话筒8位音频有过低信噪比。声音听起来在11KHZ,16位单声道很大。

I changed the bit size from 8 bit audio to 16 bit audio and the noise problem is fixed. Apprarently 8 bit audio from mic had too low signal-to-noise ratio. Voice sounds great at 11khz, 16 bit mono.

本项目的要求也因为我张贴这种改变不过,。我们现在正在尝试添加视频以及。我有接收从摄像头每100ms实况图像的回调设置。我需要来编码的音频和视频,混流,发送它们对我的插座到服务器,该服务器重新发送该流至另一端,它接收所述流,解复用器流和解码的音频和视频,播放视频中一个图片框和输出音频的扬声器。

The requirements of this project have changed since I posted this, however. We are now trying to add video as well. I have a callback setup that receives live images every 100ms from a webcam. I need to encode the audio and video, mux them, transmit them on my socket to the server, the server re-transmits the stream to the other client, which receives the stream, demuxes the stream and decodes the audio and video, displays the video in a picture box and outputs the audio to the speaker.

我在看ffmpeg的助阵与(DE | EN)编码/ [德]混流,而我也期待在SharpFFmpeg为C#互操作库ffmpeg的。

I am looking at ffmpeg to help out with the (de|en)coding/[de]muxing, and I am also looking at SharpFFmpeg as a C# interop library to ffmpeg.

我找不到这样做的任何很好的例子。我已经走遍了互联网所有星期,没有真正的运气。 !您可以提供任何帮助深表感谢。

I cannot find any good examples of doing this. I have scoured the Internet all week, with no real luck. Any help you can provide is much appreciated!

下面是一些代码,包括我的呼唤回来了MIC录音功能:

Here's some code, including my call back function for the mic recording:


        private const int AUDIO_FREQ = 11025;
        private const int CHANNELS = 1;
        private const int BITS = 16;
        private const int BYTES_PER_SEC = AUDIO_FREQ * CHANNELS * (BITS / 8);
        private const int BLOCKS_PER_SEC = 40;
        private const int BUFFER_SECS = 1;
        private const int BUF_SIZE = ((int)(BYTES_PER_SEC / BLOCKS_PER_SEC * BUFFER_SECS / 2)) * 2; // rounded to nearest EVEN number

        private WaveLib.WaveOutPlayer m_Player;
        private WaveLib.WaveInRecorder m_Recorder;
        private WaveLib.FifoStream m_Fifo;

        WebCam MyWebCam;

        public void OnPickupHeadset()
        {
            stopRingTone();
            m_Fifo = new WaveLib.FifoStream();

            WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(AUDIO_FREQ, BITS, CHANNELS);
            m_Player = new WaveLib.WaveOutPlayer(-1, fmt, BUF_SIZE, BLOCKS_PER_SEC,
                            new WaveLib.BufferFillEventHandler(PlayerCB));
            m_Recorder = new WaveLib.WaveInRecorder(-1, fmt, BUF_SIZE, BLOCKS_PER_SEC,
                            new WaveLib.BufferDoneEventHandler(RecorderCB));

            MyWebCam = null;
            try
            {
                MyWebCam = new WebCam();                
                MyWebCam.InitializeWebCam(ref pbMyPhoto, pbPhoto.Width, pbPhoto.Height);
                MyWebCam.Start();
            }
            catch { }

        }

        private byte[] m_PlayBuffer;
        private void PlayerCB(IntPtr data, int size)
        {
            try
            {
                if (m_PlayBuffer == null || m_PlayBuffer.Length != size)
                    m_PlayBuffer = new byte[size];

                if (m_Fifo.Length >= size)
                {
                    m_Fifo.Read(m_PlayBuffer, 0, size);
                }
                else
                {
                    // Read what we can 
                    int fifoLength = (int)m_Fifo.Length;
                    m_Fifo.Read(m_PlayBuffer, 0, fifoLength);

                    // Zero out rest of buffer
                    for (int i = fifoLength; i < m_PlayBuffer.Length; i++)
                        m_PlayBuffer[i] = 0;                        
                }

                // Return the play buffer
                Marshal.Copy(m_PlayBuffer, 0, data, size);
            }
            catch { }
        }


        private byte[] m_RecBuffer;
        private void RecorderCB(IntPtr data, int size)
        {
            try
            {
                if (m_RecBuffer == null || m_RecBuffer.Length != size)
                    m_RecBuffer = new byte[size];
                Marshal.Copy(data, m_RecBuffer, 0, size);

                // HERE'S WHERE I WOULD ENCODE THE AUDIO IF I KNEW HOW

                // Send data to server
                if (theForm.CallClient != null)
                {
                    SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                    args.SetBuffer(m_RecBuffer, 0, m_RecBuffer.Length);
                    theForm.CallClient.SendAsync(args);
                }
            }
            catch { }
        }

        //Called from network stack when data received from server (other client)
        public void PlayBuffer(byte[] buffer, int length)
        {
            try
            {
                //HERE'S WHERE I WOULD DECODE THE AUDIO IF I KNEW HOW

                m_Fifo.Write(buffer, 0, length); 
            }
            catch { }
        }



所以,我应该在哪里何去何从?

So where should I go from here?

推荐答案

在这里你的目标是一种相互排斥的。原因你11025Hz / 8位/单声道的WAV文件声音嘈杂(以嘶巨大的量)是因为他们的低采样率和比特分辨率(44100Hz / 16位/立体声是CD质量的音频标准)。

Your goals here are kind of mutually exclusive. The reason your 11025Hz/8bit/Mono WAV files sound noisy (with a tremendous amount of "hiss") is because of their low sample rate and bit resolution (44100Hz/16bit/Stereo is the standard for CD-quality audio).

如果您继续记录,并以该速率流,你将有嘈杂的声音 - 时期。只有这样,才能消除(或者其实只是减弱),这种噪音将上采样音频为44100Hz / 16位,然后在其上进行某种形式的降噪算法。这采样将不得不这样做,因为它在服务器上通过客户端应用程序执行,流意味着你会随后流式音频8X比原来的大之前(做在服务器上也将是毫无意义的,因为你会最好只在首位的密集格式)记录。

If you continue recording and streaming at that rate, you are going to have noisy audio - period. The only way to eliminate (or actually just attenuate) this noise would be to up-sample the audio to 44100Hz/16bit and then perform a noise reduction algorithm of some sort on it. This upsampling would have to be performed by the client application, since doing it on the server before streaming means you'd then be streaming audio 8X larger than your original (doing it on the server would also be utterly pointless, since you'd be better off just recording in the denser format in the first place).

您想要做的是记录你的原始音频的CD音质的格式,然后压缩它像MP3或的Ogg Vorbis的标准格式。看到这个早些时候问题:

What you want to do is to record your original audio in a CD-quality format and then compress it to a standard format like MP3 or Ogg Vorbis. See this earlier question:

http://stackoverflow.com/questions/203254/whats-the-best-audio-compression-library-for-net

更新:我没有使用过这一点,但:

Update: I haven't used this, but:

http://www.ohloh.net/p/OggVorbisDecoder

我想你需要一个编码器,但我couldn 找不到一个的Ogg Vorbis。我想你可以尝试编码的WMV格式,还有:

I think you need an encoder, but I couldn't find one for Ogg Vorbis. I think you could try encoding to the WMV format, as well:

http://www.discussweb.com/c-programming/1728-encoding-wmv-file-c-net.html

更新2:对不起,我流的知识水平是相当低的。如果我做这样的事情,你在做什么,我会(通过PInvoke的使用 avifil32.dll 方法),创建音频和静止图像的(未压缩)的AVI文件第一,然后将其压缩为MPEG格式(或其他格式标准 - YouTube有一个网页,他们谈论他们的首选格式,而且它可能很好用其中之一)。

Update 2: Sorry, my knowledge level of streaming is pretty low. If I were doing something like what you're doing, I would create an (uncompressed) AVI file from the audio and the still images (using avifil32.dll methods via PInvoke) first, then compress it to MPEG (or whatever format is standard - YouTube has a page where they talk about their preferred formats, and it's probably good to use one of these).

我不知道这是否会做你的需要,但此链接:

I'm not sure if this will do what you need, but this link:

http://csharpmagics.blogspot.com/

使用这个免费的播放器:

using this free player:

http://www.videolan.org/

可能会奏效。

这篇关于降噪和压缩的音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆