Skip to content

Commit

Permalink
Merge pull request #14 from joshua-jerred/sstv_fix
Browse files Browse the repository at this point in the history
SSTV fix
  • Loading branch information
joshua-jerred authored Aug 14, 2024
2 parents e449479 + d111ac0 commit d4dd100
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
19 changes: 19 additions & 0 deletions docs/sstv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SSTV

## Robot36 quick notes

Audio sample rate of 48000, so 1728000 total samples. This means 7200 samples,
150ms, per scan line.

| | |
| ----------------- | ---------------------------------------- |
| *VIS Code* | 8d (decimal) |
| Color Mode | Y, R-Y, B-Y |
| Scan Sequence | Y, R-Y (even lines) - Y, B-Y (odd lines) |
| Number of Lines | 240 |
| Transmission Time | 36 seconds |
| Image Size | 320x240 |

## Useful links

https://vu2nsb.com/cw-digital-radio/slow-scan-tv-sstv/
3 changes: 3 additions & 0 deletions include/SignalEasel/sstv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Modulator : public signal_easel::Modulator {
enum class ColorFormat { _4_2_0_, _4_2_2_, NONE };
enum class ColorType { Y, Cb, Cr };

void addPreamble();
void encodeAdjustedImage(SstvImage &image);
void readImageLine(SstvImage &image, uint32_t line_number);
void encodeScanLine(uint32_t line_number);
Expand All @@ -85,6 +86,8 @@ class Modulator : public signal_easel::Modulator {
uint32_t line_width_ = 0;
uint32_t num_of_lines_ = 0;

uint8_t vis_code_ = 0;

double y_scan_line_time_ = 0;
double c_scan_line_time_ = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Boost_erSeat
35 changes: 33 additions & 2 deletions src/sstv/sstv_modulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Modulator::Modulator(sstv::Settings settings) : settings_(std::move(settings)) {
color_format_ = ColorFormat::_4_2_0_;
line_width_ = 320;
num_of_lines_ = 240;

vis_code_ = 0b10001000;

y_scan_line_time_ = 88.0;
c_scan_line_time_ = 44.0;

Expand Down Expand Up @@ -64,13 +67,41 @@ void Modulator::encodeImage(std::string input_image_path) {
}

scan_line_buffer_.reserve(line_width_);

addPreamble();
encodeAdjustedImage(image);

} catch (const std::exception &e) {
throw Exception(Exception::Id::SSTV_IMAGE_TOOLS_ERROR, e.what());
}
}

void Modulator::addPreamble() {
auto visCodeBitFrequncy = [](uint8_t vis_code, uint8_t bit_number) {
return vis_code & (1 << bit_number) ? 1100 : 1300;
};

pulse(100, 1900);
pulse(100, 1500);
pulse(100, 1900);
pulse(100, 1500);
pulse(100, 2300);
pulse(100, 1500);
pulse(100, 2300);
pulse(100, 1500);

pulse(300, 1900); // Leader Tone
pulse(10, 1500); // Break
pulse(300, 1900); // Leader Tone

pulse(30, 1200); // Start Bit

for (int i = 0; i < 8; i++) {
pulse(30, visCodeBitFrequncy(vis_code_, i));
}

pulse(21, 1200); // Stop Bit
}

void Modulator::encodeAdjustedImage(SstvImage &image) {
for (uint32_t i = 0; i < num_of_lines_; i++) {
// for (int i = 0; i < 1; i++) {
Expand Down Expand Up @@ -167,7 +198,7 @@ void Modulator::writeBuffer(const double total_time, ColorType ycbcr_colors) {
int previous_pixel_index = -1;
int frequency = 0;
double color = 0;
for (int i = 0; i < num_of_samples; i++) {
for (int i = 1; i <= num_of_samples; i++) {
int new_pixel_index =
(int)((double)i / (double)num_of_samples * (double)line_width_);
if (new_pixel_index != previous_pixel_index) {
Expand Down

0 comments on commit d4dd100

Please sign in to comment.