| 207 | typename FFT_FUNC |
| 208 | > |
| 209 | auto stft_impl ( |
| 210 | const matrix_exp<EXP>& signal, |
| 211 | const WINDOW& w, |
| 212 | std::size_t fftsize, |
| 213 | std::size_t wlen, |
| 214 | std::size_t hoplen, |
| 215 | const FFT_FUNC& fft_obj |
| 216 | ) |
| 217 | { |
| 218 | using T = typename EXP::type; |
| 219 | using R = remove_complex_t<T>; |
| 220 | using C = add_complex_t<T>; |
| 221 | |
| 222 | static_assert(std::is_floating_point<R>::value, "underlying type must be real or complex floating point type"); |
| 223 | DLIB_ASSERT(is_vector(signal), "input must be a vector type"); |
| 224 | DLIB_ASSERT(signal.size() >= (long)wlen, "signal.size() >= wlen not satisfied"); |
| 225 | DLIB_ASSERT(fftsize >= wlen, "fftsize >= wlen not satisfied"); |
| 226 | DLIB_ASSERT(wlen >= hoplen, "wlen >= hoplen not satisfied"); |
| 227 | |
| 228 | // Input is left-padded by wlen/2 and right-padded wlen/2 |
| 229 | const std::size_t total_padding = wlen; |
| 230 | const std::size_t overlap = wlen - hoplen; |
| 231 | const std::size_t nframes = (signal.size() + total_padding - overlap) / hoplen; |
| 232 | matrix<C> stft = zeros_matrix<C>(nframes, |
| 233 | FFT_FUNC::freqsize(fftsize)); |
| 234 | matrix<R> win(1,wlen); |
| 235 | for (std::size_t i = 0 ; i < wlen ; ++i) |
| 236 | win(0, i) = w(i, wlen); |
| 237 | |
| 238 | // TODO: reduce extra buffers, e.g. padded |
| 239 | matrix<T> padded; |
| 240 | |
| 241 | if (is_row_vector(signal)) |
| 242 | padded = join_rows(join_rows(zeros_matrix<T>(1, wlen/2), signal), zeros_matrix<T>(1, wlen/2)); |
| 243 | else |
| 244 | padded = join_rows(join_rows(zeros_matrix<T>(1, wlen/2), trans(signal)), zeros_matrix<T>(1, wlen/2)); |
| 245 | |
| 246 | for (long i = 0 ; i < stft.nr() ; ++i) |
| 247 | { |
| 248 | set_rowm(stft, i) = fft_obj(join_rows(pointwise_multiply(win, subm(padded, 0, i*hoplen, 1, wlen)), |
| 249 | zeros_matrix<T>(1, fftsize - wlen))); |
| 250 | } |
| 251 | |
| 252 | return stft; |
| 253 | } |
| 254 | |
| 255 | template < |
| 256 | typename ReturnType, |
no test coverage detected