@Override
    public int getSamples(byte[] buffer) {
        byte[] cvBuffer = null;

        provider.getSamples(buffer);

        if(attenuationCv != null) {
            cvBuffer = new byte[buffer.length];
            attenuationCv.getSamples(cvBuffer);
        }

        int index = 0;

        for(int i = 0; i < buffer.length / 2; i++) {
            // If there is cv input then apply that to the attenuationRatio
            if(cvBuffer != null) {
                short cvSample = SampleConverter.toSample(cvBuffer, index);
                double cvValue = SampleConverter.getSampleValue(cvSample) * 2;


                if(cvValue < 0.0) {
                    cvValue *= -1;
                }

                // Apply modulation value to sample
                if(attenuationBaseRatio * cvValue <= 1.0) {
                    attenuationRatio = attenuationBaseRatio * cvValue;
                }
            }

            short sample = SampleConverter.toSample(buffer, index);

            sample = attenuate(sample);

            // Store the processed sample back to the buffer.
            buffer[index++] = (byte)(sample >> 8);
            buffer[index++] = (byte)(sample & 0xFF);
        }

        return buffer.length;
    }