Browse Source

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 10 years ago
parent
commit
ad746ca291
2 changed files with 15 additions and 11 deletions
  1. +10
    -9
      filter_biquad.cpp
  2. +5
    -2
      filter_biquad.h

+ 10
- 9
filter_biquad.cpp View File

@@ -37,10 +37,10 @@ void AudioFilterBiquad::update(void)

block = receiveWritable();
if (!block) return;
data = (uint32_t *)(block->data);
end = data + AUDIO_BLOCK_SAMPLES/2;
state = (int32_t *)definition;
do {
data = (uint32_t *)(block->data); // needs to be done inside the loop, end need not be reset.
a0 = *state++;
a1 = *state++;
a2 = *state++;
@@ -78,14 +78,20 @@ void AudioFilterBiquad::update(void)
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 *src=(int32_t *)source;
while(set)
{
*dest+=7;
if(!(*dest&0x80000000)) return;
*dest++;
set--;
}
__disable_irq();
for(uint8_t index=0;index<5;index++)
{
*dest++=*src++;
*dest++=*source++;
}
if(doReset)
{
@@ -96,8 +102,3 @@ void AudioFilterBiquad::updateCoefs(int *source, bool doReset)
__enable_irq();
}

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


+ 5
- 2
filter_biquad.h View File

@@ -36,8 +36,11 @@ public:
: AudioStream(1, inputQueueArray), definition(parameters) { }
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:
int *definition;
audio_block_t *inputQueueArray[1];

Loading…
Cancel
Save