private void SetSampleDataToWasapiStart(int idx, WWFlacRWCS.FlacRW flac)
        {
            WWFlacRWCS.Metadata meta;
            flac.GetDecodedMetadata(out meta);

            mFromFormat = new DeviceFormat();
            mFromFormat.Set(meta.channels, meta.sampleRate,
                            WasapiCS.BitAndFormatToSampleFormatType(meta.bitsPerSample, meta.bitsPerSample, WasapiCS.BitFormatType.SInt));

            long totalBytes = meta.totalSamples * mDeviceFormat.BytesPerFrame();

            mWasapi.AddPlayPcmDataAllocateMemory(idx, totalBytes);

            mDecodedPcmOffs = 0;
        }
예제 #2
0
        private int SetSampleDataToWasapiStart(int idx, WWFlacRWCS.FlacRW flac)
        {
            int hr = 0;

            mDecodedPcmOffs = 0;

            WWFlacRWCS.Metadata meta;
            flac.GetDecodedMetadata(out meta);

            mFromFormat = new DeviceFormat();
            mFromFormat.Set(meta.channels, meta.sampleRate,
                            WasapiCS.BitAndFormatToSampleFormatType(
                                meta.bitsPerSample, meta.bitsPerSample, WasapiCS.BitFormatType.SInt),
                            WasapiCS.GetTypicalChannelMask(meta.channels));

            if (WasapiCS.ShareMode.Exclusive == mShareMode)
            {
                // 排他モードの時。サンプルレート変換しないので
                // サンプル数がFromと同じ。
                long totalBytes = meta.totalSamples * mDeviceFormat.BytesPerFrame();
                mWasapi.AddPlayPcmDataAllocateMemory(idx, totalBytes);
            }
            else
            {
                // 共有モードの時。サンプルレート変換する。
                long totalBytes = (meta.totalSamples * mDeviceFormat.SampleRate / mFromFormat.SampleRate) * mDeviceFormat.BytesPerFrame();
                mWasapi.AddPlayPcmDataAllocateMemory(idx, totalBytes);

                var resampleFrom = new WWMFResamplerCs.WWPcmFormat(WWMFResamplerCs.WWPcmFormat.SampleFormat.SF_Int,
                                                                   mFromFormat.NumChannels, mFromFormat.UseBitsPerSample(), mFromFormat.SampleRate,
                                                                   WasapiCS.GetTypicalChannelMask(mFromFormat.NumChannels), mFromFormat.ValidBitsPerSample());
                var resampleTo = new WWMFResamplerCs.WWPcmFormat(WWMFResamplerCs.WWPcmFormat.SampleFormat.SF_Float,
                                                                 mDeviceFormat.NumChannels, mDeviceFormat.UseBitsPerSample(), mDeviceFormat.SampleRate,
                                                                 mDeviceFormat.DwChannelMask, mDeviceFormat.ValidBitsPerSample());
                hr = mMfResampler.Init(resampleFrom, resampleTo, 60);
                if (hr < 0)
                {
                    Console.WriteLine("mMfResampler.Init() failed {0:X8}", hr);
                }
            }

            return(hr);
        }