Calculate the # of samples per video frame (for a specific frame number and frame rate)
| 454 | |
| 455 | // Calculate the # of samples per video frame (for a specific frame number and frame rate) |
| 456 | int Frame::GetSamplesPerFrame(int64_t number, Fraction fps, int sample_rate, int channels) |
| 457 | { |
| 458 | // Directly return 0 for invalid audio/frame-rate parameters |
| 459 | // so that we do not need to deal with NaNs later |
| 460 | if (channels <= 0 || sample_rate <= 0 || fps.num <= 0 || fps.den <= 0) return 0; |
| 461 | |
| 462 | // Get the total # of samples for the previous frame, and the current frame (rounded) |
| 463 | double fps_rate = fps.Reciprocal().ToDouble(); |
| 464 | |
| 465 | // Determine previous samples total, and make sure it's evenly divisible by the # of channels |
| 466 | double previous_samples = (sample_rate * fps_rate) * (number - 1); |
| 467 | double previous_samples_remainder = fmod(previous_samples, (double)channels); // subtract the remainder to the total (to make it evenly divisible) |
| 468 | previous_samples -= previous_samples_remainder; |
| 469 | |
| 470 | // Determine the current samples total, and make sure it's evenly divisible by the # of channels |
| 471 | double total_samples = (sample_rate * fps_rate) * number; |
| 472 | double total_samples_remainder = fmod(total_samples, (double)channels); // subtract the remainder to the total (to make it evenly divisible) |
| 473 | total_samples -= total_samples_remainder; |
| 474 | |
| 475 | // Subtract the previous frame's total samples with this frame's total samples. Not all sample rates can |
| 476 | // be evenly divided into frames, so each frame can have have different # of samples. |
| 477 | int samples_per_frame = round(total_samples - previous_samples); |
| 478 | if (samples_per_frame < 0) |
| 479 | samples_per_frame = 0; |
| 480 | return samples_per_frame; |
| 481 | } |
| 482 | |
| 483 | // Calculate the # of samples per video frame (for the current frame number) |
| 484 | int Frame::GetSamplesPerFrame(Fraction fps, int sample_rate, int channels) |
nothing calls this directly
no test coverage detected