mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-13 08:55:39 -04:00
Bias-T now works in capture mode
Simplified soundboard app, still some work to do Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
1d13389b5a
21 changed files with 557 additions and 125 deletions
|
@ -27,9 +27,6 @@
|
|||
#include "portapack.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
CaptureAppView::CaptureAppView(NavigationView& nav) {
|
||||
|
@ -49,20 +46,20 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
|
|||
&waterfall,
|
||||
});
|
||||
|
||||
field_frequency.set_value(target_frequency());
|
||||
field_frequency.set_value(receiver_model.tuning_frequency());
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
this->on_target_frequency_changed(f);
|
||||
this->on_tuning_frequency_changed(f);
|
||||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(this->target_frequency());
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
this->on_target_frequency_changed(f);
|
||||
this->on_tuning_frequency_changed(f);
|
||||
this->field_frequency.set_value(f);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
field_frequency_step.set_by_value(receiver_model.frequency_step());
|
||||
field_frequency_step.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
receiver_model.set_frequency_step(v);
|
||||
|
@ -70,26 +67,19 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
|
|||
};
|
||||
|
||||
option_bandwidth.on_change = [this](size_t, uint32_t base_rate) {
|
||||
sampling_rate = 8 * base_rate;
|
||||
sampling_rate = 8 * base_rate; // Decimation by 8 done on baseband side
|
||||
|
||||
waterfall.on_hide();
|
||||
set_target_frequency(target_frequency());
|
||||
record_view.set_sampling_rate(sampling_rate);
|
||||
radio::set_baseband_rate(sampling_rate);
|
||||
receiver_model.set_sampling_rate(sampling_rate);
|
||||
waterfall.on_show();
|
||||
};
|
||||
|
||||
radio::enable({
|
||||
tuning_frequency(),
|
||||
sampling_rate,
|
||||
baseband_bandwidth,
|
||||
rf::Direction::Receive,
|
||||
receiver_model.rf_amp(),
|
||||
static_cast<int8_t>(receiver_model.lna()),
|
||||
static_cast<int8_t>(receiver_model.vga()),
|
||||
});
|
||||
|
||||
option_bandwidth.set_selected_index(7); // 500k
|
||||
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::Capture);
|
||||
receiver_model.set_baseband_bandwidth(baseband_bandwidth);
|
||||
receiver_model.enable();
|
||||
|
||||
record_view.on_error = [&nav](std::string message) {
|
||||
nav.display_modal("Error", message);
|
||||
|
@ -97,8 +87,7 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
|
|||
}
|
||||
|
||||
CaptureAppView::~CaptureAppView() {
|
||||
radio::disable();
|
||||
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
|
@ -120,21 +109,8 @@ void CaptureAppView::focus() {
|
|||
record_view.focus();
|
||||
}
|
||||
|
||||
void CaptureAppView::on_target_frequency_changed(rf::Frequency f) {
|
||||
set_target_frequency(f);
|
||||
}
|
||||
|
||||
void CaptureAppView::set_target_frequency(const rf::Frequency new_value) {
|
||||
persistent_memory::set_tuned_frequency(new_value);;
|
||||
radio::set_tuning_frequency(tuning_frequency());
|
||||
}
|
||||
|
||||
rf::Frequency CaptureAppView::target_frequency() const {
|
||||
return persistent_memory::tuned_frequency();
|
||||
}
|
||||
|
||||
rf::Frequency CaptureAppView::tuning_frequency() const {
|
||||
return target_frequency() - (sampling_rate / 4);
|
||||
void CaptureAppView::on_tuning_frequency_changed(rf::Frequency f) {
|
||||
receiver_model.set_tuning_frequency(f);
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
#include "ui_record_view.hpp"
|
||||
#include "ui_spectrum.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace ui {
|
||||
|
||||
class CaptureAppView : public View {
|
||||
|
@ -53,12 +50,7 @@ private:
|
|||
uint32_t sampling_rate = 0;
|
||||
static constexpr uint32_t baseband_bandwidth = 2500000;
|
||||
|
||||
void on_target_frequency_changed(rf::Frequency f);
|
||||
|
||||
rf::Frequency target_frequency() const;
|
||||
void set_target_frequency(const rf::Frequency new_value);
|
||||
|
||||
rf::Frequency tuning_frequency() const;
|
||||
void on_tuning_frequency_changed(rf::Frequency f);
|
||||
|
||||
Labels labels {
|
||||
{ { 0 * 8, 1 * 16 }, "Rate:", Color::light_grey() },
|
||||
|
|
250
firmware/application/apps/soundboard_app.cpp
Normal file
250
firmware/application/apps/soundboard_app.cpp
Normal file
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// To prepare samples: for f in ./*.wav; do sox "$f" -r 48000 -c 1 -b8 --norm "conv/$f"; done
|
||||
|
||||
#include "soundboard_app.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "tonesets.hpp"
|
||||
|
||||
using namespace tonekey;
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui {
|
||||
|
||||
bool SoundBoardView::is_active() const {
|
||||
return (bool)replay_thread;
|
||||
}
|
||||
|
||||
void SoundBoardView::stop() {
|
||||
if (is_active())
|
||||
replay_thread.reset();
|
||||
|
||||
transmitter_model.disable();
|
||||
tx_view.set_transmitting(false);
|
||||
|
||||
//button_play.set_bitmap(&bitmap_play);
|
||||
ready_signal = false;
|
||||
}
|
||||
|
||||
void SoundBoardView::handle_replay_thread_done(const uint32_t return_code) {
|
||||
stop();
|
||||
progressbar.set_value(0);
|
||||
|
||||
if (return_code == ReplayThread::END_OF_FILE) {
|
||||
if (check_random.value()) {
|
||||
lfsr_v = lfsr_iterate(lfsr_v);
|
||||
playing_id = lfsr_v % file_list.size();
|
||||
menu_view.set_highlighted(playing_id);
|
||||
start_tx(playing_id);
|
||||
} else if (check_loop.value()) {
|
||||
start_tx(playing_id);
|
||||
}
|
||||
} else if (return_code == ReplayThread::READ_ERROR) {
|
||||
file_error();
|
||||
}
|
||||
}
|
||||
|
||||
void SoundBoardView::set_ready() {
|
||||
ready_signal = true;
|
||||
}
|
||||
|
||||
void SoundBoardView::focus() {
|
||||
menu_view.focus();
|
||||
}
|
||||
|
||||
void SoundBoardView::file_error() {
|
||||
nav_.display_modal("Error", "File read error.");
|
||||
}
|
||||
|
||||
void SoundBoardView::start_tx(const uint32_t id) {
|
||||
auto reader = std::make_unique<WAVFileReader>();
|
||||
uint32_t tone_key_index = options_tone_key.selected_index();
|
||||
uint32_t sample_rate;
|
||||
|
||||
stop();
|
||||
|
||||
if (!reader->open(u"/WAV/" + file_list[id].native())) {
|
||||
file_error();
|
||||
return;
|
||||
}
|
||||
|
||||
playing_id = id;
|
||||
|
||||
progressbar.set_max(reader->sample_count());
|
||||
|
||||
//button_play.set_bitmap(&bitmap_stop);
|
||||
|
||||
sample_rate = reader->sample_rate();
|
||||
|
||||
replay_thread = std::make_unique<ReplayThread>(
|
||||
std::move(reader),
|
||||
read_size, buffer_count,
|
||||
&ready_signal,
|
||||
[](uint32_t return_code) {
|
||||
ReplayThreadDoneMessage message { return_code };
|
||||
EventDispatcher::send_message(message);
|
||||
}
|
||||
);
|
||||
|
||||
baseband::set_audiotx_config(
|
||||
1536000 / 20, // Update vu-meter at 20Hz
|
||||
transmitter_model.channel_bandwidth(),
|
||||
0, // Gain is unused
|
||||
TONES_F2D(tone_key_frequency(tone_key_index), 1536000)
|
||||
);
|
||||
baseband::set_sample_rate(sample_rate);
|
||||
|
||||
transmitter_model.set_sampling_rate(1536000);
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
transmitter_model.enable();
|
||||
|
||||
tx_view.set_transmitting(true);
|
||||
}
|
||||
|
||||
/*void SoundBoardView::show_infos() {
|
||||
if (!reader->open(file_list[menu_view.highlighted_index()]))
|
||||
return;
|
||||
|
||||
text_duration.set(to_string_time_ms(reader->ms_duration()));
|
||||
text_title.set(reader->title().substr(0, 15));
|
||||
}*/
|
||||
|
||||
void SoundBoardView::on_tx_progress(const uint32_t progress) {
|
||||
progressbar.set_value(progress);
|
||||
}
|
||||
|
||||
void SoundBoardView::on_select_entry() {
|
||||
tx_view.focus();
|
||||
}
|
||||
|
||||
void SoundBoardView::refresh_list() {
|
||||
auto reader = std::make_unique<WAVFileReader>();
|
||||
|
||||
file_list.clear();
|
||||
|
||||
// List directories and files, put directories up top
|
||||
for (const auto& entry : std::filesystem::directory_iterator(u"WAV", u"*")) {
|
||||
if (std::filesystem::is_regular_file(entry.status())) {
|
||||
if (entry.path().string().length()) {
|
||||
|
||||
auto entry_extension = entry.path().extension().string();
|
||||
|
||||
for (auto &c: entry_extension)
|
||||
c = toupper(c);
|
||||
|
||||
if (entry_extension == ".WAV") {
|
||||
|
||||
if (reader->open(u"/WAV/" + entry.path().native())) {
|
||||
if ((reader->channels() == 1) && (reader->bits_per_sample() == 8)) {
|
||||
//sounds[c].ms_duration = reader->ms_duration();
|
||||
//sounds[c].path = u"WAV/" + entry.path().native();
|
||||
file_list.push_back(entry.path());
|
||||
if (file_list.size() == 100)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_list.size()) {
|
||||
// Hide widgets, show warning
|
||||
menu_view.hidden(true);
|
||||
text_empty.hidden(false);
|
||||
set_dirty();
|
||||
} else {
|
||||
// Hide warning, show widgets
|
||||
menu_view.hidden(false);
|
||||
text_empty.hidden(true);
|
||||
set_dirty();
|
||||
|
||||
menu_view.clear();
|
||||
|
||||
for (size_t n = 0; n < file_list.size(); n++) {
|
||||
menu_view.add_item({
|
||||
file_list[n].string().substr(0, 30),
|
||||
ui::Color::white(),
|
||||
nullptr,
|
||||
[this](){
|
||||
on_select_entry();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
menu_view.set_highlighted(0); // Refresh
|
||||
}
|
||||
}
|
||||
|
||||
SoundBoardView::SoundBoardView(
|
||||
NavigationView& nav
|
||||
) : nav_ (nav)
|
||||
{
|
||||
baseband::run_image(portapack::spi_flash::image_tag_audio_tx);
|
||||
|
||||
add_children({
|
||||
&labels,
|
||||
&menu_view,
|
||||
&text_empty,
|
||||
&options_tone_key,
|
||||
&text_title,
|
||||
&text_duration,
|
||||
&progressbar,
|
||||
&check_loop,
|
||||
&check_random,
|
||||
&tx_view
|
||||
});
|
||||
|
||||
refresh_list();
|
||||
|
||||
text_title.set(to_string_dec_uint(file_list.size()));
|
||||
|
||||
tone_keys_populate(options_tone_key);
|
||||
options_tone_key.set_selected_index(0);
|
||||
|
||||
check_loop.set_value(false);
|
||||
check_random.set_value(false);
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
transmitter_model.set_tuning_frequency(f);
|
||||
};
|
||||
};
|
||||
|
||||
tx_view.on_start = [this]() {
|
||||
start_tx(menu_view.highlighted_index());
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
tx_view.set_transmitting(false);
|
||||
stop();
|
||||
};
|
||||
}
|
||||
|
||||
SoundBoardView::~SoundBoardView() {
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
}
|
161
firmware/application/apps/soundboard_app.hpp
Normal file
161
firmware/application/apps/soundboard_app.hpp
Normal file
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __UI_SOUNDBOARD_H__
|
||||
#define __UI_SOUNDBOARD_H__
|
||||
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "replay_thread.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "lfsr_random.hpp"
|
||||
#include "io_wave.hpp"
|
||||
#include "tone_key.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class SoundBoardView : public View {
|
||||
public:
|
||||
SoundBoardView(NavigationView& nav);
|
||||
~SoundBoardView();
|
||||
|
||||
SoundBoardView(const SoundBoardView&) = delete;
|
||||
SoundBoardView(SoundBoardView&&) = delete;
|
||||
SoundBoardView& operator=(const SoundBoardView&) = delete;
|
||||
SoundBoardView& operator=(SoundBoardView&&) = delete;
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Soundboard"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
enum tx_modes {
|
||||
NORMAL = 0,
|
||||
RANDOM
|
||||
};
|
||||
|
||||
tx_modes tx_mode = NORMAL;
|
||||
|
||||
uint32_t playing_id { };
|
||||
|
||||
std::vector<std::filesystem::path> file_list { };
|
||||
|
||||
const size_t read_size { 2048 }; // Less ?
|
||||
const size_t buffer_count { 3 };
|
||||
std::unique_ptr<ReplayThread> replay_thread { };
|
||||
bool ready_signal { false };
|
||||
lfsr_word_t lfsr_v = 1;
|
||||
|
||||
//void show_infos();
|
||||
void start_tx(const uint32_t id);
|
||||
//void on_ctcss_changed(uint32_t v);
|
||||
void stop();
|
||||
bool is_active() const;
|
||||
void set_ready();
|
||||
void handle_replay_thread_done(const uint32_t return_code);
|
||||
void file_error();
|
||||
void on_tx_progress(const uint32_t progress);
|
||||
void refresh_list();
|
||||
void on_select_entry();
|
||||
|
||||
Labels labels {
|
||||
{ { 0, 20 * 8 + 4 }, "Title:", Color::light_grey() },
|
||||
{ { 0, 23 * 8 }, "Key:", Color::light_grey() }
|
||||
};
|
||||
|
||||
MenuView menu_view {
|
||||
{ 0, 2 * 8, 240, 20 * 8 },
|
||||
true
|
||||
};
|
||||
Text text_empty {
|
||||
{ 7 * 8, 12 * 8, 16 * 8, 16 },
|
||||
"Empty directory !",
|
||||
};
|
||||
|
||||
Text text_title {
|
||||
{ 6 * 8, 20 * 8 + 4, 15 * 8, 16 }
|
||||
};
|
||||
|
||||
Text text_duration {
|
||||
{ 22 * 8, 20 * 8 + 4, 6 * 8, 16 }
|
||||
};
|
||||
|
||||
OptionsField options_tone_key {
|
||||
{ 4 * 8, 23 * 8 },
|
||||
18,
|
||||
{ }
|
||||
};
|
||||
|
||||
Checkbox check_loop {
|
||||
{ 8, 25 * 8 + 4 },
|
||||
4,
|
||||
"Loop"
|
||||
};
|
||||
|
||||
Checkbox check_random {
|
||||
{ 10 * 8, 25 * 8 + 4 },
|
||||
6,
|
||||
"Random"
|
||||
};
|
||||
|
||||
ProgressBar progressbar {
|
||||
{ 0 * 8, 30 * 8 - 4, 30 * 8, 16 }
|
||||
};
|
||||
|
||||
TransmitterView tx_view {
|
||||
16 * 16,
|
||||
5000,
|
||||
12
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_replay_thread_error {
|
||||
Message::ID::ReplayThreadDone,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const ReplayThreadDoneMessage*>(p);
|
||||
this->handle_replay_thread_done(message.return_code);
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_fifo_signal {
|
||||
Message::ID::RequestSignal,
|
||||
[this](const Message* const p) {
|
||||
const auto message = static_cast<const RequestSignalMessage*>(p);
|
||||
if (message->signal == RequestSignalMessage::Signal::FillRequest) {
|
||||
this->set_ready();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress {
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.progress);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif/*__UI_SOUNDBOARD_H__*/
|
Loading…
Add table
Add a link
Reference in a new issue