15 #include "userDataAudio.h"
16 #include "userDataAudioCursor.h"
30 _desired_channels(channels),
33 _remove_after_read(remove_after_read)
56 nassert_raise(
"A UserDataAudio can only be opened by one consumer at a time.");
72 read_samples(
int n, PN_int16 *data) {
73 int ready = (_data.size() / _desired_channels);
74 int desired = n * _desired_channels;
75 int avail = ready * _desired_channels;
76 if (avail > desired) avail = desired;
77 for (
int i=0; i<avail; i++) {
80 for (
int i=avail; i<desired; i++) {
83 for (
int i=0; i<avail; i++) {
96 int words = n * _desired_channels;
97 for (
int i=0; i<words; i++) {
98 _data.push_back(data[i]);
113 if (n > maxlen) n = maxlen;
114 int words = n * _desired_channels;
115 for (
int i=0; i<words; i++) {
132 int samples = str.size() / (2 * _desired_channels);
133 int words = samples * _desired_channels;
134 for (
int i=0; i<words; i++) {
135 int c1 = ((
unsigned char)str[i*2+0]);
136 int c2 = ((
unsigned char)str[i*2+1]);
137 PN_int16 n = (c1 | (c2 << 8));
void done()
Promises not to append any more samples, ie, this marks the end of the audio stream.
void append(PN_int16 *data, int n)
Appends audio samples to the buffer.
PN_int16 get_int16()
Extracts a signed 16-bit integer.
A UserDataAudioCursor is a means to manually supply a sequence of raw audio samples.
int get_remaining_size() const
Return the bytes left in the datagram.
A MovieAudio is actually any source that provides a sequence of audio samples.
A UserDataAudio is a way for the user to manually supply raw audio samples.
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.