19 #include <opus/opusfile.h> 27 int cb_read(
void *stream,
unsigned char *ptr,
int nbytes) {
28 istream *in = (istream *)stream;
29 nassertr(in !=
nullptr, -1);
31 in->read((
char *)ptr, nbytes);
41 int cb_seek(
void *stream, opus_int64 offset,
int whence) {
42 if (!opus_enable_seek) {
46 istream *in = (istream *)stream;
47 nassertr(in !=
nullptr, -1);
51 in->seekg(offset, std::ios::beg);
55 in->seekg(offset, std::ios::cur);
59 in->seekg(offset, std::ios::end);
64 <<
"Illegal parameter to seek in cb_seek\n";
70 <<
"Failure to seek to byte " << offset;
74 movies_cat.error(
false)
75 <<
" from current location!\n";
79 movies_cat.error(
false)
80 <<
" from end of file!\n";
84 movies_cat.error(
false) <<
"!\n";
93 opus_int64 cb_tell(
void *stream) {
94 istream *in = (istream *)stream;
95 nassertr(in !=
nullptr, -1);
100 int cb_close(
void *stream) {
101 istream *in = (istream *)stream;
102 nassertr(in !=
nullptr, EOF);
109 static const OpusFileCallbacks callbacks = {cb_read, cb_seek, cb_tell, cb_close};
118 OpusAudioCursor(OpusAudio *src, istream *stream) :
123 nassertv(stream !=
nullptr);
124 nassertv(stream->good());
127 _op = op_open_callbacks((
void *)stream, &callbacks,
nullptr, 0, &error);
128 if (_op ==
nullptr) {
130 <<
"Failed to read Opus file (error code " << error <<
").\n";
134 ogg_int64_t samples = op_pcm_total(_op, -1);
135 if (samples != OP_EINVAL) {
137 _length = (double)samples / 48000.0;
140 _audio_channels = op_channel_count(_op, -1);
143 _can_seek = opus_enable_seek && op_seekable(_op);
144 _can_seek_fast = _can_seek;
154 if (_op !=
nullptr) {
164 void OpusAudioCursor::
166 if (!opus_enable_seek) {
170 t = std::max(t, 0.0);
173 int error = op_pcm_seek(_op, (ogg_int64_t)(t * 48000.0));
176 <<
"Seek failed (error " << error <<
"). Opus stream may not be seekable.\n";
180 _last_seek = op_pcm_tell(_op) / 48000.0;
189 void OpusAudioCursor::
190 read_samples(
int n, int16_t *data) {
191 int16_t *end = data + (n * _audio_channels);
196 int read_samples = op_read(_op, data, end - data, &link);
197 if (read_samples > 0) {
198 data += read_samples * _audio_channels;
199 _samples_read += read_samples;
207 int channels = op_channel_count(_op, link);
208 if (channels != _audio_channels) {
210 <<
"Opus file has inconsistent channel count!\n";
213 _audio_channels = channels;
222 memset(data, 0, (
unsigned char *)end - (
unsigned char *)data);
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
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().
A MovieAudio is actually any source that provides a sequence of audio samples.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.