feat:adjust gain in speaker volume. add led and auto-disconnect toggle in mute.

This commit is contained in:
awalol
2026-03-22 00:33:30 +08:00
parent 49eba414cb
commit 845656aedd
7 changed files with 50 additions and 37 deletions
+4 -3
View File
@@ -6,6 +6,7 @@
#include "bt.h"
#include "resample.h"
#include "tusb.h"
#include "usb.h"
#include <algorithm>
#define INPUT_CHANNELS 4
@@ -13,7 +14,7 @@
#define SAMPLE_SIZE 64
#define REPORT_SIZE 142
#define REPORT_ID 0x32
#define VOLUME_GAIN 2
// #define VOLUME_GAIN 2
#define BUFFER_LENGTH 55
static WDL_Resampler resampler;
@@ -49,8 +50,8 @@ void audio_loop() {
// 4. 转换为int8并缓冲,满64字节即组包发送
for (int i = 0; i < out_frames; i++) {
int val_l = (int) (out_buf[i * 2] * 127.0f * VOLUME_GAIN);
int val_r = (int) (out_buf[i * 2 + 1] * 127.0f * VOLUME_GAIN);
int val_l = (int) (out_buf[i * 2] * 127.0f * (volume[0] ?: 1));
int val_r = (int) (out_buf[i * 2 + 1] * 127.0f * (volume[0] ?: 1));
haptic_buf[haptic_buf_pos++] = (int8_t) std::clamp(val_l, -128, 127); // 似乎clamp有点多余?还是以防万一吧
haptic_buf[haptic_buf_pos++] = (int8_t) std::clamp(val_r, -128, 127);