mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 15:27:40 +00:00
@@ -20,3 +20,4 @@
|
||||
*/
|
||||
|
||||
#include "dsp_fft.hpp"
|
||||
#include "complex.hpp"
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "complex.hpp"
|
||||
#include "hal.h"
|
||||
#include "utility.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
|
||||
namespace std {
|
||||
/* https://github.com/AE9RB/fftbench/blob/master/cxlr.hpp
|
||||
@@ -135,4 +136,45 @@ void fft_c_preswapped(std::array<T, N>& data, const size_t from, const size_t to
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ifft(v,N):
|
||||
[0] If N==1 then return.
|
||||
[1] For k = 0 to N/2-1, let ve[k] = v[2*k]
|
||||
[2] Compute ifft(ve, N/2);
|
||||
[3] For k = 0 to N/2-1, let vo[k] = v[2*k+1]
|
||||
[4] Compute ifft(vo, N/2);
|
||||
[5] For m = 0 to N/2-1, do [6] through [9]
|
||||
[6] Let w.real() = cos(2*PI*m/N)
|
||||
[7] Let w.imag() = sin(2*PI*m/N)
|
||||
[8] Let v[m] = ve[m] + w*vo[m]
|
||||
[9] Let v[m+N/2] = ve[m] - w*vo[m]
|
||||
*/
|
||||
template<typename T>
|
||||
void ifft( T *v, int n, T *tmp )
|
||||
{
|
||||
if(n>1) {
|
||||
int k,m;
|
||||
T z, w, *vo, *ve;
|
||||
ve = tmp; vo = tmp+n/2;
|
||||
for(k=0; k<n/2; k++) {
|
||||
ve[k] = v[2*k];
|
||||
vo[k] = v[2*k+1];
|
||||
}
|
||||
ifft( ve, n/2, v ); /* FFT on even-indexed elements of v[] */
|
||||
ifft( vo, n/2, v ); /* FFT on odd-indexed elements of v[] */
|
||||
for(m=0; m<n/2; m++) {
|
||||
w.real(sine_table_i8[((int)(m/(double)n * 0x100 + 0x40)) & 0xFF]);
|
||||
w.imag(sine_table_i8[((int)(m/(double)n * 0x100)) & 0xFF]);
|
||||
|
||||
z.real((w.real()*vo[m].real() - w.imag()*vo[m].imag())/127); /* Re(w*vo[m]) */
|
||||
z.imag((w.real()*vo[m].imag() + w.imag()*vo[m].real())/127); /* Im(w*vo[m]) */
|
||||
v[ m ].real(ve[m].real() + z.real());
|
||||
v[ m ].imag(ve[m].imag() + z.imag());
|
||||
v[m+n/2].real(ve[m].real() - z.real());
|
||||
v[m+n/2].imag(ve[m].imag() - z.imag());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#endif/*__DSP_FFT_H__*/
|
||||
|
@@ -489,8 +489,8 @@ bool ILI9341::drawBMP2(const ui::Point p, const std::string file) {
|
||||
if(pointer + 4 > 256)
|
||||
break;
|
||||
switch(type) {
|
||||
case 0:
|
||||
case 3:
|
||||
case 0: // R5G6B5
|
||||
case 3: // A1R5G5B5
|
||||
if(!type)
|
||||
line_buffer[px] = ui::Color((uint16_t)buffer[pointer] | ((uint16_t)buffer[pointer + 1] << 8));
|
||||
else
|
||||
@@ -498,13 +498,13 @@ bool ILI9341::drawBMP2(const ui::Point p, const std::string file) {
|
||||
pointer += 2;
|
||||
file_pos += 2;
|
||||
break;
|
||||
case 1:
|
||||
case 1: // 24
|
||||
default:
|
||||
line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]);
|
||||
pointer += 3;
|
||||
file_pos += 3;
|
||||
break;
|
||||
case 2:
|
||||
case 2: // 32
|
||||
line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]);
|
||||
pointer += 4;
|
||||
file_pos += 4;
|
||||
|
@@ -109,6 +109,8 @@ public:
|
||||
AudioSpectrum = 52,
|
||||
APRSPacket = 53,
|
||||
APRSRxConfigure = 54,
|
||||
SpectrumPainterBufferRequestConfigure = 55,
|
||||
SpectrumPainterBufferResponseConfigure = 56,
|
||||
MAX
|
||||
};
|
||||
|
||||
@@ -1143,4 +1145,40 @@ public:
|
||||
uint32_t return_code;
|
||||
};
|
||||
|
||||
class SpectrumPainterBufferConfigureRequestMessage : public Message {
|
||||
public:
|
||||
constexpr SpectrumPainterBufferConfigureRequestMessage(
|
||||
uint16_t width,
|
||||
uint16_t height,
|
||||
bool update,
|
||||
int32_t bw
|
||||
) : Message { ID::SpectrumPainterBufferRequestConfigure },
|
||||
width { width },
|
||||
height { height },
|
||||
update { update },
|
||||
bw { bw }
|
||||
{
|
||||
}
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
bool update;
|
||||
int32_t bw;
|
||||
};
|
||||
|
||||
using SpectrumPainterFIFO = FIFO<std::vector<uint8_t>>;
|
||||
class SpectrumPainterBufferConfigureResponseMessage : public Message {
|
||||
public:
|
||||
static constexpr size_t fifo_k = 2;
|
||||
|
||||
constexpr SpectrumPainterBufferConfigureResponseMessage(
|
||||
SpectrumPainterFIFO* fifo
|
||||
) : Message { ID::SpectrumPainterBufferResponseConfigure },
|
||||
fifo { fifo }
|
||||
{
|
||||
}
|
||||
|
||||
SpectrumPainterFIFO* fifo { nullptr };
|
||||
};
|
||||
|
||||
#endif/*__MESSAGE_H__*/
|
||||
|
@@ -68,7 +68,7 @@ struct SharedMemory {
|
||||
uint8_t volatile request_m4_performance_counter{ 0 };
|
||||
uint8_t volatile m4_cpu_usage{ 0 };
|
||||
uint16_t volatile m4_stack_usage{ 0 };
|
||||
uint16_t volatile m4_heap_usage{ 0 };
|
||||
uint32_t volatile m4_heap_usage{ 0 };
|
||||
uint16_t volatile m4_buffer_missed{ 0 };
|
||||
};
|
||||
|
||||
|
86
firmware/common/random.cpp
Normal file
86
firmware/common/random.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* 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 "random.hpp"
|
||||
|
||||
static unsigned long state[N]; /* the array for the state vector */
|
||||
static int rnd_left = 1;
|
||||
static int rnd_init = 0;
|
||||
static unsigned long *rnd_next;
|
||||
|
||||
/* initializes state[N] with a seed */
|
||||
void init_genrand(unsigned long s)
|
||||
{
|
||||
int j;
|
||||
state[0] = s & 0xffffffffUL;
|
||||
|
||||
for (j = 1; j < N; j++)
|
||||
{
|
||||
state[j] = (1812433253UL * (state[j - 1] ^ (state[j - 1] >> 30)) + j);
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array state[]. */
|
||||
/* 2002/01/09 modified by Makoto Matsumoto */
|
||||
state[j] &= 0xffffffffUL; /* for >32 bit machines */
|
||||
}
|
||||
|
||||
rnd_left = 1;
|
||||
rnd_init = 1;
|
||||
}
|
||||
|
||||
static void next_state(void)
|
||||
{
|
||||
unsigned long *p = state;
|
||||
int j;
|
||||
|
||||
/* if init_genrand() has not been called, */
|
||||
/* a default initial seed is used */
|
||||
if (rnd_init == 0)
|
||||
init_genrand(5489UL);
|
||||
|
||||
rnd_left = N;
|
||||
rnd_next = state;
|
||||
|
||||
for (j = N - M + 1; --j; p++)
|
||||
*p = p[M] ^ TWIST(p[0], p[1]);
|
||||
|
||||
for (j = M; --j; p++)
|
||||
*p = p[M - N] ^ TWIST(p[0], p[1]);
|
||||
|
||||
*p = p[M - N] ^ TWIST(p[0], state[0]);
|
||||
}
|
||||
|
||||
long genrand_int31(void)
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if (--rnd_left == 0)
|
||||
next_state();
|
||||
y = *rnd_next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return (long)(y >> 1);
|
||||
}
|
35
firmware/common/random.hpp
Normal file
35
firmware/common/random.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
||||
#define UMASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LMASK 0x7fffffffUL /* least significant r bits */
|
||||
#define MIXBITS(u, v) (((u)&UMASK) | ((v)&LMASK))
|
||||
#define TWIST(u, v) ((MIXBITS(u, v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
|
||||
|
||||
/* initializes state[N] with a seed */
|
||||
extern void init_genrand(unsigned long s);
|
||||
extern long genrand_int31(void);
|
@@ -104,6 +104,7 @@ constexpr image_tag_t image_tag_rds { 'P', 'R', 'D', 'S' };
|
||||
constexpr image_tag_t image_tag_replay { 'P', 'R', 'E', 'P' };
|
||||
constexpr image_tag_t image_tag_gps { 'P', 'G', 'P', 'S' };
|
||||
constexpr image_tag_t image_tag_siggen { 'P', 'S', 'I', 'G' };
|
||||
constexpr image_tag_t image_tag_spectrum_painter { 'P', 'S', 'P', 'T' };
|
||||
constexpr image_tag_t image_tag_sstv_tx { 'P', 'S', 'T', 'X' };
|
||||
constexpr image_tag_t image_tag_tones { 'P', 'T', 'O', 'N' };
|
||||
constexpr image_tag_t image_tag_flash_utility { 'P', 'F', 'U', 'T' };
|
||||
|
@@ -57,6 +57,16 @@ struct Color {
|
||||
)}
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t to_greyscale() {
|
||||
uint32_t r = ((v >> 11) & 31U) << 3;
|
||||
uint32_t g = ((v >> 5) & 63U) << 2;
|
||||
uint32_t b = (v & 31U) << 3;
|
||||
|
||||
uint32_t grey = (r * 299 + g * 587 + b * 114) / 1000;
|
||||
|
||||
return (uint8_t)grey;
|
||||
}
|
||||
|
||||
Color operator-() const {
|
||||
return (v ^ 0xffff);
|
||||
|
Reference in New Issue
Block a user