haptics gain before resample
This commit is contained in:
+11
-7
@@ -35,6 +35,7 @@ alignas(8) static uint32_t audio_core1_stack[8192];
|
|||||||
queue_t audio_fifo;
|
queue_t audio_fifo;
|
||||||
static uint8_t opus_buf[200];
|
static uint8_t opus_buf[200];
|
||||||
critical_section_t opus_cs;
|
critical_section_t opus_cs;
|
||||||
|
|
||||||
struct audio_raw_element {
|
struct audio_raw_element {
|
||||||
float data[512 * 2];
|
float data[512 * 2];
|
||||||
};
|
};
|
||||||
@@ -60,10 +61,11 @@ void audio_loop() {
|
|||||||
WDL_ResampleSample *in_buf;
|
WDL_ResampleSample *in_buf;
|
||||||
int nframes = resampler.ResamplePrepare(frames, OUTPUT_CHANNELS, &in_buf);
|
int nframes = resampler.ResamplePrepare(frames, OUTPUT_CHANNELS, &in_buf);
|
||||||
|
|
||||||
float gain = mute[0] ? 0.0f : powf(10.0f, get_config().speaker_volume / 20.0f);
|
const float audio_gain = mute[0] ? 0.0f : powf(10.0f, get_config().speaker_volume / 20.0f);
|
||||||
|
const float haptics_gain = get_config().haptics_gain;
|
||||||
for (int i = 0; i < nframes; i++) {
|
for (int i = 0; i < nframes; i++) {
|
||||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS] / 32768.0f * gain;
|
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS] / 32768.0f * audio_gain;
|
||||||
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS + 1] / 32768.0f * gain;
|
audio_buf[audio_buf_pos++] = raw[i * INPUT_CHANNELS + 1] / 32768.0f * audio_gain;
|
||||||
if (audio_buf_pos == 512 * 2) {
|
if (audio_buf_pos == 512 * 2) {
|
||||||
static audio_raw_element element{};
|
static audio_raw_element element{};
|
||||||
memcpy(element.data, audio_buf, 512 * 2 * 4);
|
memcpy(element.data, audio_buf, 512 * 2 * 4);
|
||||||
@@ -76,8 +78,10 @@ void audio_loop() {
|
|||||||
audio_buf_pos = 0;
|
audio_buf_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_buf[i * 2] = (WDL_ResampleSample) raw[i * INPUT_CHANNELS + 2] / 32768.0f;
|
in_buf[i * 2] = static_cast<WDL_ResampleSample>(clamp(raw[i * INPUT_CHANNELS + 2] / 32768.0f * haptics_gain,
|
||||||
in_buf[i * 2 + 1] = (WDL_ResampleSample) raw[i * INPUT_CHANNELS + 3] / 32768.0f;
|
-1.0f, 1.0f));
|
||||||
|
in_buf[i * 2 + 1] = static_cast<WDL_ResampleSample>(clamp(raw[i * INPUT_CHANNELS + 3] / 32768.0f * haptics_gain,
|
||||||
|
-1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 48kHz -> 3kHz 重采样
|
// 3. 48kHz -> 3kHz 重采样
|
||||||
@@ -89,8 +93,8 @@ void audio_loop() {
|
|||||||
|
|
||||||
// 4. 转换为int8并缓冲,满64字节即组包发送
|
// 4. 转换为int8并缓冲,满64字节即组包发送
|
||||||
for (int i = 0; i < out_frames; i++) {
|
for (int i = 0; i < out_frames; i++) {
|
||||||
int val_l = (int) (out_buf[i * 2] * 127.0f * max(get_config().haptics_gain,1.0f));
|
int val_l = static_cast<int>(out_buf[i * 2] * 127.0f);
|
||||||
int val_r = (int) (out_buf[i * 2 + 1] * 127.0f * max(get_config().haptics_gain,1.0f));
|
int val_r = static_cast<int>(out_buf[i * 2 + 1] * 127.0f);
|
||||||
haptic_buf[haptic_buf_pos++] = (int8_t) clamp(val_l, -128, 127); // 似乎clamp有点多余?还是以防万一吧
|
haptic_buf[haptic_buf_pos++] = (int8_t) clamp(val_l, -128, 127); // 似乎clamp有点多余?还是以防万一吧
|
||||||
haptic_buf[haptic_buf_pos++] = (int8_t) clamp(val_r, -128, 127);
|
haptic_buf[haptic_buf_pos++] = (int8_t) clamp(val_r, -128, 127);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user