c++ - 如何定义和设置指向在中间类中传递两次的二维数组的指针
问题描述
我的 MainProcessor 中有一个数组
float waveforms[2][1080] = { {0}, {0} };
我将它传递给 SynthVoice,如下所示:
osc1Voice->setWavetable(waveforms, 0); //[1]
osc2Voice->setWavetable(waveforms, 1);
我在 SynthVoice.h 中这样读到它:
typedef float array_of_wavetable[1080];
void setWavetable(array_of_wavetable* waveform, int number)
{
wavetable = waveform;
id = number;
}
所以我可以在我的 SynthVoice 类中这样使用它:
wavetable[id][first_sample + int(phase_0)]
现在我已经将 [1] 移到了一个新类 (OscilatorProcessor.h) 中,并且我想设置一个来自 MainProcessor -> OscillatorProcessor -> SynthVoice 的指针,以便我可以将其用作波表 [id] [相位]。
现在我不知道如何将它从我的 MainProcessor 传递到中间的 OscillatorProcessor 。所以我可以在 SynthVoice 类中以同样的方式阅读它。
我希望这是有道理的。感谢您的时间
编辑:最小的可重现示例
#include <iostream>
typedef float array_of_wavetable[1080];
class SynthVoice
{
public:
void setWavetable(array_of_wavetable* waveform, int number)
{
wavetable = waveform;
id = number;
}
void outputWavetable()
{
for(int i = 0; i < 1080; i++)
{
std::cout << wavetable[id][i];
}
}
private:
array_of_wavetable * wavetable;
int id;
};
class OscillatorProcessor
{
public:
void setWavetable(array_of_wavetable * waveform, int number)
{
wavetable = waveform;
id = number;
}
void sendWaveToVoice()
{
SynthVoice voice;
voice.setWavetable(wavetable, id);
voice.outputWavetable();
}
private:
array_of_wavetable * wavetable;
int id;
};
int main() {
float waveform_templates[4][1080] = { {0}, {0}, {0}, {0} };
OscillatorProcessor oscillator;
oscillator.setWavetable(waveform_templates, 2);
return 0;
}
解决方案
推荐阅读
- wordpress - 我在 Wordpress 管理菜单上删除了用户,但用户数据仍保留在 phpmyadmin 中
- ios - SwiftUI 持有对已删除核心数据对象的引用导致崩溃
- php - PHP获取最后五分钟的增量
- mysql - 如何在 GROUP_CONCAT 中实现 SQL 查询以使用“,”分隔并以“&”结尾
- c++ - c ++计算给出inf或零的long doubles
- algorithm - 需要算法来确定两组之间的最佳配对
- algorithm - 拆分集合后如何在合并排序中应用合并逻辑?
- rust - 为什么通过 `for` 循环遍历集合在 Rust 中被视为“移动”?
- flutter - Flutter:更新列表中的特定索引(Firestore)
- java - 我被Java困住了