Ejemplo n.º 1
0
 def __init__(self, schedulerType, mmuType, memCompact):
     self.running = False
     self.kernelMode = False
     self.mmu = mmuType
     self.pcbt = {}
     self.cpu = None
     self.io = None
     self.pid_counter = 0
     self.current_pid = None
     self.idle = True
     self.scheduler = schedulerType
     self.longScheduler = PLP()
     self.memCompact = memCompact
Ejemplo n.º 2
0
class Kernel:
    lock = threading.RLock()
    
    def __init__(self, schedulerType, mmuType, memCompact):
        self.running = False
        self.kernelMode = False
        self.mmu = mmuType
        self.pcbt = {}
        self.cpu = None
        self.io = None
        self.pid_counter = 0
        self.current_pid = None
        self.idle = True
        self.scheduler = schedulerType
        self.longScheduler = PLP()
        self.memCompact = memCompact
    
    def  start(self):
        print('[kernel] starting...')
        
        if not self.running:
            self.running = 1
            self.cpu = CPU(self, self.mmu)
            self.cpu.start()
            self.io = IO(self)
            self.io.start()
            print('[kernel] started.')
        
    def stop(self):
        self.running = False
        sys.exit(0)
    
    def interrupt(self, signal):
        self.lock.acquire()
        
        self.kernelMode = True
        
        try: 
            signal.execute(self)
        finally:
            self.kernelMode = False
            self.lock.release()
    
    def run(self, prog): 
        self.lock.acquire()
        
        try:
            pid = self.pid_counter
            self.pid_counter = self.pid_counter + 1
            self.pcbt[pid] = PCB(pid, prog.priority, 0)
            self.longScheduler.add(self, self.pcbt[pid], prog, self.memCompact)
        finally:
            self.lock.release()
        
        print('[kernel.run] pid %d: %s'%(pid, prog))
        
        self.interrupt(SignalNew())
    
    def setQuantum(self, quantum):
        self.scheduler.setQuantum(quantum)
    
    def getCPUburstTime(self):
        return self.cpu.burstTime
    
    def canLoad(self, prog):
        return self.mmu.canLoad(prog)
    
    def load(self, pcb, prog):
        self.mmu.load(pcb, prog)
    
    def longReschedule(self):
        self.longScheduler.reschedule(self)
    
    def reschedule(self):
        self.scheduler.reschedule(self)
    
    def compact(self):
        self.mmu.compact(self.pcbt)
        
    def exit(self):
        self.cpu.pcb = None
        self.mmu.unload(self.pcbt[self.current_pid])
        del self.pcbt[self.current_pid]
        self.current_pid = None
    
    def set_idle(self):
        self.idle = True
def features(filename,varin):


    fs              = varin['fs']
    framesize       = varin['framesize']
    hopsize         = varin['hopsize']
    feature_select  = varin['feature_select']

    audio           = ess.MonoLoader(downmix = 'left', filename = filename, sampleRate = fs)()

    # spectrogram init
    winAnalysis     = 'hann'
    N               = 2 * framesize                     # padding 1 time framesize
    SPECTRUM        = ess.Spectrum(size=N)
    WINDOW          = ess.Windowing(type=winAnalysis, zeroPadding=N-framesize)
    highFrequencyBound = fs/2 if fs/2<11000 else 11000
    MFCC            = ess.MFCC(sampleRate=fs,highFrequencyBound=highFrequencyBound,inputSize=framesize+1)
    GFCC            = ess.GFCC(sampleRate=fs,highFrequencyBound=highFrequencyBound)
    ZCR             = ess.ZeroCrossingRate()
    ENERGY          = ess.Energy()
    mfcc            = []
    mfccBands       = []
    gfcc            = []
    energy          = []
    zcr             = []
    autoCorrelation = []
    mX              = []

    print 'calculating ', feature_select, ' ... ...'

    for frame in ess.FrameGenerator(audio, frameSize=framesize, hopSize=hopsize):

        frame_audio     = frame
        frame           = WINDOW(frame)
        mXFrame         = SPECTRUM(frame)
        mX.append(mXFrame)

        energyFrame     = ENERGY(mXFrame)
        energy.append(energyFrame)

        if feature_select == 'mfcc' or feature_select == 'dmfcc':
            bands,mfccFrame = MFCC(mXFrame)
            mfccFrame       = mfccFrame[1:]
            mfcc.append(mfccFrame)

        if feature_select == 'mfccBands':
            bands,mfccFrame = MFCC(mXFrame)
            mfccBands.append(bands)

        if feature_select == 'gfcc':
            bands,gfccFrame = GFCC(mXFrame)
            gfccFrame       = gfccFrame[1:]
            gfcc.append(gfccFrame)

        if feature_select == 'zcr':
            zcrFrame        = ZCR(frame_audio)
            zcr.append(zcrFrame)

        if feature_select == 'autoCorrelation':
            autoCorrelationFrame = np.corrcoef(frame_audio)
            autoCorrelation.append(autoCorrelationFrame)

    mX              = np.array(mX)

    if feature_select == 'mfcc':
        feature         = np.array(mfcc)

    elif feature_select == 'dmfcc':
        dmfcc           = Fdeltas(np.array(mfcc).transpose(),w=9)
        ddmfcc          = Fdeltas(dmfcc,w=5)
        feature         = np.transpose(np.vstack((dmfcc,ddmfcc)))

    elif feature_select == 'mfccBands':
        feature         = np.array(mfccBands)

    elif feature_select == 'gfcc':
        feature         = np.array(gfcc)

    elif feature_select == 'plpcc':
        feature,plp,bark    = PLP(mX,modelorder=12,rasta=False)
        feature         = feature[:,1:]

    elif feature_select == 'plp':
        plpcc,feature,bark  = PLP(mX,modelorder=12,rasta=False)
        feature         = feature[:,1:]

    elif feature_select == 'rasta-plpcc':
        feature,plp,bark    = PLP(mX,modelorder=12,rasta=True)
        feature         = feature[:,1:]

    elif feature_select == 'rasta-plp':
        plpcc,feature,bark  = PLP(mX,modelorder=12,rasta=True)
        feature         = feature[:,1:]

    elif feature_select == 'bark':
        plpcc,plp,feature   = PLP(mX,modelorder=12,rasta=False)

    elif feature_select == 'zcr':
        feature             = np.array(zcr)

    elif feature_select == 'autoCorrelation':
        feature             = np.array(autoCorrelation)

    else:
        feature,d_MRCG,dd_MRCG = MRCG(audio,fs=fs)

    return feature,energy,mX