17.01.2013 Views

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

musicdsp.org source code archive - WSInf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Look ahead limiting (click this to go back to the index)<br />

References : Posted by Wilfried Welti<br />

Notes :<br />

use add_value with all values which enter the look-ahead area,<br />

and remove_value with all value which leave this area. to get<br />

the maximum value in the look-ahead area, use get_max_value.<br />

in the very beginning initialize the table with zeroes.<br />

If you always want to know the maximum amplitude in<br />

your look-ahead area, the thing becomes a sorting<br />

problem. very primitive approach using a look-up table<br />

Code :<br />

void lookup_add(unsigned section, unsigned size, unsigned value)<br />

{<br />

if (section==value)<br />

lookup[section]++;<br />

else<br />

{<br />

size >>= 1;<br />

if (value>section)<br />

{<br />

lookup[section]++;<br />

lookup_add(section+size,size,value);<br />

}<br />

else<br />

lookup_add(section-size,size,value);<br />

}<br />

}<br />

void lookup_remove(unsigned section, unsigned size, unsigned value)<br />

{<br />

if (section==value)<br />

lookup[section]--;<br />

else<br />

{<br />

size >>= 1;<br />

if (value>section)<br />

{<br />

lookup[section]--;<br />

lookup_remove(section+size,size,value);<br />

}<br />

else<br />

lookup_remove(section-size,size,value);<br />

}<br />

}<br />

unsigned lookup_getmax(unsigned section, unsigned size)<br />

{<br />

unsigned max = lookup[section] ? section : 0;<br />

size >>= 1;<br />

if (size)<br />

if (max)<br />

{<br />

max = lookup_getmax((section+size),size);<br />

if (!max) max=section;<br />

}<br />

else<br />

max = lookup_getmax((section-size),size);<br />

return max;<br />

}<br />

void add_value(unsigned value)<br />

{<br />

lookup_add(LOOKUP_VALUES>>1, LOOKUP_VALUES>>1, value);<br />

}<br />

void remove_value(unsigned value)<br />

{<br />

lookup_remove(LOOKUP_VALUES>>1, LOOKUP_VALUES>>1, value);<br />

}<br />

unsigned get_max_value()<br />

{<br />

return lookup_getmax(LOOKUP_VALUES>>1, LOOKUP_VALUES>>1);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!