Semi-naive audio recording to SD card.

This commit is contained in:
Jared Boone
2016-02-09 17:49:17 -08:00
parent c01f2d82e1
commit 59f1a32566
10 changed files with 227 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);
};

View 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__*/