Example #1
0
 def retrieve(self):
     signal = SignalObj(self.recData,
                        'time',
                        self.samplingRate,
                        freqMin=20,
                        freqMax=20e3)
     return signal
Example #2
0
 def retrieve(self):
     arr = self.recData.reshape((self.numSamples, self.numInChannels))
     assert arr.ndim == 2
     signal = SignalObj(arr,
                        'time',
                        self.samplingRate,
                        freqMin=20,
                        freqMax=20e3)
     return signal
Example #3
0
 def playrec(self, monitor = Monitor(5512)):
     with Streaming('IO',
                    self.samplingRate,
                    self.device,
                    'float32',
                    0,
                    self.inChannels,
                    self.outChannels,
                    self.excitation,
                    None,
                    self.numSamples,
                    monitor) as strm:
         rec = strm.playrec()
     return SignalObj(rec, 'time', self.samplingRate)
Example #4
0
 def record(self, monitor = Monitor(5512)):
     with Streaming('I',
                    self.samplingRate,
                    self.device,
                    'float32',
                    0,
                    self.inChannels,
                    None,
                    None,
                    None,
                    self.numSamples,
                    monitor) as strm:
         rec = strm.record()
     return SignalObj(rec, 'time', self.samplingRate)
Example #5
0
    def run(self):
        """
        Starts reproducing the excitation signal and recording at the same time
        Outputs a signalObj with the recording content
        """
        # Code snippet to guarantee that generated object name is
        # the declared at global scope
        # for frame, line in traceback.walk_stack(None):
        for framenline in traceback.walk_stack(None):
            # varnames = frame.f_code.co_varnames
            varnames = framenline[0].f_code.co_varnames
            if varnames is ():
                break
        # creation_file, creation_line, creation_function, \
        #     creation_text = \
        extracted_text = \
            traceback.extract_stack(framenline[0], 1)[0]
        # traceback.extract_stack(framenline, 1)[0]
        # creation_name = creation_text.split("=")[0].strip()
        creation_name = extracted_text[3].split("=")[0].strip()

        timeStamp = time.ctime(time.time())
        recording = sd.playrec(self.excitation.timeSignal *
                               self.outputLinearGain,
                               samplerate=self.samplingRate,
                               input_mapping=self.inChannels.mapping,
                               output_mapping=self.outChannels.mapping,
                               device=self.device,
                               blocking=self.blocking,
                               latency='low',
                               dtype='float32')
        recording = np.squeeze(recording)
        recording = SignalObj(signalArray=recording * self.inChannels.CFlist(),
                              domain='time',
                              samplingRate=self.samplingRate,
                              freqMin=self.freqMin,
                              freqMax=self.freqMax)
        recording.channels = self.inChannels
        recording.timeStamp = timeStamp
        recording.comment = 'SignalObj from a PlayRec measurement'
        recording.creation_name = creation_name
        _print_max_level(self.excitation,
                         kind='output',
                         gain=self.outputLinearGain,
                         mapping=self.outChannels.mapping)
        _print_max_level(recording, kind='input')
        return recording
Example #6
0
    def run(self):
        """
        Run method: starts recording during Tmax seconds
        Outputs a signalObj with the recording content
        """
        # Code snippet to guarantee that generated object name is
        # the declared at global scope
        # for frame, line in traceback.walk_stack(None):
        for framenline in traceback.walk_stack(None):
            # varnames = frame.f_code.co_varnames
            varnames = framenline[0].f_code.co_varnames
            if varnames == ():
                break
        # creation_file, creation_line, creation_function, \
        #     creation_text = \
        extracted_text = \
            traceback.extract_stack(framenline[0], 1)[0]
            # traceback.extract_stack(frame, 1)[0]
        # creation_name = creation_text.split("=")[0].strip()
        creation_name = extracted_text[3].split("=")[0].strip()

        # Record
        recording = sd.rec(frames=self.numSamples,
                           samplerate=self.samplingRate,
                           mapping=self.inChannels.mapping,
                           blocking=self.blocking,
                           device=self.device,
                           latency='low',
                           dtype='float32')
        recording = np.squeeze(recording)
        recording = SignalObj(signalArray=recording*self.inChannels.CFlist(),
                              domain='time',
                              samplingRate=self.samplingRate)
        recording.channels = self.inChannels
        recording.timeStamp = time.ctime(time.time())
        recording.freqMin, recording.freqMax\
            = self.freqMin, self.freqMax
        recording.comment = 'SignalObj from a Rec measurement'
        recording.creation_name = creation_name
        _print_max_level(recording, kind='input')
        return recording
Example #7
0
        return len(self.outChannels)

    @property
    def numChannels(self):
        if self.IO == 'I':
            return self.numInChannels
        elif self.IO == 'O':
            return self.numOutChannels
        elif self.IO == 'IO':
            return self.numInChannels, self.numOutChannels


if __name__ == "__main__":

    ms = Measurement(samplingRate=44100,
                     numSamples=2**18,
                     device=0,
                     inChannels=2,
                     outChannels=2)
    mon = Monitor(ms.samplingRate // 8)
    stm = Streaming('I', ms, 'float32', 256, monitor=mon)

    print("\nRecording:")
    audio = stm.record()

    ms.excitation = SignalObj(audio, 'time', stm.samplingRate)
    stm.set_io_properties(ms, 'IO')

    print("\nPlaying:")
    stm.play()