Exemplo n.º 1
0
/** Determine if we're changing directions (scratching) and then perform
    a stretch */
CSAMPLE * EngineBufferScaleLinear::getScaled(unsigned long buf_size) {
    float rate_add_new = m_dBaseRate;
    float rate_add_old = m_fOldBaseRate; //Smoothly interpolate to new playback rate
    int samples_read = 0;
    m_samplesRead = 0;

    // Guard against buf_size == 0
    if ((int)buf_size == 0)
        return m_buffer;

    if (rate_add_new * rate_add_old < 0) {
        //calculate half buffer going one way, and half buffer going
        //the other way.

        //first half: rate goes from old rate to zero
        m_fOldBaseRate = rate_add_old;
        m_dBaseRate = 0.0;
        m_buffer = do_scale(m_buffer, buf_size/2, &samples_read);

        // reset prev sample so we can now read in the other direction (may not
        // be necessary?)
        int iCurSample = static_cast<int>(ceil(m_dCurSampleIndex)) * 2;
        if (iCurSample + 1 < buffer_int_size) {
            int iNextSample = static_cast<int>(ceil(m_dNextSampleIndex)) * 2;
            m_fPrevSample[0] = buffer_int[iNextSample];
            m_fPrevSample[1] = buffer_int[iNextSample + 1];
        }

        // if the buffer has extra samples, do a read so RAMAN ends up back where
        // it should be
        int extra_samples = buffer_int_size - iCurSample - 2;
        if (extra_samples > 0) {
            if (extra_samples % 2 != 0)
                extra_samples++;
            //qDebug() << "extra samples" << extra_samples;

            samples_read += m_pReadAheadManager->getNextSamples(
                rate_add_new, buffer_int, extra_samples);
        }
        //force a buffer read:
        buffer_int_size=0;
        //make sure the indexes stay correct for interpolation
        m_dCurSampleIndex = 0 - m_dCurSampleIndex + floor(m_dCurSampleIndex);
        m_dNextSampleIndex = 1.0 - (m_dNextSampleIndex - floor(m_dNextSampleIndex));

        //second half: rate goes from zero to new rate
        m_fOldBaseRate = 0.0;
        m_dBaseRate = rate_add_new;
        //pass the address of the sample at the halfway point
        do_scale(&m_buffer[buf_size/2], buf_size/2, &samples_read);

        m_samplesRead = samples_read;
        return m_buffer;
    }

    CSAMPLE* result = do_scale(m_buffer, buf_size, &samples_read);
    m_samplesRead = samples_read;
    return result;
}
Exemplo n.º 2
0
inline void SpatialSceneBuilder::scale(double x, double y, double z)
{
    do_scale(math::Vec3(x,y,z));
}
Exemplo n.º 3
0
inline void SpatialSceneBuilder::scale(math::Vec3 s)
{
    do_scale(s);
}