Exemple #1
0
        public void RenderWithCompressor()
        {
            string outputFile = "RenderWithCompressor.wav";

            using (
                AudioCompressor compressor =
                    AudioCompressorFactory.Create(AudioFormat.CompactDiscQualityStereoPcm))
                using (ITimeline timeline = new DefaultTimeline())
                {
                    IGroup audioGroup = timeline.AddAudioGroup();
                    ITrack rootTrack  = audioGroup.AddTrack();
                    rootTrack.AddClip("testinput.wav", GroupMediaType.Audio, InsertPosition.Relative, 0, 0, 2);

                    // render the timeline
                    using (
                        var renderer =
                            new WavFileRenderer(timeline, outputFile, compressor.Filter, compressor.MediaType, null))
                    {
                        ExecuteRenderer(renderer,
                                        @"<timeline framerate=""30.0000000"">
<group type=""audio"" framerate=""30.0000000"" previewmode=""0"">
    <track>
        <clip start=""0"" stop=""2"" src=""testinput.wav"" mstart=""0""/>
    </track>
</group>
</timeline>");
                    }

                    AssertLengths(timeline.Fps, 2, outputFile);
                }
        }
 public void Create()
 {
     using (
         AudioCompressor compressor =
             AudioCompressorFactory.Create(AudioFormat.CompactDiscQualityStereoPcm))
     {
         Assert.IsNotNull(compressor.Filter);
         Assert.IsNotNull(compressor.MediaType);
     }
 }
Exemple #3
0
        /// <summary>
        /// Adds an audio compressor if needed (by checking the registry)
        /// </summary>
        public void AddAudioCompressor()
        {
            if (RegAudioCompressorEnabled)
            {
                try
                {
                    cg.AddCompressor(AudioCompressor.DefaultFilterInfo());
                    Log(cg.Compressor.Dump());

                    DefaultAudioCompressorSettings();
                }
                catch (Exception e)
                {
                    // If we encounter an error trying to add or configure the
                    // compressor, just disable compressor and log it
                    RegAudioCompressorEnabled = false;
                    Log(e.ToString());
                }
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        public WavFileRenderer(ITimeline timeline, string outputFile, AudioFormat format, IDESCombineCB audioCallback)
            : base(timeline)
        {
            AudioCompressor compressor = null;

            try
            {
                compressor = AudioCompressorFactory.Create(format);

                _dc.Add(compressor.Filter);

                RenderToWavDest(outputFile, compressor.Filter, compressor.MediaType, audioCallback);

                ChangeState(RendererState.Initialized);
            }
            finally
            {
                if ((compressor != null) && (compressor.MediaType != null))
                {
                    DsUtils.FreeAMMediaType(compressor.MediaType);
                }
            }
        }
        /// <summary>
        /// Get the selected audio compressor from the registry.  It may be a moniker of a compressor that is enabled
        /// on the system or "Uncompressed".  Otherwise return the default compressor.
        /// </summary>
        /// <returns></returns>
        public static FilterInfo SelectedCompressor()
        {
            FilterInfo selectedCompressor    = AudioCompressor.DefaultFilterInfo();
            string     regSelectedCompressor = (string)AVReg.ReadValue(AVReg.SelectedDevices, AVReg.AudioCompressor);

            if (regSelectedCompressor != null)
            {
                if (regSelectedCompressor == "Uncompressed")
                {
                    return(new FilterInfo("Uncompressed", "Uncompressed", Guid.Empty));
                }

                foreach (FilterInfo fi in AudioCompressor.EnabledCompressors)
                {
                    if (fi.Moniker == regSelectedCompressor)
                    {
                        selectedCompressor = fi;
                        break;
                    }
                }
            }

            return(selectedCompressor);
        }