public static AudioCompressor Create(AudioFormat format) { if (format == null) throw new ArgumentNullException("format"); AudioEncoder encoder = AudioEncoder.FindByFriendlyName(format.AudioCompressor); if (encoder == null) throw new SplicerException( string.Format(CultureInfo.CurrentUICulture, Resources.ErrorCanResolveAudioEncoder, format.AudioCompressor)); if (!format.UseDefaults) { WavFormatInfo formatInfo = WavFormatInfoTools.FindFormat(encoder.Filter, PinDirection.Output, format); if (formatInfo == null) { var builder = new StringBuilder(); builder.AppendFormat(CultureInfo.CurrentUICulture, Resources.ErrorCanNotResolveMediaTypeForEncoder, format.Khz, format.Kbps, format.IsMono); foreach (WavFormatInfo info in encoder.Formats) { builder.Append(Environment.NewLine); builder.Append(info.ToString()); } throw new SplicerException(builder.ToString()); } return new AudioCompressor(encoder.Filter, formatInfo.MediaType); } else { return new AudioCompressor(encoder.Filter, null); } }
public static IBaseFilter CreateAudioCompressor(DisposalCleanup dc, IGraphBuilder graph, IPin outPin, AudioFormat settings) { if (dc == null) throw new ArgumentNullException("dc"); if (graph == null) throw new ArgumentNullException("graph"); if (outPin == null) throw new ArgumentNullException("outPin"); if (settings == null) throw new ArgumentNullException("settings"); int hr = 0; using (AudioCompressor compressor = AudioCompressorFactory.Create(settings)) { IBaseFilter compressorFilter = compressor.Filter; dc.Add(compressorFilter); hr = graph.AddFilter(compressorFilter, settings.AudioCompressor); DsError.ThrowExceptionForHR(hr); FilterGraphTools.ConnectFilters(graph, outPin, compressorFilter, true); // set the media type on the output pin of the compressor if (compressor.MediaType != null) { FilterGraphTools.SetFilterFormat(compressor.MediaType, compressorFilter); } return compressorFilter; } }
public static WavFormatInfo FindFormat(IBaseFilter filter, PinDirection direction, AudioFormat format) { IEnumerator<WavFormatInfo> enumerator = EnumerateFormatsForDirection(filter, direction); while (enumerator.MoveNext()) { if ((enumerator.Current.IsMono == format.IsMono) && (enumerator.Current.Khz == format.Khz) && (enumerator.Current.Kbps == format.Kbps)) { return enumerator.Current; } enumerator.Current.Dispose(); } return null; }
public WavFileRenderer(ITimeline timeline, string outputFile, AudioFormat format, ICallbackParticipant[] audioParticipants) : base(timeline) { AudioCompressor compressor = null; try { compressor = AudioCompressorFactory.Create(format); Cleanup.Add(compressor.Filter); RenderToWavDest(outputFile, compressor.Filter, compressor.MediaType, audioParticipants); ChangeState(RendererState.Initialized); } finally { if ((compressor != null) && (compressor.MediaType != null)) { DsUtils.FreeAMMediaType(compressor.MediaType); } } }
public static WavFormatInfo FindFormat(IBaseFilter filter, PinDirection direction, AudioFormat format) { IEnumerator <WavFormatInfo> enumerator = EnumerateFormatsForDirection(filter, direction); while (enumerator.MoveNext()) { if ((enumerator.Current.IsMono == format.IsMono) && (enumerator.Current.Khz == format.Khz) && (enumerator.Current.Kbps == format.Kbps)) { return(enumerator.Current); } enumerator.Current.Dispose(); } return(null); }