<commit_before><commit_msg>Add sine wave sweep test<commit_after>#!/usr/bin/env python
try:
    from cStringIO import StringIO
except ImportError:
    from io import StringIO

class Makefile(object):
    def __init__(self):
        self._fp = StringIO()
        self._all = set()
        self._targets = set()
    def add_default(self, x):
        self._all.add(x)
    def build(self, target, deps, *cmds):
        if target in self._targets:
            return
        self._targets.add(target)
        fp = self._fp
        fp.write(target + ':')
        for dep in deps:
            fp.write(' ' + dep)
        fp.write('\n')
        for cmd in cmds:
            fp.write('\t' + cmd + '\n')
    def write(self, *line):
        for line in line:
            self._fp.write(line + '\n')
    def save(self):
        f = open('Makefile', 'w')
        f.write('all:')
        for t in sorted(self._all):
            f.write(' ' + t)
        f.write('\n')
        f.write(self._fp.getvalue())

make = Makefile()
make.write(
    'FR := ../build/product/fresample',
    'SOX := sox')

def test_sweep(depth, rate1, rate2):
    inpath = 'in_%dk%d.wav' % (rate1 // 1000, depth)
    make.build(
        inpath, ['Makefile'],
        '$(SOX) -b %d -r %d -n $@ synth 8 sine 0+%d vol 0.999' %
        (depth, rate1, rate1//2))
    for q in range(4):
        outpath = 'out_%dk%d_%dk%dq' % \
                  (rate1 // 1000, depth, rate2/1000, q)
        make.build(
            outpath + '.wav', [inpath, '$(FR)', 'Makefile'],
            '$(FR) -q %d -r %d $< $@' % (q, rate2))
        make.build(
            outpath + '.png', [outpath + '.wav', 'Makefile'],
            'sox $< -n spectrogram -w kaiser -o $@')
        make.add_default(outpath + '.png')

test_sweep(16, 96000, 44100)
test_sweep(16, 96000, 48000)
test_sweep(16, 48000, 44100)
make.write(
    'clean:',
    '\trm -f *.wav *.png')
make.save()
{'fraction_non_alphanumeric': 0.1733403582718651, 'fraction_numerical': 0.03371970495258166, 'mean_word_length': 1.9170506912442395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3351504', 'n_tokens_mistral': 744, 'n_tokens_neox': 681, 'n_words': 170}