mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Semi-naive audio recording to SD card.
This commit is contained in:
parent
c01f2d82e1
commit
59f1a32566
@ -183,6 +183,7 @@ CPPSRC = main.cpp \
|
||||
file.cpp \
|
||||
log_file.cpp \
|
||||
png_writer.cpp \
|
||||
audio_thread.cpp \
|
||||
manchester.cpp \
|
||||
string_format.cpp \
|
||||
temperature_logger.cpp \
|
||||
|
@ -135,6 +135,8 @@ AnalogAudioView::AnalogAudioView(
|
||||
audio::output::start();
|
||||
|
||||
update_modulation(static_cast<ReceiverModel::Mode>(modulation));
|
||||
|
||||
audio_thread = std::make_unique<AudioThread>("audio.s16");
|
||||
}
|
||||
|
||||
AnalogAudioView::~AnalogAudioView() {
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_spectrum.hpp"
|
||||
|
||||
#include "audio_thread.hpp"
|
||||
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
|
||||
namespace ui {
|
||||
@ -146,6 +148,8 @@ private:
|
||||
|
||||
spectrum::WaterfallWidget waterfall;
|
||||
|
||||
std::unique_ptr<AudioThread> audio_thread;
|
||||
|
||||
void on_tuning_frequency_changed(rf::Frequency f);
|
||||
void on_baseband_bandwidth_changed(uint32_t bandwidth_hz);
|
||||
void on_rf_amp_changed(bool v);
|
||||
|
24
firmware/application/audio_thread.cpp
Normal file
24
firmware/application/audio_thread.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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 "audio_thread.hpp"
|
||||
|
||||
Thread* AudioThread::thread = nullptr;
|
127
firmware/application/audio_thread.hpp
Normal file
127
firmware/application/audio_thread.hpp
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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 __AUDIO_THREAD_H__
|
||||
#define __AUDIO_THREAD_H__
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
#include "file.hpp"
|
||||
|
||||
#include "event_m0.hpp"
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "hackrf_gpio.hpp"
|
||||
using namespace hackrf::one;
|
||||
|
||||
#include <cstring>
|
||||
|
||||
class StreamOutput {
|
||||
public:
|
||||
StreamOutput(
|
||||
FIFO<uint8_t, 13>* const fifo
|
||||
) : fifo { fifo }
|
||||
{
|
||||
}
|
||||
|
||||
size_t available() {
|
||||
return fifo->len();
|
||||
}
|
||||
|
||||
size_t read(void* const data, const size_t length) {
|
||||
return fifo->out(reinterpret_cast<uint8_t*>(data), length);
|
||||
}
|
||||
|
||||
private:
|
||||
FIFO<uint8_t, 13>* const fifo;
|
||||
};
|
||||
|
||||
class AudioThread {
|
||||
public:
|
||||
AudioThread(
|
||||
std::string file_path
|
||||
) : file_path { std::move(file_path) }
|
||||
{
|
||||
// Need significant stack for FATFS
|
||||
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this);
|
||||
}
|
||||
|
||||
~AudioThread() {
|
||||
chThdTerminate(thread);
|
||||
chThdWait(thread);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string file_path;
|
||||
|
||||
File file;
|
||||
static Thread* thread;
|
||||
|
||||
static msg_t static_fn(void* arg) {
|
||||
auto obj = static_cast<AudioThread*>(arg);
|
||||
obj->run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void run() {
|
||||
auto write_buffer = std::make_unique<std::array<uint8_t, 4096>>();
|
||||
if( !write_buffer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( !file.open_for_append(file_path) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
while( !chThdShouldTerminate() ) {
|
||||
// SUCH A HACK!!!
|
||||
|
||||
auto fifo = reinterpret_cast<FIFO<uint8_t, 13>*>(shared_memory.FIFO_HACK);
|
||||
if( !fifo ) {
|
||||
break;
|
||||
}
|
||||
|
||||
StreamOutput stream { fifo };
|
||||
|
||||
if( stream.available() >= write_buffer->size() ) {
|
||||
led_usb.on();
|
||||
|
||||
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
|
||||
|
||||
if( bytes_to_write ) {
|
||||
if( !file.write(write_buffer->data(), bytes_to_write) ) {
|
||||
led_tx.on();
|
||||
break;
|
||||
}
|
||||
}
|
||||
led_usb.off();
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(25);
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
};
|
||||
|
||||
#endif/*__AUDIO_THREAD_H__*/
|
@ -251,4 +251,6 @@ void EventDispatcher::init_message_queues() {
|
||||
new (&shared_memory.application_queue) MessageQueue(
|
||||
shared_memory.application_queue_data, SharedMemory::application_queue_k
|
||||
);
|
||||
|
||||
shared_memory.FIFO_HACK = nullptr;
|
||||
}
|
||||
|
@ -83,15 +83,21 @@ void AudioOutput::on_block(
|
||||
}
|
||||
}
|
||||
|
||||
fill_audio_buffer(audio);
|
||||
fill_audio_buffer(audio, audio_present);
|
||||
}
|
||||
|
||||
void AudioOutput::fill_audio_buffer(const buffer_f32_t& audio) {
|
||||
void AudioOutput::fill_audio_buffer(const buffer_f32_t& audio, const bool send_to_fifo) {
|
||||
std::array<int16_t, 32> audio_int;
|
||||
|
||||
auto audio_buffer = audio::dma::tx_empty_buffer();
|
||||
for(size_t i=0; i<audio_buffer.count; i++) {
|
||||
const int32_t sample_int = audio.p[i] * k;
|
||||
const int32_t sample_saturated = __SSAT(sample_int, 16);
|
||||
audio_buffer.p[i].left = audio_buffer.p[i].right = sample_saturated;
|
||||
audio_int[i] = sample_saturated;
|
||||
}
|
||||
if( send_to_fifo ) {
|
||||
stream.write(audio_int.data(), audio_int.size() * sizeof(int16_t));
|
||||
}
|
||||
|
||||
feed_audio_stats(audio);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "dsp_iir.hpp"
|
||||
#include "dsp_squelch.hpp"
|
||||
|
||||
#include "stream_input.hpp"
|
||||
#include "block_decimator.hpp"
|
||||
#include "audio_stats_collector.hpp"
|
||||
|
||||
@ -53,12 +54,14 @@ private:
|
||||
IIRBiquadFilter deemph;
|
||||
FMSquelch squelch;
|
||||
|
||||
StreamInput stream;
|
||||
|
||||
AudioStatsCollector audio_stats;
|
||||
|
||||
uint64_t audio_present_history = 0;
|
||||
|
||||
void on_block(const buffer_f32_t& audio);
|
||||
void fill_audio_buffer(const buffer_f32_t& audio);
|
||||
void fill_audio_buffer(const buffer_f32_t& audio, const bool send_to_fifo);
|
||||
void feed_audio_stats(const buffer_f32_t& audio);
|
||||
};
|
||||
|
||||
|
54
firmware/baseband/stream_input.hpp
Normal file
54
firmware/baseband/stream_input.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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 __STREAM_INPUT_H__
|
||||
#define __STREAM_INPUT_H__
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "fifo.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
class StreamInput {
|
||||
public:
|
||||
StreamInput() : fifo { std::make_unique<FIFO<uint8_t, 13>>() }
|
||||
{
|
||||
// TODO: Send stream creation message.
|
||||
shared_memory.FIFO_HACK = fifo.get();
|
||||
}
|
||||
|
||||
~StreamInput() {
|
||||
// TODO: Send stream distruction message.
|
||||
shared_memory.FIFO_HACK = nullptr;
|
||||
}
|
||||
|
||||
size_t write(const void* const data, const size_t length) {
|
||||
return fifo->in(reinterpret_cast<const uint8_t*>(data), length);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<FIFO<uint8_t, 13>> fifo;
|
||||
};
|
||||
|
||||
#endif/*__STREAM_INPUT_H__*/
|
@ -40,6 +40,7 @@ struct SharedMemory {
|
||||
uint8_t baseband_queue_data[1 << baseband_queue_k];
|
||||
MessageQueue application_queue;
|
||||
uint8_t application_queue_data[1 << application_queue_k];
|
||||
void* FIFO_HACK;
|
||||
|
||||
// TODO: M0 should directly configure and control DMA channel that is
|
||||
// acquiring ADC samples.
|
||||
|
Loading…
Reference in New Issue
Block a user