def setUp(self): settings.INPUT_DIRECTORY = 'test_audio' self.sounds = [ sound_file.SoundFile('drums.wav'), sound_file.SoundFile('noise.wav') ] self.vamp_analyzer = sonic_annotator_analyzer.SonicAnnotatorAnalyzer( ['spectral_centroid'])
def setUp(self): settings.INPUT_DIRECTORY = 'test_audio' self.sounds = [ sound_file.SoundFile('drums.wav'), sound_file.SoundFile('noise.wav') ] self.csound_analyzer = csound_analyzer.CsoundAnalyzer(['csound_rms']) experiment.Experiment.folder_name = 'test'
def setUp(self): settings.INPUT_DIRECTORY = 'test_audio' self.sounds = [ sound_file.SoundFile('drums.wav'), sound_file.SoundFile('noise.wav') ] self.essentia_analyzer = essentia_analyzer.EssentiaAnalyzer(['spectral_centroid']) experiment.Experiment.folder_name = 'test'
def setUp(self): settings.INPUT_DIRECTORY = 'test_audio' self.sounds = [ sound_file.SoundFile('drums.wav'), sound_file.SoundFile('noise.wav'), sound_file.SoundFile('synth.wav') ] experiment.Experiment.load_experiment_settings('mfcc_basic.json') analyze.Analyzer.init_features_list() self.analyzer = analyze.Analyzer(project=None)
def setUp(self): settings.INPUT_DIRECTORY = 'test_audio' self.num_sounds = 10 self.drums = sound_file.SoundFile('drums.wav') self.files_to_delete = [] self.template_file_path = os.path.join(settings.EFFECT_DIRECTORY, 'test_effect.csd.jinja2') with open(self.template_file_path, 'r') as template_file: self.template_string = template_file.read() experiment.Experiment.folder_name = 'test'
def test_fitness(self): drums = sound_file.SoundFile('drums.wav') synth = sound_file.SoundFile('synth.wav') ind1 = individual.Individual(genotype=None, neural_mode=None, effect=None) ind1.set_output_sound(drums) ind2 = individual.Individual(genotype=None, neural_mode=None, effect=None) ind2.set_output_sound(synth) # make sure sound files are analyzed project.Project([ind1.output_sound, ind2.output_sound]) # mock ind1.set_fitness = lambda x: None ind2.set_fitness = lambda x: None fitness_evaluator = fitness.LocalSimilarityFitness(target_sound=drums) fitness_evaluator.evaluate_multiple([ind1, ind2])
def test_sound_file(self): my_sound_file = sound_file.SoundFile('drums.wav') self.assertAlmostEqual(my_sound_file.get_duration(), 7.89278911565) project.Project([my_sound_file]) feature_vector_0 = my_sound_file.get_standardized_neural_input_vector( 0) self.assertEqual(len(feature_vector_0), len(experiment.Experiment.NEURAL_INPUT_CHANNELS)) feature_vector_1 = my_sound_file.get_standardized_neural_input_vector( 1) self.assertNotEqual(feature_vector_0, feature_vector_1)
def test_sound_file(self): that_effect = effect.Effect('dist_lpf') target_sound = sound_file.SoundFile('drums.wav') input_sound = sound_file.SoundFile('noise.wav') sounds = [target_sound, input_sound] project.Project(sounds) num_frames = min(target_sound.get_num_frames(), input_sound.get_num_frames()) print('num_frames', num_frames) constant_parameter_vector = [0.5] * that_effect.num_parameters parameter_vectors = [ copy.deepcopy(constant_parameter_vector) for _ in range(num_frames) ] self.start_time = time.time() cross_adapter = cross_adapt.CrossAdapter(input_sound=input_sound, neural_input_vectors=[], effect=that_effect) output_filename = 'test_cross_adapt.wav' process, output_sound_file, csd_path = cross_adapter.cross_adapt( parameter_vectors, that_effect, output_filename) self.files_to_delete.append(csd_path) print('process', process) print('output file', output_sound_file) print('csd path', csd_path) process.wait() print("Execution time: {0} seconds".format(time.time() - self.start_time))
def cross_adapt(self, parameter_vectors, effect, output_filename): vectors = copy.deepcopy(parameter_vectors) # map normalized values to the appropriate ranges of the effect parameters for i in range(effect.num_parameters): mapping = effect.parameters[i]['mapping'] min_value = mapping['min_value'] max_value = mapping['max_value'] skew_factor = mapping['skew_factor'] for parameter_vector in vectors: parameter_vector[ i] = standardizer.Standardizer.get_mapped_value( normalized_value=parameter_vector[i], min_value=min_value, max_value=max_value, skew_factor=skew_factor) channels = zip(*vectors) channels_csv = [] for channel in channels: channel_csv = ','.join(map(str, channel)) channels_csv.append(channel_csv) self.template.compile(parameter_names=effect.parameter_names, parameter_channels=channels_csv, ksmps=settings.HOP_SIZE, duration=self.input_sound.get_duration(), parameter_lpf_cutoff=self.parameter_lpf_cutoff) csd_path = os.path.join(settings.CSD_DIRECTORY, experiment.Experiment.folder_name, output_filename + '.csd') self.template.write_result(csd_path) csound = csound_handler.CsoundHandler(csd_path) output_file_path = os.path.join(settings.OUTPUT_DIRECTORY, experiment.Experiment.folder_name, output_filename) process = csound.run(input_file_path=self.input_sound.file_path, output_file_path=output_file_path, async=True) output_sound_file = sound_file.SoundFile(output_filename, is_input=False) return process, output_sound_file, csd_path
help='PRNG seed. Will be set to a random value if not specified.', type=int, required=False, default=42) arg_parser.add_argument( '--effect', dest='effect_name', type=str, help= 'The name of the sound effect to use. See the effects folder for options.', required=False, default="dist_lpf") args = arg_parser.parse_args() input_sound = sound_file.SoundFile(args.input_file, is_input=True, verify_file=True) experiment_data = { 'input_sound': input_sound.get_serialized_representation(), 'args': vars(args) } experiment.Experiment.calculate_current_experiment_id(experiment_data) that_effect = effect.Effect(args.effect_name) cross_adapter = cross_adapt.CrossAdapter(input_sound=input_sound, neural_input_vectors=None, effect=that_effect, parameter_lpf_cutoff=10) parameter_vectors = []
) arg_parser.add_argument( '--keep-csd', nargs='?', dest='keep_csd', help='Keep the csd file that was created to generate the extended sound', const=True, required=False, default=False ) arg_parser.add_argument( '--seed', dest='seed', type=int, required=False, default=-1 ) args = arg_parser.parse_args() that_sound = sound_file.SoundFile(args.input, verify_file=True) that_output_file_path = DataAugmenter().augment( that_sound, factor=args.factor, pause_between=args.pause_between, seed=args.seed, keep_csd=args.keep_csd, playback_speed_std_dev=args.playback_speed_std_dev, gain_std_dev=args.gain_std_dev ) print('Successfully created augmented sound: {}'.format(that_output_file_path))
dest='input_files', nargs=3, type=str, help='The filenames of target sound, input sound and output sound respectively', required=True ) arg_parser.add_argument( '--experiment-settings', dest='experiment_settings', type=str, help='Filename of json file in the experiment_settings folder. This file specifies which' ' features to use as neural input and for similarity calculations.', required=False, default="mfcc_basic.json" ) args = arg_parser.parse_args() experiment.Experiment.load_experiment_settings(args.experiment_settings) analyze.Analyzer.init_features_list() target_sound = sound_file.SoundFile(args.input_files[0], is_input=True, verify_file=True) input_sound = sound_file.SoundFile(args.input_files[1], is_input=True, verify_file=True) output_sound = sound_file.SoundFile(args.input_files[2], is_input=False, verify_file=True) that_project = project.Project([target_sound, input_sound]) analyzer = analyze.Analyzer(that_project) analyzer.analyze_multiple([output_sound]) similarity_score = fitness.LocalSimilarityFitness.get_local_similarity(target_sound, output_sound) print(similarity_score)
def __init__(self, args): self.args = args self.seed = random.randint( 1, 999999) if self.args.seed == -1 else self.args.seed if self.args.seed == -1: print('Seed: {}'.format(self.seed)) if len(self.args.input_files) != 2: raise Exception('Two filenames must be specified') self.target_sound = sound_file.SoundFile(self.args.input_files[0], is_input=True, verify_file=True) self.input_sound = sound_file.SoundFile(self.args.input_files[1], is_input=True, verify_file=True) if self.target_sound.num_samples != self.input_sound.num_samples: raise Exception( 'The target sound and the input sound must have the same duration' ) self.project = project.Project([self.target_sound, self.input_sound]) self.analyzer = analyze.Analyzer(self.project) self.fitness_evaluator = None if self.args.fitness == 'similarity': self.fitness_evaluator = fitness.LocalSimilarityFitness( self.target_sound) elif self.args.fitness == 'multi-objective': self.fitness_evaluator = fitness.MultiObjectiveFitness( self.target_sound) elif self.args.fitness == 'hybrid': self.fitness_evaluator = fitness.HybridFitness(self.target_sound) elif self.args.fitness == 'novelty': self.fitness_evaluator = fitness.NoveltyFitness(self.target_sound) elif self.args.fitness == 'mixed': self.fitness_evaluator = fitness.MixedFitness(self.target_sound) self.similarity_evaluator = fitness.LocalSimilarityFitness( self.target_sound) self.num_frames = min(self.target_sound.get_num_frames(), self.input_sound.get_num_frames()) self.neural_input_vectors = [] if self.args.neural_mode == 'a': for k in range(self.num_frames): vector = self.target_sound.get_standardized_neural_input_vector( k) vector.append(1.0) # bias input self.neural_input_vectors.append(vector) elif self.args.neural_mode == 'ab': for k in range(self.num_frames): vector = self.target_sound.get_standardized_neural_input_vector( k) vector += self.input_sound.get_standardized_neural_input_vector( k) vector.append(1.0) # bias input self.neural_input_vectors.append(vector) elif self.args.neural_mode == 'b': for k in range(self.num_frames): vector = self.input_sound.get_standardized_neural_input_vector( k) vector.append(1.0) # bias input self.neural_input_vectors.append(vector) elif self.args.neural_mode == 's': self.args.add_neuron_probability = 0.0 for k in range(self.num_frames): vector = [1.0] # bias input self.neural_input_vectors.append(vector) elif self.args.neural_mode == 'targets': for k in range(self.num_frames): self.neural_input_vectors.append([1.0]) # just bias self.effect = effect.get_effect_instance(self.args.effect_names) self.cross_adapter_class = (cross_adapt.TargetCrossAdapter if self.args.neural_mode == 'targets' else cross_adapt.CrossAdapter) self.cross_adapter = self.cross_adapter_class( input_sound=self.input_sound, neural_input_vectors=self.neural_input_vectors, effect=self.effect, parameter_lpf_cutoff=experiment.Experiment.PARAMETER_LPF_CUTOFF) experiment_data = { 'param_sound': self.target_sound.get_serialized_representation(), 'input_sound': self.input_sound.get_serialized_representation(), 'args': vars(self.args), 'experiment_settings': experiment.Experiment.experiment_settings, 'generations': [], 'feature_statistics': self.project.data['feature_statistics'], 'effect': self.effect.get_serialized_representation() } experiment.Experiment.calculate_current_experiment_id(experiment_data) experiment_data['seed'] = self.seed self.stats_logger = logger.Logger(os.path.join( settings.STATS_DATA_DIRECTORY, experiment.Experiment.folder_name, 'stats.json'), suppress_initialization=True) self.stats_logger.data = experiment_data self.max_similarity = None self.last_fitness_improvement = 0 # generation number if self.args.keep_k_best > -1: self.best_individual_ids = set() self.individual_fitness = {} # individual id => individual fitness self.individual_born = { } # individual id => generation when it was first found self.population = None self.init_neat() run_start_time = time.time() self.run() print("Run execution time: {0:.2f} seconds".format(time.time() - run_start_time)) self.final_clean_up()