Spectrum analyzer possible in DSP?

Discussion in 'Effects and the DSP' started by TheKezReturns, Jan 18, 2009.

  1. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    I was in a guys studio the other week and he had the realtime spectrum analyzer from his RME interface running permananetly on a second monitor.
    It's part of the driver and runs independantly of asio hosts ect. This is great for cross refernecing against mp3s ect and having to insert a vst plugin on the master and every time and work a way to get it visible permanently just isn't the same. Also, this one could almost fill the whoile screen.
    I've even heard of people running a whole spare PC just for this..... A KX Dsp plugins would be much neater.

    I'm not sure how they work. I'd make a guess and say some sort of FFT and I know this has been said to be inpractical to do in DSP in most cases, but considering it just has to break the frequency bands up and display them, could it be done?

    Obvisuly, sound quality isn't an issue and there's no processing or recombining of the bands to deal with. As far as resources, I'd be happy if the DSP was devoted to one really useful thing, considering everything else is better in vst plugin form these days anyway.
     
  2. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    This was brought up once before but nailed quickly with a 'just use this expensive software' kinda answer. But a dedicated, non cpu intensive, permanently running analyzer thats monotoring everythig that comes out the main outputs is really what I'm hoping for.

    Someone just tell me 'it can't be done' so I can forget it :)
     
  3. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    Well, the answer is yes, it is possible...
    Not with FFT, but it is always can be done via just a network of bandpass filters (well, the RME does this via bandpasses too)
    So the question is just how many bands it can have - approximately one band will need about 6 instructions and 5-6 registers - e.g (not counting any other code in DSP) ~80 bands for K2 - more then enough)

    >I'd make a guess and say some sort of FFT and I know this has been said to be inpractical to do in DSP in most cases

    for the fx8010 - it is kinda impossible - not really "inpractical"
     
  4. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    Cheers for that Max. A series of bandpass filters sounds alot simpler.
    Doesn't sound like it would be that difficult, for someone who knows their way around microcode that is...which I don't. :)
    I have to admit, I haven't the faintest idea how digital filters work, especially in 10kx microcode, but I assume you would just need to figure out the coefficients for the individual bands, take a peak reading for each and send the data to the gui.
    And possible store the values for rms and meter falling... or perhaps that would be better in the gui.

    Would there need to be some trickery to get the slope of the filters steep enough?
     
  5. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    Well, i can do the DSP part of this in a weekend (that would be fun for me)
    So if someone would volunteer for the GUI...

    >Would there need to be some trickery to get the slope of the filters steep enough?

    no, no trickery there - a conventional second-order bandpass can have whatever steep needed.
     
  6. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    Awesome.

    I'd certainly contribute what I can to the GUI but I'd probably need some help.
    I can definately do the graphics, and I've made a vst plugin before with a GUI in visual c++, but the VST SDK made that relatively easy. I'll have a look at the KX sdk and examples... see if I'm up to it.

    Also, generally I find the lower half of the spectrum most helpful as a visual aid. It would be great to have a button that zooms in on the 20Hz to 1k range. I guess you'd just need a second set of coeffients. Do you thnk that would be doable?
     
  7. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    Ok then, i'm on it.

    Well, as a starting point the GUI implementation could be very similiar to what the Peak plugins are doing (pretty same code) - and then extendend to whatever features will be handy.

    >It would be great to have a button that zooms in on the 20Hz to 1k range. Would that be doable?

    I think yes.
     
    Last edited: Jan 19, 2009
  8. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Just spitting out 'cool features' with out knowing how difficult - and certainly is not any expectation of any sort.....

    If the coefficients are stored in an array...it could maybe be simple enough to allow users to specify a (zoom??) range - dictated by Sliders or something.
    Ex:

    CoeficientsToLoad(sliderAvalue) to CoeficientsToLoad(sliderBValue)

    ... maybe, to save on some resources, instead of using 1 big resource hog of a plugin - maybe split it up into multiple instances of the same plugin, with user specified ranges/zoom...say using 4 to cover 20-20Khz (or what ever) - but I may only need 1 instance to cover the 20-1K range....

    Sort of thing. I dunno - I think could be useful for maybe a larger audience...

    Again, just an idea.
     
  9. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    Or just make three different versions.. say... 15 band, 30 band and 60 band.

    Perhaps we could start with working 30 band, inspired by the rme digicheck, then adapt a couple of other versions or add a "number of bands' switch/slider in a later version.

    Here's a shot of the rme one. Probably a good set of frequencies to start with.
     

    Attached Files:

  10. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    OK then, here we are: sa.zip
    I decided to start with a 40 band thing.
    The archive contains the dsp source code ("sa.da", "the SA" further) and c++ header with some definitions you'll optionally need (specifically, the corresponding band frequency values).
    As i mentioned earlier, the kxl code can be the same as a Peak plugin code - except that you have 40 bands instead of two - so one could start just with copy-pasting of kX's peak sources (although, i'd suggest you to consider the source code of the "mx6" ("mx6" version in the kX SDK will fit) as its "peak" related code is much more readable than native kX's "peak" sources).

    The only important difference between the "SA" and standard "Peak" plugins code is that the "SA" produces a 6dB higher peak values (so you will need to offset the visual representation accordingly).

    The peak values of the "SA" are in pk00..pk39 registers, they are indexed continuously so to read the values in the plugin code (that's what one typically does on timer) you do a simple iteration - something like this:
    Code:
    void readPeaks(unsigned (&values)[sa::nBands])
    {
        enum {pk00 = 0x8000}; // index of the first "peak" register (as in generated "SA_info")
        for (int i = 0; i < sa::nBands; i++)
        {
            get_dsp_register(word(pk00 + i), values + i);
            set_dsp_register(word(pk00 + i), 0);
        }
    }
    That's it, current peak values are in the "values" array - and the rest is a matter of drawing.
    (well, strictly speaking, the kxl also should handle/apply all those "hold", "release/decay" features)

    For a compatibility with the standard Peak plugins i made the "SA" to output the peak levels in logarithmic scale, but, as things go further, i'd suggest to switch to linear mode as it is a bit more flexible (see http://www.driverheaven.net/effects-dsp/32454-peak-plugin-one-register-less.html for a "lin.vs.log" peak handling overview)
    To switch the "SA" to linear mode simply change (in "sa.da") "const plog = 31i" to "const plog = 1i".

    OK... i think that's all for now - i'll post if i remember something important.

    Ah, btw...
    Known "SA" dsp code issues:

    * Under some circumstances, the lowest 2 or 3 bands may produce a random noise about (up to) -70dB. (Basically, their frequency range is just where 32-bit precision is already not enough) - this is acceptable as a working range of a conventional spectrum analyzer is typically above that level (e.g. the noise won't be visible) - but (if necessary) the plugin (e.g. kxl) can have some workaround for noisy bands, for example it can ignore the values below ~-70dB (e.g. just threat it as -Inf.) or a sort of.
     
    Last edited: Jan 23, 2009
  11. TheKezReturns

    TheKezReturns New Member

    Joined:
    Apr 25, 2005
    Messages:
    118
    Likes Received:
    1
    Trophy Points:
    0
    You da man Max. You don't mess around!
    Ok, I'll dig out my old version of visual c++ see what damage I can do.
    It will probably take me a while to get my head around it again. The last time I even looked at coed was about 6 years ago!
    On that point, if anyone thinks they can knock it off in a few hours, don't let me stop you! :)
     
  12. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    For the proof of concept i've sketched a "minimalistic skeleton" plugin for the SA. "Minimalistic" is in quotes as in fact it is a full-featured spectrum analyzer with all of typical options/settings inside, however it does not provide any GUI to edit these options (it does not also have some other minor and boring features that a "production" plugin would have). This is just where i stop.

    source code
    kxl binary
    screenshot

    The binary is provided only for an evaluation purpose (though its use permission is not restricted specifically).
    Regarding the sources, the only file of interest there is the sa.h header, it is where everything actually happens. A code in other files just provides an auxiliary functionality (common kxl handshaking, OS interaction and other boring stuff).

    --------------------------
    Performance considerations:

    * Drawing.
    The drawing code (which is the CPU load master for the concept) of the presented skeleton (a "Demo Library" if it makes sense) is not optimized at all (it uses the "slow" gdiplus, lotsa transparency and other fancy stuff, neither i used any of common drawing optimizations which would negatively affect the readability of the sources (this was a goal a sort of). Anyway the resulting CPU load of the plugin is not that bad - more then acceptable for an evaluation.

    * Reading/writing dsp registers.
    Though the bottleneck of the SA performance is its drawing (no matter how optimized it is), the amount of DSP read/write function calls (we have 80 per each update) causes some anxiety. Since each 'get/set_dsp_...' call is "the driver call" actually, it causes the OS to switch the user/kernel mode there and back (and this is not really a free of charge procedure). The concern is that such OS and driver tugging may negatively affect some critical driver operations (low-latency ASIO streaming for example). So at some point we'd probably like to see the kX SDK providing a function to read (and optionally write) an array of registers. It's not that the new function will really improve the SA performance (its DSP I/O related CPU load is nothing if compared to the drawing) or (vastly improve) it's I/O timing (as i understand the PCI bus and a hardware itself are the bottlenecks of the driver I/O) but likely it would help to get things a bit more smoothly or a sort of. Well, anyway, the new function won't make things worse by any means.

    -------------------------
    Building:
    * Add the "h" directory of the kX SDK to include directories
    * Add the "lib" directory of the kX SDK to library directories
    * Link to kxapi.lib and gdiplus.lib
    * Compile as non-MFC and non-unicode dll
     
    Last edited: Feb 8, 2009
  13. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    Looks good Max. :)

    Thanks for making the window sizeable (since it uses less CPU with smaller window). :cool:

    Now if it just remembered it's size, and had an always on top option. ;):rofl:
     
  14. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    Îòâåò: Spectrum analyzer possible in DSP?

    >Now if it just remembered it's size, and had an always on top option.

    yeah - this is what i meant with "minor and boring features that a "production" plugin would have" :rofl:
    Well, to be honest i have an update under development - so...
     
  15. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Very nice - I can even load it with the default DSP (10K2 anyway), something I did not expect.

    your skills amaze me. Thank you very much.
     
  16. TravelRec.

    TravelRec. Alternative Audioproductions

    Joined:
    Sep 8, 2003
    Messages:
    1,710
    Likes Received:
    3
    Trophy Points:
    0
    Hello Max M.,

    thank you for the great and useful tool. It is a fine plugin that expands kX-drivers possibilities one more time ;)
     
  17. stylus02

    stylus02 New Member

    Joined:
    Jan 11, 2008
    Messages:
    283
    Likes Received:
    2
    Trophy Points:
    0
    excellent max, great mastering tool. :)
     
  18. edwardar

    edwardar New Member

    Joined:
    Jan 7, 2003
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    0
    I just wanted to thank you too for this - it's amazing what these old soundcards are capable of - what's more amazing is the skill and time put in by the coders of some of these fantastic plugins!
     
  19. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63
    SA.minus updated

    Meanwhile i have updated the SA.minus.

    Changes:
    * Settings are now editable via keyboard shortcuts (press F1 for the list)
    * Display colours are editable via registry (i included several colour schemes for show, but you can craft your own and share it with others)
    * Some cosmetic drawing optimizations (~1.5 times faster with default settings)
    * Other boring stuff here and there (saving window size and position etc. etc.)

    source code
    kxl binary
    screenshot

    Since current kxl source code is a bit cryptic in certain aspects (i'm just lazy to clean it up) - i'll keep the sources of the vanilla kxl available for reference.
     
    Last edited: Feb 8, 2009
    Tyrsonswood likes this.
  20. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    Nice Max, thanks again :)

    The "Change peak hold representation (bar/line)" option (among other things) is a nice touch :cool:

    A note to anyone who might be using my PluginQL addon, this plugin uses one of the same key combos as does PluginQL, and as such you will need to disable the hotkeys in PluginQL in order to save settings in this plugin.
     
    Last edited: Feb 8, 2009

Share This Page

visited