Help with using filters for a x-over

Status
Not open for further replies.
Hi all.
I'm new to the forum & to be totally honest, don't have a single clue about coding (not even a 'teensy' little bit).
I was given a RCF Evox 5 speaker by a friend after he somehow managed to damage the main board & fried the onboard dsp ic that splits the sound (highs & lows).
I purchased a Teensy 4 and an audio board with the hopes of making a basic active line level cross-over for this speaker.
I went onto the website with audio design tool and put together what I thought I required to do this.
Basically using both inputs (line in) then going to 2x bi-quad filters, then each to an amp & then out.
This kinda worked as I do get audio out, but the sound is distorted on certain frequencies. I have no idea what code to use inside of the project.
I played around & tried to learn what I could from using other peoples examples & kinda managed to get a low & high output, but unfortunately it still sounds bad to me.
I don't even know where to look to find the code to use for this or where to read up on what each piece of code does, where to put brackets, curly brackets, semi-colons etc...
I even watched those Teensy audio workshop video's (all of them!!) None of them mention what code you must use after using the web based tool??
Please, please, please can someone help me with this. I have no idea what I'm doing but I am willing to learn. I'm starting to lose my mind!!

This is all the code I put in (using the tool, examples & guessing):

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=55,363
AudioFilterBiquad biquad1; //xy=310,341
AudioFilterBiquad biquad2; //xy=312,388
AudioAmplifier amp4; //xy=429,392
AudioAmplifier amp3; //xy=431,341
AudioOutputI2S i2s2; //xy=649,340
AudioConnection patchCord1(i2s1, 0, biquad1, 0);
AudioConnection patchCord2(i2s1, 1, biquad2, 0);
AudioConnection patchCord3(biquad1, amp3);
AudioConnection patchCord4(biquad2, amp4);
AudioConnection patchCord5(amp4, 0, i2s2, 1);
AudioConnection patchCord6(amp3, 0, i2s2, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=422,586
// GUItool: end automatically generated code






const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_LINEIN;

void setup() {
AudioMemory(12);

sgtl5000_1.enable(); // Enable the audio shield
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(1);

// Amplification
amp3.gain(7);
amp4.gain(5);

// Butterworth filter, 48 db/octave
biquad1.setLowpass(0, 200, 1);

// Linkwitz-Riley filter, 48 dB/octave
//biquad1.setLowpass(0, 200, 1);


// Butterworth filter, 48 db/octave
biquad2.setHighpass(0, 200, 1);

// Linkwitz-Riley filter, 48 dB/octave
//biquad2.setHighpass(0, 200, 1);
}


void loop() {
}

Any help / guidance will be appreciated.

Thanks in advance.
 
Internally, the Teensy Audio lib uses 16bit integer math to do the DSP operations. Prosumer DSP crossovers are going to use at least 32bit or perhaps 48bit math to do their DSP operations. The Teensy Audio lib is chock full of clever optimizations to allow running on inexpensive 32bit ARM microcontrollers. The tradeoff is that you probably won't get fidelity comparable to higher cost off-the-shelf solutions.

Having said that, amp3 and amp4 applying so much gain to the signal could be a source of distortion. You may try external gain stages (op amps) before and/or after the Teensy if you really need that much gain.
 
The biquad filter uses 32 bit math internally, and 32 bit coefficients. 16 x 32 bit multiplies are done internally as 48 bits, then rounded back to 32.

Sure, it probably isn't comparable to high end prosumer products.

But quite a lot of work has gone into this filter's numerical precision. It's isn't just 16 bits and all designed around minimizing CPU time at the expense of quality.
 
Thank you so much replying guys. First off, is the code that I posted correct?
As I said, I actually just took a guess at what to do based on similar code in the examples I found. Am I using the correct filter?
The combined use of Linkwitz Riley & Butterworth filters in the code doesn't make sense to me at all. Am I implementing one filter ontop of another (using both?)
If you know of any sites or anywhere where I can find a list of audio codes & any reading material that can help me learn where to put brackets & colons etc..
I am very keen to learn more about this powerful little board. So any info would be greatly appreciated.
The gain that I used for amp 3 & 4 was me trying to boost the overall output level coz once the filter was applied the output was really low.
The amps did boost the signal level, sadly along with the noise floor :(
Looking at the output waveform on a scope, I see no visible clipping whilst doing a sweep. However with actual music I can hear a bit of breakup / distortion.
The scope also reveals that it's not only the x-over frequencies that are affected. I seem to be getting a almost linear taper of the frequencies from 200hz in either direction.
Eg: With the high pass filter, I am down 6db's at 250hz, then -3db's at 500hz, and 0db at 750hz etc...
The idea was to cross over at 200hz with a roll off of 48db per octave from 200hz down (for high pass) & 200hz up (for low pass) with out any other frequencies being affected. I can't help but feel that the code I've put into this is insufficient & perhaps I need to add more or use different commands.
If anyone can suggest some improvements a better way to do this & achieve nice results please chime in.
Once again, thank you for taking the time to respond & trying to help.
 
Status
Not open for further replies.
Back
Top