Player12
An open source football management simulator
Loading...
Searching...
No Matches
audio_device.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <SDL3/SDL.h>
12
13#include <array>
14#include <atomic>
15#include <thread>
16
17#include "audio/audio_mixer.h"
18
19namespace Audio
20{
33{
34 public:
35 explicit AudioDevice(Mixer& mixer);
37 AudioDevice(const AudioDevice&) = delete;
39
41 bool isOpen();
42
43 private:
44 static void SDLCALL feed(void* userdata, SDL_AudioStream* stream,
45 int additionalAmount, int totalAmount);
46
47 static constexpr int CHUNK_FRAMES = 512;
48
49 void open();
50
52 std::atomic<SDL_AudioStream*> stream{nullptr};
53 bool subsystemStarted = false;
54 std::jthread opener;
56 std::array<float, 2 * CHUNK_FRAMES> chunk{};
57};
58} // namespace Audio
Definition audio_device.h:33
bool isOpen()
Definition audio_device.cpp:44
AudioDevice & operator=(const AudioDevice &)=delete
std::atomic< SDL_AudioStream * > stream
Definition audio_device.h:52
static void SDLCALL feed(void *userdata, SDL_AudioStream *stream, int additionalAmount, int totalAmount)
Definition audio_device.cpp:59
~AudioDevice()
Definition audio_device.cpp:50
static constexpr int CHUNK_FRAMES
Definition audio_device.h:47
std::array< float, 2 *CHUNK_FRAMES > chunk
Definition audio_device.h:56
std::jthread opener
Definition audio_device.h:54
Mixer & mixer
Definition audio_device.h:51
void open()
Definition audio_device.cpp:29
AudioDevice(const AudioDevice &)=delete
bool subsystemStarted
Definition audio_device.h:53
Definition audio_mixer.h:40
Definition audio_device.cpp:17