public static SoundIO getSoundIO(String captureDeviceDesc, String outputTypeDesc, String soundFormatDesc) { Mp3SoundCapture.Outputs outputType; switch (outputTypeDesc.ToLower()) { case "wav": outputType = Mp3SoundCapture.Outputs.Wav; break; case "mp3": outputType = Mp3SoundCapture.Outputs.Mp3; break; case "rawpcm": outputType = Mp3SoundCapture.Outputs.RawPcm; break; default: outputType = Mp3SoundCapture.Outputs.Wav; break; } SoundCaptureDevice captureDevice = SoundCaptureDevice.AllAvailable.Where(d => d.Description == captureDeviceDesc).FirstOrDefault(); PcmSoundFormat soundFormat = StandartSoundFormats.Where(d => d.Description == soundFormatDesc).FirstOrDefault(); return(new SoundIO(captureDevice, outputType, soundFormat)); //_mp3SoundCapture = new Mp3SoundCapture //{ // CaptureDevice = captureDevice, // OutputType = outputType, // WaveFormat = soundFormat, // WaitOnStop = true, // NormalizeVolume = true //}; }
/// <summary> /// Constructs the capture component which is then able to capture many sound pieces /// and append then to provided outputStream. /// </summary> /// <param name="waveFormat">Format of raw PCM wave data (how the sound is to be captured). /// See SoundFormat static properties.</param> /// <param name="outputStream">Stream to which the captured data is written by this component. /// It must be open before capture starts.</param> /// <param name="useSynchronizationContext">False disables event marshalling to the synchronization /// context thread.</param> public SoundCapture(PcmSoundFormat waveFormat, Stream outputStream, bool useSynchronizationContext) { if (useSynchronizationContext) { this.syncContext = SynchronizationContext.Current; } this.WaveFormat = waveFormat; this.OutputStream = outputStream; }
protected override void RewriteData(BinaryReader input, BinaryWriter output) { PcmSoundFormat format = (PcmSoundFormat)InputFormat; if (format.BitsPerSample == 8) { Normalize8(input, output); } else if (format.BitsPerSample == 16) { Normalize16(input, output); } else { throw new ArgumentException("Unsupported bits per sample: " + format.BitsPerSample + "."); } }
/// <summary> /// Constructs the capture component which is then able to capture many sound pieces /// and append then to provided outputStream. /// </summary> /// <param name="waveFormat">Format of raw PCM wave data (how the sound is to be captured). /// See SoundFormat static properties.</param> /// <param name="outputStream">Stream to which the captured data is written by this component. /// It must be open before capture starts.</param> public SoundCapture(PcmSoundFormat waveFormat, Stream outputStream) : this(waveFormat, outputStream, true) { }
public SoundIO(SoundCaptureDevice captureDevice, Mp3SoundCapture.Outputs outputType, PcmSoundFormat soundFormat) { _mp3SoundCapture = new Mp3SoundCapture { CaptureDevice = captureDevice, OutputType = outputType, WaveFormat = soundFormat, WaitOnStop = true, NormalizeVolume = true }; }