mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 01:55:25 -04:00
44124711e9
Adapted to changes in GDCore/GDL. git-svn-id: svn://localhost@768 8062f311-0dae-4547-b526-b8ab9ac864a5
132 lines
2.5 KiB
C++
132 lines
2.5 KiB
C++
/**
|
|
This code is re-adapted from SFMLTheora distributed under zlib licence.
|
|
*/
|
|
|
|
#include "VideoAudioInterface.h"
|
|
|
|
VideoAudioInterface::VideoAudioInterface
|
|
(TheoraVideoClip* owner, int nChannels, int freq) :
|
|
TheoraAudioInterface(owner, nChannels, freq), TheoraTimer()
|
|
{
|
|
nChannels_ = nChannels;
|
|
freq_ = freq;
|
|
|
|
read_ = 0;
|
|
|
|
Initialize(nChannels_, freq_);
|
|
}
|
|
|
|
|
|
void VideoAudioInterface::insertData(float** data, int nSamples)
|
|
{
|
|
sf::Lock lock(dataMutex_);
|
|
|
|
for (int i = 0; i < nSamples; ++i) {
|
|
for (int j = 0; j < nChannels_; ++j) {
|
|
float fSample = data[j][i];
|
|
fSample = fSample < -1.0f ? -1.0f : fSample;
|
|
fSample = fSample > 1.0f ? 1.0f : fSample;
|
|
sf::Int16 iSample = static_cast<sf::Int16>(fSample * 32767);
|
|
|
|
data_.push_back(iSample);
|
|
}
|
|
}
|
|
|
|
if (GetStatus() != sf::SoundStream::Playing)
|
|
Play();
|
|
}
|
|
|
|
void VideoAudioInterface::destroy()
|
|
{
|
|
data_.clear();
|
|
read_ = 0;
|
|
}
|
|
|
|
void VideoAudioInterface::play()
|
|
{
|
|
Play();
|
|
}
|
|
|
|
void VideoAudioInterface::pause()
|
|
{
|
|
Pause();
|
|
}
|
|
|
|
void VideoAudioInterface::stop()
|
|
{
|
|
Stop();
|
|
}
|
|
|
|
void VideoAudioInterface::seek(float time)
|
|
{
|
|
Stop();
|
|
|
|
mTime = time;
|
|
|
|
data_.clear();
|
|
read_ = 0;
|
|
|
|
Play();
|
|
}
|
|
|
|
|
|
bool VideoAudioInterface::OnGetData(sf::SoundStream::Chunk& data)
|
|
{
|
|
sf::Lock lock(dataMutex_);
|
|
|
|
if (data_.size() == 0)
|
|
return false;
|
|
|
|
if (read_ > 0)
|
|
data_.erase(data_.begin(), data_.begin() + read_);
|
|
|
|
read_ = data_.size();
|
|
read_ = read_ > SFMLT_AI_MAXBUFFERSIZE ? SFMLT_AI_MAXBUFFERSIZE : read_;
|
|
|
|
if (read_ == 0)
|
|
return false;
|
|
|
|
data.Samples = &data_[0];
|
|
data.NbSamples = read_;
|
|
|
|
return true;
|
|
}
|
|
|
|
void VideoAudioInterface::OnSeek(sf::Uint32 timeOffset)
|
|
{
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
//Audio Interface Factory class //
|
|
///////////////////////////////////////////////////////////
|
|
VideoAudioInterfaceFactory::VideoAudioInterfaceFactory()
|
|
{
|
|
audioInterface_ = NULL;
|
|
}
|
|
|
|
|
|
VideoAudioInterfaceFactory::~VideoAudioInterfaceFactory()
|
|
{
|
|
if (audioInterface_ != NULL) {
|
|
delete audioInterface_;
|
|
audioInterface_ = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
VideoAudioInterface*
|
|
VideoAudioInterfaceFactory::createInstance(TheoraVideoClip* owner,
|
|
int nChannels, int freq)
|
|
{
|
|
if (audioInterface_ != NULL) {
|
|
delete audioInterface_;
|
|
audioInterface_ = NULL;
|
|
}
|
|
|
|
audioInterface_ = new VideoAudioInterface(owner, nChannels, freq);
|
|
|
|
return audioInterface_;
|
|
}
|
|
|