diff --git a/desidulate/sidlib.py b/desidulate/sidlib.py index c115cd2..547f97b 100755 --- a/desidulate/sidlib.py +++ b/desidulate/sidlib.py @@ -449,12 +449,11 @@ def hash_vdf(vdf, non_meta_cols): v_df.loc[v_df['test1'] == 1, ['test1_first']] = pd.NA v_df['test1_first'] = v_df.groupby(['ssf'], sort=False)['test1_first'].min() v_df.loc[ - (v_df['test1'] == 1) & (v_df['clock'] <= v_df['test1_first']), - ['freq1', 'tri1', 'saw1', 'pulse1', 'noise1', 'flt1'] + mod_cols] = pd.NA + (v_df['test1'] == 1) & (v_df['clock'] <= v_df['test1_first']), ['freq1', 'pwduty1', 'flt1']] = pd.NA v_df.drop(['test1_first'], axis=1, inplace=True) # fold noise1 + other waveforms, to waveform 0. - v_df.loc[(v_df['noise1'] == 1) & ((v_df['pulse1'] == 1) | (v_df['saw1'] == 1) | (v_df['tri1'] == 1)), ['noise1', 'pulse1', 'saw1', 'tri1']] = 0 + # v_df.loc[(v_df['noise1'] == 1) & ((v_df['pulse1'] == 1) | (v_df['saw1'] == 1) | (v_df['tri1'] == 1)), ['noise1', 'pulse1', 'saw1', 'tri1']] = 0 # remove modulator voice state while sync1/ring1 not set v_df.loc[(v_df['freq3'] == 0), ['ring1', 'sync1']] = 0 v_df.loc[(v_df['ring1'] == 1) & (v_df['tri1'] == 0), ['ring1']] = 0 diff --git a/tests/test_sidwav.py b/tests/test_sidwav.py index 8d24fa1..ef8e760 100755 --- a/tests/test_sidwav.py +++ b/tests/test_sidwav.py @@ -16,7 +16,7 @@ class SidWavTestCase(unittest.TestCase): def _make_wav_df(rows): return pd.DataFrame(rows, dtype=pd.UInt64Dtype()).set_index('clock').fillna(method='ffill').astype(pd.UInt64Dtype()) - def _same_samples(self, df1, df2, same=True): + def _same_samples(self, df1, df2): sid = get_sid(pal=True) raw_samples = state2samples(df1, sid) sid = get_sid(pal=True) @@ -24,10 +24,7 @@ def _same_samples(self, df1, df2, same=True): self.assertTrue(len(raw_samples)) self.assertTrue(len(raw_samples2)) self.assertNotEqual(df1.to_string(), df2.to_string()) - if same: - self.assertTrue(np.array_equal(raw_samples, raw_samples2)) - else: - self.assertFalse(np.array_equal(raw_samples, raw_samples2)) + return np.array_equal(raw_samples, raw_samples2) def test_skiptest(self): sid = get_sid(pal=True) @@ -47,7 +44,7 @@ def test_skiptest(self): def test_ring_non_tri(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1024, 'sus1': 15, 'gate1': 1, 'pwduty1': 1024, 'pulse1': 1, 'saw1': 1, 'vol': 15, 'freq3': 512} - end = {'hashid': 1, 'clock': 1e6 * 20, 'freq1': 0} + end = {'hashid': 1, 'clock': 1e6 * 2, 'freq1': 0} df1 = self._make_wav_df([ gateon, end, @@ -57,12 +54,73 @@ def test_ring_non_tri(self): gateon, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) + + def test_initial_freq_while_test(self): + gateon = {'hashid': 1, 'clock': 0, 'freq1': 1024, 'sus1': 15, 'gate1': 1, 'pwduty1': 1024, 'pulse1': 1, 'vol': 15, 'test1': 1} + testoff = {'hashid': 1, 'clock': 1e5, 'test1': 0, 'freq1': 1024} + end = {'hashid': 1, 'clock': 1e6, 'freq1': 0} + df1 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'freq1': 512}, + {'hashid': 1, 'clock': 1e4 * 2, 'freq1': 1024}, + testoff, + end, + ]) + df2 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'freq1': 1024}, + {'hashid': 1, 'clock': 1e4 * 2, 'freq1': 1024}, + testoff, + end, + ]) + self.assertTrue(self._same_samples(df1, df2)) + + def test_initial_pwduty_while_test(self): + gateon = {'hashid': 1, 'clock': 0, 'freq1': 1024, 'sus1': 15, 'gate1': 1, 'pwduty1': 1024, 'pulse1': 1, 'vol': 15, 'test1': 1} + testoff = {'hashid': 1, 'clock': 1e5, 'test1': 0, 'freq1': 1024} + end = {'hashid': 1, 'clock': 1e6, 'freq1': 0} + df1 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'pwduty1': 1024}, + {'hashid': 1, 'clock': 1e4 * 2, 'pwduty1': 1024}, + testoff, + end, + ]) + df2 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'pwduty1': 512}, + {'hashid': 1, 'clock': 1e4 * 2, 'pwduty1': 1024}, + testoff, + end, + ]) + self.assertTrue(self._same_samples(df1, df2)) + + def test_initial_noise_pulse_while_test(self): + gateon = {'hashid': 1, 'clock': 0, 'freq1': 1024, 'sus1': 15, 'gate1': 1, 'pwduty1': 1024, 'tri': 1, 'vol': 15, 'test1': 1} + testoff = {'hashid': 1, 'clock': 1e5, 'test1': 0, 'freq1': 1024} + changeback = {'hashid': 1, 'clock': 1e4 * 2, 'noise1': 0, 'pulse1': 1} + end = {'hashid': 1, 'clock': 1e6, 'freq1': 0} + df1 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'pulse1': 1, 'noise1': 0}, + changeback, + testoff, + end, + ]) + df2 = self._make_wav_df([ + gateon, + {'hashid': 1, 'clock': 1e4, 'pulse1': 0, 'noise1': 1}, + changeback, + testoff, + end, + ]) + self.assertFalse(self._same_samples(df1, df2)) def test_sync_noise(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1024, 'sus1': 15, 'gate1': 1, 'noise1': 1, 'vol': 15, 'freq3': 512} - gateoff = {'hashid': 1, 'clock': 1e6 * 10, 'gate1': 0} - end = {'hashid': 1, 'clock': 1e6 * 20, 'freq1': 0} + gateoff = {'hashid': 1, 'clock': 1e6, 'gate1': 0} + end = {'hashid': 1, 'clock': 1e6 * 2, 'freq1': 0} df1 = self._make_wav_df([ gateon, end, @@ -72,12 +130,12 @@ def test_sync_noise(self): gateon, end, ]) - self._same_samples(df1, df2, same=False) + self.assertFalse(self._same_samples(df1, df2)) def test_changes_in_no_rel(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1000, 'sus1': 15, 'rel': 0, 'gate1': 1, 'tri1': 1, 'vol': 15} - gateoff = {'hashid': 1, 'clock': 1e6 * 10, 'gate1': 0} - end = {'hashid': 1, 'clock': 1e6 * 20, 'freq1': 0} + gateoff = {'hashid': 1, 'clock': 1e6, 'gate1': 0} + end = {'hashid': 1, 'clock': 1e6 * 2, 'freq1': 0} df1 = self._make_wav_df([ gateon, gateoff, @@ -89,11 +147,11 @@ def test_changes_in_no_rel(self): {'hashid': 1, 'clock': gateoff['clock'] + 256, 'freq1': gateon['freq1'] * 2}, end, ]) - self._same_samples(df1, df2, same=False) + self.assertFalse(self._same_samples(df1, df2)) def test_no_flt_route(self): - gateoff = {'hashid': 1, 'clock': 1e6 * 10, 'gate1': 0} - end = {'hashid': 1, 'clock': 1e6 * 20, 'freq1': 0} + gateoff = {'hashid': 1, 'clock': 1e6, 'gate1': 0} + end = {'hashid': 1, 'clock': 1e6 * 2, 'freq1': 0} df1 = self._make_wav_df([ {'hashid': 1, 'clock': 0, 'freq1': 1000, 'sus1': 15, 'gate1': 1, 'tri1': 1, 'vol': 15, 'flt1': 1, 'fltres': 15, 'fltcoff': 16}, gateoff, @@ -104,11 +162,11 @@ def test_no_flt_route(self): gateoff, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) def test_rel_change_before_gateoff(self): - gateoff = {'hashid': 1, 'clock': 1e6 * 10, 'gate1': 0} - end = {'hashid': 1, 'clock': 1e6 * 20, 'freq1': 0} + gateoff = {'hashid': 1, 'clock': 1e6, 'gate1': 0} + end = {'hashid': 1, 'clock': 1e6 * 2, 'freq1': 0} rel = 5 df1 = self._make_wav_df([ {'hashid': 1, 'clock': 0, 'freq1': 1000, 'sus1': 15, 'gate1': 1, 'tri1': 1, 'vol': 15, 'rel1': rel}, @@ -117,11 +175,11 @@ def test_rel_change_before_gateoff(self): ]) df2 = self._make_wav_df([ {'hashid': 1, 'clock': 0, 'freq1': 1000, 'sus1': 15, 'gate1': 1, 'tri1': 1, 'vol': 15, 'rel1': rel * 2}, - {'hashid': 1, 'clock': 1e6 * 1, 'rel1': rel}, + {'hashid': 1, 'clock': 1e5, 'rel1': rel}, gateoff, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) def test_dec_change_before_gateoff(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1000, 'dec': 2, 'sus1': 10, 'gate1': 1, 'tri1': 1, 'vol': 15} @@ -138,7 +196,7 @@ def test_dec_change_before_gateoff(self): gateoff, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) def test_sus_change_before_gateoff(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1000, 'dec': 2, 'sus1': 10, 'gate1': 1, 'tri1': 1, 'vol': 15} @@ -155,7 +213,7 @@ def test_sus_change_before_gateoff(self): gateoff, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) def test_dec_sus_change_before_gateoff(self): gateon = {'hashid': 1, 'clock': 0, 'freq1': 1000, 'dec': 2, 'sus1': 10, 'gate1': 1, 'tri1': 1, 'vol': 15} @@ -172,7 +230,7 @@ def test_dec_sus_change_before_gateoff(self): gateoff, end, ]) - self._same_samples(df1, df2) + self.assertTrue(self._same_samples(df1, df2)) def test_df2wav(self): sid = get_sid(pal=True) @@ -184,7 +242,7 @@ def test_df2wav(self): test_real_freq = sid.real_sid_freq(test_raw_freq) df = self._make_wav_df([ {'hashid': 1, 'count': 1, 'clock': 0, 'freq1': test_raw_freq, 'sus1': 15, 'gate1': 1, 'tri1': 1, 'vol': 15}, - {'hashid': 1, 'count': 1, 'clock': 1e6 * 10, 'gate1': 0}]) + {'hashid': 1, 'count': 1, 'clock': 1e6 * 3, 'gate1': 0}]) write_wav(test_wav, sid, state2samples(df, sid)) freq_max = loudestf(test_wav) freq_diff = abs(freq_max - test_real_freq)