haha ChatGPT's audio compressor

ChatGPT wrote a compressor. Just trying to imagine how awful this might sound.

#include #include #include

using namespace std;

// Function to apply compression to the audio samples vector applyCompression(vector samples, double threshold, double ratio) { vector output;

for (double sample : samples) {
    double gain;

    // Check if sample exceeds threshold
    if (abs(sample) > threshold) {
        gain = threshold + (1 - threshold) / ratio;
    }
    else {
        gain = sample;
    }

    output.push_back(gain);
}

return output;

}

int main() { // Example input audio samples vector inputSamples = {0.1, 0.5, 0.7, 0.8, 0.9, 1.2, 1.5, 1.8, 2.0};

// Compression settings
double threshold = 0.8;
double ratio = 4.0;

// Apply compression to the input samples
vector<double> outputSamples = applyCompression(inputSamples, threshold, ratio);

// Output the compressed samples
for (double sample : outputSamples) {
    cout << sample << " ";
}
cout << endl;

return 0;

}

Haha now with attack and release times?

#include #include #include

using namespace std;

// Function to apply compression to the audio samples vector applyCompression(vector samples, double threshold, double ratio, double attackTime, double releaseTime, double sampleRate) { vector output; double gain = 1.0; double envelope = 0.0;

for (double sample : samples) {
    double absSample = abs(sample);

    // Calculate envelope using a simple peak follower algorithm
    if (absSample > envelope) {
        envelope += (absSample - envelope) * (1.0 / (attackTime * sampleRate));
    }
    else {
        envelope += (absSample - envelope) * (1.0 / (releaseTime * sampleRate));
    }

    // Calculate gain based on envelope and compression settings
    if (envelope > threshold) {
        gain = threshold + (1.0 - threshold) / pow(envelope / threshold, 1.0 / ratio);
    }
    else {
        gain = 1.0;
    }

    output.push_back(sample * gain);
}

return output;

}

int main() { // Example input audio samples vector inputSamples = {0.1, 0.5, 0.7, 0.8, 0.9, 1.2, 1.5, 1.8, 2.0};

// Compression settings
double threshold = 0.8;
double ratio = 4.0;
double attackTime = 0.1;
double releaseTime = 0.5;
double sampleRate = 44100.0;

// Apply compression to the input samples
vector<double> outputSamples = applyCompression(inputSamples, threshold, ratio, attackTime, releaseTime, sampleRate);

// Output the compressed samples
for (double sample : outputSamples) {
    cout << sample << " ";
}
cout << endl;

return 0;

}

I was thinking about an album fully created by chatgpt. I can’t do that, it’s blocked in my country, but it would be fun for someone to do that. Like “could you create a generative patch for me” or something, then “how long the track should be”, “what about a title” and so on. Maybe even a picture if it does pics, I am not sure

I guess you’d need to start with “how do you make a computer?” before moving on to anything else :grinning:

I was gonna say the first one has infinitely fast attack and release, it would obviously sound awful… The second one with attack and release it pretty basic - there may be VCV compressors that simple. Still, hard-knee only and a not very sophisticated detector. CPU usage might be high with that pow call in there every sample. but looks like it would work…