Added more SSTV modes

A bit more work done on Replay (still not enabled)
This commit is contained in:
furrtek 2017-03-23 21:28:21 +00:00
parent 6a0bcb9cca
commit 685e4c6e4b
19 changed files with 288 additions and 172 deletions

View File

@ -175,6 +175,28 @@ static constexpr Bitmap bitmap_sd_card_unknown {
{ 16, 16 }, bitmap_sd_card_unknown_data { 16, 16 }, bitmap_sd_card_unknown_data
}; };
static constexpr uint8_t bitmap_play_data[] = {
0x00, 0x00,
0x00, 0x00,
0x0C, 0x00,
0x3C, 0x00,
0xFC, 0x00,
0xFC, 0x03,
0xFC, 0x0F,
0xFC, 0x3F,
0xFC, 0x3F,
0xFC, 0x0F,
0xFC, 0x03,
0xFC, 0x00,
0x3C, 0x00,
0x0C, 0x00,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_play {
{ 16, 16 }, bitmap_play_data
};
static constexpr uint8_t bitmap_icon_stealth_data[] = { static constexpr uint8_t bitmap_icon_stealth_data[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,

View File

@ -319,6 +319,7 @@ public:
Result<Size> write(const void* const data, const Size bytes_to_write); Result<Size> write(const void* const data, const Size bytes_to_write);
Result<Offset> seek(const uint64_t Offset); Result<Offset> seek(const uint64_t Offset);
Size size();
template<size_t N> template<size_t N>
Result<Size> write(const std::array<uint8_t, N>& data) { Result<Size> write(const std::array<uint8_t, N>& data) {

View File

@ -23,13 +23,13 @@
// Color bitmaps generated with: // Color bitmaps generated with:
// Gimp image > indexed colors (16), then "xxd -i *.bmp" // Gimp image > indexed colors (16), then "xxd -i *.bmp"
//BUG: Length is wrong in soundboard for long files (> 1min ?)
//BUG: RDS Radiotext is not recognized in Redsea (and car radio) //BUG: RDS Radiotext is not recognized in Redsea (and car radio)
//BUG: RDS doesn't stop baseband when stopping tx ? //BUG: RDS doesn't stop baseband when stopping tx ?
//BUG: Check AFSK transmit end, skips last bits ? //BUG: Check AFSK transmit end, skips last bits ?
//TEST: Imperial in whipcalc //TEST: Imperial in whipcalc
//TODO: IQ replay
//TODO: Optimize (and group ?) CTCSS tone gen code //TODO: Optimize (and group ?) CTCSS tone gen code
//TODO: Morse use prosigns //TODO: Morse use prosigns
//TODO: Morse live keying mode ? //TODO: Morse live keying mode ?
@ -49,7 +49,6 @@ Continuous (Fox-oring)
//TODO: Script engine ? //TODO: Script engine ?
//TODO: Close Call multiple slices (buggy) //TODO: Close Call multiple slices (buggy)
//TODO: Finish EPAR tx //TODO: Finish EPAR tx
//TODO: IQ replay
//TODO: Wav visualizer //TODO: Wav visualizer
//TODO: File browser view ? //TODO: File browser view ?

View File

@ -21,6 +21,7 @@
*/ */
#include "replay_app.hpp" #include "replay_app.hpp"
#include "string_format.hpp"
#include "baseband_api.hpp" #include "baseband_api.hpp"
@ -32,20 +33,31 @@ using namespace portapack;
namespace ui { namespace ui {
ReplayAppView::ReplayAppView(NavigationView& nav) { ReplayAppView::ReplayAppView(
baseband::run_image(portapack::spi_flash::image_tag_replay); NavigationView& nav
) : nav_ (nav)
{
std::vector<std::filesystem::path> file_list;
// Search for files
file_list = scan_root_files(u"/", u"*.C16");
if (!file_list.size()) {
file_error = true;
return;
}
//baseband::run_image(portapack::spi_flash::image_tag_replay);
add_children({ add_children({
&channel,
&field_frequency, &field_frequency,
&field_frequency_step, &field_frequency_step,
&field_rf_amp, &field_rf_amp,
&field_lna,
&field_vga,
&replay_view, &replay_view,
&waterfall, &waterfall,
}); });
replay_view.set_file_list(file_list);
field_frequency.set_value(target_frequency()); field_frequency.set_value(target_frequency());
field_frequency.set_step(receiver_model.frequency_step()); field_frequency.set_step(receiver_model.frequency_step());
field_frequency.on_change = [this](rf::Frequency f) { field_frequency.on_change = [this](rf::Frequency f) {
@ -66,17 +78,6 @@ ReplayAppView::ReplayAppView(NavigationView& nav) {
this->field_frequency.set_step(v); this->field_frequency.set_step(v);
}; };
radio::enable({
target_frequency(),
sampling_rate,
baseband_bandwidth,
rf::Direction::Transmit,
receiver_model.rf_amp(),
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga())
});
replay_view.set_sampling_rate(sampling_rate / 8);
replay_view.on_error = [&nav](std::string message) { replay_view.on_error = [&nav](std::string message) {
nav.display_modal("Error", message); nav.display_modal("Error", message);
}; };

View File

@ -45,9 +45,13 @@ public:
void focus() override; void focus() override;
std::string title() const override { return "Capture"; }; std::string title() const override { return "Replay (beta)"; };
private: private:
NavigationView& nav_;
bool file_error { false };
static constexpr ui::Dim header_height = 2 * 16; static constexpr ui::Dim header_height = 2 * 16;
static constexpr uint32_t sampling_rate = 4000000; static constexpr uint32_t sampling_rate = 4000000;
@ -58,10 +62,6 @@ private:
rf::Frequency target_frequency() const; rf::Frequency target_frequency() const;
void set_target_frequency(const rf::Frequency new_value); void set_target_frequency(const rf::Frequency new_value);
Channel channel {
{ 24 * 8, 5, 6 * 8, 4 },
};
FrequencyField field_frequency { FrequencyField field_frequency {
{ 0 * 8, 0 * 16 }, { 0 * 8, 0 * 16 },
}; };
@ -74,20 +74,12 @@ private:
{ 16 * 8, 0 * 16 } { 16 * 8, 0 * 16 }
}; };
LNAGainField field_lna {
{ 18 * 8, 0 * 16 }
};
VGAGainField field_vga {
{ 21 * 8, 0 * 16 }
};
ReplayView replay_view { ReplayView replay_view {
{ 0 * 8, 1 * 16, 30 * 8, 1 * 16 }, { 0 * 8, 1 * 16, 30 * 8, 1 * 16 },
"BBD_????", ReplayView::FileType::RawS16, 16384, 3 16384, 3
}; };
spectrum::WaterfallWidget waterfall; spectrum::WaterfallWidget waterfall { };
}; };
} /* namespace ui */ } /* namespace ui */

View File

@ -358,10 +358,10 @@ SystemMenuView::SystemMenuView(NavigationView& nav) {
{ "Play dead", ui::Color::red(), &bitmap_icon_playdead, [&nav](){ nav.push<PlayDeadView>(); } }, { "Play dead", ui::Color::red(), &bitmap_icon_playdead, [&nav](){ nav.push<PlayDeadView>(); } },
{ "Receivers", ui::Color::cyan(), &bitmap_icon_receivers, [&nav](){ nav.push<ReceiverMenuView>(); } }, { "Receivers", ui::Color::cyan(), &bitmap_icon_receivers, [&nav](){ nav.push<ReceiverMenuView>(); } },
{ "Capture", ui::Color::blue(), &bitmap_icon_capture, [&nav](){ nav.push<CaptureAppView>(); } }, { "Capture", ui::Color::blue(), &bitmap_icon_capture, [&nav](){ nav.push<CaptureAppView>(); } },
{ "Replay", ui::Color::grey(), &bitmap_icon_replay, [&nav](){ nav.push<NotImplementedView>(); } }, { "Replay", ui::Color::grey(), &bitmap_icon_replay, [&nav](){ nav.push<NotImplementedView>(); } }, // ReplayAppView
{ "Audio transmitters", ui::Color::green(), &bitmap_icon_audiotx, [&nav](){ nav.push<TransmitterAudioMenuView>(); } }, { "Audio transmitters", ui::Color::green(), &bitmap_icon_audiotx, [&nav](){ nav.push<TransmitterAudioMenuView>(); } },
{ "Code transmitters", ui::Color::green(), &bitmap_icon_codetx, [&nav](){ nav.push<TransmitterCodedMenuView>(); } }, { "Code transmitters", ui::Color::green(), &bitmap_icon_codetx, [&nav](){ nav.push<TransmitterCodedMenuView>(); } },
{ "SSTV transmitter", ui::Color::dark_orange(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } }, { "SSTV transmitter", ui::Color::dark_green(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
{ "Close Call", ui::Color::cyan(), &bitmap_icon_closecall, [&nav](){ nav.push<CloseCallView>(); } }, { "Close Call", ui::Color::cyan(), &bitmap_icon_closecall, [&nav](){ nav.push<CloseCallView>(); } },
{ "Jammer", ui::Color::orange(),&bitmap_icon_jammer, [&nav](){ nav.push<JammerView>(); } }, { "Jammer", ui::Color::orange(),&bitmap_icon_jammer, [&nav](){ nav.push<JammerView>(); } },
{ "Utilities", ui::Color::purple(),&bitmap_icon_utilities, [&nav](){ nav.push<UtilitiesView>(); } }, { "Utilities", ui::Color::purple(),&bitmap_icon_utilities, [&nav](){ nav.push<UtilitiesView>(); } },

View File

@ -37,28 +37,38 @@ using namespace portapack;
namespace ui { namespace ui {
void ReplayView::on_file_changed(const uint32_t duration) {
std::string str_duration = "";
if (duration >= 60)
str_duration = to_string_dec_uint(duration / 60) + "m";
text_duration.set(str_duration + to_string_dec_uint(duration % 60) + "s");
}
ReplayView::ReplayView( ReplayView::ReplayView(
const Rect parent_rect, const Rect parent_rect,
std::string filename,
const FileType file_type,
const size_t read_size, const size_t read_size,
const size_t buffer_count const size_t buffer_count
) : View { parent_rect }, ) : View { parent_rect },
filename { filename },
file_type { file_type },
read_size { read_size }, read_size { read_size },
buffer_count { buffer_count } buffer_count { buffer_count }
{ {
add_children({ add_children({
&rect_background, &rect_background,
&button_record, &button_play,
&text_replay_filename, &options_files,
&text_time_seek, &text_duration,
//&text_time_seek,
}); });
rect_background.set_parent_rect({ { 0, 0 }, size() }); rect_background.set_parent_rect({ { 0, 0 }, size() });
button_record.on_select = [this](ImageButton&) { options_files.on_change = [this](size_t, int32_t duration) {
this->on_file_changed(duration);
};
button_play.on_select = [this](ImageButton&) {
this->toggle(); this->toggle();
}; };
@ -72,21 +82,22 @@ ReplayView::~ReplayView() {
} }
void ReplayView::focus() { void ReplayView::focus() {
button_record.focus(); options_files.focus();
} }
void ReplayView::set_sampling_rate(const size_t new_sampling_rate) { void ReplayView::set_file_list(const std::vector<std::filesystem::path>& file_list) {
if( new_sampling_rate != sampling_rate ) { File bbd_file;
stop(); uint32_t duration;
sampling_rate = new_sampling_rate;
button_record.hidden(sampling_rate == 0); for (const auto& file : file_list) {
text_replay_filename.hidden(sampling_rate == 0); bbd_file.open("/" + file.string());
text_time_seek.hidden(sampling_rate == 0); duration = bbd_file.size() / (2 * 2 * (sampling_rate / 8));
rect_background.hidden(sampling_rate != 0); file_options.emplace_back(file.string().substr(0, 8), duration);
update_status_display();
} }
options_files.set_options(file_options);
options_files.set_selected_index(0); // First file
on_file_changed(file_options[0].second);
} }
bool ReplayView::is_active() const { bool ReplayView::is_active() const {
@ -104,17 +115,10 @@ void ReplayView::toggle() {
void ReplayView::start() { void ReplayView::start() {
stop(); stop();
text_replay_filename.set("");
if( sampling_rate == 0 ) {
return;
}
auto reader = std::make_unique<FileReader>(); auto reader = std::make_unique<FileReader>();
if( reader ) { if( reader ) {
text_replay_filename.set(filename.string()); button_play.set_bitmap(&bitmap_stop);
button_record.set_bitmap(&bitmap_stop);
replay_thread = std::make_unique<ReplayThread>( replay_thread = std::make_unique<ReplayThread>(
std::move(reader), std::move(reader),
read_size, buffer_count, read_size, buffer_count,
@ -130,12 +134,23 @@ void ReplayView::start() {
} }
update_status_display(); update_status_display();
radio::enable({
460000000, //target_frequency(),
4000000, //sampling_rate,
2500000, //baseband_bandwidth,
rf::Direction::Transmit,
receiver_model.rf_amp(),
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga())
});
} }
void ReplayView::stop() { void ReplayView::stop() {
if( is_active() ) { if( is_active() ) {
replay_thread.reset(); replay_thread.reset();
button_record.set_bitmap(&bitmap_record); radio::disable();
button_play.set_bitmap(&bitmap_play);
} }
update_status_display(); update_status_display();

View File

@ -37,17 +37,10 @@ namespace ui {
class ReplayView : public View { class ReplayView : public View {
public: public:
std::function<void(std::string)> on_error; std::function<void(std::string)> on_error { };
enum FileType {
RawS16 = 2,
WAV = 3,
};
ReplayView( ReplayView(
const Rect parent_rect, const Rect parent_rect,
std::string filename,
FileType file_type,
const size_t read_size, const size_t read_size,
const size_t buffer_count const size_t buffer_count
); );
@ -55,7 +48,7 @@ public:
void focus() override; void focus() override;
void set_sampling_rate(const size_t new_sampling_rate); void set_file_list(const std::vector<std::filesystem::path>& file_list);
void start(); void start();
void stop(); void stop();
@ -63,43 +56,53 @@ public:
bool is_active() const; bool is_active() const;
private: private:
using option_t = std::pair<std::string, int32_t>;
using options_t = std::vector<option_t>;
static constexpr uint32_t sampling_rate = 4000000;
void toggle(); void toggle();
void on_file_changed(const uint32_t duration);
void on_tick_second(); void on_tick_second();
void update_status_display(); void update_status_display();
void handle_replay_thread_done(const File::Error error); void handle_replay_thread_done(const File::Error error);
void handle_error(const File::Error error); void handle_error(const File::Error error);
const std::filesystem::path filename;
const FileType file_type;
const size_t read_size; const size_t read_size;
const size_t buffer_count; const size_t buffer_count;
size_t sampling_rate { 0 }; SignalToken signal_token_tick_second { };
SignalToken signal_token_tick_second; options_t file_options { };
Rectangle rect_background { Rectangle rect_background {
Color::black() Color::black()
}; };
ImageButton button_record { ImageButton button_play {
{ 4 * 8, 0 * 16, 2 * 8, 1 * 16 }, { 0 * 8, 0 * 16, 2 * 8, 1 * 16 },
&bitmap_record, &bitmap_play,
Color::red(), Color::green(),
Color::black() Color::black()
}; };
Text text_replay_filename { OptionsField options_files {
{ 7 * 8, 0 * 16, 8 * 8, 16 }, { 2 * 8, 0 * 8 },
"", 8,
{ }
}; };
Text text_time_seek { Text text_duration {
{ 21 * 8, 0 * 16, 9 * 8, 16 }, { 11 * 8, 0 * 8, 12 * 8, 16 },
"", "-"
}; };
std::unique_ptr<ReplayThread> replay_thread; /*Text text_time_seek {
{ 18 * 8, 0 * 16, 9 * 8, 16 },
"",
};*/
std::unique_ptr<ReplayThread> replay_thread { };
MessageHandlerRegistration message_handler_capture_thread_error { MessageHandlerRegistration message_handler_capture_thread_error {
Message::ID::CaptureThreadDone, Message::ID::CaptureThreadDone,

View File

@ -99,6 +99,7 @@ void SSTVTXView::on_tuning_frequency_changed(rf::Frequency f) {
void SSTVTXView::prepare_scanline() { void SSTVTXView::prepare_scanline() {
sstv_scanline scanline_buffer; sstv_scanline scanline_buffer;
uint32_t component, pixel_idx; uint32_t component, pixel_idx;
uint8_t offset;
if (scanline_counter >= (256 * 3)) { if (scanline_counter >= (256 * 3)) {
progressbar.set_value(0); progressbar.set_value(0);
@ -123,30 +124,32 @@ void SSTVTXView::prepare_scanline() {
component = scanline_counter % 3; component = scanline_counter % 3;
if ((!scanline_counter) || (component == 2)) { if ((!scanline_counter && tx_sstv_mode->sync_on_first) || (component == tx_sstv_mode->sync_index)) {
// Sync
scanline_buffer.start_tone.frequency = SSTV_F2D(1200); scanline_buffer.start_tone.frequency = SSTV_F2D(1200);
scanline_buffer.start_tone.duration = SSTV_MS2S(9); scanline_buffer.start_tone.duration = tx_sstv_mode->samples_per_sync;
} else
scanline_buffer.start_tone.duration = 0;
scanline_buffer.gap_tone.frequency = SSTV_F2D(1500); scanline_buffer.gap_tone.frequency = SSTV_F2D(1500);
scanline_buffer.gap_tone.duration = SSTV_MS2S(1.5); scanline_buffer.gap_tone.duration = tx_sstv_mode->samples_per_gap;
} else {
// Regular scanline
scanline_buffer.start_tone.duration = 0;
if (tx_sstv_mode->gaps) {
scanline_buffer.gap_tone.frequency = SSTV_F2D(1500);
scanline_buffer.gap_tone.duration = tx_sstv_mode->samples_per_gap;
}
}
if (component == 0) { if (!component) {
// Read a new line // Read a new line
read_boundary(pixels_buffer, read_boundary(pixels_buffer,
bmp_header.image_data + ((255 - (scanline_counter / 3)) * sizeof(pixels_buffer)), bmp_header.image_data + ((255 - (scanline_counter / 3)) * sizeof(pixels_buffer)),
sizeof(pixels_buffer)); sizeof(pixels_buffer));
} }
offset = component_map[component];
for (uint32_t bmp_px = 0; bmp_px < 320; bmp_px++) { for (uint32_t bmp_px = 0; bmp_px < 320; bmp_px++) {
pixel_idx = bmp_px * 3; pixel_idx = bmp_px * 3;
if (component == 0) scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + offset];
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + 1]; // Green
else if (component == 1)
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx]; // Blue
else
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + 2]; // Red
} }
baseband::set_fifo_data((int8_t *)&scanline_buffer); baseband::set_fifo_data((int8_t *)&scanline_buffer);
@ -155,15 +158,12 @@ void SSTVTXView::prepare_scanline() {
} }
void SSTVTXView::start_tx() { void SSTVTXView::start_tx() {
// Baseband SSTV TX code should have a 2 scanlines buffer, and ask // The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before
// for fill-up when there's 1 or less remaining. This should leave // TX start, and asks for fill-up when a new scanline starts being read. This should
// enough time for the code here to generate the scanline data // leave enough time for the code in prepare_scanline() before it ends.
// before tx. See sstv.hpp:
// Scottie 2 is 320x256 px
scanline_counter = 0; scanline_counter = 0;
prepare_scanline(); prepare_scanline(); // Preload one scanline
transmitter_model.set_sampling_rate(3072000U); transmitter_model.set_sampling_rate(3072000U);
transmitter_model.set_rf_amp(true); transmitter_model.set_rf_amp(true);
@ -171,8 +171,8 @@ void SSTVTXView::start_tx() {
transmitter_model.enable(); transmitter_model.enable();
baseband::set_sstv_data( baseband::set_sstv_data(
0b00011101, // Scottie 2, 275.2us/px tx_sstv_mode->vis_code,
(uint32_t)(0.0002752 * 3072000.0) tx_sstv_mode->samples_per_pixel
); );
// Todo: Find a better way to prevent user from changing bitmap during tx // Todo: Find a better way to prevent user from changing bitmap during tx
@ -180,13 +180,31 @@ void SSTVTXView::start_tx() {
tx_view.focus(); tx_view.focus();
} }
void SSTVTXView::on_bitmap_changed(size_t index) { void SSTVTXView::on_bitmap_changed(const size_t index) {
bmp_file.open("/sstv/" + bitmaps[index].string()); bmp_file.open("/sstv/" + bitmaps[index].string());
bmp_file.read(&bmp_header, sizeof(bmp_header)); bmp_file.read(&bmp_header, sizeof(bmp_header));
progressbar.set_max(256 * 3);
set_dirty(); set_dirty();
} }
void SSTVTXView::on_mode_changed(const size_t index) {
sstv_color_seq tx_color_sequence;
tx_sstv_mode = &sstv_modes[index];
tx_color_sequence = sstv_modes[index].color_sequence;
if (tx_color_sequence == SSTV_COLOR_RGB) {
component_map[0] = 2;
component_map[1] = 1;
component_map[2] = 0;
} else if (tx_color_sequence == SSTV_COLOR_GBR) {
component_map[0] = 1;
component_map[1] = 0;
component_map[2] = 2;
}
progressbar.set_max(sstv_modes[index].lines * 3);
}
SSTVTXView::SSTVTXView( SSTVTXView::SSTVTXView(
NavigationView& nav NavigationView& nav
) : nav_ (nav) ) : nav_ (nav)
@ -195,6 +213,8 @@ SSTVTXView::SSTVTXView(
using option_t = std::pair<std::string, int32_t>; using option_t = std::pair<std::string, int32_t>;
using options_t = std::vector<option_t>; using options_t = std::vector<option_t>;
options_t bitmap_options; options_t bitmap_options;
options_t mode_options;
uint32_t c;
// Search for valid bitmaps // Search for valid bitmaps
file_list = scan_root_files(u"/sstv", u"*.bmp"); file_list = scan_root_files(u"/sstv", u"*.bmp");
@ -205,11 +225,11 @@ SSTVTXView::SSTVTXView(
for (const auto& file_name : file_list) { for (const auto& file_name : file_list) {
if (!bmp_file.open("/sstv/" + file_name.string()).is_valid()) { if (!bmp_file.open("/sstv/" + file_name.string()).is_valid()) {
bmp_file.read(&bmp_header, sizeof(bmp_header)); bmp_file.read(&bmp_header, sizeof(bmp_header));
if ((bmp_header.signature == 0x4D42) && if ((bmp_header.signature == 0x4D42) && // "BM"
(bmp_header.width == 320) && // Must be == 320x256 pixels for now (bmp_header.width == 320) && // Must be exactly 320x256 pixels for now
(bmp_header.height == 256) && (bmp_header.height == 256) &&
(bmp_header.planes == 1) && (bmp_header.planes == 1) &&
(bmp_header.bpp >= 24) && // 24 or 32 bpp (bmp_header.bpp == 24) && // 24 bpp only
(bmp_header.compression == 0)) { // No compression (bmp_header.compression == 0)) { // No compression
bitmaps.push_back(file_name); bitmaps.push_back(file_name);
} }
@ -227,21 +247,33 @@ SSTVTXView::SSTVTXView(
add_children({ add_children({
&labels, &labels,
&options_bitmaps, &options_bitmaps,
&text_mode, &options_modes,
&progressbar, &progressbar,
&tx_view &tx_view
}); });
// Populate file list
for (const auto& bitmap : bitmaps) for (const auto& bitmap : bitmaps)
bitmap_options.emplace_back(bitmap.string().substr(0, 16), 0); bitmap_options.emplace_back(bitmap.string().substr(0, 16), 0);
options_bitmaps.set_options(bitmap_options); options_bitmaps.set_options(bitmap_options);
// Populate mode list
for (c = 0; c < SSTV_MODES_NB; c++)
mode_options.emplace_back(sstv_modes[c].name, c);
options_modes.set_options(mode_options);
options_bitmaps.on_change = [this](size_t i, int32_t) { options_bitmaps.on_change = [this](size_t i, int32_t) {
this->on_bitmap_changed(i); this->on_bitmap_changed(i);
}; };
options_bitmaps.set_selected_index(0); options_bitmaps.set_selected_index(0); // First file
on_bitmap_changed(0); on_bitmap_changed(0);
options_modes.on_change = [this](size_t i, int32_t) {
this->on_mode_changed(i);
};
options_modes.set_selected_index(1); // Scottie 2
on_mode_changed(1);
tx_view.on_edit_frequency = [this, &nav]() { tx_view.on_edit_frequency = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency()); auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
new_view->on_changed = [this](rf::Frequency f) { new_view->on_changed = [this](rf::Frequency f) {

View File

@ -44,6 +44,11 @@ public:
SSTVTXView(NavigationView& nav); SSTVTXView(NavigationView& nav);
~SSTVTXView(); ~SSTVTXView();
SSTVTXView(const SSTVTXView&) = delete;
SSTVTXView(SSTVTXView&&) = delete;
SSTVTXView& operator=(const SSTVTXView&) = delete;
SSTVTXView& operator=(SSTVTXView&&) = delete;
void focus() override; void focus() override;
void paint(Painter&) override; void paint(Painter&) override;
@ -54,21 +59,26 @@ private:
sstv_scanline scanline_buffer { }; sstv_scanline scanline_buffer { };
bool file_error { false };
File bmp_file { }; File bmp_file { };
bmp_header_t bmp_header { }; bmp_header_t bmp_header { };
std::vector<std::filesystem::path> bitmaps { }; std::vector<std::filesystem::path> bitmaps { };
bool file_error { false };
uint32_t scanline_counter { 0 }; uint32_t scanline_counter { 0 };
uint8_t pixels_buffer[320 * 3]; // 320 pixels @ 24bpp uint8_t pixels_buffer[320 * 3]; // 320 pixels @ 24bpp
const sstv_mode * tx_sstv_mode { };
uint8_t component_map[3] { };
void read_boundary(uint8_t * buffer, uint32_t position, uint32_t length); void read_boundary(uint8_t * buffer, uint32_t position, uint32_t length);
void on_bitmap_changed(size_t index); void on_bitmap_changed(const size_t index);
void on_mode_changed(const size_t index);
void on_tuning_frequency_changed(rf::Frequency f); void on_tuning_frequency_changed(rf::Frequency f);
void start_tx(); void start_tx();
void prepare_scanline(); void prepare_scanline();
Labels labels { Labels labels {
{ { 1 * 8, 1 * 8 }, "File:", Color::light_grey() } { { 1 * 8, 1 * 8 }, "File:", Color::light_grey() },
{ { 1 * 8, 3 * 8 }, "Mode:", Color::light_grey() }
}; };
OptionsField options_bitmaps { OptionsField options_bitmaps {
@ -76,9 +86,10 @@ private:
16, 16,
{ } { }
}; };
Text text_mode { OptionsField options_modes {
{ 2 * 8, 4 * 8, 16 * 8, 16 }, { 6 * 8, 3 * 8 },
"Scottie 2" 16,
{ }
}; };
ProgressBar progressbar { ProgressBar progressbar {

View File

@ -39,13 +39,17 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
//const auto& decimator_out = decim_1_out; //const auto& decimator_out = decim_1_out;
//const auto& channel = decimator_out; //const auto& channel = decimator_out;
//if( stream ) { if( stream ) {
// const size_t bytes_to_write = sizeof(*decimator_out.p) * decimator_out.count; const size_t bytes_to_read = buffer.count; // ?
// const auto result = stream->write(decimator_out.p, bytes_to_write); const auto result = stream->read(iq_buffer.p, bytes_to_read);
//} }
//feed_channel_stats(channel); //feed_channel_stats(channel);
for (size_t i = 0; i < buffer.count; i++) {
buffer.p[i] = { iq_buffer.p[i].real() >> 8, iq_buffer.p[i].imag() >> 8};
}
/*spectrum_samples += channel.count; /*spectrum_samples += channel.count;
if( spectrum_samples >= spectrum_interval_samples ) { if( spectrum_samples >= spectrum_interval_samples ) {
spectrum_samples -= spectrum_interval_samples; spectrum_samples -= spectrum_interval_samples;
@ -60,7 +64,7 @@ void ReplayProcessor::on_message(const Message* const message) {
channel_spectrum.on_message(message); channel_spectrum.on_message(message);
break;*/ break;*/
case Message::ID::ReplayConfig: case Message::ID::CaptureConfig:
replay_config(*reinterpret_cast<const ReplayConfigMessage*>(message)); replay_config(*reinterpret_cast<const ReplayConfigMessage*>(message));
break; break;

View File

@ -52,13 +52,13 @@ private:
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit };
//RSSIThread rssi_thread { NORMALPRIO + 10 }; //RSSIThread rssi_thread { NORMALPRIO + 10 };
std::array<complex16_t, 512> dst; std::array<complex16_t, 2048> iq { };
const buffer_c16_t dst_buffer { const buffer_c16_t iq_buffer {
dst.data(), iq.data(),
dst.size() iq.size()
}; };
std::unique_ptr<StreamOutput> stream; std::unique_ptr<StreamOutput> stream { };
/*SpectrumCollector channel_spectrum; /*SpectrumCollector channel_spectrum;
size_t spectrum_interval_samples = 0; size_t spectrum_interval_samples = 0;

View File

@ -40,7 +40,7 @@ void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
// of the scanline. Todo: simplify ! // of the scanline. Todo: simplify !
if (state == STATE_CALIBRATION) { if (state == STATE_CALIBRATION) {
// Once per scanline // Once per picture
tone_delta = calibration_sequence[substep].first; tone_delta = calibration_sequence[substep].first;
sample_count = calibration_sequence[substep].second; sample_count = calibration_sequence[substep].second;
if (substep == 2) { if (substep == 2) {
@ -49,17 +49,15 @@ void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
} else } else
substep++; substep++;
} else if (state == STATE_VIS) { } else if (state == STATE_VIS) {
// Once per scanline // Once per picture
if (substep == 10) { if (substep == 10) {
current_scanline = &scanline_buffer[buffer_flip]; current_scanline = &scanline_buffer[buffer_flip];
buffer_flip ^= 1; buffer_flip ^= 1;
if (asked == false) {
// Ask application for a new scanline // Ask application for a new scanline
shared_memory.application_queue.push(sig_message); shared_memory.application_queue.push(sig_message);
asked = true; // Do we have to transmit a start tone ?
}
if (current_scanline->start_tone.duration) { if (current_scanline->start_tone.duration) {
state = STATE_START; state = STATE_SYNC;
tone_delta = current_scanline->start_tone.frequency; tone_delta = current_scanline->start_tone.frequency;
sample_count = current_scanline->start_tone.duration; sample_count = current_scanline->start_tone.duration;
} else { } else {
@ -69,23 +67,19 @@ void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
} }
} else { } else {
tone_delta = vis_code_sequence[substep]; tone_delta = vis_code_sequence[substep];
sample_count = SSTV_MS2S(30); // VIS code bit is 30ms sample_count = SSTV_MS2S(30); // A VIS code bit is 30ms
substep++; substep++;
} }
} else if (state == STATE_START) { } else if (state == STATE_SYNC) {
// Once per scanline, optional // Once per scanline, optional
state = STATE_PIXELS; state = STATE_PIXELS;
tone_delta = current_scanline->gap_tone.frequency; tone_delta = current_scanline->gap_tone.frequency;
sample_count = current_scanline->gap_tone.duration; sample_count = current_scanline->gap_tone.duration;
} else if (state == STATE_PIXELS) { } else if (state == STATE_PIXELS) {
// Many times per scanline // Many times per scanline
pixel_luma = current_scanline->luma[pixel_index]; tone_delta = SSTV_F2D(1500 + ((current_scanline->luma[pixel_index] * 800) / 256));
pixel_index++;
tone_delta = SSTV_F2D(1500 + ((pixel_luma * 800) / 256));
sample_count = pixel_duration; sample_count = pixel_duration;
pixel_index++;
if (pixel_index >= 320) { if (pixel_index >= 320) {
// Scanline done, (dirty) state jump // Scanline done, (dirty) state jump
@ -98,6 +92,7 @@ void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
sample_count--; sample_count--;
} }
// Tone synth
tone_sample = (sine_table_i8[(tone_phase & 0xFF000000U) >> 24]); tone_sample = (sine_table_i8[(tone_phase & 0xFF000000U) >> 24]);
tone_phase += tone_delta; tone_phase += tone_delta;
@ -116,29 +111,27 @@ void SSTVTXProcessor::execute(const buffer_c8_t& buffer) {
void SSTVTXProcessor::on_message(const Message* const msg) { void SSTVTXProcessor::on_message(const Message* const msg) {
const auto message = *reinterpret_cast<const SSTVConfigureMessage*>(msg); const auto message = *reinterpret_cast<const SSTVConfigureMessage*>(msg);
uint8_t vis_code;
switch(msg->id) { switch(msg->id) {
case Message::ID::SSTVConfigure: case Message::ID::SSTVConfigure:
pixel_duration = message.pixel_duration; pixel_duration = message.pixel_duration;
if (!pixel_duration) { if (!pixel_duration) {
configured = false; configured = false; // Shutdown
return; return;
} }
vis_code = message.vis_code; vis_code = message.vis_code;
// VIS code: // VIS code:
// 1200 // 1200, (0=1300, 1=1100), 1200
// 00011101 (0=1300, 1=1100)
// 1200
vis_code_sequence[0] = SSTV_VIS_SS; vis_code_sequence[0] = SSTV_VIS_SS;
for (uint32_t c = 0; c < 8; c++) { for (uint32_t c = 0; c < 8; c++)
vis_code_sequence[c + 1] = ((vis_code << c) & 0x80) ? SSTV_VIS_ONE : SSTV_VIS_ZERO; vis_code_sequence[c + 1] = ((vis_code >> c) & 1) ? SSTV_VIS_ONE : SSTV_VIS_ZERO;
}
vis_code_sequence[9] = SSTV_VIS_SS; vis_code_sequence[9] = SSTV_VIS_SS;
fm_delta = 9000 * (0xFFFFFFULL / 3072000); // Fixed for now fm_delta = 9000 * (0xFFFFFFULL / 3072000); // Fixed bw for now
pixel_index = 0; pixel_index = 0;
sample_count = 0; sample_count = 0;
@ -151,7 +144,6 @@ void SSTVTXProcessor::on_message(const Message* const msg) {
case Message::ID::FIFOData: case Message::ID::FIFOData:
memcpy(&scanline_buffer[buffer_flip], static_cast<const FIFODataMessage*>(msg)->data, sizeof(sstv_scanline)); memcpy(&scanline_buffer[buffer_flip], static_cast<const FIFODataMessage*>(msg)->data, sizeof(sstv_scanline));
asked = false;
break; break;
default: default:

View File

@ -50,7 +50,7 @@ private:
enum state_t { enum state_t {
STATE_CALIBRATION = 0, STATE_CALIBRATION = 0,
STATE_VIS, STATE_VIS,
STATE_START, STATE_SYNC,
STATE_PIXELS STATE_PIXELS
}; };
@ -63,8 +63,6 @@ private:
uint32_t vis_code_sequence[10] { }; uint32_t vis_code_sequence[10] { };
sstv_scanline scanline_buffer[2] { }; sstv_scanline scanline_buffer[2] { };
uint8_t buffer_flip { 0 }, substep { 0 }; uint8_t buffer_flip { 0 }, substep { 0 };
uint8_t vis_code { };
uint32_t pixel_duration { }; uint32_t pixel_duration { };
sstv_scanline * current_scanline { }; sstv_scanline * current_scanline { };
@ -77,9 +75,7 @@ private:
uint32_t sample_count { 0 }; uint32_t sample_count { 0 };
uint32_t phase { 0 }, sphase { 0 }; uint32_t phase { 0 }, sphase { 0 };
int32_t tone_sample { 0 }, delta { 0 }; int32_t tone_sample { 0 }, delta { 0 };
int8_t re { 0 }, im { 0 }; int8_t re { }, im { };
bool asked { false };
RequestSignalMessage sig_message { RequestSignalMessage::Signal::FillRequest }; RequestSignalMessage sig_message { RequestSignalMessage::Signal::FillRequest };
}; };

View File

@ -40,7 +40,7 @@ StreamOutput::StreamOutput(ReplayConfig* const config) :
} }
} }
size_t StreamOutput::write(const void* const data, const size_t length) { size_t StreamOutput::read(const void* const data, const size_t length) {
const uint8_t* p = static_cast<const uint8_t*>(data); const uint8_t* p = static_cast<const uint8_t*>(data);
size_t written = 0; size_t written = 0;

View File

@ -35,7 +35,12 @@ class StreamOutput {
public: public:
StreamOutput(ReplayConfig* const config); StreamOutput(ReplayConfig* const config);
size_t write(const void* const data, const size_t length); StreamOutput(const StreamOutput&) = delete;
StreamOutput(StreamOutput&&) = delete;
StreamOutput& operator=(const StreamOutput&) = delete;
StreamOutput& operator=(StreamOutput&&) = delete;
size_t read(const void* const data, const size_t length);
private: private:
static constexpr size_t buffer_count_max_log2 = 3; static constexpr size_t buffer_count_max_log2 = 3;

View File

@ -29,12 +29,28 @@ namespace sstv {
#define SSTV_DELTA_COEF ((1ULL << 32) / SSTV_SAMPLERATE) #define SSTV_DELTA_COEF ((1ULL << 32) / SSTV_SAMPLERATE)
#define SSTV_F2D(f) (uint32_t)((f) * SSTV_DELTA_COEF) #define SSTV_F2D(f) (uint32_t)((f) * SSTV_DELTA_COEF)
#define SSTV_MS2S(f) (uint32_t)((f) / 1000.0 * (float)SSTV_SAMPLERATE) #define SSTV_MS2S(d) (uint32_t)((d) / 1000.0 * (float)SSTV_SAMPLERATE)
#define SSTV_VIS_SS SSTV_F2D(1200) #define SSTV_VIS_SS SSTV_F2D(1200)
#define SSTV_VIS_ZERO SSTV_F2D(1300) #define SSTV_VIS_ZERO SSTV_F2D(1300)
#define SSTV_VIS_ONE SSTV_F2D(1100) #define SSTV_VIS_ONE SSTV_F2D(1100)
enum sstv_color_seq {
SSTV_COLOR_RGB,
SSTV_COLOR_GBR,
SSTV_COLOR_YUV // Not supported for now
};
#define SSTV_MODES_NB 6
// From http://www.graphics.stanford.edu/~seander/bithacks.html, nice !
inline uint8_t sstv_parity(uint8_t code) {
uint8_t out = code;
out ^= code >> 4;
out &= 0x0F;
return (((0b0110100110010110 >> out) & 1) << 7) | code;
}
struct sstv_tone { struct sstv_tone {
uint32_t frequency; uint32_t frequency;
uint32_t duration; uint32_t duration;
@ -46,6 +62,33 @@ struct sstv_scanline {
uint8_t luma[320]; uint8_t luma[320];
}; };
struct sstv_mode {
std::string name;
uint8_t vis_code;
bool color; // Unused for now
sstv_color_seq color_sequence;
uint16_t pixels;
uint16_t lines;
uint32_t samples_per_pixel;
bool sync_on_first;
uint8_t sync_index;
bool gaps;
uint32_t samples_per_sync;
uint32_t samples_per_gap;
//std::pair<uint16_t, uint16_t> luma_range;
};
const sstv_mode sstv_modes[SSTV_MODES_NB] = {
{ "Scottie 1", sstv_parity(60), true, SSTV_COLOR_GBR, 320, 256, SSTV_MS2S(0.4320), true, 2, true, SSTV_MS2S(9), SSTV_MS2S(1.5) },
{ "Scottie 2", sstv_parity(56), true, SSTV_COLOR_GBR, 320, 256, SSTV_MS2S(0.2752), true, 2, true, SSTV_MS2S(9), SSTV_MS2S(1.5) },
{ "Scottie DX", sstv_parity(76), true, SSTV_COLOR_GBR, 320, 256, SSTV_MS2S(1.08), true, 2, true, SSTV_MS2S(9), SSTV_MS2S(1.5) },
{ "Martin 1", sstv_parity(44), true, SSTV_COLOR_GBR, 320, 256, SSTV_MS2S(0.4576), false, 0, true, SSTV_MS2S(4.862), SSTV_MS2S(0.572) },
{ "Martin 2", sstv_parity(40), true, SSTV_COLOR_GBR, 320, 256, SSTV_MS2S(0.2288), false, 0, true, SSTV_MS2S(4.862), SSTV_MS2S(0.572) },
{ "SC2-180", sstv_parity(55), true, SSTV_COLOR_RGB, 320, 256, SSTV_MS2S(0.7344), false, 0, false, SSTV_MS2S(5.5225), SSTV_MS2S(0.5) },
//{ "PASOKON 3", sstv_parity(113), true, SSTV_COLOR_RGB, 640, 496, SSTV_MS2S(0.2083), { 1500, 2300 } },
//{ "PASOKON 7", sstv_parity(115), true, SSTV_COLOR_RGB, 640, 496, SSTV_MS2S(0.4167), { 1500, 2300 } }
};
} /* namespace sstv */ } /* namespace sstv */
#endif/*__SSTV_H__*/ #endif/*__SSTV_H__*/

BIN
firmware/graphics/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.