mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-17 19:54:35 -05:00
Soundboard bugfix: shouldn't crash with long file names
This commit is contained in:
parent
394331ebd2
commit
15f66eb74e
@ -166,23 +166,15 @@ std::filesystem::path next_filename_stem_matching_pattern(std::filesystem::path
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::filesystem::path> scan_root_files(const TCHAR* directory, const std::string& extension) {
|
std::vector<std::filesystem::path> scan_root_files(const std::filesystem::path& directory,
|
||||||
|
const std::filesystem::path& extension) {
|
||||||
|
|
||||||
std::vector<std::filesystem::path> file_list { };
|
std::vector<std::filesystem::path> file_list { };
|
||||||
std::filesystem::path file_path;
|
|
||||||
FRESULT res;
|
for(const auto& entry : std::filesystem::directory_iterator(directory, extension)) {
|
||||||
DIR dir;
|
if( std::filesystem::is_regular_file(entry.status()) ) {
|
||||||
static FILINFO fno;
|
file_list.push_back(entry.path());
|
||||||
|
|
||||||
res = f_opendir(&dir, directory);
|
|
||||||
if (res == FR_OK) {
|
|
||||||
for (;;) {
|
|
||||||
res = f_readdir(&dir, &fno);
|
|
||||||
if (res != FR_OK || fno.fname[0] == 0) break;
|
|
||||||
file_path = fno.fname;
|
|
||||||
if (file_path.extension().string() == extension)
|
|
||||||
file_list.push_back(file_path);
|
|
||||||
}
|
}
|
||||||
f_closedir(&dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return file_list;
|
return file_list;
|
||||||
|
@ -233,7 +233,7 @@ space_info space(const path& p);
|
|||||||
} /* namespace filesystem */
|
} /* namespace filesystem */
|
||||||
} /* namespace std */
|
} /* namespace std */
|
||||||
|
|
||||||
std::vector<std::filesystem::path> scan_root_files(const TCHAR* directory, const std::string& extension);
|
std::vector<std::filesystem::path> scan_root_files(const std::filesystem::path& directory, const std::filesystem::path& extension);
|
||||||
std::filesystem::path next_filename_stem_matching_pattern(std::filesystem::path filename_stem_pattern);
|
std::filesystem::path next_filename_stem_matching_pattern(std::filesystem::path filename_stem_pattern);
|
||||||
|
|
||||||
/* Values added to FatFs FRESULT enum, values outside the FRESULT data type */
|
/* Values added to FatFs FRESULT enum, values outside the FRESULT data type */
|
||||||
|
@ -125,13 +125,13 @@ private:
|
|||||||
data_t data;
|
data_t data;
|
||||||
};
|
};
|
||||||
|
|
||||||
header_t header;
|
header_t header { };
|
||||||
|
|
||||||
File file;
|
File file { };
|
||||||
uint32_t data_start;
|
uint32_t data_start { };
|
||||||
uint32_t bytes_per_sample;
|
uint32_t bytes_per_sample { };
|
||||||
uint32_t data_size_;
|
uint32_t data_size_ { 0 };
|
||||||
uint32_t sample_rate_;
|
uint32_t sample_rate_ { };
|
||||||
std::filesystem::path last_path { };
|
std::filesystem::path last_path { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,9 +89,8 @@ void SoundBoardView::prepare_audio() {
|
|||||||
void SoundBoardView::focus() {
|
void SoundBoardView::focus() {
|
||||||
buttons[0].focus();
|
buttons[0].focus();
|
||||||
|
|
||||||
if (!max_sound) {
|
if (!max_sound)
|
||||||
nav_.display_modal("No files", "No files in /wav/ directory", ABORT, nullptr);
|
nav_.display_modal("No files", "No files in /wav/ directory", ABORT, nullptr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundBoardView::on_tuning_frequency_changed(rf::Frequency f) {
|
void SoundBoardView::on_tuning_frequency_changed(rf::Frequency f) {
|
||||||
@ -157,7 +156,7 @@ void SoundBoardView::refresh_buttons(uint16_t id) {
|
|||||||
button.id = n_sound;
|
button.id = n_sound;
|
||||||
|
|
||||||
if (n_sound < max_sound) {
|
if (n_sound < max_sound) {
|
||||||
button.set_text(sounds[n_sound].path.stem().string());
|
button.set_text(sounds[n_sound].path.stem().string().substr(0, 8));
|
||||||
button.set_style(styles[sounds[n_sound].path.stem().string()[0] & 3]);
|
button.set_style(styles[sounds[n_sound].path.stem().string()[0] & 3]);
|
||||||
} else {
|
} else {
|
||||||
button.set_text("- - -");
|
button.set_text("- - -");
|
||||||
@ -204,11 +203,11 @@ SoundBoardView::SoundBoardView(
|
|||||||
|
|
||||||
reader = std::make_unique<WAVFileReader>();
|
reader = std::make_unique<WAVFileReader>();
|
||||||
|
|
||||||
file_list = scan_root_files(reinterpret_cast<const TCHAR*>("/wav"), ".WAV");
|
file_list = scan_root_files(u"wav", u"*.WAV");
|
||||||
|
|
||||||
c = 0;
|
c = 0;
|
||||||
for (auto& path : file_list) {
|
for (auto& path : file_list) {
|
||||||
if (reader->open(path)) {
|
if (reader->open(u"wav/" + path.native())) {
|
||||||
if (reader->channels() == 1) {
|
if (reader->channels() == 1) {
|
||||||
sounds[c].size = reader->data_size();
|
sounds[c].size = reader->data_size();
|
||||||
sounds[c].sample_duration = reader->data_size() / (reader->bits_per_sample() / 8);
|
sounds[c].sample_duration = reader->data_size() / (reader->bits_per_sample() / 8);
|
||||||
@ -234,7 +233,7 @@ SoundBoardView::SoundBoardView(
|
|||||||
&field_frequency,
|
&field_frequency,
|
||||||
&number_bw,
|
&number_bw,
|
||||||
&text_kHz,
|
&text_kHz,
|
||||||
&options_ctcss,
|
//&options_ctcss,
|
||||||
&text_page,
|
&text_page,
|
||||||
&text_duration,
|
&text_duration,
|
||||||
&pbar,
|
&pbar,
|
||||||
@ -243,7 +242,7 @@ SoundBoardView::SoundBoardView(
|
|||||||
&button_exit
|
&button_exit
|
||||||
});
|
});
|
||||||
|
|
||||||
ctcss_options.emplace_back(std::make_pair("None", 0));
|
/*ctcss_options.emplace_back(std::make_pair("None", 0));
|
||||||
|
|
||||||
for (c = 0; c < CTCSS_TONES_NB; c++)
|
for (c = 0; c < CTCSS_TONES_NB; c++)
|
||||||
ctcss_options.emplace_back(std::make_pair(ctcss_tones[c].PL_code, c));
|
ctcss_options.emplace_back(std::make_pair(ctcss_tones[c].PL_code, c));
|
||||||
@ -253,7 +252,7 @@ SoundBoardView::SoundBoardView(
|
|||||||
options_ctcss.on_change = [this](size_t, OptionsField::value_t v) {
|
options_ctcss.on_change = [this](size_t, OptionsField::value_t v) {
|
||||||
this->on_ctcss_changed(v);
|
this->on_ctcss_changed(v);
|
||||||
};
|
};
|
||||||
options_ctcss.set_selected_index(0);
|
options_ctcss.set_selected_index(0);*/
|
||||||
|
|
||||||
const auto button_fn = [this](Button& button) {
|
const auto button_fn = [this](Button& button) {
|
||||||
tx_mode = NORMAL;
|
tx_mode = NORMAL;
|
||||||
|
@ -69,19 +69,19 @@ private:
|
|||||||
uint32_t ms_duration = 0;
|
uint32_t ms_duration = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t sample_counter;
|
uint32_t sample_counter { 0 };
|
||||||
uint32_t sample_duration;
|
uint32_t sample_duration { 0 };
|
||||||
uint8_t page = 0;
|
uint8_t page = 0;
|
||||||
|
|
||||||
uint16_t lfsr_v = 0x1337;
|
uint16_t lfsr_v = 0x1337;
|
||||||
|
|
||||||
std::unique_ptr<WAVFileReader> reader;
|
std::unique_ptr<WAVFileReader> reader { };
|
||||||
|
|
||||||
sound sounds[105];
|
sound sounds[105];
|
||||||
uint8_t max_sound;
|
uint8_t max_sound { 0 };
|
||||||
uint8_t max_page;
|
uint8_t max_page { 0 };
|
||||||
|
|
||||||
uint32_t _ctcss_freq;
|
uint32_t _ctcss_freq { 0 };
|
||||||
|
|
||||||
int8_t audio_buffer[1024];
|
int8_t audio_buffer[1024];
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ private:
|
|||||||
.foreground = { 153, 102, 255 }
|
.foreground = { 153, 102, 255 }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::array<Button, 21> buttons;
|
std::array<Button, 21> buttons { };
|
||||||
const Style * styles[4] = { &style_a, &style_b, &style_c, &style_d };
|
const Style * styles[4] = { &style_a, &style_b, &style_c, &style_d };
|
||||||
|
|
||||||
void on_tuning_frequency_changed(rf::Frequency f);
|
void on_tuning_frequency_changed(rf::Frequency f);
|
||||||
|
@ -47,11 +47,12 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
||||||
auto audio = demod.execute(channel_out, audio_buffer);
|
auto audio = demod.execute(channel_out, audio_buffer);
|
||||||
|
|
||||||
// End up with 16 samples
|
// End up with 32 samples ?
|
||||||
for (uint32_t c = 0; c < 16; c++) {
|
for (uint32_t c = 0; c < 16; c++) {
|
||||||
|
|
||||||
const int32_t audio_sample = audio.p[c] * 32768.0f;
|
const int32_t sample_int = audio.p[c] * 32768.0f;
|
||||||
//const int32_t audio_sample = __SSAT(sample_int, 16);
|
//const int32_t audio_sample = audio.p[c] * 32768.0f;
|
||||||
|
const int32_t audio_sample = __SSAT(sample_int, 16);
|
||||||
|
|
||||||
slicer_sr <<= 1;
|
slicer_sr <<= 1;
|
||||||
slicer_sr |= (audio_sample < 0);
|
slicer_sr |= (audio_sample < 0);
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user