Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Erik
Beginner
90 Views

Init VS InitAlloc (specifically the IIR ones)

I believe for the best performance I need to use IIRInit to initialize my State (instead of IIRInitAlloc), along with that I will of course have to allocate a buffer of the size specified by ippsIIRGetStateSize. What I am unsure about is where does State get allocated. In the IPP Reference Manual Volume 1, IIRInit is defined as "Initializes an arbitrary IIR filter state.". Reading the Description it makes no mention that the function will create the State but just copy the taps into the State. Looking at the Parameters description for ppState mentions creation of the State. So I am confused by that.
1. So does IIRInit need the state to be already allocated?

2. If IIRInit does allocate State is it safe to call IIRFree on a State alloced by IIRInit?
In IIRFree's documentation in the Reference Manual it only makes mention of freeing a state allocated by IIRInitAlloc(or the _BiQuad version).

3. Is my assumption correct that to get the best performance I need to use IIRInit instead of IIRInitAlloc?

Thank you for any answers or information.
0 Kudos
4 Replies
Vladimir_Dudnik
Employee
90 Views

Hello,

Why don't you look at IPP documentation?

IPP manual, volume 1. Chapter 6 IIR Filter Functions, page 6-94

To initialize and use an IIR filter, follow this general scheme:

  1. Call ippsIIRInitAlloc to allocate memory and initialize the filter as an arbitrary
    order IIR filter, or call ippsIIRInitAlloc_BiQuad to allocate memory and initialize
    the filter as a cascade of biquads.
    Or alternatively call either ippsIIRInit to initialize the filter as an arbitrary order IIR
    filter in the external buffer, or ippsIIRInit_BiQuad to initialize the filter as a cascade
    of biquads in the external buffer. Size of the buffer can be computed by calling the
    functions ippsIIRGetStateSize or ippsIIRGetStateSize_BiQuad, respectively.
  2. Call ippsIIROne repeatedly to filter a single sample through an IIR filter or call
    ippsIIR to filter consecutive samples at once.
  3. Call ippsIIRGetDlyLine and ippsIIRSetDlyLine to get and set the delay line
    values in the IIR state structure.
  4. Call ippsIIRSetTaps to set new tap values in the previously initialized filter state
    structure.
  5. After all filtering is complete, call ippsIIRFree to release dynamic memory associated
    with the filter state structure created by ippsIIRInitAlloc or
    ippsIIRInitAlloc_BiQuad.
    Alternatively, you may use the direct version of the functions. These functions perform
    filtering without initializing the filter state structure. All required parameters are directly set
    in the function.

Regards,
Vladimir

Erik
Beginner
90 Views

I have looked at the manual at the exact section you mentioned, in my post I even quoted from the manual.

I can infer an answer to my 1st question that when using IIRInit and having to use ippsIIRGetStateSize the State will be in the memory allocated with the result from GetStateSize. I can also assume that for question 2 that it is not safe to call IIRFree on a State created with IIRInit. The Reference manual could be much more explicit in the usage of IIRInit and IIRGetStateSize instead of requiring the reader to make guesses at their usage. I would prefer to not make guesses at code I develop and that is what drove me to post my questions.

As for my 3rd question the Manual makes no attempt at suggesting a difference in IIRInit and IIRInitAlloc and why one would use one over the other.

Thanks for trying to help Vladimir but I was well aware of the material you posted.
Vladimir_Dudnik
Employee
90 Views

In IPP for some function family we provide two approaches, the first, function allocate memory internally, which not always might be what customer wants and second when you can allocate memory by your own way (might be important for example in kernel mode drivers). For the second case, we provide function which tell you how many memory you need to allocate and also function which initialise that memory block. Of course it is your responisbility to free that memory by appropriate function (CRT free() if you use malloc() or delete if you use new or whatever)

Regards,
Vladimir

Erik
Beginner
90 Views

Thank you for your input.
Reply