private byte[] ConvF64toF32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { double dv = System.BitConverter.ToDouble(from, fromPos); float fv = (float)dv; if (SAMPLE_VALUE_MAX_FLOAT <= fv) { fv = SAMPLE_VALUE_MAX_FLOAT_TO_I24; IncrementClippedCounter(); } if (fv < SAMPLE_VALUE_MIN_FLOAT) { fv = SAMPLE_VALUE_MIN_FLOAT; IncrementClippedCounter(); } byte [] b = System.BitConverter.GetBytes(fv); to[toPos++] = b[0]; to[toPos++] = b[1]; to[toPos++] = b[2]; to[toPos++] = b[3]; fromPos += 8; } })); }
private byte[] ConvF64toI32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { double dv = System.BitConverter.ToDouble(from, fromPos); int iv = 0; if ((long)Int32.MaxValue < (long)(dv * Int32.MaxValue)) { iv = Int32.MaxValue; IncrementClippedCounter(); } else if ((long)(-dv * Int32.MinValue) < (long)Int32.MinValue) { iv = Int32.MinValue; IncrementClippedCounter(); } else { iv = (int)(-dv * Int32.MinValue); } to[toPos++] = (byte)((iv >> 0) & 0xff); to[toPos++] = (byte)((iv >> 8) & 0xff); to[toPos++] = (byte)((iv >> 16) & 0xff); to[toPos++] = (byte)((iv >> 24) & 0xff); fromPos += 8; } })); }
public void Set(int samplingRate, WasapiCS.SampleFormatType fmt, int numChannels, int latencyMillisec, int zeroFlushMillisec, WasapiDataFeedModeType dfm, WasapiSharedOrExclusiveType shareMode, RenderThreadTaskType threadTaskType, int resamplerConversionQuality, WasapiCS.StreamType streamType, WasapiCS.MMThreadPriorityType threadPriority) { this.setuped = true; this.samplingRate = samplingRate; this.sampleFormat = fmt; this.NumChannels = numChannels; this.latencyMillisec = latencyMillisec; this.zeroFlushMillisec = zeroFlushMillisec; this.dfm = dfm; this.shareMode = shareMode; this.threadTaskType = threadTaskType; this.ResamplerConversionQuality = resamplerConversionQuality; this.StreamType = streamType; this.ThreadPriority = threadPriority; }
private byte[] ConvF64toI24orI32V24(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; bool writePad = toFormat == WasapiCS.SampleFormatType.Sint32V24; for (int i = 0; i < nSample; ++i) { double dv = System.BitConverter.ToDouble(from, fromPos); if (SAMPLE_VALUE_MAX_DOUBLE <= dv) { dv = SAMPLE_VALUE_MAX_DOUBLE_TO_I24; IncrementClippedCounter(); } if (dv < SAMPLE_VALUE_MIN_DOUBLE) { dv = SAMPLE_VALUE_MIN_DOUBLE; IncrementClippedCounter(); } int iv = (int)(dv * 8388608.0); if (writePad) { to[toPos++] = 0; } to[toPos++] = (byte)(iv & 0xff); to[toPos++] = (byte)((iv >> 8) & 0xff); to[toPos++] = (byte)((iv >> 16) & 0xff); fromPos += 8; } })); }
private byte[] ConvF32toI32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { float fv = System.BitConverter.ToSingle(from, fromPos); if (SAMPLE_VALUE_MAX_FLOAT <= fv) { fv = SAMPLE_VALUE_MAX_FLOAT_TO_I24; IncrementClippedCounter(); } if (fv < SAMPLE_VALUE_MIN_FLOAT) { fv = SAMPLE_VALUE_MIN_FLOAT; IncrementClippedCounter(); } int iv = (int)(fv * 8388608.0f); to[toPos++] = 0; to[toPos++] = (byte)(iv & 0xff); to[toPos++] = (byte)((iv >> 8) & 0xff); to[toPos++] = (byte)((iv >> 16) & 0xff); fromPos += 4; } })); }
public bool CompatibleTo( int samplingRate, WasapiCS.SampleFormatType fmt, int numChannels, int latencyMillisec, int zeroFlushMillisec, WasapiDataFeedModeType dfm, WasapiSharedOrExclusiveType shareMode, RenderThreadTaskType threadTaskType, int resamplerConversionQuality, WasapiCS.StreamType streamType, WasapiCS.MMThreadPriorityType threadPriority) { return(this.setuped && this.samplingRate == samplingRate && SampleFormatIsCompatible(this.sampleFormat, fmt) && this.NumChannels == numChannels && this.latencyMillisec == latencyMillisec && this.ZeroFlushMillisec == zeroFlushMillisec && this.dfm == dfm && this.shareMode == shareMode && this.threadTaskType == threadTaskType && this.ResamplerConversionQuality == resamplerConversionQuality && this.StreamType == streamType && this.ThreadPriority == threadPriority); }
/// <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); }
public void Set(int numChannels, int sampleRate, WasapiCS.SampleFormatType sampleFormat, int dwChannelMask) { NumChannels = numChannels; SampleRate = sampleRate; SampleFormat = sampleFormat; DwChannelMask = dwChannelMask; }
/// <summary> /// 量子化ビット数を、もし必要なら変更する。 /// </summary> /// <param name="pd">入力PcmData</param> /// <returns>変更後PcmData</returns> public PcmData BitsPerSampleConvAsNeeded(PcmData pd, WasapiCS.SampleFormatType fmt, WasapiPcmUtil.PcmFormatConverter.BitsPerSampleConvArgs args) { switch (fmt) { case WasapiCS.SampleFormatType.Sfloat: // System.Console.WriteLine("Converting to Sfloat32bit..."); pd = mConv.Convert(pd, WasapiCS.SampleFormatType.Sfloat, args); break; case WasapiCS.SampleFormatType.Sint16: // System.Console.WriteLine("Converting to SInt16bit..."); pd = mConv.Convert(pd, WasapiCS.SampleFormatType.Sint16, args); break; case WasapiCS.SampleFormatType.Sint24: // System.Console.WriteLine("Converting to SInt24..."); pd = mConv.Convert(pd, WasapiCS.SampleFormatType.Sint24, args); break; case WasapiCS.SampleFormatType.Sint32V24: // System.Console.WriteLine("Converting to SInt32V24..."); pd = mConv.Convert(pd, WasapiCS.SampleFormatType.Sint32V24, args); break; case WasapiCS.SampleFormatType.Sint32: // System.Console.WriteLine("Converting to SInt32bit..."); pd = mConv.Convert(pd, WasapiCS.SampleFormatType.Sint32, args); break; default: System.Diagnostics.Debug.Assert(false); break; } return(pd); }
private byte[] ConvCommon(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args, ConversionLoop convLoop) { var from = pcmFrom.GetSampleArray(); long nSample = from.LongLength * 8 / pcmFrom.BitsPerSample; var to = new byte[nSample * WasapiCS.SampleFormatTypeToUseBitsPerSample(toFormat) / 8]; convLoop(from, to, nSample, args.noiseShaping); return(to); }
public bool IsConversionNoiseshapingOrDitherCapable(WasapiCS.SampleFormatType fromFormat, WasapiCS.SampleFormatType toFormat) { System.Diagnostics.Debug.Assert(0 <= (int)fromFormat && (int)fromFormat <= (int)WasapiCS.SampleFormatType.Sdouble); System.Diagnostics.Debug.Assert(0 <= (int)toFormat && (int)toFormat <= (int)WasapiCS.SampleFormatType.Sdouble); if (fromFormat == WasapiCS.SampleFormatType.Unknown || toFormat == WasapiCS.SampleFormatType.Unknown) { return(false); } return(mNoiseShapingOrDitherCapabilityTable[(int)fromFormat][(int)toFormat]); }
private static bool SampleFormatIsCompatible( WasapiCS.SampleFormatType lhs, WasapiCS.SampleFormatType rhs) { switch (lhs) { case WasapiCS.SampleFormatType.Sint24: case WasapiCS.SampleFormatType.Sint32V24: return(rhs == WasapiCS.SampleFormatType.Sint24 || rhs == WasapiCS.SampleFormatType.Sint32V24); default: return(lhs == rhs); } }
private byte[] ConvI16toI24(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { // Lower 8-bit: fill 0s to[toPos++] = 0; // Higher 16-bit: copy PCM to[toPos++] = from[fromPos++]; to[toPos++] = from[fromPos++]; } })); }
private byte[] ConvI32V24toI24(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { // truncate lower 8-bit of 32-bit PCM to create 24-bit PCM to[toPos++] = from[fromPos + 1]; to[toPos++] = from[fromPos + 2]; to[toPos++] = from[fromPos + 3]; fromPos += 4; } })); }
public int Setup(int deviceIdx, WasapiCS.DataFeedMode dfm, int wasapiBufferSize, int sampleRate, WasapiCS.SampleFormatType sampleFormatType, int numChannels, int dwChannelMask) { int hr = mWasapi.Setup(deviceIdx, WasapiCS.DeviceType.Rec, WasapiCS.StreamType.PCM, sampleRate, sampleFormatType, numChannels, dwChannelMask, WasapiCS.MMCSSCallType.Enable, WasapiCS.MMThreadPriorityType.None, WasapiCS.SchedulerTaskType.ProAudio, WasapiCS.ShareMode.Exclusive, dfm, wasapiBufferSize, 0, 10000, true); mSampleFormat = sampleFormatType; mSampleRate = sampleRate; mNumChannels = numChannels; mDeviceInUse = true; return(hr); }
private byte[] ConvI32V24toI32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { // discard lower 8-bit because it is garbage to[toPos++] = 0; to[toPos++] = from[fromPos + 1]; to[toPos++] = from[fromPos + 2]; to[toPos++] = from[fromPos + 3]; fromPos += 4; } })); }
private PcmDataLib.PcmData.ValueRepresentationType SampleFormatToVRT(WasapiCS.SampleFormatType t) { switch (t) { case WasapiCS.SampleFormatType.Sfloat: return(PcmDataLib.PcmData.ValueRepresentationType.SFloat); case WasapiCS.SampleFormatType.Sint16: case WasapiCS.SampleFormatType.Sint24: case WasapiCS.SampleFormatType.Sint32V24: case WasapiCS.SampleFormatType.Sint32: return(PcmDataLib.PcmData.ValueRepresentationType.SInt); default: System.Diagnostics.Debug.Assert(false); return(PcmDataLib.PcmData.ValueRepresentationType.SInt); } }
private LargeArray <byte> CreatePcmSamples(double[] mls, WasapiCS.SampleFormatType sft, int numCh, int playCh) { int sampleBytes = (WasapiCS.SampleFormatTypeToUseBitsPerSample(sft) / 8); int frameBytes = sampleBytes * numCh; long bytes = (long)mls.Length * frameBytes; var r = new LargeArray <byte>(bytes); long writePos = 0; for (long i = 0; i < mls.Length; ++i) { for (int ch = 0; ch < numCh; ++ch) { if (ch != playCh) { for (int c = 0; c < sampleBytes; ++c) { r.Set(writePos++, 0); } } else { int v = 0x7fffffff; // -6dBする。 v /= 2; if (mls[i] < 0) { v = -v; } uint uV = (uint)v; for (int c = 0; c < sampleBytes; ++c) { byte b = (byte)(uV >> (8 * (4 - sampleBytes + c))); r.Set(writePos++, b); } } } } return(r); }
/// <param name="peakHoldSec">-1のとき∞</param> /// <param name="updateIntervalSec">録音バッファー秒数を入れる。</param> public LevelMeter(WasapiCS.SampleFormatType sampleFormat, int ch, int peakHoldSec, double updateIntervalSec, int releaseTimeDbPerSec) { mSampleFormat = sampleFormat; mCh = ch; mPeakHoldSec = peakHoldSec; mLastPeakLevelDb = new double[ch]; mPeakCalcArray = new PeakCalculator[ch]; for (int i = 0; i < ch; ++i) { mLastPeakLevelDb[i] = -144; mPeakCalcArray[i] = new PeakCalculator((peakHoldSec < 0) ? -1 : (int)(peakHoldSec / updateIntervalSec)); } ReleaseTimeDbPerSec = releaseTimeDbPerSec; mSw.Reset(); mSw.Start(); }
private byte[] ConvF32toF64(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { float fv = System.BitConverter.ToSingle(from, fromPos); double dv = (double)fv; byte [] b = System.BitConverter.GetBytes(dv); for (int j = 0; j < 8; ++j) { to[toPos++] = b[j]; } fromPos += 4; } })); }
private byte[] ConvI16toF64(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { short iv = (short)(from[fromPos] + (from[fromPos + 1] << 8)); double dv = ((double)iv) * (1.0 / 32768.0); byte [] b = System.BitConverter.GetBytes(dv); for (int j = 0; j < 8; ++j) { to[toPos++] = b[j]; } fromPos += 2; } })); }
private byte[] ConvI16toF32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { short iv = (short)(from[fromPos] + (from[fromPos + 1] << 8)); float fv = ((float)iv) * (1.0f / 32768.0f); byte [] b = System.BitConverter.GetBytes(fv); to[toPos++] = b[0]; to[toPos++] = b[1]; to[toPos++] = b[2]; to[toPos++] = b[3]; fromPos += 2; } })); }
private byte[] ConvI32toF64(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { int iv = ((int)from[fromPos + 1] << 8) + ((int)from[fromPos + 2] << 16) + ((int)from[fromPos + 3] << 24); double dv = ((double)iv) * (1.0 / 2147483648.0); byte [] b = System.BitConverter.GetBytes(dv); for (int j = 0; j < 8; ++j) { to[toPos++] = b[j]; } fromPos += 4; } })); }
private byte[] ConvI32toF32(PcmData pcmFrom, WasapiCS.SampleFormatType toFormat, BitsPerSampleConvArgs args) { return(ConvCommon(pcmFrom, toFormat, args, (from, to, nSample, noiseShaping) => { int fromPos = 0; int toPos = 0; for (int i = 0; i < nSample; ++i) { int iv = ((int)from[fromPos + 1] << 8) + ((int)from[fromPos + 2] << 16) + ((int)from[fromPos + 3] << 24); float fv = ((float)iv) * (1.0f / 2147483648.0f); byte [] b = System.BitConverter.GetBytes(fv); to[toPos++] = b[0]; to[toPos++] = b[1]; to[toPos++] = b[2]; to[toPos++] = b[3]; fromPos += 4; } })); }
public void Set(int numChannels, int sampleRate, WasapiCS.SampleFormatType sampleFormat) { NumChannels = numChannels; SampleRate = sampleRate; SampleFormat = sampleFormat; }
private bool UpdateTestParamsFromUI() { if (!Int32.TryParse(textBoxTestFrames.Text, out mNumTestFrames) || mNumTestFrames <= 0) { MessageBox.Show(Properties.Resources.msgPcmSizeError); return false; } if (0x7fffffff / 8 / 1024 / 1024 < mNumTestFrames) { MessageBox.Show(string.Format(Properties.Resources.msgPcmSizeTooLarge, 0x70000000 / 8 / 1024 / 1024)); return false; } mNumTestFrames *= 1024 * 1024; if (radioButton44100.IsChecked == true) { mSampleRate = 44100; } if (radioButton48000.IsChecked == true) { mSampleRate = 48000; } if (radioButton88200.IsChecked == true) { mSampleRate = 88200; } if (radioButton96000.IsChecked == true) { mSampleRate = 96000; } if (radioButton176400.IsChecked == true) { mSampleRate = 176400; } if (radioButton192000.IsChecked == true) { mSampleRate = 192000; } if (radioButtonPlayPcm16.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonPlayPcm24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonPlayPcm32v24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonRecPcm16.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonRecPcm24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonRecPcm32v24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonPlayEvent.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonPlayTimer.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (radioButtonRecEvent.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonRecTimer.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec)) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeError); return false; } if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge); } if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec)) { MessageBox.Show(Properties.Resources.msgRecBufferSizeError); return false; } if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec) { MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge); } return true; }
public bool IsNoiseShapingOrDitherCapable(PcmData pdFrom, WasapiCS.SampleFormatType toFormat) { return(mConv.IsConversionNoiseshapingOrDitherCapable( WasapiCS.BitAndFormatToSampleFormatType(pdFrom.BitsPerSample, pdFrom.ValidBitsPerSample, SampleFormatInfo.VrtToBft(pdFrom.SampleValueRepresentationType)), toFormat)); }
/// <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); }
public InspectFormat(int sr, WasapiCS.SampleFormatType sf) { sampleRate = sr; sampleFormat = sf; }
private bool UpdateTestParamsFromUI() { if (!Int32.TryParse(textBoxTestFrames.Text, out mNumTestFrames) || mNumTestFrames <= 0) { MessageBox.Show(Properties.Resources.msgPcmSizeError); return(false); } if (0x7fffffff / 8 / 1024 / 1024 < mNumTestFrames) { MessageBox.Show(string.Format(Properties.Resources.msgPcmSizeTooLarge, 0x70000000 / 8 / 1024 / 1024)); return(false); } mNumTestFrames *= 1024 * 1024; if (radioButton44100.IsChecked == true) { mSampleRate = 44100; } if (radioButton48000.IsChecked == true) { mSampleRate = 48000; } if (radioButton88200.IsChecked == true) { mSampleRate = 88200; } if (radioButton96000.IsChecked == true) { mSampleRate = 96000; } if (radioButton176400.IsChecked == true) { mSampleRate = 176400; } if (radioButton192000.IsChecked == true) { mSampleRate = 192000; } if (radioButtonPlayPcm16.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonPlayPcm24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonPlayPcm32v24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonRecPcm16.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonRecPcm24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonRecPcm32v24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonPlayEvent.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonPlayTimer.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (radioButtonRecEvent.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonRecTimer.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec)) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeError); return(false); } if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge); } if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec)) { MessageBox.Show(Properties.Resources.msgRecBufferSizeError); return(false); } if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec) { MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge); } return(true); }
private void radioButton32_Checked(object sender, RoutedEventArgs e) { mSampleFormat = WasapiCS.SampleFormatType.Sint32; }
private bool UpdateTestParamsFromUI() { mPlayDeviceIdx = listBoxPlayDevices.SelectedIndex; mRecDeviceIdx = listBoxRecDevices.SelectedIndex; mUseFile = radioButtonPcmFile.IsChecked == true; int testFramesMbytes = -1; if (!Int32.TryParse(textBoxTestFrames.Text, out testFramesMbytes) || testFramesMbytes <= 0) { MessageBox.Show(Properties.Resources.msgPcmSizeError); return(false); } mNumTestFrames = 1000L * 1000L * (long)testFramesMbytes; if (radioButton44100.IsChecked == true) { mSampleRate = 44100; } if (radioButton48000.IsChecked == true) { mSampleRate = 48000; } if (radioButton88200.IsChecked == true) { mSampleRate = 88200; } if (radioButton96000.IsChecked == true) { mSampleRate = 96000; } if (radioButton176400.IsChecked == true) { mSampleRate = 176400; } if (radioButton192000.IsChecked == true) { mSampleRate = 192000; } if (radioButtonPlayPcm16.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonPlayPcm24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonPlayPcm32v24.IsChecked == true) { mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonRecPcm16.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint16; } if (radioButtonRecPcm24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint24; } if (radioButtonRecPcm32v24.IsChecked == true) { mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24; } if (radioButtonPlayEvent.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonPlayTimer.IsChecked == true) { mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (radioButtonRecEvent.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven; } if (radioButtonRecTimer.IsChecked == true) { mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven; } if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec)) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeError); return(false); } if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec) { MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge); } if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec)) { MessageBox.Show(Properties.Resources.msgRecBufferSizeError); return(false); } if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec) { MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge); } mRecDwChannelMask = 0; if (checkBoxRecSetDwChannelMask.IsChecked == true) { mRecDwChannelMask = WasapiCS.GetTypicalChannelMask(NUM_CHANNELS); } return(true); }