/// <summary> /// Initializes a new instance of the <see cref="AudioConfiguration"/> class. /// </summary> /// <param name="samplingRate">The samplingrate to use.</param> /// <param name="format">The format to use.</param> /// <param name="channelSetup">The channel configuration to use.</param> public AudioConfiguration(int samplingRate, AudioSampleFormat format, AudioChannelSetup channelSetup) { SamplingRate = samplingRate; Format = format; ChannelSetup = channelSetup; switch (Format) { case AudioSampleFormat.Int8: BytesPerSample = 1; break; case AudioSampleFormat.Int16: BytesPerSample = 2; break; case AudioSampleFormat.Int24: BytesPerSample = 3; break; case AudioSampleFormat.Int32: case AudioSampleFormat.Float: BytesPerSample = 4; break; case AudioSampleFormat.Double: BytesPerSample = 8; break; case AudioSampleFormat.Unknown: BytesPerSample = 0; break; default: throw new NotImplementedException(); } BytesPerTick = BytesPerSample; ChannelSetup = channelSetup; BytesPerTick *= (int)ChannelSetup; }
/// <summary>Initializes a new instance of the <see cref="AudioData" /> class.</summary> /// <param name="samplingRate">SamplingRate.</param> /// <param name="channelSetup">Audio channel setup.</param> /// <param name="samples">The samples.</param> /// <param name="sampleCount">The sample count.</param> /// <exception cref="ArgumentNullException">Buffer.</exception> /// <exception cref="Exception"></exception> /// <exception cref="ArgumentOutOfRangeException">ChannelSetup.</exception> public AudioData(int samplingRate, AudioChannelSetup channelSetup, float[] samples, int sampleCount) : base(samplingRate, AudioSampleFormat.Float, channelSetup) { if (samples == null) { throw new ArgumentNullException("samples"); } if ((sampleCount > samples.Length) || ((sampleCount % BytesPerTick) != 0)) { throw new Exception(string.Format("Buffer length invalid!")); } if (channelSetup == AudioChannelSetup.None) { throw new ArgumentOutOfRangeException(nameof(ChannelSetup)); } SampleCount = sampleCount; data = new byte[BytesPerSample * sampleCount]; Buffer.BlockCopy(samples, 0, data, 0, sampleCount * 4); }
/// <summary>Initializes a new instance of the <see cref="AudioData"/> class.</summary> /// <param name="samplingRate">SamplingRate.</param> /// <param name="format">AudioSampleFormat.</param> /// <param name="channelSetup">Audio channel setup.</param> /// <param name="startTime">start time of the audio data.</param> /// <param name="streamIndex">stream index.</param> /// <param name="channelNumber">channel.</param> /// <param name="buffer">buffer containing the sample data.</param> public AudioData(int samplingRate, AudioSampleFormat format, AudioChannelSetup channelSetup, TimeSpan startTime, int streamIndex, int channelNumber, byte[] buffer) : base(samplingRate, format, channelSetup) { if (buffer == null) { throw new ArgumentNullException("Buffer"); } if ((BytesPerTick != 0) && ((buffer.Length % BytesPerTick) != 0)) { throw new Exception(string.Format("Buffer length invalid!")); } if (channelSetup == AudioChannelSetup.None) { throw new ArgumentOutOfRangeException(nameof(ChannelSetup)); } StreamIndex = streamIndex; data = buffer; StartTime = startTime; ChannelNumber = channelNumber; SampleCount = buffer.Length / BytesPerSample; }