def __init__(self): self.Y = numpy.array([]) self.Fs = 0 self.channels = 0 self.sample_width = 0 self._ext = -1 self._de = AudioDecoder()
class AudioTrack: def __init__(self): self.Y = numpy.array([]) self.Fs = 0 self.channels = 0 self.sample_width = 0 self._ext = -1 self._de = AudioDecoder() def time(self): return 1/self.Fs * self.Y.shape[0] def get_file_ext_code(self): return self._ext def open( self , file_name ): self.Y = numpy.array([]) self.Fs = 0 self.channels = 0 if not ( os.path.exists( file_name ) ) : return False res_f = self._de.read_track_new( file_name , self ) self._ext = self._de.get_file_ext_code() return res_f
def open( self , file_name ): self.Y = numpy.array([]) self.Fs = 0 self.channels = 0 if not ( os.path.exists( file_name ) ) : return False de = AudioDecoder() res_f = de.read_track_new( file_name , self ) return res_f
def scan_dir(self, dir_name, files_list=None): self._album = {} self._tracks = {} self._artist = {} self._disk_nr = [] if files_list == None: dir_name = os.path.abspath(dir_name) files_list = sorted(os.listdir(dir_name)) ad = AudioDecoder() for file_name in files_list: (fn, ext) = os.path.splitext(file_name) full_file = os.path.join(dir_name, file_name) if ext in ad.formats: try: self.scan_file(full_file) except UnreadableAudioFileException as uafe: pass
def scan_mp(self, dir_name="", thread_cnt=2, files_list=[]): if sys.version_info[0] == 2: dir_name = dir_name.decode('utf-8') self.dr14 = 0 job_queue_sh = mp.JoinableQueue(2000) res_queue_sh = mp.Queue(2000) if files_list == []: if not os.path.isdir(dir_name): return 0 dir_list = sorted(os.listdir(dir_name)) self.dir_name = dir_name files_list = None else: dir_list = sorted(files_list) ad = AudioDecoder() for file_name in dir_list: (fn, ext) = os.path.splitext(file_name) if ext in ad.formats: job = SharedDrResObj() job.file_name = file_name job.dir_name = dir_name job_queue_sh.put(job) threads = [1 for i in range(thread_cnt)] job_free = mp.Value('i', 0) for t in range(thread_cnt): threads[t] = mp.Process(target=self.run_mp, args=(job_queue_sh, res_queue_sh)) for t in range(thread_cnt): threads[t].start() job_queue_sh.join() succ = 0 self.res_list = [] #i = 0 dur = StructDuration() while not res_queue_sh.empty(): res = res_queue_sh.get() if res.fail: continue self.res_list.append({ 'file_name': res.file_name, 'dr14': res.dr14, 'dB_peak': res.dB_peak, 'dB_rms': res.dB_rms, 'duration': dur.float_to_str(res.duration), 'sha1': res.sha1 }) self.res_list = sorted(self.res_list, key=lambda res: res['file_name']) # i = i + 1 for d in self.res_list: if d['dr14'] > dr14.min_dr(): self.dr14 = self.dr14 + d['dr14'] succ = succ + 1 self.meta_data.scan_dir(dir_name, files_list) if len(self.res_list) > 0 and succ > 0: self.dr14 = int(round(self.dr14 / succ)) return succ else: return 0