Beispiel #1
0
    def __init__(self):
        super(AudioTest, self).__init__()

        self.m_device = QAudioDeviceInfo.defaultOutputDevice()
        self.m_output = None

        self.initializeWindow()
        self.initializeAudio()
Beispiel #2
0
    def __init__(self):
        super(AudioTest, self).__init__()

        self.m_device = QAudioDeviceInfo.defaultOutputDevice()
        self.m_output = None

        self.initializeWindow()
        self.initializeAudio()
Beispiel #3
0
    def __init__(self, args=None):
        AudioDriver.__init__(self, args)
        if args and args.audio_device:
            available_devices = {}
            for device in QAudioDeviceInfo.availableDevices(
                    QAudio.AudioOutput):
                available_devices[device.deviceName()] = device
            try:
                device = available_devices[args.audio_device]
            except KeyError:
                logger.error("Unknown audio device: %r", args.audio_device)
                logger.info("Available devices:")
                for device_name in available_devices:
                    logger.info("    %r", device_name)
                raise AudioDriverError("Unsupported audio device")
        else:
            device = QAudioDeviceInfo.defaultOutputDevice()

        playback_format = device.preferredFormat()
        self.decoder = QAudioDecoder()
        self.decoder.setAudioFormat(playback_format)
        self.output = QAudioOutput(device, playback_format)

        self.device_name = device.deviceName()
        self.duration = None
        self.bytes_written = 0
        self.last_frame = b""
        self.starting = False
        self.output_dev = None
        self.current_file = None
        self.current_buffer = None
        self.current_buffer_pos = 0

        self.output.stateChanged.connect(self.output_state_changed)
        self.output.notify.connect(self.tick)

        self.decoder.error.connect(self.decoder_error)
        self.decoder.finished.connect(self.decoder_finished)
        self.decoder.stateChanged.connect(self.decoder_state_changed)
        self.decoder.positionChanged.connect(self.decoder_pos_changed)
        self.decoder.bufferReady.connect(self.buffer_ready)
Beispiel #4
0
    def initializeAudio(self):
        self.m_pullTimer = QTimer(self)
        self.m_pullTimer.timeout.connect(self.pullTimerExpired)
        self.m_pullMode = True

        self.m_format = QAudioFormat()
        self.m_format.setSampleRate(self.DataSampleRateHz)
        self.m_format.setChannelCount(1)
        self.m_format.setSampleSize(16)
        self.m_format.setCodec('audio/pcm')
        self.m_format.setByteOrder(QAudioFormat.LittleEndian)
        self.m_format.setSampleType(QAudioFormat.SignedInt)

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

        self.m_generator = Generator(self.m_format,
                self.DurationSeconds * 1000000, self.ToneSampleRateHz, self)

        self.createAudioOutput()