27 _desired_channels(channels),
30 _remove_after_read(remove_after_read)
48 nassert_raise(
"A UserDataAudio can only be opened by one consumer at a time.");
61 read_samples(
int n, int16_t *data) {
62 int ready = (_data.size() / _desired_channels);
63 int desired = n * _desired_channels;
64 int avail = ready * _desired_channels;
65 if (avail > desired) avail = desired;
66 for (
int i=0; i<avail; i++) {
69 for (
int i=avail; i<desired; i++) {
72 for (
int i=0; i<avail; i++) {
83 int words = n * _desired_channels;
84 for (
int i=0; i<words; i++) {
85 _data.push_back(data[i]);
97 if (n > maxlen) n = maxlen;
98 int words = n * _desired_channels;
99 for (
int i=0; i<words; i++) {
112 int samples = str.size() / (2 * _desired_channels);
113 int words = samples * _desired_channels;
114 for (
int i=0; i<words; i++) {
115 int c1 = ((
unsigned char)str[i*2+0]);
116 int c2 = ((
unsigned char)str[i*2+1]);
117 int16_t n = (c1 | (c2 << 8));
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void done()
Promises not to append any more samples, ie, this marks the end of the audio stream.
void append(int16_t *data, int n)
Appends audio samples to the buffer.
PT(MovieAudioCursor) UserDataAudio
Open this audio, returning a UserDataAudioCursor.
size_t get_remaining_size() const
Return the bytes left in the datagram.
A UserDataAudioCursor is a means to manually supply a sequence of raw audio samples.
A MovieAudio is actually any source that provides a sequence of audio samples.
int16_t get_int16()
Extracts a signed 16-bit integer.
UserDataAudio(int rate, int channels, bool remove_after_read=true)
This constructor returns a UserDataAudio — a means to supply raw audio samples manually.
A class to retrieve the individual data elements previously stored in a Datagram.
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.