4.1 Overview
ntsc.raw is generated by a Python script. The flow is as follows:
Python generates PCM data at 1 line = 12 samples, writes 262 lines per frame, saves to SD card as ntsc.raw. Spresense plays it back via AudioClass at 192kHz 24bit Stereo through the CXD5247 DAC. Audio Jack outputs L ch as VIDEO through 470 ohm and R ch as SYNC through 1k ohm. These are mixed by resistors and sent via RCA to the TV.
4.2 Constants
SAMPLE_RATE is 188811 Hz, fine-tuned from actual measurement. NTSC horizontal sync frequency is 15734.26 Hz. NTSC_H is 262 vertical lines. NTSC_W is 12 samples per line. SYNC_W is 2 samples for sync pulse width. BLANK_W is 3 samples for blanking width. VRAM_W is 9 samples equals 9 pixels. LINE_REPEAT is 3 lines per pixel row. VRAM_H is 87 lines.
4.3 Writing One Sample
24bit Stereo means 6 bytes per sample. L channel carries VIDEO data, R channel carries SYNC data, both written in 24bit little-endian format.
4.4 Generating One Frame
Lines 0 to 8 are the vertical sync period.
Lines 9 to 20 are the vertical blanking period.
Lines 21 to 261 are the active video period.
Within each active line, the first 2 samples are SYNC,
next 1 sample is BLANK,
and the remaining 9 samples carry VIDEO data mapped from VRAM.
4.5 VRAM and Drawing
VRAM is a 2D array of 9 columns by 87 rows. Each cell holds 0 or 1. draw_pixel writes to VRAM with bounds checking.
4.6 font3x5 Character Drawing
Each character is represented as a 15bit bitmap in a 3 wide by 5 tall dot matrix. draw_char iterates over each bit and calls draw_pixel accordingly.
4.7 Loop Playback
ntsc.raw contains only 1 frame. When Spresense reaches the end of the file it seeks back to the beginning and continues playing. This allows continuous NTSC video output from a file of only 1.8KB.
chrmlinux03
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.