博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[置顶] 合唱音效
阅读量:4952 次
发布时间:2019-06-11

本文共 3544 字,大约阅读时间需要 11 分钟。

1. 算法原理 
合唱即多人一起唱歌,以下是算法的原理图:
/* * *        * gain-in                                           ___ * ibuff -----+--------------------------------------------->|   | *            |      _________                               |   | *            |     |         |                   * level 1  |   | *            +---->| delay 1 |----------------------------->|   | *            |     |_________|                              |   | *            |        /|\                                   |   | *            :         |                                    |   | *            : +-----------------+   +--------------+       | + | *            : | Delay control 1 |<--| mod. speed 1 |       |   | *            : +-----------------+   +--------------+       |   | *            |      _________                               |   | *            |     |         |                   * level n  |   | *            +---->| delay n |----------------------------->|   | *                  |_________|                              |   | *                     /|\                                   |___| *                      |                                      | *              +-----------------+   +--------------+         | * gain-out *              | Delay control n |<--| mod. speed n |         | *              +-----------------+   +--------------+         +----->obuff * * */

2. 代码实现

void dsound_chorus_processmix(dsound_chorus_t* chorus, dsound_real_t *in,			    dsound_real_t *left_out, dsound_real_t *right_out){  int sample_index;  int i;  dsound_real_t d_in, d_out;  for (sample_index = 0; sample_index < FLUID_BUFSIZE; sample_index++) {    d_in = in[sample_index];    d_out = 0.0f;# if 0    /* Debug: Listen to the chorus signal only */    left_out[sample_index]=0;    right_out[sample_index]=0;#endif    /* Write the current sample into the circular buffer */    chorus->chorusbuf[chorus->counter] = d_in;    for (i = 0; i < chorus->number_blocks; i++) {      int ii;      /* Calculate the delay in subsamples for the delay line of chorus block nr. */      /* The value in the lookup table is so, that this expression       * will always be positive.  It will always include a number of       * full periods of MAX_SAMPLES*INTERPOLATION_SUBSAMPLES to       * remain positive at all times. */      int pos_subsamples = (INTERPOLATION_SUBSAMPLES * chorus->counter			    - chorus->lookup_tab[chorus->phase[i]]);      int pos_samples = pos_subsamples/INTERPOLATION_SUBSAMPLES;      /* modulo divide by INTERPOLATION_SUBSAMPLES */      pos_subsamples &= INTERPOLATION_SUBSAMPLES_ANDMASK;      for (ii = 0; ii < INTERPOLATION_SAMPLES; ii++){	/* Add the delayed signal to the chorus sum d_out Note: The	 * delay in the delay line moves backwards for increasing	 * delay!*/	/* The & in chorusbuf[...] is equivalent to a division modulo	   MAX_SAMPLES, only faster. */	d_out += chorus->chorusbuf[pos_samples & MAX_SAMPLES_ANDMASK]	  * chorus->sinc_table[ii][pos_subsamples];	pos_samples--;      };      /* Cycle the phase of the modulating LFO */      chorus->phase[i]++;      chorus->phase[i] %= (chorus->modulation_period_samples);    } /* foreach chorus block */    d_out *= chorus->level;    /* Add the chorus sum d_out to output */    left_out[sample_index] += d_out;    right_out[sample_index] += d_out;    /* Move forward in circular buffer */    chorus->counter++;    chorus->counter %= MAX_SAMPLES;  } /* foreach sample */}

posted on
2012-06-26 08:03 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/musicfans/archive/2012/06/26/2819305.html

你可能感兴趣的文章
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
JavaScript笔记——正则表达式
查看>>
网页消息类
查看>>
【BZOJ】2959: 长跑(lct+缩点)(暂时弃坑)
查看>>
日常一些出现bug的问题
查看>>
同时启动多个tomcat服务器
查看>>
怎么将iphone上的照片导出到本地文件
查看>>
Repeater+DataPagerSource分页
查看>>
模块化导出
查看>>
pagebean pagetag java 后台代码实现分页 demo 前台标签分页 后台java分页
查看>>
Sphinx 2.0.8 发布,全文搜索引擎 Installing Sphinx on Windows
查看>>
pod
查看>>
ResultSet 可滚动性和可更新性
查看>>
iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
查看>>
LUOGU P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat…
查看>>
toad for oracle中文显示乱码
查看>>
scala的REPL shell的调用
查看>>
SQL中Group By的使用
查看>>
错误org/aopalliance/intercept/MethodInterceptor解决方法
查看>>
Pylint在项目中的使用
查看>>