25 _audio_rate = src->_desired_rate;
26 _audio_channels = src->_desired_channels;
27 _can_seek = !src->_remove_after_read;
28 _can_seek_fast = !src->_remove_after_read;
30 if(!src->_remove_after_read) {
31 assert(src->_aborted &&
"UserData was not closed before by a done() call");
32 _length = static_cast<double>(src->_data.size() / _audio_channels) / _audio_rate;
40 ~UserDataAudioCursor() {
42 source->_cursor =
nullptr;
54 if(source->_remove_after_read) {
55 source->read_samples(n, data);
58 int offset = _samples_read * _audio_channels;
59 int avail = source->_data.size() - offset;
60 int desired = n * _audio_channels;
61 if (avail > desired) avail = desired;
63 for (
int i=0; i<avail; i++) {
64 data[i] = source->_data[i+offset];
66 for (
int i=avail; i<desired; i++) {
79 if(_can_seek && 0 <= t && _length <= t) {
80 _samples_read = static_cast<int>(t * _audio_rate * _audio_channels + 0.5f);
96 if(source->_remove_after_read)
return source->_data.size() / _audio_channels;
97 else return source->_data.size() / _audio_channels - _samples_read;
virtual void seek(double offset)
Set the offset if possible.
A UserDataAudioCursor is a means to manually supply a sequence of raw audio samples.
virtual void read_samples(int n, int16_t *data)
Read audio samples from the stream.
A MovieAudio is actually any source that provides a sequence of audio samples.
virtual int ready() const
Returns the number of audio samples ready to be read.
A UserDataAudio is a way for the user to manually supply raw audio samples.
TypeHandle is the identifier used to differentiate C++ class types.
A MovieAudio is actually any source that provides a sequence of audio samples.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.