Пример #1
0
    def initializeAudio(self):
        self.pullTimer.timeout.connect(self.pullTimerExpired)

        self.pullMode = True

        self.fmt.setFrequency(DATA_FREQUENCY_HZ)
        self.fmt.setChannels(1)
        self.fmt.setSampleSize(16)
        self.fmt.setCodec("audio/pcm")
        self.fmt.setByteOrder(QAudioFormat.LittleEndian)
        self.fmt.setSampleType(QAudioFormat.SignedInt)

        info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice())
        if not info.isFormatSupported(self.fmt):
            print "Default format not supported - trying to use nearest"
            self.fmt = info.nearestFormat(self.fmt)

        self.generator = Generator(self.fmt, DURATION_SECONDS * 1000000, TONE_FREQUENCY_HZ, self, self.dump)

        self.createAudioOutput()
Пример #2
0
    def initializeAudio(self):
        self.pullTimer.timeout.connect(self.pullTimerExpired)

        self.pullMode = True

        self.fmt.setFrequency(DATA_FREQUENCY_HZ)
        self.fmt.setChannels(1)
        self.fmt.setSampleSize(16)
        self.fmt.setCodec('audio/pcm')
        self.fmt.setByteOrder(QAudioFormat.LittleEndian)
        self.fmt.setSampleType(QAudioFormat.SignedInt)

        info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice())
        if not info.isFormatSupported(self.fmt):
            print 'Default format not supported - trying to use nearest'
            self.fmt = info.nearestFormat(self.fmt)

        self.generator = Generator(self.fmt, DURATION_SECONDS * 1000000,
                                   TONE_FREQUENCY_HZ, self, self.dump)

        self.createAudioOutput()
Пример #3
0
class AudioTest(QObject):
    modeHasChanged = Signal("QVariantList")
    newResult = Signal(str)
    newNearest = Signal("QVariantList")

    def __init__(self, parent=None):
        QObject.__init__(self, parent)

        self.deviceInfo = QAudioDeviceInfo()
        self.settings = QAudioFormat()
        self.mode = QAudio.Mode()
        self._availableDevices = {}
        self._availableCodecs = {}
        self._availableFreqs = {}
        self._availableChannels = {}
        self._availableTypes = {}
        self._availableSizes = {}
        self._availableEnds = {}

        self.mode = QAudio.AudioOutput

    @Slot()
    def test(self):
        # tries to set all the settings picked.
        if not self.deviceInfo.isNull():
            if self.deviceInfo.isFormatSupported(self.settings):
                self.newResult.emit("Success")
                '''
                self.testResult.setText(self.tr("Success"))
                self.nearestFreq.setText("")
                self.nearestChannel.setText("")
                self.nearestCodec.setText("")
                self.nearestSampleSize.setText("")
                self.nearestSampleType.setText("")
                self.nearestEndian.setText("")
                '''
            else:
                nearest = self.deviceInfo.nearestFormat(self.settings)
                self.newResult.emit("Failed")
                newValues = []
                newValues.append("") # keep the same positions as newLabels list
                newValues.append(nearest.codec()) # codec - 1
                newValues.append(str(nearest.frequency())) # freq - 2
                newValues.append(str(nearest.channels())) # channel - 3
                newValues.append(sampletoString(nearest.sampleType())) # type - 4
                newValues.append(str(nearest.sampleSize())) # size - 5
                newValues.append(byteOrdertoString(nearest.byteOrder())) # end - 6
                self.newNearest.emit(newValues)
        else:
            self.newResult.emit("No Device")

    @Slot(str)
    def modeChanged(self, idx):
        # mode has changed
        if idx == "Input":
            mode = QAudio.AudioInput
        else:
            mode = QAudio.AudioOutput

        self._availableDevices = {}
        for deviceInfo in QAudioDeviceInfo.availableDevices(mode):
            self._availableDevices[deviceInfo.deviceName()] = deviceInfo

        firstDevice = QAudioDeviceInfo.availableDevices(mode)[0].deviceName()
        self.deviceChanged(firstDevice)

    @Slot(str)
    def deviceChanged(self, idx):
        if len(self._availableDevices) == 0:
            return
        newLabels = []
        newLabels.append(idx) # device - 0

        # device has changed
        self.deviceInfo = self._availableDevices[idx]

        codecz = self.deviceInfo.supportedCodecs()
        self._availableCodecs = {}
        for codec in codecz:
            self._availableCodecs[codec] = codec
        if len(codecz):
            self.settings.setCodec(codecz[0])
            newLabels.append(codecz[0]) # codec - 1

        freqz = self.deviceInfo.supportedFrequencies()
        self._availableFreqs = {}
        for freq in freqz:
            self._availableFreqs[str(freq)] = freq
        if len(freqz):
            self.settings.setFrequency(freqz[0])
            newLabels.append(str(freqz[0])) # freq - 2

        chz = self.deviceInfo.supportedChannels()
        self._availableChannels = {}
        for ch in chz:
            self._availableChannels[str(ch)] = ch
        # Add false to create failed condition!
        self._availableChannels["FAIL"] = -1
        if len(chz):
            self.settings.setChannels(chz[0])
            newLabels.append(str(chz[0])) # channel - 3


        sampleTypes = self.deviceInfo.supportedSampleTypes()
        self._availableTypes = {}
        for sample in sampleTypes:
            self._availableTypes[sampletoString(sample)] = sample
        if len(sampleTypes):
            self.settings.setSampleType(sampleTypes[0])
            newLabels.append(sampletoString(sampleTypes[0])) # type - 4

        sampleSizes = self.deviceInfo.supportedSampleSizes()
        self._availableSizes = {}
        for sample in sampleSizes:
            self._availableSizes[str(sample)] = sample
        if len(sampleSizes):
            self.settings.setSampleSize(sampleSizes[0])
            newLabels.append(str(sampleSizes[0])) # size - 5

        endianz = self.deviceInfo.supportedByteOrders()
        self._availableEnds = {}
        for endian in endianz:
            self._availableEnds[byteOrdertoString(endian)] = endian
        if len(endianz):
            self.settings.setByteOrder(endianz[0])
            newLabels.append(byteOrdertoString(endianz[0])) # end - 6

        # Update all the buttons
        self.modeHasChanged.emit(newLabels)

    @Slot(str)
    def codecChanged(self, idx):
        self.settings.setCodec(self._availableCodecs[idx])

    @Slot(str)
    def freqChanged(self, idx):
        # freq has changed
        self.settings.setFrequency(int(self._availableFreqs[idx]))

    @Slot(str)
    def channelChanged(self, idx):
        self.settings.setChannels(int(self._availableChannels[idx]))

    @Slot(str)
    def sizeChanged(self, idx):
        self.settings.setSampleSize(int(self._availableSizes[idx]))

    @Slot(str)
    def typeChanged(self, idx):
        sampleType = stringToSample(self._availableTypes[idx])
        if sampleType == QAudioFormat.SignedInt:
            self.settings.setSampleType(QAudioFormat.SignedInt)
        elif sampleType == QAudioFormat.UnSignedInt:
            self.settings.setSampleType(QAudioFormat.UnSignedInt)
        elif sampleType == QAudioFormat.Float:
            self.settings.setSampleType(QAudioFormat.Float)

    @Slot(str)
    def endChanged(self, idx):
        endian = stringToByteOrder(self._availableEnds[idx])
        if endian == QAudioFormat.LittleEndian:
            self.settings.setByteOrder(QAudioFormat.LittleEndian)
        elif endian == QAudioFormat.BigEndian:
            self.settings.setByteOrder(QAudioFormat.BigEndian)

    @Property("QStringList", constant=True)
    def availableDevices(self):
        return self._availableDevices.keys()

    @Property("QStringList", constant=True)
    def availableCodecs(self):
        return self._availableCodecs.keys()

    @Property("QStringList", constant=True)
    def availableFreqs(self):
        return self._availableFreqs.keys()

    @Property("QStringList", constant=True)
    def availableChannels(self):
        return self._availableChannels.keys()

    @Property("QStringList", constant=True)
    def availableTypes(self):
        return self._availableTypes.keys()

    @Property("QStringList", constant=True)
    def availableSizes(self):
        return self._availableSizes.keys()

    @Property("QStringList", constant=True)
    def availableEnds(self):
        return self._availableEnds.keys()
Пример #4
0
class AudioTest(AudioDevicesBase, Ui_AudioDevicesBase):
    def __init__(self, parent=None):
        AudioDevicesBase.__init__(self, parent)

        self.deviceInfo = QAudioDeviceInfo()
        self.settings = QAudioFormat()
        self.mode = QAudio.Mode()

        self.mode = QAudio.AudioOutput
        self.testButton.clicked.connect(self.test)
        self.modeBox.activated[int].connect(self.modeChanged)
        self.deviceBox.activated[int].connect(self.deviceChanged)
        self.frequencyBox.activated[int].connect(self.freqChanged)
        self.channelsBox.activated[int].connect(self.channelChanged)
        self.codecsBox.activated[int].connect(self.codecChanged)
        self.sampleSizesBox.activated[int].connect(self.sampleSizeChanged)
        self.sampleTypesBox.activated[int].connect(self.sampleTypeChanged)
        self.endianBox.activated[int].connect(self.endianChanged)
        self.populateTableButton.clicked.connect(self.populateTable)
        self.modeBox.setCurrentIndex(0)
        self.modeChanged(0)
        self.deviceBox.setCurrentIndex(0)
        self.deviceChanged(0)

    def test(self):
        # tries to set all the settings picked.
        self.testResult.clear()
        if not self.deviceInfo.isNull():
            if self.deviceInfo.isFormatSupported(self.settings):
                self.testResult.setText(self.tr("Success"))
                self.nearestFreq.setText("")
                self.nearestChannel.setText("")
                self.nearestCodec.setText("")
                self.nearestSampleSize.setText("")
                self.nearestSampleType.setText("")
                self.nearestEndian.setText("")
            else:
                nearest = self.deviceInfo.nearestFormat(self.settings)
                self.testResult.setText(self.tr("Failed"))
                self.nearestFreq.setText(str(nearest.frequency()))
                self.nearestChannel.setText(str(nearest.channels()))
                self.nearestCodec.setText(nearest.codec())
                self.nearestSampleSize.setText(str(nearest.sampleSize()))
                self.nearestSampleType.setText(
                    sampletoString(nearest.sampleType()))
                self.nearestEndian.setText(
                    byteOrdertoString(nearest.byteOrder()))
        else:
            self.testResult.setText(self.tr("No Device"))

    def modeChanged(self, idx):
        self.testResult.clear()
        # mode has changed
        if idx == 0:
            mode = QAudio.AudioInput
        else:
            mode = QAudio.AudioOutput

        self.deviceBox.clear()
        for deviceInfo in QAudioDeviceInfo.availableDevices(mode):
            self.deviceBox.addItem(deviceInfo.deviceName(), deviceInfo)

        self.deviceBox.setCurrentIndex(0)
        self.deviceChanged(0)

    def deviceChanged(self, idx):
        self.testResult.clear()
        if self.deviceBox.count() == 0:
            return

        # device has changed
        self.deviceInfo = self.deviceBox.itemData(idx)
        self.frequencyBox.clear()
        freqz = self.deviceInfo.supportedFrequencies()
        for freq in freqz:
            self.frequencyBox.addItem(str(freq))
        if len(freqz):
            self.settings.setFrequency(freqz[0])

        self.channelsBox.clear()
        chz = self.deviceInfo.supportedChannels()
        for ch in chz:
            self.channelsBox.addItem(str(ch))
        if len(chz):
            self.settings.setChannels(chz[0])

        self.codecsBox.clear()
        codecz = self.deviceInfo.supportedCodecs()
        for codec in codecz:
            self.codecsBox.addItem(codec)
        if len(codecz):
            self.settings.setCodec(codecz[0])

        # Add false to create failed condition!
        self.codecsBox.addItem("audio/test")

        self.sampleSizesBox.clear()
        sampleSizez = self.deviceInfo.supportedSampleSizes()
        for sample in sampleSizez:
            self.sampleSizesBox.addItem(str(sample))
        if len(sampleSizez):
            self.settings.setSampleSize(sampleSizez[0])

        self.sampleTypesBox.clear()
        sampleTypez = self.deviceInfo.supportedSampleTypes()
        for sample in sampleTypez:
            self.sampleTypesBox.addItem(sampletoString(sample))
        if len(sampleTypez):
            self.settings.setSampleType(sampleTypez[0])

        self.endianBox.clear()
        endianz = self.deviceInfo.supportedByteOrders()
        for endian in endianz:
            self.endianBox.addItem(byteOrdertoString(endian))
        if len(endianz):
            self.settings.setByteOrder(endianz[0])

        self.allFormatsTable.clearContents()

    def populateTable(self):
        row = 0
        format = QAudioFormat()
        for codec in self.deviceInfo.supportedCodecs():
            format.setCodec(codec)
            for frequency in self.deviceInfo.supportedFrequencies():
                format.setFrequency(frequency)
                for channels in self.deviceInfo.supportedChannels():
                    format.setChannels(channels)
                    for sampleType in self.deviceInfo.supportedSampleTypes():
                        format.setSampleType(sampleType)
                        for sampleSize in self.deviceInfo.supportedSampleSizes(
                        ):
                            format.setSampleSize(sampleSize)
                            for endian in self.deviceInfo.supportedByteOrders(
                            ):
                                format.setByteOrder(endian)
                                if self.deviceInfo.isFormatSupported(format):
                                    self.allFormatsTable.setRowCount(row + 1)

                                    codecItem = QTableWidgetItem(
                                        format.codec())
                                    self.allFormatsTable.setItem(
                                        row, 0, codecItem)

                                    frequencyItem = QTableWidgetItem(
                                        str(format.frequency()))
                                    self.allFormatsTable.setItem(
                                        row, 1, frequencyItem)

                                    channelsItem = QTableWidgetItem(
                                        str(format.channels()))
                                    self.allFormatsTable.setItem(
                                        row, 2, channelsItem)

                                    sampleTypeItem = QTableWidgetItem(
                                        sampletoString(format.sampleType()))
                                    self.allFormatsTable.setItem(
                                        row, 3, sampleTypeItem)

                                    sampleSizeItem = QTableWidgetItem(
                                        str(format.sampleSize()))
                                    self.allFormatsTable.setItem(
                                        row, 4, sampleSizeItem)

                                    byteOrderItem = QTableWidgetItem(
                                        byteOrdertoString(format.byteOrder()))
                                    self.allFormatsTable.setItem(
                                        row, 5, byteOrderItem)
                                    row += 1

    def freqChanged(self, idx):
        # freq has changed
        self.settings.setFrequency(int(self.frequencyBox.itemText(idx)))

    def channelChanged(self, idx):
        self.settings.setChannels(int(self.channelsBox.itemText(idx)))

    def codecChanged(self, idx):
        self.settings.setCodec(self.codecsBox.itemText(idx))

    def sampleSizeChanged(self, idx):
        self.settings.setSampleSize(int(self.sampleSizesBox.itemText(idx)))

    def sampleTypeChanged(self, idx):
        sampleType = stringToSample(self.sampleTypesBox.itemText(idx))
        if sampleType == QAudioFormat.SignedInt:
            self.settings.setSampleType(QAudioFormat.SignedInt)
        elif sampleType == QAudioFormat.UnSignedInt:
            self.settings.setSampleType(QAudioFormat.UnSignedInt)
        elif sampleType == QAudioFormat.Float:
            self.settings.setSampleType(QAudioFormat.Float)

    def endianChanged(self, idx):
        endian = stringToByteOrder(self.endianBox.itemText(idx))
        if endian == QAudioFormat.LittleEndian:
            self.settings.setByteOrder(QAudioFormat.LittleEndian)
        elif endian == QAudioFormat.BigEndian:
            self.settings.setByteOrder(QAudioFormat.BigEndian)
Пример #5
0
class AudioTest(AudioDevicesBase, Ui_AudioDevicesBase):
    def __init__(self, parent=None):
        AudioDevicesBase.__init__(self, parent)

        self.deviceInfo = QAudioDeviceInfo()
        self.settings = QAudioFormat()
        self.mode = QAudio.Mode()

        self.mode = QAudio.AudioOutput
        self.testButton.clicked.connect(self.test)
        self.modeBox.activated[int].connect(self.modeChanged)
        self.deviceBox.activated[int].connect(self.deviceChanged)
        self.frequencyBox.activated[int].connect(self.freqChanged)
        self.channelsBox.activated[int].connect(self.channelChanged)
        self.codecsBox.activated[int].connect(self.codecChanged)
        self.sampleSizesBox.activated[int].connect(self.sampleSizeChanged)
        self.sampleTypesBox.activated[int].connect(self.sampleTypeChanged)
        self.endianBox.activated[int].connect(self.endianChanged)
        self.populateTableButton.clicked.connect(self.populateTable)
        self.modeBox.setCurrentIndex(0)
        self.modeChanged(0)
        self.deviceBox.setCurrentIndex(0)
        self.deviceChanged(0)

    def test(self):
        # tries to set all the settings picked.
        self.testResult.clear()
        if not self.deviceInfo.isNull():
            if self.deviceInfo.isFormatSupported(self.settings):
                self.testResult.setText(self.tr("Success"))
                self.nearestFreq.setText("")
                self.nearestChannel.setText("")
                self.nearestCodec.setText("")
                self.nearestSampleSize.setText("")
                self.nearestSampleType.setText("")
                self.nearestEndian.setText("")
            else:
                nearest = self.deviceInfo.nearestFormat(self.settings)
                self.testResult.setText(self.tr("Failed"))
                self.nearestFreq.setText(str(nearest.frequency()))
                self.nearestChannel.setText(str(nearest.channels()))
                self.nearestCodec.setText(nearest.codec())
                self.nearestSampleSize.setText(str(nearest.sampleSize()))
                self.nearestSampleType.setText(sampletoString(nearest.sampleType()))
                self. nearestEndian.setText(byteOrdertoString(nearest.byteOrder()))
        else:
            self.testResult.setText(self.tr("No Device"))

    def modeChanged(self, idx):
        self.testResult.clear();
        # mode has changed
        if idx == 0:
            mode = QAudio.AudioInput
        else:
            mode = QAudio.AudioOutput

        self.deviceBox.clear()
        for deviceInfo in QAudioDeviceInfo.availableDevices(mode):
            self.deviceBox.addItem(deviceInfo.deviceName(), deviceInfo)

        self.deviceBox.setCurrentIndex(0)
        self.deviceChanged(0)

    def deviceChanged(self, idx):
        self.testResult.clear()
        if self.deviceBox.count() == 0:
            return

        # device has changed
        self.deviceInfo = self.deviceBox.itemData(idx)
        self.frequencyBox.clear()
        freqz = self.deviceInfo.supportedFrequencies()
        for freq in freqz:
            self.frequencyBox.addItem(str(freq))
        if len(freqz):
            self.settings.setFrequency(freqz[0])

        self.channelsBox.clear();
        chz = self.deviceInfo.supportedChannels()
        for ch in chz:
            self.channelsBox.addItem(str(ch))
        if len(chz):
            self.settings.setChannels(chz[0])

        self.codecsBox.clear()
        codecz = self.deviceInfo.supportedCodecs()
        for codec in codecz:
            self.codecsBox.addItem(codec)
        if len(codecz):
            self.settings.setCodec(codecz[0])

        # Add false to create failed condition!
        self.codecsBox.addItem("audio/test");

        self.sampleSizesBox.clear()
        sampleSizez = self.deviceInfo.supportedSampleSizes()
        for sample in sampleSizez:
            self.sampleSizesBox.addItem(str(sample))
        if len(sampleSizez):
            self.settings.setSampleSize(sampleSizez[0])

        self.sampleTypesBox.clear()
        sampleTypez = self.deviceInfo.supportedSampleTypes()
        for sample in sampleTypez:
            self.sampleTypesBox.addItem(sampletoString(sample))
        if len(sampleTypez):
            self.settings.setSampleType(sampleTypez[0])

        self.endianBox.clear();
        endianz = self.deviceInfo.supportedByteOrders()
        for endian in endianz:
            self.endianBox.addItem(byteOrdertoString(endian))
        if len(endianz):
            self.settings.setByteOrder(endianz[0])

        self.allFormatsTable.clearContents()

    def populateTable(self):
        row = 0
        format = QAudioFormat()
        for codec in self.deviceInfo.supportedCodecs():
            format.setCodec(codec)
            for frequency in self.deviceInfo.supportedFrequencies():
                format.setFrequency(frequency)
                for channels in self.deviceInfo.supportedChannels():
                    format.setChannels(channels)
                    for sampleType in self.deviceInfo.supportedSampleTypes():
                        format.setSampleType(sampleType)
                        for sampleSize in self.deviceInfo.supportedSampleSizes():
                            format.setSampleSize(sampleSize)
                            for endian in self.deviceInfo.supportedByteOrders():
                                format.setByteOrder(endian)
                                if self.deviceInfo.isFormatSupported(format):
                                    self.allFormatsTable.setRowCount(row + 1);

                                    codecItem = QTableWidgetItem(format.codec())
                                    self.allFormatsTable.setItem(row, 0, codecItem)

                                    frequencyItem = QTableWidgetItem(str(format.frequency()))
                                    self.allFormatsTable.setItem(row, 1, frequencyItem)

                                    channelsItem = QTableWidgetItem(str(format.channels()))
                                    self.allFormatsTable.setItem(row, 2, channelsItem)

                                    sampleTypeItem = QTableWidgetItem(sampletoString(format.sampleType()))
                                    self.allFormatsTable.setItem(row, 3, sampleTypeItem)

                                    sampleSizeItem = QTableWidgetItem(str(format.sampleSize()))
                                    self.allFormatsTable.setItem(row, 4, sampleSizeItem)

                                    byteOrderItem = QTableWidgetItem(byteOrdertoString(format.byteOrder()))
                                    self.allFormatsTable.setItem(row, 5, byteOrderItem)
                                    row += 1

    def freqChanged(self, idx):
        # freq has changed
        self.settings.setFrequency(int(self.frequencyBox.itemText(idx)))

    def channelChanged(self, idx):
        self.settings.setChannels(int(self.channelsBox.itemText(idx)))

    def codecChanged(self, idx):
        self.settings.setCodec(self.codecsBox.itemText(idx))

    def sampleSizeChanged(self, idx):
        self.settings.setSampleSize(int(self.sampleSizesBox.itemText(idx)))

    def sampleTypeChanged(self, idx):
        sampleType = stringToSample(self.sampleTypesBox.itemText(idx))
        if sampleType == QAudioFormat.SignedInt:
            self.settings.setSampleType(QAudioFormat.SignedInt)
        elif sampleType == QAudioFormat.UnSignedInt:
            self.settings.setSampleType(QAudioFormat.UnSignedInt)
        elif sampleType == QAudioFormat.Float:
            self.settings.setSampleType(QAudioFormat.Float)

    def endianChanged(self, idx):
        endian = stringToByteOrder(self.endianBox.itemText(idx))
        if endian == QAudioFormat.LittleEndian:
            self.settings.setByteOrder(QAudioFormat.LittleEndian)
        elif endian == QAudioFormat.BigEndian:
            self.settings.setByteOrder(QAudioFormat.BigEndian)
Пример #6
0
class AudioTest(QObject):
    modeHasChanged = Signal("QVariantList")
    newResult = Signal(str)
    newNearest = Signal("QVariantList")

    def __init__(self, parent=None):
        QObject.__init__(self, parent)

        self.deviceInfo = QAudioDeviceInfo()
        self.settings = QAudioFormat()
        self.mode = QAudio.Mode()
        self._availableDevices = {}
        self._availableCodecs = {}
        self._availableFreqs = {}
        self._availableChannels = {}
        self._availableTypes = {}
        self._availableSizes = {}
        self._availableEnds = {}

        self.mode = QAudio.AudioOutput

    @Slot()
    def test(self):
        # tries to set all the settings picked.
        if not self.deviceInfo.isNull():
            if self.deviceInfo.isFormatSupported(self.settings):
                self.newResult.emit("Success")
                '''
                self.testResult.setText(self.tr("Success"))
                self.nearestFreq.setText("")
                self.nearestChannel.setText("")
                self.nearestCodec.setText("")
                self.nearestSampleSize.setText("")
                self.nearestSampleType.setText("")
                self.nearestEndian.setText("")
                '''
            else:
                nearest = self.deviceInfo.nearestFormat(self.settings)
                self.newResult.emit("Failed")
                newValues = []
                newValues.append(
                    "")  # keep the same positions as newLabels list
                newValues.append(nearest.codec())  # codec - 1
                newValues.append(str(nearest.frequency()))  # freq - 2
                newValues.append(str(nearest.channels()))  # channel - 3
                newValues.append(sampletoString(
                    nearest.sampleType()))  # type - 4
                newValues.append(str(nearest.sampleSize()))  # size - 5
                newValues.append(byteOrdertoString(
                    nearest.byteOrder()))  # end - 6
                self.newNearest.emit(newValues)
        else:
            self.newResult.emit("No Device")

    @Slot(str)
    def modeChanged(self, idx):
        # mode has changed
        if idx == "Input":
            mode = QAudio.AudioInput
        else:
            mode = QAudio.AudioOutput

        self._availableDevices = {}
        for deviceInfo in QAudioDeviceInfo.availableDevices(mode):
            self._availableDevices[deviceInfo.deviceName()] = deviceInfo

        firstDevice = QAudioDeviceInfo.availableDevices(mode)[0].deviceName()
        self.deviceChanged(firstDevice)

    @Slot(str)
    def deviceChanged(self, idx):
        if len(self._availableDevices) == 0:
            return
        newLabels = []
        newLabels.append(idx)  # device - 0

        # device has changed
        self.deviceInfo = self._availableDevices[idx]

        codecz = self.deviceInfo.supportedCodecs()
        self._availableCodecs = {}
        for codec in codecz:
            self._availableCodecs[codec] = codec
        if len(codecz):
            self.settings.setCodec(codecz[0])
            newLabels.append(codecz[0])  # codec - 1

        freqz = self.deviceInfo.supportedFrequencies()
        self._availableFreqs = {}
        for freq in freqz:
            self._availableFreqs[str(freq)] = freq
        if len(freqz):
            self.settings.setFrequency(freqz[0])
            newLabels.append(str(freqz[0]))  # freq - 2

        chz = self.deviceInfo.supportedChannels()
        self._availableChannels = {}
        for ch in chz:
            self._availableChannels[str(ch)] = ch
        # Add false to create failed condition!
        self._availableChannels["FAIL"] = -1
        if len(chz):
            self.settings.setChannels(chz[0])
            newLabels.append(str(chz[0]))  # channel - 3

        sampleTypes = self.deviceInfo.supportedSampleTypes()
        self._availableTypes = {}
        for sample in sampleTypes:
            self._availableTypes[sampletoString(sample)] = sample
        if len(sampleTypes):
            self.settings.setSampleType(sampleTypes[0])
            newLabels.append(sampletoString(sampleTypes[0]))  # type - 4

        sampleSizes = self.deviceInfo.supportedSampleSizes()
        self._availableSizes = {}
        for sample in sampleSizes:
            self._availableSizes[str(sample)] = sample
        if len(sampleSizes):
            self.settings.setSampleSize(sampleSizes[0])
            newLabels.append(str(sampleSizes[0]))  # size - 5

        endianz = self.deviceInfo.supportedByteOrders()
        self._availableEnds = {}
        for endian in endianz:
            self._availableEnds[byteOrdertoString(endian)] = endian
        if len(endianz):
            self.settings.setByteOrder(endianz[0])
            newLabels.append(byteOrdertoString(endianz[0]))  # end - 6

        # Update all the buttons
        self.modeHasChanged.emit(newLabels)

    @Slot(str)
    def codecChanged(self, idx):
        self.settings.setCodec(self._availableCodecs[idx])

    @Slot(str)
    def freqChanged(self, idx):
        # freq has changed
        self.settings.setFrequency(int(self._availableFreqs[idx]))

    @Slot(str)
    def channelChanged(self, idx):
        self.settings.setChannels(int(self._availableChannels[idx]))

    @Slot(str)
    def sizeChanged(self, idx):
        self.settings.setSampleSize(int(self._availableSizes[idx]))

    @Slot(str)
    def typeChanged(self, idx):
        sampleType = stringToSample(self._availableTypes[idx])
        if sampleType == QAudioFormat.SignedInt:
            self.settings.setSampleType(QAudioFormat.SignedInt)
        elif sampleType == QAudioFormat.UnSignedInt:
            self.settings.setSampleType(QAudioFormat.UnSignedInt)
        elif sampleType == QAudioFormat.Float:
            self.settings.setSampleType(QAudioFormat.Float)

    @Slot(str)
    def endChanged(self, idx):
        endian = stringToByteOrder(self._availableEnds[idx])
        if endian == QAudioFormat.LittleEndian:
            self.settings.setByteOrder(QAudioFormat.LittleEndian)
        elif endian == QAudioFormat.BigEndian:
            self.settings.setByteOrder(QAudioFormat.BigEndian)

    @Property("QStringList", constant=True)
    def availableDevices(self):
        return self._availableDevices.keys()

    @Property("QStringList", constant=True)
    def availableCodecs(self):
        return self._availableCodecs.keys()

    @Property("QStringList", constant=True)
    def availableFreqs(self):
        return self._availableFreqs.keys()

    @Property("QStringList", constant=True)
    def availableChannels(self):
        return self._availableChannels.keys()

    @Property("QStringList", constant=True)
    def availableTypes(self):
        return self._availableTypes.keys()

    @Property("QStringList", constant=True)
    def availableSizes(self):
        return self._availableSizes.keys()

    @Property("QStringList", constant=True)
    def availableEnds(self):
        return self._availableEnds.keys()