Ejemplo n.º 1
0
def test_codec_CompleteFilter():
    filter = CompleteFilter(filters=[PeakingEQ(1000, 50, 3.2, -5),
                                     LowShelf(1000, 25, 1, 3.2, count=3),
                                     ComplexHighPass(FilterType.BUTTERWORTH, 6, 1000, 12)],
                            description='Hello from me')
    output = json.dumps(filter.to_json())
    expected = '{"_type": "CompleteFilter", "description": "Hello from me", "fs": 1000, "filters": [' \
               '{"_type": "ComplexHighPass", "filter_type": "BW", "order": 6, "fs": 1000, "fc": 12.0}, ' \
               '{"_type": "LowShelf", "fs": 1000, "fc": 25.0, "q": 1.0, "gain": 3.2, "count": 3}, ' \
               '{"_type": "PeakingEQ", "fs": 1000, "fc": 50.0, "q": 3.2, "gain": -5.0}' \
               ']}'
    assert output == expected
    decoded = filter_from_json(json.loads(output))
    assert decoded is not None
    assert isinstance(decoded, CompleteFilter)
    assert decoded.description == 'Hello from me'
    assert decoded.filters is not None
    assert len(decoded.filters) == len(filter.filters)
    assert decoded.getTransferFunction() is not None
    assert isinstance(decoded.filters[0], filter.filters[0].__class__)
    assert filter.filters[0].fs == decoded.filters[0].fs
    assert filter.filters[0].type == decoded.filters[0].type
    assert filter.filters[0].order == decoded.filters[0].order
    assert filter.filters[0].freq == decoded.filters[0].freq
    assert isinstance(decoded.filters[1], filter.filters[1].__class__)
    assert filter.filters[1].fs == decoded.filters[1].fs
    assert filter.filters[1].q == decoded.filters[1].q
    assert filter.filters[1].gain == decoded.filters[1].gain
    assert filter.filters[1].freq == decoded.filters[1].freq
    assert filter.filters[1].count == decoded.filters[1].count
    assert isinstance(decoded.filters[2], filter.filters[2].__class__)
    assert filter.filters[2].fs == decoded.filters[2].fs
    assert filter.filters[2].q == decoded.filters[2].q
    assert filter.filters[2].gain == decoded.filters[2].gain
    assert filter.filters[2].freq == decoded.filters[2].freq
Ejemplo n.º 2
0
def test_codec_signal():
    fs = 1000
    peak = LowShelf(fs, 30, 1, 10,
                    count=2).get_transfer_function().get_magnitude()
    avg = LowShelf(fs, 30, 1, 10).get_transfer_function().get_magnitude()
    median = LowShelf(fs, 30, 1, 10).get_transfer_function().get_magnitude()
    filt = CompleteFilter()
    filt.save(HighShelf(fs, 60, 1, 5, count=2))
    data = SingleChannelSignalData('test',
                                   fs,
                                   xy_data=[avg, peak, median],
                                   filter=filt,
                                   duration_seconds=123456,
                                   start_seconds=123,
                                   offset=4.2)
    output = json.dumps(signaldata_to_json(data))
    assert output is not None
    decoded = signaldata_from_json(json.loads(output), None)
    assert decoded is not None
    assert isinstance(decoded, SingleChannelSignalData)
    assert decoded.name == data.name
    assert decoded.fs == data.fs
    assert decoded.filter is not None
    assert type(decoded.filter) is type(data.filter)
    assert decoded.filter.id != -1
    assert decoded.filter.description == data.filter.description
    assert decoded.filter.filters == data.filter.filters
    assert decoded.current_unfiltered is not None
    assert len(decoded.current_unfiltered) == 3
    assert decoded.current_unfiltered == data.current_unfiltered
    assert decoded.duration_hhmmss == data.duration_hhmmss
    assert decoded.start_hhmmss == data.start_hhmmss
    assert decoded.end_hhmmss == data.end_hhmmss
    assert decoded.offset == data.offset
Ejemplo n.º 3
0
 def __disable_on_disconnect(self):
     ''' Clears all relevant state on disconnect. '''
     self.connectButton.setEnabled(True)
     self.disconnectButton.setEnabled(False)
     self.ipAddress.setReadOnly(False)
     self.resyncFilters.setEnabled(False)
     self.deleteFiltersButton.setEnabled(False)
     self.editFilterButton.setEnabled(False)
     self.showDetailsButton.setEnabled(False)
     self.createPulsesButton.setEnabled(False)
     self.filtersetSelector.clear()
     self.__filters_by_channel = {}
     self.__current_device_filters_by_channel = {}
     self.beqFile.clear()
     self.__beq_filter = None
     self.selectBeqButton.setEnabled(False)
     self.addFilterButton.setEnabled(False)
     self.removeFilterButton.setEnabled(False)
     self.applyFiltersButton.setEnabled(False)
     self.autoSyncButton.setEnabled(False)
     self.__show_signal_mapping()
     self.syncStatus.setIcon(qta.icon('fa5s.unlink'))
     self.syncStatus.setEnabled(False)
     self.__filters.filter = CompleteFilter(fs=HTP1_FS, sort_by_id=True)
     self.__simple_signal = self.__create_pulse('default', self.__filters.filter)
     self.__magnitude_model.redraw()
Ejemplo n.º 4
0
 def __init__(self, view, preferences, label=None, on_update=lambda _: True):
     self.__filter = CompleteFilter()
     self.__view = view
     self.__preferences = preferences
     self.__table = None
     self.__label = label
     self.__on_update = on_update
Ejemplo n.º 5
0
def filter_from_json(o):
    '''
    Converts a dict (parsed from json) to a filter.
    :param o: the dict.
    :return: the filter.
    '''
    from model.iir import Passthrough, PeakingEQ, LowShelf, HighShelf, FirstOrder_LowPass, \
        FirstOrder_HighPass, SecondOrder_LowPass, SecondOrder_HighPass, AllPass, CompleteFilter, ComplexLowPass, \
        FilterType, ComplexHighPass

    filt = None
    if '_type' not in o:
        raise ValueError(f"{o} is not a filter")
    if o['_type'] == Passthrough.__name__:
        if 'fs' in o:
            filt = Passthrough(fs=int(o['fs']))
        else:
            filt = Passthrough()
    elif o['_type'] == Gain.__name__:
        filt = Gain(o['fs'], o['gain'])
    elif o['_type'] == PeakingEQ.__name__:
        filt = PeakingEQ(o['fs'], o['fc'], o['q'], o['gain'])
    elif o['_type'] == LowShelf.__name__:
        filt = LowShelf(o['fs'], o['fc'], o['q'], o['gain'], o['count'])
    elif o['_type'] == HighShelf.__name__:
        filt = HighShelf(o['fs'], o['fc'], o['q'], o['gain'], o['count'])
    elif o['_type'] == FirstOrder_LowPass.__name__:
        filt = FirstOrder_LowPass(o['fs'], o['fc'], o['q'])
    elif o['_type'] == FirstOrder_HighPass.__name__:
        filt = FirstOrder_HighPass(o['fs'], o['fc'], o['q'])
    elif o['_type'] == SecondOrder_LowPass.__name__:
        filt = SecondOrder_LowPass(o['fs'], o['fc'], o['q'])
    elif o['_type'] == SecondOrder_HighPass.__name__:
        filt = SecondOrder_HighPass(o['fs'], o['fc'], o['q'])
    elif o['_type'] == AllPass.__name__:
        filt = AllPass(o['fs'], o['fc'], o['q'])
    elif o['_type'] == CompleteFilter.__name__:
        kwargs = {}
        if 'fs' in o:
            kwargs['fs'] = o['fs']
        filt = CompleteFilter(
            filters=[filter_from_json(x) for x in o['filters']],
            description=o['description'],
            **kwargs)
    elif o['_type'] == ComplexLowPass.__name__:
        filt = ComplexLowPass(FilterType(o['filter_type']), o['order'],
                              o['fs'], o['fc'])
    elif o['_type'] == ComplexHighPass.__name__:
        filt = ComplexHighPass(FilterType(o['filter_type']), o['order'],
                               o['fs'], o['fc'])
    if filt is None:
        raise ValueError(f"{o._type} is an unknown filter type")
    else:
        if filt.id == -1:
            filt.id = uuid4()
        return filt
Ejemplo n.º 6
0
 def __optimise_filter(self):
     '''
     Optimises the current filter and stores it as a snapshot.
     '''
     current_filter = self.__working.clone()
     to_save = self.targetBiquadCount.value() - current_filter.biquads
     if to_save < 0:
         optimised_filter = CompleteFilter(fs=current_filter.fs,
                                           filters=optimise_filters(current_filter, current_filter.fs, -to_save),
                                           description='Optimised')
         self.__snapshot.filter = optimised_filter
     else:
         QMessageBox.information(self,
                                 'Optimise Filters',
                                 f"Current filter uses {current_filter.biquads} biquads so no optimisation required")
Ejemplo n.º 7
0
 def filter(self, filt):
     if filt is None:
         filt = CompleteFilter()
     if isinstance(filt, CompleteFilter):
         if self.__table is not None:
             self.__table.beginResetModel()
         self.__filter = filt
         if self.__label is not None:
             if self.__filter.listener is not None:
                 self.__label.setText(f"Filter - {filt.listener.name}")
             else:
                 self.__label.setText(f"Filter - Default")
         self.post_update()
         if self.__table is not None:
             self.__table.endResetModel()
     else:
         raise ValueError(f"FilterModel only accepts CompleteFilter, ignoring {filt}")
Ejemplo n.º 8
0
 def __load_filter_as_snapshot(self):
     ''' Allows a filter to be loaded from a supported file format and set as the snapshot. '''
     result = QMessageBox.question(self,
                                   'Load Filter or XML?',
                                   f"Do you want to load from a filter or a minidsp beq file?"
                                   f"\n\nClick Yes to load from a filter or No for a beq file",
                                   QMessageBox.Yes | QMessageBox.No,
                                   QMessageBox.No)
     load_xml = result == QMessageBox.No
     loaded_snapshot = None
     if load_xml is True:
         from model.minidsp import load_as_filter
         filters, _ = load_as_filter(self, self.__preferences, self.__signal.fs)
         if filters is not None:
             loaded_snapshot = CompleteFilter(fs=self.__signal.fs, filters=filters, description='Snapshot')
     else:
         loaded_snapshot = load_filter(self)
     if loaded_snapshot is not None:
         self.__snapshot.filter = loaded_snapshot
Ejemplo n.º 9
0
 def __missing__(self, key):
     self[key] = CompleteFilter(fs=HTP1_FS, sort_by_id=True)
     return self[key]