Add cairo interface.
This commit is contained in:
parent
a03eb9599f
commit
9bcc0ae88e
63 changed files with 1247 additions and 450 deletions
|
@ -20,7 +20,7 @@ std::unique_ptr<AudioManager> AudioManager::Create()
|
|||
|
||||
void AudioManager::AddAudioDevice(AudioDevicePtr device)
|
||||
{
|
||||
mAudioDevices.push_back(device);
|
||||
mAudioDevices.push_back(std::move(device));
|
||||
}
|
||||
|
||||
IAudioInterface* AudioManager::GetAudioInterface()
|
||||
|
@ -28,7 +28,26 @@ IAudioInterface* AudioManager::GetAudioInterface()
|
|||
return mAudioInterface.get();
|
||||
}
|
||||
|
||||
std::vector<AudioDevicePtr> AudioManager::GetAudioDevices()
|
||||
unsigned AudioManager::GetNumAudioDevices() const
|
||||
{
|
||||
return mAudioDevices;
|
||||
return mAudioDevices.size();
|
||||
}
|
||||
|
||||
AudioDevice* AudioManager::GetAudioDevice(unsigned idx) const
|
||||
{
|
||||
if (idx < mAudioDevices.size())
|
||||
{
|
||||
return mAudioDevices[idx].get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AudioManager::Play()
|
||||
{
|
||||
if (mAudioDevices.size() == 0)
|
||||
{
|
||||
mAudioDevices.push_back(AudioDevice::Create());
|
||||
}
|
||||
mAudioInterface->OpenDevice(mAudioDevices[0]);
|
||||
mAudioInterface->Play(mAudioDevices[0]);
|
||||
}
|
||||
|
|
|
@ -24,9 +24,13 @@ public:
|
|||
|
||||
void AddAudioDevice(AudioDevicePtr device);
|
||||
|
||||
std::vector<AudioDevicePtr> GetAudioDevices();
|
||||
unsigned GetNumAudioDevices() const;
|
||||
|
||||
AudioDevice* GetAudioDevice(unsigned idx) const;
|
||||
|
||||
IAudioInterface* GetAudioInterface();
|
||||
|
||||
void Play();
|
||||
};
|
||||
|
||||
using AudioManagerUPtr = std::unique_ptr<AudioManager>;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
|
||||
find_package(ALSA REQUIRED)
|
||||
|
||||
list(APPEND linux_HEADERS
|
||||
audio_interfaces/AlsaInterface.h
|
||||
${ALSA_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
list(APPEND audio_HEADERS
|
||||
|
@ -37,7 +41,7 @@ target_include_directories(audio PUBLIC
|
|||
)
|
||||
|
||||
list(APPEND linux_LIBS
|
||||
asound
|
||||
${ALSA_LIBRARIES}
|
||||
)
|
||||
|
||||
target_link_libraries(audio PUBLIC core ${linux_LIBS})
|
||||
|
|
|
@ -14,9 +14,9 @@ AlsaInterface::~AlsaInterface()
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<AlsaInterface> AlsaInterface::Create()
|
||||
std::unique_ptr<AlsaInterface> AlsaInterface::Create()
|
||||
{
|
||||
return std::make_shared<AlsaInterface>();
|
||||
return std::make_unique<AlsaInterface>();
|
||||
}
|
||||
|
||||
void AlsaInterface::OpenDevice(const AudioDevicePtr& device)
|
||||
|
@ -51,7 +51,7 @@ void AlsaInterface::OpenDevice(const AudioDevicePtr& device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetAccessType(AudioDevicePtr device)
|
||||
void AlsaInterface::SetAccessType(const AudioDevicePtr& device)
|
||||
{
|
||||
if (snd_pcm_hw_params_set_access(mHandle, mHardwareParams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
|
||||
MLOG_ERROR("Error setting device access.");
|
||||
|
@ -59,7 +59,7 @@ void AlsaInterface::SetAccessType(AudioDevicePtr device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetSampleFormat(AudioDevicePtr device)
|
||||
void AlsaInterface::SetSampleFormat(const AudioDevicePtr& device)
|
||||
{
|
||||
/* Set sample format */
|
||||
if (snd_pcm_hw_params_set_format(mHandle, mHardwareParams, SND_PCM_FORMAT_S16_LE) < 0) {
|
||||
|
@ -68,7 +68,7 @@ void AlsaInterface::SetSampleFormat(AudioDevicePtr device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetSampleRate(AudioDevicePtr device)
|
||||
void AlsaInterface::SetSampleRate(const AudioDevicePtr& device)
|
||||
{
|
||||
unsigned rate = device->GetSampleRate();
|
||||
unsigned exact_rate = rate;
|
||||
|
@ -82,7 +82,7 @@ void AlsaInterface::SetSampleRate(AudioDevicePtr device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetPeriod(AudioDevicePtr device)
|
||||
void AlsaInterface::SetPeriod(const AudioDevicePtr& device)
|
||||
{
|
||||
/* Set number of periods. Periods used to be called fragments. */
|
||||
if (snd_pcm_hw_params_set_periods(mHandle, mHardwareParams, device->GetPeriod(), 0) < 0)
|
||||
|
@ -92,7 +92,7 @@ void AlsaInterface::SetPeriod(AudioDevicePtr device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetBufferSize(AudioDevicePtr device)
|
||||
void AlsaInterface::SetBufferSize(const AudioDevicePtr& device)
|
||||
{
|
||||
int periods = static_cast<int>(device->GetPeriod());
|
||||
|
||||
|
@ -105,7 +105,7 @@ void AlsaInterface::SetBufferSize(AudioDevicePtr device)
|
|||
}
|
||||
}
|
||||
|
||||
void AlsaInterface::SetChannelNumber(AudioDevicePtr device)
|
||||
void AlsaInterface::SetChannelNumber(const AudioDevicePtr& device)
|
||||
{
|
||||
/* Set number of channels */
|
||||
if (snd_pcm_hw_params_set_channels(mHandle, mHardwareParams, device->GetNumChannels()) < 0)
|
||||
|
|
|
@ -19,21 +19,21 @@ public:
|
|||
|
||||
~AlsaInterface();
|
||||
|
||||
static std::shared_ptr<AlsaInterface> Create();
|
||||
static std::unique_ptr<AlsaInterface> Create();
|
||||
|
||||
void OpenDevice(const AudioDevicePtr& device) override;
|
||||
|
||||
void SetAccessType(AudioDevicePtr device);
|
||||
void SetAccessType(const AudioDevicePtr& device);
|
||||
|
||||
void SetSampleFormat(AudioDevicePtr device);
|
||||
void SetSampleFormat(const AudioDevicePtr& device);
|
||||
|
||||
void SetSampleRate(AudioDevicePtr device);
|
||||
void SetSampleRate(const AudioDevicePtr& device);
|
||||
|
||||
void SetPeriod(AudioDevicePtr device);
|
||||
void SetPeriod(const AudioDevicePtr& device);
|
||||
|
||||
void SetBufferSize(AudioDevicePtr device);
|
||||
void SetBufferSize(const AudioDevicePtr& device);
|
||||
|
||||
void SetChannelNumber(AudioDevicePtr device);
|
||||
void SetChannelNumber(const AudioDevicePtr& device);
|
||||
|
||||
void Play(const AudioDevicePtr& device) override;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue