f1 playing bak working
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include "xua_conf.h"
|
||||
#include "share_buffer.h"
|
||||
|
||||
extern uint32_t init_eq_data(unsigned sample_freq);
|
||||
|
||||
#if F1_MUSIC_UAC2 == 1 && DNR_ENABLE == 1
|
||||
/* 改动原因:3 streaming chan + 1 普通 chan 传 us 192kHz(跨 tile 静态内存不共享) */
|
||||
uint32_t uc_ssrc_ds_in; /* tile[0]→tile[1] 192kHz mic */
|
||||
@@ -27,13 +29,18 @@ void dnr_exchange_buffer(int32_t *data);
|
||||
|
||||
// sample_freq 作为首字发送给 tile[0] 的 dsp_main,用于采样率变化检测和 EQ 初始化
|
||||
void buffer_exchange(chanend_t c_data, unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[], unsigned sample_freq) {
|
||||
chan_out_word(c_data, sample_freq);
|
||||
// chan_out_buf_word (c_data, sampsFromUsbToAudio, 2);
|
||||
// chan_in_buf_word (c_data , sampsFromUsbToAudio, 2);
|
||||
#if DNR_ENABLE == 1
|
||||
chan_out_buf_word (c_data, sampsFromAudioToUsb, 2);
|
||||
chan_in_buf_word (c_data , sampsFromAudioToUsb, 2);
|
||||
#endif
|
||||
unsigned data_in[4] = {0,0,0,0};
|
||||
unsigned data_out[4] = {0,0,0,0};
|
||||
data_in[0] = sampsFromUsbToAudio[0];
|
||||
data_in[1] = sampsFromUsbToAudio[1];
|
||||
data_in[2] = sampsFromAudioToUsb[0];
|
||||
data_in[3] = sampsFromAudioToUsb[1];
|
||||
chan_out_buf_word (c_data, data_in, 4);
|
||||
chan_in_buf_word (c_data , data_out, 4);
|
||||
sampsFromUsbToAudio[0] = data_out[0];
|
||||
sampsFromUsbToAudio[1] = data_out[1];
|
||||
sampsFromAudioToUsb[0] = data_out[2];
|
||||
sampsFromAudioToUsb[1] = data_out[3];
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +51,10 @@ void dsp_main (chanend_t c_data) {
|
||||
int mic_output[I2S_CHANS_ADC];
|
||||
int count = 0;
|
||||
unsigned ch[1] = {2};
|
||||
unsigned data_in[4] = {0,0,0,0};
|
||||
unsigned data_out[4] = {0,0,0,0};
|
||||
#if F1_MUSIC_UAC2 == 1
|
||||
unsigned current_sample_freq = 0;
|
||||
unsigned current_sample_freq = 192000;
|
||||
#else
|
||||
unsigned current_sample_freq = 48000;
|
||||
#endif
|
||||
@@ -60,25 +69,33 @@ void dsp_main (chanend_t c_data) {
|
||||
static int us_first_batch = 1;
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
/* 协议:tile[1] 先发 sample_freq,再发 mic_input[2];
|
||||
* tile[0] 接收处理后发回 mic_output[2] */
|
||||
unsigned sample_freq = (unsigned)chan_in_word(c_data);
|
||||
// chan_in_buf_word (c_data , play_input, 2);
|
||||
|
||||
/* 采样率变化:复位 SSRC 状态 */
|
||||
if (sample_freq != current_sample_freq && sample_freq != 0) {
|
||||
current_sample_freq = sample_freq;
|
||||
init_eq_data(current_sample_freq);
|
||||
clear_ring_buffer(0);
|
||||
clear_ring_buffer(1);
|
||||
clear_ring_buffer(2);
|
||||
clear_ring_buffer(3);
|
||||
#if F1_MUSIC_UAC2 == 1 && DNR_ENABLE == 1
|
||||
/* 改动原因:采样率变化时复位所有 SSRC 状态,下一批重新从头开始 */
|
||||
ds_tick = 0;
|
||||
us_cache_idx = 4;
|
||||
us_first_batch = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
while (1) {
|
||||
chan_in_buf_word(c_data, data_in, 4);
|
||||
chan_out_buf_word(c_data, data_out, 4);
|
||||
|
||||
// chan_out_buf_word (c_data , play_output, I2S_CHANS_DAC);
|
||||
chan_in_buf_word(c_data, mic_input, 2); /* 接收 tile[1] 发来的原始 mic */
|
||||
#if EQ_ENABLE == 1
|
||||
write_to_ring_buffer(0, data_in[0]);
|
||||
write_to_ring_buffer(1, data_in[1]);
|
||||
data_out[0] = read_from_ring_buffer(2);
|
||||
data_out[1] = read_from_ring_buffer(3);
|
||||
// data_out[0] = data_in[0];
|
||||
// data_out[1] = data_in[1];
|
||||
#else
|
||||
data_out[0] = data_in[0];
|
||||
data_out[1] = data_in[1];
|
||||
#endif
|
||||
|
||||
#if DNR_ENABLE == 1
|
||||
#if F1_MUSIC_UAC2 == 1
|
||||
@@ -93,8 +110,8 @@ void dsp_main (chanend_t c_data) {
|
||||
* 在前 3 拍期间已完成并阻塞等待消费,读取近乎零延迟),再触发本批 ds→DNR→us_in。
|
||||
* 代价:录音延迟增加约 20.8µs(一个 48kHz 周期),人耳不可感知。
|
||||
*/
|
||||
s_chan_out_word((chanend_t)uc_ssrc_ds_in, (uint32_t)mic_input[0]);
|
||||
s_chan_out_word((chanend_t)uc_ssrc_ds_in, (uint32_t)mic_input[1]);
|
||||
s_chan_out_word((chanend_t)uc_ssrc_ds_in, (uint32_t)data_in[2]);
|
||||
s_chan_out_word((chanend_t)uc_ssrc_ds_in, (uint32_t)data_in[3]);
|
||||
ds_tick++;
|
||||
|
||||
if (ds_tick >= 4) {
|
||||
@@ -124,23 +141,21 @@ void dsp_main (chanend_t c_data) {
|
||||
}
|
||||
|
||||
if (us_cache_idx < 4) {
|
||||
mic_output[0] = us_cache[us_cache_idx][0];
|
||||
mic_output[1] = us_cache[us_cache_idx][1];
|
||||
data_out[2] = us_cache[us_cache_idx][0];
|
||||
data_out[3] = us_cache[us_cache_idx][1];
|
||||
us_cache_idx++;
|
||||
} else {
|
||||
mic_output[0] = 0;
|
||||
mic_output[1] = 0;
|
||||
data_out[2] = 0;
|
||||
data_out[3] = 0;
|
||||
}
|
||||
#else
|
||||
dnr_exchange_buffer(mic_input);
|
||||
mic_output[0] = mic_input[0];
|
||||
mic_output[1] = mic_input[1];
|
||||
dnr_exchange_buffer((int32_t *)&data_in[2]);
|
||||
data_out[2] = data_in[2];
|
||||
data_out[3] = data_in[3];
|
||||
#endif
|
||||
#else
|
||||
mic_output[0] = mic_input[0];
|
||||
mic_output[1] = mic_input[1];
|
||||
data_out[2] = data_in[2];
|
||||
data_out[3] = data_in[3];
|
||||
#endif
|
||||
/* 发回处理后的 mic 数据,buffer_exchange 接收后写入 sampsFromAudioToUsb */
|
||||
chan_out_buf_word(c_data, mic_output, I2S_CHANS_ADC);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user