mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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 "audioutilities.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackSound::Wav;
|
||||
|
||||
namespace BlackSound
|
||||
@@ -19,16 +22,27 @@ namespace BlackSound
|
||||
{
|
||||
CResourceSound::CResourceSound(const QString &audioFileName)
|
||||
{
|
||||
m_wavFile = new CWavFile();
|
||||
m_wavFile->open(audioFileName);
|
||||
if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float)
|
||||
CWavFile wavFile;
|
||||
m_fn.clear();
|
||||
m_samples.clear();
|
||||
if (wavFile.open(audioFileName))
|
||||
{
|
||||
m_samples = convertFloatBytesTo16BitPCM(m_wavFile->audioData());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_samples = convertBytesTo16BitPCM(m_wavFile->audioData());
|
||||
if (wavFile.fileFormat().sampleType() == QAudioFormat::Float)
|
||||
{
|
||||
m_samples = convertFloatBytesTo16BitPCM(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
|
||||
|
||||
@@ -31,8 +31,14 @@ namespace BlackSound
|
||||
//! Audio data
|
||||
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:
|
||||
Wav::WavFile *m_wavFile = nullptr;
|
||||
QString m_fn; //!< file name
|
||||
QVector<qint16> m_samples;
|
||||
};
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user