Update scale_clip_test.(def|tpl) to test for new code.

This commit is contained in:
Erik de Castro Lopo 2006-10-03 11:48:10 +00:00
parent ac70c1b941
commit 843056fc3f
3 changed files with 142 additions and 22 deletions

View File

@ -1,3 +1,11 @@
2006-10-03 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/double64.c src/float32.c
Add optional clipping on float file data to int read data conversions.
* tests/tests/scale_clip_test.(def|tpl)
Add test for above new code.
2006-09-06 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* tests/aiff_rw_test.c

View File

@ -1,15 +1,29 @@
autogen definitions scale_clip_test.tpl;
float_type = {
type_name = "float" ;
short_name = "flt" ;
upper_name = "FLOAT" ;
float_type_name = "float" ;
float_short_name = "flt" ;
float_upper_name = "FLOAT" ;
} ;
float_type = {
type_name = "double" ;
short_name = "dbl" ;
upper_name = "DOUBLE" ;
float_type_name = "double" ;
float_short_name = "dbl" ;
float_upper_name = "DOUBLE" ;
} ;
int_type = {
int_type_name = "short" ;
int_short_name = "s" ;
int_max_value = 0x7FFFF ;
} ;
int_type = {
int_type_name = "int" ;
int_short_name = "i" ;
int_max_value = 0x7FFFFFFF ;
} ;

View File

@ -1,6 +1,6 @@
[+ AutoGen5 template c +]
/*
** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 1999-2006 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -45,13 +45,21 @@
[+ FOR float_type +]
[+ FOR data_type
+]static void [+ (get "short_name") +]_scale_clip_test_[+ (get "name") +] (const char *filename, int filetype, float maxval) ;
+]static void [+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +] (const char *filename, int filetype, float maxval) ;
[+ ENDFOR data_type
+][+ ENDFOR float_type +]
[+ FOR float_type +]
[+ FOR int_type
+]static void [+ (get "float_type_name") +]_[+ (get "int_type_name") +]_clip_test (const char *filename, int filetype) ;
[+ ENDFOR int_type
+][+ ENDFOR float_type +]
typedef union
{ double dbl [BUFFER_SIZE] ;
float flt [BUFFER_SIZE] ;
int i [BUFFER_SIZE] ;
short s [BUFFER_SIZE] ;
} BUFFER ;
/* Data buffer. */
@ -86,6 +94,11 @@ main (void)
dbl_scale_clip_test_32 ("scale_clip_be32.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
dbl_scale_clip_test_32 ("scale_clip_le32.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
float_int_clip_test ("flt_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
float_short_clip_test ("flt_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
double_int_clip_test ("dbl_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
double_short_clip_test ("dbl_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
return 0 ;
} /* main */
@ -96,20 +109,20 @@ main (void)
[+ FOR float_type +]
[+ FOR data_type
+]static void
[+ (get "short_name") +]_scale_clip_test_[+ (get "name") +] (const char *filename, int filetype, float maxval)
[+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +] (const char *filename, int filetype, float maxval)
{ SNDFILE *file ;
SF_INFO sfinfo ;
int k ;
[+ (get "type_name") +] *data_out, *data_in ;
[+ (get "float_type_name") +] *data_out, *data_in ;
double diff, clip_max_diff ;
print_test_name ("[+ (get "short_name") +]_scale_clip_test_[+ (get "name") +]", filename) ;
print_test_name ("[+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +]", filename) ;
data_out = buffer_out.[+ (get "short_name") +] ;
data_in = buffer_in.[+ (get "short_name") +] ;
data_out = buffer_out.[+ (get "float_short_name") +] ;
data_in = buffer_in.[+ (get "float_short_name") +] ;
for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
{ data_out [k] = SINE_AMP * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
{ data_out [k] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
} ;
@ -126,9 +139,9 @@ main (void)
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
test_write_[+ (get "type_name") +]_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
sf_command (file, SFC_SET_NORM_[+ (get "upper_name") +], NULL, SF_FALSE) ;
test_write_[+ (get "type_name") +]_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
test_write_[+ (get "float_type_name") +]_or_die (file, 0, data_out, HALF_BUFFER_SIZE, __LINE__) ;
sf_command (file, SFC_SET_NORM_[+ (get "float_upper_name") +], NULL, SF_FALSE) ;
test_write_[+ (get "float_type_name") +]_or_die (file, 0, data_out + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
sf_close (file) ;
memset (&buffer_in, 0, sizeof (buffer_in)) ;
@ -154,9 +167,9 @@ main (void)
check_log_buffer_or_die (file, __LINE__) ;
test_read_[+ (get "type_name") +]_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
sf_command (file, SFC_SET_NORM_[+ (get "upper_name") +], NULL, SF_FALSE) ;
test_read_[+ (get "type_name") +]_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
test_read_[+ (get "float_type_name") +]_or_die (file, 0, data_in, HALF_BUFFER_SIZE, __LINE__) ;
sf_command (file, SFC_SET_NORM_[+ (get "float_upper_name") +], NULL, SF_FALSE) ;
test_read_[+ (get "float_type_name") +]_or_die (file, 0, data_in + HALF_BUFFER_SIZE, HALF_BUFFER_SIZE, __LINE__) ;
sf_close (file) ;
/* Check normalized version. */
@ -223,16 +236,101 @@ main (void)
printf ("ok\n") ;
unlink (filename) ;
} /* [+ (get "short_name") +]_scale_clip_test_[+ (get "name") +] */
} /* [+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +] */
[+ ENDFOR data_type
+]
[+ ENDFOR float_type +]
/*==============================================================================
*/
[+ FOR float_type +]
[+ FOR int_type
+]static void [+ (get "float_type_name") +]_[+ (get "int_type_name") +]_clip_test (const char *filename, int filetype)
{ SNDFILE *file ;
SF_INFO sfinfo ;
[+ (get "float_type_name") +] *data_out ;
[+ (get "int_type_name") +] *data_in, max_value ;
int k ;
print_test_name ("[+ (get "float_type_name") +]_[+ (get "int_type_name") +]_clip_test", filename) ;
data_out = buffer_out.[+ (get "float_short_name") +] ;
data_in = buffer_in.[+ (get "int_short_name") +] ;
for (k = 0 ; k < BUFFER_SIZE ; k++)
data_out [k] = 0.995 * sin (4 * M_PI * k / BUFFER_SIZE) ;
data_out [BUFFER_SIZE / 8] = 1.0 ;
data_out [3 * BUFFER_SIZE / 8] = -1.000000001 ;
data_out [5 * BUFFER_SIZE / 8] = 1.0 ;
data_out [7 * BUFFER_SIZE / 8] = -1.000000001 ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sfinfo.samplerate = 44100 ;
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
sfinfo.channels = 1 ;
sfinfo.format = filetype ;
/* Save unclipped data to the file. */
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
test_write_[+ (get "float_type_name") +]_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
sf_close (file) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
sfinfo.format &= (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK) ;
if (sfinfo.format != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n\n", __LINE__, filetype, sfinfo.format) ;
exit (1) ;
} ;
if (sfinfo.frames != BUFFER_SIZE)
{ printf ("\n\nLine %d: Incorrect number of frames in file (%d => %ld).\n\n", __LINE__, BUFFER_SIZE, SF_COUNT_TO_LONG (sfinfo.frames)) ;
exit (1) ;
} ;
if (sfinfo.channels != 1)
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n\n", __LINE__) ;
exit (1) ;
} ;
check_log_buffer_or_die (file, __LINE__) ;
sf_command (file, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
test_read_[+ (get "int_type_name") +]_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
/*-sf_command (file, SFC_SET_NORM_[+ (get "float_upper_name") +], NULL, SF_FALSE) ;-*/
sf_close (file) ;
/* Check the first half. */
max_value = 0 ;
for (k = 0 ; k < sfinfo.frames ; k++)
{ /* Check if data_out has different sign from data_in. */
if ((data_out [k] < 0.0 && data_in [k] > 0) || (data_out [k] > 0.0 && data_in [k] < 0))
{ printf ("\n\nLine %d: Data wrap around at index %d/%d (%f -> %d).\n\n", __LINE__, k, BUFFER_SIZE, data_out [k], data_in [k]) ;
exit (1) ;
} ;
max_value = (max_value > abs (data_in [k])) ? max_value : abs (data_in [k]) ;
} ;
puts ("ok") ;
} /* [+ (get "float_type_name") +]_[+ (get "int_type_name") +]_clip_test */
[+ ENDFOR int_type
+][+ ENDFOR float_type +]
[+ COMMENT
Do not edit or modify anything in this comment block.
The following line is a file identity tag for the GNU Arch
The following line is a file identity tag for the GNU Arch
revision control system.
arch-tag: dc1613fe-2985-462c-a0b4-62143a7570e8