32 bits cleanup

This commit is contained in:
Philippe G
2021-03-04 20:30:06 -08:00
parent 15f1cebcdb
commit b3ff717d32
11 changed files with 120 additions and 116 deletions

View File

@@ -34,6 +34,7 @@ set_source_files_properties(flac.c
)
add_definitions(-DLINKALL -DLOOPBACK -DNO_FAAD -DRESAMPLE16 -DEMBEDDED -DTREMOR_ONLY -DBYTES_PER_FRAME=4)
# add_definitions(-DLINKALL -DLOOPBACK -DNO_FAAD -DEMBEDDED -DTREMOR_ONLY -DBYTES_PER_FRAME=8)
add_compile_options (-O3 )

View File

@@ -853,8 +853,8 @@ static void visu_update(void) {
int mode = visu.mode & ~VISU_ESP32;
// not enough samples
if (visu_export.level < (mode == VISU_VUMETER ? RMS_LEN : FFT_LEN) * 2 && visu_export.running) {
// not enough frames
if (visu_export.level < (mode == VISU_VUMETER ? RMS_LEN : FFT_LEN) && visu_export.running) {
pthread_mutex_unlock(&visu_export.mutex);
return;
}
@@ -865,14 +865,14 @@ static void visu_update(void) {
if (visu_export.running) {
if (mode == VISU_VUMETER) {
s16_t *iptr = visu_export.buffer;
s16_t *iptr = (s16_t*) visu_export.buffer + (BYTES_PER_FRAME / 4) - 1;
// calculate sum(L²+R²), try to not overflow at the expense of some precision
for (int i = RMS_LEN; --i >= 0;) {
visu.bars[0].current += (*iptr * *iptr + (1 << (RMS_LEN_BIT - 2))) >> (RMS_LEN_BIT - 1);
iptr++;
iptr += BYTES_PER_FRAME / 4;
visu.bars[1].current += (*iptr * *iptr + (1 << (RMS_LEN_BIT - 2))) >> (RMS_LEN_BIT - 1);
iptr++;
iptr += BYTES_PER_FRAME / 4;
}
// convert to dB (1 bit remaining for getting X²/N, 60dB dynamic starting from 0dBFS = 3 bits back-off)
@@ -882,11 +882,13 @@ static void visu_update(void) {
else if (visu.bars[i].current < 0) visu.bars[i].current = 0;
}
} else {
s16_t *iptr = (s16_t*) visu_export.buffer + (BYTES_PER_FRAME / 4) - 1;
// on xtensa/esp32 the floating point FFT takes 1/2 cycles of the fixed point
for (int i = 0 ; i < FFT_LEN ; i++) {
// don't normalize here, but we are due INT16_MAX and FFT_LEN / 2 / 2
visu.samples[i * 2 + 0] = (float) (visu_export.buffer[2*i] + visu_export.buffer[2*i + 1]) * visu.hanning[i];
visu.samples[i * 2 + 0] = (float) (*iptr + *(iptr+BYTES_PER_FRAME/4)) * visu.hanning[i];
visu.samples[i * 2 + 1] = 0;
iptr += 2 * BYTES_PER_FRAME / 4;
}
// actual FFT that might be less cycle than all the crap below

View File

@@ -22,7 +22,7 @@ typedef int16_t s16_t;
typedef int32_t s32_t;
typedef int64_t s64_t;
typedef unsigned long long u64_t;
#ifndef PTHREAD_STACK_MIN
#define PTHREAD_STACK_MIN 256
#endif
@@ -42,7 +42,12 @@ typedef unsigned long long u64_t;
#define PLAYER_ID custom_player_id
extern u8_t custom_player_id;
#define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Firmware=" VERSION
#if BYTES_PER_FRAME == 8
#define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Depth=32,Firmware=" VERSION
#else
#define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Depth=16,Firmware=" VERSION
#endif
// to force some special buffer attribute
#define EXT_BSS __attribute__((section(".ext_ram.bss")))
@@ -78,10 +83,10 @@ u8_t get_battery(void); // must provide 0..15 or define as 0x0
extern struct visu_export_s {
pthread_mutex_t mutex;
u32_t level, size, rate, gain;
s16_t *buffer;
void *buffer;
bool running;
} visu_export;
void output_visu_export(s16_t *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain);
void output_visu_export(void *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain);
void output_visu_init(log_level level);
void output_visu_close(void);

View File

@@ -112,7 +112,7 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g
memcpy(btout + oframes * BYTES_PER_FRAME, buf, out_frames * BYTES_PER_FRAME);
}
output_visu_export((s16_t*) (btout + oframes * BYTES_PER_FRAME), out_frames, output.current_sample_rate, silence, (gainL + gainR) / 2);
output_visu_export(btout + oframes * BYTES_PER_FRAME, out_frames, output.current_sample_rate, silence, ((gainL & ~MONO_FLAG) + (gainR & ~MONO_FLAG)) / 2);
oframes += out_frames;

View File

@@ -400,42 +400,18 @@ bool output_volume_i2s(unsigned left, unsigned right) {
*/
static int _i2s_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr) {
#if BYTES_PER_FRAME == 8
s32_t *optr;
#endif
if (!silence) {
if (output.fade == FADE_ACTIVE && output.fade_dir == FADE_CROSS && *cross_ptr) {
_apply_cross(outputbuf, out_frames, cross_gain_in, cross_gain_out, cross_ptr);
}
#if BYTES_PER_FRAME == 4
_apply_gain(outputbuf, out_frames, gainL, gainR);
memcpy(obuf + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME);
#else
optr = (s32_t*) outputbuf->readp;
#endif
} else {
#if BYTES_PER_FRAME == 4
memcpy(obuf + oframes * BYTES_PER_FRAME, silencebuf, out_frames * BYTES_PER_FRAME);
#else
optr = (s32_t*) silencebuf;
#endif
}
#if BYTES_PER_FRAME == 8
IF_DSD(
if (output.outfmt == DOP) {
update_dop((u32_t *) optr, out_frames, output.invert);
} else if (output.outfmt != PCM && output.invert)
dsd_invert((u32_t *) optr, out_frames);
)
_scale_and_pack_frames(obuf + oframes * BYTES_PER_FRAME, optr, out_frames, gainL, gainR, output.format);
#endif
output_visu_export((s16_t*) (obuf + oframes * BYTES_PER_FRAME), out_frames, output.current_sample_rate, silence, (gainL + gainR) / 2);
output_visu_export(obuf + oframes * BYTES_PER_FRAME, out_frames, output.current_sample_rate, silence, ((gainL & ~MONO_FLAG) + (gainR & ~MONO_FLAG)) / 2);
oframes += out_frames;
return out_frames;
@@ -556,8 +532,10 @@ static void *output_thread_i2s(void *arg) {
//return;
}
#if BYTES_PER_FRAME == 4
// run equalizer
equalizer_process(obuf, oframes * BYTES_PER_FRAME, output.current_sample_rate);
#endif
// we assume that here we have been able to entirely fill the DMA buffers
if (spdif) {

View File

@@ -23,14 +23,8 @@
#include "squeezelite.h"
#if BYTES_PER_FRAM == 4
#define MAX_VAL16 0x7fffffffLL
#define MAX_SCALESAMPLE 0x7fffffffffffLL
#define MIN_SCALESAMPLE -MAX_SCALESAMPLE
#else
#define MAX_SCALESAMPLE 0x7fffffffffffLL
#define MIN_SCALESAMPLE -MAX_SCALESAMPLE
#endif
// inlining these on windows prevents them being linkable...
#if !WIN

View File

@@ -29,7 +29,7 @@ static struct visu_export_s *visu = &visu_export;
static log_level loglevel = lINFO;
void output_visu_export(s16_t *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain) {
void output_visu_export(void *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain) {
// no data to process
if (silence) {
@@ -44,10 +44,10 @@ void output_visu_export(s16_t *frames, frames_t out_frames, u32_t rate, bool sil
// stuff buffer up and wait for consumer to read it (should reset level)
if (visu->level < visu->size) {
u32_t space = min(visu->size - visu->level, out_frames * 2) * 2;
u32_t space = min(visu->size - visu->level, out_frames) * BYTES_PER_FRAME;
memcpy(visu->buffer + visu->level, frames, space);
visu->level += space / 2;
visu->level += space / BYTES_PER_FRAME;
visu->running = true;
visu->rate = rate ? rate : 44100;
visu->gain = gain;
@@ -71,7 +71,7 @@ void output_visu_init(log_level level) {
visu->size = VISUEXPORT_SIZE;
visu->running = false;
visu->rate = 44100;
visu->buffer = malloc(VISUEXPORT_SIZE * sizeof(s16_t) * 2);
LOG_INFO("Initialize VISUEXPORT %u 16 bits samples", VISUEXPORT_SIZE);
visu->buffer = malloc(VISUEXPORT_SIZE * BYTES_PER_FRAME);
LOG_INFO("Initialize VISUEXPORT %u %u bits samples", VISUEXPORT_SIZE, BYTES_PER_FRAME * 4);
}