浏览代码

fix for compounding/cascading filters

'data' needs to be reset inside the 'flag' controlled loop or
*undefined* behavior is likely when user sets 'flag' and loop repeats
without resetting 'data' to beginning of block.
dds
robsoles 11 年前
父节点
当前提交
ad746ca291
共有 2 个文件被更改,包括 15 次插入11 次删除
  1. +10
    -9
      filter_biquad.cpp
  2. +5
    -2
      filter_biquad.h

+ 10
- 9
filter_biquad.cpp 查看文件



block = receiveWritable(); block = receiveWritable();
if (!block) return; if (!block) return;
data = (uint32_t *)(block->data);
end = data + AUDIO_BLOCK_SAMPLES/2; end = data + AUDIO_BLOCK_SAMPLES/2;
state = (int32_t *)definition; state = (int32_t *)definition;
do { do {
data = (uint32_t *)(block->data); // needs to be done inside the loop, end need not be reset.
a0 = *state++; a0 = *state++;
a1 = *state++; a1 = *state++;
a2 = *state++; a2 = *state++;
release(block); release(block);
} }


void AudioFilterBiquad::updateCoefs(int *source, bool doReset)
void AudioFilterBiquad::updateCoefs(uint8_t set,int *source, bool doReset)
{ {
int32_t *dest=(int32_t *)definition; int32_t *dest=(int32_t *)definition;
int32_t *src=(int32_t *)source;
while(set)
{
*dest+=7;
if(!(*dest&0x80000000)) return;
*dest++;
set--;
}
__disable_irq(); __disable_irq();
for(uint8_t index=0;index<5;index++) for(uint8_t index=0;index<5;index++)
{ {
*dest++=*src++;
*dest++=*source++;
} }
if(doReset) if(doReset)
{ {
__enable_irq(); __enable_irq();
} }


void AudioFilterBiquad::updateCoefs(int *source)
{
updateCoefs(source,false);
}


+ 5
- 2
filter_biquad.h 查看文件

: AudioStream(1, inputQueueArray), definition(parameters) { } : AudioStream(1, inputQueueArray), definition(parameters) { }
virtual void update(void); virtual void update(void);
void updateCoefs(int *source, bool doReset);
void updateCoefs(int *source);
void updateCoefs(uint8_t set,int *source, bool doReset);

void updateCoefs(uint8_t set,int *source) { updateCoefs(set,source,false); }
void updateCoefs(int *source, bool doReset) { updateCoefs(0,source,doReset); }
void updateCoefs(int *source) { updateCoefs(0,source,false); }
private: private:
int *definition; int *definition;
audio_block_t *inputQueueArray[1]; audio_block_t *inputQueueArray[1];

正在加载...
取消
保存