History

lavu/tx: add DCT-III implementation

Lynne committed 3 years ago

Commit a56d7e01 parent 504b7be1 file · +70 −2Browse files

Unified · Split

libavutil/tx_template.c+70−2
@@ -1737,6 +1737,11 @@ static av_cold int TX_NAME(ff_tx_dct_init)(AVTXContext *s, · 1736 unmodified lines
17371737 TXSample *tab;
17381738 SCALE_TYPE rsc = *((SCALE_TYPE *)scale);
17391739
1740+ if (inv) {
1741+ len *= 2;
1742+ s->len *= 2;
1743+ rsc *= 0.5;
1744+ }
17401745
17411746 if ((ret = ff_tx_init_subtx(s, TX_TYPE(RDFT), flags, NULL, len, inv, &rsc)))
17421747 return ret;
@@ -1752,8 +1757,13 @@ static av_cold int TX_NAME(ff_tx_dct_init)(AVTXContext *s, · 9 unmodified lines
17521757 for (int i = 0; i < len; i++)
17531758 tab[i] = RESCALE(cos(i*freq)*(!inv + 1));
17541759
1755− for (int i = 0; i < len/2; i++)
1756− tab[len + i] = RESCALE(cos((len - 2*i - 1)*freq));
1760+ if (inv) {
1761+ for (int i = 0; i < len/2; i++)
1762+ tab[len + i] = RESCALE(0.5 / sin((2*i + 1)*freq));
1763+ } else {
1764+ for (int i = 0; i < len/2; i++)
1765+ tab[len + i] = RESCALE(cos((len - 2*i - 1)*freq));
1766+ }
17571767
17581768 return 0;
17591769 }
@@ -1818,6 +1828,49 @@ static void TX_NAME(ff_tx_dctII)(AVTXContext *s, void *_dst, · 58 unmodified lines
18181828 dst[1] = next;
18191829 }
18201830
1831+static void TX_NAME(ff_tx_dctIII)(AVTXContext *s, void *_dst,
1832+ void *_src, ptrdiff_t stride)
1833+{
1834+ TXSample *dst = _dst;
1835+ TXSample *src = _src;
1836+ const int len = s->len;
1837+ const int len2 = len >> 1;
1838+ const TXSample *exp = (void *)s->exp;
1839+#ifdef TX_INT32
1840+ int64_t tmp1, tmp2 = src[len - 1];
1841+ tmp2 = (2*tmp2 + 0x40000000) >> 31;
1842+#else
1843+ TXSample tmp1, tmp2 = 2*src[len - 1];
1844+#endif
1845+
1846+ src[len] = tmp2;
1847+
1848+ for (int i = len - 2; i >= 2; i -= 2) {
1849+ TXSample val1 = src[i - 0];
1850+ TXSample val2 = src[i - 1] - src[i + 1];
1851+
1852+ CMUL(src[i + 1], src[i], exp[len - i], exp[i], val1, val2);
1853+ }
1854+
1855+ s->fn[0](&s->sub[0], dst, src, sizeof(float));
1856+
1857+ for (int i = 0; i < len2; i++) {
1858+ TXSample in1 = dst[i];
1859+ TXSample in2 = dst[len - i - 1];
1860+ TXSample c = exp[len + i];
1861+
1862+ tmp1 = in1 + in2;
1863+ tmp2 = in1 - in2;
1864+ tmp2 *= c;
1865+#ifdef TX_INT32
1866+ tmp2 = (tmp2 + 0x40000000) >> 31;
1867+#endif
1868+
1869+ dst[i] = tmp1 + tmp2;
1870+ dst[len - i - 1] = tmp1 - tmp2;
1871+ }
1872+}
1873+
18211874 static const FFTXCodelet TX_NAME(ff_tx_dctII_def) = {
18221875 .name = TX_NAME_STR("dctII"),
18231876 .function = TX_NAME(ff_tx_dctII),
@@ -1832,6 +1885,20 @@ static const FFTXCodelet TX_NAME(ff_tx_dctII_def) = { · 8 unmodified lines
18321885 .prio = FF_TX_PRIO_BASE,
18331886 };
18341887
1888+static const FFTXCodelet TX_NAME(ff_tx_dctIII_def) = {
1889+ .name = TX_NAME_STR("dctIII"),
1890+ .function = TX_NAME(ff_tx_dctIII),
1891+ .type = TX_TYPE(DCT),
1892+ .flags = AV_TX_UNALIGNED | AV_TX_INPLACE |
1893+ FF_TX_OUT_OF_PLACE | FF_TX_INVERSE_ONLY,
1894+ .factors = { 2, TX_FACTOR_ANY },
1895+ .min_len = 2,
1896+ .max_len = TX_LEN_UNLIMITED,
1897+ .init = TX_NAME(ff_tx_dct_init),
1898+ .cpu_flags = FF_TX_CPU_FLAGS_ALL,
1899+ .prio = FF_TX_PRIO_BASE,
1900+};
1901+
18351902 int TX_TAB(ff_tx_mdct_gen_exp)(AVTXContext *s, int *pre_tab)
18361903 {
18371904 int off = 0;
@@ -1920,6 +1987,7 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] = { · 82 unmodified lines
19201987 &TX_NAME(ff_tx_rdft_r2c_def),
19211988 &TX_NAME(ff_tx_rdft_c2r_def),
19221989 &TX_NAME(ff_tx_dctII_def),
1990+ &TX_NAME(ff_tx_dctIII_def),
19231991
19241992 NULL,
19251993 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t