Пример #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 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);
        }
Пример #3
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;
        }
Пример #4
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);
        }