2012-06-27 54 views
3

我正在绑定实现一个基本的音频延迟 - 但我所得到的是垃圾,可能是非常明显的 - 但我似乎无法发现它...如何让音频延迟起作用?

音频处理通过缓冲区是在运行时确定。

我想我正在做一些可怕的指针错误,试着看看其他一些代码 - 但他们都似乎“不完整”总是缺少一些基本的东西 - 可能是我的代码中还有些什么。

// Process audio 
// 1 
void Gain::subProcessSimpleDelay(int bufferOffset, int sampleFrames) 
{ 
    // Assign pointers to your in/output buffers. 
    // Each buffer is an array of float samples. 
    float* in1 = bufferOffset + pinInput1.getBuffer(); 
    float* in2 = bufferOffset + pinInput2.getBuffer(); 
    float* out1 = bufferOffset + pinOutput1.getBuffer(); 

    // SampleFrames = how many samples to process (can vary). 
    // Repeat (loop) that many times 
    for(int s = sampleFrames; s > 0; --s) 
    { 
     // get the sample 'POINTED TO' by in1. 
     float input1 = *in1;  

     float feedback = *in2; 
     float output; 
     unsigned short int p, r; 
     unsigned short int len; 
     len = 600; 

     // check at delay length calculation 
     if (len > 65535) 
      len = 65535; 
     // otherwise, a length of 0 will output the input from 
     // 65536 samples ago 
     else if (len < 1) 
      len = 1; 

     r = p - len; // loop 
     output = buffer[r]; 
     buffer[p] = input1 + output * feedback; 
     p++; 

     *out1 = output; 

     // store the result in the output buffer. 
     // increment the pointers (move to next sample in buffers). 
     in1++; 
     in2++; 
     out1++; 
    } 
} 

有人能告诉我什么是错?

回答

2

您还没有初始化p。在此代码中需要注意的其他事项: -

  • 您确定sampleFrames + bufferOffset小于输入和输出缓冲区的大小吗?你真的可以用一种方法来检查。
  • 目前尚不清楚其中buffer来自,或者什么可能是其他人写它。如果在你的代码运行之前垃圾是垃圾的,那么你最终会随处都有垃圾,因为你要做的第一件事就是从中读取垃圾。
  • 你不说什么类型的pinInput1.getBuffer()等回报。如果他们返回char*,你只知道它正好指向float数组,你需要你做任何指针算法,之前的结果转换为float*,以确保你前进到下一个浮动的该数组,而不是数组的下一个字节。
+0

部屋 - 忘了说了 - 问题是在for循环。该代码是一个.dll - 在音频流浮 - >飘出来 - 在pinInput1.getBuffer()的东西就是标准调用约定。缓冲区假定为循环延迟缓冲区 - >在.h文件中作为浮点缓冲区[65536]初始化。 –

+0

你是对的! p没有正确初始化 - 既不是r!他们需要单独使用 - 因为他们需要1个样本延迟才能“随意”。我是一个怪胎白痴;-)感谢您的帮助! –