21 AudioReaderSource::AudioReaderSource(
ReaderBase *audio_reader, int64_t starting_frame_number)
22 : reader(audio_reader), frame_position(starting_frame_number), videoCache(NULL), frame(NULL),
23 sample_position(0), speed(1), stream_position(0) {
34 if (info.numSamples > 0) {
35 int remaining_samples = info.numSamples;
36 int remaining_position = info.startSample;
39 if (speed != 1 || !videoCache->
isReady()) {
44 while (remaining_samples > 0) {
48 frame = reader->
GetFrame(frame_position);
55 if (reader && frame) {
56 if (sample_position + remaining_samples <= frame->GetAudioSamplesCount()) {
58 for (
int channel = 0; channel < frame->GetAudioChannelsCount(); channel++) {
59 if (channel < info.buffer->getNumChannels()) {
60 info.buffer->addFrom(channel, remaining_position, *frame->GetAudioSampleBuffer(),
61 channel, sample_position, remaining_samples);
64 sample_position += remaining_samples;
65 remaining_position += remaining_samples;
66 remaining_samples = 0;
68 }
else if (sample_position + remaining_samples > frame->GetAudioSamplesCount()) {
70 int amount_to_copy = frame->GetAudioSamplesCount() - sample_position;
71 for (
int channel = 0; channel < frame->GetAudioChannelsCount(); channel++) {
72 if (channel < info.buffer->getNumChannels()) {
73 info.buffer->addFrom(channel, remaining_position, *frame->GetAudioSampleBuffer(), channel,
74 sample_position, amount_to_copy);
77 sample_position += amount_to_copy;
78 remaining_position += amount_to_copy;
79 remaining_samples -= amount_to_copy;
83 if (sample_position == frame->GetAudioSamplesCount()) {
84 frame_position += speed;