22 AudioReaderSource::AudioReaderSource(
ReaderBase *audio_reader, int64_t starting_frame_number)
23 : reader(audio_reader), frame_position(starting_frame_number), videoCache(NULL), frame(NULL),
24 sample_position(0), speed(1), stream_position(0) {
35 if (info.numSamples > 0) {
36 int remaining_samples = info.numSamples;
37 int remaining_position = info.startSample;
40 if (speed != 1 || !videoCache->
isReady()) {
45 while (remaining_samples > 0) {
50 frame = reader->
GetFrame(frame_position);
57 if (reader && frame) {
58 if (sample_position + remaining_samples <= frame->GetAudioSamplesCount()) {
60 for (
int channel = 0; channel < frame->GetAudioChannelsCount(); channel++) {
61 if (channel < info.buffer->getNumChannels()) {
62 info.buffer->addFrom(channel, remaining_position, *frame->GetAudioSampleBuffer(),
63 channel, sample_position, remaining_samples);
66 sample_position += remaining_samples;
67 remaining_position += remaining_samples;
68 remaining_samples = 0;
70 }
else if (sample_position + remaining_samples > frame->GetAudioSamplesCount()) {
72 int amount_to_copy = frame->GetAudioSamplesCount() - sample_position;
73 for (
int channel = 0; channel < frame->GetAudioChannelsCount(); channel++) {
74 if (channel < info.buffer->getNumChannels()) {
75 info.buffer->addFrom(channel, remaining_position, *frame->GetAudioSampleBuffer(), channel,
76 sample_position, amount_to_copy);
79 sample_position += amount_to_copy;
80 remaining_position += amount_to_copy;
81 remaining_samples -= amount_to_copy;
85 if (sample_position == frame->GetAudioSamplesCount()) {
86 frame_position += speed;