Skip to content

Commit d6057e2

Browse files
committed
Some fixes to new unit test
1 parent 709d550 commit d6057e2

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

tests/cppunittest/FrameMapper_Tests.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -493,34 +493,37 @@ TEST(distribute_samples) {
493493
int num_seconds = 1;
494494

495495
// Source frame rates (varies the # of samples per frame)
496-
vector<openshot::Fraction> rates = { openshot::Fraction(30,1),
497-
openshot::Fraction(24,1) ,
498-
openshot::Fraction(119,4),
499-
openshot::Fraction(30000,1001) };
496+
std::vector<openshot::Fraction> rates = {
497+
openshot::Fraction(30,1),
498+
openshot::Fraction(24,1) ,
499+
openshot::Fraction(119,4),
500+
openshot::Fraction(30000,1001)
501+
};
502+
500503
for (auto& frame_rate : rates) {
501504
// Init sin wave variables
502505
int OFFSET = 0;
503506
float AMPLITUDE = 0.75;
504-
double ANGLE = 0.0;
505507
int NUM_SAMPLES = 100;
508+
double angle = 0.0;
506509

507510
// Create cache object to hold test frames
508-
CacheMemory cache;
511+
openshot::CacheMemory cache;
509512

510513
// Let's create some test frames
511-
for (int64_t frame_number = 1; frame_number <= (frame_rate.ToFloat() * num_seconds * 2); frame_number++) {
514+
for (int64_t frame_number = 1; frame_number <= (frame_rate.ToFloat() * num_seconds * 2); ++frame_number) {
512515
// Create blank frame (with specific frame #, samples, and channels)
513516
int sample_count = openshot::Frame::GetSamplesPerFrame(frame_number, frame_rate, sample_rate, channels);
514-
std::shared_ptr<openshot::Frame> f(new openshot::Frame(frame_number, sample_count, channels));
517+
auto f = std::make_shared<openshot::Frame>(frame_number, sample_count, channels);
515518
f->SampleRate(sample_rate);
516519

517520
// Create test samples with sin wave (predictable values)
518521
float *audio_buffer = new float[sample_count * 2];
519522
for (int sample_number = 0; sample_number < sample_count; sample_number++) {
520523
// Calculate sin wave
521-
float sample_value = float(AMPLITUDE * sin(ANGLE) + OFFSET);
524+
float sample_value = float(AMPLITUDE * sin(angle) + OFFSET);
522525
audio_buffer[sample_number] = abs(sample_value);
523-
ANGLE += (2 * M_PI) / NUM_SAMPLES;
526+
angle += (2 * M_PI) / NUM_SAMPLES;
524527
}
525528

526529
// Add custom audio samples to Frame (bool replaceSamples, int destChannel, int destStartSample, const float* source,
@@ -529,20 +532,23 @@ TEST(distribute_samples) {
529532

530533
// Add test frame to dummy reader
531534
cache.Add(f);
535+
536+
delete[] audio_buffer;
532537
}
533538

534-
// Create a default fraction (should be 1/1)
535539
openshot::DummyReader r(frame_rate, 1920, 1080, sample_rate, channels, 30.0, &cache);
536-
r.Open(); // Open the reader
540+
r.Open();
537541

538542
// Target frame rates
539-
vector<openshot::Fraction> mapped_rates = { openshot::Fraction(30,1),
540-
openshot::Fraction(24,1) ,
541-
openshot::Fraction(119,4),
542-
openshot::Fraction(30000,1001) };
543+
vector<openshot::Fraction> mapped_rates = {
544+
openshot::Fraction(30,1),
545+
openshot::Fraction(24,1),
546+
openshot::Fraction(119,4),
547+
openshot::Fraction(30000,1001)
548+
};
543549
for (auto &mapped_rate : mapped_rates) {
544550
// Reset SIN wave
545-
ANGLE = 0.0;
551+
angle = 0.0;
546552

547553
// Map to different fps
548554
FrameMapper map(&r, mapped_rate, PULLDOWN_NONE, sample_rate, channels, LAYOUT_STEREO);
@@ -556,8 +562,8 @@ TEST(distribute_samples) {
556562
for (int sample_index = 0; sample_index < sample_count; sample_index++) {
557563

558564
// Calculate sin wave
559-
float predicted_value = abs(float(AMPLITUDE * sin(ANGLE) + OFFSET));
560-
ANGLE += (2 * M_PI) / NUM_SAMPLES;
565+
float predicted_value = abs(float(AMPLITUDE * sin(angle) + OFFSET));
566+
angle += (2 * M_PI) / NUM_SAMPLES;
561567

562568
// Verify each mapped sample value is correct (after being redistributed by the FrameMapper)
563569
float mapped_value = map.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0);
@@ -586,18 +592,16 @@ TEST(distribute_samples) {
586592
t1.Open();
587593

588594
// Reset SIN wave
589-
ANGLE = 0.0;
595+
angle = 0.0;
590596

591597
for (int frame_index = starting_clip_frame; frame_index < (starting_clip_frame + (t1.info.fps.ToFloat() * num_seconds)); frame_index++) {
592598
for (int sample_index = 0; sample_index < t1.GetFrame(frame_index)->GetAudioSamplesCount(); sample_index++) {
593599
// Calculate sin wave
594-
float predicted_value = abs(float(AMPLITUDE * sin(ANGLE) + OFFSET));
595-
ANGLE += (2 * M_PI) / NUM_SAMPLES;
600+
float predicted_value = abs(float(AMPLITUDE * sin(angle) + OFFSET));
601+
angle += (2 * M_PI) / NUM_SAMPLES;
596602

597603
// Verify each mapped sample value is correct (after being redistributed by the FrameMapper)
598604
float timeline_value = t1.GetFrame(frame_index)->GetAudioSample(0, sample_index, 1.0);
599-
600-
// Testing wave value X 2, since we have 2 overlapping clips
601605
CHECK_CLOSE(predicted_value, timeline_value, 0.001);
602606
}
603607
}

0 commit comments

Comments
 (0)