19 #define DR_FLAC_IMPLEMENTATION 27 static size_t cb_read_proc(
void *user,
void *buffer,
size_t size) {
28 std::istream *stream = (std::istream *)user;
29 nassertr(stream !=
nullptr,
false);
31 stream->read((
char *)buffer, size);
38 return stream->gcount();
44 static bool cb_seek_proc(
void *user,
int offset) {
45 std::istream *stream = (std::istream *)user;
46 nassertr(stream !=
nullptr,
false);
48 stream->seekg(offset, std::ios::cur);
49 return !stream->fail();
65 nassertv(stream !=
nullptr);
66 nassertv(stream->good());
68 _drflac = drflac_open(&cb_read_proc, &cb_seek_proc, (
void *)stream);
70 if (_drflac ==
nullptr) {
72 <<
"Failed to open FLAC file.\n";
76 _length = (_drflac->totalSampleCount / _drflac->channels) / (
double)_drflac->sampleRate;
78 _audio_channels = _drflac->channels;
79 _audio_rate = _drflac->sampleRate;
82 _can_seek_fast = _can_seek;
92 if (_drflac !=
nullptr) {
93 drflac_close(_drflac);
95 if (_stream !=
nullptr) {
106 t = std::max(t, 0.0);
108 uint64_t sample = t * _drflac->sampleRate;
110 if (drflac_seek_to_sample(_drflac, sample * _drflac->channels)) {
111 _last_seek = sample / (double)_drflac->sampleRate;
123 int desired = n * _audio_channels;
124 _samples_read += drflac_read_s16(_drflac, desired, data) / _audio_channels;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
virtual void read_samples(int n, int16_t *data)
Read audio samples from the stream.
virtual ~FlacAudioCursor()
xxx
A MovieAudio is actually any source that provides a sequence of audio samples.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void seek(double offset)
Seeks to a target location.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
FlacAudioCursor(FlacAudio *src, std::istream *stream)
Reads the .wav header from the indicated stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.