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


C++ Float32Array::data方法代码示例

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


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

示例1: processCurve

void WaveShaperDSPKernel::processCurve(const float* source, float* destination, size_t framesToProcess)
{
    ASSERT(source && destination && waveShaperProcessor());

    Float32Array* curve = waveShaperProcessor()->curve();
    if (!curve) {
        // Act as "straight wire" pass-through if no curve is set.
        memcpy(destination, source, sizeof(float) * framesToProcess);
        return;
    }

    float* curveData = curve->data();
    int curveLength = curve->length();

    ASSERT(curveData);

    if (!curveData || !curveLength) {
        memcpy(destination, source, sizeof(float) * framesToProcess);
        return;
    }

    // Apply waveshaping curve.
    for (unsigned i = 0; i < framesToProcess; ++i) {
        const float input = source[i];

        // Calculate a virtual index based on input -1 -> +1 with -1 being curve[0], +1 being
        // curve[curveLength - 1], and 0 being at the center of the curve data. Then linearly
        // interpolate between the two points in the curve.
        double virtualIndex = 0.5 * (input + 1) * (curveLength - 1);
        double output;

        if (virtualIndex < 0) {
            // input < -1, so use curve[0]
            output = curveData[0];
        } else if (virtualIndex >= curveLength - 1) {
            // input >= 1, so use last curve value
            output = curveData[curveLength - 1];
        } else {
            // The general case where -1 <= input < 1, where 0 <= virtualIndex < curveLength - 1,
            // so interpolate between the nearest samples on the curve.
            unsigned index1 = static_cast<unsigned>(virtualIndex);
            unsigned index2 = index1 + 1;
            double interpolationFactor = virtualIndex - index1;

            double value1 = curveData[index1];
            double value2 = curveData[index2];

            output = (1.0 - interpolationFactor) * value1 + interpolationFactor * value2;
        }
        destination[i] = output;
    }
}
开发者ID:335969568,项目名称:Blink-1,代码行数:52,代码来源:WaveShaperDSPKernel.cpp

示例2: processCurve

void WaveShaperDSPKernel::processCurve(const float* source, float* destination, size_t framesToProcess)
{
    ASSERT(source && destination && waveShaperProcessor());

    Float32Array* curve = waveShaperProcessor()->curve();
    if (!curve) {
        // Act as "straight wire" pass-through if no curve is set.
        memcpy(destination, source, sizeof(float) * framesToProcess);
        return;
    }

    float* curveData = curve->data();
    int curveLength = curve->length();

    ASSERT(curveData);

    if (!curveData || !curveLength) {
        memcpy(destination, source, sizeof(float) * framesToProcess);
        return;
    }

    // Apply waveshaping curve.
    for (unsigned i = 0; i < framesToProcess; ++i) {
        const float input = source[i];

        // Calculate a virtual index based on input -1 -> +1 with 0 being at the center of the curve data.
        // Then linearly interpolate between the two points in the curve.
        double virtualIndex = 0.5 * (input + 1) * curveLength;
        int index1 = static_cast<int>(virtualIndex);
        int index2 = index1 + 1;
        double interpolationFactor = virtualIndex - index1;

        // Clip index to the input range of the curve.
        // This takes care of input outside of nominal range -1 -> +1
        index1 = max(index1, 0);
        index1 = min(index1, curveLength - 1);
        index2 = max(index2, 0);
        index2 = min(index2, curveLength - 1);

        double value1 = curveData[index1];
        double value2 = curveData[index2];

        double output = (1.0 - interpolationFactor) * value1 + interpolationFactor * value2;
        destination[i] = output;
    }
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:46,代码来源:WaveShaperDSPKernel.cpp

示例3: valuesForTimeRangeImpl


//.........这里部分代码省略.........
            case ParamEvent::LinearRampToValue:
            case ParamEvent::ExponentialRampToValue:
            {
                currentTime = fillToTime;

                // Simply stay at a constant value.
                value = event.value();
                for (; writeIndex < fillToFrame; ++writeIndex)
                    values[writeIndex] = value;

                break;
            }

            case ParamEvent::SetTarget:
            {
                currentTime = fillToTime;

                // Exponential approach to target value with given time constant.
                float target = event.value();
                float timeConstant = event.timeConstant();
                float discreteTimeConstant = static_cast<float>(AudioUtilities::discreteTimeConstantForSampleRate(timeConstant, controlRate));

                for (; writeIndex < fillToFrame; ++writeIndex) {
                    values[writeIndex] = value;
                    value += (target - value) * discreteTimeConstant;
                }

                break;
            }

            case ParamEvent::SetValueCurve:
            {
                Float32Array* curve = event.curve();
                float* curveData = curve ? curve->data() : 0;
                unsigned numberOfCurvePoints = curve ? curve->length() : 0;

                // Curve events have duration, so don't just use next event time.
                float duration = event.duration();
                float durationFrames = duration * sampleRate;
                float curvePointsPerFrame = static_cast<float>(numberOfCurvePoints) / durationFrames;

                if (!curve || !curveData || !numberOfCurvePoints || duration <= 0 || sampleRate <= 0) {
                    // Error condition - simply propagate previous value.
                    currentTime = fillToTime;
                    for (; writeIndex < fillToFrame; ++writeIndex)
                        values[writeIndex] = value;
                    break;
                }

                // Save old values and recalculate information based on the curve's duration
                // instead of the next event time.
                unsigned nextEventFillToFrame = fillToFrame;
                float nextEventFillToTime = fillToTime;
                fillToTime = min(endTime, time1 + duration);
                fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime - startTime, sampleRate);
                fillToFrame = min(fillToFrame, numberOfValues);

                // Index into the curve data using a floating-point value.
                // We're scaling the number of curve points by the duration (see curvePointsPerFrame).
                float curveVirtualIndex = 0;
                if (time1 < currentTime) {
                    // Index somewhere in the middle of the curve data.
                    // Don't use timeToSampleFrame() since we want the exact floating-point frame.
                    float frameOffset = (currentTime - time1) * sampleRate;
                    curveVirtualIndex = curvePointsPerFrame * frameOffset;
                }
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:67,代码来源:AudioParamTimeline.cpp


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