mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
Ref T730, style
This commit is contained in:
committed by
Mat Sutcliffe
parent
cd58108bfe
commit
6a9109bf8f
@@ -32,8 +32,10 @@ namespace BlackSound
|
||||
//! Noise generator
|
||||
CPinkNoiseGenerator(QObject *parent = nullptr) : ISampleProvider(parent) {}
|
||||
|
||||
//! Read samples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! Gain
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BlackSound
|
||||
{
|
||||
CResourceSound::CResourceSound(const QString &audioFileName)
|
||||
{
|
||||
m_wavFile = new WavFile;
|
||||
m_wavFile = new CWavFile();
|
||||
m_wavFile->open(audioFileName);
|
||||
if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float)
|
||||
{
|
||||
@@ -30,10 +30,5 @@ namespace BlackSound
|
||||
m_samples = convertBytesTo16BitPCM(m_wavFile->audioData());
|
||||
}
|
||||
}
|
||||
|
||||
const QVector<qint16> &CResourceSound::audioData()
|
||||
{
|
||||
return m_samples;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace BlackSound
|
||||
//! Sound of audio file
|
||||
CResourceSound(const QString &audioFileName);
|
||||
|
||||
const QVector<qint16> &audioData();
|
||||
//! Audio data
|
||||
const QVector<qint16> &audioData() const { return m_samples; }
|
||||
|
||||
private:
|
||||
Wav::WavFile *m_wavFile = nullptr;
|
||||
Wav::WavFile *m_wavFile = nullptr;
|
||||
QVector<qint16> m_samples;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace BlackSound
|
||||
|
||||
const qint64 samplesToCopy = qMin(availableSamples, count);
|
||||
samples.clear();
|
||||
samples.fill(0, samplesToCopy);
|
||||
samples.fill(0, static_cast<int>(samplesToCopy));
|
||||
|
||||
for (int i = 0; i < samplesToCopy; i++)
|
||||
{
|
||||
m_tempBuffer[i] = m_resourceSound.audioData().at(m_position + i);
|
||||
m_tempBuffer[i] = m_resourceSound.audioData().at(static_cast<int>(m_position) + i);
|
||||
}
|
||||
|
||||
if (!qFuzzyCompare(m_gain, 1.0))
|
||||
@@ -54,5 +54,5 @@ namespace BlackSound
|
||||
|
||||
return static_cast<int>(samplesToCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -26,21 +26,30 @@ namespace BlackSound
|
||||
//! Ctor
|
||||
CResourceSoundSampleProvider(const CResourceSound &resourceSound, QObject *parent = nullptr);
|
||||
|
||||
//! copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! copydoc ISampleProvider::isFinished
|
||||
virtual bool isFinished() const override { return m_isFinished; }
|
||||
|
||||
//! Looping @{
|
||||
bool looping() const { return m_looping; }
|
||||
void setLooping(bool looping) { m_looping = looping; }
|
||||
// @}
|
||||
|
||||
//! Gain @{
|
||||
double gain() const { return m_gain; }
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
//! @}
|
||||
|
||||
//! Temp buffer @{
|
||||
QVector<qint16> getTempBuffer() const { return m_tempBuffer; }
|
||||
void setTempBuffer(const QVector<qint16> &value) { m_tempBuffer = value; }
|
||||
//! @}
|
||||
|
||||
private:
|
||||
double m_gain = 1.0;
|
||||
bool m_looping = false;
|
||||
double m_gain = 1.0;
|
||||
bool m_looping = false;
|
||||
|
||||
CResourceSound m_resourceSound;
|
||||
qint64 m_position = 0;
|
||||
@@ -48,7 +57,7 @@ namespace BlackSound
|
||||
QVector<qint16> m_tempBuffer;
|
||||
bool m_isFinished = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -21,20 +21,24 @@ namespace BlackSound
|
||||
class BLACKSOUND_EXPORT Samples
|
||||
{
|
||||
public:
|
||||
//! Singleton
|
||||
static Samples &instance();
|
||||
|
||||
//! Various samples (sounds) @{
|
||||
CResourceSound crackle() const;
|
||||
CResourceSound click() const;
|
||||
CResourceSound whiteNoise() const;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
//! Ctor
|
||||
Samples();
|
||||
|
||||
CResourceSound m_crackle;
|
||||
CResourceSound m_click;
|
||||
CResourceSound m_whiteNoise;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // SAMPLES_H
|
||||
#endif // guard
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include <qendian.h>
|
||||
#include <QVector>
|
||||
#include <QDebug>
|
||||
// #include "utils.h"
|
||||
#include "wavfile.h"
|
||||
// #include "utils.h"
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
@@ -50,29 +50,29 @@ namespace BlackSound
|
||||
WAVEHeader wave;
|
||||
};
|
||||
|
||||
WavFile::WavFile(QObject *parent) :
|
||||
CWavFile::CWavFile(QObject *parent) :
|
||||
QFile(parent),
|
||||
m_headerLength(0)
|
||||
{ }
|
||||
|
||||
bool WavFile::open(const QString &fileName)
|
||||
bool CWavFile::open(const QString &fileName)
|
||||
{
|
||||
close();
|
||||
setFileName(fileName);
|
||||
return QFile::open(QIODevice::ReadOnly) && readHeader();
|
||||
}
|
||||
|
||||
const QAudioFormat &WavFile::fileFormat() const
|
||||
const QAudioFormat &CWavFile::fileFormat() const
|
||||
{
|
||||
return m_fileFormat;
|
||||
}
|
||||
|
||||
qint64 WavFile::headerLength() const
|
||||
qint64 CWavFile::headerLength() const
|
||||
{
|
||||
return m_headerLength;
|
||||
}
|
||||
|
||||
bool WavFile::readHeader()
|
||||
bool CWavFile::readHeader()
|
||||
{
|
||||
seek(0);
|
||||
CombinedHeader header;
|
||||
@@ -132,15 +132,14 @@ namespace BlackSound
|
||||
|
||||
if (memcmp(&dataHeader.descriptor.id, "data", 4) == 0)
|
||||
{
|
||||
qint32 dataLength = qFromLittleEndian<qint32>(dataHeader.descriptor.size);
|
||||
const qint32 dataLength = qFromLittleEndian<qint32>(dataHeader.descriptor.size);
|
||||
m_audioData = read(dataLength);
|
||||
if (m_audioData.size() != dataLength)
|
||||
{
|
||||
return false;
|
||||
m_audioData.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -20,22 +20,30 @@ namespace BlackSound
|
||||
namespace Wav
|
||||
{
|
||||
//! * WAV file
|
||||
class WavFile : public QFile
|
||||
class CWavFile : public QFile
|
||||
{
|
||||
public:
|
||||
//! Ctor
|
||||
WavFile(QObject *parent = nullptr);
|
||||
CWavFile(QObject *parent = nullptr);
|
||||
|
||||
//! Standard open
|
||||
using QFile::open;
|
||||
|
||||
//! Open
|
||||
bool open(const QString &fileName);
|
||||
|
||||
//! Audio format
|
||||
const QAudioFormat &fileFormat() const;
|
||||
|
||||
//! Header length
|
||||
qint64 headerLength() const;
|
||||
QByteArray audioData() { return m_audioData; }
|
||||
|
||||
//! The audio data
|
||||
const QByteArray &audioData() const { return m_audioData; }
|
||||
|
||||
private:
|
||||
bool readHeader();
|
||||
|
||||
private:
|
||||
QAudioFormat m_fileFormat;
|
||||
qint64 m_headerLength;
|
||||
QByteArray m_audioData;
|
||||
|
||||
Reference in New Issue
Block a user