LCOV - code coverage report
Current view: top level - src/media/audio - audioloop.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 3 66.7 %
Date: 2024-03-28 08:00:27 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
       5             :  *
       6             :  *  Inspired by tonegenerator of
       7             :  *   Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
       8             :  *
       9             :  *  This program is free software; you can redistribute it and/or modify
      10             :  *  it under the terms of the GNU General Public License as published by
      11             :  *  the Free Software Foundation; either version 3 of the License, or
      12             :  *  (at your option) any later version.
      13             :  *
      14             :  *  This program is distributed in the hope that it will be useful,
      15             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :  *  GNU General Public License for more details.
      18             :  *
      19             :  *  You should have received a copy of the GNU General Public License
      20             :  *  along with this program; if not, write to the Free Software
      21             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      22             :  */
      23             : #pragma once
      24             : 
      25             : #include "ring_types.h"
      26             : #include "noncopyable.h"
      27             : #include "audio_format.h"
      28             : #include "media_buffer.h"
      29             : 
      30             : extern "C" {
      31             : #include <libavutil/frame.h>
      32             : }
      33             : 
      34             : /**
      35             :  * @file audioloop.h
      36             :  * @brief Loop on a sound file
      37             :  */
      38             : 
      39             : namespace jami {
      40             : 
      41             : class AudioLoop
      42             : {
      43             : public:
      44             :     AudioLoop(AudioFormat format);
      45             : 
      46             :     AudioLoop& operator=(AudioLoop&& o) noexcept
      47             :     {
      48             :         std::swap(buffer_, o.buffer_);
      49             :         std::swap(pos_, o.pos_);
      50             :         return *this;
      51             :     }
      52             : 
      53             :     virtual ~AudioLoop();
      54             : 
      55             :     /**
      56             :      * Get the next fragment of the tone
      57             :      * the function change the intern position, and will loop
      58             :      * @param output  The data buffer
      59             :      * @param nb of int16 to send
      60             :      * @param gain The gain [-1.0, 1.0]
      61             :      */
      62             :     void getNext(AVFrame* output, bool mute);
      63             :     std::unique_ptr<AudioFrame> getNext(size_t samples = 0, bool mute = false);
      64             : 
      65             :     void seek(double relative_position);
      66             : 
      67             :     /**
      68             :      * Reset the pointer position
      69             :      */
      70          68 :     void reset() { pos_ = 0; }
      71             : 
      72             :     /**
      73             :      * Accessor to the size of the buffer
      74             :      * @return unsigned int The size
      75             :      */
      76           0 :     size_t getSize() const { return buffer_->nb_samples; }
      77         528 :     AudioFormat getFormat() const { return format_; }
      78             : 
      79             : protected:
      80             :     AudioFormat format_;
      81             :     /** The data buffer */
      82             :     libjami::FrameBuffer buffer_ {};
      83             : 
      84             :     /** current position, set to 0, when initialize */
      85             :     size_t pos_ {0};
      86             : 
      87             : private:
      88             :     NON_COPYABLE(AudioLoop);
      89             :     virtual void onBufferFinish();
      90             : };
      91             : 
      92             : } // namespace jami

Generated by: LCOV version 1.14