def run(args, logger): mg.log( warning_handler=logger.warning, info_handler=logger.info, debug_handler=logger.debug, ) bit_to_subtype = {16: "PCM_16", 24: "PCM_24", 32: "FLOAT"} logger.debug(f"{mg.__title__} {mg.__version__}") logger.debug(f"Maintained by {mg.__author__}: {mg.__email__}") logger.debug(f'Contributors: {", ".join(mg.__credits__)}') try: mg.process( target=args.target, reference=args.reference, results=[ mg.Result( args.result, bit_to_subtype.get(args.bit), use_limiter=not args.no_limiter, normalize=not args.dont_normalize, ) ], ) except Exception as e: logger.exception("Got the exception while executing mg.process()")
def show_index(): """Display / route.""" final_dict = {} if 'username' in flask.session: # Get the username user = flask.session['username'] final_dict['login'] = True final_dict['username'] = user final_dict['submitted'] = False # Database portion if flask.request.method == 'POST': print(flask.request.form["guitar_select"]) src_file, ref_file, input_src, input_ref = tonefinder.views.util.save_file( ) print(src_file) if src_file != "" and ref_file != "": target_file = input_src target_dir = os.path.join( tonefinder.app.config['TRANSFORMED_FOLDER'], user) if not os.path.isdir(target_dir): os.mkdir(target_dir) target_path = os.path.join(target_dir, target_file) ir = input_src[:-4] + "_" + input_ref[:-4] + "_ir.wav" ir_dir = os.path.join(tonefinder.app.config['IR_FOLDER'], user) if not os.path.isdir(ir_dir): os.mkdir(ir_dir) ir_path = os.path.join(ir_dir, ir) mg.process( target=src_file, reference=ref_file, # pcm16 and pcm24 are just basic shortcuts # You can also use the Result class to make some advanced results results=[ mg.Result(target_path, subtype="PCM_24", use_limiter=False) ], ir_file=ir_path) final_dict['submitted'] = True final_dict['transformed'] = target_file final_dict['irfile'] = ir return flask.render_template("index.html", **final_dict) else: return flask.redirect(flask.url_for('login'))
def process(session: MGSession): if session.code != 2002: return paths = Paths(session.target.file.name, session.target.title) updater = SessionUpdater(session, paths) mg.log(info_handler=updater.info, warning_handler=updater.warning, show_codes=True) try: mg.process( target=media(session.target.file.name), reference=media(session.reference.file.name), results=[ mg.pcm16(media(paths.result16)), mg.pcm24(media(paths.result24)), ], preview_target=mg.pcm16(media(paths.preview_target)), preview_result=mg.pcm16(media(paths.preview_result)), ) except Exception as e: updater.info(str(e))
import matchering as mg # Sending all log messages to the default print function # Just delete the following line to work silently mg.log(print) mg.process( # The track you want to master target='my_song.wav', # Some "wet" reference track reference='some_popular_song.wav', # Where and how to save your results results=[ mg.pcm16('my_song_master_16bit.wav'), mg.pcm24('my_song_master_24bit.wav'), ])
import matchering as mg # Let's keep only warning outputs here, muting everything else mg.log(warning_handler=print) mg.process( target="my_song.wav", reference="some_popular_song.wav", results=[ mg.pcm16("my_song_master_16bit.wav"), mg.pcm24("my_song_master_24bit.wav"), ], # These two lines will allow you to create two 30-second FLAC files with the loudest parts of: # 'my_song.wav' and 'my_song_master_16bit.wav' # Use them to quickly compare the target audio with the resulting audio preview_target=mg.pcm16("preview_my_song.flac"), preview_result=mg.pcm16("preview_my_song_master.flac"), )
import matchering as mg # Let's keep info and warning outputs here, muting out the debug ones mg.log(info_handler=print, warning_handler=print) mg.process( target="audio_files/251.wav", reference="audio_files/fender_251.wav", # pcm16 and pcm24 are just basic shortcuts # You can also use the Result class to make some advanced results results=[ # Basic WAV 16-bit, match + master mg.pcm16("my_song_master_16bit.wav"), # FLAC 24-bit, match only (no limiter), normalized to -0.01 dB # Recommendations for adjusting the amplitude will be displayed in the debug print if it is enabled mg.Result("custom_result_24bit_no_limiter.wav", subtype="PCM_24", use_limiter=False), # AIFF 32-bit float, match only (no limiter), non-normalized # Can exceed 0 dB without clipping # So you can directly feed it to some VST limiter in your DAW # More available formats and subtypes: # https://pysoundfile.readthedocs.io/en/latest/#soundfile.available_formats # https://pysoundfile.readthedocs.io/en/latest/#soundfile.available_subtypes ], ir_file="mid_ir.wav")
# The warning output will be highlighted with exclamation marks on both sides def warning(text): my_print("!" * 20) my_print(f"! WARNING: {text}") my_print("!" * 20) # Set new handlers mg.log(warning_handler=warning, info_handler=info, debug_handler=my_print) mg.process( target="my_song.wav", reference="some_popular_song.wav", results=[ mg.pcm16("my_song_master_16bit.wav"), mg.pcm24("my_song_master_24bit.wav"), ], ) # These settings will result in the following text output: # ... # 2020-01-11 11:03:29.225821: INFO: Loading and analysis # 2020-01-11 11:03:29.225821: Loading the TARGET file: 'my_song.wav'... # 2020-01-11 11:03:29.396622: The TARGET file is loaded # 2020-01-11 11:03:29.396622: TARGET audio length: 22932000 samples (0:08:40) # 2020-01-11 11:03:30.528787: !!!!!!!!!!!!!!!!!!!! # 2020-01-11 11:03:30.528787: ! WARNING: The applied limiter is detected in the TARGET file... # 2020-01-11 11:03:30.528787: !!!!!!!!!!!!!!!!!!!! # 2020-01-11 11:03:30.528787: Loading the REFERENCE file: 'some_popular_song.wav'... # ...
mg.process( target='my_song.wav', reference='some_popular_song.wav', # pcm16 and pcm24 are just basic shortcuts # You can also use the Result class to make some advanced results results=[ # Basic WAV 16-bit, match + master mg.pcm16('my_song_master_16bit.wav'), # FLAC 24-bit, match only (no limiter), normalized to -0.01 dB # Recommendations for adjusting the amplitude will be displayed in the debug print if it is enabled mg.Result( 'custom_result_24bit_no_limiter.flac', subtype='PCM_24', use_limiter=False ), # AIFF 32-bit float, match only (no limiter), non-normalized # Can exceed 0 dB without clipping # So you can directly feed it to some VST limiter in your DAW mg.Result( 'custom_result_32bit_no_limiter_non-normalized.aiff', subtype='FLOAT', use_limiter=False, normalize=False ) # More available formats and subtypes: # https://pysoundfile.readthedocs.io/en/latest/#soundfile.available_formats # https://pysoundfile.readthedocs.io/en/latest/#soundfile.available_subtypes ] )
def main_automaster(args, **kwargs): # convert from auto args template # TODO: if len(targets) == len(references) then match up, otherwise random choice, otherwise single # print(f"main_automaster args {args}") # if type(args.references) in [list]: # args.references = args.references[0] if len(args.references) == 1: references = [args.references[0] for _ in range(len(args.filenames))] elif len(args.references) == len(args.filenames): references = args.references else: references = [random.choice(args.references) for _ in range(len(args.filenames))] if args.verbose: print(f"main_automaster references {references}") automaster_results = { 'targets': [], 'references': [], 'results': [], } # print(f"main_automaster filenames {args.filenames}") # print(f"main_automaster references {references}") for target_i, target in enumerate(args.filenames): reference = references[target_i] # filename_export = f"{target[:-4]}_master{args.bitdepth}.wav" filename_export = os.path.join( args.rootdir, os.path.basename(args.filename_export) + ".wav") if args.verbose: print(f"main_automaster target {target}, reference {reference}, bitdepth {args.bitdepth}") print(f"main_automaster outputs {filename_export}") if not os.path.exists(target) or not os.path.exists(reference): print(f"main_automaster target {target} or reference {reference} doesnt exist") continue if args.bitdepth == 16: result = mg.pcm16(filename_export) else: result = mg.pcm24(filename_export) mg.process( # The track you want to master target=target, # Some "wet" reference track reference=reference, # Where and how to save your results results=[result], ) # print(f"automaster result = {result}") automaster_results['targets'].append(target) automaster_results['references'].append(reference) automaster_results['results'].append(filename_export) results = { 'data': { 'output_files': [ {'format': args.outputs[0], 'filename': os.path.basename(automaster_results['results'][0])} ], } } filename_result = os.path.join( args.rootdir, os.path.basename(args.filename_export) + ".json") # this saves the array in .json format json.dump( results, codecs.open(filename_result, 'w', encoding='utf-8'), # separators=(',', ':'), # sort_keys=True, # indent=4, # cls=NumpyEncoder, ) if 'task' in kwargs: kwargs['task'].set_done(result_location=os.path.basename(args.filename_export) + ".json") return results
# Let's completely disable any text output here # mg.log(print) mg.process( target='my_song.wav', reference='some_popular_song.wav', results=[ mg.pcm16('my_song_master_16bit.wav'), mg.pcm24('my_song_master_24bit.wav'), ], # Create a custom Config instance to edit matchering configuration # Think twice before you change something here config=mg.Config( # Increase the maximum length to 30 minutes from the default value of 15 max_length=30 * 60, # Increase the internal and resulting sample rate to 96 kHz from the default value of 44.1 kHz internal_sample_rate=96000, # Change the threshold value (float, not dB) from the default value of 0.9981 (-0.01 dB) threshold=0.7079, # -3 dB # Change the temp folder to work with ffmpeg temp_folder='/tmp', # Lower the preview length to 15 seconds from the default value of 30 preview_size=15, # Allow matchering to accept the same files (useless in fact) allow_equality=True # Etc... # The remaining parameters will be filled with default values # Examine defaults.py to find other parameters ))
my_print(f'INFO: {text}') # The warning output will be highlighted with exclamation marks on both sides def warning(text): my_print('!' * 20) my_print(f'! WARNING: {text}') my_print('!' * 20) # Set new handlers mg.log(warning_handler=warning, info_handler=info, debug_handler=my_print) mg.process(target='my_song.wav', reference='some_popular_song.wav', results=[ mg.pcm16('my_song_master_16bit.wav'), mg.pcm24('my_song_master_24bit.wav'), ]) # These settings will result in the following text output: # ... # 2020-01-11 11:03:29.225821: INFO: Loading and analysis # 2020-01-11 11:03:29.225821: Loading the TARGET file: 'my_song.wav'... # 2020-01-11 11:03:29.396622: The TARGET file is loaded # 2020-01-11 11:03:29.396622: TARGET audio length: 22932000 samples (0:08:40) # 2020-01-11 11:03:30.528787: !!!!!!!!!!!!!!!!!!!! # 2020-01-11 11:03:30.528787: ! WARNING: The applied limiter is detected in the TARGET file... # 2020-01-11 11:03:30.528787: !!!!!!!!!!!!!!!!!!!! # 2020-01-11 11:03:30.528787: Loading the REFERENCE file: 'some_popular_song.wav'... # ...
ref_k_default = '11.84.0.-1.0-1.1-1' args.reference = references[ref_k_default]['filename'] target_k = args.target[:-4] ref_k = args.reference[:-4] print(f'processing') print(f' target {args.target}') print(f' ref {args.reference}') # reference = references['sampa_daratofly']['filename'] # reference = references['dj-stingray-cryptic']['filename'] results = [] if args.bitdepth == 24: results.append(mg.pcm24('{0}_master_24bit.wav'.format(target_k))) else: results.append(mg.pcm16('{0}_master_16bit.wav'.format(target_k))) mg.process( # The track you want to master target=args.target, # Some "wet" reference track # reference=, reference=args.reference, # Where and how to save your results results=results, )