CathodeRetro::Internal::SignalGenerator

This is an internal class used by CathodeRetro::CathodeRetro to take an input RGB texture and generate a texture containing a set of composite or S-Video scanlines to send to SignalDecoder).

If you are using the CathodeRetro::CathodeRetro class, you should not need to use this class directly.

For a description of what this class does, see Generating a Fake NTSC Signal.

Public Members

Public Methods

(constructor)
                SignalGenerator(
                  IGraphicsDevice *deviceIn,
                  SignalType type,
                  uint32_t inputWidth,
                  uint32_t inputHeight,
                  const SourceSettings &inputSettings)
              
Description
Construct a new instance of the Internal::SignalGenerator class.
Parameters
deviceIn

Type: IGraphicsDevice *

Pointer to the graphics device instance that this instance should use for all of its drawing-related functionality. This pointer will be cached so the lifetime of deviceIn must extend past the lifetime of the Internal::SignalGenerator instance being created.

type

Type: SignalType

The type of signal to emulate.

This value should not be SignalType::RGB, as no generator/decoder is needed for RGB signals.

inputWidth

Type: uint32_t

The expected width of the input RGB image, in texels.

inputHeight

Type: uint32_t

The expected height of the input RGB image, in texels.

inputSettings

Type: const SourceSettings &

Properties of the hypothetical source "machine" that is generating the signal being emulated.

SignalProperties
                const Internal::SignalProperties &SignalProperties() const
              
Description
Get the roperties of the hypothetical source "machine" that is generating the signal being emulated.
Return Value
Type: const Internal::SignalProperties &

The properties of the hypothetical source "machine" that is generating the signal being emulated.

SignalLevels
                const Internal::SignalLevels &SignalLevels() const
              
Description
Get information about the various voltage levels of the signal, as well as how much temporal artifact reduction to apply.
Return Value
Type: const Internal::SignalLevels &

The level information for this generator.

PhasesTexture
                const ITexture *PhasesTexture() const
              
Description
Get a texture (with dimensions of (1 x signalProps.scanlineCount) containing the colorburst phase for each scanline (in fractional multiples of the color carrier frequency) of the last frame rendered by Generate.
Return Value
Type: const ITexture *

The phases texture.

SignalTexture
                const ITexture *SignalTexture() const
              
Description
Get a texture (with dimensions of ( signalProps.scanlineWidth x signalProps.scanlineCount) containing the generated composite or S-Video scanline signals for the last frame rendered by Generate.
Return Value
Type: const ITexture *

The scanline signal texture.

SetArtifactSettings
                void SetArtifactSettings(
                  const ArtifactSettings &settings)
              
Description

Update the artifact settings that this generator will use to generate its signal textures.

Note that, if the temporalArtifactReduction member of the supplied artifact settings changes from zero to or non-zero or vice-versa, internal textures will be reallocated, so caution is advised when changing these settings on the fly.

Parameters
settings

Type: const ArtifactSettings &

The new artifact settings to use in Generate.

Generate
                void Generate(
                  const ITexture *inputRGBTexture, 
                  int32_t frameStartPhaseNumeratorIn = -1)
              
Description
Take the input RGB texture (with expected dimensions equal to the inputWidth and inputHeight parameters passed to the constructor), and convert it into a composite or S-Video signal (based on the signal type given to the constructor), using an optional start-of-frame phase value.
Parameters
inputRGBTexture

Type: const ITexture *

The input RGB texture for the current frame, that we want to generate a signal from.

frameStartPhaseNumeratorIn

Type: int32_t

An optional frame start phase numerator.

A negative value (the default) means "use the internally-tracked phase numerator (frameStartPhaseNumerator)".

When divided by sourceSettings.denominator, this represents the phase offset of the colorburst for the first scanline.

Private Members

Private Structures

RGBToSVideoConstantData
Description
This structure maps to the constant buffer input to the generator-rgb-to-svideo-or-composite shader. Refer to its page for documentation of the fields.
GeneratePhaseTextureConstantData
Description
This structure maps to the constant buffer input to the generator-gen-phase shader. Refer to its page for documentation of the fields.
ApplyArtifactsConstantData
Description
This structure maps to the constant buffer input to the generator-apply-artifacts shader. Refer to its page for documentation of the fields.

Private Methods

GeneratePhasesTexture
                void GeneratePhasesTexture()
              
Description

Generates the per-scanline phases texture (phasesTexture).

This texture is used both by GenerateCleanSignal and by Internal::SignalDecoder for the phase of the color carrier wave.

Called by Generate.

GenerateCleanSignal
                void GenerateCleanSignal(
                  const ITexture *rgbTexture)
              
Description

Generate a fake NTSC signal based on the input texture.

Called by Generate.

Parameters
rgbTexture
Type: const ITexture *

The input texture to generate our fake NTSC signal from.

ApplyArtifacts
                void ApplyArtifacts()
              
Description

Applies any ghosting or noise artifacts to the clean signal, resulting in the final output signal texture.

Will render from signalTexture to scratchSignalTexture, then swap the two (so that signalTexture contains the output).

Called (when needed) by Generate.

Private Fields

device
                IGraphicsDevice *device
              
Type
IGraphicsDevice *
Description
Pointer to the graphics device that should be used to create graphics objects and render.
noiseSeed
                uint32_t noiseSeed = 0
              
Type
uint32_t
Description
A seed value used to generate noise, in the shaders. Increments every frame and wraps every so often (every ~1 million frames) to avoid numerical issues in the shader.
generateSignalConstantBuffer
                std::unique_ptr<IConstantBuffer> generateSignalConstantBuffer
              
Type
std::unique_ptr<IConstantBuffer>
Description
The constant buffer that is used in GeneratePhasesTexture as an input to the generator-gen-phase shader, and in GenerateCleanSignal as an input to the generator-rgb-to-svideo-or-composite shader.
applyArtifactsConstantBuffer
                std::unique_ptr<IConstantBuffer> applyArtifactsConstantBuffer
              
Type
std::unique_ptr<IConstantBuffer>
Description
The constant buffer that is used in ApplyArtifacts as an input to the generator-apply-artifacts shader.
phasesTexture
                std::unique_ptr<IRenderTarget> phasesTexture
              
Type
std::unique_ptr<IRenderTarget>
Description
A texture (with dimensions of (1 x signalProps.scanlineCount) containing the colorburst phase for each scanline (in fractional multiples of the color carrier frequency) of the last frame rendered by Generate.
signalTexture
                std::unique_ptr<IRenderTarget> signalTexture
              
Type
std::unique_ptr<IRenderTarget>
Description
A texture (with dimensions of ( signalProps.scanlineWidth x signalProps.scanlineCount) containing the generated composite or S-Video scanline signals for the last frame rendered by Generate.
scratchSignalTexture
                std::unique_ptr<IRenderTarget> scratchSignalTexture
              
Type
std::unique_ptr<IRenderTarget>
Description

A texture (with the same dimensions and format as signalTexture) used as the temporary output of ApplyArtifacts.

At the end of ApplyArtifacts, this texture is swapped with signalTexture so signalTexture always contains the latest signal output.

sourceSettings
                SourceSettings sourceSettings
              
Type
SourceSettings
Description
The source settings that were given to use in the constructor.
signalProps
                Internal::SignalProperties signalProps
              
Type
Internal::SignalProperties
Description
Properties of the signal generated based on the inputs to the constructor.
levels
                Internal::SignalLevels levels
              
Type
Internal::SignalLevels
Description
Level information that is generated when GenerateCleanSignal runs.
artifactSettings
                ArtifactSettings artifactSettings
              
Type
ArtifactSettings
Description
The artifact settings that were given to us on the last call to SetArtifactSettings.
frameStartPhaseNumerator
                uint32_t frameStartPhaseNumerator = 0
              
Type
uint32_t
Description

The numerator of the scanline phase value for the first scanline of the current frame.

The actual phase value is this divided by sourceSettings.denominator.

prevFrameStartPhaseNumerator
                uint32_t prevFrameStartPhaseNumerator = 0
              
Type
uint32_t
Description

The numerator of the scanline phase value for the first scanline of the previously-generated frame.

This is used as the starting phase for the (optional) second version of the current frame generated for temporal artifact reduction.

The actual phase value is this divided by sourceSettings.denominator.

isEvenFrame
                bool isEvenFrame = false
              
Type
bool
Description

This is true if this is an "even" frame, false if it's an "odd" frame, tracked for purposes of knowing which value to increment frameStartPhaseNumerator by every frame.

The first frame is considered the even frame, and then it alternates from there.