<commit_before>/* Copyright (c) 2013-2015 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioProcessorQt.h"

#include "AudioDevice.h"

#include <QAudioOutput>

extern "C" {
#include "gba/supervisor/thread.h"
}

using namespace QGBA;

AudioProcessorQt::AudioProcessorQt(QObject* parent)
	: AudioProcessor(parent)
	, m_audioOutput(nullptr)
	, m_device(nullptr)
{
}

void AudioProcessorQt::setInput(GBAThread* input) {
	AudioProcessor::setInput(input);
	if (m_device) {
		m_device->setInput(input);
		if (m_audioOutput) {
			m_device->setFormat(m_audioOutput->format());
		}
	}
}

void AudioProcessorQt::start() {
	if (!m_device) {
		m_device = new AudioDevice(this);
	}

	if (!m_audioOutput) {
		QAudioFormat format;
		format.setSampleRate(44100);
		format.setChannelCount(2);
		format.setSampleSize(16);
		format.setCodec("audio/pcm");
		format.setByteOrder(QAudioFormat::LittleEndian);
		format.setSampleType(QAudioFormat::SignedInt);

		m_audioOutput = new QAudioOutput(format, this);
	}

	m_device->setInput(input());
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(input()->audioBuffers * 4);

	m_audioOutput->start(m_device);
}

void AudioProcessorQt::pause() {
	if (m_audioOutput) {
		m_audioOutput->stop();
	}
}

void AudioProcessorQt::setBufferSamples(int samples) {
	AudioProcessor::setBufferSamples(samples);
	if (m_audioOutput) {
		m_audioOutput->stop();
		m_audioOutput->setBufferSize(samples * 4);
		m_audioOutput->start(m_device);
	}
}

void AudioProcessorQt::inputParametersChanged() {
	if (m_device) {
		m_device->setFormat(m_audioOutput->format());
	}
}<commit_msg>Qt: Fix PulseAudio output with small buffer size<commit_after>/* Copyright (c) 2013-2015 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioProcessorQt.h"

#include "AudioDevice.h"

#include <QAudioOutput>

extern "C" {
#include "gba/supervisor/thread.h"
}

using namespace QGBA;

AudioProcessorQt::AudioProcessorQt(QObject* parent)
	: AudioProcessor(parent)
	, m_audioOutput(nullptr)
	, m_device(nullptr)
{
}

void AudioProcessorQt::setInput(GBAThread* input) {
	AudioProcessor::setInput(input);
	if (m_device) {
		m_device->setInput(input);
		if (m_audioOutput) {
			m_device->setFormat(m_audioOutput->format());
		}
	}
}

void AudioProcessorQt::start() {
	if (!m_device) {
		m_device = new AudioDevice(this);
	}

	if (!m_audioOutput) {
		QAudioFormat format;
		format.setSampleRate(44100);
		format.setChannelCount(2);
		format.setSampleSize(16);
		format.setCodec("audio/pcm");
		format.setByteOrder(QAudioFormat::LittleEndian);
		format.setSampleType(QAudioFormat::SignedInt);

		m_audioOutput = new QAudioOutput(format, this);
		m_audioOutput->setCategory("game");
	}

	m_device->setInput(input());
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(input()->audioBuffers * 4);

	m_audioOutput->start(m_device);
}

void AudioProcessorQt::pause() {
	if (m_audioOutput) {
		m_audioOutput->stop();
	}
}

void AudioProcessorQt::setBufferSamples(int samples) {
	AudioProcessor::setBufferSamples(samples);
	if (m_audioOutput) {
		m_audioOutput->stop();
		m_audioOutput->setBufferSize(samples * 4);
		m_audioOutput->start(m_device);
	}
}

void AudioProcessorQt::inputParametersChanged() {
	if (m_device) {
		m_device->setFormat(m_audioOutput->format());
	}
}
{'fraction_non_alphanumeric': 0.14187893727745823, 'fraction_numerical': 0.012051492741714598, 'mean_word_length': 5.64, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922079', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1279, 'n_words': 234}