当前位置: 移动技术网 > IT编程>网页制作>HTML > Portapack应用开发教程SSTV接收机 F

Portapack应用开发教程SSTV接收机 F

2020年11月26日  | 移动技术网IT编程  | 我要评论
上一篇文章我计算了声音的频率。后来我可以用模拟视频解调的控件来展示图像亮度根据频率变化了,这个没什么特别的,只是花时间就能搞定,所以我这里就不贴代码了。现在我要绘制真正的sstv图像了,但是我需要一个无线电的sstv信号源,我之前只有声波sstv信号源。(portapack本身也能作为无线电sstv信号源,但是只有martin和scottie制式,没有robot8。)后来用了下面的流图,它把wav文件经过nbfm调制转为无线电波,可以作为我要的信号源。

上一篇文章我计算了声音的频率。

后来我可以用模拟视频解调的控件来展示图像亮度根据频率变化了,这个没什么特别的,只是花时间就能搞定,所以我这里就不贴代码了。

现在我要绘制真正的sstv图像了,但是我需要一个无线电的sstv信号源,我之前只有声波sstv信号源。(portapack本身也能作为无线电sstv信号源,但是只有martin和scottie制式,没有robot8。)

后来用了下面的流图,它把wav文件经过nbfm调制转为无线电波,可以作为我要的信号源。

 

https://github.com/undertuga/NBFM-TX

我先用电脑上的hackrf和解码程序测试了一下,确实能从这个信号源里得到图像。效果比声波传输得更少。

接下来,确认信号源没问题后,我就可以用它来测试portapack的接收了。

我还发现了每行的像素点数量不是固定的,不同照片是不一样的,如果不在正确的位置换行,那么照片可能是斜着的。

这个现象在portapack和电脑上都会发现。

换行问题,在电脑上很容易优化,但是portapack上就没那么方便了。下面是电脑上的代码节选,针对不同图片要设置不同换行的位置。

这是因为本来sstv里面的换行信号被我忽略了。否则我可以等那个信号出现就换行。以后得加回去。

 if (lineIndex == 534) //583 for black white//534 for selfie//519 for cartoon
        {
            lineCount = lineCount + 1;
            lineIndex = 0;

            imshow("frame", frame);
            if (waitKey(5) == 'q')
            {

            }
        }

下面是我在portapack里的要改的比较重要的文件。

这个文件基于ui_tv.cpp改的。 

ui_sstv.cpp

/*
 * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
 * Copyright (C) 2020 Shao
 *
 * This file is part of PortaPack.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#include "ui_sstv.hpp"

#include "spectrum_color_lut.hpp"

#include "portapack.hpp"
using namespace portapack;

#include "baseband_api.hpp"

#include "string_format.hpp"

#include <cmath>
#include <array>

namespace ui {
namespace sstv {


/* TimeScopeView******************************************************/

TimeScopeView::TimeScopeView(
	const Rect parent_rect
) : View { parent_rect }
{
	set_focusable(true);
	
	add_children({
		//&labels,
		//&field_frequency,
		&waveform
	});
	
	/*field_frequency.on_change = [this](int32_t) {
		set_dirty();
	};
	field_frequency.set_value(10);*/
}

void TimeScopeView::paint(Painter& painter) {
	const auto r = screen_rect();

	painter.fill_rectangle(r, Color::black());
	
	// Cursor
	/*
	const Rect r_cursor {
		field_frequency.value() / (48000 / 240), r.bottom() - 32 - cursor_band_height,
		1, cursor_band_height
	};
	painter.fill_rectangle(
		r_cursor,
		Color::red()
	);*/
}

void TimeScopeView::on_audio_spectrum(const AudioSpectrum* spectrum) {
	for (size_t i = 0; i < spectrum->db.size(); i++)
		audio_spectrum[i] = ((int16_t)spectrum->db[i] - 127) * 256;
	waveform.set_dirty();
}
/* SSTVView *********************************************************/

void SSTVView::on_show() {
	clear();

	const auto screen_r = screen_rect();
	display.scroll_set_area(screen_r.top(), screen_r.bottom());
}

void SSTVView::on_hide() {
	/* TODO: Clear region to eliminate brief flash of content at un-shifted
	 * position?
	 */
	display.scroll_disable();
}

void SSTVView::paint(Painter& painter) {
	// Do nothing.
	(void)painter;
}

void SSTVView::on_adjust_xcorr(uint8_t xcorr){
	x_correction = xcorr;
}

void SSTVView::on_channel_spectrum(
	const ChannelSpectrum& spectrum
) {

	for(size_t i=0; i<=63; i++) 
	{
		video_buffer_int[i+count*64] = spectrum.db[i*4];
	}
	count = count + 1;
	if (count == 200)
	{
		count = 0;
		ui::Color line_buffer[200];

		uint32_t bmp_px;
		for (line = 0; line < 101; line++)
		{
			for (bmp_px = 0; bmp_px < 125; bmp_px++) //125 good for classic 120 good for black 
			{	
				line_buffer[bmp_px] = spectrum_rgb4_lut[video_buffer_int[bmp_px+125*line]];
			}

			display.render_line({ 0, line + 100 }, 200 , line_buffer);
		}
	}
}

void SSTVView::clear() {
	display.fill_rectangle(
		screen_rect(),
		Color::black()
	);
}

/* SSTVWidget *******************************************************/

SSTVWidget::SSTVWidget(const bool cursor) {
	add_children({
		&sstv_view,
		&field_xcorr
	});
	field_xcorr.set_value(10);
}

void SSTVWidget::on_show() {
	baseband::spectrum_streaming_start();
}

void SSTVWidget::on_hide() {
	baseband::spectrum_streaming_stop();
}

void SSTVWidget::show_audio_spectrum_view(const bool show) {
	if ((audio_spectrum_view && show) || (!audio_spectrum_view && !show)) return;
	
	if (show) {
		audio_spectrum_view = std::make_unique<TimeScopeView>(audio_spectrum_view_rect);
		add_child(audio_spectrum_view.get());
		update_widgets_rect();
	} else {
		audio_spectrum_update = false;
		remove_child(audio_spectrum_view.get());
		audio_spectrum_view.reset();
		update_widgets_rect();
	}
}

void SSTVWidget::update_widgets_rect() {
	if (audio_spectrum_view) {
		sstv_view.set_parent_rect(sstv_reduced_rect);
	} else {
		sstv_view.set_parent_rect(sstv_normal_rect);
	}
	sstv_view.on_show();
}

void SSTVWidget::set_parent_rect(const Rect new_parent_rect) {
	View::set_parent_rect(new_parent_rect);
	
	sstv_normal_rect = { 0, scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height};
	sstv_reduced_rect = { 0, audio_spectrum_height + scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height - audio_spectrum_height };
	
	update_widgets_rect();
}

void SSTVWidget::paint(Painter& painter) {
	// TODO:
	(void)painter;
}

void SSTVWidget::on_channel_spectrum(const ChannelSpectrum& spectrum) {
	sstv_view.on_channel_spectrum(spectrum);
	sstv_view.on_adjust_xcorr(field_xcorr.value());
	sampling_rate = spectrum.sampling_rate;
	
}

void SSTVWidget::on_audio_spectrum() {
	audio_spectrum_view->on_audio_spectrum(audio_spectrum_data);
}

} /* namespace sstv */
} /* namespace ui */

on_channel_spectrum里是最核心的部分,把收到的数据组合起来,成为一个比较长的缓存数组。

然后再从缓存数组里读出每一行的数据绘制出来。

125决定了这一行的长度,相同制式,不同图片,长度是可变的。

count决定了刷新率,101是一次显示多少行,相当于一幅画面的长度。

要保证count*64 > 101*125。

这里101和125都是代码里写死的,这样还不是很好。

至少要做一个可以界面上更改125的方法,然后101根据125和count来自动算出来。如果125都能自动计算就更好了,我在考虑要不要做。也许还是做一个robot8在portapack上的发射机更有意义?

现在还有不少值得优化的,比如只用了低通滤波,没用降噪和带通滤波,另外2000~2300Hz现在颜色都是白色饱和了,照道理这个范围亮度还应该有变化的。

给你们看看我目前已经实现的效果。

原图:

我解调出来的:

视频:

https://www.bilibili.com/video/BV1YK411V79X/

本文地址:https://blog.csdn.net/shukebeta008/article/details/110145158

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网