mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
movies: Python-facing read_samples should return bytes object
Also, properly returns partial buffers based on number of actual samples read
This commit is contained in:
parent
c513342247
commit
c329a41dd3
@ -93,23 +93,28 @@ read_samples(int n, Datagram *dg) {
|
|||||||
* This is not particularly efficient, but it may be a convenient way to
|
* This is not particularly efficient, but it may be a convenient way to
|
||||||
* manipulate samples in python.
|
* manipulate samples in python.
|
||||||
*/
|
*/
|
||||||
std::string MovieAudioCursor::
|
vector_uchar MovieAudioCursor::
|
||||||
read_samples(int n) {
|
read_samples(int n) {
|
||||||
std::ostringstream result;
|
vector_uchar result;
|
||||||
int16_t tmp[4096];
|
int16_t tmp[4096];
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
int blocksize = (4096 / _audio_channels);
|
int blocksize = (4096 / _audio_channels);
|
||||||
if (blocksize > n) blocksize = n;
|
if (blocksize > n) {
|
||||||
int words = blocksize * _audio_channels;
|
blocksize = n;
|
||||||
read_samples(blocksize, tmp);
|
|
||||||
for (int i=0; i<words; i++) {
|
|
||||||
int16_t word = tmp[i];
|
|
||||||
result.put((char)(word & 255));
|
|
||||||
result.put((char)((word>>8) & 255));
|
|
||||||
}
|
}
|
||||||
n -= blocksize;
|
int nread = read_samples(blocksize, tmp);
|
||||||
|
if (nread == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
int words = nread * _audio_channels;
|
||||||
|
for (int i = 0; i < words; ++i) {
|
||||||
|
int16_t word = tmp[i];
|
||||||
|
result.push_back((uint8_t)(word & 255u));
|
||||||
|
result.push_back((uint8_t)((word >> 8) & 255u));
|
||||||
|
}
|
||||||
|
n -= nread;
|
||||||
}
|
}
|
||||||
return result.str();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ PUBLISHED:
|
|||||||
virtual int ready() const;
|
virtual int ready() const;
|
||||||
virtual void seek(double offset);
|
virtual void seek(double offset);
|
||||||
void read_samples(int n, Datagram *dg);
|
void read_samples(int n, Datagram *dg);
|
||||||
std::string read_samples(int n);
|
vector_uchar read_samples(int n);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int read_samples(int n, int16_t *data);
|
virtual int read_samples(int n, int16_t *data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user