File: comp_filterbankreassign.cc

package info (click to toggle)
octave-ltfat 2.3.1%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,712 kB
  • sloc: ansic: 30,379; cpp: 8,808; java: 1,499; objc: 345; makefile: 248; xml: 182; python: 124; sh: 18; javascript: 12
file content (147 lines) | stat: -rw-r--r-- 4,827 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#define TYPEDEPARGS 0
#define MATCHEDARGS 1, 2
#define SINGLEARGS
#define COMPLEXINDEPENDENT
#define OCTFILENAME comp_filterbankreassign // change to filename
#define OCTFILEHELP "Computes reassigned filterbank spectrogram.\n\
Usage: sr=comp_filterbankreassign(s,itime,ifreq,a,cfreq);\n\
Yeah."


#include "ltfat_oct_template_helper.h"
/*
   gabreassign forwarders
   */

    static inline void
fwd_filterbankreassign(const double *s[], const double *tgrad[], const double *fgrad[],
         ltfat_int N[],  double a[],  double cfreq[],
        const ltfat_int M, double *sr[], fbreassOptOut* optout)
{
    ltfat_filterbankreassign_d(s, tgrad, fgrad, N, a, cfreq, M, sr, REASS_DEFAULT, optout);
}

    static inline void
fwd_filterbankreassign(const float *s[], const float *tgrad[], const float *fgrad[],
         ltfat_int N[],  double a[],  double cfreq[],
        const ltfat_int M, float *sr[], fbreassOptOut* optout)
{
    ltfat_filterbankreassign_s(s, tgrad, fgrad, N, a, cfreq, M, sr, REASS_DEFAULT, optout);
}

    static inline void
fwd_filterbankreassign(const Complex *s[], const double *tgrad[], const double *fgrad[],
         ltfat_int N[],  double a[],  double cfreq[],
        const ltfat_int M, Complex *sr[], fbreassOptOut* optout)
{
    ltfat_filterbankreassign_dc(reinterpret_cast<const ltfat_complex_d **>(s),
            tgrad, fgrad, N, a, cfreq, M,
            reinterpret_cast<ltfat_complex_d **>(sr),
            REASS_DEFAULT, optout);
}

    static inline void
fwd_filterbankreassign(const FloatComplex *s[], const float *tgrad[], const float *fgrad[],
         ltfat_int N[],  double a[],  double cfreq[],
        const ltfat_int M, FloatComplex *sr[], fbreassOptOut* optout)
{
    ltfat_filterbankreassign_sc(reinterpret_cast<const ltfat_complex_s **>(s),
            tgrad, fgrad, N, a, cfreq, M,
            reinterpret_cast<ltfat_complex_s **>(sr),
            REASS_DEFAULT, optout);
}

template <class LTFAT_TYPE, class LTFAT_REAL, class LTFAT_COMPLEX>
    octave_value_list
octFunction(const octave_value_list& args, int nargout)
{
    DEBUGINFO;
    Cell sCell      = args(0).cell_value();
    Cell tgradCell  = args(1).cell_value();
    Cell fgradCell  = args(2).cell_value();
    Matrix aMat     = args(3).matrix_value();
    Matrix cfreqMat = args(4).matrix_value();

    const ltfat_int M  = (ltfat_int) sCell.numel();


    OCTAVE_LOCAL_BUFFER (ltfat_int, NPtr, M);
    OCTAVE_LOCAL_BUFFER (double, aPtr, M);
    OCTAVE_LOCAL_BUFFER (const LTFAT_TYPE*, sPtr, M);
    OCTAVE_LOCAL_BUFFER (const LTFAT_REAL*, tgradPtr, M);
    OCTAVE_LOCAL_BUFFER (const LTFAT_REAL*, fgradPtr, M);
    OCTAVE_LOCAL_BUFFER (LTFAT_TYPE*, srPtr, M);

    OCTAVE_LOCAL_BUFFER (MArray<LTFAT_TYPE>, s_elems, M);
    OCTAVE_LOCAL_BUFFER (MArray<LTFAT_REAL>, tgrad_elems, M);
    OCTAVE_LOCAL_BUFFER (MArray<LTFAT_REAL>, fgrad_elems, M);
    OCTAVE_LOCAL_BUFFER (MArray<LTFAT_TYPE>, sr_elems, M);

    for (octave_idx_type m = 0; m < M; ++m)
    {
        s_elems[m] = ltfatOctArray<LTFAT_TYPE>(sCell.elem(m));
        tgrad_elems[m] = ltfatOctArray<LTFAT_REAL>(tgradCell.elem(m));
        fgrad_elems[m] = ltfatOctArray<LTFAT_REAL>(fgradCell.elem(m));

        sPtr[m] = s_elems[m].data();
        tgradPtr[m] = tgrad_elems[m].data();
        fgradPtr[m] = fgrad_elems[m].data();
        NPtr[m] = s_elems[m].rows();

        sr_elems[m] = MArray<LTFAT_TYPE>(dim_vector(NPtr[m], 1));
        srPtr[m] = sr_elems[m].fortran_vec();
        aPtr[m] = aMat(m);
    }
    octave_value_list retlist;

    fbreassOptOut* optout = NULL;
    Cell repos;
    octave_idx_type sumN = 0;
    if (nargout > 1)
    {
        for (octave_idx_type ii = 0; ii < M; ii++) sumN += NPtr[ii];

        repos = Cell(dim_vector(sumN, 1));
        optout = fbreassOptOut_init(sumN, 16 );
    }

    // Adjust a
    if (aMat.columns() > 1)
    {
        for (octave_idx_type m = 0; m < M; ++m)
        {
            aPtr[m] /= aMat(m + M);
        }
    }

    fwd_filterbankreassign(sPtr, tgradPtr, fgradPtr, NPtr, aPtr, cfreqMat.fortran_vec(), M,
            srPtr, optout);

    // Output cell
    Cell srCell(dim_vector(M, 1));
    for (octave_idx_type m = 0; m < M; ++m)
    {
        srCell.elem(m) = sr_elems[m];
    }
    retlist(0) = srCell;


    if (nargout > 1)
    {
        for (ltfat_int ii = 0; ii < sumN; ii++)
        {
            octave_idx_type l = optout->reposl[ii];
            MArray<double> cEl = MArray<double>(dim_vector(l, l > 0 ? 1 : 0));
            double* cElPtr = cEl.fortran_vec();
            for (octave_idx_type jj = 0; jj < optout->reposl[ii]; jj++)
            {
                cElPtr[jj] = static_cast<double>(optout->repos[ii][jj]) + 1.0;
            }
            repos.elem(ii) = cEl;
        }

        retlist(1) = repos;
        fbreassOptOut_destroy(optout);
    }
    return retlist;
}