Пример #1
0
        /////////////////////////////////////////////////////////////////////////

        // HighPassWave

        //

        // 高通滤波

        //

        // 参数:Format —— 波形音频格式结构WAVEFORMATEX

        //      lpData —— 波形音频数据块指针

        //      dwDataLength —— 波形音频数据块大小

        //      fFrequencyPass —— 滤波频率阈值

        //

        // 无返回值

        /////////////////////////////////////////////////////////////////////////

        unsafe public static void HighPassWave(WAVEFORMATEX Format, byte[] data,

                                               int dwDataLength, float fFrequencyPass)

        {
            fixed(byte *lpData = data)
            {
                float fParam0, fParam1, fParam2;

                int nSamplesPerSec = Format.nSamplesPerSec;



                fParam0 = (20.0f / fFrequencyPass + 1.0f / nSamplesPerSec) /

                          (2.0f / fFrequencyPass + 1.0f / nSamplesPerSec);

                fParam1 = (-20.0f / fFrequencyPass + 1.0f / nSamplesPerSec) /

                          (2.0f / fFrequencyPass + 1.0f / nSamplesPerSec);

                fParam2 = (1.0f / nSamplesPerSec - 2.0f / fFrequencyPass) /

                          (2.0f / fFrequencyPass + 1.0f / nSamplesPerSec);



                PassWave(Format, lpData, dwDataLength, fFrequencyPass,

                         fParam0, fParam1, fParam2);
            }
        }
Пример #2
0
		/////////////////////////////////////////////////////////////////////////

		// LowPassWave

		//

		// 低通滤波

		//

		// 参数:Format —— 波形音频格式结构WAVEFORMATEX

		//      lpData —— 波形音频数据块指针

		//      dwDataLength —— 波形音频数据块大小

		//      fFrequencyPass —— 滤波频率阈值

		//

		// 无返回值

		/////////////////////////////////////////////////////////////////////////

		unsafe 	public static void LowPassWave(WAVEFORMATEX Format, byte[] data,             

			int dwDataLength, float fFrequencyPass)

		{

			fixed(byte* lpData=data)
			{
				float fParam0,fParam1,fParam2;

				int   nSamplesPerSec = Format.nSamplesPerSec;

 

				fParam0=(1.0f/nSamplesPerSec)/(2.0f/fFrequencyPass+

					1.0f/nSamplesPerSec);

				fParam1=fParam0;

				fParam2=(1.0f/nSamplesPerSec-2.0f/fFrequencyPass)/

					(2.0f/fFrequencyPass+1.0f/nSamplesPerSec);

 

				PassWave(Format, lpData, dwDataLength, fFrequencyPass, 

					fParam0, fParam1, fParam2);
			}

		}
Пример #3
0
		public WaveOut(int index,WAVEFORMATEX format,int buffersize,int buffer_count)//波形输出
		{
			this.m_fmt=format;
			this.m_outdex=index;
			m_buffersize=buffersize;
			m_outcb=new waveProc(this.waveOutProc);
			Debug.Assert(buffer_count>0 && buffer_count<65535);
			this.m_hs=new WAVEHDR[buffer_count];
			this.gchs=new GCHandle[buffer_count];
			for(int i=0;i<buffer_count;i++)
			{
				gchs[i]=GCHandle.Alloc(new byte[buffersize],GCHandleType.Pinned);
				WAVEHDR hdr=new WAVEHDR();
				hdr.dwBufferLength=buffersize;
				hdr.lpData=this.gchs[i].AddrOfPinnedObject();
				hdr.dwUser=i;
				this.m_hs[i]=hdr;
			}
			CheckError(waveOutOpen(ref m_out,m_outdex,ref m_fmt,m_outcb,0,0x00030000));
		}
Пример #4
0
 public WaveOut(int index, WAVEFORMATEX format, int buffersize, int buffer_count)     //波形输出
 {
     this.m_fmt    = format;
     this.m_outdex = index;
     m_buffersize  = buffersize;
     m_outcb       = new waveProc(this.waveOutProc);
     Debug.Assert(buffer_count > 0 && buffer_count < 65535);
     this.m_hs = new WAVEHDR[buffer_count];
     this.gchs = new GCHandle[buffer_count];
     for (int i = 0; i < buffer_count; i++)
     {
         gchs[i] = GCHandle.Alloc(new byte[buffersize], GCHandleType.Pinned);
         WAVEHDR hdr = new WAVEHDR();
         hdr.dwBufferLength = buffersize;
         hdr.lpData         = this.gchs[i].AddrOfPinnedObject();
         hdr.dwUser         = i;
         this.m_hs[i]       = hdr;
     }
     CheckError(waveOutOpen(ref m_out, m_outdex, ref m_fmt, m_outcb, 0, 0x00030000));
 }
Пример #5
0
		public WaveIn(int index,WAVEFORMATEX format,int buffersize,int buffer_count)
		{
			this.m_fmt=format;
			this.m_index=index;
			m_incb=new waveProc(this.waveInProc);
			Debug.Assert(buffer_count>0 && buffer_count<65535);
			
			this.m_hs=new WAVEHDR[buffer_count];
			this.gchs=new GCHandle[buffer_count];
		//	this.datas=new IntPtr[buffer_count];
			for(int i=0;i<buffer_count;i++)
			{
				gchs[i]=GCHandle.Alloc(new byte[buffersize],GCHandleType.Pinned);
			//	this.datas[i]=Marshal.AllocCoTaskMem(buffer_count);
				WAVEHDR hdr=new WAVEHDR();
				hdr.dwBufferLength=buffersize;
				hdr.lpData=this.gchs[i].AddrOfPinnedObject();
				hdr.dwUser=i;
				this.m_hs[i]=hdr;
			}
			CheckError(waveInOpen(ref m_in,m_index,ref m_fmt,m_incb,0,0x00030000));
			CheckError(waveInStart(m_in));
		}
Пример #6
0
        public WaveIn(int index, WAVEFORMATEX format, int buffersize, int buffer_count)
        {
            this.m_fmt   = format;
            this.m_index = index;
            m_incb       = new waveProc(this.waveInProc);
            Debug.Assert(buffer_count > 0 && buffer_count < 65535);

            this.m_hs = new WAVEHDR[buffer_count];
            this.gchs = new GCHandle[buffer_count];
            //	this.datas=new IntPtr[buffer_count];
            for (int i = 0; i < buffer_count; i++)
            {
                gchs[i] = GCHandle.Alloc(new byte[buffersize], GCHandleType.Pinned);
                //	this.datas[i]=Marshal.AllocCoTaskMem(buffer_count);
                WAVEHDR hdr = new WAVEHDR();
                hdr.dwBufferLength = buffersize;
                hdr.lpData         = this.gchs[i].AddrOfPinnedObject();
                hdr.dwUser         = i;
                this.m_hs[i]       = hdr;
            }
            CheckError(waveInOpen(ref m_in, m_index, ref m_fmt, m_incb, 0, 0x00030000));
            CheckError(waveInStart(m_in));
        }
Пример #7
0
        /////////////////////////////////////////////////////////////////////////

        // PassWave

        //

        // 滤波算法

        //

        // 参数:Format —— 波形音频格式结构WAVEFORMATEX

        //      lpData —— 波形音频数据块指针

        //      dwDataLength —— 波形音频数据块大小

        //      fFrequencyPass —— 滤波频率阈值

        //      fParam0, fParam1, fParam2 —— 滤波参数

        //

        // 无返回值

        /////////////////////////////////////////////////////////////////////////

        unsafe private static void PassWave(WAVEFORMATEX Format, byte *lpData,

                                            int dwDataLength, float fFrequencyPass,

                                            float fParam0, float fParam1, float fParam2)

        {
            float fXL0, fXL1, fYL1, fYL0;

            float fXR0, fXR1, fYR1, fYR0;

            int i;



            switch (Format.wBitsPerSample)

            {
            case 8:

                switch (Format.nChannels)

                {
                case 1:

                    fXL0 = (float)*(byte *)lpData;

                    fXL1 = fXL0;

                    fYL1 = fXL0;

                    for (i = 0; i < dwDataLength; i += sizeof(byte))

                    {
                        fXL0 = (float)*(byte *)(lpData + i);

                        fYL0 = fParam0 * fXL0 + fParam1 * fXL1 -

                               fParam2 * fYL1;

                        *(byte *)(lpData + i) = (byte)fYL0;

                        fXL1 = fXL0;

                        fYL1 = fYL0;
                    }

                    break;

                case 2:

                    fXL0 = (float)*(byte *)lpData;

                    fXL1 = fXL0;

                    fYL1 = fXL0;

                    fXR0 = (float)*(byte *)(lpData + sizeof(byte));

                    fXR1 = fXR0;

                    fYR1 = fXR0;

                    for (i = 0; i < dwDataLength; i += 2 * sizeof(byte))

                    {
                        fXL0 = (float)*(byte *)(lpData + i);

                        fYL0 = fParam0 * fXL0 + fParam1 * fXL1 -

                               fParam2 * fYL1;

                        *(byte *)(lpData + i) = (byte)fYL0;

                        fXL1 = fXL0;

                        fYL1 = fYL0;

                        fXR0 = (float)*(byte *)(lpData + i + sizeof(byte));

                        fYR0 = fParam0 * fXR0 + fParam1 * fXR1 -

                               fParam2 * fYR1;

                        *(byte *)(lpData + i + sizeof(byte)) = (byte)fYR0;

                        fXR1 = fXR0;

                        fYR1 = fYR0;
                    }

                    break;
                }

                break;

            case 16:

                switch (Format.nChannels)

                {
                case 1:

                    fXL0 = (float)*(short *)lpData;

                    fXL1 = fXL0;

                    fYL1 = fXL0;

                    for (i = 0; i < dwDataLength; i += 2)

                    {
                        fXL0 = (float)*(short *)(lpData + i);

                        fYL0 = fParam0 * fXL0 + fParam1 * fXL1 -

                               fParam2 * fYL1;

                        *(short *)(lpData + i) = (short)fYL0;

                        fXL1 = fXL0;

                        fYL1 = fYL0;
                    }

                    break;

                case 2:

                    fXL0 = (float)*(short *)lpData;

                    fXL1 = fXL0;

                    fYL1 = fXL0;

                    fXR0 = (float)*(short *)(lpData + sizeof(short));

                    fXR1 = fXR0;

                    fYR1 = fXR0;

                    for (i = 0; i < dwDataLength; i += 2 * sizeof(short))

                    {
                        fXL0 = (float)*(short *)(lpData + i);

                        fYL0 = fParam0 * fXL0 + fParam1 * fXL1 -

                               fParam2 * fYL1;

                        *(short *)(lpData + i) = (short)fYL0;

                        fXL1 = fXL0;

                        fYL1 = fYL0;

                        fXR0 = (float)*(short *)(lpData +

                                                 i + sizeof(short));

                        fYR0 = fParam0 * fXR0 + fParam1 * fXR1 -

                               fParam2 * fYR1;

                        *(short *)(lpData + i + sizeof(short)) =

                            (short)fYR0;

                        fXR1 = fXR0;

                        fYR1 = fYR0;
                    }

                    break;
                }

                break;
            }
        }
Пример #8
0
		private extern static int waveOutOpen(ref IntPtr phwo,int uDeviceID,
			ref WAVEFORMATEX pwfx, waveProc dwCallback,int dwInstance, int fdwOpen);
Пример #9
0
		/////////////////////////////////////////////////////////////////////////

		// PassWave

		//

		// 滤波算法

		//

		// 参数:Format —— 波形音频格式结构WAVEFORMATEX

		//      lpData —— 波形音频数据块指针

		//      dwDataLength —— 波形音频数据块大小

		//      fFrequencyPass —— 滤波频率阈值

		//      fParam0, fParam1, fParam2 —— 滤波参数

		//

		// 无返回值

		/////////////////////////////////////////////////////////////////////////

		unsafe private static void PassWave(WAVEFORMATEX Format, byte* lpData, 

			int dwDataLength, float fFrequencyPass,

			float fParam0,float fParam1, float fParam2)

		{

			float fXL0,fXL1,fYL1,fYL0;

			float fXR0,fXR1,fYR1,fYR0;

			int i;

 

			switch(Format.wBitsPerSample)

			{

				case 8:

				switch(Format.nChannels)

				{

					case 1:

						fXL0=(float)*(byte *)lpData;

						fXL1=fXL0;

						fYL1=fXL0;

						for(i=0;i<dwDataLength;i+=sizeof(byte))

						{

							fXL0=(float)*(byte *)(lpData+i);

							fYL0=fParam0*fXL0+fParam1*fXL1-

								fParam2*fYL1;

							*(byte *)(lpData+i)=(byte)fYL0;

							fXL1=fXL0;

							fYL1=fYL0;

						}

						break;

					case 2:

						fXL0=(float)*(byte *)lpData;

						fXL1=fXL0;

						fYL1=fXL0;

						fXR0=(float)*(byte *)(lpData+sizeof(byte));

						fXR1=fXR0;

						fYR1=fXR0;

						for(i=0;i<dwDataLength;i+=2*sizeof(byte))

						{

							fXL0=(float)*(byte *)(lpData+i);

							fYL0=fParam0*fXL0+fParam1*fXL1-

								fParam2*fYL1;

							*(byte *)(lpData+i)=(byte)fYL0;

							fXL1=fXL0;

							fYL1=fYL0;

							fXR0=(float)*(byte *)(lpData+i+sizeof(byte));

							fYR0=fParam0*fXR0+fParam1*fXR1-

								fParam2*fYR1;

							*(byte *)(lpData+i+sizeof(byte))=(byte)fYR0;

							fXR1=fXR0;

							fYR1=fYR0;

						}

						break;

				}

					break;

				case 16:

				switch(Format.nChannels)

				{

					case 1:

						fXL0=(float)*(short *)lpData;

						fXL1=fXL0;

						fYL1=fXL0;

						for(i=0;i<dwDataLength;i+=2)

						{

							fXL0=(float)*(short *)(lpData+i);

							fYL0=fParam0*fXL0+fParam1*fXL1-

								fParam2*fYL1;

							*(short *)(lpData+i)=(short)fYL0;

							fXL1=fXL0;

							fYL1=fYL0;

						}

						break;

					case 2:

						fXL0=(float)*(short *)lpData;

						fXL1=fXL0;

						fYL1=fXL0;

						fXR0=(float)*(short *)(lpData+sizeof(short));

						fXR1=fXR0;

						fYR1=fXR0;

						for(i=0;i<dwDataLength;i+=2*sizeof(short))

						{

							fXL0=(float)*(short *)(lpData+i);

							fYL0=fParam0*fXL0+fParam1*fXL1-

								fParam2*fYL1;

							*(short *)(lpData+i)=(short)fYL0;

							fXL1=fXL0;

							fYL1=fYL0;

							fXR0=(float)*(short *)(lpData+

								i+sizeof(short));

							fYR0=fParam0*fXR0+fParam1*fXR1-

								fParam2*fYR1;

							*(short *)(lpData+i+sizeof(short))=

								(short)fYR0;

							fXR1=fXR0;

							fYR1=fYR0;

						}

						break;

				}

					break;

			}

		}
Пример #10
0
 private extern static int waveOutOpen(ref IntPtr phwo, int uDeviceID,
                                       ref WAVEFORMATEX pwfx, waveProc dwCallback, int dwInstance, int fdwOpen);