|
|
@@ -93,23 +93,28 @@ read_samples(int n, Datagram *dg) {
|
|
|
* This is not particularly efficient, but it may be a convenient way to
|
|
|
* manipulate samples in python.
|
|
|
*/
|
|
|
-std::string MovieAudioCursor::
|
|
|
+vector_uchar MovieAudioCursor::
|
|
|
read_samples(int n) {
|
|
|
- std::ostringstream result;
|
|
|
+ vector_uchar result;
|
|
|
int16_t tmp[4096];
|
|
|
while (n > 0) {
|
|
|
int blocksize = (4096 / _audio_channels);
|
|
|
- if (blocksize > n) blocksize = n;
|
|
|
- int words = blocksize * _audio_channels;
|
|
|
- read_samples(blocksize, tmp);
|
|
|
- for (int i=0; i<words; i++) {
|
|
|
+ if (blocksize > n) {
|
|
|
+ blocksize = n;
|
|
|
+ }
|
|
|
+ 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.put((char)(word & 255));
|
|
|
- result.put((char)((word>>8) & 255));
|
|
|
+ result.push_back((uint8_t)(word & 255u));
|
|
|
+ result.push_back((uint8_t)((word >> 8) & 255u));
|
|
|
}
|
|
|
- n -= blocksize;
|
|
|
+ n -= nread;
|
|
|
}
|
|
|
- return result.str();
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
|