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:
parent
9fcd3433b3
commit
0d01be5b27
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user