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


C++ Annotation::getTargetEnd方法代码示例

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


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

示例1: pitch_track

static bool pitch_track(Annotation &ann, get_f0_session *session)
{
    QString p = ann.getAudioPath();
    if (p.isEmpty())
        return false;

    SF_INFO sfinfo;
    SNDFILE *sndfile = sf_open(p.toUtf8().constData(), SFM_READ, &sfinfo);
    if (sndfile == 0)
        return false;
    sf_close(sndfile);

    double fend = ((double) sfinfo.frames) / sfinfo.samplerate;
    double beg = ann.getTargetStart() - 0.5;
    double end = ann.getTargetEnd() + 0.5;
    if (beg < 0.0)
        beg = 0.0;
    if (end > fend)
        end = fend;

    QVector<float> v;
    get_f0(p.toUtf8().constData(), session, beg, end, callback, &v);

    double t0 = ann.getTargetStart() - beg;
    double step = (ann.getTargetEnd() - ann.getTargetStart()) / 29.0;
    QVector<float> pitch_sample;
    for (int i=0; i < 30; ++i) {
        double t = t0 + step * i;
        double x = t / session->par->frame_step;
        double x1 = floor(x);
        double x2 = ceil(x);
        double x0 = x1 - 1.0;
        double x3 = x2 + 1.0;
        int i0 = int(x0) * 2;
        int i1 = int(x1) * 2;
        int i2 = int(x2) * 2;
        int i3 = int(x3) * 2;
        float vp0 = i0 >= 0 ? v.at(i0+1) : 0.0;
        float vp1 = v.at(i1+1);
        float vp2 = v.at(i2+1);
        float vp3 = i3 < 60 ? v.at(i3+1) : 0.0;
        double y;

        if (vp1 < 0.5) {
            // x1 unvoiced
            if (vp2 < 0.5) {
                // x1, x2 unvoiced
                y = -1.0;
            }
            else {
                // x1 unvoiced, x2 voiced
                if (x - x1 < 0.5) {
                    // x is closer to unvoiced x1
                    y = -1.0;
                }
                else {
                    // x is closer to voiced x2
                    if (vp3 < 0.5) {
                        // x3 is unvoiced or ob
                        y = v.at(i2);
                    }
                    else {
                        // x3 is voiced
                        // extrapolate with x2 and x3
                        int y2 = v.at(i2);
                        int y3 = v.at(i3);
                        y = (x3*y2 - x2*y3 + (y3-y2)*x) / (x3 - x2);
                    }
                }
            }
        }
        else {
            // x1 is voiced
            if (vp2 < 0.5) {
                // x1 voiced, x2 unvoiced
                if (x2 - x < 0.5) {
                    // x is closer to unvoiced x2
                    y = -1.0;
                }
                else {
                    // x is closer to voiced x1
                    if (vp0 < 0.5) {
                        // x0 is unvoiced or ob
                        y = v.at(i1);
                    }
                    else {
                        // x0 is voiced
                        // extraploate with x0 and x1
                        int y0 = v.at(i0);
                        int y1 = v.at(i1);
                        y = (x1*y0 - x0*y1 + (y1-y0)*x) / (x1 - x0);
                    }
                }
            }
            else {
                // interpolate with x1 and x2
                double y1 = v.at(i1);
                double y2 = v.at(i2);
                y = (y2 - y1) / (x2 - x1) * (x - x1) + y1;
            }
//.........这里部分代码省略.........
开发者ID:askhar516,项目名称:toney,代码行数:101,代码来源:f0contour.cpp


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