-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
writes a unit test a makes it passes
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
!= [] | ||
) |