diff --git a/minamidera/soundpointsgenerators.py b/minamidera/soundpointsgenerators.py index ed00155..f164317 100644 --- a/minamidera/soundpointsgenerators.py +++ b/minamidera/soundpointsgenerators.py @@ -1,9 +1,43 @@ +import statistics + import pang +import numpy as np class AtaxicSoundPointsGenerator(pang.SoundPointsGenerator): - def __init__(self, pitches_set, intensity_set, density_set, duration_set): + def __init__(self, pitches_set, intensity_set, density_set, duration_set, seed): self.pitches_set = pitches_set self.intensity_set = intensity_set self.density_set = density_set self.duration_set = duration_set + self._random_number_generator = np.random.default_rng(seed) + + def __call__(self, sequence_duration): + instances = self._generate_instances(sequence_duration) + return [ + pang.SoundPoint(instance, duration, pitch) + for instance, duration, pitch in zip( + instances, + self._generate_durations(len(instances)), + self._generate_pitches(len(instances)), + ) + ] + + def _generate_instances(self, sequence_duration): + (density,) = self.density_set + return sorted( + self._random_number_generator.uniform( + 0.0, sequence_duration, density * sequence_duration + ) + ) + + def _generate_durations(self, number_of_sound_points): + (duration,) = self.duration_set + return self._random_number_generator.exponential( + duration, number_of_sound_points + ) + + def _generate_pitches(self, number_of_sound_points): + return self._random_number_generator.choice( + tuple(self.pitches_set), number_of_sound_points + ).tolist() diff --git a/minamidera/statemapper.py b/minamidera/statemapper.py index cdffe8c..aafa82b 100644 --- a/minamidera/statemapper.py +++ b/minamidera/statemapper.py @@ -34,4 +34,5 @@ def map_state_vector_to_sound_points_generator( INTENSITY_SETS[state_vector[1]], DENSITY_SETS[state_vector[2]], DURATION_SETS[state_vector[3]], + 238492, ) diff --git a/tests/test_soundpointgenerators.py b/tests/test_soundpointgenerators.py new file mode 100644 index 0000000..4cba4c5 --- /dev/null +++ b/tests/test_soundpointgenerators.py @@ -0,0 +1,10 @@ +from minamidera import soundpointsgenerators + + +def test_generated_sound_points_list_is_not_empty(): + assert ( + soundpointsgenerators.AtaxicSoundPointsGenerator( + {0, 1, 2}, {0}, {1}, {1}, 2984756 + )(10) + != [] + )