Exemplo n.º 1
0
class VampyPluginConfigTest(unittest.TestCase):
    def setUp(self):
        self.empty_config = VampyPluginParams(None, None)
        self.basic_config = VampyPluginParams(2048, 4096)
        self.extended_config = VampyPluginParams(2048, 2048, sub_bands=9)

    def test_should_create_parameters_from_config(self):
        assert_that(self.empty_config.extraction_params()).is_equal_to({})
        assert_that(self.basic_config.extraction_params()).is_equal_to({
            "step_size":
            4096,
            "block_size":
            2048
        })
        assert_that(self.extended_config.extraction_params()).is_equal_to({
            "step_size":
            2048,
            "block_size":
            2048,
            "sub_bands":
            9
        })

    def test_should_serialize_and_deserialize(self):
        serialized = self.extended_config.to_serializable()
        json_serialized = json.dumps(serialized)
        assert_that(json_serialized).is_not_empty()

        deserialized = json.loads(json_serialized)
        back_to_object = VampyPluginParams.from_serializable(deserialized)
        assert_that(back_to_object).is_equal_to(self.extended_config)
Exemplo n.º 2
0
 def _build_plugin_config(self, request: ExtractionRequest) -> VampyPluginParams:
     if request.plugin_config:
         block_size = request.plugin_config.pop("block_size", None)
         step_size = request.plugin_config.pop("step_size", None)
         return VampyPluginParams(block_size, step_size, **request.plugin_config)
     else:
         return VampyPluginParams(None, None)
Exemplo n.º 3
0
    def test_should_serialize_and_deserialize(self):
        serialized = self.extended_config.to_serializable()
        json_serialized = json.dumps(serialized)
        assert_that(json_serialized).is_not_empty()

        deserialized = json.loads(json_serialized)
        back_to_object = VampyPluginParams.from_serializable(deserialized)
        assert_that(back_to_object).is_equal_to(self.extended_config)
Exemplo n.º 4
0
 def from_serializable(cls, serialized: Dict[str, Any]):
     audio_meta_object = CompressedAudioFileMeta.from_serializable(serialized["audio_meta"])
     id3_tag_object = Id3Tag.from_serializable(serialized["id3_tag"])
     plugin_object = VampyPlugin.from_serializable(serialized["plugin"])
     plugin_config_object = VampyPluginParams.from_serializable(serialized["plugin_config"])
     serialized.update({"audio_meta": audio_meta_object, "id3_tag": id3_tag_object,
                        "plugin": plugin_object, "plugin_config": plugin_config_object})
     return AnalysisRequest(**serialized)
Exemplo n.º 5
0
 def setUp(self):
     self.audio_meta_example = CompressedAudioFileMeta("some_file.mp3", 1024 * 1024 * 2, 1, 44100, 45., 128.)
     self.id3_tag_example = Id3Tag(artist="Unknown Artist", title="Unknown Title", album="Unknown Album",
                                   date=2017, track=1, genre="Unknown Genre")
     self.example_vampy_plugin = VampyPlugin("vamp-example-plugins", "amplitudefollower", "amplitude",
                                             library_file_name="/root/vamp/vamp-example-plugins.so")
     self.task_id = "fa3b5d8c-b760-49e0-b8b5-7ce0737621d8"
     self.plugin_config_example = VampyPluginParams(block_size=2048, step_size=512)
     self.analysis_request_example = AnalysisRequest(self.task_id, self.audio_meta_example, self.id3_tag_example,
                                                     self.example_vampy_plugin, self.plugin_config_example)
Exemplo n.º 6
0
 def setUp(self):
     self.task_id = "0f961f20-b036-5740-b526-013523dd88c7"
     self.audio_meta_example_1 = CompressedAudioFileMeta(
         "some_file.mp3", 1024 * 1024 * 2, 1, 44100, 45., 128.)
     self.audio_meta_example_2 = CompressedAudioFileMeta(
         "some_file_2.mp3", 1024 * 1024 * 2, 1, 44100, 45., 128.)
     self.tag_example_1 = Id3Tag(artist="Pink Floyd",
                                 title="Have a cigar",
                                 album="Wish you were here",
                                 date=1975,
                                 track=3,
                                 genre="Progressive rock")
     self.tag_example_2 = Id3Tag(artist="Floyd",
                                 title="Cigar",
                                 album="Wish you were here",
                                 date=1981,
                                 track=2,
                                 genre="Rock")
     self.plugin_example_1 = VampyPlugin("my_vendor", "my_name", "outputs",
                                         "my_file.so")
     self.plugin_example_2 = VampyPlugin("my_vendor", "my_name_2",
                                         "outputs", "my_file_2.so")
     self.plugin_config_example_1 = VampyPluginParams(block_size=2048,
                                                      step_size=1024)
     self.the_request = AnalysisRequest(
         task_id=self.task_id,
         audio_meta=self.audio_meta_example_1,
         id3_tag=self.tag_example_1,
         plugin=self.plugin_example_1,
         plugin_config=self.plugin_config_example_1)
     self.plugin_repo = VampyPluginRepository(self.session_provider)
     self.audio_repo = AudioFileRepository(self.session_provider)
     self.audio_tag_repo = AudioTagRepository(self.session_provider)
     self.plugin_config_repo = PluginConfigRepository(self.session_provider)
     self.request_repo = RequestRepository(self.session_provider,
                                           self.audio_repo,
                                           self.audio_tag_repo,
                                           self.plugin_repo,
                                           self.plugin_config_repo)
Exemplo n.º 7
0
 def _map_to_object(self, entity: PluginConfig) -> VampyPluginParams:
     block_size = entity.block_size if entity.block_size != PLUGIN_CONFIG_DEFAULT else None
     step_size = entity.step_size if entity.step_size != PLUGIN_CONFIG_DEFAULT else None
     return VampyPluginParams(block_size=block_size,
                              step_size=step_size,
                              **json.loads(entity.additional_params))
Exemplo n.º 8
0
 def setUp(self):
     self.empty_config = VampyPluginParams(None, None)
     self.basic_config = VampyPluginParams(2048, 4096)
     self.extended_config = VampyPluginParams(2048, 2048, sub_bands=9)