@@ -435,6 +435,77 @@ void testcelt_float2int16(int use_ref_impl, int buffer_size)
435
435
#undef MAX_BUFFER_SIZE
436
436
}
437
437
438
+ void testopus_limit2_checkwithin1 (int use_ref_impl )
439
+ {
440
+ #define BUFFER_SIZE 37 /* strange float count to trigger residue loop of SIMD implementation */
441
+ #define BYTE_COUNT (BUFFER_SIZE * sizeof(float))
442
+ int i , within1 ;
443
+ const int arch = opus_select_arch ();
444
+
445
+ float pattern [BUFFER_SIZE ], buffer [BUFFER_SIZE ];
446
+
447
+ for (i = 0 ; i < BUFFER_SIZE ; ++ i )
448
+ {
449
+ pattern [i ] = i % 2 ? -1.f : 1.f ;
450
+ }
451
+
452
+ /* All values within -1..1:
453
+ Nothing changed. Return value is implementation-dependent (not expected to recognise nothing exceeds -1..1) */
454
+ memcpy (buffer , pattern , BYTE_COUNT );
455
+ within1 = use_ref_impl ? opus_limit2_checkwithin1_c (buffer , BUFFER_SIZE ) : opus_limit2_checkwithin1 (buffer , BUFFER_SIZE , arch );
456
+ if (memcmp (buffer , pattern , BYTE_COUNT ) != 0 )
457
+ {
458
+ fprintf (stderr , "opus_limit2_checkwithin1() modified values not exceeding -1..1 (ref=%d)\n" , use_ref_impl );
459
+ ret = 1 ;
460
+ }
461
+
462
+ /* One value exceeds -1..1, within -2..2:
463
+ Values unchanged. Return value says not all values are within -1..1 */
464
+ for (i = 0 ; i < BUFFER_SIZE ; ++ i )
465
+ {
466
+ const float replace_value = pattern [i ] * 1.001f ;
467
+
468
+ memcpy (buffer , pattern , BYTE_COUNT );
469
+ buffer [i ] = replace_value ;
470
+ within1 = use_ref_impl ? opus_limit2_checkwithin1_c (buffer , BUFFER_SIZE ) : opus_limit2_checkwithin1 (buffer , BUFFER_SIZE , arch );
471
+ if (within1 || buffer [i ] != replace_value )
472
+ {
473
+ fprintf (stderr , "opus_limit2_checkwithin1() handled value exceeding -1..1 erroneously (ref=%d, i=%d)\n" , use_ref_impl , i );
474
+ ret = 1 ;
475
+ }
476
+ buffer [i ] = pattern [i ];
477
+ if (memcmp (buffer , pattern , BYTE_COUNT ) != 0 )
478
+ {
479
+ fprintf (stderr , "opus_limit2_checkwithin1() modified value within -2..2 (ref=%d, i=%d)\n" , use_ref_impl , i );
480
+ ret = 1 ;
481
+ }
482
+ }
483
+
484
+ /* One value exceeds -2..2:
485
+ One value is hardclipped, others are unchanged. Return value says not all values are within -1..1 */
486
+ for (i = 0 ; i < BUFFER_SIZE ; ++ i )
487
+ {
488
+ const float replace_value = pattern [i ] * 2.1 ;
489
+
490
+ memcpy (buffer , pattern , BYTE_COUNT );
491
+ buffer [i ] = replace_value ;
492
+ within1 = use_ref_impl ? opus_limit2_checkwithin1_c (buffer , BUFFER_SIZE ) : opus_limit2_checkwithin1 (buffer , BUFFER_SIZE , arch );
493
+ if (within1 || buffer [i ] != (replace_value > 0.f ? 2.f : -2.f ))
494
+ {
495
+ fprintf (stderr , "opus_limit2_checkwithin1() handled value exceeding -2..2 erroneously (ref=%d, i=%d)\n" , use_ref_impl , i );
496
+ ret = 1 ;
497
+ }
498
+ buffer [i ] = pattern [i ];
499
+ if (memcmp (buffer , pattern , BYTE_COUNT ) != 0 )
500
+ {
501
+ fprintf (stderr , "opus_limit2_checkwithin1() modified value within -2..2 (ref=%d, i=%d)\n" , use_ref_impl , i );
502
+ ret = 1 ;
503
+ }
504
+ }
505
+ #undef BUFFER_SIZE
506
+ #undef BYTE_COUNT
507
+ }
508
+
438
509
#endif
439
510
440
511
int main (void )
@@ -461,6 +532,7 @@ int main(void)
461
532
testcelt_float2int16 (use_ref_impl [i ], 32 );
462
533
testcelt_float2int16 (use_ref_impl [i ], 127 );
463
534
testcelt_float2int16 (use_ref_impl [i ], 1031 );
535
+ testopus_limit2_checkwithin1 (use_ref_impl [i ]);
464
536
}
465
537
#endif
466
538
return ret ;
0 commit comments