swift
Loading...
Searching...
No Matches
bufferedwaveprovider.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDebug>
7
9
10namespace swift::sound::sample_provider
11{
13 {
14 const QString on =
15 QStringLiteral("%1 format: '%2'").arg(this->metaObject()->className(), swift::sound::toQString(format));
16 this->setObjectName(on);
17
18 // Set buffer size to 10 secs
19 m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000);
20 }
21
23 {
24 int delta = m_audioBuffer.size() + samples.size() - m_maxBufferSize;
25 if (delta > 0)
26 {
27 m_audioBuffer.remove(0, delta);
28 }
29 m_audioBuffer.append(samples);
30 }
31
33 {
34 const int len = static_cast<int>(qMin(count, static_cast<qint64>(m_audioBuffer.size())));
35 samples = m_audioBuffer.mid(0, len);
36 // if (len != 0) qDebug() << "Reading" << count << "samples." << m_audioBuffer.size() << "currently in the
37 // buffer.";
38 m_audioBuffer.remove(0, len);
39 return len;
40 }
41
42 void CBufferedWaveProvider::clearBuffer() { m_audioBuffer.clear(); }
43} // namespace swift::sound::sample_provider
int readSamples(QVector< float > &samples, qint64 count)
ISampleProvider::readSamples.
CBufferedWaveProvider(const QAudioFormat &format, QObject *parent=nullptr)
Ctor.
void addSamples(const QVector< float > &samples)
Add samples.
ISampleProvider(QObject *parent=nullptr)
Ctor.
QList< T > mid(qsizetype pos, qsizetype length) const const
void remove(qsizetype i, qsizetype n)
qsizetype size() const const
QObject(QObject *parent)
virtual const QMetaObject * metaObject() const const
QObject * parent() const const
void setObjectName(QAnyStringView name)
QString arg(Args &&... args) const const