예제 #1
0
        public static WaveFormat SuggestFormat(WaveFormat sourceFormat)
        {
            WaveFormat result = new WaveFormat(sourceFormat.SampleRate, 16, sourceFormat.Channels); //todo: 16bits fix

            AcmException.Try(AcmInterop.acmFormatSuggest(IntPtr.Zero, sourceFormat, result,
                                                         Marshal.SizeOf(result), AcmFormatSuggestFlags.FormatTag), "acmFormatSuggest");
            return(result);
        }
예제 #2
0
        public void BeginConvert()
        {
            _header.cbStruct = Marshal.SizeOf(_header);
            SetupHeader(_header);

            MmException.Try(AcmInterop.acmStreamPrepareHeader(
                                _handle, _header), "acmStreamPrepareHeader");
        }
예제 #3
0
        public AcmResult EndConvert()
        {
            SetupHeader(_header);

            MmException.Try(AcmInterop.acmStreamUnprepareHeader(
                                _handle, _header), "acmStreamUnprepareHeader");

            return(new AcmResult(_header.inputBufferLengthUsed, _header.outputBufferLengthUsed,
                                 _header.outputBufferLengthUsed == _destinationBuffer.Length, _destinationBuffer));
        }
예제 #4
0
        private AcmDriverDetails GetDetails(IntPtr driverHandle)
        {
            AcmDriverDetails result = new AcmDriverDetails();

            result.cbStruct = Marshal.SizeOf(result);
            var r = AcmInterop.acmDriverDetails(driverHandle, ref result, IntPtr.Zero);

            MmException.Try(r, "acmDriverDetails");
            return(result);
        }
예제 #5
0
        public static int StreamSize(IntPtr acmStreamHandle, int value, AcmStreamSizeFlags flags)
        {
            if (value == 0)
            {
                return(0);
            }
            int tmp = 0;

            AcmException.Try(AcmInterop.acmStreamSize(
                                 acmStreamHandle,
                                 value,
                                 out tmp,
                                 flags), "acmStreamSize");
            return(tmp);
        }
예제 #6
0
        public void Convert(byte[] sourceBuffer, int count)
        {
            if (count % _sourceFormat.BlockAlign != 0 || count == 0)
            {
                Debug.WriteLine("No valid number of bytes to convert. Parameter: count");
                count -= (count % _sourceFormat.BlockAlign);
            }

            Array.Copy(sourceBuffer, _sourceBuffer, count);

            _header.inputBufferLength     = count;
            _header.inputBufferLengthUsed = count;

            AcmException.Try(AcmInterop.acmStreamConvert(
                                 _handle, _header, _flags), "acmStreamConvert");
            _flags = AcmConvertFlags.ACM_STREAMCONVERTF_BLOCKALIGN;
        }
예제 #7
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (_handle != IntPtr.Zero)
                {
                    AcmInterop.acmStreamClose(_handle);
                    _handle = IntPtr.Zero;
                }

                if (_header != null)
                {
                    _header.Dispose();
                    _header = null;
                }
            }
            _disposed = true;
        }
예제 #8
0
        public AcmBufferConverter(WaveFormat sourceFormat, WaveFormat destinationFormat, IntPtr driver)
        {
            AcmException.Try(AcmInterop.acmStreamOpen(
                                 out _handle,
                                 driver,
                                 sourceFormat,
                                 destinationFormat,
                                 null,
                                 IntPtr.Zero,
                                 IntPtr.Zero,
                                 AcmStreamOpenFlags.ACM_STREAMOPENF_NONREALTIME),
                             "acmStreamOpen");

            int sourceBufferSize = Math.Max(UInt16.MaxValue + 1 /*65536*/, sourceFormat.BytesPerSecond);

            sourceBufferSize -= (sourceBufferSize % sourceFormat.BlockAlign);

            int destinationBufferSize = StreamSize(_handle, sourceBufferSize, AcmStreamSizeFlags.Input);

            _header = new AcmHeader(_handle, sourceFormat, sourceBufferSize, destinationBufferSize);
        }