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
1737 TXSample *tab;1737 TXSample *tab;
1738 SCALE_TYPE rsc = *((SCALE_TYPE *)scale);1738 SCALE_TYPE rsc = *((SCALE_TYPE *)scale);
1739 1739
1740 if (inv) {
1741 len *= 2;
1742 s->len *= 2;
1743 rsc *= 0.5;
1744 }
1740 1745
1741 if ((ret = ff_tx_init_subtx(s, TX_TYPE(RDFT), flags, NULL, len, inv, &rsc)))1746 if ((ret = ff_tx_init_subtx(s, TX_TYPE(RDFT), flags, NULL, len, inv, &rsc)))
1742 return ret;1747 return ret;
@@ -1752,8 +1757,13 @@ static av_cold int TX_NAME(ff_tx_dct_init)(AVTXContext *s, · 9 unmodified lines
1752 for (int i = 0; i < len; i++)1757 for (int i = 0; i < len; i++)
1753 tab[i] = RESCALE(cos(i*freq)*(!inv + 1));1758 tab[i] = RESCALE(cos(i*freq)*(!inv + 1));
1754 1759
1755 for (int i = 0; i < len/2; i++)1760 if (inv) {
1756 tab[len + i] = RESCALE(cos((len - 2*i - 1)*freq));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 }
1757 1767
1758 return 0;1768 return 0;
1759}1769}
@@ -1818,6 +1828,49 @@ static void TX_NAME(ff_tx_dctII)(AVTXContext *s, void *_dst, · 58 unmodified lines
1818 dst[1] = next;1828 dst[1] = next;
1819}1829}
1820 1830
1831static 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
1821static const FFTXCodelet TX_NAME(ff_tx_dctII_def) = {1874static const FFTXCodelet TX_NAME(ff_tx_dctII_def) = {
1822 .name = TX_NAME_STR("dctII"),1875 .name = TX_NAME_STR("dctII"),
1823 .function = TX_NAME(ff_tx_dctII),1876 .function = TX_NAME(ff_tx_dctII),
@@ -1832,6 +1885,20 @@ static const FFTXCodelet TX_NAME(ff_tx_dctII_def) = { · 8 unmodified lines
1832 .prio = FF_TX_PRIO_BASE,1885 .prio = FF_TX_PRIO_BASE,
1833};1886};
1834 1887
1888static 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
1835int TX_TAB(ff_tx_mdct_gen_exp)(AVTXContext *s, int *pre_tab)1902int TX_TAB(ff_tx_mdct_gen_exp)(AVTXContext *s, int *pre_tab)
1836{1903{
1837 int off = 0;1904 int off = 0;
@@ -1920,6 +1987,7 @@ const FFTXCodelet * const TX_NAME(ff_tx_codelet_list)[] = { · 82 unmodified lines
1920 &TX_NAME(ff_tx_rdft_r2c_def),1987 &TX_NAME(ff_tx_rdft_r2c_def),
1921 &TX_NAME(ff_tx_rdft_c2r_def),1988 &TX_NAME(ff_tx_rdft_c2r_def),
1922 &TX_NAME(ff_tx_dctII_def),1989 &TX_NAME(ff_tx_dctII_def),
1990 &TX_NAME(ff_tx_dctIII_def),
1923 1991
1924 NULL,1992 NULL,
1925};1993};

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