mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
Ref T731, CResourceSound fixed
* avoid memory leak, wav file is only locally needed * remember file name
This commit is contained in:
committed by
Mat Sutcliffe
parent
197854e7de
commit
9d4a821389
@@ -10,7 +10,10 @@
|
|||||||
|
|
||||||
#include "resourcesound.h"
|
#include "resourcesound.h"
|
||||||
#include "audioutilities.h"
|
#include "audioutilities.h"
|
||||||
|
#include "blackmisc/fileutils.h"
|
||||||
|
#include "blackmisc/stringutils.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackSound::Wav;
|
using namespace BlackSound::Wav;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
@@ -19,16 +22,27 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
CResourceSound::CResourceSound(const QString &audioFileName)
|
CResourceSound::CResourceSound(const QString &audioFileName)
|
||||||
{
|
{
|
||||||
m_wavFile = new CWavFile();
|
CWavFile wavFile;
|
||||||
m_wavFile->open(audioFileName);
|
m_fn.clear();
|
||||||
if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float)
|
m_samples.clear();
|
||||||
|
if (wavFile.open(audioFileName))
|
||||||
{
|
{
|
||||||
m_samples = convertFloatBytesTo16BitPCM(m_wavFile->audioData());
|
if (wavFile.fileFormat().sampleType() == QAudioFormat::Float)
|
||||||
}
|
{
|
||||||
else
|
m_samples = convertFloatBytesTo16BitPCM(wavFile.audioData());
|
||||||
{
|
}
|
||||||
m_samples = convertBytesTo16BitPCM(m_wavFile->audioData());
|
else
|
||||||
|
{
|
||||||
|
m_samples = convertBytesTo16BitPCM(wavFile.audioData());
|
||||||
|
}
|
||||||
|
m_fn = audioFileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CResourceSound::isSameFileName(const QString &fn) const
|
||||||
|
{
|
||||||
|
if (fn.isEmpty()) { return false; }
|
||||||
|
return stringCompare(fn, m_fn, CFileUtils::osFileNameCaseSensitivity());
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -31,8 +31,14 @@ namespace BlackSound
|
|||||||
//! Audio data
|
//! Audio data
|
||||||
const QVector<qint16> &audioData() const { return m_samples; }
|
const QVector<qint16> &audioData() const { return m_samples; }
|
||||||
|
|
||||||
|
//! Corresponding file
|
||||||
|
const QString &getFileName() { return m_fn; }
|
||||||
|
|
||||||
|
//! Is same file?
|
||||||
|
bool isSameFileName(const QString &fn) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Wav::WavFile *m_wavFile = nullptr;
|
QString m_fn; //!< file name
|
||||||
QVector<qint16> m_samples;
|
QVector<qint16> m_samples;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user