Files
utun2/tools/chatgui/src/sound_manager.h
T
Evgeny 4fde0b0325 feat: integrate Opus codec into lib/libopus + voice messages in chatgui
- Add lib/libopus/ (opus v1.6.1 embedded source: CELT 18 .c, SILK 77 .c, SILK float 28 .c, OPUS core 14 .c)
- Add lib/opus_codec.h/.c (wrapper: encoder, decoder, raw PCM int16)
- Add tests/test_opus_codec.c (7 tests: silence, sine, compression, PLC, null, defaults, multi-frame)
- chatgui: AudioRecorder (miniaudio capture, 48kHz mono)
- chatgui: VoiceEncoder (PCM→Opus file with custom container)
- chatgui: VoicePlayer (Opus→PCM playback via SoundManager)
- chatgui: PTT button in InputBar, voice message send/receive in MessageList
- chatgui: AudioDeviceSettingsPage (device selection, persisted in ui_state)
- chatgui: MessageDelegate voice message rendering (play button + duration)
- Update autotools: configure.ac, Makefile.am, src/Makefile.am, tests/Makefile.am
- Update CMake: chatgui CMakeLists.txt, libutun CMakeLists.txt (link libopus_internal.a)
2026-07-26 20:34:38 +03:00

68 lines
1.5 KiB
C++

#pragma once
#include <QObject>
#include <QHash>
#include <QString>
#include <QByteArray>
#include <vector>
#include <cstdint>
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);
struct DeviceInfo {
QString name;
bool isDefault = false;
};
static QVector<DeviceInfo> enumeratePlaybackDevices();
static QVector<DeviceInfo> 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;
bool m_initialized = false;
bool m_enabled = true;
float m_volume = 0.8f;
QHash<QString, EventSettings> m_eventSettings;
QHash<QString, LoadedSound> m_sounds;
};