def dummyFill(self): # Preenche o dicionário de dados medidos com sinais nulos. dummyFill = cp.deepcopy(self.MS.excitationSignals) # for key in dummyFill: for sourceCode in self.MS.outChannel: for rN in range(1,self.MS.receiversNumber+1): self.measuredData[sourceCode+'R'+str(rN)] = {} # Insere as chaves referente as configurações fonte receptor for key in self.MS.excitationSignals: self.measuredData[sourceCode+'R'+str(rN)][key] = {\ 'binaural':\ [pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),2),domain='time',samplingRate=self.MS.samplingRate), pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),2),domain='time',samplingRate=self.MS.samplingRate), pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),2),domain='time',samplingRate=self.MS.samplingRate)], 'hc': [pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),1),domain='time',samplingRate=self.MS.samplingRate), pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),1),domain='time',samplingRate=self.MS.samplingRate), pytta.SignalObj(np.random.rand(len(dummyFill[key].timeSignal),1),domain='time',samplingRate=self.MS.samplingRate)]} # Insere as chaves referentes ao sinal de excitação e tipo de gravação self.status[sourceCode+'R'+str(rN)][key] = {'binaural':True,'hc':True} # Insere as chaves referentes ao sinal de excitação e tipo de gravação noisefloorstr = 'pytta.SignalObj(np.random.rand(self.MS.noiseFloorTp*self.MS.samplingRate,1),domain="time",samplingRate=self.MS.samplingRate)' self.measuredData['noisefloor'] = [[eval(noisefloorstr),eval(noisefloorstr),eval(noisefloorstr)], [eval(noisefloorstr),eval(noisefloorstr),eval(noisefloorstr)]] # Cria lista de medições de ruído de fundo self.status['noisefloor'] = True # Cria lista de medições de ruído de fundo self.measuredData['calibration'] = {} # Cria dicionário com os canais de entrada da medição calibrationstr = 'pytta.SignalObj(np.random.rand(self.MS.calibrationTp*self.MS.samplingRate,1),domain="time",samplingRate=self.MS.samplingRate)' for chN in self.MS.inChName: self.measuredData['calibration'][chN] = [[eval(calibrationstr),eval(calibrationstr),eval(calibrationstr)], [eval(calibrationstr),eval(calibrationstr),eval(calibrationstr)]]# Cria uma lista de calibrações para cada canal self.status['calibration'][chN] = True
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Jun 16 16:39:48 2019 @author: joaovitor """ import pytta import numpy as np from scipy.io import loadmat from matplotlib import pyplot as plt f = loadmat('RIS/RI_mono_1.mat') mySignal = pytta.SignalObj(f['MonoRIS1_time'], 'time', 44100) myRT = pytta.rooms.RT(20, mySignal, 3) myD50 = pytta.rooms.D(50, mySignal, 1) myC80 = pytta.rooms.C(80, mySignal, 6)
# Carregando sinal de música excitationSignals['musica'] = pytta.read_wav( 'audio/Piano Over the rainbow Mic2 SHORT_edited.wav') # Carregando sinal de fala excitationSignals['fala'] = pytta.read_wav( 'audio/Voice Sabine Short_edited.WAV') # %% Carrega sensibilidade do microfone para compensação na cadeia de entrada loadtxt = np.loadtxt(fname='14900_no_header.txt') mSensFreq = loadtxt[:, 0] mSensdBMag = loadtxt[:, 1] # plt.semilogx(mSensFreq, mSensdBMag) # %% Carrega resposta da fonte para compensação na cadeia de saida matLoad = io.loadmat('hcorrDodecCTISM2m_Brum.mat') ir = pytta.SignalObj(matLoad['hcorrDodecCTISM2m'], 'time', 44100) sSensFreq = ir.freqVector sourceSens = 1 / np.abs(ir.freqSignal)[:, 0] normIdx = np.where(sSensFreq > 1000)[0][0] sourceSens = sourceSens / sourceSens[normIdx] sSensdBMag = 20 * np.log10(sourceSens) # plt.semilogx(sSensFreq, sSensdBMag) # %% Cria novo setup de medição e inicializa objeto de dados, que gerencia o # MeasurementSetup e os dados da medição em disco MS = rmr.MeasurementSetup( name='med-teste', # Nome da medição samplingRate=44100, # [Hz] # Sintaxe : device = [<in>,<out>] ou <in/out> # Utilize pytta.list_devices() para listar # os dispositivos do seu computador.
def save(self, dataObj): # Desmembra o SignalObj measureTake de 4 canais em 3 SignalObj referentes ao arranjo biauricular # em uma posição e ao centro da cabeça em duas outras posições if self.kind == 'newpoint' or self.kind == 'noisefloor': chcont = 0 self.binaural = [] self.hc1 = [] self.hc2 = [] if self.channelStatus[0] and self.channelStatus[1]: for i in range(0, self.averages): self.binaural.append( pytta.SignalObj( self.measuredTake[i].timeSignal[:, chcont:chcont + 2], 'time', samplingRate=self.measuredTake[i].samplingRate, comment=self.excitation)) self.binaural[-1].channels[0].name = self.MS.inChName[0] self.binaural[-1].channels[1].name = self.MS.inChName[1] if self.kind == 'noisefloor': SR = [self.receiver[0], self.receiver[1]] else: SR = [ self.source + self.receiver[0], self.source + self.receiver[1] ] self.binaural[i].sourceReceiver = SR self.binaural[i].temp = self.measuredTake[i].temp self.binaural[i].RH = self.measuredTake[i].RH self.binaural[i].timeStamp = self.measuredTake[i].timeStamp chcont = chcont + 2 if self.channelStatus[2]: for i in range(0, self.averages): self.hc1.append( pytta.SignalObj( self.measuredTake[i].timeSignal[:, chcont], 'time', samplingRate=self.measuredTake[i].samplingRate, comment=self.excitation)) self.hc1[-1].channels[0].name = self.MS.inChName[2] if self.kind == 'noisefloor': SR = self.receiver[2] else: SR = self.source + self.receiver[2] self.hc1[i].sourceReceiver = SR self.hc1[i].temp = self.measuredTake[i].temp self.hc1[i].RH = self.measuredTake[i].RH self.hc1[i].timeStamp = self.measuredTake[i].timeStamp chcont = chcont + 1 if self.channelStatus[3]: for i in range(0, self.averages): self.hc2.append( pytta.SignalObj( self.measuredTake[i].timeSignal[:, chcont], 'time', samplingRate=self.measuredTake[i].samplingRate, comment=self.excitation)) self.hc2[-1].channels[0].name = self.MS.inChName[3] if self.kind == 'noisefloor': SR = self.receiver[3] else: SR = self.source + self.receiver[3] self.hc2[i].sourceReceiver = SR self.hc2[i].temp = self.measuredTake[i].temp self.hc2[i].RH = self.measuredTake[i].RH self.hc2[i].timeStamp = self.measuredTake[i].timeStamp # Salva dados no dicionário do objeto de dados dataObj taketopkl = {'measuredData': {}, 'status': {}} if self.kind == 'newpoint': # Adiciona cada uma das três posições de receptor da última tomada de medição if self.channelStatus[0] and self.channelStatus[1]: dataObj.measuredData[self.binaural[0].sourceReceiver[0]][ self.binaural[0].comment]['binaural'] = self.binaural taketopkl['measuredData'][ self.binaural[0].sourceReceiver[0]] = { self.binaural[0].comment: { 'binaural': self.binaural } } dataObj.status[self.binaural[0].sourceReceiver[0]][ self.binaural[0].comment]['binaural'] = True taketopkl['status'][self.binaural[0].sourceReceiver[0]] = { self.binaural[0].comment: { 'binaural': True } } if self.channelStatus[2]: dataObj.measuredData[self.hc1[0].sourceReceiver][ self.hc1[0].comment]['hc'] = self.hc1 taketopkl['measuredData'][self.hc1[0].sourceReceiver] = { self.hc1[0].comment: { 'hc': self.hc1 } } dataObj.status[self.hc1[0].sourceReceiver][ self.hc1[0].comment]['hc'] = True taketopkl['status'][self.hc1[0].sourceReceiver] = { self.hc1[0].comment: { 'hc': True } } if self.channelStatus[3]: dataObj.measuredData[self.hc2[0].sourceReceiver][ self.hc2[0].comment]['hc'] = self.hc2 taketopkl['measuredData'][self.hc2[0].sourceReceiver] = { self.hc2[0].comment: { 'hc': self.hc2 } } dataObj.status[self.hc2[0].sourceReceiver][ self.hc2[0].comment]['hc'] = True taketopkl['status'][self.hc2[0].sourceReceiver] = { self.hc2[0].comment: { 'hc': True } } if self.kind == 'noisefloor': newNF = {} if self.channelStatus[0] and self.channelStatus[1]: newNF[self.binaural[0].sourceReceiver[0]] = self.binaural if self.channelStatus[2]: newNF[self.hc1[0].sourceReceiver] = self.hc1 if self.channelStatus[3]: newNF[self.hc2[0].sourceReceiver] = self.hc2 dataObj.measuredData['noisefloor'].append(newNF) taketopkl['measuredData']['noisefloor'] = newNF dataObj.status['noisefloor'] = True taketopkl['status']['noisefloor'] = True if self.kind == 'calibration': self.calibAverages = [] # Pegando o nome do canal calibrado j = 0 for i in self.channelStatus: if i: self.inChName = [self.MS.inChName[j]] j = j + 1 for i in range(0, self.averages): self.calibAverages.append( pytta.SignalObj( self.measuredTake[i].timeSignal[:, 0], 'time', samplingRate=self.measuredTake[i].samplingRate, # channelName=self.inChName, comment=self.excitation)) self.calibAverages[i].channels[0].name = self.MS.inChName[0] # self.calibAverages[i].sourceReceiver = self.sourceReceiver[2] self.calibAverages[i].temp = self.measuredTake[i].temp self.calibAverages[i].RH = self.measuredTake[i].RH self.calibAverages[i].timeStamp = self.measuredTake[ i].timeStamp dataObj.measuredData['calibration'][self.inChName[0]].append( self.calibAverages) taketopkl['measuredData']['calibration'] = { self.inChName[0]: self.calibAverages } dataObj.status['calibration'][self.inChName[0]] = True taketopkl['status']['calibration'] = {self.inChName[0]: True} if self.tempHumid != None: self.tempHumid.stop() # Save last take to file mypath = getcwd() + '/' + self.MS.name + '/' mytakefilesprefix = self.MS.name + '_D_take-' myMSfile = self.MS.name + '_MS' if not exists(mypath): mkdir(mypath) myfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] lasttake = 0 saveMS = True for file in myfiles: if mytakefilesprefix in file: newlasttake = file.replace(mytakefilesprefix, '') newlasttake = int(newlasttake.replace('.pkl', '')) if newlasttake > lasttake: lasttake = newlasttake if myMSfile in file: saveMS = False if saveMS: msD = { 'averages': self.MS.averages, 'calibrationTp': self.MS.calibrationTp, 'device': self.MS.device, 'excitationSignals': self.MS.excitationSignals, 'freqMax': self.MS.freqMax, 'freqMin': self.MS.freqMin, 'inChName': self.MS.inChName, 'inChannel': self.MS.inChannel, 'measurementObjects': self.MS.measurementObjects, 'name': self.MS.name, 'noiseFloorTp': self.MS.noiseFloorTp, 'outChannel': self.MS.outChannel, 'receiversNumber': self.MS.receiversNumber, 'samplingRate': self.MS.samplingRate, 'sourcesNumber': self.MS.sourcesNumber } output = open(mypath + myMSfile + '.pkl', 'wb') pickle.dump(msD, output) output.close() output = open(mypath + mytakefilesprefix + str(lasttake + 1) + '.pkl', 'wb') pickle.dump(taketopkl, output) output.close()
def renew_audio(self): self.audio = pytta.SignalObj(self.file.read(), 'time', self.file.samplerate) self.file.close() return