/// <summary> /// Configure the Opus encoder filter /// after the encoder is in the graph and connected /// to the source. /// /// Warning: This might not work for a DVCaptureGraph. /// </summary> /// <param name="cg"></param> /// <param name="j"></param> public override void PostConnectConfig(Dictionary <string, Object> args) { CaptureGraph cg = args["CaptureGraph"] as CaptureGraph; IAudioCaptureGraph iacg = cg as IAudioCaptureGraph; _AMMediaType[] mts = Pin.GetMediaTypes(cg.Source.OutputPin); bool mtSet = false; foreach (_AMMediaType mt in mts) { WAVEFORMATEX wfex = (WAVEFORMATEX)MediaType.FormatType.MarshalData(mt); if ((wfex.SamplesPerSec == Frequency) && (wfex.Channels == Channels) && (wfex.BitsPerSample == Depth)) { cg.Source.SetMediaType(mt); mtSet = true; break; } } if (!mtSet) { throw new ApplicationException("The audio device doesn't support the configured values of SamplesPerSec/Channels/BitsPerSample."); } IOpusEncoderCtl iOpus = (IOpusEncoderCtl)iacg.AudioCompressor.BaseFilter; iOpus.SetSignal(Signal); int br = BitRate; if (br == 0) { br = ManualBitRate; } iOpus.SetBitRate(br); iOpus.SetComplexity(Complexity); iOpus.SetMaxBandwidth(MaxBandwidth); iOpus.SetVbr(VBR); iOpus.SetVbrConstraint(VBRConstraint); iOpus.SetDtx(DTX); iOpus.SetPacketLossPerc(PacketLossPerc); iOpus.SetLsbDepth(LSBDepth); iOpus.SetForcedChannels(ForcedChannels); }
/// <summary> /// Determine if a particular format is compatible with the encoder. /// </summary> /// <returns></returns> public static bool WorksWithOpus(WAVEFORMATEX wfex) { if (wfex.BitsPerSample != 16) { return(false); } if (wfex.Channels != 1 && wfex.Channels != 2) { return(false); } foreach (int f in ValuesFrequency) { if (wfex.SamplesPerSec == f) { return(true); } } return(false); }
public CompressorFmt(WAVEFORMATEX wfex) { this.WFEX = wfex; }
/// <summary> /// Determine if a particular format is compatible with the encoder. /// </summary> /// <returns></returns> public static bool WorksWithOpus(WAVEFORMATEX wfex) { if (wfex.BitsPerSample != 16) return false; if (wfex.Channels != 1 && wfex.Channels != 2) { return false; } foreach (int f in ValuesFrequency) { if (wfex.SamplesPerSec == f) { return true; } } return false; }