1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-19 08:52:33 +02:00

Implemented SoundSource class to handle libsndfile loading

This commit is contained in:
Timmy Sjöstedt 2016-05-24 21:07:03 +02:00
parent 9fcd3433b3
commit 0d01be5b27
2 changed files with 28 additions and 0 deletions

View File

@ -26,6 +26,17 @@ private:
sf::SoundBuffer buffer;
};
class SoundSource
{
friend class SoundManager;
public:
void loadFromFile(const std::string& filename);
private:
SF_INFO fileInfo;
SNDFILE* file;
std::vector<uint16_t> data;
};
std::vector<PlayingSound> sounds;
sf::SoundStream* backgroundNoise;

View File

@ -11,6 +11,23 @@ void checkALerror(const std::string& file, unsigned int line);
#define alCheck(stmt) stmt
#endif
void SoundManager::SoundSource::loadFromFile(const std::string& filename)
{
fileInfo.format = 0;
file = sf_open(filename.c_str(), SFM_READ, &fileInfo);
if (file) {
size_t numRead = 0;
std::array<int16_t, 4096> readBuffer;
while ((numRead = sf_read_short(file, readBuffer.data(), readBuffer.size())) != 0) {
data.insert(data.end(), readBuffer.begin(), readBuffer.begin() + numRead);
}
} else {
std::cerr << "Error opening sound file \"" << filename << "\": " << sf_strerror(file) << std::endl;
}
}
SoundManager::SoundManager()
: backgroundNoise(nullptr)
{