1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-23 02:42:39 +01:00

Set up OpenAL buffers etc for MADStream

This commit is contained in:
Timmy Sjöstedt 2016-05-27 14:01:08 +02:00
parent 62243b0382
commit b539b09975
2 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,9 @@
#include <stdint.h>
#include <iostream>
#include <rw/defines.hpp>
#include <AL/al.h>
#include <AL/alc.h>
#include "audio/alCheck.hpp"
#include <vector>
@ -25,6 +28,10 @@ class MADStream : public sf::SoundStream
unsigned int mReadProgress;
std::vector<int16_t> mCurrentSamples;
constexpr static size_t numALbuffers = 8;
ALuint buffers[numALbuffers];
ALuint alSource;
static inline signed int scale(mad_fixed_t sample);
static mad_flow ms_header(void* user, mad_header const* header);
static mad_flow ms_input(void* user, mad_stream* stream);

View File

@ -94,7 +94,8 @@ void MADStream::onSeek(sf::Time timeOffset)
MADStream::MADStream()
: mFdm(nullptr)
{
alCheck(alGenBuffers(numALbuffers, buffers));
alCheck(alGenSources(1, &alSource));
}
MADStream::~MADStream()
@ -136,5 +137,11 @@ bool MADStream::openFromFile(const std::string& loc)
this->initialize(2, mMadSampleRate);
alCheck(alSourcef(alSource, AL_PITCH, 1));
alCheck(alSourcef(alSource, AL_GAIN, 1));
alCheck(alSource3f(alSource, AL_POSITION, 0, 0, 0));
alCheck(alSource3f(alSource, AL_VELOCITY, 0, 0, 0));
alCheck(alSourcei(alSource, AL_LOOPING, AL_FALSE));
return true;
}