Beispiel #1
0
def test_codec_PeakingEQ():
    filter = PeakingEQ(48000, 100, 0.707, 4.3)
    output = json.dumps(filter.to_json())
    assert output == '{"_type": "PeakingEQ", "fs": 48000, "fc": 100.0, "q": 0.707, "gain": 4.3}'
    decoded = filter_from_json(json.loads(output))
    assert decoded is not None
    assert isinstance(decoded, PeakingEQ)
    assert filter.fs == decoded.fs
    assert filter.q == decoded.q
    assert filter.gain == decoded.gain
    assert filter.freq == decoded.freq
    assert decoded.get_transfer_function() is not None
Beispiel #2
0
def xml_to_filt(file, fs=1000, unroll=False):
    ''' Extracts a set of filters from the provided minidsp file '''
    from model.iir import PeakingEQ, LowShelf, HighShelf

    filts = __extract_filters(file)
    output = []
    for filt_tup, count in filts.items():
        filt_dict = dict(filt_tup)
        if filt_dict['type'] == 'SL':
            for i in range(0, count if unroll is True else 1):
                filt = LowShelf(fs, float(filt_dict['freq']), float(filt_dict['q']), float(filt_dict['boost']),
                                count=1 if unroll is True else count)
                output.append(filt)
        elif filt_dict['type'] == 'SH':
            for i in range(0, count if unroll is True else 1):
                filt = HighShelf(fs, float(filt_dict['freq']), float(filt_dict['q']), float(filt_dict['boost']),
                                 count=1 if unroll is True else count)
                output.append(filt)
        elif filt_dict['type'] == 'PK':
            for i in range(0, count):
                filt = PeakingEQ(fs, float(filt_dict['freq']), float(filt_dict['q']), float(filt_dict['boost']))
                output.append(filt)
        else:
            logger.info(f"Ignoring unknown filter type {filt_dict}")
    return output
Beispiel #3
0
 def create_shaping_filter(self):
     '''
     Creates a filter of the specified type.
     :return: the filter.
     '''
     filt = None
     if self.filterType.currentText() == 'Low Shelf':
         filt = LowShelf(self.__signal.fs, self.freq.value(),
                         self.filterQ.value(), self.filterGain.value(),
                         self.filterCount.value())
     elif self.filterType.currentText() == 'High Shelf':
         filt = HighShelf(self.__signal.fs, self.freq.value(),
                          self.filterQ.value(), self.filterGain.value(),
                          self.filterCount.value())
     elif self.filterType.currentText() == 'PEQ':
         filt = PeakingEQ(self.__signal.fs, self.freq.value(),
                          self.filterQ.value(), self.filterGain.value())
     elif self.filterType.currentText() == 'Gain':
         filt = Gain(self.__signal.fs, self.filterGain.value())
     elif self.filterType.currentText() == 'Variable Q LPF':
         filt = SecondOrder_LowPass(self.__signal.fs, self.freq.value(),
                                    self.filterQ.value())
     elif self.filterType.currentText() == 'Variable Q HPF':
         filt = SecondOrder_HighPass(self.__signal.fs, self.freq.value(),
                                     self.filterQ.value())
     if filt is None:
         raise ValueError(
             f"Unknown filter type {self.filterType.currentText()}")
     else:
         filt.id = self.__selected_id
     return filt
Beispiel #4
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
Beispiel #5
0
 def __convert_to_filter(filter_params, id):
     ft = int(filter_params['FilterType']) if SyncHTP1Dialog.__has_filter_type(filter_params) else 0
     if ft == 0:
         return PeakingEQ(HTP1_FS, filter_params['Fc'], filter_params['Q'], filter_params['gaindB'], f_id=id)
     elif ft == 1:
         return LowShelf(HTP1_FS, filter_params['Fc'], filter_params['Q'], filter_params['gaindB'], f_id=id)
     elif ft == 2:
         return HighShelf(HTP1_FS, filter_params['Fc'], filter_params['Q'], filter_params['gaindB'], f_id=id)
Beispiel #6
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
Beispiel #7
0
 def __make_passthrough(idx):
     return PeakingEQ(HTP1_FS, 100, 1, 0, f_id=idx)