From 94530dd9a4ad4b3d7f6ac35b56c2fbaf4087e009 Mon Sep 17 00:00:00 2001 From: awalol Date: Tue, 17 Mar 2026 16:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=9F=B3=E9=87=8F=E8=B0=83=E8=8A=82?= =?UTF-8?q?=E7=9A=84=E8=8C=83=E5=9B=B4=E8=AE=BE=E4=B8=BA=20-100=20?= =?UTF-8?q?=E5=88=B0=200=20(=E5=BD=93=E5=89=8D=E6=97=A0=E4=BD=9C=E7=94=A8)?= =?UTF-8?q?,=20=E6=98=8E=E7=A1=AE=E5=A2=9E=E7=9B=8A=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/audio.cpp | 13 +++++++------ src/usb.cpp | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index ee042a2..2b0b94e 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -10,9 +10,10 @@ #define INPUT_CHANNELS 4 #define OUTPUT_CHANNELS 2 -#define SAMPLE_SIZE 64 -#define REPORT_SIZE 142 -#define REPORT_ID 0x32 +#define SAMPLE_SIZE 64 +#define REPORT_SIZE 142 +#define REPORT_ID 0x32 +#define VOLUME_GAIN 2 static WDL_Resampler resampler; static uint8_t reportSeqCounter = 0; @@ -47,9 +48,9 @@ void audio_loop() { // 4. 转换为int8并缓冲,满64字节即组包发送 for (int i = 0; i < out_frames; i++) { - int val_l = (int) (out_buf[i * 2] * 254.0f); - int val_r = (int) (out_buf[i * 2 + 1] * 254.0f); - haptic_buf[haptic_buf_pos++] = (int8_t) std::clamp(val_l, -128, 127); + 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); + 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); if (haptic_buf_pos != SAMPLE_SIZE) { diff --git a/src/usb.cpp b/src/usb.cpp index 5c134ff..7a7862d 100644 --- a/src/usb.cpp +++ b/src/usb.cpp @@ -86,6 +86,7 @@ static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const uint8_t channelNum = TU_U16_LOW(p_request->wValue); uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue); uint8_t entityID = TU_U16_HIGH(p_request->wIndex); + // 当前音量的调节不会影响音量大小,看看后面有没有用再补全吧 // If request is for our speaker feature unit if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT || entityID == UAC1_ENTITY_MIC_FEATURE_UNIT) { @@ -107,14 +108,14 @@ static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const case AUDIO10_CS_REQ_GET_MIN: TU_LOG2(" Get Volume min of channel: %u\r\n", channelNum); { - int16_t min = -90; // -90 dB + int16_t min = -100; // -100 dB min = min * 256; // convert to 1/256 dB units return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &min, sizeof(min)); } case AUDIO10_CS_REQ_GET_MAX: TU_LOG2(" Get Volume max of channel: %u\r\n", channelNum); { - int16_t max = 30; // +30 dB + int16_t max = 0; // 0 dB max = max * 256; // convert to 1/256 dB units return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &max, sizeof(max)); }