~aleteoryx/muditaos

ref: f7f4adc19f17944349eeae2bcde8e5c98235e4e3 muditaos/module-audio/board/rt1051/SAIAudioDevice.hpp -rw-r--r-- 1.1 KiB
f7f4adc1 — Maciej Gibowicz [BH-1264] Add alarm sound fade in 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Audio/AudioDevice.hpp>
#include <Audio/Stream.hpp>

#include "fsl_sai_edma.h"

namespace audio
{

    class SAIAudioDevice : public AudioDevice
    {
      public:
        SAIAudioDevice(I2S_Type *base, sai_edma_handle_t *rxHandle, sai_edma_handle_t *txHandle);

        void onDataSend() override;
        void onDataReceive() override;
        void enableInput() override;
        void enableOutput() override;
        void disableInput() override;
        void disableOutput() override;

      protected:
        void initiateRxTransfer();
        void initiateTxTransfer();
        RetCode setOutputVolume(float vol) override;

        I2S_Type *_base;
        sai_edma_handle_t *rx = nullptr;
        sai_edma_handle_t *tx = nullptr;
        bool txEnabled        = false;
        bool rxEnabled        = false;

      private:
        void scaleOutputVolume(audio::Stream::Span &span);

        float volumeFactor{1.0};
    };

} // namespace audio