Compartilhar via


Synth Filter Sample

 
Microsoft DirectShow 9.0

Synth Filter Sample

The Synth filter is a source filter that generates audio waveforms.

This sample is included with the Windows SDK. It is located under the following path: [SDK Root]\Samples\Multimedia\DirectShow\Filters\Synth.

This filter illustrates dynamic graph building. It can switch between uncompressed PCM audio and compressed MS_ADPCM (Microsoft Adaptive Delta Pulse Code Modulation) format.

This filter appears in GraphEdit as "Audio Synthesizer Filter."

For more information about dynamic graph building, see Dynamic Graph Building.

User's Guide

The Synth filter enables the user to set the waveform, frequency, number of channels, and other properties through the property page. To set either the upper or lower endpoint of the swept frequency range, hold down SHIFT while adjusting the frequency slider. The filter also supports a custom interface, ISynth2, for setting these properties.

To demonstrate the dynamic graph building feature, do the following:

  1. Build the filter and register it with the Regsvr32 utility.
  2. Launch GraphEdit.
  3. Insert the Audio Synthesizer filter. It appears in the DirectShow Filters category.
  4. Render the filter's output pin.
  5. Click the Play button.
  6. Open the filter's property page.
  7. In the Output Format area, select PCM or Microsoft ADPCM.

Programming Notes

This sample contains the following files:

  • Dynsrc.h, Dynsrc.cpp: Contains two base classes for source filters that support dynamic graph building, CDynamicSource and CDynamicSourceStream.
  • ISynth.h: Declares the custom ISynth2 interface for setting properties on the filter.
  • Resource.h: Contains resource constants.
  • Synth.def: Exports the DLL functions needed by the COM library.
  • Synth.h, Synth.cpp: Contains the CAudioSynth class, which generates the audio data, and the CSynthFilter class, which implements the filter.
  • Synth.rc: Contains resources used by the filter.
  • Synthprp.h, Synthprp.cpp: Implements the filter's property page.

The CDynamicSource class is adapted from the CSource base class. It uses one or more output pins derived from the CDynamicSourceStream class. The CDynamicSourceStream class is adapted from the CSourceStream class, but derives from the CDynamicOutputPin class rather than the CBaseOutputPin class.

The CDynamicSource class has the following methods not found in CSource:

The CDynamicSourceStream class has the following methods not found in CSourceStream:

  • DestroySourceThread: Shuts down the worker thread.
  • FatalError: Signals an error to the filter graph manager.
  • OutputPinNeedsToBeReconnected: Signals that the output pin should be reconnected. When this method is called, the worker thread calls the CDynamicOutputPin::DynamicReconnect method to reconnect the pin.

See Also