# Control audio processing in SOF

# Redefine headphone control FOR SOF. This is same as Headphone in HDA/HiFi-analog.conf
# but adds DRC and EQ controls.

DefineMacro.SofAnalogPlaybackControl {
	Define.EndpointDrcVar "PostMixerAnalogPlayback${var:__endpoint}DrcBlob"
	Define.EndpointIirVar "PostMixerAnalogPlayback${var:__endpoint}IirBlob"
	Define.EndpointFirVar "PostMixerAnalogPlayback${var:__endpoint}FirBlob"
	Define.EndpointDrcBlob "${var:$EndpointDrcVar}"
	Define.EndpointIirBlob "${var:$EndpointIirVar}"
	Define.EndpointFirBlob "${var:$EndpointFirVar}"

	If.endpoint_with_drc {
		Condition {
			Type ControlExists
			Control "name='${var:PostMixerAnalogPlaybackDrcSwitch}'"
		}
		True {
			EnableSequence [
				# For debug uncomment below the echo command to see what blobs are applied
				cset "name='${var:PostMixerAnalogPlaybackDrcSwitch}' ${var:__drcswitch}"
				cset-tlv "name='${var:PostMixerAnalogPlaybackDrcBytes}' ${var:EndpointDrcBlob}"
				cset-tlv "name='${var:PostMixerAnalogPlaybackIirBytes}' ${var:EndpointIirBlob}"
				cset-tlv "name='${var:PostMixerAnalogPlaybackFirBytes}' ${var:EndpointFirBlob}"
			]
		}
		False.If.endpoint_with_eq {
			Condition {
				Type ControlExists
				Control "name='${var:PostMixerAnalogPlaybackFirBytes}'"
			}
			True {
				EnableSequence [
					# For debug uncomment below the echo command to see what blobs are applied
					cset-tlv "name='${var:PostMixerAnalogPlaybackIirBytes}' ${var:EndpointIirBlob}"
					cset-tlv "name='${var:PostMixerAnalogPlaybackFirBytes}' ${var:EndpointFirBlob}"
				]
			}
		}
	}
}

# Merge this to Headpones subtree in HDA/HiFi-analog.conf
If.hp {
	Condition {
		Type String
		Empty "${var:hpvol}"
	}
	True.SectionDevice."Headphones" {
		Macro.headphone.SofAnalogPlaybackControl "endpoint=Headphone drcswitch=off"
	}
}

# Merge this to Speaker subtree in HDA/HiFi-analog.conf
If.spk {
	Condition {
		Type String
		Empty "${var:spkvol}"
	}
	True.SectionDevice."Speaker" {
		Macro.speaker.SofAnalogPlaybackControl "endpoint=Speaker drcswitch=on"
	}
}
