Exemplo n.º 1
0
void SynthEvent::setFrequency( float aFrequency, bool allOscillators, bool storeAsBaseFrequency )
{
    _frequency = aFrequency;
    _phaseIncr = aFrequency / AudioEngineProps::SAMPLE_RATE;

    // store as base frequency (acts as a reference "return point" for pitch shifting modules)
    if ( storeAsBaseFrequency )
        _baseFrequency = aFrequency;

    if ( _type == WaveForms::KARPLUS_STRONG )
        initKarplusStrong();

    // update properties of secondary oscillator, note that OSC2 can
    // have a pitch that deviates from the first oscillator
    // as such we multiply it by the deviation of the new frequency
    if ( allOscillators && _osc2 != 0 )
    {
        //float multiplier = aFrequency / currentFreq;
        //_osc2->setFrequency( _osc2->_frequency * multiplier, true, storeAsBaseFrequency );
        createOSC2( position, length, _instrument );
    }
}
Exemplo n.º 2
0
void SynthEvent::setFrequency( float aFrequency, bool allOscillators, bool storeAsBaseFrequency )
{
    float currentFreq = _frequency;
    _frequency        = aFrequency;
    //_phase            = 0.0f; // will create nasty pop if another freq was playing previously
    _phaseIncr        = aFrequency / AudioEngineProps::SAMPLE_RATE;

    // store as base frequency (acts as a reference "return point" for pitch shifting modules)
    if ( storeAsBaseFrequency )
        _baseFrequency = aFrequency;

    if ( /*!isSequenced &&*/ _type == WaveForms::KARPLUS_STRONG )
        initKarplusStrong();

    // update properties of secondary oscillator, note that OSC2 can
    // have a pitch that deviates from the first oscillator
    // as such we multiply it by the deviation of the new frequency
    if ( allOscillators && _osc2 != 0 )
    {
        float multiplier = aFrequency / currentFreq;
        _osc2->setFrequency( _osc2->_frequency * multiplier, true, storeAsBaseFrequency );
    }
}
Exemplo n.º 3
0
void SynthEvent::calculateBuffers()
{
    // we override the entire function body as we need some
    // oscillator 2-specific operations in here

    if ( _locked )
    {
        _updateAfterUnlock = true;
        return;
    }
    int oldLength;

    if ( isSequenced )
    {
        _cancel = true;

        oldLength     = _sampleLength;
        _sampleLength = ( int )( length * ( float ) AudioEngine::bytes_per_tick );
        _sampleStart  = position * AudioEngine::bytes_per_tick;
        _sampleEnd    = _sampleStart + _sampleLength;
    }
    else {
        // quick releases of a noteOn-instruction should ring for at least a 64th note
        _minLength    = AudioEngine::bytes_per_bar / 64;
        _sampleLength = AudioEngine::bytes_per_bar;     // important for amplitude swell in
        oldLength     = AudioEngineProps::BUFFER_SIZE;  // buffer is as long as the engine's buffer size
        _hasMinLength = false;                          // keeping track if the min length has been rendered
    }

    _adsr->setBufferLength( _sampleLength );

    // sample length changed (f.i. tempo change) or buffer not yet created ? create buffer for (new) length

    if ( _sampleLength != oldLength )
    {
        if ( !hasParent ) // OSC2 generates no buffer (writes into parent buffer, saves memory)
        {
            // note that when event caching is enabled, the buffer is as large as
            // the total event length requires

            if ( AudioEngineProps::EVENT_CACHING && isSequenced )
            {
                destroyBuffer(); // clear previous buffer contents
                _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, _sampleLength );
            }
            else
                _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, AudioEngineProps::BUFFER_SIZE );

            // though this event manages its child oscillator, the render method needs these properties
            if ( _osc2 != 0 ) {
                _osc2->_sampleLength = _sampleLength;
                _osc2->_sampleStart  = _sampleStart;
                _osc2->_sampleEnd    = _sampleEnd;
            }
        }
    }

    if ( isSequenced )
    {
        if ( _type == WaveForms::KARPLUS_STRONG )
            initKarplusStrong();

        if ( AudioEngineProps::EVENT_CACHING )
        {
            resetCache(); // yes here, not in cache()-invocation as cancels might otherwise remain permanent (see BulkCacher)

            if ( _autoCache && !_caching ) // re-cache
                cache( false );
        }
    }
}
Exemplo n.º 4
0
void SynthEvent::calculateBuffers()
{
    if ( _locked )
    {
        _updateAfterUnlock = true;
        return;
    }

    int oldLength;

    if ( isSequenced )
    {
        if ( _caching )
            _cancel = true;

        oldLength     = _sampleLength;
        _sampleLength = ( int )( length * ( float ) AudioEngine::bytes_per_tick );
        _sampleStart  = position * AudioEngine::bytes_per_tick;
        _sampleEnd    = _sampleStart + _sampleLength;
    }
    else {
        // quick releases of the key should at least ring for a 32nd note
        _minLength    = AudioEngine::bytes_per_bar / 32;
        _sampleLength = AudioEngine::bytes_per_bar;     // important for amplitude swell in
        oldLength     = AudioEngineProps::BUFFER_SIZE;  // buffer is as long as the engine's buffer size
        _hasMinLength = false;                          // keeping track if the min length has been rendered
    }

    _adsr->setBufferLength( _sampleLength );

    // sample length changed (f.i. tempo change) or buffer not yet created ?
    // create buffer for (new) sample length
    if ( _sampleLength != oldLength || _buffer == 0 )
    {
        destroyBuffer(); // clear previous buffer contents

        // OSC2 generates no buffer (writes into parent buffer, saves memory)
        if ( !hasParent )
        {
            // note that when event caching is enabled, the buffer is as large as
            // the total event length requires

            if ( AudioEngineProps::EVENT_CACHING && isSequenced )
                _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, _sampleLength );
            else
                _buffer = new AudioBuffer( AudioEngineProps::OUTPUT_CHANNELS, AudioEngineProps::BUFFER_SIZE );
        }
     }

    if ( isSequenced )
    {
        if ( _type == WaveForms::KARPLUS_STRONG )
            initKarplusStrong();

        if ( AudioEngineProps::EVENT_CACHING )
        {
            resetCache(); // yes here, not in cache()-invocation as cancels might otherwise remain permanent (see BulkCacher)

            // (re)cache (unless this event is OSC2 as only the parent event can invoke the render)
            if ( _autoCache && !hasParent )
            {
                if ( !_caching )
                    cache( false );
                else
                    _cancel = true;
            }
        }
    }
}