fix: usbaudio set_cur cmd set volume
This commit is contained in:
+3
-2
@@ -13,6 +13,7 @@
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/util/queue.h"
|
||||
#include "config.h"
|
||||
#include "usb.h"
|
||||
|
||||
#define INPUT_CHANNELS 4
|
||||
#define OUTPUT_CHANNELS 2
|
||||
@@ -59,8 +60,8 @@ void audio_loop() {
|
||||
int nframes = resampler.ResamplePrepare(frames, OUTPUT_CHANNELS, &in_buf);
|
||||
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS] / 32768.0f * (get_config().speaker_volume - 1.0f);
|
||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS + 1] / 32768.0f * (get_config().speaker_volume - 1.0f);
|
||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS] / 32768.0f * (get_config().speaker_volume - 1.0f) * !mute[0];
|
||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS + 1] / 32768.0f * (get_config().speaker_volume - 1.0f) * !mute[0];
|
||||
if (audio_buf_pos == 512 * 2) {
|
||||
static audio_raw_element element{};
|
||||
memcpy(element.data,audio_buf,512 * 2 * 4);
|
||||
|
||||
@@ -122,3 +122,8 @@ void set_config(const uint8_t *new_config, const uint16_t len) {
|
||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
||||
}
|
||||
}
|
||||
|
||||
void set_config(const Config_body &new_config) {
|
||||
config.body = new_config;
|
||||
config_valid();
|
||||
}
|
||||
|
||||
@@ -32,5 +32,6 @@ bool config_save();
|
||||
const Config_body& get_config();
|
||||
void set_config(const uint8_t *new_config, const uint16_t len);
|
||||
void config_valid();
|
||||
void set_config(const Config_body &new_config);
|
||||
|
||||
#endif //DS5_BRIDGE_CONFIG_H
|
||||
|
||||
+10
-2
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "tusb.h"
|
||||
#include "bsp/board_api.h"
|
||||
#include "config.h"
|
||||
|
||||
uint8_t mute[2]; // 0: SPEAKER(0x02) 1: MIC(0x05)
|
||||
float volume[2] = {1.0f}; // 0: SPEAKER(0x02) 1: MIC(0x05)
|
||||
@@ -66,6 +67,11 @@ static bool audio10_set_req_entity(tusb_control_request_t const *p_request, uint
|
||||
TU_VERIFY(p_request->wLength == 2);
|
||||
|
||||
volume[index] = static_cast<float>(tu_unaligned_read16(pBuff)) / 256;
|
||||
if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
|
||||
auto config = get_config();
|
||||
config.speaker_volume = volume[index];
|
||||
set_config(config);
|
||||
}
|
||||
|
||||
TU_LOG2(" Set Volume: %d dB of entity: %u\r\n", volume[index], entityID);
|
||||
return true;
|
||||
@@ -103,8 +109,10 @@ static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const
|
||||
switch (p_request->bRequest) {
|
||||
case AUDIO10_CS_REQ_GET_CUR:
|
||||
TU_LOG2(" Get Volume of entity: %u\r\n", entityID); {
|
||||
int16_t vol = volume[index];
|
||||
vol = vol * 256; // convert to 1/256 dB units
|
||||
if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
|
||||
volume[index] = get_config().speaker_volume;
|
||||
}
|
||||
int16_t vol = volume[index] * 256; // convert to 1/256 dB units
|
||||
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &vol, sizeof(vol));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user