Example #1
0
        public static AudioEvent CreateInstance(IntPtr data, int dataLength, double timeStamp, WAVEFORMATEX wfx)
        {
            if (data == IntPtr.Zero || dataLength < 1)
                throw new ArgumentException("data is null or empty");

            AudioEvent anEvent = new AudioEvent(data, dataLength, timeStamp, wfx);

            return anEvent;
        }
Example #2
0
        private AudioEvent(IntPtr data, int dataLength, double timeStamp, WAVEFORMATEX wfx)
        {
            DataBuffer = new byte[dataLength];
            DataLength = dataLength;
            SampleTime = timeStamp;
            WaveFormat = wfx;

            //copy the data to the byte buffer
            Marshal.Copy(data, DataBuffer, 0, dataLength);
        }
Example #3
0
        public WaveOutputPort(int deviceID, WAVEFORMATEX wf)
        {
            fCallbackMethod = new WaveCallback(this.DefaultAudioCallback);

            DeviceHandle = null;
            DeviceID = deviceID;
            WaveFormat = wf;
            PCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf);
            
            Open();
        }
Example #4
0
        public static double GetAmplitudeRange(WAVEFORMATEX wfx)
        {
            double maxRange = 0;

            if (16 == wfx.wBitsPerSample)
                maxRange = short.MaxValue/2;
            if (8 == wfx.wBitsPerSample)
                maxRange = byte.MaxValue/2;

            return maxRange;
        }
Example #5
0
        public WinMMAudioDevice(int deviceID, WAVEFORMATEX wf)
        {
            fCallbackMethod = new WaveCallback(this.DefaultAudioCallback);

            fDeviceHandle = IntPtr.Zero;
            fDeviceID = deviceID;
            fWaveFormat = wf;
            fPCMFormat = PCMAudioFormat.CreateFromWaveFormat(wf);

            //if (callbackProc != null)
            //    fCallbackProcedure = callbackProc;
            //else
            //    fCallbackProcedure = DefaultAudioCallback;
        }
Example #6
0
        public static WAVEFORMATEX CreatePCMFormat(int channels, int sampleRate, int bitsPerSample)
        {
            int bytesPerSample = bitsPerSample / 8;
            WAVEFORMATEX wfx = new WAVEFORMATEX();

            wfx.wFormatTag = WAVEFORMAT.WAVE_FORMAT_PCM;
            wfx.nChannels = (short)channels;
            wfx.wBitsPerSample = (ushort)bitsPerSample;      // 8 or 16
            wfx.nSamplesPerSec = (ushort)sampleRate;

            wfx.nAvgBytesPerSec = (int)(sampleRate * channels * bytesPerSample);
            wfx.nBlockAlign = (short)(channels * bytesPerSample);

            wfx.cbSize = 0;

            return wfx;
        }
Example #7
0
 public WaveInputPort(int deviceID, WAVEFORMATEX wf, double latency)
     :this(deviceID, wf.nChannels, wf.nSamplesPerSec, wf.wBitsPerSample, latency)
 {
 }
Example #8
0
        public static PCMAudioFormat CreateFromWaveFormat(WAVEFORMATEX wfx)
        {
            PCMAudioFormat af = new PCMAudioFormat(wfx.nChannels, wfx.wBitsPerSample, (int)wfx.nSamplesPerSec);

            return af;
        }
Example #9
0
 public static extern int SendMessageW([In] IntPtr hWnd, int Msg, uint wParam, ref WAVEFORMATEX waveFormat);
Example #10
0
 public int capGetAudioFormat(ref WAVEFORMATEX s, int wSize)
 {
     int retValue = SendMessageW(fWindowHandle, Vfw.WM_CAP_GET_AUDIOFORMAT, (uint)wSize, ref s);
     return retValue;
 }
Example #11
0
 public bool capSetAudioFormat(ref WAVEFORMATEX s, int wSize)
 {
     return 1 == SendMessageW(fWindowHandle, Vfw.WM_CAP_SET_AUDIOFORMAT, (uint)wSize, ref s);
 }