File indexing completed on 2025-02-23 04:35:41

0001 /*
0002     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef WAVEBUFFER_H
0008 #define WAVEBUFFER_H
0009 
0010 #include "streamprocessor/streamprocessor.h"
0011 
0012 #include <QObject>
0013 
0014 // FIXME: make sample size configurable or drop this
0015 //*
0016 #define SAMPLE_TYPE qint16
0017 #define SAMPLE_MIN -32768
0018 #define SAMPLE_MAX 32767
0019 /*/
0020 #define SAMPLE_TYPE quint8
0021 #define SAMPLE_MIN 0
0022 #define SAMPLE_MAX 255
0023 //*/
0024 
0025 namespace SubtitleComposer {
0026 class WaveformWidget;
0027 class ZoomBuffer;
0028 
0029 struct WaveZoomData {
0030     quint32 min;
0031     quint32 max;
0032 };
0033 
0034 class WaveBuffer : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     explicit WaveBuffer(WaveformWidget *parent = nullptr);
0040 
0041     /**
0042      * @brief waveformDuration
0043      * @return seconds FIXME: make it milliseconds
0044      */
0045     inline quint32 waveformDuration() const { return m_waveformDuration; }
0046 
0047     inline quint32 lengthMillis() const { return m_waveformChannelSize * 1000 / m_samplesSec; }
0048     inline quint32 lengthSamples() const { return m_waveformChannelSize; }
0049 
0050     /**
0051      * @brief sampleRateMillis
0052      * @return number of samples per second
0053      */
0054     inline quint32 sampleRate() const { return m_samplesSec; }
0055 
0056     quint32 millisPerPixel() const;
0057 
0058     inline quint16 channels() const { return m_waveformChannels; }
0059 
0060     inline bool isDecoding() const { return m_wfFrame != nullptr; }
0061 
0062     /**
0063      * @brief MAX_WINDOW_ZOOM
0064      * @return FIXME:
0065      */
0066     inline static quint32 MAX_WINDOW_ZOOM() { return 3000; }
0067 
0068     quint32 samplesAvailable() const;
0069 
0070     void setAudioStream(const QString &mediaFile, int audioStream);
0071     void setNullAudioStream(quint64 msecVideoLength);
0072     void clearAudioStream();
0073 
0074     inline ZoomBuffer * zoomBuffer() const { return m_zoomBuffer; }
0075 
0076 signals:
0077     void waveformUpdated();
0078 
0079 private:
0080     void onStreamData(const void *buffer, qint32 size, const WaveFormat *waveFormat, const qint64 msecStart, const qint64 msecDuration);
0081     void onStreamProgress(quint64 msecPos, quint64 msecLength);
0082     void onStreamFinished();
0083 
0084 private:
0085     WaveformWidget *m_wfWidget;
0086 
0087     StreamProcessor *m_stream;
0088 
0089     quint32 m_waveformDuration; // FIXME: change to msec
0090     quint16 m_waveformChannels;
0091     quint32 m_waveformChannelSize;
0092     SAMPLE_TYPE **m_waveform;
0093 
0094     quint32 m_samplesSec;
0095 
0096     struct WaveformFrame *m_wfFrame;
0097 
0098     ZoomBuffer *m_zoomBuffer;
0099 };
0100 }
0101 
0102 #endif // WAVEBUFFER_H