Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add software volume scaling buffers to PCM sinks

+94 -6
+16 -1
firmware/target/hosted/pcm-airplay.c
··· 25 25 #include <stdbool.h> 26 26 #include <stddef.h> 27 27 #include <stdint.h> 28 + #include <stdlib.h> 28 29 #include <string.h> 29 30 30 31 #include "pcm.h" ··· 49 50 static const void *pcm_data = NULL; 50 51 static size_t pcm_size = 0; 51 52 53 + /* Scratch buffer for SW volume scaling */ 54 + static void *airplay_vol_buf = NULL; 55 + static size_t airplay_vol_buf_cap = 0; 56 + 52 57 static pthread_mutex_t airplay_mtx; 53 58 static pthread_t airplay_tid; 54 59 static volatile bool airplay_running = false; ··· 60 65 61 66 while (!airplay_stop) { 62 67 pthread_mutex_lock(&airplay_mtx); 63 - const void *data = pcm_data; 68 + const void *raw = pcm_data; 64 69 size_t size = pcm_size; 65 70 pcm_data = NULL; 66 71 pcm_size = 0; 67 72 pthread_mutex_unlock(&airplay_mtx); 73 + 74 + /* Apply SW volume scaling */ 75 + if (size > airplay_vol_buf_cap) { 76 + free(airplay_vol_buf); 77 + airplay_vol_buf = malloc(size); 78 + airplay_vol_buf_cap = airplay_vol_buf ? size : 0; 79 + } 80 + const void *data = (airplay_vol_buf && size > 0) 81 + ? (pcm_copy_buffer(airplay_vol_buf, raw, size), airplay_vol_buf) 82 + : raw; 68 83 69 84 if (data && size > 0) { 70 85 if (pcm_airplay_write((const uint8_t *)data, size) < 0) {
+16 -1
firmware/target/hosted/pcm-chromecast.c
··· 28 28 #include <stdbool.h> 29 29 #include <stddef.h> 30 30 #include <stdint.h> 31 + #include <stdlib.h> 31 32 #include <time.h> 32 33 #include <unistd.h> 33 34 ··· 52 53 53 54 static const void *pcm_data = NULL; 54 55 static size_t pcm_size = 0; 56 + 57 + /* Scratch buffer for SW volume scaling */ 58 + static void *chromecast_vol_buf = NULL; 59 + static size_t chromecast_vol_buf_cap = 0; 55 60 56 61 static pthread_mutex_t chromecast_mtx; 57 62 static pthread_t chromecast_tid; ··· 72 77 73 78 while (!chromecast_stop) { 74 79 pthread_mutex_lock(&chromecast_mtx); 75 - const void *data = pcm_data; 80 + const void *raw = pcm_data; 76 81 size_t size = pcm_size; 77 82 pcm_data = NULL; 78 83 pcm_size = 0; 79 84 pthread_mutex_unlock(&chromecast_mtx); 85 + 86 + /* Apply SW volume scaling */ 87 + if (size > chromecast_vol_buf_cap) { 88 + free(chromecast_vol_buf); 89 + chromecast_vol_buf = malloc(size); 90 + chromecast_vol_buf_cap = chromecast_vol_buf ? size : 0; 91 + } 92 + const void *data = (chromecast_vol_buf && size > 0) 93 + ? (pcm_copy_buffer(chromecast_vol_buf, raw, size), chromecast_vol_buf) 94 + : raw; 80 95 81 96 if (data && size > 0) { 82 97 if (pcm_chromecast_write((const uint8_t *)data, size) < 0) {
+15 -1
firmware/target/hosted/pcm-fifo.c
··· 57 57 static const void *pcm_data = NULL; 58 58 static size_t pcm_size = 0; 59 59 60 + /* Scratch buffer for SW volume scaling */ 61 + static void *fifo_vol_buf = NULL; 62 + static size_t fifo_vol_buf_cap = 0; 63 + 60 64 static pthread_mutex_t fifo_mtx; 61 65 static pthread_t fifo_tid; 62 66 static volatile bool fifo_running = false; ··· 118 122 119 123 while (!fifo_stop) { 120 124 pthread_mutex_lock(&fifo_mtx); 121 - const void *data = pcm_data; 125 + const void *raw = pcm_data; 122 126 size_t size = pcm_size; 123 127 pcm_data = NULL; 124 128 pcm_size = 0; 125 129 pthread_mutex_unlock(&fifo_mtx); 130 + 131 + /* Apply SW volume scaling before writing */ 132 + if (size > fifo_vol_buf_cap) { 133 + free(fifo_vol_buf); 134 + fifo_vol_buf = malloc(size); 135 + fifo_vol_buf_cap = fifo_vol_buf ? size : 0; 136 + } 137 + const void *data = (fifo_vol_buf && size > 0) 138 + ? (pcm_copy_buffer(fifo_vol_buf, raw, size), fifo_vol_buf) 139 + : raw; 126 140 127 141 /* Write current chunk in pieces so stop() can interrupt promptly */ 128 142 while (size > 0 && !fifo_stop) {
+16 -1
firmware/target/hosted/pcm-squeezelite.c
··· 27 27 #include <stdbool.h> 28 28 #include <stddef.h> 29 29 #include <stdint.h> 30 + #include <stdlib.h> 30 31 #include <time.h> 31 32 #include <unistd.h> 32 33 ··· 49 50 50 51 static const void *pcm_data = NULL; 51 52 static size_t pcm_size = 0; 53 + 54 + /* Scratch buffer for SW volume scaling */ 55 + static void *squeezelite_vol_buf = NULL; 56 + static size_t squeezelite_vol_buf_cap = 0; 52 57 53 58 static pthread_mutex_t squeezelite_mtx; 54 59 static pthread_t squeezelite_tid; ··· 69 74 70 75 while (!squeezelite_stop) { 71 76 pthread_mutex_lock(&squeezelite_mtx); 72 - const void *data = pcm_data; 77 + const void *raw = pcm_data; 73 78 size_t size = pcm_size; 74 79 pcm_data = NULL; 75 80 pcm_size = 0; 76 81 pthread_mutex_unlock(&squeezelite_mtx); 82 + 83 + /* Apply SW volume scaling */ 84 + if (size > squeezelite_vol_buf_cap) { 85 + free(squeezelite_vol_buf); 86 + squeezelite_vol_buf = malloc(size); 87 + squeezelite_vol_buf_cap = squeezelite_vol_buf ? size : 0; 88 + } 89 + const void *data = (squeezelite_vol_buf && size > 0) 90 + ? (pcm_copy_buffer(squeezelite_vol_buf, raw, size), squeezelite_vol_buf) 91 + : raw; 77 92 78 93 if (data && size > 0) { 79 94 if (pcm_squeezelite_write((const uint8_t *)data, size) < 0) {
+15 -1
firmware/target/hosted/pcm-tcp.c
··· 65 65 static const void *pcm_data = NULL; 66 66 static size_t pcm_size = 0; 67 67 68 + /* Scratch buffer for SW volume scaling */ 69 + static void *tcp_vol_buf = NULL; 70 + static size_t tcp_vol_buf_cap = 0; 71 + 68 72 static pthread_mutex_t tcp_mtx; 69 73 static pthread_t tcp_tid; 70 74 static volatile bool tcp_running = false; ··· 125 129 126 130 while (!tcp_stop) { 127 131 pthread_mutex_lock(&tcp_mtx); 128 - const void *data = pcm_data; 132 + const void *raw = pcm_data; 129 133 size_t size = pcm_size; 130 134 pcm_data = NULL; 131 135 pcm_size = 0; 132 136 pthread_mutex_unlock(&tcp_mtx); 137 + 138 + /* Apply SW volume scaling */ 139 + if (size > tcp_vol_buf_cap) { 140 + free(tcp_vol_buf); 141 + tcp_vol_buf = malloc(size); 142 + tcp_vol_buf_cap = tcp_vol_buf ? size : 0; 143 + } 144 + const void *data = (tcp_vol_buf && size > 0) 145 + ? (pcm_copy_buffer(tcp_vol_buf, raw, size), tcp_vol_buf) 146 + : raw; 133 147 134 148 /* Write current chunk in pieces so stop() can interrupt promptly */ 135 149 while (size > 0 && !tcp_stop) {
+16 -1
firmware/target/hosted/pcm-upnp.c
··· 26 26 #include <stdbool.h> 27 27 #include <stddef.h> 28 28 #include <stdint.h> 29 + #include <stdlib.h> 29 30 #include <time.h> 30 31 #include <unistd.h> 31 32 ··· 49 50 50 51 static const void *pcm_data = NULL; 51 52 static size_t pcm_size = 0; 53 + 54 + /* Scratch buffer for SW volume scaling */ 55 + static void *upnp_vol_buf = NULL; 56 + static size_t upnp_vol_buf_cap = 0; 52 57 53 58 static pthread_mutex_t upnp_mtx; 54 59 static pthread_t upnp_tid; ··· 69 74 70 75 while (!upnp_stop) { 71 76 pthread_mutex_lock(&upnp_mtx); 72 - const void *data = pcm_data; 77 + const void *raw = pcm_data; 73 78 size_t size = pcm_size; 74 79 pcm_data = NULL; 75 80 pcm_size = 0; 76 81 pthread_mutex_unlock(&upnp_mtx); 82 + 83 + /* Apply SW volume scaling */ 84 + if (size > upnp_vol_buf_cap) { 85 + free(upnp_vol_buf); 86 + upnp_vol_buf = malloc(size); 87 + upnp_vol_buf_cap = upnp_vol_buf ? size : 0; 88 + } 89 + const void *data = (upnp_vol_buf && size > 0) 90 + ? (pcm_copy_buffer(upnp_vol_buf, raw, size), upnp_vol_buf) 91 + : raw; 77 92 78 93 if (data && size > 0) { 79 94 if (pcm_upnp_write((const uint8_t *)data, size) < 0) {