def add_wave(self, frequency, length, location='END', level=None):
        if location == 'END':
            location = len(self.data)
        elif location < 0:
            location = 0
        elif location * 44100 > len(self.data):
            location = len(self.data) / 44100.0

        # location is a time, so let's adjust
        location = int(location * 44100)

        if level == None:
            level = self.volume
        elif level > 100:
            level = 100
        elif level < 0:
            level = 0

        for n in range(0, int(44100 * length)):
            val = self.wave_type(frequency, n)
            val *= level / 100.0 * 32767

            if location + n >= len(self.data):
                self.data.append(val)
            else:
                current_val = self.data[location + n]
                if current_val + val > 32767:
                    val = 32767
                elif current_val + val < -32768:
                    val = -32768
                else:
                    val += current_val

                self.data[location + n] = val
dataset/ETHPy150Open jdan/Melopy/melopy/melopy.py/Melopy.add_wave/original