Пример #1
0
        /// <summary>
        /// Set the media type based on values from BASS.DLL
        /// </summary>
        /// <param name="psc">The IGenericSampleConfig onto which we set the mediatype</param>
        override public void SetMediaType(IGenericSampleConfig psc)
        {
            int lFrequency = 0;
            int lVolume    = 0;
            int lPan       = 0;

            WaveFormatEx     w     = new WaveFormatEx();
            BASS_CHANNELINFO lInfo = new BASS_CHANNELINFO();

            Bass.BASS_ChannelGetInfo(m_fChan, lInfo);
            if ((lInfo.flags & (int)BASSStream.BASS_SAMPLE_8BITS) == (int)BASSStream.BASS_SAMPLE_8BITS)
            {
                w.wBitsPerSample = 8;
            }
            else
            {
                w.wBitsPerSample = 16;
            }
            Bass.BASS_ChannelGetAttributes(m_fChan, ref lFrequency, ref lVolume, ref lPan);

            w.cbSize          = (short)Marshal.SizeOf(typeof(WaveFormatEx));
            w.nChannels       = (short)lInfo.chans;
            w.nSamplesPerSec  = lFrequency;
            w.wFormatTag      = 1;
            w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;
            m_BytesPerSample  = (short)(w.nChannels * (w.wBitsPerSample / 8));
            m_Frequency       = lFrequency;
            m_Channels        = lInfo.chans;
            w.nBlockAlign     = (short)m_BytesPerSample;
            w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;

            AMMediaType amt = new AMMediaType();

            amt.majorType  = MediaType.Audio;
            amt.subType    = MediaSubType.PCM;
            amt.formatType = FormatType.WaveEx;
            amt.formatPtr  = Marshal.AllocCoTaskMem(w.cbSize);
            amt.formatSize = w.cbSize;
            Marshal.StructureToPtr(w, amt.formatPtr, false);

            int hr = psc.SetMediaTypeEx(amt, BUFSIZE);

            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(amt);
        }