void bob::ap::Ceps::operator()(const blitz::Array<double,1>& input, blitz::Array<double,2>& ceps_matrix) { // Get expected dimensionality of output array blitz::TinyVector<int,2> feature_shape = bob::ap::Ceps::getShape(input); // Check dimensionality of output array bob::core::array::assertSameShape(ceps_matrix, feature_shape); int n_frames=feature_shape(0); int shift_frame=0; double last_frame_elem=0; // Create the holder for the previous frame and make sure it's the same as the current frame // Used by SSFC features computation blitz::Array<double,1> _prev_frame_d; _prev_frame_d.resize(m_cache_frame_d.shape()); // Create the temporary holder for SSFC features computation blitz::Array<double,1> _temp_frame_d; _temp_frame_d.resize(m_cache_frame_d.shape()); if (m_ssfc_features) { //we are going to always process the next frame within the loop shift_frame = 1; // Init the first frame to the input extractNormalizeFrame(input, 0, _prev_frame_d); // Apply pre-emphasis pre_emphasis(_prev_frame_d, last_frame_elem); // Apply the Hamming window hammingWindow(_prev_frame_d); // Take the power spectrum of the first part of the FFT powerSpectrumFFT(_prev_frame_d); } blitz::Range r1(0,m_n_ceps-1); for (int i=0; i<n_frames; ++i) { // Init the current frame from the input, we process (i+1)th frame for SSFC features extractNormalizeFrame(input, i+shift_frame, m_cache_frame_d); // Update output with energy if required if (m_with_energy) ceps_matrix(i,(int)m_n_ceps) = logEnergy(m_cache_frame_d); // Apply pre-emphasis pre_emphasis(m_cache_frame_d, last_frame_elem); // Apply the Hamming window hammingWindow(m_cache_frame_d); // Take the power spectrum of the first part of the FFT // Note that after this call, we only operate on the first half of m_cache_frame_d array. The second half is ignored. // powerSpectrumFFT changes first half+1 elements of m_cache_frame_d array powerSpectrumFFT(m_cache_frame_d); if (m_ssfc_features) { // retrieve the previous frame into our temp _temp_frame_d = _prev_frame_d; // remember the current frame for the next round, before we change current frame _prev_frame_d = m_cache_frame_d; // Computation of SSFC features: // We take the previous frame and find the difference between values of current and previous frames m_cache_frame_d -= _temp_frame_d; // We compute norm2 for the difference as per SSFC features m_cache_frame_d = blitz::pow2(m_cache_frame_d); // Then, we can apply the filter and DCT later on } // Filter with triangular or rectangular filter bank (either in linear or Mel domain) filterBank(m_cache_frame_d); // Apply DCT kernel and update the output blitz::Array<double,1> ceps_matrix_row(ceps_matrix(i,r1)); if (m_scfc_features) // do not apply DCT on SCFC features ceps_matrix_row = m_cache_filters(r1); else applyDct(ceps_matrix_row); } //compute the center of the cut-off frequencies const int n_coefs = (m_with_energy ? m_n_ceps + 1 : m_n_ceps); blitz::Range rall = blitz::Range::all(); blitz::Range ro0(0,n_coefs-1); blitz::Range ro1(n_coefs,2*n_coefs-1); blitz::Range ro2(2*n_coefs,3*n_coefs-1); if (m_with_delta) { blitz::Array<double,2> ceps_matrix_0(ceps_matrix(rall,ro0)); blitz::Array<double,2> ceps_matrix_1(ceps_matrix(rall,ro1)); addDerivative(ceps_matrix_0, ceps_matrix_1); if (m_with_delta_delta) { blitz::Array<double,2> ceps_matrix_2(ceps_matrix(rall,ro2)); addDerivative(ceps_matrix_1, ceps_matrix_2); } } }
void VStreamsUnit::_testReadOnlyStream() { // Test read-only memory streams. // Multiple streams can share a buffer; no shared i/o state between them; none deletes the buffer. // The scope here forces destruction, which would crash if one of the streams tried to delete the buffer. // First we'll fill it with 4 integer values to be verified by reading via streams. Vu8 readOnlyBuffer[16]; /* local scope */ { VMemoryStream initializer(readOnlyBuffer, VMemoryStream::kAllocatedOnStack, false, 16, 0); VBinaryIOStream initializerIO(initializer); initializerIO.writeS32(1); initializerIO.writeS32(2); initializerIO.writeS32(3); initializerIO.writeS32(4); } // Now we'll create 3 read-only streams using that buffer that we've initialized. VReadOnlyMemoryStream r1(readOnlyBuffer, 16); VBinaryIOStream ro1(r1); VReadOnlyMemoryStream r2(readOnlyBuffer, 16); VBinaryIOStream ro2(r2); VReadOnlyMemoryStream r3(readOnlyBuffer, 16); VBinaryIOStream ro3(r3); // Now we'll read in an interleaved fashion, testing that each reader sees the full sequence of bytes. VUNIT_ASSERT_EQUAL_LABELED(ro1.readS32(), 1, "ro1 1"); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 1, "ro2 1"); VUNIT_ASSERT_EQUAL_LABELED(ro3.readS32(), 1, "ro3 1"); VUNIT_ASSERT_EQUAL_LABELED(ro1.readS32(), 2, "ro1 2"); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 2, "ro2 2"); VUNIT_ASSERT_EQUAL_LABELED(ro3.readS32(), 2, "ro3 2"); VUNIT_ASSERT_EQUAL_LABELED(ro1.readS32(), 3, "ro1 3"); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 3, "ro2 3"); VUNIT_ASSERT_EQUAL_LABELED(ro3.readS32(), 3, "ro3 3"); VUNIT_ASSERT_EQUAL_LABELED(ro1.readS32(), 4, "ro1 4"); // Briefly test a couple of seeks and reads backward in the stream. ro2.seek(-8, SEEK_CUR); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 2, "ro2 2 after seek"); VUNIT_ASSERT_EQUAL_LABELED(ro3.readS32(), 4, "ro3 4"); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 3, "ro2 3"); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 4, "ro2 4"); // Now that we're at the presumed EOF, verify that a read will throw EOF. try { (void) ro1.readS32(); VUNIT_ASSERT_FAILURE("EOF was not thrown on read past EOF"); } catch (const VEOFException& /*ex*/) { VUNIT_ASSERT_SUCCESS("EOF thrown on read past EOF"); } // Verify that the EOF exception does not affect that or any other reader. ro2.seek(-4, SEEK_CUR); VUNIT_ASSERT_EQUAL_LABELED(ro2.readS32(), 4, "ro2 4"); ro1.seek(-8, SEEK_CUR); VUNIT_ASSERT_EQUAL_LABELED(ro1.readS32(), 3, "ro1 3"); // Verify that any attempt to write will throw EOF, regardless of io offset. ro3.seek0(); // go back to start of stream try { ro3.writeS32(1); VUNIT_ASSERT_FAILURE("EOF was not thrown on writing to a read-only stream"); } catch (const VEOFException& /*ex*/) { VUNIT_ASSERT_SUCCESS("EOF thrown on writing to a read-only stream"); } }