mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 13:37:03 +03:00
opus & vorbis fix when using resampling
This commit is contained in:
@@ -5,11 +5,11 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* NOTE for drivers:
|
/* NOTE for drivers:
|
||||||
The build-in DrawPixel(Fast), DrawCBR and ClearWindow are optimized for 1 bit
|
The build-in DrawPixel(Fast), DrawCBR and ClearWindow have optimized for 1 bit
|
||||||
and 4 bits screen depth. For any other type of screen, DrawCBR and ClearWindow
|
and 4 bits grayscale screen depth and 8, 16, 24 color. For any other type of screen,
|
||||||
default to use DrawPixel, which is very sub-optimal. For such other depth, you
|
DrawCBR and ClearWindow default to use DrawPixel, which is very sub-optimal. For
|
||||||
must supply the DrawPixelFast. The built-in 1 bit depth function are only for
|
other depth, you must supply the DrawPixelFast. The built-in 1 bit depth function
|
||||||
screen with vertical framing (1 byte = 8 lines). For example SSD1326 in
|
are only for screen with vertical framing (1 byte = 8 lines). For example SSD1326 in
|
||||||
monochrome mode is not such type of screen, SH1106 and SSD1306 are
|
monochrome mode is not such type of screen, SH1106 and SSD1306 are
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,9 @@
|
|||||||
* thread has a higher priority. Using an interim buffer where opus decoder writes the output is not great from
|
* thread has a higher priority. Using an interim buffer where opus decoder writes the output is not great from
|
||||||
* an efficiency (one extra memory copy) point of view, but it allows the lock to not be kept for too long
|
* an efficiency (one extra memory copy) point of view, but it allows the lock to not be kept for too long
|
||||||
*/
|
*/
|
||||||
|
#if EMBEDDED
|
||||||
#define FRAME_BUF 2048
|
#define FRAME_BUF 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BYTES_PER_FRAME == 4
|
#if BYTES_PER_FRAME == 4
|
||||||
#define ALIGN(n) (n)
|
#define ALIGN(n) (n)
|
||||||
@@ -151,16 +153,14 @@ static decode_state opus_decompress(void) {
|
|||||||
LOG_INFO("setting track_start");
|
LOG_INFO("setting track_start");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !FRAME_BUF
|
|
||||||
LOCK_O_direct;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FRAME_BUF
|
#if FRAME_BUF
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
|
frames = min(frames, FRAME_BUF);
|
||||||
write_buf = u->write_buf;
|
write_buf = u->write_buf;
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
|
LOCK_O_direct;
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
write_buf = outputbuf->writep;
|
write_buf = outputbuf->writep;
|
||||||
@@ -171,10 +171,6 @@ static decode_state opus_decompress(void) {
|
|||||||
write_buf = process.inbuf;
|
write_buf = process.inbuf;
|
||||||
);
|
);
|
||||||
|
|
||||||
#if FRAME_BUF
|
|
||||||
frames = min(frames, FRAME_BUF);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// write the decoded frames into outputbuf then unpack them (they are 16 bits)
|
// write the decoded frames into outputbuf then unpack them (they are 16 bits)
|
||||||
n = OP(u, read, u->of, (opus_int16*) write_buf, frames * channels, NULL);
|
n = OP(u, read, u->of, (opus_int16*) write_buf, frames * channels, NULL);
|
||||||
|
|
||||||
@@ -190,15 +186,21 @@ static decode_state opus_decompress(void) {
|
|||||||
frames = n;
|
frames = n;
|
||||||
count = frames * channels;
|
count = frames * channels;
|
||||||
|
|
||||||
iptr = (s16_t *)write_buf + count;
|
// work backward to unpack samples (if needed)
|
||||||
optr = (ISAMPLE_T *) outputbuf->writep + frames * 2;
|
iptr = (s16_t *) write_buf + count;
|
||||||
|
optr = (ISAMPLE_T *) write_buf + frames * 2;
|
||||||
|
|
||||||
if (channels == 2) {
|
if (channels == 2) {
|
||||||
#if BYTES_PER_FRAME == 4
|
#if BYTES_PER_FRAME == 4
|
||||||
|
#if FRAME_BUF
|
||||||
|
// copy needed only when DIRECT and FRAME_BUF
|
||||||
|
IF_DIRECT(
|
||||||
memcpy(outputbuf->writep, write_buf, frames * BYTES_PER_FRAME);
|
memcpy(outputbuf->writep, write_buf, frames * BYTES_PER_FRAME);
|
||||||
|
)
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*--optr = *--iptr << 16;
|
*--optr = ALIGN(*--iptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (channels == 1) {
|
} else if (channels == 1) {
|
||||||
@@ -298,8 +300,8 @@ struct codec *register_opus(void) {
|
|||||||
static struct codec ret = {
|
static struct codec ret = {
|
||||||
'u', // id
|
'u', // id
|
||||||
"ops", // types
|
"ops", // types
|
||||||
4096, // min read
|
4*1024, // min read
|
||||||
20480, // min space
|
32*1024, // min space
|
||||||
opus_open, // open
|
opus_open, // open
|
||||||
opus_close, // close
|
opus_close, // close
|
||||||
opus_decompress, // decode
|
opus_decompress, // decode
|
||||||
@@ -311,7 +313,9 @@ struct codec *register_opus(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u->of = NULL;
|
u->of = NULL;
|
||||||
|
#if FRAME_BUF
|
||||||
u->write_buf = NULL;
|
u->write_buf = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!load_opus()) {
|
if (!load_opus()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -387,9 +387,6 @@ typedef BOOL bool;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef u32_t frames_t;
|
|
||||||
typedef int sockfd;
|
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
typedef enum { lERROR = 0, lWARN, lINFO, lDEBUG, lSDEBUG } log_level;
|
typedef enum { lERROR = 0, lWARN, lINFO, lDEBUG, lSDEBUG } log_level;
|
||||||
|
|
||||||
@@ -402,6 +399,9 @@ void logprint(const char *fmt, ...);
|
|||||||
#define LOG_DEBUG(fmt, ...) if (loglevel >= lDEBUG) logprint("%s %s:%d " fmt "\n", logtime(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
#define LOG_DEBUG(fmt, ...) if (loglevel >= lDEBUG) logprint("%s %s:%d " fmt "\n", logtime(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||||
#define LOG_SDEBUG(fmt, ...) if (loglevel >= lSDEBUG) logprint("%s %s:%d " fmt "\n", logtime(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
#define LOG_SDEBUG(fmt, ...) if (loglevel >= lSDEBUG) logprint("%s %s:%d " fmt "\n", logtime(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
typedef uint32_t frames_t;
|
||||||
|
typedef int sockfd;
|
||||||
|
|
||||||
#if EMBEDDED
|
#if EMBEDDED
|
||||||
#include "embedded.h"
|
#include "embedded.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -29,7 +29,9 @@
|
|||||||
* thread has a higher priority. Using an interim buffer where vorbis decoder writes the output is not great from
|
* thread has a higher priority. Using an interim buffer where vorbis decoder writes the output is not great from
|
||||||
* an efficiency (one extra memory copy) point of view, but it allows the lock to not be kept for too long
|
* an efficiency (one extra memory copy) point of view, but it allows the lock to not be kept for too long
|
||||||
*/
|
*/
|
||||||
|
#if EMBEDDED
|
||||||
#define FRAME_BUF 2048
|
#define FRAME_BUF 2048
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BYTES_PER_FRAME == 4
|
#if BYTES_PER_FRAME == 4
|
||||||
#define ALIGN(n) (n)
|
#define ALIGN(n) (n)
|
||||||
@@ -183,16 +185,14 @@ static decode_state vorbis_decode(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !FRAME_BUF
|
|
||||||
LOCK_O_direct;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FRAME_BUF
|
#if FRAME_BUF
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
|
frames = min(frames, FRAME_BUF);
|
||||||
write_buf = v->write_buf;
|
write_buf = v->write_buf;
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
|
LOCK_O_direct;
|
||||||
IF_DIRECT(
|
IF_DIRECT(
|
||||||
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
frames = min(_buf_space(outputbuf), _buf_cont_write(outputbuf)) / BYTES_PER_FRAME;
|
||||||
write_buf = outputbuf->writep;
|
write_buf = outputbuf->writep;
|
||||||
@@ -203,9 +203,6 @@ static decode_state vorbis_decode(void) {
|
|||||||
write_buf = process.inbuf;
|
write_buf = process.inbuf;
|
||||||
);
|
);
|
||||||
|
|
||||||
#if FRAME_BUF
|
|
||||||
frames = min(frames, FRAME_BUF);
|
|
||||||
#endif
|
|
||||||
bytes = frames * 2 * channels; // samples returned are 16 bits
|
bytes = frames * 2 * channels; // samples returned are 16 bits
|
||||||
|
|
||||||
// write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them
|
// write the decoded frames into outputbuf even though they are 16 bits per sample, then unpack them
|
||||||
@@ -237,15 +234,21 @@ static decode_state vorbis_decode(void) {
|
|||||||
frames = n / 2 / channels;
|
frames = n / 2 / channels;
|
||||||
count = frames * channels;
|
count = frames * channels;
|
||||||
|
|
||||||
iptr = (s16_t *)write_buf + count;
|
// work backward to unpack samples (if needed)
|
||||||
optr = (ISAMPLE_T *) outputbuf->writep + frames * 2;
|
iptr = (s16_t *) write_buf + count;
|
||||||
|
optr = (ISAMPLE_T *) write_buf + frames * 2;
|
||||||
|
|
||||||
if (channels == 2) {
|
if (channels == 2) {
|
||||||
#if BYTES_PER_FRAME == 4
|
#if BYTES_PER_FRAME == 4
|
||||||
|
#if FRAME_BUF
|
||||||
|
// copy needed only when DIRECT and FRAME_BUF
|
||||||
|
IF_DIRECT(
|
||||||
memcpy(outputbuf->writep, write_buf, frames * BYTES_PER_FRAME);
|
memcpy(outputbuf->writep, write_buf, frames * BYTES_PER_FRAME);
|
||||||
|
)
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*--optr = *--iptr << 16;
|
*--optr = ALIGN(*--iptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (channels == 1) {
|
} else if (channels == 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user