<commit_before>#include "AudioProcessor.h"

#include "AudioDevice.h"

#include <QAudioOutput>

extern "C" {
#include "gba-thread.h"
}

using namespace QGBA;

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

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

void AudioProcessor::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(m_context);
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(m_context->audioBuffers * 4);

	m_audioOutput->start(m_device);
}

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

void AudioProcessor::setBufferSamples(int samples) {
	QAudioFormat format = m_audioOutput->format();
	m_audioOutput->setBufferSize(samples * format.channelCount() * format.sampleSize() / 8);
}<commit_msg>Only try to stop audio output if there is an audio output device<commit_after>#include "AudioProcessor.h"

#include "AudioDevice.h"

#include <QAudioOutput>

extern "C" {
#include "gba-thread.h"
}

using namespace QGBA;

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

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

void AudioProcessor::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(m_context);
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(m_context->audioBuffers * 4);

	m_audioOutput->start(m_device);
}

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

void AudioProcessor::setBufferSamples(int samples) {
	QAudioFormat format = m_audioOutput->format();
	m_audioOutput->setBufferSize(samples * format.channelCount() * format.sampleSize() / 8);
}
{'fraction_non_alphanumeric': 0.14248990084465663, 'fraction_numerical': 0.007344840249724568, 'mean_word_length': 6.130890052356021, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '3204246', 'n_tokens_mistral': 1023, 'n_tokens_neox': 970, 'n_words': 150}