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 -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 ) add_compile_options (-O3 )

View File

@@ -853,8 +853,8 @@ static void visu_update(void) {
int mode = visu.mode & ~VISU_ESP32; int mode = visu.mode & ~VISU_ESP32;
// not enough samples // not enough frames
if (visu_export.level < (mode == VISU_VUMETER ? RMS_LEN : FFT_LEN) * 2 && visu_export.running) { if (visu_export.level < (mode == VISU_VUMETER ? RMS_LEN : FFT_LEN) && visu_export.running) {
pthread_mutex_unlock(&visu_export.mutex); pthread_mutex_unlock(&visu_export.mutex);
return; return;
} }
@@ -865,14 +865,14 @@ static void visu_update(void) {
if (visu_export.running) { if (visu_export.running) {
if (mode == VISU_VUMETER) { 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 // calculate sum(L²+R²), try to not overflow at the expense of some precision
for (int i = RMS_LEN; --i >= 0;) { for (int i = RMS_LEN; --i >= 0;) {
visu.bars[0].current += (*iptr * *iptr + (1 << (RMS_LEN_BIT - 2))) >> (RMS_LEN_BIT - 1); 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); 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) // 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 if (visu.bars[i].current < 0) visu.bars[i].current = 0;
} }
} else { } 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 // on xtensa/esp32 the floating point FFT takes 1/2 cycles of the fixed point
for (int i = 0 ; i < FFT_LEN ; i++) { for (int i = 0 ; i < FFT_LEN ; i++) {
// don't normalize here, but we are due INT16_MAX and FFT_LEN / 2 / 2 // 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; visu.samples[i * 2 + 1] = 0;
iptr += 2 * BYTES_PER_FRAME / 4;
} }
// actual FFT that might be less cycle than all the crap below // actual FFT that might be less cycle than all the crap below

View File

@@ -42,7 +42,12 @@ typedef unsigned long long u64_t;
#define PLAYER_ID custom_player_id #define PLAYER_ID custom_player_id
extern u8_t 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 // to force some special buffer attribute
#define EXT_BSS __attribute__((section(".ext_ram.bss"))) #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 { extern struct visu_export_s {
pthread_mutex_t mutex; pthread_mutex_t mutex;
u32_t level, size, rate, gain; u32_t level, size, rate, gain;
s16_t *buffer; void *buffer;
bool running; bool running;
} visu_export; } 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_init(log_level level);
void output_visu_close(void); 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); 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; 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, 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) { 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 (!silence) {
if (output.fade == FADE_ACTIVE && output.fade_dir == FADE_CROSS && *cross_ptr) { 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); _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); _apply_gain(outputbuf, out_frames, gainL, gainR);
memcpy(obuf + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME); memcpy(obuf + oframes * BYTES_PER_FRAME, outputbuf->readp, out_frames * BYTES_PER_FRAME);
#else
optr = (s32_t*) outputbuf->readp;
#endif
} else { } else {
#if BYTES_PER_FRAME == 4
memcpy(obuf + oframes * BYTES_PER_FRAME, silencebuf, out_frames * BYTES_PER_FRAME); memcpy(obuf + oframes * BYTES_PER_FRAME, silencebuf, out_frames * BYTES_PER_FRAME);
#else
optr = (s32_t*) silencebuf;
#endif
} }
#if BYTES_PER_FRAME == 8 output_visu_export(obuf + oframes * BYTES_PER_FRAME, out_frames, output.current_sample_rate, silence, ((gainL & ~MONO_FLAG) + (gainR & ~MONO_FLAG)) / 2);
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);
oframes += out_frames; oframes += out_frames;
return out_frames; return out_frames;
@@ -556,8 +532,10 @@ static void *output_thread_i2s(void *arg) {
//return; //return;
} }
#if BYTES_PER_FRAME == 4
// run equalizer // run equalizer
equalizer_process(obuf, oframes * BYTES_PER_FRAME, output.current_sample_rate); 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 // we assume that here we have been able to entirely fill the DMA buffers
if (spdif) { if (spdif) {

View File

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

View File

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

View File

@@ -38,6 +38,7 @@
<hr> <hr>
[% END %] [% END %]
[% IF pref_equalizer %]
[% WRAPPER setting title="PLUGIN_SQUEEZEESP32_EQUALIZER" desc="" %] [% WRAPPER setting title="PLUGIN_SQUEEZEESP32_EQUALIZER" desc="" %]
<div>[% "PLUGIN_SQUEEZEESP32_EQUALIZER_SAVE" | string %]</div> <div>[% "PLUGIN_SQUEEZEESP32_EQUALIZER_SAVE" | string %]</div>
[% END %] [% END %]
@@ -100,5 +101,6 @@
<input type="text" class="stdedit sliderInput_-13_20" name="pref_equalizer.9" id="pref_equalizer.9" value="[% pref_equalizer.9 %]" size="2"> <input type="text" class="stdedit sliderInput_-13_20" name="pref_equalizer.9" id="pref_equalizer.9" value="[% pref_equalizer.9 %]" size="2">
[% END %] [% END %]
[% END %] [% END %]
[% END %]
[% PROCESS settings/footer.html %] [% PROCESS settings/footer.html %]

View File

@@ -14,7 +14,7 @@ my $prefs = preferences('plugin.squeezeesp32');
my $log = logger('plugin.squeezeesp32'); my $log = logger('plugin.squeezeesp32');
{ {
__PACKAGE__->mk_accessor('rw', 'tone_update'); __PACKAGE__->mk_accessor('rw', qw(tone_update depth));
} }
sub new { sub new {
@@ -64,6 +64,10 @@ sub minBass { -13 }
sub init { sub init {
my $client = shift; my $client = shift;
my ($id, $caps) = @_;
my ($depth) = $caps =~ /Depth=(\d+)/;
$client->depth($depth || 16);
if (!$handlersAdded) { if (!$handlersAdded) {
@@ -107,6 +111,22 @@ sub initPrefs {
$client->SUPER::initPrefs; $client->SUPER::initPrefs;
} }
sub power {
my $client = shift;
my $on = shift;
my $res = $client->SUPER::power($on, @_);
return $res unless defined $on;
if ($on) {
$client->update_artwork(1);
} else {
$client->clear_artwork(1);
}
return $res;
}
# Allow the player to define it's display width (and probably more) # Allow the player to define it's display width (and probably more)
sub playerSettingsFrame { sub playerSettingsFrame {
my $client = shift; my $client = shift;
@@ -232,16 +252,16 @@ sub send_artwork {
} }
sub clear_artwork { sub clear_artwork {
my ($client, $request) = @_; my ($client, $force, $from) = @_;
my $artwork = $prefs->client($client)->get('artwork'); my $artwork = $prefs->client($client)->get('artwork');
if ($artwork && $artwork->{'enable'}) { if ($artwork && $artwork->{'enable'}) {
main::INFOLOG && $log->is_info && $log->info("artwork stop/clear " . $request->getRequestString()); main::INFOLOG && $log->is_info && $log->info("artwork stop/clear " . ($from || ""));
$client->pluginData('artwork_md5', ''); $client->pluginData('artwork_md5', '');
# refresh screen and disable artwork when artwork was full screen (hack) # refresh screen and disable artwork when artwork was full screen (hack)
if (!$artwork->{'x'} && !$artwork->{'y'}) { if ((!$artwork->{'x'} && !$artwork->{'y'}) || $force) {
$client->sendFrame(grfa => \("\x00"x4)) unless $artwork->{'x'} || $artwork->{'y'}; $client->sendFrame(grfa => \("\x00"x4));
$client->display->update; $client->display->update;
} }
} }

View File

@@ -76,6 +76,7 @@ sub handler {
} }
if ($client->depth == 16) {
my $equalizer = $cprefs->get('equalizer'); my $equalizer = $cprefs->get('equalizer');
for my $i (0 .. $#{$equalizer}) { for my $i (0 .. $#{$equalizer}) {
$equalizer->[$i] = $paramRef->{"pref_equalizer.$i"} || 0; $equalizer->[$i] = $paramRef->{"pref_equalizer.$i"} || 0;
@@ -83,6 +84,7 @@ sub handler {
$cprefs->set('equalizer', $equalizer); $cprefs->set('equalizer', $equalizer);
$client->update_tones($equalizer); $client->update_tones($equalizer);
} }
}
if ($client->displayWidth) { if ($client->displayWidth) {
# the Settings super class can't handle anything but scalar values # the Settings super class can't handle anything but scalar values
@@ -91,7 +93,7 @@ sub handler {
$paramRef->{'pref_artwork'} = $cprefs->get('artwork'); $paramRef->{'pref_artwork'} = $cprefs->get('artwork');
} }
$paramRef->{'pref_equalizer'} = $cprefs->get('equalizer'); $paramRef->{'pref_equalizer'} = $cprefs->get('equalizer') if $client->depth == 16;
return $class->SUPER::handler($client, $paramRef); return $class->SUPER::handler($client, $paramRef);
} }

View File

@@ -65,7 +65,7 @@ sub onStopClear {
my $client = $request->client || return; my $client = $request->client || return;
if ($client->isa('Plugins::SqueezeESP32::Player')) { if ($client->isa('Plugins::SqueezeESP32::Player')) {
$client->clear_artwork($request); $client->clear_artwork(0, $request->getRequestString());
} }
} }