pvr 150 based linux script + settings for better quality sam

The place for all discussion on gaming hardware
Post Reply
holering
Posts: 9
Joined: Fri Dec 13, 2013 7:05 am

pvr 150 based linux script + settings for better quality sam

Post by holering »

Might be a mistake to put this here,

I've been using this for a while and it seems to work although it's very important to use high quality cables, and sometimes you must rebuild the composite output with clean sync.

VirtualBox can be used if post Windows XP or MacOS X 8086 is your local host and you're using a WinTV USB2 PVR with the 5 digit number underneath with 24xxx (xxx being three random numbers). There's other usb devices with the same cx25840 based hardware which should also work. Minimal linux install in VirtualBox can offer good usb sampling results into a virtual disk drive.

I'm planning to finish a UI gtk program to make this much easier so I don't have to use the script anymore. I'm placing the script here as an attachment and a sample on this post. I don't recommend using it unless you know what you're doing and follow the datasheet. Unfortunately the datasheet can be very illogical at times; some hexadecimal values are deliberately given as a string of thousandth even though the description uses single digits.

So basically this allows disabling the agc, chroma agc, and shutting down other parts that aren't used; and manually adjusting gains, comb filter, color, tint, contrast and quite a wealth of other options. It looks like it's even possible to sample with ypbpr component by using a svideo to two rca phono style plugs cable adapter; the datasheet explains changing the input source for chroma and luminance with other channels. Ypbpr doesn't have agc so it's not necessary to disable but I haven't tested this.

Ok so here's the composite cvbs script:(be careful with the improper line endings!)

Code: Select all

#!/bin/bash
# Hauppauge PVR-150 tweaked using Sega Dreamcast console via composite.  Tried
# to get colors as close to VGA as possible.  Highest definition attainable 
# seems to be with comb filter forced on with highest settings, and  
# temporal-spatial-median filters turned off.  Attaining highest definition
# has negative effect of severe dot crawling, but this could be mitigated
# by filtering a resultant captured interlaced video file through software.
# Also, square pixel output seems broken; requires video_pll set to 8X NTSC,
# PAL, and/or SECAM frequencies according to page 3-76 in CX25840 datasheet.
# Have to resort to default (ITU-R BT.656 (don't care)) with SQ_PIXEL=0.

# Module required for cx25840ctl
modprobe i2c-dev

# Reset driver
#rmmod ivtv_alsa
#rmmod ivtv
#modprobe ivtv
#modprobe ivtv_alsa


# Increase latency for IDE and SATA if you get errors
#setpci -v -s 00:16.2 latency_timer=ff
#setpci -v -s 00:16.0 latency_timer=ff
#setpci -v -s 00:12.2 latency_timer=ff
#setpci -v -s 00:13.0 latency_timer=ff
#setpci -v -s 00:12.0 latency_timer=ff
#setpci -v -s 00:13.2 latency_timer=ff
#setpci -v -s 00:15.0 latency_timer=ff
#setpci -v -s 00:0a.0 latency_timer=ff
#setpci -v -s 00:14.5 latency_timer=ff
#setpci -v -s 00:14.4 latency_timer=ff
#setpci -v -s 00:14.3 latency_timer=ff
#setpci -v -s 00:14.2 latency_timer=ff
#setpci -v -s 00:14.1 latency_timer=ff
#setpci -v -s 00:11.0 latency_timer=ff
#setpci -v -s 03:07.0 latency_timer=ff

echo `Tell driver to disable all filtering; and set encoding and output options.`
v4l2-ctl -i 2
v4l2-ctl --set-ctrl video_mute_yuv=0
v4l2-ctl --set-ctrl stream_vbi_format=0
v4l2-ctl --set-ctrl temporal_filter_mode=0
v4l2-ctl --set-ctrl temporal_filter=0
v4l2-ctl --set-ctrl video_temporal_decimation=0
v4l2-ctl --set-ctrl median_filter_type=0
v4l2-ctl --set-ctrl median_luma_filter_minimum=0
v4l2-ctl --set-ctrl median_luma_filter_maximum=0
v4l2-ctl --set-ctrl median_chroma_filter_minimum=0
v4l2-ctl --set-ctrl median_chroma_filter_maximum=0
v4l2-ctl --set-ctrl spatial_filter_mode=0
v4l2-ctl --set-ctrl spatial_chroma_filter_type=0
v4l2-ctl --set-ctrl spatial_luma_filter_type=0
v4l2-ctl --set-ctrl spatial_filter=0
v4l2-ctl --set-ctrl video_encoding=0
#v4l2-ctl --set-ctrl brightness=100
v4l2-ctl --set-ctrl audio_mute=0
v4l2-ctl --set-ctrl audio_encoding=0
v4l2-ctl --set-ctrl audio_sampling_frequency=1
v4l2-ctl --set-ctrl stream_type=0

echo ` Tune the card for composite NTSC`
cx25840ctl -s 0 << EOF

#HACTIVE_CNT=864
#VACTIVE_CNT=512
HSCALE=0
VSCALE=0
HBLANK_CNT=124 (original)
#HBLANK_CNT=62
#HBLANK_CNT=10
#VBLANK_CNT=26 (original)
VBLANK_CNT=2

VALIDFMT=0

# Still need to find clamp (max value) for bright screen flashes (sync distorts)
# Raw output
IR_TX_OUT_SEL=0
PIXCLK_OUT_SEL=0
SLEEP_ANALOG_MSK=0
SLEEP_DLL_MSK=0
SLEEP=0
TEST=0
IR_TX=1
PRGM6=1
#CHIP_SEL
#VIPCLK
#IRQ_N
#PRGM4
#SLEEP

# VIP host port mode RAW
#VIP
#TEST
#IR_TX
#PRGM6
#SLEEP

# ITU-R BT.656 decoding
#CH(1)_SOURCE
#Video Input Control

# Video signal path
#DEBOUNCE_COUNT=11
#DEBOUNCE_COUNT=01

DEBOUNCE_COUNT=00
VT_LINE_CNT_HYST=11
ACTFMT=1
CLAMPRAW_EN=1
CLK_GATING=1
ANC_DAT_EN=0
BLU_FIELD_EN=0
BLU_FIELD_ACT=0
MAN_FAST_LOCK=1
AUTO_LOCK_SPD=1
PREFETCH_EN=1
VS_INTRLACE=1
VBI_MD_LINE1=0
VBI_MD_LINE2=0
VBI_MD_LINE3=0
VBI_MD_LINE4=0
VBI_MD_LINE5=0
VBI_MD_LINE6=0
VBI_MD_LINE7=0
VBI_MD_LINE8=0
VBI_MD_LINE9=0
VBI_MD_LINE10=0
VBI_MD_LINE11=0
VBI_MD_LINE12=0
VBI_MD_LINE13=0
VBI_MD_LINE14=0
VBI_MD_LINE15=0
VBI_MD_LINE16=0
VBI_MD_LINE17=0
MOJI_PACK_DIS=1
VBI1_FORMAT_TYPE=0100
VBI2_FORMAT_TYPE=0100
VBI3_FORMAT_TYPE=0100
SPECIAL_PLAY_N=1
VPRES_VERT_EN=1
VPRES=1
FILTER_BIAS_1_0_=0
FILTER_BIAS_1_0_=01
FILTER_BIAS_1_0_=10
FILTER_BIAS_1_0_=11
LINE_AVG_DIS=1
EDGE_RESYNC_EN=0
DISCONNECT_CHAN1=1

# Signal Clamping
#VIPCLAMP_EN=1
#VIPBLANK_EN=1
# SVIDEO CLAMP
#CLAMP_SEL_CH1=0 (0x0) "Video decoder drives clamp level"
#CLAMP_SEL_CH2=1 (0x1) "Clamp level is fixed at 3'b111 (midcode clamp). Use for"
#CLAMP_SEL_CH3=1 (0x1) "Clamp level is fixed at 3'b111 (midcode clamp). Use for"
#DUAL_MODE_ADC2=0
#HALF_BW_CH=0
#INPUT_MODE=0 # Composite (For some reason, this produces less noise for SVIDEO and may be more desirable)
#INPUT_MODE=01 #SVIDEO (For some reason, this has more noise vs INPUT_MODE=0)
#INPUT_MODE=10 #SVIDEO with half-rate chroma and half-rate audio (colors can get corrupt)

# Composite CLAMP
DROOP_COMP_CH3=0
DROOP_COMP_CH2=0
VGA_SEL_CH3=1
VGA_SEL_CH1=1
CLAMP_EN_CH3=0
CLAMP_EN_CH2=0
CLAMP_EN_CH1=0
CLAMP_EN_CH2=0
CLAMP_EN_CH3=0
CLAMP_SEL_CH1=0 (0x0) "Video decoder drives clamp level"
CLAMP_SEL_CH2=0 (0x1) "Clamp level is fixed at 3'b111 (midcode clamp). Use for"
CLAMP_SEL_CH3=0
DUAL_MODE_ADC2=1
HALF_BW_CH=0
INPUT_MODE=0 #Composite (For some reason, this produces less noise for SVIDEO at times)

#COMPONENT CLAMP
#CLAMP_SEL_CH1=0 (0x0) "Video decoder drives clamp level"
#CLAMP_SEL_CH2=1 (0x1) "Clamp level is fixed at 3'b111 (midcode clamp). Use for"
#CLAMP_SEL_CH3=1
#DUAL_MODE_ADC2=1
#HALF_BW_CH=1
#INPUT_MODE=11 #Component

# Clamp levels should be 001 if gains are 0
#CLAMP_LEVEL_CH1=001
#CLAMP_LEVEL_CH2=001
#CLAMP_LEVEL_CH3=001
#CLAMP_LEVEL=001
CLAMP_LEVEL_CH1=111
CLAMP_LEVEL_CH2=111
CLAMP_LEVEL_CH3=111
#CLAMP_LEVEL=111
#CLAMP_LEVEL_CH1=110
#CLAMP_LEVEL_CH2=110
#CLAMP_LEVEL_CH3=110
#CLAMP_LEVEL=110
CLAMP_AUTO_EN=0

# VSYNC
FAST_LOCK_MD=1
VSYNC=1
VSYNC_TRAIL_STAT=1
VSYNC_TRAIL_MSK=1
VLOCK=1
VLOCK_CHANGE_STAT=0
VLOCK_CHANGE_MSK=1
HLOCK=0
HLOCK_CHANGE_STAT=0
HLOCK_CHANGE_MSK=0

# ITU_R BT.656 (13.5 MHz) PLL (DEFAULT)
#VID_PLL_INT=0xF
#VID_PLL_FRAC1=254 (0xFE)
#VID_PLL_FRAC4=1 (0x0)
#VID_PLL_POST=5


# These autodetected defaults work. Make sure SQ_PIXEL=1!
#SQ_PIXEL=1
CHIP_ACFG_DIS=0 (0x0)
#SQ_PIXEL=1
#SQ_PIXEL=0
#CHIP_ACFG_DIS=0 (0x0)
#VID_PLL_INT=13 (0xD)
#VID_PLL_POST=4 (0x4)
#VID_PLL_FRAC1=230 (0xE6)
#VID_PLL_FRAC2=182 (0xB6)
#VID_PLL_FRAC3=109 (0x6D)
#VID_PLL_FRAC4=1 (0x1)
#VID_PLL_DDS=0 (0x0) "Enable"
#VID_PLL_RST=0 (0x0) "Do not reset"
#VID_PLL_LOCK=0 (0x1) "Locked"
#VID_PLL_UNLOCK=1 (0x1) "Unlock detected"

# NTSC (12.272715 MHz) PLL (Used for square pixel output; SQ_PIXEL=1)
#VID_PLL_INT=0xD
#VID_PLL_FRAC1=0x5B6D52
#VID_PLL_FRAC2=0x5B6D52
#VID_PLL_FRAC3=0x5B6D52
#VID_PLL_FRAC4=0x5B6D52
#VID_PLL_POST=4

#___ (14.75 MHz) PLL (Used for square pixel output; SQ_PIXEL=1)
#VID_PLL_INT=0x10
#VID_PLL_FRAC1=0xB7
#VID_PLL_FRAC2=0x0F
#VID_PLL_FRAC3=0xF7
#VID_PLL_FRAC4=0x0
#VID_PLL_POST=0x04

# CVBS ONLY
HTL_15K_EN=1
HTL_500K_EN=0 # Enables the 500 Khz LPF data to be used for locking. Only for -24.

# Disable auto signal detect
#EN_AV_LOCK=0 # Enable locking of auxiliary PLL to video pixel rate
ACFG_DIS=0
AFD_NTSC_SEL=0
AFD_PAL60_DIS=1
AFD_PALM_SEL=0
#VID_FMT_SEL=0001 # NTSC-M
#VID_FMT_SEL=0010 # NTSC-J
VID_FMT_SEL=0011 # NTSC-4.43
#VID_FMT_SEL=1000 # PAL 60?

# Fast color lock
AUTO_SC_LOCK=1 # Auto chroma subcarrier lock speed select
MAN_SC_FAST_LOCK=0 # Manual chroma subcarrier lock speed select

# NTSC recommended settings for comb filter
#COMB_NOTCH_MODE=0X1
#COMB_PHASE_LIMIT=0X14

# Comb filter
#COMB_PHASE_LIMIT=32
COMB_PHASE_LIMIT=56
COMB_NOTCH_MODE=0
CCOMB_REDUCE_EN=0 # Comb filter reduces amplitude of chroma that's not comb filtered (based on comb filter error).  -24 only.
LCOMB_ERR_LIMIT=255
#LUMA_THRESHOLD=32
LUMA_THRESHOLD=255
CCOMB_ERR_LIMIT=255
APL_DETECT_ENA=0 # Forces comb filter into notch mode if white line surrounded by black is detected
CCOMB_2LN_CHECK=1
LCOMB_2LN_EN=1 (0x1) "Enable"
LCOMB_3LN_EN=1 (0x1) "Enable"
CCOMB_2LN_EN=1 (0x1) "Enable"
CCOMB_3LN_EN=1 (0x1) "Enable"
BLEND_SLOPE=0
CKILL_MODE=3
CKILLEN=0

# AGC
CAGCEN=0
AGC_LOOP_GAIN=0
AGC_LOCK=1
AGC_AUTO_EN=0
AAGC_HYST1=5
AAGC_HYST2=9
AAGC_TH=20
AAGC_GAIN_EN=0
AAGC_DEFAULT=32
AAGC_DEFAULT_EN=0
#AGC_GAIN_LOW=1000
#AGC_GAIN_HIGH=10
#CAGCEN=1 (0x1) "Enable"
#AGC_LOCK=1 (0x1)
#AGC_GAIN=1671 (0x687)
#AGC_AUTO_EN=0 (0x1) "Auto mode"
##AGC_LOOP_GAIN=2 (0x2)
#AAGC_HYST1=5 (0x5)
#AAGC_HYST2=9 (0x9)
#AAGC_TH=20 (0x14)
#AAGC_GAIN_EN=0 (0x0) "Disable"
#AAGC_DEFAULT=32 (0x20)
#AAGC_DEFAULT_EN=0 (0x0) "Disable"



# Video settings (Dreamcast)
#BRIGHT=35
#CNTRST=128
#USAT=190 # Original signal is 128
#VSAT=190 # Original signal is 128
#HUE=-7

# Video settings (LD-717)
#BRIGHT=30
#CNTRST=128
#USAT=190 # Original signal is 128
#VSAT=190 # Original signal is 128
#HUE=-7

# Video settings (LD-V4200) IN PROGRESS!
BRIGHT=0
CNTRST=128
USAT=128 # Original signal is 128
VSAT=128 # Original signal is 128
HUE=0


# Default VGA Settings
VGA_SEL_CH1=0 "Video decoder drives VGA gain setting"
VGA_SEL_CH2=0 "Audio decoder drives VGA gain setting"
#VGA_SEL_CH3=0 "Audio decoder drives VGA gain setting"
#VGA_SEL_CH1=1 "Video decoder drives VGA gain setting"
#VGA_SEL_CH2=1 "Audio decoder drives VGA gain setting"
VGA_SEL_CH3=1
VGA_AUTO_EN=0 (0x0) "Freeze/manual"
VGA_CRUSH_EN=0 (0x0)
VGA_SYNC=220 (0xDC)
VGA_TRACK_RANGE=64 (0x40)
VGA_ACQUIRE_RANGE=16 (0x10)

# Custom VGA Settings
#VGA_GAIN=0
#VGA_TRACK_RANGE=0x40
#VGA_ACQUIRE_RANGE=0x10
#VGA_SYNC=0xDC
#VGA_SYNC=1
#VGA_TRACK_RANGE=60
#VGA_ACQUIRE_RANGE=255

# Sharpness filter (this filter adds gain to luma for increased sharpness)
#PEAK_SEL=00 # +2DB
#PEAK_SEL=01 # +3.5DB
#PEAK_SEL=10 # +5.0DB
PEAK_SEL=11 # +6.0DB
#PEAK_EN=1 # Enable sharpen filter
PEAK_EN=0 # Disable sharpen filter


# This can clean up video but can leave out details and other original parts.
#C_CORE_SEL=11
#LUMA_CORE_SEL=11

# Set video to original levels
C_CORE_SEL=000
LUMA_CORE_SEL=00

# Signal filter
WCEN=0
HFILT=0
#VFILT=010 # 4 Tap interpolation
VFILT=0 # 2 Tap interpolation
#VFILT=011 # 5 Tap interpolation
C_LPF_ENABLE=0
RANGE=1x
MAJ_SEL_ENABLE=0
CHROMA_IN_SEL=0 (0x0) "ADC 1"
LUMA_IN_SEL=0 (0x0) "ADC 1"

# Anti-alias filter
BYPASS_CH1=1
BYPASS_CH2=1
BYPASS_CH3=1
#BYPASS_CH1=0
#BYPASS_CH2=0
#BYPASS_CH3=0

# Prefer 12DB for brightness (whites are white and brightness can be slightly stronger)
# More detail in dark scenes without white crush
#AFE_12DB_EN=1
#EN_12DB_CH1=1
#EN_12DB_CH2=1
#EN_12DB_CH3=1
#AGC_GAIN=1000
#VGA_GAIN=0

# Prefer gain (VGA and AGC) for brightness (whites become more red and brightness slightly weaker).
# Possible to lose detail from white-crush in bright scenes due to the strong gain levels (this may result in better colors and you might not get white crush; it depends on the gain levels (AGC and VGA)).  This can give best results for composite video.
AFE_12DB_EN=0
EN_12DB_CH1=0
EN_12DB_CH2=0
EN_12DB_CH3=0
#AGC_GAIN=1500
AGC_GAIN=1350
VGA_GAIN=25

# Signal tuning
MODE10B=1
VBIHACTRAW_EN=1
#UV_LPF_SEL=10
#LUMA_LPF_SEL=10
UV_LPF_SEL=0
LUMA_LPF_SEL=0
SYNC_TIP_INC=1000
SYNC_TIP_REDUCE=0
FORMAT_45MHZ=1 # "auto-detect"
#FORMAT_65MHZ=1 # "System L"
#FORMAT_65MHZ=0 # "System DK"
#FORMAT_45MHZ=0 # Chroma
FORMAT_65MHZ=10 # Auto-detect
VGA_AUTO_EN=0 (0x0) "Freeze/manual"
VGA_CRUSH_EN=0 (0x0)

#Audio signal path
#SA_MCLK_SEL0
#SA_MCLK_DIV=0
#SA_UP2X_BYPASS=0
#AC97_UP2X_BYPASS=0
#BASEBAND_BYPASS_CTL=1
#DMTRX_BYPASS=1

EOF

# Cheat with these settings to get a nicer (and less accurate) look!
#(it's filtering hence it's cheating)!
#v4l2-ctl --set-ctrl temporal_filter_mode=0
#v4l2-ctl --set-ctrl temporal_filter=0
#v4l2-ctl --set-ctrl video_temporal_decimation=0 # Max 255. Doesn't work with temporal_filter_mode=1
#v4l2-ctl --set-ctrl median_filter_type=0
#v4l2-ctl --set-ctrl median_luma_filter_minimum=0
#v4l2-ctl --set-ctrl median_luma_filter_maximum=255
#v4l2-ctl --set-ctrl median_chroma_filter_minimum=0
#v4l2-ctl --set-ctrl median_chroma_filter_maximum=255
#v4l2-ctl --set-ctrl spatial_filter_mode=1
#v4l2-ctl --set-ctrl spatial_chroma_filter_type=0
#v4l2-ctl --set-ctrl spatial_luma_filter_type=1
#v4l2-ctl --set-ctrl spatial_filter=0

FORMAT_65MHZ=1 # "System L"
#FORMAT_65MHZ=0 # "System DK"
#FORMAT_45MHZ=0 # Chroma
FORMAT_65MHZ=10 # Auto-detect
VGA_AUTO_EN=0 (0x0) "Freeze/manual"
VGA_CRUSH_EN=0 (0x0)

#Audio signal path
#SA_MCLK_SEL0
#SA_MCLK_DIV=0
#SA_UP2X_BYPASS=0
#AC97_UP2X_BYPASS=0
#BASEBAND_BYPASS_CTL=1
#DMTRX_BYPASS=1

EOF

# Cheat with these settings to get a nicer (and less accurate) look!
#(it's filtering hence it's cheating)!
#v4l2-ctl --set-ctrl temporal_filter_mode=0
#v4l2-ctl --set-ctrl temporal_filter=0
#v4l2-ctl --set-ctrl video_temporal_decimation=0 # Max 255. Doesn't work with temporal_filter_mode=1
#v4l2-ctl --set-ctrl median_filter_type=0
#v4l2-ctl --set-ctrl median_luma_filter_minimum=0
#v4l2-ctl --set
holering
Posts: 9
Joined: Fri Dec 13, 2013 7:05 am

Re: pvr 150 based linux script + settings for better quality

Post by holering »

If you have agc issues with bright games (Duck Hunt, Crazy Taxi, etc), try to use a vcr to filter the composite or luminance (svideo to two rca phono style plug adapter. Pass luminance through composite). This will narrow the range and might allow proper sampling without agc attenuation. You can see the Mermaid movie examples here how it looks after it's passed through an svhs (it gets narrowed). viewtopic.php?p=1337072#p1337072

Even if you have a fully disabled agc, it's still worth filtering the results since a lot of bits are potentially saved without quality loss during sampling after manually offsetting the gain difference.

You can find and scavenge lots of faulty vcrs with bad heads or bad tape drives with fully functional composite passthrough and these become very useful as professional narrowers.

When sampling in Linux, use gstreamer. Gstreamer has a pipeline feature which maintains sync. Even after sampling, the sync may still seem off but this is corrected by changing framerate to match time of the audio. It's better to download every sampled frame instead of losing some from the sampling hardware. Audio and video clock sampling are usually different with frequency modulated sources so wrong framerate usually results.

edit
When narrowing the signal with a vcr from ypbpr, the green cable goes through composite input.
Post Reply