当前位置: 首页>>代码示例>>C++>>正文


C++ Audio::samples方法代码示例

本文整理汇总了C++中Audio::samples方法的典型用法代码示例。如果您正苦于以下问题:C++ Audio::samples方法的具体用法?C++ Audio::samples怎么用?C++ Audio::samples使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Audio的用法示例。


在下文中一共展示了Audio::samples方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: calcStft

//read wav, calc mfcc and write to array
int Stft::calcStft(const Audio &audio, int windowSize, int feedRate)
{
	// calculate dimension / num of columns

  	int fftOrder;
    int i,j;

    // calc fft length => next power of 2
    fftOrder = ceil(logf(windowSize)/logf(2.0f));
    fftLen = 1 << fftOrder;

    NoOfWindows = (audio.length() - (windowSize - feedRate))/feedRate;

#ifdef FFTW
    double *frame_buffer;
    fftw_complex *spectrum;
    fftw_plan p;

    // alloc multidimensional array
    spectrogramm = new Fw32f *[NoOfWindows]; // alloc some pointers ...
    for (int i = 0; i < NoOfWindows ; i++)
        spectrogramm[i] = new Fw32f[fftLen/2]; // ... and alloc an array for each pointer

    // alloc framebuffer for real audio data of each window
    frame_buffer = (double*) fftw_malloc(fftLen * sizeof(double));
    // alloc buffer for calculated complex spectrum of each window
    spectrum = (fftw_complex*) fftw_malloc(fftLen * sizeof(fftw_complex));

    // the real to complex fft plan
    p = fftw_plan_dft_r2c_1d(fftLen, frame_buffer, spectrum, FFTW_ESTIMATE );

  //  Fw64u timeStamp1 = fwGetCpuClocks();
    // pre-calc hamming window
    double* hamming = (double*)malloc(windowSize * sizeof(double));
    for(int i=0; i<windowSize; i++)
        hamming[i] = 1 * (0.54 - 0.46*cos(2*M_PI*i/windowSize));

    // calc FFT for each window
    for (i = j = 0; i + windowSize < audio.length(); i += feedRate, j++) {
        // copy with padding, convert to double and apply hamming window
        // CopyWithHamming(&audio.samples()[i], frame_buffer, fftLen, windowSize);
        CopyConvertAndMultiply(&audio.samples()[i], frame_buffer, hamming, fftLen, windowSize);
        // do fft
        fftw_execute(p); /* repeat as needed */
        //  calc power spectrum => re*re + im*im
        PowerSpectrum(spectrogramm[j], spectrum, fftLen);
    }
    // get timestamp
 //   Fw64u timeStamp2 = fwGetCpuClocks();
 //   cout << (timeStamp2 - timeStamp1)/(2.4*1E9) << endl;

    fftw_destroy_plan(p);
    fftw_free(spectrum);
    fftw_free(frame_buffer);
    free(hamming);

#else  // Intel IPP

    Ipp32f *frame_buffer; // the window buffer
    frame_buffer = ippsMalloc_32f(fftLen);

    // alloc multidimensional array
    spectrogramm = new Ipp32f *[NoOfWindows]; // alloc some pointers ...
    for (int i = 0; i < NoOfWindows ; i++)
        spectrogramm[i] = new Ipp32f[fftLen/2+1]; // ... and alloc an array for each pointer

    // alloc & init fft structure
    IppsFFTSpec_R_32f *pFFTSpec;
	status = ippsFFTInitAlloc_R_32f(&pFFTSpec,
                                    fftOrder,
                                    IPP_FFT_DIV_INV_BY_N, // INV ???????
                                    ippAlgHintFast);

    // alloc temporary complex buffer !
    // Ipp32fc *pTmp = (Ipp32fc*)ippsMalloc_32f((fftLen)+2);
    Ipp32fc *pTmp = ippsMalloc_32fc((fftLen)+2);

    Fw64u timeStamp1 = fwGetCpuClocks();
    // calc FFT for each window
    for (i = j = 0; i + windowSize < audio.length(); i += feedRate, j++)
    {
        // copy WINDOW_SIZE + evtl. PADDING samples into buffer
        ippsCopyWithPadding_32f(&audio.samples()[i], windowSize, frame_buffer, fftLen);

        // Add the hamming window to the input signal
		ippsWinHamming_32f_I(frame_buffer, windowSize);
        //WinHamming_I((double*)frame_buffer, windowSize);

        ippsFFTFwd_RToCCS_32f(frame_buffer, (Ipp32f*)pTmp ,pFFTSpec, 0);
        //
        ippsPowerSpectr_32fc((Ipp32fc*)pTmp, spectrogramm[j], fftLen/2+1);
        //  ippsReal_32fc((Ipp32fc*)pTmp, spectrogramm[j], fftLen/2);        // cout << j << " " << i << endl;
    }
    // get timestamp
    Fw64u timeStamp2 = fwGetCpuClocks();
    cout << (timeStamp2 - timeStamp1)/(2.4*1E9) << endl;

    // free mem
    ippsFree(frame_buffer);
//.........这里部分代码省略.........
开发者ID:viat,项目名称:featurex,代码行数:101,代码来源:Stft.cpp


注:本文中的Audio::samples方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。