/// <summary>
        /// Converts sample format to toFormat and returns new instance of PcmData.
        /// pcmFrom is not changed.
        /// </summary>
        /// <param name="toFormat">sample format to convert</param>
        /// <returns>Newly instanciated PcmData</returns>
        public PcmData Convert(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args)
        {
            if (args == null)
            {
                args = new BitsPerSampleConvArgs(NoiseShapingType.None);
            }

            var fromFormat = WasapiCS.BitAndFormatToSampleFormatType(pcmFrom.BitsPerSample, pcmFrom.ValidBitsPerSample,
                                                                     SampleFormatInfo.VrtToBft(pcmFrom.SampleValueRepresentationType));

            if (fromFormat == WasapiCS.SampleFormatType.Unknown ||
                toFormat == WasapiCS.SampleFormatType.Unknown)
            {
                return(null);
            }

            var newSampleArray = mConvert[(int)fromFormat][(int)toFormat](pcmFrom, toFormat, args);

            PcmData newPcmData = new PcmData();

            newPcmData.CopyHeaderInfoFrom(pcmFrom);
            newPcmData.SetFormat(pcmFrom.NumChannels,
                                 WasapiCS.SampleFormatTypeToUseBitsPerSample(toFormat),
                                 WasapiCS.SampleFormatTypeToValidBitsPerSample(toFormat), pcmFrom.SampleRate,
                                 SampleFormatInfo.BftToVrt(WasapiCS.SampleFormatTypeToBitFormatType(toFormat)), pcmFrom.NumFrames);
            newPcmData.SetSampleArray(newSampleArray);

            return(newPcmData);
        }
Esempio n. 2
0
 public bool IsNoiseShapingOrDitherCapable(PcmData pdFrom, WasapiCS.SampleFormatType toFormat)
 {
     return(mConv.IsConversionNoiseshapingOrDitherCapable(
                WasapiCS.BitAndFormatToSampleFormatType(pdFrom.BitsPerSample, pdFrom.ValidBitsPerSample,
                                                        SampleFormatInfo.VrtToBft(pdFrom.SampleValueRepresentationType)), toFormat));
 }
Esempio n. 3
0
        /// <summary>
        /// PcmDataの形式と、(共有・排他)、フォーマット固定設定から、
        /// デバイスに設定されるビットフォーマットを取得。
        ///
        /// これは、内容的にテーブルなので、テーブルにまとめたほうが良い。
        /// </summary>
        /// <returns>デバイスに設定されるビットフォーマット</returns>
        static public SampleFormatInfo CreateSetupSampleFormat(
            WasapiSharedOrExclusiveType sharedOrExclusive,
            BitsPerSampleFixType bitsPerSampleFixType,
            int bitsPerSample,
            int validBitsPerSample,
            PcmDataLib.PcmData.ValueRepresentationType vrt,
            int candidateId)
        {
            SampleFormatInfo sf = new SampleFormatInfo();

            if (sharedOrExclusive == WasapiSharedOrExclusiveType.Shared)
            {
                // 共有モード
                sf.bitsPerSample      = bitsPerSample;
                sf.validBitsPerSample = validBitsPerSample;
                sf.bitFormatType      = SampleFormatInfo.VrtToBft(vrt);
                return(sf);
            }

            // 排他モード
            switch (bitsPerSampleFixType)
            {
            case BitsPerSampleFixType.Sint16:
                sf.bitFormatType      = WasapiCS.BitFormatType.SInt;
                sf.bitsPerSample      = 16;
                sf.validBitsPerSample = 16;
                break;

            case BitsPerSampleFixType.Sint24:
                sf.bitFormatType      = WasapiCS.BitFormatType.SInt;
                sf.bitsPerSample      = 24;
                sf.validBitsPerSample = 24;
                break;

            case BitsPerSampleFixType.Sint32:
                sf.bitFormatType      = WasapiCS.BitFormatType.SInt;
                sf.bitsPerSample      = 32;
                sf.validBitsPerSample = 32;
                break;

            case BitsPerSampleFixType.Sint32V24:
                sf.bitFormatType      = WasapiCS.BitFormatType.SInt;
                sf.bitsPerSample      = 32;
                sf.validBitsPerSample = 24;
                break;

            case BitsPerSampleFixType.Sfloat32:
                sf.bitFormatType      = WasapiCS.BitFormatType.SFloat;
                sf.bitsPerSample      = 32;
                sf.validBitsPerSample = 32;
                break;

            case BitsPerSampleFixType.AutoSelect:
                WasapiCS.SampleFormatType sampleFormat = WasapiCS.SampleFormatType.Sint16;
                switch (validBitsPerSample)
                {
                case 16:
                    sampleFormat = mTryFormat16[candidateId];
                    break;

                case 24:
                default: /* ? */
                    sampleFormat = mTryFormat24[candidateId];
                    break;

                case 32:
                    sampleFormat = mTryFormat32[candidateId];
                    break;
                }

                sf.bitFormatType      = WasapiCS.BitFormatType.SInt;
                sf.bitsPerSample      = WasapiCS.SampleFormatTypeToUseBitsPerSample(sampleFormat);
                sf.validBitsPerSample = WasapiCS.SampleFormatTypeToValidBitsPerSample(sampleFormat);
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            return(sf);
        }