forked from bartvdbraak/blender
3D Audio GSoC:
Streaming improved.
This commit is contained in:
parent
7ba4362c72
commit
cc71dcc218
@ -55,9 +55,9 @@ AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
|
|||||||
delete[] m_y;
|
delete[] m_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_BaseIIRFilterReader::read(int & length, sample_t* buffer)
|
void AUD_BaseIIRFilterReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
m_reader->read(length, buffer);
|
m_reader->read(length, eos, buffer);
|
||||||
|
|
||||||
for(m_channel = 0; m_channel < m_channels; m_channel++)
|
for(m_channel = 0; m_channel < m_channels; m_channel++)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ public:
|
|||||||
|
|
||||||
virtual ~AUD_BaseIIRFilterReader();
|
virtual ~AUD_BaseIIRFilterReader();
|
||||||
|
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
|
|
||||||
virtual sample_t filter()=0;
|
virtual sample_t filter()=0;
|
||||||
};
|
};
|
||||||
|
@ -69,7 +69,7 @@ int AUD_DelayReader::getPosition() const
|
|||||||
return m_reader->getPosition() + m_delay;
|
return m_reader->getPosition() + m_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_DelayReader::read(int & length, sample_t* buffer)
|
void AUD_DelayReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
if(m_remdelay > 0)
|
if(m_remdelay > 0)
|
||||||
{
|
{
|
||||||
@ -81,10 +81,9 @@ void AUD_DelayReader::read(int & length, sample_t* buffer)
|
|||||||
memset(buffer, 0, m_remdelay * samplesize);
|
memset(buffer, 0, m_remdelay * samplesize);
|
||||||
|
|
||||||
int len = length - m_remdelay;
|
int len = length - m_remdelay;
|
||||||
m_reader->read(len, buffer + m_remdelay * specs.channels);
|
m_reader->read(len, eos, buffer + m_remdelay * specs.channels);
|
||||||
|
|
||||||
if(len < length-m_remdelay)
|
length = m_remdelay + len;
|
||||||
length = m_remdelay + len;
|
|
||||||
|
|
||||||
m_remdelay = 0;
|
m_remdelay = 0;
|
||||||
}
|
}
|
||||||
@ -95,5 +94,5 @@ void AUD_DelayReader::read(int & length, sample_t* buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_reader->read(length, buffer);
|
m_reader->read(length, eos, buffer);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
virtual void seek(int position);
|
virtual void seek(int position);
|
||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_DELAYREADER
|
#endif //AUD_DELAYREADER
|
||||||
|
@ -89,29 +89,27 @@ AUD_Specs AUD_DoubleReader::getSpecs() const
|
|||||||
return m_reader1->getSpecs();
|
return m_reader1->getSpecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_DoubleReader::read(int & length, sample_t* buffer)
|
void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
if(!m_finished1)
|
if(!m_finished1)
|
||||||
{
|
{
|
||||||
int len = length;
|
int len = length;
|
||||||
m_reader1->read(len, buffer);
|
m_reader1->read(len, m_finished1, buffer);
|
||||||
|
|
||||||
if(len < length)
|
if(m_finished1)
|
||||||
{
|
{
|
||||||
const AUD_Specs specs = m_reader1->getSpecs();
|
const AUD_Specs specs = m_reader1->getSpecs();
|
||||||
|
|
||||||
len = length - len;
|
len = length - len;
|
||||||
length -= len;
|
length -= len;
|
||||||
|
|
||||||
m_reader2->read(len, buffer + length * specs.channels);
|
m_reader2->read(len, eos, buffer + length * specs.channels);
|
||||||
|
|
||||||
length += len;
|
length += len;
|
||||||
|
|
||||||
m_finished1 = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_reader2->read(length, buffer);
|
m_reader2->read(length, eos, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_DOUBLEREADER
|
#endif //AUD_DOUBLEREADER
|
||||||
|
@ -65,7 +65,7 @@ AUD_Specs AUD_EffectReader::getSpecs() const
|
|||||||
return m_reader->getSpecs();
|
return m_reader->getSpecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_EffectReader::read(int & length, sample_t* buffer)
|
void AUD_EffectReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
m_reader->read(length, buffer);
|
m_reader->read(length, eos, buffer);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_EFFECTREADER
|
#endif //AUD_EFFECTREADER
|
||||||
|
@ -42,13 +42,13 @@ AUD_FaderReader::AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_FaderReader::read(int & length, sample_t* buffer)
|
void AUD_FaderReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
int position = m_reader->getPosition();
|
int position = m_reader->getPosition();
|
||||||
AUD_Specs specs = m_reader->getSpecs();
|
AUD_Specs specs = m_reader->getSpecs();
|
||||||
int samplesize = AUD_SAMPLE_SIZE(specs);
|
int samplesize = AUD_SAMPLE_SIZE(specs);
|
||||||
|
|
||||||
m_reader->read(length, buffer);
|
m_reader->read(length, eos, buffer);
|
||||||
|
|
||||||
if((position + length) / (float)specs.rate <= m_start)
|
if((position + length) / (float)specs.rate <= m_start)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ public:
|
|||||||
AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType type,
|
AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType type,
|
||||||
float start,float length);
|
float start,float length);
|
||||||
|
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_FADERREADER
|
#endif //AUD_FADERREADER
|
||||||
|
@ -49,13 +49,15 @@ AUD_LimiterReader::AUD_LimiterReader(AUD_Reference<AUD_IReader> reader,
|
|||||||
// skip first m_start samples by reading them
|
// skip first m_start samples by reading them
|
||||||
int length = AUD_DEFAULT_BUFFER_SIZE;
|
int length = AUD_DEFAULT_BUFFER_SIZE;
|
||||||
AUD_Buffer buffer(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(m_reader->getSpecs()));
|
AUD_Buffer buffer(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(m_reader->getSpecs()));
|
||||||
|
bool eos = false;
|
||||||
for(int len = m_start;
|
for(int len = m_start;
|
||||||
length == AUD_DEFAULT_BUFFER_SIZE;
|
length == AUD_DEFAULT_BUFFER_SIZE && !eos;
|
||||||
len -= AUD_DEFAULT_BUFFER_SIZE)
|
len -= AUD_DEFAULT_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
if(len < AUD_DEFAULT_BUFFER_SIZE)
|
if(len < AUD_DEFAULT_BUFFER_SIZE)
|
||||||
length = len;
|
length = len;
|
||||||
m_reader->read(length, buffer.getBuffer());
|
|
||||||
|
m_reader->read(length, eos, buffer.getBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,18 +82,50 @@ int AUD_LimiterReader::getPosition() const
|
|||||||
return AUD_MIN(pos, m_end) - m_start;
|
return AUD_MIN(pos, m_end) - m_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_LimiterReader::read(int & length, sample_t* buffer)
|
void AUD_LimiterReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
|
eos = false;
|
||||||
if(m_end >= 0)
|
if(m_end >= 0)
|
||||||
{
|
{
|
||||||
int position = m_reader->getPosition();
|
int position = m_reader->getPosition();
|
||||||
if(position + length > m_end)
|
if(position + length > m_end)
|
||||||
|
{
|
||||||
length = m_end - position;
|
length = m_end - position;
|
||||||
|
eos = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(position < m_start)
|
||||||
|
{
|
||||||
|
int len2 = length;
|
||||||
|
for(int len = m_start - position;
|
||||||
|
len2 == length && !eos;
|
||||||
|
len -= length)
|
||||||
|
{
|
||||||
|
if(len < length)
|
||||||
|
len2 = len;
|
||||||
|
|
||||||
|
m_reader->read(len2, eos, buffer);
|
||||||
|
position += len2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(position < m_start)
|
||||||
|
{
|
||||||
|
length = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(length < 0)
|
if(length < 0)
|
||||||
{
|
{
|
||||||
length = 0;
|
length = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_reader->read(length, buffer);
|
if(eos)
|
||||||
|
{
|
||||||
|
m_reader->read(length, eos, buffer);
|
||||||
|
eos = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_reader->read(length, eos, buffer);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
virtual void seek(int position);
|
virtual void seek(int position);
|
||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_LIMITERREADER
|
#endif //AUD_LIMITERREADER
|
||||||
|
@ -68,21 +68,20 @@ int AUD_LoopReader::getPosition() const
|
|||||||
return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
|
return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_LoopReader::read(int & length, sample_t* buffer)
|
void AUD_LoopReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
AUD_Specs specs = m_reader->getSpecs();
|
const AUD_Specs specs = m_reader->getSpecs();
|
||||||
|
|
||||||
int len = length;
|
int len = length;
|
||||||
|
|
||||||
m_reader->read(len, buffer);
|
m_reader->read(length, eos, buffer);
|
||||||
|
|
||||||
if(len < length && m_left)
|
if(length < len && eos && m_left)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = length;
|
||||||
|
length = len;
|
||||||
|
|
||||||
pos += len;
|
while(pos < length && eos && m_left)
|
||||||
|
|
||||||
while(pos < length && m_left)
|
|
||||||
{
|
{
|
||||||
if(m_left > 0)
|
if(m_left > 0)
|
||||||
m_left--;
|
m_left--;
|
||||||
@ -90,7 +89,7 @@ void AUD_LoopReader::read(int & length, sample_t* buffer)
|
|||||||
m_reader->seek(0);
|
m_reader->seek(0);
|
||||||
|
|
||||||
len = length - pos;
|
len = length - pos;
|
||||||
m_reader->read(len, buffer + pos * specs.channels);
|
m_reader->read(len, eos, buffer + pos * specs.channels);
|
||||||
|
|
||||||
// prevent endless loop
|
// prevent endless loop
|
||||||
if(!len)
|
if(!len)
|
||||||
@ -101,6 +100,4 @@ void AUD_LoopReader::read(int & length, sample_t* buffer)
|
|||||||
|
|
||||||
length = pos;
|
length = pos;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
length = len;
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
virtual void seek(int position);
|
virtual void seek(int position);
|
||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_LOOPREADER
|
#endif //AUD_LOOPREADER
|
||||||
|
@ -60,7 +60,7 @@ int AUD_ReverseReader::getPosition() const
|
|||||||
return m_position;
|
return m_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_ReverseReader::read(int & length, sample_t* buffer)
|
void AUD_ReverseReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
// first correct the length
|
// first correct the length
|
||||||
if(m_position + length > m_length)
|
if(m_position + length > m_length)
|
||||||
@ -69,6 +69,7 @@ void AUD_ReverseReader::read(int & length, sample_t* buffer)
|
|||||||
if(length <= 0)
|
if(length <= 0)
|
||||||
{
|
{
|
||||||
length = 0;
|
length = 0;
|
||||||
|
eos = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ void AUD_ReverseReader::read(int & length, sample_t* buffer)
|
|||||||
|
|
||||||
// read from reader
|
// read from reader
|
||||||
m_reader->seek(m_length - m_position - len);
|
m_reader->seek(m_length - m_position - len);
|
||||||
m_reader->read(len, buffer);
|
m_reader->read(len, eos, buffer);
|
||||||
|
|
||||||
// set null if reader didn't give enough data
|
// set null if reader didn't give enough data
|
||||||
if(len < length)
|
if(len < length)
|
||||||
@ -102,4 +103,5 @@ void AUD_ReverseReader::read(int & length, sample_t* buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
eos = false;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
virtual void seek(int position);
|
virtual void seek(int position);
|
||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_REVERSEREADER
|
#endif //AUD_REVERSEREADER
|
||||||
|
@ -82,7 +82,7 @@ AUD_Specs AUD_SuperposeReader::getSpecs() const
|
|||||||
return m_reader1->getSpecs();
|
return m_reader1->getSpecs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SuperposeReader::read(int & length, sample_t* buffer)
|
void AUD_SuperposeReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
AUD_Specs specs = m_reader1->getSpecs();
|
AUD_Specs specs = m_reader1->getSpecs();
|
||||||
int samplesize = AUD_SAMPLE_SIZE(specs);
|
int samplesize = AUD_SAMPLE_SIZE(specs);
|
||||||
@ -90,17 +90,19 @@ void AUD_SuperposeReader::read(int & length, sample_t* buffer)
|
|||||||
m_buffer.assureSize(length * samplesize);
|
m_buffer.assureSize(length * samplesize);
|
||||||
|
|
||||||
int len1 = length;
|
int len1 = length;
|
||||||
m_reader1->read(len1, buffer);
|
m_reader1->read(len1, eos, buffer);
|
||||||
|
|
||||||
if(len1 < length)
|
if(len1 < length)
|
||||||
memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
|
memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
|
||||||
|
|
||||||
int len2 = length;
|
int len2 = length;
|
||||||
|
bool eos2;
|
||||||
sample_t* buf = m_buffer.getBuffer();
|
sample_t* buf = m_buffer.getBuffer();
|
||||||
m_reader2->read(len2, buf);
|
m_reader2->read(len2, eos2, buf);
|
||||||
|
|
||||||
for(int i = 0; i < len2 * specs.channels; i++)
|
for(int i = 0; i < len2 * specs.channels; i++)
|
||||||
buffer[i] += buf[i];
|
buffer[i] += buf[i];
|
||||||
|
|
||||||
length = AUD_MAX(len1, len2);
|
length = AUD_MAX(len1, len2);
|
||||||
|
eos &= eos2;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SUPERPOSEREADER
|
#endif //AUD_SUPERPOSEREADER
|
||||||
|
@ -70,7 +70,7 @@ struct AUD_OpenALHandle : AUD_Handle
|
|||||||
int current;
|
int current;
|
||||||
|
|
||||||
/// Whether the stream doesn't return any more data.
|
/// Whether the stream doesn't return any more data.
|
||||||
bool data_end;
|
bool eos;
|
||||||
|
|
||||||
/// The loop count of the source.
|
/// The loop count of the source.
|
||||||
int loopcount;
|
int loopcount;
|
||||||
@ -166,11 +166,11 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
while(info--)
|
while(info--)
|
||||||
{
|
{
|
||||||
// if there's still data to play back
|
// if there's still data to play back
|
||||||
if(!sound->data_end)
|
if(!sound->eos)
|
||||||
{
|
{
|
||||||
// read data
|
// read data
|
||||||
length = m_buffersize;
|
length = m_buffersize;
|
||||||
sound->reader->read(length, m_buffer.getBuffer());
|
sound->reader->read(length, sound->eos, m_buffer.getBuffer());
|
||||||
|
|
||||||
// looping necessary?
|
// looping necessary?
|
||||||
if(length == 0 && sound->loopcount)
|
if(length == 0 && sound->loopcount)
|
||||||
@ -181,13 +181,15 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
sound->reader->seek(0);
|
sound->reader->seek(0);
|
||||||
|
|
||||||
length = m_buffersize;
|
length = m_buffersize;
|
||||||
sound->reader->read(length, m_buffer.getBuffer());
|
sound->reader->read(length, sound->eos, m_buffer.getBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sound->loopcount != 0)
|
||||||
|
sound->eos = false;
|
||||||
|
|
||||||
// read nothing?
|
// read nothing?
|
||||||
if(length == 0)
|
if(length == 0)
|
||||||
{
|
{
|
||||||
sound->data_end = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +199,7 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
ALenum err;
|
ALenum err;
|
||||||
if((err = alGetError()) != AL_NO_ERROR)
|
if((err = alGetError()) != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
sound->data_end = true;
|
sound->eos = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +212,7 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
|
|
||||||
if((err = alGetError()) != AL_NO_ERROR)
|
if((err = alGetError()) != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
sound->data_end = true;
|
sound->eos = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +221,7 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
&sound->buffers[sound->current]);
|
&sound->buffers[sound->current]);
|
||||||
if(alGetError() != AL_NO_ERROR)
|
if(alGetError() != AL_NO_ERROR)
|
||||||
{
|
{
|
||||||
sound->data_end = true;
|
sound->eos = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +240,7 @@ void AUD_OpenALDevice::updateStreams()
|
|||||||
if(info != AL_PLAYING)
|
if(info != AL_PLAYING)
|
||||||
{
|
{
|
||||||
// if it really stopped
|
// if it really stopped
|
||||||
if(sound->data_end)
|
if(sound->eos)
|
||||||
{
|
{
|
||||||
if(sound->stop)
|
if(sound->stop)
|
||||||
sound->stop(sound->stop_data);
|
sound->stop(sound->stop_data);
|
||||||
@ -556,7 +558,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
|
|||||||
sound->reader = reader;
|
sound->reader = reader;
|
||||||
sound->current = 0;
|
sound->current = 0;
|
||||||
sound->isBuffered = false;
|
sound->isBuffered = false;
|
||||||
sound->data_end = false;
|
|
||||||
sound->loopcount = 0;
|
sound->loopcount = 0;
|
||||||
sound->stop = NULL;
|
sound->stop = NULL;
|
||||||
sound->stop_data = NULL;
|
sound->stop_data = NULL;
|
||||||
@ -587,7 +588,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
|
|||||||
for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
|
for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
|
||||||
{
|
{
|
||||||
length = m_buffersize;
|
length = m_buffersize;
|
||||||
reader->read(length, m_buffer.getBuffer());
|
reader->read(length,sound->eos, m_buffer.getBuffer());
|
||||||
alBufferData(sound->buffers[i], sound->format, m_buffer.getBuffer(),
|
alBufferData(sound->buffers[i], sound->format, m_buffer.getBuffer(),
|
||||||
length * AUD_DEVICE_SAMPLE_SIZE(specs),
|
length * AUD_DEVICE_SAMPLE_SIZE(specs),
|
||||||
specs.rate);
|
specs.rate);
|
||||||
@ -658,7 +659,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IFactory> factory, bool kee
|
|||||||
sound->keep = keep;
|
sound->keep = keep;
|
||||||
sound->current = -1;
|
sound->current = -1;
|
||||||
sound->isBuffered = true;
|
sound->isBuffered = true;
|
||||||
sound->data_end = true;
|
sound->eos = true;
|
||||||
sound->loopcount = 0;
|
sound->loopcount = 0;
|
||||||
sound->stop = NULL;
|
sound->stop = NULL;
|
||||||
sound->stop_data = NULL;
|
sound->stop_data = NULL;
|
||||||
@ -862,7 +863,7 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
|
|||||||
{
|
{
|
||||||
alhandle->reader->seek((int)(position *
|
alhandle->reader->seek((int)(position *
|
||||||
alhandle->reader->getSpecs().rate));
|
alhandle->reader->getSpecs().rate));
|
||||||
alhandle->data_end = false;
|
alhandle->eos = false;
|
||||||
|
|
||||||
ALint info;
|
ALint info;
|
||||||
|
|
||||||
@ -887,7 +888,7 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
|
|||||||
for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
|
for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
|
||||||
{
|
{
|
||||||
length = m_buffersize;
|
length = m_buffersize;
|
||||||
alhandle->reader->read(length, m_buffer.getBuffer());
|
alhandle->reader->read(length, alhandle->eos, m_buffer.getBuffer());
|
||||||
alBufferData(alhandle->buffers[i], alhandle->format,
|
alBufferData(alhandle->buffers[i], alhandle->format,
|
||||||
m_buffer.getBuffer(),
|
m_buffer.getBuffer(),
|
||||||
length * AUD_DEVICE_SAMPLE_SIZE(specs),
|
length * AUD_DEVICE_SAMPLE_SIZE(specs),
|
||||||
@ -897,6 +898,9 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(alhandle->loopcount != 0)
|
||||||
|
alhandle->eos = false;
|
||||||
|
|
||||||
alSourceQueueBuffers(alhandle->source,
|
alSourceQueueBuffers(alhandle->source,
|
||||||
AUD_OPENAL_CYCLE_BUFFERS,
|
AUD_OPENAL_CYCLE_BUFFERS,
|
||||||
alhandle->buffers);
|
alhandle->buffers);
|
||||||
@ -1045,7 +1049,10 @@ bool AUD_OpenALDevice::setLoopCount(AUD_Handle* handle, int count)
|
|||||||
lock();
|
lock();
|
||||||
bool result = isValid(handle);
|
bool result = isValid(handle);
|
||||||
if(result)
|
if(result)
|
||||||
|
{
|
||||||
((AUD_OpenALHandle*)handle)->loopcount = count;
|
((AUD_OpenALHandle*)handle)->loopcount = count;
|
||||||
|
((AUD_OpenALHandle*)handle)->eos = false;
|
||||||
|
}
|
||||||
unlock();
|
unlock();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ long AUD_SRCResampleReader::doCallback(float** data)
|
|||||||
int length = m_buffer.getSize() / AUD_SAMPLE_SIZE(m_tspecs);
|
int length = m_buffer.getSize() / AUD_SAMPLE_SIZE(m_tspecs);
|
||||||
|
|
||||||
*data = m_buffer.getBuffer();
|
*data = m_buffer.getBuffer();
|
||||||
m_reader->read(length, *data);
|
m_reader->read(length, m_eos, *data);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -104,13 +104,17 @@ AUD_Specs AUD_SRCResampleReader::getSpecs() const
|
|||||||
return m_tspecs;
|
return m_tspecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SRCResampleReader::read(int & length, sample_t* buffer)
|
void AUD_SRCResampleReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
int size = length * AUD_SAMPLE_SIZE(m_tspecs);
|
int size = length;
|
||||||
|
|
||||||
m_buffer.assureSize(size);
|
m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_tspecs));
|
||||||
|
|
||||||
|
m_eos = false;
|
||||||
|
|
||||||
length = src_callback_read(m_src, m_factor, length, buffer);
|
length = src_callback_read(m_src, m_factor, length, buffer);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
|
||||||
|
eos = m_eos && (length < size);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
int m_position;
|
int m_position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether reader reached end of stream.
|
||||||
|
*/
|
||||||
|
bool m_eos;
|
||||||
|
|
||||||
// hide copy constructor and operator=
|
// hide copy constructor and operator=
|
||||||
AUD_SRCResampleReader(const AUD_SRCResampleReader&);
|
AUD_SRCResampleReader(const AUD_SRCResampleReader&);
|
||||||
AUD_SRCResampleReader& operator=(const AUD_SRCResampleReader&);
|
AUD_SRCResampleReader& operator=(const AUD_SRCResampleReader&);
|
||||||
@ -104,7 +109,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SRCRESAMPLEREADER
|
#endif //AUD_SRCRESAMPLEREADER
|
||||||
|
@ -342,13 +342,14 @@ void AUD_FFMPEGReader::seek(int position)
|
|||||||
// read until we're at the right position
|
// read until we're at the right position
|
||||||
int length = AUD_DEFAULT_BUFFER_SIZE;
|
int length = AUD_DEFAULT_BUFFER_SIZE;
|
||||||
AUD_Buffer buffer(length * AUD_SAMPLE_SIZE(m_specs));
|
AUD_Buffer buffer(length * AUD_SAMPLE_SIZE(m_specs));
|
||||||
|
bool eos;
|
||||||
for(int len = position - m_position;
|
for(int len = position - m_position;
|
||||||
length == AUD_DEFAULT_BUFFER_SIZE;
|
length == AUD_DEFAULT_BUFFER_SIZE;
|
||||||
len -= AUD_DEFAULT_BUFFER_SIZE)
|
len -= AUD_DEFAULT_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
if(len < AUD_DEFAULT_BUFFER_SIZE)
|
if(len < AUD_DEFAULT_BUFFER_SIZE)
|
||||||
length = len;
|
length = len;
|
||||||
read(length, buffer.getBuffer());
|
read(length, eos, buffer.getBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,7 +382,7 @@ AUD_Specs AUD_FFMPEGReader::getSpecs() const
|
|||||||
return m_specs.specs;
|
return m_specs.specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
|
void AUD_FFMPEGReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
// read packages and decode them
|
// read packages and decode them
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
@ -431,7 +432,8 @@ void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
|
|||||||
pkgbuf_pos-data_size);
|
pkgbuf_pos-data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(left > 0)
|
if(eos = (left > 0))
|
||||||
length -= left;
|
length -= left;
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_FFMPEGREADER
|
#endif //AUD_FFMPEGREADER
|
||||||
|
@ -66,7 +66,7 @@ AUD_Specs AUD_BufferReader::getSpecs() const
|
|||||||
return m_specs;
|
return m_specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_BufferReader::read(int & length, sample_t* buffer)
|
void AUD_BufferReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
int sample_size = AUD_SAMPLE_SIZE(m_specs);
|
int sample_size = AUD_SAMPLE_SIZE(m_specs);
|
||||||
|
|
||||||
@ -74,7 +74,10 @@ void AUD_BufferReader::read(int & length, sample_t* buffer)
|
|||||||
|
|
||||||
// in case the end of the buffer is reached
|
// in case the end of the buffer is reached
|
||||||
if(m_buffer->getSize() < (m_position + length) * sample_size)
|
if(m_buffer->getSize() < (m_position + length) * sample_size)
|
||||||
|
{
|
||||||
length = m_buffer->getSize() / sample_size - m_position;
|
length = m_buffer->getSize() / sample_size - m_position;
|
||||||
|
eos = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(length < 0)
|
if(length < 0)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_BUFFERREADER
|
#endif //AUD_BUFFERREADER
|
||||||
|
@ -804,13 +804,14 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
|
|||||||
|
|
||||||
int len;
|
int len;
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
bool eos;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
len = samplerate;
|
len = samplerate;
|
||||||
buffer.resize((position + len) * sizeof(float), true);
|
buffer.resize((position + len) * sizeof(float), true);
|
||||||
reader->read(len, buffer.getBuffer() + position);
|
reader->read(len, eos, buffer.getBuffer() + position);
|
||||||
position += len;
|
position += len;
|
||||||
} while(len != 0);
|
} while(!eos);
|
||||||
|
|
||||||
float* result = (float*)malloc(position * sizeof(float));
|
float* result = (float*)malloc(position * sizeof(float));
|
||||||
memcpy(result, buffer.getBuffer(), position * sizeof(float));
|
memcpy(result, buffer.getBuffer(), position * sizeof(float));
|
||||||
@ -903,6 +904,7 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
|
|||||||
int len = reader->getLength();
|
int len = reader->getLength();
|
||||||
float samplejump = (float)len / (float)length;
|
float samplejump = (float)len / (float)length;
|
||||||
float min, max;
|
float min, max;
|
||||||
|
bool eos;
|
||||||
|
|
||||||
for(int i = 0; i < length; i++)
|
for(int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
@ -914,9 +916,9 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
|
|||||||
buf = aBuffer.getBuffer();
|
buf = aBuffer.getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
reader->read(len, buf);
|
reader->read(len, eos, buf);
|
||||||
|
|
||||||
if(len < 1)
|
if(eos)
|
||||||
{
|
{
|
||||||
length = i;
|
length = i;
|
||||||
break;
|
break;
|
||||||
|
@ -76,13 +76,13 @@ AUD_Specs AUD_ChannelMapperReader::getSpecs() const
|
|||||||
return m_specs;
|
return m_specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
|
void AUD_ChannelMapperReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
m_buffer.assureSize(length * m_rch * sizeof(sample_t));
|
m_buffer.assureSize(length * m_rch * sizeof(sample_t));
|
||||||
|
|
||||||
sample_t* in = m_buffer.getBuffer();
|
sample_t* in = m_buffer.getBuffer();
|
||||||
|
|
||||||
m_reader->read(length, in);
|
m_reader->read(length, eos, in);
|
||||||
|
|
||||||
sample_t sum;
|
sample_t sum;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
~AUD_ChannelMapperReader();
|
~AUD_ChannelMapperReader();
|
||||||
|
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_CHANNELMAPPERREADER
|
#endif //AUD_CHANNELMAPPERREADER
|
||||||
|
@ -75,13 +75,13 @@ AUD_Specs AUD_ConverterReader::getSpecs() const
|
|||||||
return m_specs.specs;
|
return m_specs.specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_ConverterReader::read(int & length, sample_t* buffer)
|
void AUD_ConverterReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
|
int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
|
||||||
|
|
||||||
m_buffer.assureSize(length * samplesize);
|
m_buffer.assureSize(length * samplesize);
|
||||||
|
|
||||||
m_reader->read(length, m_buffer.getBuffer());
|
m_reader->read(length, eos, m_buffer.getBuffer());
|
||||||
|
|
||||||
m_convert((data_t*)buffer, (data_t*)m_buffer.getBuffer(),
|
m_convert((data_t*)buffer, (data_t*)m_buffer.getBuffer(),
|
||||||
length * m_specs.channels);
|
length * m_specs.channels);
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
AUD_ConverterReader(AUD_Reference<AUD_IReader> reader, AUD_DeviceSpecs specs);
|
AUD_ConverterReader(AUD_Reference<AUD_IReader> reader, AUD_DeviceSpecs specs);
|
||||||
|
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_CONVERTERREADER
|
#endif //AUD_CONVERTERREADER
|
||||||
|
@ -92,15 +92,15 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to read the next length samples out of the source.
|
* Request to read the next length samples out of the source.
|
||||||
* The buffer for reading has to stay valid until the next call of this
|
* The buffer supplied has the needed size.
|
||||||
* method or until the reader is deleted.
|
|
||||||
* \param[in,out] length The count of samples that should be read. Shall
|
* \param[in,out] length The count of samples that should be read. Shall
|
||||||
* contain the real count of samples after reading, in case
|
* contain the real count of samples after reading, in case
|
||||||
* there were only fewer samples available.
|
* there were only fewer samples available.
|
||||||
* A smaller value also indicates the end of the reader.
|
* A smaller value also indicates the end of the reader.
|
||||||
* \param[out] buffer The pointer to the buffer with the samples.
|
* \param[out] eos End of stream, whether the end is reached or not.
|
||||||
|
* \param[int] buffer The pointer to the buffer to read into.
|
||||||
*/
|
*/
|
||||||
virtual void read(int & length, sample_t* buffer)=0;
|
virtual void read(int& length, bool& eos, sample_t* buffer)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_IREADER
|
#endif //AUD_IREADER
|
||||||
|
@ -71,18 +71,18 @@ AUD_Specs AUD_LinearResampleReader::getSpecs() const
|
|||||||
return m_tspecs;
|
return m_tspecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
|
void AUD_LinearResampleReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
|
int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
|
||||||
int size = length * AUD_SAMPLE_SIZE(m_sspecs);
|
int size = length;
|
||||||
|
|
||||||
m_buffer.assureSize(size);
|
m_buffer.assureSize(size * AUD_SAMPLE_SIZE(m_sspecs));
|
||||||
|
|
||||||
int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
|
int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
|
||||||
int len = need;
|
int len = need;
|
||||||
sample_t* buf = m_buffer.getBuffer();
|
sample_t* buf = m_buffer.getBuffer();
|
||||||
|
|
||||||
m_reader->read(len, buf);
|
m_reader->read(len, eos, buf);
|
||||||
|
|
||||||
if(len < need)
|
if(len < need)
|
||||||
length = floor((m_sposition + len - 1) * m_factor) - m_position;
|
length = floor((m_sposition + len - 1) * m_factor) - m_position;
|
||||||
@ -123,4 +123,5 @@ void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
|
|||||||
|
|
||||||
m_sposition += len;
|
m_sposition += len;
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
eos &= length < size;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_LINEARRESAMPLEREADER
|
#endif //AUD_LINEARRESAMPLEREADER
|
||||||
|
@ -113,7 +113,7 @@ AUD_Specs AUD_SequencerReader::getSpecs() const
|
|||||||
return m_mixer->getSpecs().specs;
|
return m_mixer->getSpecs().specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SequencerReader::read(int & length, sample_t* buffer)
|
void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
AUD_DeviceSpecs specs = m_mixer->getSpecs();
|
AUD_DeviceSpecs specs = m_mixer->getSpecs();
|
||||||
int rate = specs.rate;
|
int rate = specs.rate;
|
||||||
@ -171,7 +171,7 @@ void AUD_SequencerReader::read(int & length, sample_t* buffer)
|
|||||||
len -= skip;
|
len -= skip;
|
||||||
if(strip->reader->getPosition() != current)
|
if(strip->reader->getPosition() != current)
|
||||||
strip->reader->seek(current);
|
strip->reader->seek(current);
|
||||||
strip->reader->read(len, m_buffer.getBuffer());
|
strip->reader->read(len, eos, m_buffer.getBuffer());
|
||||||
m_mixer->mix(m_buffer.getBuffer(), skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
|
m_mixer->mix(m_buffer.getBuffer(), skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,4 +183,6 @@ void AUD_SequencerReader::read(int & length, sample_t* buffer)
|
|||||||
m_mixer->read((data_t*)buffer, 1.0f);
|
m_mixer->read((data_t*)buffer, 1.0f);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
|
||||||
|
eos = false;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SEQUENCERREADER
|
#endif //AUD_SEQUENCERREADER
|
||||||
|
@ -66,8 +66,9 @@ AUD_Specs AUD_SilenceReader::getSpecs() const
|
|||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SilenceReader::read(int & length, sample_t* buffer)
|
void AUD_SilenceReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
memset(buffer, 0, length * sizeof(sample_t));
|
memset(buffer, 0, length * sizeof(sample_t));
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
eos = false;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SILENCEREADER
|
#endif //AUD_SILENCEREADER
|
||||||
|
@ -72,7 +72,7 @@ AUD_Specs AUD_SinusReader::getSpecs() const
|
|||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SinusReader::read(int & length, sample_t* buffer)
|
void AUD_SinusReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
// fill with sine data
|
// fill with sine data
|
||||||
for(int i = 0; i < length; i++)
|
for(int i = 0; i < length; i++)
|
||||||
@ -82,4 +82,5 @@ void AUD_SinusReader::read(int & length, sample_t* buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
eos = false;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SINUSREADER
|
#endif //AUD_SINUSREADER
|
||||||
|
@ -112,6 +112,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
|||||||
AUD_SoftwareHandle* sound;
|
AUD_SoftwareHandle* sound;
|
||||||
int len;
|
int len;
|
||||||
int pos;
|
int pos;
|
||||||
|
bool eos;
|
||||||
std::list<AUD_SoftwareHandle*> stopSounds;
|
std::list<AUD_SoftwareHandle*> stopSounds;
|
||||||
sample_t* buf = m_buffer.getBuffer();
|
sample_t* buf = m_buffer.getBuffer();
|
||||||
|
|
||||||
@ -130,10 +131,10 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
len = length;
|
len = length;
|
||||||
|
|
||||||
sound->reader->read(len, buf);
|
sound->reader->read(len, eos, buf);
|
||||||
|
|
||||||
// in case of looping
|
// in case of looping
|
||||||
while(pos + len < length && sound->loopcount)
|
while(pos + len < length && sound->loopcount && eos)
|
||||||
{
|
{
|
||||||
m_mixer->mix(buf, pos, len, sound->volume);
|
m_mixer->mix(buf, pos, len, sound->volume);
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
|||||||
sound->reader->seek(0);
|
sound->reader->seek(0);
|
||||||
|
|
||||||
len = length - pos;
|
len = length - pos;
|
||||||
sound->reader->read(len, buf);
|
sound->reader->read(len, eos, buf);
|
||||||
|
|
||||||
// prevent endless loop
|
// prevent endless loop
|
||||||
if(!len)
|
if(!len)
|
||||||
@ -156,7 +157,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
|||||||
pos += len;
|
pos += len;
|
||||||
|
|
||||||
// in case the end of the sound is reached
|
// in case the end of the sound is reached
|
||||||
if(pos < length)
|
if(eos && !sound->loopcount)
|
||||||
{
|
{
|
||||||
if(sound->stop)
|
if(sound->stop)
|
||||||
sound->stop(sound->stop_data);
|
sound->stop(sound->stop_data);
|
||||||
|
@ -45,6 +45,7 @@ AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> fac
|
|||||||
int sample_size = AUD_SAMPLE_SIZE(m_specs);
|
int sample_size = AUD_SAMPLE_SIZE(m_specs);
|
||||||
int length;
|
int length;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
bool eos = false;
|
||||||
|
|
||||||
// get an approximated size if possible
|
// get an approximated size if possible
|
||||||
int size = reader->getLength();
|
int size = reader->getLength();
|
||||||
@ -54,16 +55,17 @@ AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> fac
|
|||||||
else
|
else
|
||||||
size += m_specs.rate;
|
size += m_specs.rate;
|
||||||
|
|
||||||
// as long as we fill our buffer to the end
|
// as long as the end of the stream is not reached
|
||||||
while(index == m_buffer->getSize() / sample_size)
|
while(!eos)
|
||||||
{
|
{
|
||||||
// increase
|
// increase
|
||||||
m_buffer->resize(size*sample_size, true);
|
m_buffer->resize(size*sample_size, true);
|
||||||
|
|
||||||
// read more
|
// read more
|
||||||
length = size-index;
|
length = size-index;
|
||||||
reader->read(length, m_buffer->getBuffer() + index * m_specs.channels);
|
reader->read(length, eos, m_buffer->getBuffer() + index * m_specs.channels);
|
||||||
size += AUD_BUFFER_RESIZE_BYTES / sample_size;
|
if(index == m_buffer->getSize() / sample_size)
|
||||||
|
size += AUD_BUFFER_RESIZE_BYTES / sample_size;
|
||||||
index += length;
|
index += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,9 +161,13 @@ AUD_Specs AUD_SndFileReader::getSpecs() const
|
|||||||
return m_specs;
|
return m_specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AUD_SndFileReader::read(int & length, sample_t* buffer)
|
void AUD_SndFileReader::read(int& length, bool& eos, sample_t* buffer)
|
||||||
{
|
{
|
||||||
|
int olen = length;
|
||||||
|
|
||||||
length = sf_readf_float(m_sndfile, buffer, length);
|
length = sf_readf_float(m_sndfile, buffer, length);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
|
|
||||||
|
eos = length < olen;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public:
|
|||||||
virtual int getLength() const;
|
virtual int getLength() const;
|
||||||
virtual int getPosition() const;
|
virtual int getPosition() const;
|
||||||
virtual AUD_Specs getSpecs() const;
|
virtual AUD_Specs getSpecs() const;
|
||||||
virtual void read(int & length, sample_t* buffer);
|
virtual void read(int& length, bool& eos, sample_t* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //AUD_SNDFILEREADER
|
#endif //AUD_SNDFILEREADER
|
||||||
|
Loading…
Reference in New Issue
Block a user