Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: TNS Activation Algorithm (Read 4518 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

TNS Activation Algorithm

I implemented the TNS module based on the ISO specs including the Activation criteria which is based on the "Prediction Gain".. However I noticed that in this approach,  sometimes the TNS is switched on for signals that doesn't show any transient!! Could anyone confirm this? I thought that prediction gain is just a measurement of how accurate the predictors could model the spectrals. Would it be possible that some steady state signals could be highly predictable across the frequency domain? (It is of course highly predictable inter-frame)



wkwai

TNS Activation Algorithm

Reply #1
I am not sure if this kind of situation happen, but usually TNS LPC prediction gain is big for non-flat temporal envelopes only.

Usually there are more methods to control TNS activation - you can also calculate pre and post TNS perceptual entropies on the MDCT signal prior and after the TNS module, and measure the bit savings done by TNS.

TNS Activation Algorithm

Reply #2
Yes, I was about to test the bit comparison module of the TNS..

My test signal is a 500 Hz Sine wave. TNS processing starts from 1500 Hz to the max.  What happened is that the MDCT spectral of the pure Sine wave isn't just a single coefficient as it should be in pure theory, but there is some "smearing" into the higher frequencies range. It's spectrals isn't compact enough.  Predicting these "extra (flat)" spectral components results in a very high prediction gain. TNS is triggered.

According to the theory I have, prediction across spectral component would result in high coding gain if the temporal envelope is "flat". But this doesn't necessary mean that when there is a high coding gain, there is a transient??  How does the prediction gain have anything to do with transient?  In some cases of transient, the prediction gain is low and the TNS is disabled?? 

TNS Activation Algorithm

Reply #3
Interesting - I am working on the TNS algorithm right now  Although in some other areas apart from triggering.

Your problem could be solved with the method I already described - you need to calculate the TNS band PE - and then calculate the actual bit savings you might get with the TNS - and use this as additional trigger condition.

This way, you might eliminate the "false positives" like the case you described. In some cases TNS might not give any advantage and it would only waste bits useful for the spectral bit allocation.

The only problem is that you are going to increase the complexity of the analysis function if you implement the PE based approach.  I think that it might be possible to derive the PE change directly with some approximation formula.

TNS Activation Algorithm

Reply #4
Hmm - I tried my TNS implementation with your test case (500 Hz, and 4000 Hz) and it never estimated gain bigger than ~1.20  which is usually well below ISO switching criteria (1.4 in the standard IIRC).

Perhaps I chose the wrong way of testing, or your implementation might have some bug?

TNS Activation Algorithm

Reply #5
Maybe there might be a bug.. I will try to study  this problem further..
Where is your frequency range  for  Levinson Durbin Calculation? If I start from 0Hz to max, the TNS would not trigger.

Another issue.. I thought about this TNS concept and from my overall understanding, TNS NEVER result in final coding gain because the Mask2Signal ratio is weighted by the mdct spectrals after the TNS module..
 

      PsychoacustioModel ( Mask2Signal)
      TNS(mdct)
      Weighting(Mask2Signal, mdct)
      .....
      ......

I think there was an earlier question in this forum whether if TNS is saving bits or not? Thinking of it again, it never save bits.. Though there is a prediction gain, the Mask is actually readjusted to a new lower level after TNS processing.. So TNS is used to preserved some aspect of the spectrals which would be destroyed in normal quantization but will always result in extra overhead bits.

TNS Activation Algorithm

Reply #6
Quote
Maybe there might be a bug.. I will try to study this problem further..
Where is your frequency range for Levinson Durbin Calculation? If I start from 0Hz to max, the TNS would not trigger.


TNS LPC frequency range is calculated dynamically, depending on the signal statistics and coding gain.

Starting from 0Hz is definitely not a wise idea - limitation to at least 1.5 kHz is desired.

Quote
Another issue.. I thought about this TNS concept and from my overall understanding, TNS NEVER result in final coding gain because the Mask2Signal ratio is weighted by the mdct spectrals after the TNS module..


PsychoacustioModel ( Mask2Signal)
TNS(mdct)
Weighting(Mask2Signal, mdct)


That heavily depends on implementation.  One of the solution is to measure PE in the TNS module by the following way:

pre_tns_percep_entropy = SUM (  pre_tns_mdct_nrg / pre_tns_mask_thresh )
post_tnc_pecrep_entropy = SUM ( post_tns_mdct_nrg / pre_tns_mask_thresh )

Actual MDCT energy reduction is:  pre_tns_entropy / post_tns_entropy - You will find out that it is highly correlated with the LPC gain, although  sometimes it is not correlated (i.e. gain is very big, say >5.0  but the energy reduction is minimal)

Of course, later there is a step of modification of the masking thresholds depending on TNS, but what you get later is quiter signal without transient which is much easier to code - i.e. - it does not require overcoding.

Quote
I think there was an earlier question in this forum whether if TNS is saving bits or not? Thinking of it again, it never save bits.. Though there is a prediction gain, the Mask is actually readjusted to a new lower level after TNS processing.. So TNS is used to preserved some aspect of the spectrals which would be destroyed in normal quantization but will always result in extra overhead bits.


That is also dependent on the implementation - recalculating masking levels on new energy without any modification might not be a wise idea since you overcode - but in reality, TNS saves bits because it eliminates big peaks (surges) in energy and gives quiter signal.

TNS Activation Algorithm

Reply #7
Quote
pre_tns_percep_entropy = SUM (  pre_tns_mdct_nrg / pre_tns_mask_thresh )
post_tnc_pecrep_entropy = SUM ( post_tns_mdct_nrg / pre_tns_mask_thresh )

This formula is only correct if you do the Mask weighting before the TNS module. This would result in coding gain. However, the ISO reference code shows that the weighting is done after TNS! So there couldn't be any coding gain. 

TNS Activation Algorithm

Reply #8
Quote
This formula is only correct if you do the Mask weighting before the TNS module. This would result in coding gain. However, the ISO reference code shows that the weighting is done after TNS! So there couldn't be any coding gain. 


What is done in the ISO reference code does not matter it should be done in all implementations

Anyway, my point is - that if there is PE reduction as I described above, the TNS definitely is usable at that range - if the result is otherwise,  it might seem that TNS is going to introduce more artifacts.