import math


def calc_rms(data, channel, num_channels, num_samples_per_channel):
    """ Calculate RMS of a data buffer """
    value = 0.0
    for i in range(num_samples_per_channel):
        index = (i * num_channels) + channel
        value += (data[index] * data[index]) / num_samples_per_channel

    return math.sqrt(value)