#pragma once #include #include #include #include #include #include struct ma_engine; struct ma_context; struct ma_decoder; struct ma_sound; class SoundManager : public QObject { Q_OBJECT public: struct EventSettings { bool enabled = true; float volume = 0.8f; }; static SoundManager* instance(); bool init(); void shutdown(); void setEnabled(bool enabled); bool isEnabled() const; void setVolume(float volume); float volume() const; void setEvent(const QString& name, bool enabled, float volume); EventSettings eventSettings(const QString& name) const; bool loadSound(const QString& name, const QString& filePath); void play(const QString& name); ma_context* context(); void playRawPcm(const int16_t* pcm, int sampleCount, int sampleRate, int channels); void pauseCurrentPcm(); void resumeCurrentPcm(); void stopCurrentPcm(); void seekCurrentPcm(unsigned long long pcmFrame); unsigned long long currentPcmCursor() const; bool isCurrentPcmPlaying() const; int currentPcmSampleRate() const { return m_currentPcmSampleRate; } struct DeviceInfo { QString name; bool isDefault = false; }; static QVector enumeratePlaybackDevices(); static QVector enumerateCaptureDevices(); private: SoundManager() = default; ~SoundManager(); struct LoadedSound { QByteArray mp3Data; ma_decoder* decoder = nullptr; ma_sound* sound = nullptr; }; ma_engine* m_engine = nullptr; ma_context* m_context = nullptr; ma_sound* m_currentPcmSound = nullptr; void* m_currentPcmBuffer = nullptr; int m_currentPcmSampleRate = 0; bool m_initialized = false; bool m_enabled = true; float m_volume = 0.8f; QHash m_eventSettings; QHash m_sounds; };