示例#1
0
 def __init__(self,
              ip="127.0.0.1",
              dsp=Adau145x()):
     self.dsp = dsp
     self.ip = ip
     self.sigmatcp = SigmaTCPClient(self.dsp, self.ip)
     self.resetgpio = None
示例#2
0
def main():
    global sigmatcp

    if len(sys.argv) > 1:
        if "-v" in sys.argv:
            logging.basicConfig(format='%(levelname)s: %(name)s - %(message)s',
                                level=logging.DEBUG,
                                force=True)
    else:
        logging.basicConfig(format='%(levelname)s: %(name)s - %(message)s',
                            level=logging.INFO,
                            force=True)

    signal.signal(signal.SIGUSR1, stop_playback)

    sigmatcp = SigmaTCPClient(Adau145x(), "127.0.0.1")

    while True:
        time.sleep(1)

        if stopped:
            logging.debug("stopped")
            continue

        if (spdifactive()):
            silenceloop()
        else:
            logging.debug("no SPDIF lock, sleeping")
示例#3
0
 def set_ip(self, ip):
     self.ip = ip
     self.sigmatcp = SigmaTCPClient(self.dsp, self.ip)
示例#4
0
class DSPToolkit():
    def __init__(self, ip="127.0.0.1", dsp=Adau145x()):
        self.dsp = dsp
        self.ip = ip
        self.sigmatcp = SigmaTCPClient(self.dsp, self.ip)
        self.resetgpio = None

    def set_ip(self, ip):
        self.ip = ip
        self.sigmatcp = SigmaTCPClient(self.dsp, self.ip)

    def set_volume(self, volume):
        volctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_VOL_CTL))

        if volctl is not None:
            self.sigmatcp.write_decimal(volctl, volume)
            return True
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_CTL)
            return False

    def set_limit(self, volume):
        volctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_VOL_LIMIT))

        if volctl is not None:
            self.sigmatcp.write_decimal(volctl, volume)
            return True
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_LIMIT)
            return False

    def get_volume(self):
        volctl = None
        try:
            volctl = datatools.parse_int(
                self.sigmatcp.request_metadata(ATTRIBUTE_VOL_CTL))
        except:
            pass

        if volctl is not None:
            return self.sigmatcp.read_decimal(volctl)
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_CTL)

    def get_limit(self):
        volctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_VOL_LIMIT))

        if volctl:
            return self.sigmatcp.read_decimal(volctl)
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_LIMIT)

    def set_balance(self, value):
        '''
        Sets the balance of left/right channels.
        Value ranges from 0 (only left channel) to 2 (only right channel)
        at balance=1 the volume setting on both channels is equal
        '''
        if (value < 0) or (value > 2):
            raise RuntimeError("Balance value must be between 0 and 2")

        balctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_BALANCE))

        if balctl is not None:
            self.sigmatcp.write_decimal(balctl, value)

    def write_biquad(self, addr, bq_params):
        self.sigmatcp.write_biquad(addr, bq_params)

    def write_fir(self, coefficients, mode=MODE_BOTH):

        (firleft, len_left) = datatools.parse_int_length(
            self.sigmatcp.request_metadata(ATTRIBUTE_FIR_FILTER_LEFT))
        (firright, len_right) = datatools.parse_int_length(
            self.sigmatcp.request_metadata(ATTRIBUTE_FIR_FILTER_RIGHT))

        if mode == MODE_BOTH or mode == MODE_LEFT:
            result = self.write_coefficients(firleft, len_left, coefficients)

        if mode == MODE_BOTH or mode == MODE_RIGHT:
            result = self.write_coefficients(firright, len_right, coefficients)

        return result

    def write_coefficients(self, addr, length, coefficients):
        if len(coefficients) > length:
            logging.error("can't deploy coefficients %s > %s",
                          len(coefficients), length)
            return False

        data = []
        for coeff in coefficients:
            x = list(self.sigmatcp.get_decimal_repr(coeff))
            data[0:0] = x

        x = list(self.sigmatcp.get_decimal_repr(0))
        for _i in range(len(coefficients), length):
            data[0:0] = x

        self.sigmatcp.write_memory(addr, data)

        return True

    def get_checksum(self):
        return self.sigmatcp.program_checksum()

    def generic_request(self, request_code, response_code=None):
        return self.sigmatcp.request_generic(request_code, response_code)

    def set_filters(self, filters, mode=MODE_BOTH, cutoff_long=False):

        (addr_left, length_left) = datatools.parse_int_length(
            self.sigmatcp.request_metadata(ATTRIBUTE_IIR_FILTER_LEFT))
        (addr_right, length_right) = datatools.parse_int_length(
            self.sigmatcp.request_metadata(ATTRIBUTE_IIR_FILTER_RIGHT))

        if mode == MODE_LEFT:
            maxlen = length_left
        elif mode == MODE_RIGHT:
            maxlen = length_right
        else:
            maxlen = min(length_left, length_right)

        assert maxlen % 5 == 0

        maxlen = maxlen / 5

        if len(filters) > maxlen and (cutoff_long == False):
            raise (DSPError(
                "{} filters given, but filter bank has only {} slots".format(
                    len(filters), maxlen)))

        self.hibernate(True)

        logging.debug("deploying filters %s", filters)

        i = 0
        for f in filters:
            logging.debug(f)
            if mode == MODE_LEFT or mode == MODE_BOTH:
                if i < length_left:
                    self.sigmatcp.write_biquad(addr_left + i * 5, f)
            if mode == MODE_RIGHT or mode == MODE_BOTH:
                if i < length_right:
                    self.sigmatcp.write_biquad(addr_right + i * 5, f)
            i += 1
            if i > maxlen:
                break

        self.hibernate(False)

    def clear_iir_filters(self, mode=MODE_BOTH):
        # Simply fill filter arrays with dummy filters
        self.set_filters([Biquad.plain()] * 256, mode=mode, cutoff_long=True)

    def install_profile(self, xmlfile):
        return self.sigmatcp.write_eeprom_from_file(xmlfile)

    def install_profile_from_content(self, content):
        return self.sigmatcp.write_eeprom_from_xml(content)

    def mute(self, mute=True):
        mutereg = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_MUTE_REG))

        if mutereg is not None:
            if mute:
                self.sigmatcp.write_memory(mutereg, self.sigmatcp.int_data(1))
            else:
                self.sigmatcp.write_memory(mutereg, self.sigmatcp.int_data(0))
            return True
        else:
            return False

    def reset(self):
        self.sigmatcp.reset()

    def hibernate(self, hibernate=True):
        self.sigmatcp.hibernate(hibernate)
        time.sleep(0.001)

    def get_meta(self, attribute):
        return self.sigmatcp.request_metadata(attribute)

    def get_samplerate(self):
        sr = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_SAMPLERATE))

        if sr is None or sr == 0:
            return 48000
        else:
            return sr