def SetLowpass(self, frequency, order=16): if frequency is not None: sumpf.deactivate_output(self.__bypass_filter.GetOutput) method_pairs = [(self.__filter.SetFilterFunction, sumpf.modules.FilterGenerator.BUTTERWORTH(order=order)), (self.__filter.SetFrequency, frequency), (self.__bypass_filter.SetSelection, self.__FILTER)] sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator) else: self.__bypass_filter.SetSelection(self.__BYPASS)
def SetNLFunctions(self, nonlinearfunctions): """ Sets the nonlinear functions of the Hammerstein group model. :param nonlinearfunctions: the tuple of nonlinear functions eg. (nlsp.function_factory.power_series(1),...) """ nonlinfunc = [] for i in range(len(self.hmodels)): nonlinfunc.append((self.hmodels[i].SetNLFunction, nonlinearfunctions[i])) sumpf.set_multiple_values(nonlinfunc)
def SetInput(self, signal): """ Sets the input to the Hammerstein group model. :param signal: the input signal """ inputs = [] for i in range(len(self.hmodels)): inputs.append((self.hmodels[i].SetInput, signal)) sumpf.set_multiple_values(inputs)
def SetMaximumHarmonics(self, maxharmonics): """ Sets the maximum orders of distortions produced by the nonlinear function. :param maxharmonics: the tuple of maximum harmonics eg. (1,...) """ harmonics = [] for i in range(len(self.hmodels)): harmonics.append((self.hmodels[i].SetMaximumHarmonic, maxharmonics[i])) sumpf.set_multiple_values(harmonics)
def SetInput(self, input_signal=None): """ Set the input to the model. :param input_signal: the input signal """ inputs = [] for i in range(len(self.__hmodels)): inputs.append((self.__hmodels[i].SetInput, input_signal)) sumpf.set_multiple_values(inputs)
def SetRegularization(self, start_frequency, stop_frequency, transition_width, epsilon_max): if epsilon_max == 0.0: self.__select_regularization.SetSelection(self.__NOT_REGULARIZE) else: method_pairs = [(self.__regularization.SetStartFrequency, start_frequency), (self.__regularization.SetStopFrequency, stop_frequency), (self.__regularization.SetTransitionLength, int(round(transition_width / self.__properties.GetResolution()))), (self.__regularization.SetEpsilonMax, epsilon_max), (self.__select_regularization.SetSelection, self.__REGULARIZE)] sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator)
def SetFilterIRS(self, impulseresponse): """ Sets the impulse response of the linear blocks of the Hammerstein group model. :param impulseresponse: the tuple of filter impulse responses eg. (IR1,...) :return: """ irs = [] for i in range(len(self.hmodels)): irs.append((self.hmodels[i].SetFilterIR, impulseresponse[i])) sumpf.set_multiple_values(irs)
def SetWindow(self, function, interval=None): if function is not None: method_pairs = [(self.__bypass_window.SetSelection, self.__WINDOW), (self.__window.SetFunction, function)] if interval is not None: linterval = [] for d in interval: index = sumpf.modules.DurationToLength(duration=d, samplingrate=self.__properties.GetSamplingRate()).GetLength() linterval.append(index) method_pairs.append((self.__window.SetFallInterval, linterval)) sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator) else: self.__bypass_window.SetSelection(self.__BYPASS)
def Start(self, amplitude, sweep_duration, silence_duration, start_frequency, stop_frequency, sweep_function, fade, averages, capture_port, playback_port): """ Starts the recording process. @param amplitude: @param sweep_duration: @param silence_duration: @param start_frequency: @param stop_frequency: @param sweep_function: @param fade: a time in seconds as a float, that specifies the length of the fade in and fade out of the sweep @param averages: @param capture_port: the name of the other program's capture port @param playback_port: the name of the other program's playback port """ self.__has_data = True # connect to jack jack_input = self.__audio_io.GetInputs()[0] jack_output = self.__audio_io.GetOutputs()[0] if capture_port is not None: self.__audio_io.Connect(jack_output, capture_port) if playback_port is not None: self.__audio_io.Connect(playback_port, jack_input) # prepare settings method_pairs = [] method_pairs.append((self.__generator.SetStartFrequency, start_frequency)) method_pairs.append((self.__generator.SetStopFrequency, stop_frequency)) method_pairs.append((self.__generator.SetSweepFunction, (sumpf.modules.SweepGenerator.LINEAR, sumpf.modules.SweepGenerator.EXPONENTIAL, sumpf.modules.SweepGenerator.SYNCHRONIZED)[sweep_function])) if sweep_duration is not None: method_pairs.append((self.__sweep_duration.SetDuration, sweep_duration)) if silence_duration is not None: method_pairs.append((self.__silence_duration.SetDuration, silence_duration)) fade_length = sumpf.modules.DurationToLength(duration=fade, samplingrate=self.__properties.GetSamplingRate()).GetLength() if fade_length == 0: method_pairs.append((self.__generator.SetInterval, None)) method_pairs.append((self.__fade_sweep.SetRaiseInterval, None)) method_pairs.append((self.__fade_sweep.SetFallInterval, None)) else: method_pairs.append((self.__generator.SetInterval, (fade_length, -fade_length))) method_pairs.append((self.__fade_sweep.SetRaiseInterval, (0, fade_length))) method_pairs.append((self.__fade_sweep.SetFallInterval, (-fade_length, -1))) method_pairs.append((self.__amplifier.SetValue2, amplitude)) method_pairs.append((self.__average.SetNumber, averages)) method_pairs.append((self.__average.Start,)) # apply settings and start recording sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator) # disconnect from jack if capture_port is not None: self.__audio_io.Disconnect(playback_port, jack_input) if playback_port is not None: self.__audio_io.Disconnect(jack_output, capture_port)
def SetNormalize(self, normalize, individual=False, frequency=1000.0): """ @param normalize: False, to disable normalization, "average" to normalize to average, "frequency" to normalize to frequency """ sumpf.deactivate_output(self.__bypass_normalize.GetOutput) if normalize in ("average", "frequency"): method_pairs = [(self.__bypass_normalize.SetSelection, self.__NORMALIZE)] if normalize == "average": method_pairs.append((self.__select_normalization.SetSelection, self.__AVERAGE)) method_pairs.append((self.__normalize_avg.SetIndividual, individual)) else: method_pairs.append((self.__select_normalization.SetSelection, self.__FREQUENCY)) method_pairs.append((self.__normalize_frq.SetFrequency, frequency)) sumpf.set_multiple_values(pairs=method_pairs, progress_indicator=self.__progress_indicator) else: self.__bypass_normalize.SetSelection(self.__BYPASS) sumpf.activate_output(self.__bypass_normalize.GetOutput)
def test_set_multiple_values(self): """ Tests the set_multiple_values function. Most assertions will be don in the SetMultipleValuesTestClass class. """ # test with single Inputs testobject = SetMultipleValuesTestClass(testcase=self) sumpf.connect(testobject.GetState, self.obj1.SetValue) testobject.Start() sumpf.set_multiple_values(pairs=[(testobject.SetValue1, 37.9), (testobject.SetValue2, "Broccoli"), (testobject.TriggerValue3,)]) self.assertEqual(testobject.GetValue1(), 37.9) self.assertEqual(testobject.GetValue2(), "Broccoli") self.assertEqual(testobject.GetValue3(), True) # test with a MultiInput sumpf.set_multiple_values(pairs=[(testobject.AddValue4, 1), (testobject.AddValue4, 2), (testobject.AddValue4, 3)]) self.assertEqual(testobject.GetValue4().GetData(), [1, 2, 3])
def test_set_multiple_values(self): """ Tests the set_multiple_values function when a progress_indicator is given. Most assertions will be don in the SetMultipleValuesTestClass and ProgressTester classes. """ # test with single Inputs testobject = SetMultipleValuesTestClass(testcase=self) progress_tester = ProgressTester(progress=(5, 4, "SetMultipleValuesTestClass.GetState has just finished"), testcase=self, count_inputs=False) sumpf.connect(testobject.GetState, progress_tester.Input) testobject.Start() progress_indicator = sumpf.progressindicators.ProgressIndicator_All(message="smv") testobject.SetProgressIndicator(progress_indicator) progress_tester.SetProgressIndicator(progress_indicator) sumpf.set_multiple_values(pairs=[(testobject.SetValue1, 37.9), (testobject.SetValue2, "Broccoli"), (testobject.TriggerValue3,)], progress_indicator=progress_indicator) # test with a MultiInput sumpf.set_multiple_values(pairs=[(testobject.AddValue4, 1), (testobject.AddValue4, 2), (testobject.AddValue4, 3)], progress_indicator=progress_indicator)