HephAudio v3.0.6
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
LinuxAudio.h
1#pragma once
2#if defined(__linux__) && !defined(__ANDROID__)
3#include "HephAudioShared.h"
4#include "NativeAudio.h"
7#include "Params/AlsaParams.h"
8#include <alsa/asoundlib.h>
9
12namespace HephAudio
13{
14 namespace Native
15 {
20 class HEPH_API LinuxAudio final : public NativeAudio
21 {
22 public:
23 using NativeAudio::InitializeRender;
24 using NativeAudio::InitializeCapture;
25
26 private:
27 static constexpr long volume_max = INT32_MAX;
28
29 private:
30 AlsaParams params;
31 snd_pcm_t* renderPcm;
32 snd_pcm_t* capturePcm;
33
34 public:
36 LinuxAudio();
37
38 LinuxAudio(const LinuxAudio&) = delete;
39 LinuxAudio& operator=(const LinuxAudio&) = delete;
40
42 ~LinuxAudio();
43
44 void SetMasterVolume(double volume) override;
45 double GetMasterVolume() const override;
46 void InitializeRender(AudioDevice* device, AudioFormatInfo format) override;
47 void StopRendering() override;
48 void InitializeCapture(AudioDevice* device, AudioFormatInfo format) override;
49 void StopCapturing() override;
50 void GetNativeParams(NativeAudioParams& nativeParams) const override;
51 void SetNativeParams(const NativeAudioParams& nativeParams) override;
52
53 private:
54 bool EnumerateAudioDevices() override;
55 void RenderData(useconds_t bufferDuration_us);
56 void CaptureData(useconds_t bufferDuration_us);
57 snd_pcm_format_t ToPcmFormat(const AudioFormatInfo& format) const;
58 snd_pcm_chmap* ToPcmChmap(const AudioFormatInfo& format) const;
59 };
60 }
61}
62#endif
#define HEPH_API
Definition HephShared.h:132