#pragma once

#include "IAudioInterface.h"

#include <alsa/asoundlib.h>
#include <memory>

class AlsaInterface : public IAudioInterface
{
public:
    AlsaInterface();

    ~AlsaInterface();

    static std::unique_ptr<AlsaInterface> Create();

    void play(AudioDevice* device, AudioSample* sample, unsigned duration) override;

private:
    void openDevice(AudioDevice* device) override;

    void setAccessType(AudioDevice* device);

    bool setSampleFormat(AudioDevice* device);

    bool setSampleRate(AudioDevice* device);

    bool setPeriod(AudioDevice* device);

    bool setBufferSize(AudioDevice* device);

    bool setChannelNumber(AudioDevice* device);

    snd_pcm_t* mHandle;
    snd_pcm_hw_params_t* mHardwareParams;
    snd_pcm_uframes_t mPeriodSize;
};

using AlsaInterfacePtr = std::unique_ptr<AlsaInterface>;
