<commit_before># Author:  <NAME>
# Created: 2016-01-08
# Copyright (C) 2016, <NAME>
# License: MIT
# Website sympl.org/pysound
#
# Simple wave forms

import numpy as np
import math
from pysound.buffer import SoundBuffer, get_buffer

def square_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = duration*rate;
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    ratio = get_buffer(samples, ratio)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        data[i] = offset[i] + amplitude[i]*(1 if t < ratio[i] else -1)
    return buffer

def saw_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = duration*rate;
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    ratio = get_buffer(samples, ratio)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        if t < ratio[i]:
            v = -1 + 2*t/ratio[i]
        else:
            v = 1 - 2*(t-ratio[i])/(1-ratio[i])
        data[i] = offset[i] + amplitude[i]*v
    return buffer

def sine_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = duration*rate;
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        data[i] = offset[i] + amplitude[i]*math.sin(t*2*math.pi)<commit_msg>Force number of samples to be an integer<commit_after># Author:  <NAME>
# Created: 2016-01-08
# Copyright (C) 2016, <NAME>
# License: MIT
# Website sympl.org/pysound
#
# Simple wave forms

import numpy as np
import math
from pysound.buffer import SoundBuffer, get_buffer

def square_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = int(duration*rate)
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    ratio = get_buffer(samples, ratio)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        data[i] = offset[i] + amplitude[i]*(1 if t < ratio[i] else -1)
    return buffer

def saw_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = int(duration*rate)
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    ratio = get_buffer(samples, ratio)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        if t < ratio[i]:
            v = -1 + 2*t/ratio[i]
        else:
            v = 1 - 2*(t-ratio[i])/(1-ratio[i])
        data[i] = offset[i] + amplitude[i]*v
    return buffer

def sine_wave(rate=11025, duration=1, frequency=400, amplitude=1, ratio=0.5, offset=0):
    samples = int(duration*rate)
    buffer = SoundBuffer(samples)
    data = buffer.getData()
    t = 0
    frequency = get_buffer(samples, frequency)
    amplitude = get_buffer(samples, amplitude)
    offset = get_buffer(samples, offset)
    for i in range(samples):
        t += frequency[i]/rate
        t %= 1
        data[i] = offset[i] + amplitude[i]*math.sin(t*2*math.pi)
{'fraction_non_alphanumeric': 0.1300877893056664, 'fraction_numerical': 0.03458366586858207, 'mean_word_length': 3.0958605664488017, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '4646012', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1240, 'n_words': 320}