Esempio n. 1
0
        public OutBuffer(IntPtr WaveOut, WAVEFORMATEX Format, int Count) : base(Format, Count)
        {
            waveOut = WaveOut;

            MmException.CheckThrow(Winmm.waveOutPrepareHeader(WaveOut, header, Marshal.SizeOf(header)));
            header.dwFlags |= WaveHdrFlags.WHDR_DONE;
        }
Esempio n. 2
0
        private static int BlockAlignedSize(WAVEFORMATEX Format, int Count)
        {
            int align = Format.nBlockAlign;
            int size  = Count * Format.wBitsPerSample / 8;

            return(size + (align - (size % align)) % align);
        }
Esempio n. 3
0
        public OutBuffer(IntPtr WaveOut, WAVEFORMATEX Format, int Count)
            : base(Format, Count)
        {
            waveOut = WaveOut;

            MmException.CheckThrow(Winmm.waveOutPrepareHeader(WaveOut, ref header, Marshal.SizeOf(header)));
            header.dwFlags |= WaveHdrFlags.WHDR_DONE;
        }
Esempio n. 4
0
        private static void ConvertSamples(IntPtr In, IntPtr Out, WAVEFORMATEX Format, int Count)
        {
            switch (Format.wBitsPerSample)
            {
            case 16: Audio.Util.LEf64ToLEi16(In, Out, Count); break;

            case 32: Audio.Util.LEf64ToLEi32(In, Out, Count); break;

            default: throw new NotImplementedException("Unsupported sample type.");
            }
        }
Esempio n. 5
0
        public WaveOut(int Device, WAVEFORMATEX Format, int BufferSize)
        {
            Log.Global.WriteLine(MessageType.Info, "Opening wave out device '{0}'.", Device);

            // Construct waveOut
            MmException.CheckThrow(Winmm.waveOutOpen(out waveOut, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveOutOpenFlags.CALLBACK_NULL));

            // Create buffers.
            buffers = new List<OutBuffer>();
            for (int i = 0; i < 4; ++i)
                buffers.Add(new OutBuffer(waveOut, Format, BufferSize));
        }
Esempio n. 6
0
        public WaveOut(int Device, WAVEFORMATEX Format, int BufferSize)
        {
            Log.Global.WriteLine(MessageType.Info, "Opening wave out device '{0}'.", Device);

            // Construct waveOut
            MmException.CheckThrow(Winmm.waveOutOpen(out waveOut, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveOutOpenFlags.CALLBACK_NULL));

            // Create buffers.
            buffers = new List <OutBuffer>();
            for (int i = 0; i < 4; ++i)
            {
                buffers.Add(new OutBuffer(waveOut, Format, BufferSize));
            }
        }
Esempio n. 7
0
        public Buffer(WAVEFORMATEX Format, int Count)
        {
            handle = GCHandle.Alloc(this);

            size = BlockAlignedSize(Format, Count);
            samples = new Audio.SampleBuffer(Count) { Tag = this };

            header = new WAVEHDR();
            header.lpData = Marshal.AllocHGlobal(size);
            header.dwUser = (IntPtr)handle;
            header.dwBufferLength = (uint)size;
            header.dwFlags = 0;
            pin = GCHandle.Alloc(header, GCHandleType.Pinned);
        }
Esempio n. 8
0
        public Stream(SampleHandler SampleCallback, Channel[] Input, Channel[] Output, double Latency) : base(Input, Output)
        {
            callback = SampleCallback;

            int Rate     = 48000;
            int Bits     = 16;
            int Channels = 1;

            format = new WAVEFORMATEX(Rate, Bits, Channels);

            buffer  = (int)Math.Ceiling(Latency / 2 * Rate * Channels);
            waveIn  = Input.Select(i => new WaveIn(i.Device, format, buffer)).ToArray();
            waveOut = Output.Select(i => new WaveOut(i.Device, format, buffer)).ToArray();

            proc = new Thread(new ThreadStart(Proc));
            proc.Start();
        }
Esempio n. 9
0
        public Buffer(WAVEFORMATEX Format, int Count)
        {
            samples = new Audio.SampleBuffer(Count)
            {
                Tag = this
            };

            int size = BlockAlignedSize(Format, Count);

            data                  = new byte[size];
            dataPin               = GCHandle.Alloc(data, GCHandleType.Pinned);
            header                = new WAVEHDR();
            headerPin             = GCHandle.Alloc(header, GCHandleType.Pinned);
            header.lpData         = dataPin.AddrOfPinnedObject();
            header.dwBufferLength = (uint)size;
            header.dwFlags        = 0;
        }
Esempio n. 10
0
        public Buffer(WAVEFORMATEX Format, int Count)
        {
            handle = GCHandle.Alloc(this);

            size    = BlockAlignedSize(Format, Count);
            samples = new Audio.SampleBuffer(Count)
            {
                Tag = this
            };

            header                = new WAVEHDR();
            header.lpData         = Marshal.AllocHGlobal(size);
            header.dwUser         = (IntPtr)handle;
            header.dwBufferLength = (uint)size;
            header.dwFlags        = 0;
            pin = GCHandle.Alloc(header, GCHandleType.Pinned);
        }
Esempio n. 11
0
        public WaveIn(int Device, WAVEFORMATEX Format, int BufferSize)
        {
            Log.Global.WriteLine(MessageType.Info, "Opening wave in device '{0}'.", Device);

            // Construct waveIn
            MmException.CheckThrow(Winmm.waveInOpen(out waveIn, Device, ref Format, IntPtr.Zero, IntPtr.Zero, WaveInOpenFlags.CALLBACK_NULL));

            // Create buffers.
            buffers = new List <InBuffer>();
            for (int i = 0; i < 4; ++i)
            {
                InBuffer b = new InBuffer(waveIn, Format, BufferSize);
                b.Record();
                buffers.Add(b);
            }

            MmException.CheckThrow(Winmm.waveInStart(waveIn));
        }
Esempio n. 12
0
        public WaveIn(int Device, WAVEFORMATEX Format, int BufferSize)
        {
            Log.Global.WriteLine(MessageType.Info, "Opening wave in device '{0}'.", Device);

            // Construct waveIn
            MmException.CheckThrow(Winmm.waveInOpen(out waveIn, Device, ref Format, callback.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveInOpenFlags.CALLBACK_EVENT));

            // Create buffers.
            buffers = new List<InBuffer>();
            for (int i = 0; i < 4; ++i)
            {
                InBuffer b = new InBuffer(waveIn, Format, BufferSize);
                b.Record();
                buffers.Add(b);
            }

            MmException.CheckThrow(Winmm.waveInStart(waveIn));
        }
Esempio n. 13
0
 public static extern MMRESULT waveOutOpen(out IntPtr hWaveOut, int uDeviceID, ref WAVEFORMATEX lpFormat, IntPtr dwCallback, IntPtr dwInstance, WaveOutOpenFlags dwFlags);
Esempio n. 14
0
        public InBuffer(IntPtr WaveIn, WAVEFORMATEX Format, int Count) : base(Format, Count)
        {
            waveIn = WaveIn;

            MmException.CheckThrow(Winmm.waveInPrepareHeader(waveIn, ref header, Marshal.SizeOf(header)));
        }
Esempio n. 15
0
 public static extern MMRESULT waveInOpen(out IntPtr phwi, int uDeviceID, ref WAVEFORMATEX lpFormat, IntPtr dwCallback, IntPtr dwInstance, WaveInOpenFlags dwFlags);
Esempio n. 16
0
        private static int BlockAlignedSize(WAVEFORMATEX Format, int Count)
        {
            int align = Format.nBlockAlign;
            int size = Count * Format.wBitsPerSample / 8;

            return size + (align - (size % align)) % align;
        }