在音频回调中随时间间隔更改变量
Change Variable over Time Interval in Audio Callback
所以我想在一段时间内更改 for 循环中的变量。在我的代码中,我的音频回调基本上是 运行 以下伪代码:
int start = 0, target = 100;
for (int i = 0; i < frames; i++) {
[object makeSineWave];
[object useNum:start];
if (target > start) {
// Increase start over the span of time frame
}
}
我想要做的是在一个时间间隔内以对数标度将开始值增加到目标值(为简单起见,假设为 1 秒)。我如何在音频回调的 for 循环中跟踪时间?
编辑:猜猜我正在尝试进行滤波器扫描...我猜现在我想它会类似于正弦扫描?更多代码-
OSStatus RenderTone(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
// Get Audio Data
AudioData *data = (__bridge AudioData *)inRefCon;
static Float32 phs = 0, sub_phs = 0;
Float32 freq = data->freq;
// Calculate phases
Float32 phs_incr = 2 * M_PI * freq / data->srate;
Float32 sample;
// Buffers
Float32 *bufL = (Float32 *)ioData->mBuffers[0].mData;
Float32 *bufR = (Float32 *)ioData->mBuffers[1].mData;
// Start at 1 hz, target is 500 hz
int start = 1, target = 500;
// Generate Samples
for (UInt32 i = 0; i < inNumberFrames; i++) {
// Sine waveform
sample = sinf(phs);
sample = [data->filter processFilter:sample fc:start];
// change start here using current time?
// should not increase to target immediately, over span of 1 second
bufL[i] = buf[R] = sample;
// Increment phase
phs += phs_incr;
// Wrap phase
phs = wrapPhase(phs);
}
}
我似乎通过查看 CCRMA 的 STK 找到了如何做到这一点...我希望我早点找到的好资源!
所以我想在一段时间内更改 for 循环中的变量。在我的代码中,我的音频回调基本上是 运行 以下伪代码:
int start = 0, target = 100;
for (int i = 0; i < frames; i++) {
[object makeSineWave];
[object useNum:start];
if (target > start) {
// Increase start over the span of time frame
}
}
我想要做的是在一个时间间隔内以对数标度将开始值增加到目标值(为简单起见,假设为 1 秒)。我如何在音频回调的 for 循环中跟踪时间?
编辑:猜猜我正在尝试进行滤波器扫描...我猜现在我想它会类似于正弦扫描?更多代码-
OSStatus RenderTone(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
// Get Audio Data
AudioData *data = (__bridge AudioData *)inRefCon;
static Float32 phs = 0, sub_phs = 0;
Float32 freq = data->freq;
// Calculate phases
Float32 phs_incr = 2 * M_PI * freq / data->srate;
Float32 sample;
// Buffers
Float32 *bufL = (Float32 *)ioData->mBuffers[0].mData;
Float32 *bufR = (Float32 *)ioData->mBuffers[1].mData;
// Start at 1 hz, target is 500 hz
int start = 1, target = 500;
// Generate Samples
for (UInt32 i = 0; i < inNumberFrames; i++) {
// Sine waveform
sample = sinf(phs);
sample = [data->filter processFilter:sample fc:start];
// change start here using current time?
// should not increase to target immediately, over span of 1 second
bufL[i] = buf[R] = sample;
// Increment phase
phs += phs_incr;
// Wrap phase
phs = wrapPhase(phs);
}
}
我似乎通过查看 CCRMA 的 STK 找到了如何做到这一点...我希望我早点找到的好资源!