Skip to content

Commit

Permalink
处理【函数调用】参数中的【返回】命令
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Jan 22, 2024
1 parent 56181e8 commit d8f952f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/mytool/deal_silk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::mytool::PCMStruct;


/// Simple linear resampling, not great quality but get things going
// 线性插值
pub fn linear_resample(in_pcm: &Vec<f64>, out_pcm: &mut Vec<f64>) {
let in_sample_count: usize = in_pcm.len() as usize;
let out_sample_count: usize = out_pcm.len() as usize;
Expand Down Expand Up @@ -39,17 +39,17 @@ pub fn to_qq_silk(pcm: &PCMStruct) -> Vec<u8> {
// let mut dat_avg = pcm.data[index..index + pcm.channel_num].iter().sum::<f64>() / (pcm.channel_num as f64);
// 取第一个通道
let mut dat_avg = pcm.data[index];
dat_avg *= f64::powi(2.0, 16 - pcm.bits_per_sample as i32);
dat_avg *= f64::powi(2.0, 16 - pcm.bits_per_sample as i32); // 采样深度缩放为16位(此处可以决定音量),silk只支持16位
single_channel_data.push(dat_avg);
index += pcm.channel_num;
}

// 采样率转换24000
// 采样率转换24000(使用线性插值)
let new_24000_data_len = ((single_channel_data.len() as f64 * pcm.channel_num as f64/ pcm.sample_rate as f64) * out_sample_rate as f64).round() as usize;
let mut new_24000_data = vec![0f64; new_24000_data_len];
linear_resample(&single_channel_data, &mut new_24000_data);

// 转为单通道u16
// 转为单通道i16
let mut u16_data = vec![];
let mut index = 0usize;
while index < new_24000_data_len{
Expand All @@ -59,9 +59,7 @@ pub fn to_qq_silk(pcm: &PCMStruct) -> Vec<u8> {
u16_data.push(bits[0]);
u16_data.push(bits[1]);
index += pcm.channel_num;

}

// bit_rate也最好是24000,不然可能在NTQQ上无法播放
if let Ok(out) = silk_rs::encode_silk(u16_data, out_sample_rate, out_sample_rate, true){
return out;
Expand Down
11 changes: 11 additions & 0 deletions src/redlang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,17 @@ impl RedLang {
}
}

// 用于处理参数中的返回
let fun_ret_vec_len = self.fun_ret_vec.len();
if self.fun_ret_vec[fun_ret_vec_len - 1].0 == true {
// 如果参数中已经返回,就收集返回值,然后结束函数调用
let mut to_ret = String::new();
for i in fun_params_t {
to_ret += &i;
}
return Ok(to_ret);
}

// 修改参数栈
self.params_vec.push(fun_params_t);

Expand Down

0 comments on commit d8f952f

Please sign in to comment.