在我的音频处理代码(音频处理器)中,我有类似以下代码的内容。我试图避免在下面的重复代码。想知道是否有更好的方法编写此代码?
代码只是说明问题的一个示例:我有几个音频处理模块,其中一个模块的音频作为输入传递到第二个模块,依此类推,直到最终处理后的输出为止。此“块”有4个主要组成部分:初始化,处理,重置和取消初始化。
/* some code here to initialize audio processing blocks */
//snip
/*
* order of audio processing is important here.
* Is there any way to avoid writing below code
* for every processing block that gets added in
* future in c++11 perhaps??
*/
if (t1) {
t1->process(iFrame, oFrame);
iFrame = oFrame;
}
if (t2) {
t2->reset();
t2->process(iFrame, oFrame);
iFrame = oFrame;
}
if (t3) {
t3->process(iFrame, oFrame);
iFrame = oFrame;
}
/*
* if in future we want this way t1 - > t3 - > t2 then code change is required,
* is there any way to avoid this code change
*/
本质上,我正在寻找一种通用的方式来处理此问题:
P 1-> P 2-> P 3-> P 4
P 代表处理块。