<commit_before>// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKit/

// Utility class to manage DSP parameters which can change value smoothly (be ramped) while rendering, without introducing clicks or other distortion into the signal.
//
// Originally based on Apple sample code, but significantly altered by <NAME>

#pragma once

#ifdef __cplusplus

// N.B. This is C++.

#import <AudioToolbox/AudioToolbox.h>
#import <libkern/OSAtomic.h>

#import <atomic>

class ParameterRamper {
    float clampLow, clampHigh;
    float _uiValue;
    float _goal;
    float inverseSlope;
    AUAudioFrameCount samplesRemaining;
    std::atomic<int32_t> changeCounter;
    int32_t updateCounter = 0;

    void setImmediate(float value) {
        // only to be called from the render thread or when resources are not allocated.
        _goal = _uiValue = value;
        inverseSlope = 0.0;
        samplesRemaining = 0;
    }

public:
    ParameterRamper(float value = 0.0f) : changeCounter(0) {
        setImmediate(value);
    }

    void init() {
        /*
         Call this from the kernel init.
         Updates the internal value from the UI value.
         */
        setImmediate(_uiValue);
    }

    void reset() {
        changeCounter = updateCounter = 0;
    }<commit_msg>Fix data race detected by TSAN.<commit_after>// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKit/

// Utility class to manage DSP parameters which can change value smoothly (be ramped) while rendering, without introducing clicks or other distortion into the signal.
//
// Originally based on Apple sample code, but significantly altered by <NAME>

#pragma once

#ifdef __cplusplus

// N.B. This is C++.

#import <AudioToolbox/AudioToolbox.h>
#import <libkern/OSAtomic.h>

#import <atomic>

class ParameterRamper {
    float clampLow, clampHigh;
    std::atomic<float> _uiValue{0};
    float _goal;
    float inverseSlope;
    AUAudioFrameCount samplesRemaining;
    std::atomic<int32_t> changeCounter;
    int32_t updateCounter = 0;

    void setImmediate(float value) {
        // only to be called from the render thread or when resources are not allocated.
        _goal = _uiValue = value;
        inverseSlope = 0.0;
        samplesRemaining = 0;
    }

public:
    ParameterRamper(float value = 0.0f) : changeCounter(0) {
        setImmediate(value);
    }

    void init() {
        /*
         Call this from the kernel init.
         Updates the internal value from the UI value.
         */
        setImmediate(_uiValue);
    }

    void reset() {
        changeCounter = updateCounter = 0;
    }
{'fraction_non_alphanumeric': 0.08557548579970105, 'fraction_numerical': 0.009342301943198805, 'mean_word_length': 2.7864214992927865, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6097946', 'n_tokens_mistral': 807, 'n_tokens_neox': 764, 'n_words': 263}