mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
Initial commit
added libraries: opus flac libsndfile updated: libvorbis libogg openal - Everything works as expected for now. Bare in mind libsndfile needed the check for whether or not it could find the xiph libraries removed in order for this to work.
This commit is contained in:
parent
05a083ca6f
commit
a745fc3757
1954 changed files with 431332 additions and 21037 deletions
169
Engine/lib/libsndfile/tests/aiff_rw_test.c
Normal file
169
Engine/lib/libsndfile/tests/aiff_rw_test.c
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
static unsigned char aifc_data [] =
|
||||
{ 'F' , 'O' , 'R' , 'M' ,
|
||||
0x00, 0x00, 0x01, 0xE8, /* FORM length */
|
||||
|
||||
'A' , 'I' , 'F' , 'C' ,
|
||||
0x43, 0x4F, 0x4D, 0x4D, /* COMM */
|
||||
0x00, 0x00, 0x00, 0x26, /* COMM length */
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0xAE, 0x00, 0x10, 0x40, 0x0D, 0xAC, 0x44,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x4F, 0x4E, 0x45, 0x0D, 'N' ,
|
||||
'o' , 't' , ' ' , 'c' , 'o' , 'm' , 'p' , 'r' , 'e' , 's' , 's' , 'e' ,
|
||||
'd' , 0x00,
|
||||
|
||||
'F' , 'V' , 'E' , 'R' , 0x00, 0x00, 0x00, 0x04, 0xA2, 0x80, 0x51, 0x40,
|
||||
|
||||
/* A 'MARK' chunk. */
|
||||
'M' , 'A' , 'R' , 'K' , 0x00, 0x00, 0x00, 0x36, 0x00, 0x05,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 'A' ,
|
||||
0x00, 0x02, 0x00, 0x00, 0x11, 0x3A, 0x02, 'B' , 'C' , 0x00,
|
||||
0x00, 0x03, 0x00, 0x00, 0x22, 0x74, 0x03, 'D' , 'E' , 'F',
|
||||
0x00, 0x04, 0x00, 0x00, 0x33, 0xAE, 0x04, 'G' , 'H' , 'I', 'J' , 0x00,
|
||||
0x00, 0x05, 0x00, 0x00, 0x44, 0xE8, 0x05, 'K' , 'L' , 'M', 'N' , 'O' ,
|
||||
|
||||
'S' , 'S' , 'N' , 'D' ,
|
||||
0x00, 0x00, 0x01, 0x64, /* SSND length */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFF, 0xE0, 0xFF, 0xDB, 0xFF, 0xD0, 0xFF, 0xD5, 0xFF, 0xD6, 0xFF, 0xD0,
|
||||
0xFF, 0xBF, 0xFF, 0xBE, 0xFF, 0xB9, 0xFF, 0xC8, 0xFF, 0xBF, 0xFF, 0xD5,
|
||||
0xFF, 0xC3, 0xFF, 0xBF, 0xFF, 0xB3, 0xFF, 0xBE, 0xFF, 0xB4, 0xFF, 0xAD,
|
||||
0xFF, 0xAC, 0xFF, 0xAF, 0xFF, 0xB9, 0xFF, 0xB3, 0xFF, 0xA4, 0xFF, 0xA5,
|
||||
0xFF, 0x93, 0xFF, 0x95, 0xFF, 0x97, 0xFF, 0x98, 0xFF, 0x99, 0xFF, 0x9E,
|
||||
0xFF, 0x90, 0xFF, 0x80, 0xFF, 0x81, 0xFF, 0x7C, 0xFF, 0x80, 0xFF, 0x7C,
|
||||
0xFF, 0x72, 0xFF, 0x72, 0xFF, 0x6C, 0xFF, 0x75, 0xFF, 0x6E, 0xFF, 0x6F,
|
||||
0xFF, 0x66, 0xFF, 0x62, 0xFF, 0x5C, 0xFF, 0x64, 0xFF, 0x50, 0xFF, 0x56,
|
||||
0xFF, 0x56, 0xFF, 0x4A, 0xFF, 0x4A, 0xFF, 0x49, 0xFF, 0x44, 0xFF, 0x49,
|
||||
0xFF, 0x3B, 0xFF, 0x3F, 0xFF, 0x48, 0xFF, 0x46, 0xFF, 0x42, 0xFF, 0x49,
|
||||
0xFF, 0x43, 0xFF, 0x36, 0xFF, 0x40, 0xFF, 0x35, 0xFF, 0x3F, 0xFF, 0x36,
|
||||
0xFF, 0x37, 0xFF, 0x2E, 0xFF, 0x23, 0xFF, 0x23, 0xFF, 0x21, 0xFF, 0x1F,
|
||||
0xFF, 0x25, 0xFF, 0x2C, 0xFF, 0x1E, 0xFF, 0x22, 0xFF, 0x24, 0xFF, 0x2B,
|
||||
0xFF, 0x35, 0xFF, 0x27, 0xFF, 0x2E, 0xFF, 0x21, 0xFF, 0x18, 0xFF, 0x21,
|
||||
0xFF, 0x20, 0xFF, 0x0F, 0xFF, 0x21, 0xFF, 0x1A, 0xFF, 0x10, 0xFF, 0x09,
|
||||
0xFF, 0x1E, 0xFF, 0x19, 0xFF, 0x21, 0xFF, 0x13, 0xFF, 0x1B, 0xFF, 0x18,
|
||||
0xFF, 0x21, 0xFF, 0x0F, 0xFF, 0x1A, 0xFF, 0x16, 0xFF, 0x21, 0xFF, 0x1B,
|
||||
0xFF, 0x1B, 0xFF, 0x23, 0xFF, 0x1A, 0xFF, 0x21, 0xFF, 0x26, 0xFF, 0x23,
|
||||
0xFF, 0x26, 0xFF, 0x27, 0xFF, 0x30, 0xFF, 0x27, 0xFF, 0x2F, 0xFF, 0x28,
|
||||
0xFF, 0x2C, 0xFF, 0x27, 0xFF, 0x33, 0xFF, 0x29, 0xFF, 0x33, 0xFF, 0x3A,
|
||||
0xFF, 0x42, 0xFF, 0x3B, 0xFF, 0x4D, 0xFF, 0x4B, 0xFF, 0x4D, 0xFF, 0x4A,
|
||||
0xFF, 0x67, 0xFF, 0x77, 0xFF, 0x73, 0xFF, 0x7B, 0xFF, 0xDE, 0xFF, 0xAD,
|
||||
0x00, 0x4A, 0x00, 0x63, 0xEC, 0x8C, 0x03, 0xBB, 0x0E, 0xE4, 0x08, 0xF2,
|
||||
0x00, 0x70, 0xE3, 0xD1, 0xE5, 0xE4, 0x01, 0x6E, 0x0A, 0x67, 0x1C, 0x74,
|
||||
0xF8, 0x8E, 0x10, 0x7B, 0xEA, 0x3C, 0x09, 0x87, 0x1B, 0x24, 0xEF, 0x05,
|
||||
0x17, 0x76, 0x0D, 0x5B, 0x02, 0x43, 0xF5, 0xEF, 0x0C, 0x1D, 0xF7, 0x61,
|
||||
0x05, 0x95, 0x0B, 0xC2, 0xF1, 0x69, 0x1A, 0xA1, 0xEC, 0x75, 0xF4, 0x11,
|
||||
0x13, 0x4F, 0x13, 0x71, 0xFA, 0x33, 0xEC, 0x32, 0xC8, 0xCF, 0x05, 0xB0,
|
||||
0x0B, 0x61, 0x33, 0x19, 0xCE, 0x37, 0xEF, 0xD4, 0x21, 0x9D, 0xFA, 0xAE,
|
||||
} ;
|
||||
|
||||
static void rw_test (const char *filename) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ const char *filename = "rw.aifc" ;
|
||||
|
||||
print_test_name ("aiff_rw_test", filename) ;
|
||||
|
||||
dump_data_to_file (filename, aifc_data, sizeof (aifc_data)) ;
|
||||
|
||||
rw_test (filename) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
rw_test (const char *filename)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo_rd, sfinfo_rw ;
|
||||
|
||||
memset (&sfinfo_rd, 0, sizeof (sfinfo_rd)) ;
|
||||
memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
|
||||
|
||||
/* Open the file in read only mode and fill in the SF_INFO struct. */
|
||||
if ((file = sf_open (filename, SFM_READ, &sfinfo_rd)) == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open SFM_READ failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now open read/write and close the file. */
|
||||
if ((file = sf_open (filename, SFM_RDWR, &sfinfo_rw)) == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open again as read only again and fill in a new SF_INFO struct. */
|
||||
memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
|
||||
if ((file = sf_open (filename, SFM_READ, &sfinfo_rw)) == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now compare the two. */
|
||||
if (sfinfo_rd.format != sfinfo_rw.format)
|
||||
{ printf ("\n\nLine %d : format mismatch (0x%08X != 0x%08X).\n\n", __LINE__,
|
||||
sfinfo_rd.format, sfinfo_rw.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo_rd.channels != sfinfo_rw.channels)
|
||||
{ printf ("\n\nLine %d : channel count mismatch (%d != %d).\n\n", __LINE__,
|
||||
sfinfo_rd.channels, sfinfo_rw.channels) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo_rd.frames != sfinfo_rw.frames)
|
||||
{ printf ("\n\nLine %d : frame count mismatch (rd %" PRId64 " != rw %" PRId64 ").\n\n", __LINE__,
|
||||
sfinfo_rd.frames, sfinfo_rw.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* rw_test */
|
||||
|
||||
238
Engine/lib/libsndfile/tests/alaw_test.c
Normal file
238
Engine/lib/libsndfile/tests/alaw_test.c
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (65536)
|
||||
|
||||
static unsigned char alaw_encode (int sample) ;
|
||||
static int alaw_decode (unsigned int alawbyte) ;
|
||||
|
||||
static short short_buffer [BUFFER_SIZE] ;
|
||||
static unsigned char alaw_buffer [BUFFER_SIZE] ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
const char *filename ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("alaw_test", "encoder") ;
|
||||
|
||||
filename = "alaw_test.raw" ;
|
||||
|
||||
sf_info_setup (&sfinfo, SF_FORMAT_RAW | SF_FORMAT_ALAW, 44100, 1) ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Generate a file containing all possible 16 bit sample values
|
||||
** and write it to disk as alaw encoded.frames.
|
||||
*/
|
||||
|
||||
for (k = 0 ; k < 0x10000 ; k++)
|
||||
short_buffer [k] = k & 0xFFFF ;
|
||||
|
||||
sf_write_short (file, short_buffer, BUFFER_SIZE) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now open that file and compare the alaw encoded sample values
|
||||
** with what they should be.
|
||||
*/
|
||||
|
||||
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sf_read_raw (file, alaw_buffer, BUFFER_SIZE) != BUFFER_SIZE)
|
||||
{ printf ("sf_read_raw : ") ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < 0x10000 ; k++)
|
||||
if (alaw_encode (short_buffer [k]) != alaw_buffer [k])
|
||||
{ printf ("Encoder error : sample #%d (0x%02X should be 0x%02X)\n", k, alaw_buffer [k], alaw_encode (short_buffer [k])) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
print_test_name ("alaw_test", "decoder") ;
|
||||
/* Now generate a file containing all possible 8 bit encoded
|
||||
** sample values and write it to disk as alaw encoded.frames.
|
||||
*/
|
||||
|
||||
if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < 256 ; k++)
|
||||
alaw_buffer [k] = k & 0xFF ;
|
||||
|
||||
sf_write_raw (file, alaw_buffer, 256) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now open that file and compare the alaw decoded sample values
|
||||
** with what they should be.
|
||||
*/
|
||||
|
||||
if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sf_read_short (file, short_buffer, 256) != 256)
|
||||
{ printf ("sf_read_short : ") ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
||||
for (k = 0 ; k < 256 ; k++)
|
||||
if (short_buffer [k] != alaw_decode (alaw_buffer [k]))
|
||||
{ printf ("Decoder error : sample #%d (0x%02X should be 0x%02X)\n", k, short_buffer [k], alaw_decode (alaw_buffer [k])) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*=================================================================================
|
||||
** The following routines came from the sox-12.15 (Sound eXcahcnge) distribution.
|
||||
**
|
||||
** This code is not compiled into libsndfile. It is only used to test the
|
||||
** libsndfile lookup tables for correctness.
|
||||
**
|
||||
** I have included the original authors comments.
|
||||
*/
|
||||
|
||||
/*
|
||||
** A-law routines by Graeme W. Gill.
|
||||
** Date: 93/5/7
|
||||
**
|
||||
** References:
|
||||
** 1) CCITT Recommendation G.711
|
||||
**
|
||||
*/
|
||||
|
||||
#define ACLIP 31744
|
||||
|
||||
static
|
||||
unsigned char alaw_encode (int sample)
|
||||
{ static int exp_lut [128] =
|
||||
{ 1, 1, 2, 2, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7
|
||||
} ;
|
||||
|
||||
int sign, exponent, mantissa ;
|
||||
unsigned char Alawbyte ;
|
||||
|
||||
/* Get the sample into sign-magnitude. */
|
||||
sign = ((~sample) >> 8) & 0x80 ; /* set aside the sign */
|
||||
if (sign == 0)
|
||||
sample = -sample ; /* get magnitude */
|
||||
if (sample > ACLIP)
|
||||
sample = ACLIP ; /* clip the magnitude */
|
||||
|
||||
/* Convert from 16 bit linear to ulaw. */
|
||||
if (sample >= 256)
|
||||
{ exponent = exp_lut [(sample >> 8) & 0x7F] ;
|
||||
mantissa = (sample >> (exponent + 3)) & 0x0F ;
|
||||
Alawbyte = ((exponent << 4) | mantissa) ;
|
||||
}
|
||||
else
|
||||
Alawbyte = (sample >> 4) ;
|
||||
|
||||
Alawbyte ^= (sign ^ 0x55) ;
|
||||
|
||||
return Alawbyte ;
|
||||
} /* alaw_encode */
|
||||
|
||||
static
|
||||
int alaw_decode (unsigned int Alawbyte)
|
||||
{ static int exp_lut [8] = { 0, 264, 528, 1056, 2112, 4224, 8448, 16896 } ;
|
||||
int sign, exponent, mantissa, sample ;
|
||||
|
||||
Alawbyte ^= 0x55 ;
|
||||
sign = (Alawbyte & 0x80) ;
|
||||
Alawbyte &= 0x7f ; /* get magnitude */
|
||||
if (Alawbyte >= 16)
|
||||
{ exponent = (Alawbyte >> 4) & 0x07 ;
|
||||
mantissa = Alawbyte & 0x0F ;
|
||||
sample = exp_lut [exponent] + (mantissa << (exponent + 3)) ;
|
||||
}
|
||||
else
|
||||
sample = (Alawbyte << 4) + 8 ;
|
||||
if (sign == 0)
|
||||
sample = -sample ;
|
||||
|
||||
return sample ;
|
||||
} /* alaw_decode */
|
||||
|
||||
40
Engine/lib/libsndfile/tests/benchmark-0.0.28
Normal file
40
Engine/lib/libsndfile/tests/benchmark-0.0.28
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
erikd@coltrane > tests/benchmark
|
||||
Benchmarking libsndfile-0.0.28
|
||||
------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 30660117 samples per sec
|
||||
Raw read PCM_16 : 62788982 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 83.37% of raw write
|
||||
Read short from PCM_16 : 83.17% of raw read
|
||||
Write int to PCM_24 : 30.78% of raw write
|
||||
Read int from PCM_24 : 32.96% of raw read
|
||||
Write int to PCM_32 : 42.05% of raw write
|
||||
Read int from PCM_32 : 41.11% of raw read
|
||||
Write float to PCM_16 : 17.75% of raw write
|
||||
Read float from PCM_16 : 43.27% of raw read
|
||||
Write float to PCM_24 : 15.30% of raw write
|
||||
Read float from PCM_24 : 28.09% of raw read
|
||||
Write float to PCM_32 : 14.55% of raw write
|
||||
Read float from PCM_32 : 34.65% of raw read
|
||||
Write float to FLOAT : 28.98% of raw write
|
||||
Read float from FLOAT : 56.71% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 43.39% of raw write
|
||||
Read short from PCM_16 : 49.12% of raw read
|
||||
Write int to PCM_24 : 29.65% of raw write
|
||||
Read int from PCM_24 : 33.66% of raw read
|
||||
Write int to PCM_32 : 19.62% of raw write
|
||||
Read int from PCM_32 : 21.97% of raw read
|
||||
Write float to PCM_16 : 17.63% of raw write
|
||||
Read float from PCM_16 : 31.43% of raw read
|
||||
Write float to PCM_24 : 14.91% of raw write
|
||||
Read float from PCM_24 : 27.99% of raw read
|
||||
Write float to PCM_32 : 13.69% of raw write
|
||||
Read float from PCM_32 : 22.23% of raw read
|
||||
Write float to FLOAT : 19.25% of raw write
|
||||
Read float from FLOAT : 25.66% of raw read
|
||||
|
||||
35
Engine/lib/libsndfile/tests/benchmark-1.0.0
Normal file
35
Engine/lib/libsndfile/tests/benchmark-1.0.0
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
Benchmarking libsndfile-1.0.0
|
||||
-----------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 31084269 samples per sec
|
||||
Raw read PCM_16 : 63597065 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 83.19% of raw write
|
||||
Read short from PCM_16 : 82.93% of raw read
|
||||
Write int to PCM_24 : 31.12% of raw write
|
||||
Read int from PCM_24 : 37.90% of raw read
|
||||
Write float to PCM_16 : 37.00% of raw write
|
||||
Read float from PCM_16 : 45.53% of raw read
|
||||
Write float to PCM_24 : 29.08% of raw write
|
||||
Read float from PCM_24 : 28.48% of raw read
|
||||
Write float to PCM_32 : 22.08% of raw write
|
||||
Read float from PCM_32 : 31.21% of raw read
|
||||
Write float to FLOAT : 28.70% of raw write
|
||||
Read float from FLOAT : 56.32% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 22.08% of raw write
|
||||
Read short from PCM_16 : 23.20% of raw read
|
||||
Write int to PCM_24 : 30.96% of raw write
|
||||
Read int from PCM_24 : 37.76% of raw read
|
||||
Write float to PCM_16 : 35.82% of raw write
|
||||
Read float from PCM_16 : 22.61% of raw read
|
||||
Write float to PCM_24 : 27.70% of raw write
|
||||
Read float from PCM_24 : 28.37% of raw read
|
||||
Write float to PCM_32 : 20.77% of raw write
|
||||
Read float from PCM_32 : 23.46% of raw read
|
||||
Write float to FLOAT : 15.03% of raw write
|
||||
Read float from FLOAT : 15.43% of raw read
|
||||
|
||||
31
Engine/lib/libsndfile/tests/benchmark-1.0.0rc2
Normal file
31
Engine/lib/libsndfile/tests/benchmark-1.0.0rc2
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
Benchmarking libsndfile-1.0.0rc2
|
||||
--------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 31638069 samples per sec
|
||||
Raw read PCM_16 : 62788982 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 82.37% of raw write
|
||||
Read short from PCM_16 : 82.17% of raw read
|
||||
Write int to PCM_24 : 30.80% of raw write
|
||||
Read int from PCM_24 : 37.95% of raw read
|
||||
Write float to PCM_16 : 36.22% of raw write
|
||||
Read float from PCM_16 : 23.32% of raw read
|
||||
Write float to PCM_24 : 28.41% of raw write
|
||||
Read float from PCM_24 : 28.41% of raw read
|
||||
Write float to FLOAT : 28.41% of raw write
|
||||
Read float from FLOAT : 57.50% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 21.73% of raw write
|
||||
Read short from PCM_16 : 23.37% of raw read
|
||||
Write int to PCM_24 : 31.02% of raw write
|
||||
Read int from PCM_24 : 38.24% of raw read
|
||||
Write float to PCM_16 : 35.51% of raw write
|
||||
Read float from PCM_16 : 19.16% of raw read
|
||||
Write float to PCM_24 : 27.37% of raw write
|
||||
Read float from PCM_24 : 28.74% of raw read
|
||||
Write float to FLOAT : 15.11% of raw write
|
||||
Read float from FLOAT : 15.60% of raw read
|
||||
|
||||
38
Engine/lib/libsndfile/tests/benchmark-1.0.18pre16-hendrix
Normal file
38
Engine/lib/libsndfile/tests/benchmark-1.0.18pre16-hendrix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Benchmarking libsndfile-1.0.18pre15
|
||||
-----------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 103189885 samples per sec
|
||||
Raw read PCM_16 : 660854036 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 95.08% of raw write
|
||||
Read short from PCM_16 : 96.39% of raw read
|
||||
Write int to PCM_24 : 54.55% of raw write
|
||||
Read int from PCM_24 : 28.50% of raw read
|
||||
Write int to PCM_32 : 46.97% of raw write
|
||||
Read int from PCM_32 : 39.98% of raw read
|
||||
Write float to PCM_16 : 60.85% of raw write
|
||||
Read float from PCM_16 : 27.79% of raw read
|
||||
Write float to PCM_24 : 46.23% of raw write
|
||||
Read float from PCM_24 : 22.62% of raw read
|
||||
Write float to PCM_32 : 35.38% of raw write
|
||||
Read float from PCM_32 : 24.18% of raw read
|
||||
Write float to FLOAT : 47.73% of raw write
|
||||
Read float from FLOAT : 40.62% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 79.98% of raw write
|
||||
Read short from PCM_16 : 49.27% of raw read
|
||||
Write int to PCM_24 : 53.80% of raw write
|
||||
Read int from PCM_24 : 28.50% of raw read
|
||||
Write int to PCM_32 : 41.68% of raw write
|
||||
Read int from PCM_32 : 25.89% of raw read
|
||||
Write float to PCM_16 : 61.03% of raw write
|
||||
Read float from PCM_16 : 27.74% of raw read
|
||||
Write float to PCM_24 : 45.10% of raw write
|
||||
Read float from PCM_24 : 22.43% of raw read
|
||||
Write float to PCM_32 : 35.24% of raw write
|
||||
Read float from PCM_32 : 22.37% of raw read
|
||||
Write float to FLOAT : 42.01% of raw write
|
||||
Read float from FLOAT : 28.98% of raw read
|
||||
38
Engine/lib/libsndfile/tests/benchmark-1.0.18pre16-mingus
Normal file
38
Engine/lib/libsndfile/tests/benchmark-1.0.18pre16-mingus
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Benchmarking libsndfile-1.0.18pre15
|
||||
-----------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 178237074 samples per sec
|
||||
Raw read PCM_16 : 368885269 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 98.84% of raw write
|
||||
Read short from PCM_16 : 147.10% of raw read
|
||||
Write int to PCM_24 : 33.74% of raw write
|
||||
Read int from PCM_24 : 30.82% of raw read
|
||||
Write int to PCM_32 : 48.34% of raw write
|
||||
Read int from PCM_32 : 62.43% of raw read
|
||||
Write float to PCM_16 : 41.86% of raw write
|
||||
Read float from PCM_16 : 36.73% of raw read
|
||||
Write float to PCM_24 : 28.38% of raw write
|
||||
Read float from PCM_24 : 19.50% of raw read
|
||||
Write float to PCM_32 : 23.68% of raw write
|
||||
Read float from PCM_32 : 28.76% of raw read
|
||||
Write float to FLOAT : 47.21% of raw write
|
||||
Read float from FLOAT : 60.85% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 54.94% of raw write
|
||||
Read short from PCM_16 : 59.03% of raw read
|
||||
Write int to PCM_24 : 33.40% of raw write
|
||||
Read int from PCM_24 : 31.98% of raw read
|
||||
Write int to PCM_32 : 30.89% of raw write
|
||||
Read int from PCM_32 : 33.68% of raw read
|
||||
Write float to PCM_16 : 41.61% of raw write
|
||||
Read float from PCM_16 : 26.76% of raw read
|
||||
Write float to PCM_24 : 25.75% of raw write
|
||||
Read float from PCM_24 : 19.84% of raw read
|
||||
Write float to PCM_32 : 21.29% of raw write
|
||||
Read float from PCM_32 : 21.78% of raw read
|
||||
Write float to FLOAT : 30.82% of raw write
|
||||
Read float from FLOAT : 35.04% of raw read
|
||||
39
Engine/lib/libsndfile/tests/benchmark-1.0.6pre10-coltrane
Normal file
39
Engine/lib/libsndfile/tests/benchmark-1.0.6pre10-coltrane
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Benchmarking libsndfile-1.0.6pre10
|
||||
----------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 28845961 samples per sec
|
||||
Raw read PCM_16 : 63471874 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 86.21% of raw write
|
||||
Read short from PCM_16 : 82.60% of raw read
|
||||
Write int to PCM_24 : 34.89% of raw write
|
||||
Read int from PCM_24 : 37.26% of raw read
|
||||
Write int to PCM_32 : 43.36% of raw write
|
||||
Read int from PCM_32 : 41.30% of raw read
|
||||
Write float to PCM_16 : 43.02% of raw write
|
||||
Read float from PCM_16 : 43.99% of raw read
|
||||
Write float to PCM_24 : 32.72% of raw write
|
||||
Read float from PCM_24 : 28.21% of raw read
|
||||
Write float to PCM_32 : 25.92% of raw write
|
||||
Read float from PCM_32 : 30.98% of raw read
|
||||
Write float to FLOAT : 46.65% of raw write
|
||||
Read float from FLOAT : 56.66% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 54.53% of raw write
|
||||
Read short from PCM_16 : 56.32% of raw read
|
||||
Write int to PCM_24 : 35.28% of raw write
|
||||
Read int from PCM_24 : 37.33% of raw read
|
||||
Write int to PCM_32 : 26.21% of raw write
|
||||
Read int from PCM_32 : 23.51% of raw read
|
||||
Write float to PCM_16 : 41.39% of raw write
|
||||
Read float from PCM_16 : 23.56% of raw read
|
||||
Write float to PCM_24 : 30.86% of raw write
|
||||
Read float from PCM_24 : 28.27% of raw read
|
||||
Write float to PCM_32 : 23.83% of raw write
|
||||
Read float from PCM_32 : 20.54% of raw read
|
||||
Write float to FLOAT : 27.26% of raw write
|
||||
Read float from FLOAT : 29.04% of raw read
|
||||
|
||||
39
Engine/lib/libsndfile/tests/benchmark-1.0.6pre10-miles
Normal file
39
Engine/lib/libsndfile/tests/benchmark-1.0.6pre10-miles
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
Benchmarking libsndfile-1.0.6pre10
|
||||
----------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 40092612 samples per sec
|
||||
Raw read PCM_16 : 42382563 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 61.90% of raw write
|
||||
Read short from PCM_16 : 100.20% of raw read
|
||||
Write int to PCM_24 : 28.69% of raw write
|
||||
Read int from PCM_24 : 33.62% of raw read
|
||||
Write int to PCM_32 : 31.14% of raw write
|
||||
Read int from PCM_32 : 51.04% of raw read
|
||||
Write float to PCM_16 : 25.57% of raw write
|
||||
Read float from PCM_16 : 28.17% of raw read
|
||||
Write float to PCM_24 : 23.59% of raw write
|
||||
Read float from PCM_24 : 24.14% of raw read
|
||||
Write float to PCM_32 : 18.00% of raw write
|
||||
Read float from PCM_32 : 22.59% of raw read
|
||||
Write float to FLOAT : 31.32% of raw write
|
||||
Read float from FLOAT : 51.54% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 42.81% of raw write
|
||||
Read short from PCM_16 : 54.58% of raw read
|
||||
Write int to PCM_24 : 29.28% of raw write
|
||||
Read int from PCM_24 : 33.43% of raw read
|
||||
Write int to PCM_32 : 22.21% of raw write
|
||||
Read int from PCM_32 : 27.24% of raw read
|
||||
Write float to PCM_16 : 25.76% of raw write
|
||||
Read float from PCM_16 : 26.84% of raw read
|
||||
Write float to PCM_24 : 23.71% of raw write
|
||||
Read float from PCM_24 : 24.10% of raw read
|
||||
Write float to PCM_32 : 18.47% of raw write
|
||||
Read float from PCM_32 : 21.45% of raw read
|
||||
Write float to FLOAT : 22.46% of raw write
|
||||
Read float from FLOAT : 29.72% of raw read
|
||||
|
||||
75
Engine/lib/libsndfile/tests/benchmark-latest-coltrane
Normal file
75
Engine/lib/libsndfile/tests/benchmark-latest-coltrane
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
erikd@coltrane > cat tests/benchmark-0.0.28
|
||||
Benchmarking libsndfile-0.0.28
|
||||
------------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 31022959 samples per sec
|
||||
Raw read PCM_16 : 63471874 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 83.19% of raw write
|
||||
Read short from PCM_16 : 82.28% of raw read
|
||||
Write int to PCM_24 : 30.81% of raw write
|
||||
Read int from PCM_24 : 32.92% of raw read
|
||||
Write float to PCM_16 : 17.70% of raw write
|
||||
Read float from PCM_16 : 43.64% of raw read
|
||||
Write float to PCM_24 : 15.09% of raw write
|
||||
Read float from PCM_24 : 27.79% of raw read
|
||||
Write float to PCM_32 : 14.32% of raw write
|
||||
Read float from PCM_32 : 34.42% of raw read
|
||||
Write float to FLOAT : 28.64% of raw write
|
||||
Read float from FLOAT : 56.77% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 44.04% of raw write
|
||||
Read short from PCM_16 : 49.46% of raw read
|
||||
Write int to PCM_24 : 28.92% of raw write
|
||||
Read int from PCM_24 : 33.10% of raw read
|
||||
Write float to PCM_16 : 17.30% of raw write
|
||||
Read float from PCM_16 : 31.46% of raw read
|
||||
Write float to PCM_24 : 14.62% of raw write
|
||||
Read float from PCM_24 : 27.64% of raw read
|
||||
Write float to PCM_32 : 13.65% of raw write
|
||||
Read float from PCM_32 : 22.41% of raw read
|
||||
Write float to FLOAT : 19.13% of raw write
|
||||
Read float from FLOAT : 26.21% of raw read
|
||||
|
||||
erikd@coltrane > tests/benchmark
|
||||
Benchmarking libsndfile-1.0.0
|
||||
-----------------------------
|
||||
Each test takes a little over 5 seconds.
|
||||
|
||||
Raw write PCM_16 : 29884416 samples per sec
|
||||
Raw read PCM_16 : 63347175 samples per sec
|
||||
|
||||
Native endian I/O :
|
||||
Write short to PCM_16 : 88.24% of raw write
|
||||
Read short from PCM_16 : 82.76% of raw read
|
||||
Write int to PCM_24 : 34.95% of raw write
|
||||
Read int from PCM_24 : 37.17% of raw read
|
||||
Write int to PCM_32 : 43.86% of raw write
|
||||
Read int from PCM_32 : 41.22% of raw read
|
||||
Write float to PCM_16 : 42.07% of raw write
|
||||
Read float from PCM_16 : 44.25% of raw read
|
||||
Write float to PCM_24 : 32.43% of raw write
|
||||
Read float from PCM_24 : 28.93% of raw read
|
||||
Write float to PCM_32 : 25.60% of raw write
|
||||
Read float from PCM_32 : 31.10% of raw read
|
||||
Write float to FLOAT : 45.55% of raw write
|
||||
Read float from FLOAT : 57.41% of raw read
|
||||
|
||||
Endian swapped I/O :
|
||||
Write short to PCM_16 : 43.46% of raw write
|
||||
Read short from PCM_16 : 43.99% of raw read
|
||||
Write int to PCM_24 : 35.09% of raw write
|
||||
Read int from PCM_24 : 37.34% of raw read
|
||||
Write int to PCM_32 : 24.05% of raw write
|
||||
Read int from PCM_32 : 19.74% of raw read
|
||||
Write float to PCM_16 : 40.25% of raw write
|
||||
Read float from PCM_16 : 32.15% of raw read
|
||||
Write float to PCM_24 : 31.02% of raw write
|
||||
Read float from PCM_24 : 28.82% of raw read
|
||||
Write float to PCM_32 : 23.54% of raw write
|
||||
Read float from PCM_32 : 23.65% of raw read
|
||||
Write float to FLOAT : 24.87% of raw write
|
||||
Read float from FLOAT : 20.28% of raw read
|
||||
17
Engine/lib/libsndfile/tests/benchmark.def
Normal file
17
Engine/lib/libsndfile/tests/benchmark.def
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
autogen definitions benchmark.tpl;
|
||||
|
||||
data_type = {
|
||||
type_name = short ;
|
||||
multiplier = "32700.0" ;
|
||||
};
|
||||
|
||||
data_type = {
|
||||
type_name = int ;
|
||||
multiplier = "32700.0 * (1 << 16)" ;
|
||||
};
|
||||
|
||||
data_type = {
|
||||
type_name = float ;
|
||||
multiplier = "1.0" ;
|
||||
};
|
||||
|
||||
360
Engine/lib/libsndfile/tests/benchmark.tpl
Normal file
360
Engine/lib/libsndfile/tests/benchmark.tpl
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 2002-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Neat solution to the Win32/OS2 binary file flage requirement.
|
||||
** If O_BINARY isn't already defined by the inclusion of the system
|
||||
** headers, set it to zero.
|
||||
*/
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#define WRITE_FLAGS (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
|
||||
#define READ_FLAGS (O_RDONLY | O_BINARY)
|
||||
|
||||
#if (defined (WIN32) || defined (_WIN32) || defined (__OS2__))
|
||||
#define WRITE_PERMS 0777
|
||||
#else
|
||||
#define WRITE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP)
|
||||
#endif
|
||||
|
||||
#define BUFFER_SIZE (1 << 18)
|
||||
#define BLOCK_COUNT (30)
|
||||
#define TEST_DURATION (5) /* 5 Seconds. */
|
||||
|
||||
typedef struct
|
||||
{ double write_rate ;
|
||||
double read_rate ;
|
||||
} PERF_STATS ;
|
||||
|
||||
static void *data = NULL ;
|
||||
|
||||
static void calc_raw_performance (PERF_STATS *stats) ;
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void calc_[+ (get "type_name") +]_performance (int format, double read_rate, double write_rate) ;
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
static int cpu_is_big_endian (void) ;
|
||||
|
||||
static const char* get_subtype_str (int subtype) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ PERF_STATS stats ;
|
||||
char buffer [256] = "Benchmarking " ;
|
||||
int format_major ;
|
||||
|
||||
if (! (data = malloc (BUFFER_SIZE * sizeof (double))))
|
||||
{ perror ("Error : malloc failed") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, buffer + strlen (buffer), sizeof (buffer) - strlen (buffer)) ;
|
||||
|
||||
puts (buffer) ;
|
||||
memset (buffer, '-', strlen (buffer)) ;
|
||||
puts (buffer) ;
|
||||
printf ("Each test takes a little over %d seconds.\n\n", TEST_DURATION) ;
|
||||
|
||||
calc_raw_performance (&stats) ;
|
||||
|
||||
if (argc < 2 || strcmp ("--native-only", argv [1]) == 0)
|
||||
{ puts ("\nNative endian I/O :") ;
|
||||
format_major = cpu_is_big_endian () ? SF_FORMAT_AIFF : SF_FORMAT_WAV ;
|
||||
|
||||
calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
|
||||
calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
|
||||
calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ;
|
||||
} ;
|
||||
|
||||
if (argc < 2 || strcmp ("--swap-only", argv [1]) == 0)
|
||||
{ puts ("\nEndian swapped I/O :") ;
|
||||
format_major = cpu_is_big_endian () ? SF_FORMAT_WAV : SF_FORMAT_AIFF ;
|
||||
|
||||
calc_short_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
|
||||
calc_int_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
|
||||
calc_int_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_16, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_24, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_PCM_32, stats.read_rate, stats.write_rate) ;
|
||||
calc_float_performance (format_major | SF_FORMAT_FLOAT , stats.read_rate, stats.write_rate) ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
free (data) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
calc_raw_performance (PERF_STATS *stats)
|
||||
{ clock_t start_clock, clock_time ;
|
||||
int fd, k, byte_count, retval, op_count ;
|
||||
const char *filename ;
|
||||
|
||||
filename = "benchmark.dat" ;
|
||||
|
||||
byte_count = BUFFER_SIZE * sizeof (short) ;
|
||||
|
||||
/* Collect write stats */
|
||||
printf (" Raw write PCM_16 : ") ;
|
||||
fflush (stdout) ;
|
||||
|
||||
clock_time = 0 ;
|
||||
op_count = 0 ;
|
||||
start_clock = clock () ;
|
||||
|
||||
while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
|
||||
{ if ((fd = open (filename, WRITE_FLAGS, WRITE_PERMS)) < 0)
|
||||
{ printf ("Error : not able to open file : %s\n", filename) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < BLOCK_COUNT ; k++)
|
||||
{ if ((retval = write (fd, data, byte_count)) != byte_count)
|
||||
{ printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
close (fd) ;
|
||||
|
||||
clock_time = clock () - start_clock ;
|
||||
op_count ++ ;
|
||||
} ;
|
||||
|
||||
stats->write_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
|
||||
stats->write_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
|
||||
printf ("%10.0f samples per sec\n", stats->write_rate) ;
|
||||
|
||||
/* Collect read stats */
|
||||
printf (" Raw read PCM_16 : ") ;
|
||||
fflush (stdout) ;
|
||||
|
||||
clock_time = 0 ;
|
||||
op_count = 0 ;
|
||||
start_clock = clock () ;
|
||||
|
||||
while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
|
||||
{ if ((fd = open (filename, READ_FLAGS)) < 0)
|
||||
{ printf ("Error : not able to open file : %s\n", filename) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < BLOCK_COUNT ; k++)
|
||||
{ if ((retval = read (fd, data, byte_count)) != byte_count)
|
||||
{ printf ("Error : write returned %d (should have been %d)\n", retval, byte_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
close (fd) ;
|
||||
|
||||
clock_time = clock () - start_clock ;
|
||||
op_count ++ ;
|
||||
} ;
|
||||
|
||||
stats->read_rate = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
|
||||
stats->read_rate *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
|
||||
printf ("%10.0f samples per sec\n", stats->read_rate) ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* calc_raw_performance */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void
|
||||
calc_[+ (get "type_name") +]_performance (int format, double read_rate, double write_rate)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
clock_t start_clock, clock_time ;
|
||||
double performance ;
|
||||
int k, item_count, retval, op_count ;
|
||||
const char* subtype ;
|
||||
[+ (get "type_name") +] *[+ (get "type_name") +]_data ;
|
||||
const char *filename ;
|
||||
|
||||
filename = "benchmark.dat" ;
|
||||
subtype = get_subtype_str (format & SF_FORMAT_SUBMASK) ;
|
||||
|
||||
[+ (get "type_name") +]_data = data ;
|
||||
item_count = BUFFER_SIZE ;
|
||||
for (k = 0 ; k < item_count ; k++)
|
||||
[+ (get "type_name") +]_data [k] = [+ (get "multiplier") +] * sin (2 * M_PI * k / 32000.0) ;
|
||||
|
||||
/* Collect write stats */
|
||||
printf (" Write %-5s to %s : ", "[+ (get "type_name") +]", subtype) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.frames = 1 ;
|
||||
sfinfo.samplerate = 32000 ;
|
||||
|
||||
clock_time = 0 ;
|
||||
op_count = 0 ;
|
||||
start_clock = clock () ;
|
||||
|
||||
while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
|
||||
{ if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
||||
{ printf ("Error : not able to open file : %s\n", filename) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Turn off the addition of a PEAK chunk. */
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
|
||||
for (k = 0 ; k < BLOCK_COUNT ; k++)
|
||||
{ if ((retval = sf_write_[+ (get "type_name") +] (file, [+ (get "type_name") +]_data, item_count)) != item_count)
|
||||
{ printf ("Error : sf_write_short returned %d (should have been %d)\n", retval, item_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
clock_time = clock () - start_clock ;
|
||||
op_count ++ ;
|
||||
} ;
|
||||
|
||||
performance = (1.0 * BUFFER_SIZE) * BLOCK_COUNT * op_count ;
|
||||
performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
|
||||
printf ("%6.2f%% of raw write\n", 100.0 * performance / write_rate) ;
|
||||
|
||||
/* Collect read stats */
|
||||
printf (" Read %-5s from %s : ", "[+ (get "type_name") +]", subtype) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
clock_time = 0 ;
|
||||
op_count = 0 ;
|
||||
start_clock = clock () ;
|
||||
|
||||
while (clock_time < (CLOCKS_PER_SEC * TEST_DURATION))
|
||||
{ if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
||||
{ printf ("Error : not able to open file : %s\n", filename) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < BLOCK_COUNT ; k++)
|
||||
{ if ((retval = sf_read_[+ (get "type_name") +] (file, [+ (get "type_name") +]_data, item_count)) != item_count)
|
||||
{ printf ("Error : write returned %d (should have been %d)\n", retval, item_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
clock_time = clock () - start_clock ;
|
||||
op_count ++ ;
|
||||
} ;
|
||||
|
||||
performance = (1.0 * item_count) * BLOCK_COUNT * op_count ;
|
||||
performance *= (1.0 * CLOCKS_PER_SEC) / clock_time ;
|
||||
printf ("%6.2f%% of raw read\n", 100.0 * performance / read_rate) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
} /* calc_[+ (get "type_name") +]_performance */
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static int
|
||||
cpu_is_big_endian (void)
|
||||
{ unsigned char *cptr ;
|
||||
int endtest ;
|
||||
|
||||
endtest = 0x12345678 ;
|
||||
|
||||
cptr = (unsigned char*) (&endtest) ;
|
||||
|
||||
if (cptr [0] == 0x12 && cptr [1] == 0x34 && cptr [3] == 0x78)
|
||||
return SF_TRUE ;
|
||||
|
||||
return SF_FALSE ;
|
||||
} /* cpu_is_big_endian */
|
||||
|
||||
static const char*
|
||||
get_subtype_str (int subtype)
|
||||
{ switch (subtype)
|
||||
{ case SF_FORMAT_PCM_16 :
|
||||
return "PCM_16" ;
|
||||
|
||||
case SF_FORMAT_PCM_24 :
|
||||
return "PCM_24" ;
|
||||
|
||||
case SF_FORMAT_PCM_32 :
|
||||
return "PCM_32" ;
|
||||
|
||||
case SF_FORMAT_FLOAT :
|
||||
return "FLOAT " ;
|
||||
|
||||
case SF_FORMAT_DOUBLE :
|
||||
return "DOUBLE" ;
|
||||
|
||||
default : break ;
|
||||
} ;
|
||||
|
||||
return "UNKNOWN" ;
|
||||
} /* get_subtype_str */
|
||||
|
||||
138
Engine/lib/libsndfile/tests/channel_test.c
Normal file
138
Engine/lib/libsndfile/tests/channel_test.c
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2015 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void channel_test (void) ;
|
||||
static double max_diff (const float *a, const float *b, unsigned int len, unsigned int * position) ;
|
||||
|
||||
int
|
||||
main (void) // int argc, char *argv [])
|
||||
{ channel_test () ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
channel_test (void)
|
||||
{ static float float_data [1024] ;
|
||||
static float read_float [1024] ;
|
||||
static int read_int [1024] ;
|
||||
static short read_short [1024] ;
|
||||
unsigned int ch, k, position = 0 ;
|
||||
|
||||
gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 0.9) ;
|
||||
|
||||
for (ch = 1 ; ch <= 8 ; ch++)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO wsfinfo, rsfinfo ;
|
||||
sf_count_t wframes = ARRAY_LEN (float_data) / ch ;
|
||||
double maxdiff ;
|
||||
char filename [256] ;
|
||||
|
||||
snprintf (filename, sizeof (filename), "chan_%d.wav", ch) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
sf_info_setup (&wsfinfo, SF_FORMAT_WAV | SF_FORMAT_FLOAT, 48000, ch) ;
|
||||
sf_info_clear (&rsfinfo) ;
|
||||
|
||||
/* Write the test file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &wsfinfo, SF_FALSE, __LINE__) ;
|
||||
test_writef_float_or_die (file, 0, float_data, wframes, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read it as float and test. */
|
||||
file = test_open_file_or_die (filename, SFM_READ, &rsfinfo, SF_FALSE, __LINE__) ;
|
||||
exit_if_true (rsfinfo.frames == 0,
|
||||
"\n\nLine %d : Frames in file %" PRId64 ".\n\n", __LINE__, rsfinfo.frames) ;
|
||||
exit_if_true (wframes != rsfinfo.frames,
|
||||
"\n\nLine %d : Wrote %" PRId64 ", read %" PRId64 " frames.\n\n", __LINE__, wframes, rsfinfo.frames) ;
|
||||
|
||||
sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
||||
|
||||
test_readf_float_or_die (file, 0, read_float, rsfinfo.frames, __LINE__) ;
|
||||
compare_float_or_die (float_data, read_float, ch * rsfinfo.frames, __LINE__) ;
|
||||
|
||||
/* Read it as short and test. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, ch, __LINE__) ;
|
||||
test_readf_short_or_die (file, 0, read_short, rsfinfo.frames, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (read_float) ; k++)
|
||||
read_float [k] = read_short [k] * (0.9 / 0x8000) ;
|
||||
|
||||
maxdiff = max_diff (float_data, read_float, ch * rsfinfo.frames, &position) ;
|
||||
exit_if_true (maxdiff > 0.5, "\n\nLine %d : Max diff is %f at index %u\n\n", __LINE__, maxdiff, position) ;
|
||||
|
||||
/* Read it as int and test. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, ch, __LINE__) ;
|
||||
test_readf_int_or_die (file, 0, read_int, rsfinfo.frames, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (read_float) ; k++)
|
||||
read_float [k] = read_int [k] * (0.9 / 0x80000000) ;
|
||||
|
||||
maxdiff = max_diff (float_data, read_float, ch * rsfinfo.frames, &position) ;
|
||||
exit_if_true (maxdiff > 0.5, "\n\nLine %d : Max diff is %f at index %u\n\n", __LINE__, maxdiff, position) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
printf ("ok\n") ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* channel_test */
|
||||
|
||||
static double
|
||||
max_diff (const float *a, const float *b, unsigned int len, unsigned int * position)
|
||||
{ double mdiff = 0.0, diff ;
|
||||
unsigned int k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{ diff = fabs (a [k] - b [k]) ;
|
||||
if (diff > mdiff)
|
||||
{ mdiff = diff ;
|
||||
*position = k ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
return mdiff ;
|
||||
} /* max_diff */
|
||||
129
Engine/lib/libsndfile/tests/checksum_test.c
Normal file
129
Engine/lib/libsndfile/tests/checksum_test.c
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SAMPLE_RATE 8000
|
||||
|
||||
typedef struct
|
||||
{ int enc_fmt ;
|
||||
|
||||
const char * enc_name ;
|
||||
const char * dec_name ;
|
||||
|
||||
uint64_t enc_cksum ;
|
||||
uint64_t dec_cksum ;
|
||||
} CHECKSUM ;
|
||||
|
||||
static CHECKSUM
|
||||
checksum_orig [] =
|
||||
{
|
||||
{ SF_FORMAT_RAW | SF_FORMAT_ULAW,
|
||||
"checksum.ulaw", "cksum_ulaw.pcm16",
|
||||
0xbd99d34ccbe2fLL, 0xda82168ed82e9LL
|
||||
},
|
||||
{ SF_FORMAT_RAW | SF_FORMAT_ALAW,
|
||||
"checksum.alaw", "cksum_alaw.pcm16",
|
||||
0x0004afddc0fcf4bdLL, 0x2e7320230b88LL
|
||||
},
|
||||
{ SF_FORMAT_RAW | SF_FORMAT_GSM610,
|
||||
"checksum.gsm", "cksum_gsm.pcm16",
|
||||
0xa06a3faaaf684LL, 0x2d7ff668efeb9LL
|
||||
},
|
||||
{ SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
|
||||
"checksum.vox", "cksum_vox.pcm16",
|
||||
0x7c9d7afdb96a1LL, 0xe540df74a4b14LL
|
||||
},
|
||||
} ;
|
||||
|
||||
static void checksum_test (const CHECKSUM * cksum) ;
|
||||
|
||||
static float orig [1 << 14] ;
|
||||
static short data [1 << 14] ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ unsigned k ;
|
||||
|
||||
gen_windowed_sine_float (orig, ARRAY_LEN (orig), 0.9) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (checksum_orig) ; k++)
|
||||
checksum_test (&checksum_orig [k]) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
checksum_test (const CHECKSUM * cksum)
|
||||
{ SNDFILE * file ;
|
||||
SF_INFO info ;
|
||||
|
||||
print_test_name (__func__, cksum->enc_name) ;
|
||||
|
||||
memset (&info, 0, sizeof (info)) ;
|
||||
info.format = cksum->enc_fmt ;
|
||||
info.channels = 1 ;
|
||||
info.samplerate = SAMPLE_RATE ;
|
||||
|
||||
file = test_open_file_or_die (cksum->enc_name, SFM_WRITE, &info, 0, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, orig, ARRAY_LEN (orig), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (cksum->enc_name, cksum->enc_cksum, __LINE__) ;
|
||||
puts ("ok") ;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
print_test_name (__func__, cksum->dec_name) ;
|
||||
|
||||
info.format = cksum->enc_fmt ;
|
||||
info.channels = 1 ;
|
||||
info.samplerate = SAMPLE_RATE ;
|
||||
|
||||
file = test_open_file_or_die (cksum->enc_name, SFM_READ, &info, 0, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
info.format = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
|
||||
info.channels = 1 ;
|
||||
info.samplerate = SAMPLE_RATE ;
|
||||
|
||||
file = test_open_file_or_die (cksum->dec_name, SFM_WRITE, &info, 0, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (cksum->dec_name, cksum->dec_cksum, __LINE__) ;
|
||||
|
||||
remove (cksum->enc_name) ;
|
||||
remove (cksum->dec_name) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* checksum_test */
|
||||
|
||||
446
Engine/lib/libsndfile/tests/chunk_test.c
Normal file
446
Engine/lib/libsndfile/tests/chunk_test.c
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "sfendian.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void chunk_test (const char *filename, int format) ;
|
||||
static void wav_subchunk_test (unsigned int chunk_size) ;
|
||||
static void large_free_test (const char *filename, int format, unsigned int chunk_size) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0, k ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test adding chunks to WAV files\n") ;
|
||||
printf (" aiff - test adding chunks to AIFF files\n") ;
|
||||
printf (" caf - test adding chunks to CAF files\n") ;
|
||||
printf (" rf64 - test adding chunks to RF64 files\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ chunk_test ("chunks_pcm16.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
chunk_test ("chunks_pcm16.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
chunk_test ("chunks_pcm16.wavex", SF_FORMAT_WAVEX | SF_FORMAT_PCM_16) ;
|
||||
|
||||
for (k = 100 ; k < 10000 ; k *= 4)
|
||||
wav_subchunk_test (k) ;
|
||||
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ chunk_test ("chunks_pcm16.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "caf"))
|
||||
{ chunk_test ("chunks_pcm16.caf", SF_FORMAT_CAF | SF_FORMAT_PCM_16) ;
|
||||
chunk_test ("chunks_alac.caf", SF_FORMAT_CAF | SF_FORMAT_ALAC_16) ;
|
||||
large_free_test ("large_free.caf", SF_FORMAT_CAF | SF_FORMAT_PCM_16, 100) ;
|
||||
large_free_test ("large_free.caf", SF_FORMAT_CAF | SF_FORMAT_PCM_16, 20000) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "rf64"))
|
||||
{ chunk_test ("chunks_pcm16.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
chunk_test_helper (const char *filename, int format, const char * testdata)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_CHUNK_INFO chunk_info ;
|
||||
SF_CHUNK_ITERATOR * iterator ;
|
||||
uint32_t length_before ;
|
||||
int err, allow_fd ;
|
||||
|
||||
switch (format & SF_FORMAT_SUBMASK)
|
||||
{ case SF_FORMAT_ALAC_16 :
|
||||
allow_fd = SF_FALSE ;
|
||||
break ;
|
||||
default :
|
||||
allow_fd = SF_TRUE ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = format ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
||||
|
||||
/* Set up the chunk to write. */
|
||||
memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "Test") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
chunk_info.data = strdup (testdata) ;
|
||||
chunk_info.datalen = (unsigned int) strlen (chunk_info.data) ;
|
||||
|
||||
length_before = chunk_info.datalen ;
|
||||
|
||||
err = sf_set_chunk (file, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_set_chunk returned for testdata '%s' : %s\n\n", __LINE__, testdata, sf_error_number (err)
|
||||
) ;
|
||||
|
||||
memset (chunk_info.data, 0, chunk_info.datalen) ;
|
||||
free (chunk_info.data) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
||||
|
||||
memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "Test") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
|
||||
iterator = sf_get_chunk_iterator (file, &chunk_info) ;
|
||||
err = sf_get_chunk_size (iterator, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_get_chunk_size returned for testdata '%s' : %s\n\n", __LINE__, testdata, sf_error_number (err)
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
length_before > chunk_info.datalen || chunk_info.datalen - length_before > 4,
|
||||
"\n\nLine %d : testdata '%s' : Bad chunk length %u (previous length %u)\n\n", __LINE__, testdata, chunk_info.datalen, length_before
|
||||
) ;
|
||||
|
||||
chunk_info.data = malloc (chunk_info.datalen) ;
|
||||
err = sf_get_chunk_data (iterator, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_get_chunk_size returned for testdata '%s' : %s\n\n", __LINE__, testdata, sf_error_number (err)
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
memcmp (testdata, chunk_info.data, length_before),
|
||||
"\n\nLine %d : Data compare failed.\n %s\n %s\n\n", __LINE__, testdata, (char*) chunk_info.data
|
||||
) ;
|
||||
|
||||
free (chunk_info.data) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
} /* chunk_test_helper */
|
||||
|
||||
static void
|
||||
multichunk_test_helper (const char *filename, int format, const char * testdata [], size_t testdata_len)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_CHUNK_INFO chunk_info ;
|
||||
SF_CHUNK_ITERATOR * iterator ;
|
||||
uint32_t length_before [16] ;
|
||||
int err, allow_fd ;
|
||||
size_t i ;
|
||||
|
||||
|
||||
exit_if_true (
|
||||
ARRAY_LEN (length_before) < testdata_len,
|
||||
"\n\nLine %d : Bad array length.\n\n", __LINE__
|
||||
) ;
|
||||
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = format ;
|
||||
|
||||
switch (format & SF_FORMAT_SUBMASK)
|
||||
{ case SF_FORMAT_ALAC_16 :
|
||||
allow_fd = SF_FALSE ;
|
||||
break ;
|
||||
default :
|
||||
allow_fd = SF_TRUE ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ;
|
||||
|
||||
/* Set up the chunk to write. */
|
||||
for (i = 0 ; i < testdata_len ; i++)
|
||||
{ memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "Test") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
|
||||
chunk_info.data = strdup (testdata [i]) ;
|
||||
chunk_info.datalen = (unsigned int) strlen (chunk_info.data) ;
|
||||
|
||||
length_before [i] = chunk_info.datalen ;
|
||||
|
||||
err = sf_set_chunk (file, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_set_chunk returned for testdata[%d] '%s' : %s\n\n", __LINE__, (int) i, testdata [i], sf_error_number (err)
|
||||
) ;
|
||||
|
||||
memset (chunk_info.data, 0, chunk_info.datalen) ;
|
||||
free (chunk_info.data) ;
|
||||
}
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ;
|
||||
|
||||
memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "Test") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
|
||||
iterator = sf_get_chunk_iterator (file, &chunk_info) ;
|
||||
|
||||
i = 0 ;
|
||||
while (iterator)
|
||||
{ memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
err = sf_get_chunk_size (iterator, &chunk_info) ;
|
||||
exit_if_true (
|
||||
i > testdata_len,
|
||||
"\n\nLine %d : iterated to chunk #%d, but only %d chunks have been written\n\n", __LINE__, (int) i, (int) testdata_len
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_get_chunk_size returned for testdata[%d] '%s' : %s\n\n", __LINE__, (int) i, testdata [i], sf_error_number (err)
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
length_before [i] > chunk_info.datalen || chunk_info.datalen - length_before [i] > 4,
|
||||
"\n\nLine %d : testdata[%d] '%s' : Bad chunk length %u (previous length %u)\n\n", __LINE__, (int) i, testdata [i], chunk_info.datalen, length_before [i]
|
||||
) ;
|
||||
|
||||
chunk_info.data = malloc (chunk_info.datalen) ;
|
||||
err = sf_get_chunk_data (iterator, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_get_chunk_size returned for testdata[%d] '%s' : %s\n\n", __LINE__, (int) i, testdata [i], sf_error_number (err)
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
4 != chunk_info.id_size,
|
||||
"\n\nLine %d : testdata[%d] : Bad ID length %u (previous length %u)\n\n", __LINE__, (int) i, chunk_info.id_size, 4
|
||||
) ;
|
||||
exit_if_true (
|
||||
memcmp ("Test", chunk_info.id, 4),
|
||||
"\n\nLine %d : ID compare failed at %d.\n %s\n %s\n\n", __LINE__, (int) i, "Test", (char*) chunk_info.id
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
memcmp (testdata [i], chunk_info.data, length_before [i]),
|
||||
"\n\nLine %d : Data compare failed at %d.\n %s\n %s\n\n", __LINE__, (int) i, testdata [i], (char*) chunk_info.data
|
||||
) ;
|
||||
|
||||
free (chunk_info.data) ;
|
||||
iterator = sf_next_chunk_iterator (iterator) ;
|
||||
i++ ;
|
||||
}
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
} /* multichunk_test_helper */
|
||||
|
||||
|
||||
static void
|
||||
chunk_test (const char *filename, int format)
|
||||
{ const char* testdata [] =
|
||||
{ "There can be only one.", "", "A", "AB", "ABC", "ABCD", "ABCDE" } ;
|
||||
uint32_t k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (testdata) ; k++)
|
||||
chunk_test_helper (filename, format, testdata [k]) ;
|
||||
|
||||
multichunk_test_helper (filename, format, testdata, ARRAY_LEN (testdata)) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* chunk_test */
|
||||
|
||||
|
||||
static void
|
||||
wav_subchunk_test (unsigned int chunk_size)
|
||||
{ SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_CHUNK_INFO chunk_info ;
|
||||
char filename [256] ;
|
||||
char chunk_data [10240] ;
|
||||
short audio [16] ;
|
||||
int err, value ;
|
||||
|
||||
snprintf (filename, sizeof (filename), "subchunk_%04u.wav", chunk_size) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
exit_if_true (sizeof (chunk_data) < chunk_size, "\n\nLine %d : sizeof (data) < chunk_size\n\n", __LINE__) ;
|
||||
|
||||
memset (chunk_data, 53, sizeof (chunk_data)) ;
|
||||
chunk_data [chunk_size] = 0 ;
|
||||
|
||||
/* Fill in the chunk data. */
|
||||
value = MAKE_MARKER ('a', 'd', 't', 'l') ;
|
||||
memcpy (chunk_data, &value, sizeof (value)) ;
|
||||
value = MAKE_MARKER ('n', 'o', 't', 'e') ;
|
||||
memcpy (chunk_data + 4, &value, sizeof (value)) ;
|
||||
value = H2LE_32 (chunk_size - 12) ;
|
||||
memcpy (chunk_data + 8, &value, sizeof (value)) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Set up the chunk to write. */
|
||||
memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "LIST") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
chunk_info.data = chunk_data ;
|
||||
chunk_info.datalen = (unsigned int) chunk_size ;
|
||||
|
||||
err = sf_set_chunk (file, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_set_chunk returned for testdata : %s\n\n", __LINE__, sf_error_number (err)
|
||||
) ;
|
||||
|
||||
memset (chunk_info.data, 0, chunk_info.datalen) ;
|
||||
|
||||
/* Add some audio data. */
|
||||
memset (audio, 0, sizeof (audio)) ;
|
||||
sf_write_short (file, audio, ARRAY_LEN (audio)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (
|
||||
sfinfo.frames != ARRAY_LEN (audio),
|
||||
"\n\nLine %d : Incorrect sample count (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (audio)
|
||||
) ;
|
||||
|
||||
if (chunk_size < 512)
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* wav_subchunk_test */
|
||||
|
||||
static void
|
||||
large_free_test (const char *filename, int format, unsigned int chunk_size)
|
||||
{ SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_CHUNK_INFO chunk_info ;
|
||||
char chunk_data [20002] ;
|
||||
short audio [16] ;
|
||||
int err ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
exit_if_true (sizeof (chunk_data) <= chunk_size, "\n\nLine %d : sizeof (data) < chunk_size\n\n", __LINE__) ;
|
||||
|
||||
memset (chunk_data, 53, sizeof (chunk_data)) ;
|
||||
chunk_data [chunk_size] = 0 ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = format ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Set up the chunk to write. */
|
||||
memset (&chunk_info, 0, sizeof (chunk_info)) ;
|
||||
snprintf (chunk_info.id, sizeof (chunk_info.id), "free") ;
|
||||
chunk_info.id_size = 4 ;
|
||||
chunk_info.data = chunk_data ;
|
||||
chunk_info.datalen = chunk_size ;
|
||||
|
||||
err = sf_set_chunk (file, &chunk_info) ;
|
||||
exit_if_true (
|
||||
err != SF_ERR_NO_ERROR,
|
||||
"\n\nLine %d : sf_set_chunk returned for testdata : %s\n\n", __LINE__, sf_error_number (err)
|
||||
) ;
|
||||
|
||||
memset (chunk_info.data, 0, chunk_info.datalen) ;
|
||||
|
||||
/* Add some audio data. */
|
||||
memset (audio, 0, sizeof (audio)) ;
|
||||
sf_write_short (file, audio, ARRAY_LEN (audio)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (
|
||||
sfinfo.frames != ARRAY_LEN (audio),
|
||||
"\n\nLine %d : Incorrect sample count (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (audio)
|
||||
) ;
|
||||
|
||||
if (chunk_size < 512)
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* large_free_test */
|
||||
1806
Engine/lib/libsndfile/tests/command_test.c
Normal file
1806
Engine/lib/libsndfile/tests/command_test.c
Normal file
File diff suppressed because it is too large
Load diff
234
Engine/lib/libsndfile/tests/compression_size_test.c
Normal file
234
Engine/lib/libsndfile/tests/compression_size_test.c
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "dft_cmp.h"
|
||||
|
||||
#define SAMPLE_RATE 16000
|
||||
#define DATA_LENGTH (SAMPLE_RATE)
|
||||
|
||||
static const char CMP_TEST_PREFIX[] = "cmp" ;
|
||||
|
||||
static float data_out [DATA_LENGTH] ;
|
||||
|
||||
static inline float
|
||||
max_float (float a, float b)
|
||||
{ return a > b ? a : b ;
|
||||
} /* max_float */
|
||||
|
||||
static void
|
||||
vorbis_test (void)
|
||||
{ static float float_data [DFT_DATA_LENGTH] ;
|
||||
const char * filename = "vorbis_test.oga" ;
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
float max_abs = 0.0 ;
|
||||
unsigned k ;
|
||||
|
||||
get_unique_test_name (&filename, CMP_TEST_PREFIX) ;
|
||||
|
||||
print_test_name ("vorbis_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (float_data, ARRAY_LEN (float_data), 1.0) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
|
||||
/* The Vorbis encoder has a bug on PowerPC and X86-64 with sample rates
|
||||
** <= 22050. Increasing the sample rate to 32000 avoids triggering it.
|
||||
** See https://trac.xiph.org/ticket/1229
|
||||
*/
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ const char * errstr ;
|
||||
|
||||
errstr = sf_strerror (NULL) ;
|
||||
if (strstr (errstr, "Sample rate chosen is known to trigger a Vorbis") == NULL)
|
||||
{ printf ("Line %d: sf_open (SFM_WRITE) failed : %s\n", __LINE__, errstr) ;
|
||||
dump_log_buffer (NULL) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("\n Sample rate -> 32kHz ") ;
|
||||
sfinfo.samplerate = 32000 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
} ;
|
||||
|
||||
test_write_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (float_data, 0, sizeof (float_data)) ;
|
||||
|
||||
/* Read the file back in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, float_data, ARRAY_LEN (float_data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (float_data) ; k ++)
|
||||
max_abs = max_float (max_abs, fabsf (float_data [k])) ;
|
||||
|
||||
exit_if_true (max_abs > 1.023,
|
||||
"\n\nLine %d : max_abs %f should be < 1.023.\n\n", __LINE__, max_abs) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
} /* vorbis_test */
|
||||
|
||||
static void
|
||||
compression_size_test (int format, const char * filename)
|
||||
{ /*
|
||||
** Encode two files, one at quality 0.3 and one at quality 0.5 and then
|
||||
** make sure that the quality 0.3 files is the smaller of the two.
|
||||
*/
|
||||
char q3_fname [64] ;
|
||||
char q6_fname [64] ;
|
||||
char test_name [64] ;
|
||||
|
||||
SNDFILE *q3_file, *q6_file ;
|
||||
SF_INFO sfinfo ;
|
||||
int q3_size, q6_size ;
|
||||
double quality ;
|
||||
int k ;
|
||||
|
||||
get_unique_test_name (&filename, CMP_TEST_PREFIX) ;
|
||||
|
||||
snprintf (q3_fname, sizeof (q3_fname), "q3_%s", filename) ;
|
||||
snprintf (q6_fname, sizeof (q6_fname), "q6_%s", filename) ;
|
||||
|
||||
snprintf (test_name, sizeof (test_name), "q[36]_%s", filename) ;
|
||||
print_test_name (__func__, test_name) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
q3_file = test_open_file_or_die (q3_fname, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
q6_file = test_open_file_or_die (q6_fname, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
quality = 0.3 ;
|
||||
sf_command (q3_file, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (quality)) ;
|
||||
quality = 0.6 ;
|
||||
sf_command (q6_file, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (quality)) ;
|
||||
|
||||
for (k = 0 ; k < 5 ; k++)
|
||||
{ gen_lowpass_signal_float (data_out, ARRAY_LEN (data_out)) ;
|
||||
test_write_float_or_die (q3_file, 0, data_out, ARRAY_LEN (data_out), __LINE__) ;
|
||||
test_write_float_or_die (q6_file, 0, data_out, ARRAY_LEN (data_out), __LINE__) ;
|
||||
} ;
|
||||
|
||||
sf_close (q3_file) ;
|
||||
sf_close (q6_file) ;
|
||||
|
||||
q3_size = (int) file_length (q3_fname) ;
|
||||
q6_size = (int) file_length (q6_fname) ;
|
||||
|
||||
exit_if_true (q3_size >= q6_size,
|
||||
"\n\nLine %d : q3 size (%d) >= q6 size (%d)\n\n", __LINE__, q3_size, q6_size) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (q3_fname) ;
|
||||
unlink (q6_fname) ;
|
||||
} /* compression_size_test */
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int all_tests = 0, tests = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf (
|
||||
"Usage : %s <test>\n"
|
||||
" Where <test> is one of:\n"
|
||||
" vorbis - test Ogg/Vorbis\n"
|
||||
" flac - test FLAC\n"
|
||||
" opus - test Opus\n"
|
||||
" mpeg - test mpeg\n"
|
||||
" all - perform all tests\n",
|
||||
argv [0]) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
if (strcmp (argv [1], "all") == 0)
|
||||
all_tests = 1 ;
|
||||
|
||||
if (all_tests || strcmp (argv [1], "vorbis") == 0)
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ vorbis_test () ;
|
||||
compression_size_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS, "vorbis.oga") ;
|
||||
tests ++ ;
|
||||
}
|
||||
else
|
||||
puts (" No Ogg Vorbis tests because support was not compiled in.") ;
|
||||
} ;
|
||||
|
||||
if (all_tests || strcmp (argv [1], "flac") == 0)
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ compression_size_test (SF_FORMAT_FLAC | SF_FORMAT_PCM_16, "pcm16.flac") ;
|
||||
tests ++ ;
|
||||
}
|
||||
else
|
||||
puts (" No FLAC tests because support was not compiled in.") ;
|
||||
} ;
|
||||
|
||||
if (all_tests || strcmp (argv [1], "opus") == 0)
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ compression_size_test (SF_FORMAT_OGG | SF_FORMAT_OPUS, "opus.opus") ;
|
||||
tests ++ ;
|
||||
}
|
||||
else
|
||||
puts (" No Opus tests because support was not compiled in.") ;
|
||||
} ;
|
||||
|
||||
if (all_tests || strcmp (argv [1], "mpeg") == 0)
|
||||
{ if (HAVE_MPEG)
|
||||
{ compression_size_test (SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, "mpeg.mp3") ;
|
||||
tests ++ ;
|
||||
}
|
||||
else
|
||||
puts (" No MPEG tests because support was not compiled in.") ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
315
Engine/lib/libsndfile/tests/cpp_test.cc
Normal file
315
Engine/lib/libsndfile/tests/cpp_test.cc
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
/*
|
||||
** Copyright (C) 2006-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <sndfile.hh>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static short sbuffer [100] ;
|
||||
static int ibuffer [100] ;
|
||||
static float fbuffer [100] ;
|
||||
static double dbuffer [100] ;
|
||||
|
||||
static void
|
||||
ceeplusplus_wchar_test (void)
|
||||
{
|
||||
#if 0
|
||||
LPCWSTR filename = L"wchar_test.wav" ;
|
||||
|
||||
print_test_name (__func__, "ceeplusplus_wchar_test.wav") ;
|
||||
|
||||
/* Use this scope to make sure the created file is closed. */
|
||||
{
|
||||
SndfileHandle file (filename, SFM_WRITE, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 2, 44100) ;
|
||||
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* This should check that the file did in fact get created with a
|
||||
** wchar_t * filename.
|
||||
*/
|
||||
exit_if_true (
|
||||
GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES,
|
||||
"\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__
|
||||
) ;
|
||||
}
|
||||
|
||||
/* Use this because the file was created with CreateFileW. */
|
||||
DeleteFileW (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
#endif
|
||||
} /* ceeplusplus_wchar_test */
|
||||
|
||||
|
||||
|
||||
static void
|
||||
create_file (const char * filename, int format)
|
||||
{ SndfileHandle file ;
|
||||
|
||||
if (file.refCount () != 0)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file = SndfileHandle (filename, SFM_WRITE, format, 2, 48000) ;
|
||||
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file.setString (SF_STR_TITLE, filename) ;
|
||||
|
||||
/* Item write. */
|
||||
file.write (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
file.write (ibuffer, ARRAY_LEN (ibuffer)) ;
|
||||
file.write (fbuffer, ARRAY_LEN (fbuffer)) ;
|
||||
file.write (dbuffer, ARRAY_LEN (dbuffer)) ;
|
||||
|
||||
/* Frame write. */
|
||||
file.writef (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
|
||||
file.writef (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
|
||||
file.writef (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
|
||||
file.writef (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;
|
||||
|
||||
/* RAII takes care of the SndfileHandle. */
|
||||
} /* create_file */
|
||||
|
||||
static void
|
||||
check_title (const SndfileHandle & file, const char * filename)
|
||||
{ const char *title = NULL ;
|
||||
|
||||
title = file.getString (SF_STR_TITLE) ;
|
||||
|
||||
if (title == NULL)
|
||||
{ printf ("\n\n%s %d : Error : No title for %s.\n\n", __func__, __LINE__, filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (strcmp (filename, title) != 0)
|
||||
{ printf ("\n\n%s %d : Error : title '%s' should be '%s'\n\n", __func__, __LINE__, title, filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* check_title */
|
||||
|
||||
static void
|
||||
read_file (const char * filename, int format)
|
||||
{ SndfileHandle file ;
|
||||
sf_count_t count ;
|
||||
|
||||
if (file)
|
||||
{ printf ("\n\n%s %d : Error : should not be here.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file = SndfileHandle (filename) ;
|
||||
|
||||
if (1)
|
||||
{ SndfileHandle file2 = file ;
|
||||
|
||||
if (file.refCount () != 2 || file2.refCount () != 2)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be two.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be one.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (! file)
|
||||
{ printf ("\n\n%s %d : Error : should not be here.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.format () != format)
|
||||
{ printf ("\n\n%s %d : Error : format 0x%08x should be 0x%08x.\n\n", __func__, __LINE__, file.format (), format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.channels () != 2)
|
||||
{ printf ("\n\n%s %d : Error : channels %d should be 2.\n\n", __func__, __LINE__, file.channels ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.frames () != ARRAY_LEN (sbuffer) * 4)
|
||||
{ printf ("\n\n%s %d : Error : frames %ld should be %lu.\n\n", __func__, __LINE__,
|
||||
(long) file.frames (), (long) ARRAY_LEN (sbuffer) * 4 / 2) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
switch (format & SF_FORMAT_TYPEMASK)
|
||||
{ case SF_FORMAT_AU :
|
||||
break ;
|
||||
|
||||
default :
|
||||
check_title (file, filename) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
/* Item read. */
|
||||
file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
file.read (ibuffer, ARRAY_LEN (ibuffer)) ;
|
||||
file.read (fbuffer, ARRAY_LEN (fbuffer)) ;
|
||||
file.read (dbuffer, ARRAY_LEN (dbuffer)) ;
|
||||
|
||||
/* Frame read. */
|
||||
file.readf (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
|
||||
file.readf (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
|
||||
file.readf (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
|
||||
file.readf (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;
|
||||
|
||||
count = file.seek (file.frames () - 10, SEEK_SET) ;
|
||||
if (count != file.frames () - 10)
|
||||
{ printf ("\n\n%s %d : Error : offset (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
(long) count, (long) (file.frames () - 10)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
count = file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
if (count != 10 * file.channels ())
|
||||
{ printf ("\n\n%s %d : Error : count (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
(long) count, (long) (10 * file.channels ())) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* RAII takes care of the SndfileHandle. */
|
||||
} /* read_file */
|
||||
|
||||
static void
|
||||
ceeplusplus_test (const char *filename, int format)
|
||||
{
|
||||
print_test_name ("ceeplusplus_test", filename) ;
|
||||
|
||||
create_file (filename, format) ;
|
||||
read_file (filename, format) ;
|
||||
|
||||
remove (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* ceeplusplus_test */
|
||||
|
||||
static void
|
||||
ceeplusplus_extra_test (void)
|
||||
{ SndfileHandle file ;
|
||||
const char * filename = "bad_file_name.wav" ;
|
||||
int error ;
|
||||
|
||||
print_test_name ("ceeplusplus_extra_test", filename) ;
|
||||
|
||||
file = SndfileHandle (filename) ;
|
||||
|
||||
error = file.error () ;
|
||||
if (error == 0)
|
||||
{ printf ("\n\n%s %d : error should not be zero.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.strError () == NULL)
|
||||
{ printf ("\n\n%s %d : strError should not return NULL.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.seek (0, SEEK_SET) != 0)
|
||||
{ printf ("\n\n%s %d : bad seek ().\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* ceeplusplus_extra_test */
|
||||
|
||||
|
||||
static void
|
||||
ceeplusplus_rawhandle_test (const char *filename)
|
||||
{
|
||||
SNDFILE* handle ;
|
||||
{
|
||||
SndfileHandle file (filename) ;
|
||||
handle = file.rawHandle () ;
|
||||
sf_read_float (handle, fbuffer, ARRAY_LEN (fbuffer)) ;
|
||||
}
|
||||
} /* ceeplusplus_rawhandle_test */
|
||||
|
||||
static void
|
||||
ceeplusplus_takeOwnership_test (const char *filename)
|
||||
{
|
||||
SNDFILE* handle ;
|
||||
{
|
||||
SndfileHandle file (filename) ;
|
||||
handle = file.takeOwnership () ;
|
||||
}
|
||||
|
||||
if (sf_read_float (handle, fbuffer, ARRAY_LEN (fbuffer)) <= 0)
|
||||
{ printf ("\n\n%s %d : error when taking ownership of handle.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if (sf_close (handle) != 0)
|
||||
{ printf ("\n\n%s %d : cannot close file.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
SndfileHandle file (filename) ;
|
||||
SndfileHandle file2 (file) ;
|
||||
|
||||
if (file2.takeOwnership ())
|
||||
{ printf ("\n\n%s %d : taking ownership of shared handle is not allowed.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
}
|
||||
} /* ceeplusplus_takeOwnership_test */
|
||||
|
||||
static void
|
||||
ceeplusplus_handle_test (const char *filename, int format)
|
||||
{
|
||||
print_test_name ("ceeplusplus_handle_test", filename) ;
|
||||
|
||||
create_file (filename, format) ;
|
||||
|
||||
if (0) ceeplusplus_rawhandle_test (filename) ;
|
||||
ceeplusplus_takeOwnership_test (filename) ;
|
||||
|
||||
remove (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* ceeplusplus_test */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ceeplusplus_test ("cpp_test.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
ceeplusplus_test ("cpp_test.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_S8) ;
|
||||
ceeplusplus_test ("cpp_test.au", SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
|
||||
ceeplusplus_extra_test () ;
|
||||
ceeplusplus_handle_test ("cpp_test.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
|
||||
ceeplusplus_wchar_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
135
Engine/lib/libsndfile/tests/cue_test.c
Normal file
135
Engine/lib/libsndfile/tests/cue_test.c
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
|
||||
static void *
|
||||
get_cues (const char *filename, double *sr)
|
||||
{
|
||||
SNDFILE *file;
|
||||
SF_INFO sfinfo;
|
||||
|
||||
unsigned int err, size;
|
||||
uint32_t count = 0;
|
||||
SF_CUES_VAR(0) *info;
|
||||
|
||||
if ((file = sf_open(filename, SFM_READ, &sfinfo)) == NULL)
|
||||
{
|
||||
printf("can't open file '%s'\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("\n---- get cues of file '%s'\n", filename);
|
||||
|
||||
if ((err = sf_command(file, SFC_GET_CUE_COUNT, &count, sizeof(uint32_t))) == SF_FALSE)
|
||||
{
|
||||
if (sf_error(file))
|
||||
{
|
||||
printf("can't get cue info size for file '%s' (arg size %lu), err %s\n",
|
||||
filename, sizeof(uint32_t), sf_strerror(file));
|
||||
exit(2);
|
||||
}
|
||||
else
|
||||
printf("no cue info for file '%s'\n", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = sizeof(*info) + count * sizeof(SF_CUE_POINT);
|
||||
printf("number of cues %d size %d\n", count, size);
|
||||
|
||||
if (!(info = malloc(size)))
|
||||
return NULL;
|
||||
|
||||
if (sf_command(file, SFC_GET_CUE, info, size) == SF_FALSE)
|
||||
{
|
||||
printf("can't get cue info of size %d for file '%s' error %s\n",
|
||||
size, filename, sf_strerror(file));
|
||||
exit(3);
|
||||
}
|
||||
|
||||
*sr = sfinfo.samplerate;
|
||||
sf_close(file);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_cues (const char *filename)
|
||||
{
|
||||
unsigned int i;
|
||||
double sr;
|
||||
SF_CUES_VAR(0) *info = get_cues(filename, &sr);
|
||||
|
||||
if (info == NULL)
|
||||
exit(1);
|
||||
|
||||
for (i = 0; i < info->cue_count; i++)
|
||||
{
|
||||
int pos = info->cue_points[i].position;
|
||||
double t = (double) pos / sr;
|
||||
double expected = i < 8 ? (double) i / 3. : 10. / 3.;
|
||||
double error = (double) fabs(t - expected);
|
||||
|
||||
printf("cue %02d: markerID %02d position %6d offset %6d (time %.3f expected %.3f diff %f) label '%s'\n",
|
||||
i, info->cue_points[i].indx, pos, info->cue_points[i].sample_offset, t, expected, error, info->cue_points[i].name);
|
||||
|
||||
if (error > 0.025)
|
||||
exit(4);
|
||||
}
|
||||
|
||||
free(info);
|
||||
}
|
||||
|
||||
static void
|
||||
print_cues (const char *filename)
|
||||
{
|
||||
unsigned int i;
|
||||
double sr;
|
||||
SF_CUES_VAR(0) *info = get_cues(filename, &sr);
|
||||
|
||||
if (info == NULL)
|
||||
exit(1);
|
||||
|
||||
for (i = 0; i < info->cue_count; i++)
|
||||
{
|
||||
int pos = info->cue_points[i].position;
|
||||
int indx = info->cue_points[i].indx;
|
||||
int cstart = info->cue_points[i].chunk_start;
|
||||
int bstart = info->cue_points[i].block_start;
|
||||
int offset = info->cue_points[i].sample_offset;
|
||||
const char *name = info->cue_points[i].name;
|
||||
double t = (double) pos / sr;
|
||||
|
||||
if (cstart != 0 || bstart != 0)
|
||||
printf("cue %02d time %7.3f: markerID %02d position %8d chunk_start %d block_start %d offset %8d label '%s'\n",
|
||||
i, t, indx, pos, offset, cstart, bstart, name);
|
||||
else
|
||||
printf("cue %02d time %7.3f: markerID %02d position %8d offset %8d label '%s'\n",
|
||||
i, t, indx, pos, offset, name);
|
||||
}
|
||||
|
||||
free(info);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc > 1)
|
||||
for (i = 1; i < argc; i++)
|
||||
print_cues(argv[i]);
|
||||
else
|
||||
{
|
||||
test_cues("clickpluck24.wav");
|
||||
test_cues("clickpluck.wav");
|
||||
test_cues("clickpluck.aiff");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
151
Engine/lib/libsndfile/tests/dft_cmp.c
Normal file
151
Engine/lib/libsndfile/tests/dft_cmp.c
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2015 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "dft_cmp.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
#define DFT_SPEC_LENGTH (DFT_DATA_LENGTH / 2)
|
||||
|
||||
static void dft_magnitude (const double *data, double *spectrum) ;
|
||||
static double calc_max_spectral_difference (const double *spec1, const double *spec2) ;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
** Public functions.
|
||||
*/
|
||||
|
||||
double
|
||||
dft_cmp_float (int linenum, const float *in_data, const float *test_data, int len, double target_snr, int allow_exit)
|
||||
{ static double orig [DFT_DATA_LENGTH] ;
|
||||
static double test [DFT_DATA_LENGTH] ;
|
||||
unsigned k ;
|
||||
|
||||
if (len != DFT_DATA_LENGTH)
|
||||
{ printf ("Error (line %d) : dft_cmp_float : Bad input array length.\n", linenum) ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (orig) ; k++)
|
||||
{ test [k] = test_data [k] ;
|
||||
orig [k] = in_data [k] ;
|
||||
} ;
|
||||
|
||||
return dft_cmp_double (linenum, orig, test, len, target_snr, allow_exit) ;
|
||||
} /* dft_cmp_float */
|
||||
|
||||
double
|
||||
dft_cmp_double (int linenum, const double *orig, const double *test, int len, double target_snr, int allow_exit)
|
||||
{ static double orig_spec [DFT_SPEC_LENGTH] ;
|
||||
static double test_spec [DFT_SPEC_LENGTH] ;
|
||||
double snr ;
|
||||
|
||||
if (! orig || ! test)
|
||||
{ printf ("Error (line %d) : dft_cmp_double : Bad input arrays.\n", linenum) ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
if (len != DFT_DATA_LENGTH)
|
||||
{ printf ("Error (line %d) : dft_cmp_double : Bad input array length.\n", linenum) ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
dft_magnitude (orig, orig_spec) ;
|
||||
dft_magnitude (test, test_spec) ;
|
||||
|
||||
snr = calc_max_spectral_difference (orig_spec, test_spec) ;
|
||||
|
||||
if (snr > target_snr)
|
||||
{ printf ("\n\nLine %d: Actual SNR (% 4.1f) > target SNR (% 4.1f).\n\n", linenum, snr, target_snr) ;
|
||||
oct_save_double (orig, test, len) ;
|
||||
if (allow_exit)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (snr < -500.0)
|
||||
snr = -500.0 ;
|
||||
|
||||
return snr ;
|
||||
} /* dft_cmp_double */
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
** Quick dirty calculation of magnitude spectrum for real valued data using
|
||||
** Discrete Fourier Transform. Since the data is real, the DFT is only
|
||||
** calculated for positive frequencies.
|
||||
*/
|
||||
|
||||
static void
|
||||
dft_magnitude (const double *data, double *spectrum)
|
||||
{ static double cos_angle [DFT_DATA_LENGTH] = { 0.0 } ;
|
||||
static double sin_angle [DFT_DATA_LENGTH] ;
|
||||
|
||||
double real_part, imag_part ;
|
||||
int k, n ;
|
||||
|
||||
/* If sine and cosine tables haven't been initialised, do so. */
|
||||
if (cos_angle [0] == 0.0)
|
||||
for (n = 0 ; n < DFT_DATA_LENGTH ; n++)
|
||||
{ cos_angle [n] = cos (2.0 * M_PI * n / DFT_DATA_LENGTH) ;
|
||||
sin_angle [n] = -1.0 * sin (2.0 * M_PI * n / DFT_DATA_LENGTH) ;
|
||||
} ;
|
||||
|
||||
/* DFT proper. Since the data is real, only generate a half spectrum. */
|
||||
for (k = 1 ; k < DFT_SPEC_LENGTH ; k++)
|
||||
{ real_part = 0.0 ;
|
||||
imag_part = 0.0 ;
|
||||
|
||||
for (n = 0 ; n < DFT_DATA_LENGTH ; n++)
|
||||
{ real_part += data [n] * cos_angle [(k * n) % DFT_DATA_LENGTH] ;
|
||||
imag_part += data [n] * sin_angle [(k * n) % DFT_DATA_LENGTH] ;
|
||||
} ;
|
||||
|
||||
spectrum [k] = sqrt (real_part * real_part + imag_part * imag_part) ;
|
||||
} ;
|
||||
|
||||
spectrum [DFT_SPEC_LENGTH - 1] = 0.0 ;
|
||||
|
||||
spectrum [0] = spectrum [1] = spectrum [2] = 0.0 ;
|
||||
|
||||
return ;
|
||||
} /* dft_magnitude */
|
||||
|
||||
static double
|
||||
calc_max_spectral_difference (const double *orig, const double *test)
|
||||
{ double orig_max = 0.0, max_diff = 0.0 ;
|
||||
int k ;
|
||||
|
||||
for (k = 0 ; k < DFT_SPEC_LENGTH ; k++)
|
||||
{ if (orig_max < orig [k])
|
||||
orig_max = orig [k] ;
|
||||
if (max_diff < fabs (orig [k] - test [k]))
|
||||
max_diff = fabs (orig [k] - test [k]) ;
|
||||
} ;
|
||||
|
||||
if (max_diff < 1e-25)
|
||||
return -500.0 ;
|
||||
|
||||
return 20.0 * log10 (max_diff / orig_max) ;
|
||||
} /* calc_max_spectral_difference */
|
||||
25
Engine/lib/libsndfile/tests/dft_cmp.h
Normal file
25
Engine/lib/libsndfile/tests/dft_cmp.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2015 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#define DFT_DATA_LENGTH (8192)
|
||||
|
||||
double dft_cmp_float (int linenum, const float *orig, const float *test, int len, double tolerance, int allow_exit) ;
|
||||
|
||||
double dft_cmp_double (int linenum, const double *orig, const double *test, int len, double tolerance, int allow_exit) ;
|
||||
|
||||
184
Engine/lib/libsndfile/tests/dither_test.c
Normal file
184
Engine/lib/libsndfile/tests/dither_test.c
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2013 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "sfconfig.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 16)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void dither_test (const char *filename, int filetype) ;
|
||||
|
||||
/* Force the start of this buffer to be double aligned. Sparc-solaris will
|
||||
** choke if its not.
|
||||
*/
|
||||
static short data_out [BUFFER_LEN] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test WAV file peak chunk\n") ;
|
||||
printf (" aiff - test AIFF file PEAK chunk\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ dither_test ("dither.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ dither_test ("dither.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ dither_test ("dither.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "svx"))
|
||||
{ dither_test ("dither.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "nist"))
|
||||
{ dither_test ("dither.nist", SF_FORMAT_NIST | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "paf"))
|
||||
{ dither_test ("dither.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ircam"))
|
||||
{ dither_test ("dither.ircam", SF_FORMAT_IRCAM | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "voc"))
|
||||
{ dither_test ("dither.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ dither_test ("dither.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat4"))
|
||||
{ dither_test ("dither.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat5"))
|
||||
{ dither_test ("dither.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "pvf"))
|
||||
{ dither_test ("dither.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_S8) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
dither_test (const char *filename, int filetype)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_DITHER_INFO dither ;
|
||||
|
||||
print_test_name ("dither_test", filename) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Check for old version of the dither API. */
|
||||
if (sf_command (file, SFC_SET_DITHER_ON_WRITE, NULL, SF_TRUE) == 0)
|
||||
{ printf ("\n\nLine %d: Should have an error here but don't.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
memset (&dither, 0, sizeof (dither)) ;
|
||||
dither.type = SFD_WHITE ;
|
||||
dither.level = 0 ;
|
||||
|
||||
if (sf_command (file, SFC_SET_DITHER_ON_WRITE, &dither, sizeof (dither)) != 0)
|
||||
{ printf ("\n\nLine %d: sf_command (SFC_SET_DITHER_ON_WRITE) returned error : %s\n\n",
|
||||
__LINE__, sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d: Bad frame count %d (should be %d)\n\n", __LINE__, (int) sfinfo.frames, BUFFER_LEN) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
/*-unlink (filename) ;-*/
|
||||
|
||||
puts ("ok") ;
|
||||
} /* dither_test */
|
||||
|
||||
111
Engine/lib/libsndfile/tests/dwvw_test.c
Normal file
111
Engine/lib/libsndfile/tests/dwvw_test.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2014 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (10000)
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
static void dwvw_test (const char *filename, int format, int bit_width) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
dwvw_test ("dwvw12.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_12, 12) ;
|
||||
dwvw_test ("dwvw16.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_16, 16) ;
|
||||
dwvw_test ("dwvw24.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_24, 24) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
dwvw_test (const char *filename, int format, int bit_width)
|
||||
{ static int write_buf [BUFFER_SIZE] ;
|
||||
static int read_buf [BUFFER_SIZE] ;
|
||||
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
double value ;
|
||||
int k, bit_mask ;
|
||||
|
||||
srand (123456) ;
|
||||
|
||||
/* Only want to grab the top bit_width bits. */
|
||||
bit_mask = arith_shift_left (-1, 32 - bit_width) ;
|
||||
|
||||
print_test_name ("dwvw_test", filename) ;
|
||||
|
||||
sf_info_setup (&sfinfo, format, 44100, 1) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Generate random.frames. */
|
||||
for (k = 0 ; k < BUFFER_SIZE / 2 ; k++)
|
||||
{ value = 0x7FFFFFFF * sin (123.0 / sfinfo.samplerate * 2 * k * M_PI) ;
|
||||
write_buf [k] = bit_mask & lrint (value) ;
|
||||
} ;
|
||||
|
||||
for ( ; k < BUFFER_SIZE ; k++)
|
||||
write_buf [k] = bit_mask & (arith_shift_left (rand (), 11) ^ (rand () >> 11)) ;
|
||||
|
||||
sf_write_int (file, write_buf, BUFFER_SIZE) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if ((k = (int) sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE)
|
||||
{ printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
{ if (read_buf [k] != write_buf [k])
|
||||
{ printf ("Error (line %d) : %d != %d at position %d/%d\n", __LINE__,
|
||||
write_buf [k] >> (32 - bit_width), read_buf [k] >> (32 - bit_width),
|
||||
k, BUFFER_SIZE) ;
|
||||
oct_save_int (write_buf, read_buf, BUFFER_SIZE) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
printf ("ok\n") ;
|
||||
|
||||
return ;
|
||||
} /* dwvw_test */
|
||||
|
||||
314
Engine/lib/libsndfile/tests/error_test.c
Normal file
314
Engine/lib/libsndfile/tests/error_test.c
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2018 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (1 << 15)
|
||||
#define SHORT_BUFFER (256)
|
||||
|
||||
static void
|
||||
error_number_test (void)
|
||||
{ const char *noerror, *errstr ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("error_number_test", "") ;
|
||||
|
||||
noerror = sf_error_number (0) ;
|
||||
|
||||
for (k = 1 ; k < 300 ; k++)
|
||||
{ errstr = sf_error_number (k) ;
|
||||
|
||||
/* Test for termination condition. */
|
||||
if (errstr == noerror)
|
||||
break ;
|
||||
|
||||
/* Test for error. */
|
||||
if (strstr (errstr, "This is a bug in libsndfile."))
|
||||
{ printf ("\n\nError : error number %d : %s\n\n\n", k, errstr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* error_number_test */
|
||||
|
||||
static void
|
||||
error_value_test (void)
|
||||
{ static unsigned char aiff_data [0x1b0] =
|
||||
{ 'F' , 'O' , 'R' , 'M' ,
|
||||
0x00, 0x00, 0x01, 0xA8, /* FORM length */
|
||||
|
||||
'A' , 'I' , 'F' , 'C' ,
|
||||
} ;
|
||||
|
||||
const char *filename = "error.aiff" ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int error_num ;
|
||||
|
||||
print_test_name ("error_value_test", filename) ;
|
||||
|
||||
dump_data_to_file (filename, aiff_data, sizeof (aiff_data)) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
if (file != NULL)
|
||||
{ printf ("\n\nLine %d : Should not have been able to open this file.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error_num = sf_error (NULL)) <= 1 || error_num > 300)
|
||||
{ printf ("\n\nLine %d : Should not have had an error number of %d.\n\n", __LINE__, error_num) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
remove (filename) ;
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* error_value_test */
|
||||
|
||||
static void
|
||||
no_file_test (const char * filename)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
exit_if_true (sndfile != NULL, "\n\nLine %d : should not have received a valid SNDFILE* pointer.\n", __LINE__) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* no_file_test */
|
||||
|
||||
static void
|
||||
zero_length_test (const char *filename)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
FILE *file ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
/* Create a zero length file. */
|
||||
file = fopen (filename, "w") ;
|
||||
exit_if_true (file == NULL, "\n\nLine %d : fopen ('%s') failed.\n", __LINE__, filename) ;
|
||||
fclose (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
exit_if_true (sndfile != NULL, "\n\nLine %d : should not have received a valid SNDFILE* pointer.\n", __LINE__) ;
|
||||
|
||||
exit_if_true (0 && sf_error (NULL) != SF_ERR_UNRECOGNISED_FORMAT,
|
||||
"\n\nLine %3d : Error : %s\n should be : %s\n", __LINE__,
|
||||
sf_strerror (NULL), sf_error_number (SF_ERR_UNRECOGNISED_FORMAT)) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* zero_length_test */
|
||||
|
||||
static void
|
||||
bad_wav_test (const char * filename)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
FILE *file ;
|
||||
const char data [] = "RIFF WAVEfmt " ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
if ((file = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d : fopen returned NULL.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
exit_if_true (fwrite (data, sizeof (data), 1, file) != 1, "\n\nLine %d : fwrite failed.\n", __LINE__) ;
|
||||
fclose (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
if (sndfile)
|
||||
{ printf ("\n\nLine %d : should not have received a valid SNDFILE* pointer.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* bad_wav_test */
|
||||
|
||||
static void
|
||||
wav_list_recover_test (const char * filename)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
FILE *file ;
|
||||
const char data [] =
|
||||
"RIFF" "J\000\000\000"
|
||||
"WAVE" "fmt " "\020\000\000\000" "\001\000\001\000D\254\000\000\210X\001\000\002\000\020\000"
|
||||
"LIST" "\014\000\000\000" "test" "\010\000\000\000" "1234" /* test is 4 bytes short inside LIST container */
|
||||
"data" "\004\000\000\000" "abcd" ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
if ((file = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d : fopen returned NULL.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
exit_if_true (fwrite (data, sizeof (data) - 1, 1, file) != 1, "\n\nLine %d : fwrite failed.\n", __LINE__) ;
|
||||
fclose (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
if (!sndfile)
|
||||
{ printf ("\n\nLine %d : expected recovery from bogus LIST content.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != 2)
|
||||
{ printf ("\n\nLine %d : Should have read data chunk with 2 stereo frames, got %ld.\n\n", __LINE__, (long)sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* wav_list_recover_test */
|
||||
|
||||
static void
|
||||
error_close_test (void)
|
||||
{ static short buffer [SHORT_BUFFER] ;
|
||||
const char *filename = "error_close.wav" ;
|
||||
SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
FILE *file ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
/* Open a FILE* from which we will extract a file descriptor. */
|
||||
if ((file = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d : fopen returned NULL.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Set parameters for writing the file. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
||||
|
||||
sndfile = sf_open_fd (fileno (file), SFM_WRITE, &sfinfo, SF_TRUE) ;
|
||||
if (sndfile == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open_fd failed : %s\n", __LINE__, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_write_short_or_die (sndfile, 0, buffer, ARRAY_LEN (buffer), __LINE__) ;
|
||||
|
||||
/* Now close the fd associated with file before calling sf_close. */
|
||||
fclose (file) ;
|
||||
|
||||
if (sf_close (sndfile) == 0)
|
||||
{
|
||||
printf ("\n\nLine %d : sf_close should not have returned zero.\n", __LINE__) ;
|
||||
#if OS_IS_WIN32
|
||||
printf ("\nHowever, this is a known bug on windows platform so we'll ignore it.\n\n") ;
|
||||
#else
|
||||
exit (1) ;
|
||||
#endif
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* error_close_test */
|
||||
|
||||
static void
|
||||
unrecognised_test (void)
|
||||
{ const char *filename = "unrecognised.bin" ;
|
||||
SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
FILE *file ;
|
||||
int k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
file = fopen (filename, "wb") ;
|
||||
exit_if_true (file == NULL,
|
||||
"\n\nLine %d : fopen ('%s') failed : %s\n", __LINE__, filename, strerror (errno)
|
||||
) ;
|
||||
fputs ("Unrecognised file", file) ;
|
||||
fclose (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
|
||||
|
||||
exit_if_true (sndfile != NULL,
|
||||
"\n\nLine %d : SNDFILE* pointer (%p) should be NULL.\n", __LINE__, (void *) sndfile
|
||||
) ;
|
||||
|
||||
k = sf_error (sndfile) ;
|
||||
exit_if_true (k != SF_ERR_UNRECOGNISED_FORMAT,
|
||||
"\n\nLine %d : error (%d) should have been SF_ERR_UNRECOGNISED_FORMAT (%d).\n",
|
||||
__LINE__, k, SF_ERR_UNRECOGNISED_FORMAT
|
||||
) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* unrecognised_test */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
error_number_test () ;
|
||||
error_value_test () ;
|
||||
|
||||
error_close_test () ;
|
||||
|
||||
no_file_test ("no_file.wav") ;
|
||||
zero_length_test ("zero_length.wav") ;
|
||||
bad_wav_test ("bad_wav.wav") ;
|
||||
wav_list_recover_test ("list_recover.wav") ;
|
||||
|
||||
unrecognised_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
204
Engine/lib/libsndfile/tests/external_libs_test.c
Normal file
204
Engine/lib/libsndfile/tests/external_libs_test.c
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2017 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
|
||||
** the Free Software Foundation ; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program ; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static void major_format_test (void) ;
|
||||
static void subtype_format_test (void) ;
|
||||
static void simple_format_test (void) ;
|
||||
static void flac_subset_test (void) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
major_format_test () ;
|
||||
subtype_format_test () ;
|
||||
simple_format_test () ;
|
||||
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
flac_subset_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
major_format_test (void)
|
||||
{ SF_FORMAT_INFO info ;
|
||||
int have_ogg = 0, have_flac = 0 ;
|
||||
int m, major_count ;
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
|
||||
|
||||
for (m = 0 ; m < major_count ; m++)
|
||||
{ info.format = m ;
|
||||
sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
|
||||
|
||||
have_flac = info.format == SF_FORMAT_FLAC ? 1 : have_flac ;
|
||||
have_ogg = info.format == SF_FORMAT_OGG ? 1 : have_ogg ;
|
||||
} ;
|
||||
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
|
||||
}
|
||||
else
|
||||
{ exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* major_format_test */
|
||||
|
||||
static void
|
||||
subtype_format_test (void)
|
||||
{ SF_FORMAT_INFO info ;
|
||||
int have_vorbis = 0 , have_opus = 0 ;
|
||||
int s, subtype_count ;
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
|
||||
|
||||
for (s = 0 ; s < subtype_count ; s++)
|
||||
{ info.format = s ;
|
||||
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ;
|
||||
|
||||
have_vorbis = info.format == SF_FORMAT_VORBIS ? 1 : have_vorbis ;
|
||||
have_opus = info.format == SF_FORMAT_OPUS ? 1 : have_opus ;
|
||||
} ;
|
||||
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_opus == 0, "\n\nLine %d : Ogg/Opus should be available.\n\n", __LINE__) ;
|
||||
}
|
||||
else
|
||||
{ exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_opus, "\n\nLine %d : Ogg/Opus should not be available.\n\n", __LINE__) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* subtype_format_test */
|
||||
|
||||
static void
|
||||
simple_format_test (void)
|
||||
{ SF_FORMAT_INFO info ;
|
||||
int have_flac = 0, have_ogg = 0, have_vorbis = 0, have_opus = 0 ;
|
||||
int s, simple_count ;
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
sf_command (NULL, SFC_GET_SIMPLE_FORMAT_COUNT, &simple_count, sizeof (int)) ;
|
||||
|
||||
for (s = 0 ; s < simple_count ; s++)
|
||||
{ info.format = s ;
|
||||
sf_command (NULL, SFC_GET_SIMPLE_FORMAT, &info, sizeof (info)) ;
|
||||
|
||||
switch (info.format & SF_FORMAT_TYPEMASK)
|
||||
{ case SF_FORMAT_FLAC :
|
||||
have_flac = 1 ;
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_OGG :
|
||||
have_ogg = 1 ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
switch (info.format & SF_FORMAT_SUBMASK)
|
||||
{ case SF_FORMAT_VORBIS :
|
||||
have_vorbis = 1 ;
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_OPUS :
|
||||
have_opus = 1 ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
} ;
|
||||
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ exit_if_true (have_flac == 0, "\n\nLine %d : FLAC should be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_ogg == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_vorbis == 0, "\n\nLine %d : Ogg/Vorbis should be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_opus == 0, "\n\nLine %d : Ogg/Opus should be available.\n\n", __LINE__) ;
|
||||
}
|
||||
else
|
||||
{ exit_if_true (have_flac, "\n\nLine %d : FLAC should not be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_ogg, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_vorbis, "\n\nLine %d : Ogg/Vorbis should not be available.\n\n", __LINE__) ;
|
||||
exit_if_true (have_opus, "\n\nLine %d : Ogg/Opus should not be available.\n\n", __LINE__) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* simple_format_test */
|
||||
|
||||
static void
|
||||
flac_subset_test (void)
|
||||
{ float whatever [256] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t rc ;
|
||||
int samplerate ;
|
||||
const char *filename = "subset_test.flac" ;
|
||||
|
||||
/* For some formats (like FLAC) the headers are written *just* before the
|
||||
** first bit of audio data. This test makes sure errors in that process
|
||||
** are caught.
|
||||
*/
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
for (samplerate = 65536 ; samplerate < 655350 ; samplerate *= 4)
|
||||
{ sfinfo.samplerate = samplerate ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = SF_FORMAT_FLAC | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
rc = sf_write_float (file, whatever, ARRAY_LEN (whatever)) ;
|
||||
unlink (filename) ;
|
||||
exit_if_true (rc != 0, "\n\nLine %d : return code (%d) should be 0.\n\n", __LINE__, (int) rc) ;
|
||||
|
||||
sf_close (file) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* flac_subset_test */
|
||||
|
||||
334
Engine/lib/libsndfile/tests/fix_this.c
Normal file
334
Engine/lib/libsndfile/tests/fix_this.c
Normal file
|
|
@ -0,0 +1,334 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2014 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (1 << 14)
|
||||
#define SAMPLE_RATE (11025)
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
static void lcomp_test_int (const char *str, const char *filename, int filetype, double margin) ;
|
||||
|
||||
static int error_function (double data, double orig, double margin) ;
|
||||
static int decay_response (int k) ;
|
||||
|
||||
static void gen_signal_double (double *data, double scale, int datalen) ;
|
||||
|
||||
/* Force the start of these buffers to be double aligned. Sparc-solaris will
|
||||
** choke if they are not.
|
||||
*/
|
||||
|
||||
typedef union
|
||||
{ double d [BUFFER_SIZE + 1] ;
|
||||
int i [BUFFER_SIZE + 1] ;
|
||||
} BUFFER ;
|
||||
|
||||
static BUFFER data_buffer ;
|
||||
static BUFFER orig_buffer ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ const char *filename = "test.au" ;
|
||||
|
||||
lcomp_test_int ("au_g721", filename, SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_G721_32, 0.06) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
lcomp_test_int (const char *str, const char *filename, int filetype, double margin)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, m, *orig, *data ;
|
||||
sf_count_t datalen, seekpos ;
|
||||
int64_t sum_abs ;
|
||||
double scale ;
|
||||
|
||||
printf ("\nThis is program is not part of the libsndfile test suite.\n\n") ;
|
||||
|
||||
printf (" lcomp_test_int : %s ... ", str) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
datalen = BUFFER_SIZE ;
|
||||
|
||||
scale = 1.0 * 0x10000 ;
|
||||
|
||||
data = data_buffer.i ;
|
||||
orig = orig_buffer.i ;
|
||||
|
||||
gen_signal_double (orig_buffer.d, 32000.0 * scale, datalen) ;
|
||||
for (k = 0 ; k < datalen ; k++)
|
||||
orig [k] = orig_buffer.d [k] ;
|
||||
|
||||
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = 123456789 ; /* Ridiculous value. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k = sf_writef_int (file, orig, datalen)) != datalen)
|
||||
{ printf ("sf_writef_int failed with short write (%" PRId64 " => %d).\n", datalen, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (data, 0, datalen * sizeof (int)) ;
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
||||
{ printf ("sf_open_read failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)) != (filetype & (SF_FORMAT_TYPEMASK | SF_FORMAT_SUBMASK)))
|
||||
{ printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames < datalen)
|
||||
{ printf ("Too few.frames in file. (%" PRId64 " should be a little more than %" PRId64 ")\n", datalen, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames > (datalen + datalen / 2))
|
||||
{ printf ("Too many.frames in file. (%" PRId64 " should be a little more than %" PRId64 ")\n", datalen, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("Incorrect number of channels in file.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if ((k = sf_readf_int (file, data, datalen)) != datalen)
|
||||
{ printf ("Line %d: short read (%d should be %" PRId64 ").\n", __LINE__, k, datalen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sum_abs = 0 ;
|
||||
for (k = 0 ; k < datalen ; k++)
|
||||
{ if (error_function (data [k] / scale, orig [k] / scale, margin))
|
||||
{ printf ("Line %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ;
|
||||
oct_save_int (orig, data, datalen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
sum_abs += abs (data [k]) ;
|
||||
} ;
|
||||
|
||||
if (sum_abs < 1.0)
|
||||
{ printf ("Line %d: Signal is all zeros.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
|
||||
{ printf ("Line %d: Incorrect read length (%" PRId64 " should be %d).\n", __LINE__, sfinfo.frames - datalen, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* This check is only for block based encoders which must append silence
|
||||
** to the end of a file so as to fill out a block.
|
||||
*/
|
||||
if ((sfinfo.format & SF_FORMAT_SUBMASK) != SF_FORMAT_MS_ADPCM)
|
||||
for (k = 0 ; k < sfinfo.frames - datalen ; k++)
|
||||
if (ABS (data [k] / scale) > decay_response (k))
|
||||
{ printf ("Line %d : Incorrect sample B (#%d : abs (%d) should be < %d).\n", __LINE__, k, data [k], decay_response (k)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (! sfinfo.seekable)
|
||||
{ printf ("ok\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
/* Now test sf_seek function. */
|
||||
|
||||
if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
|
||||
{ printf ("Line %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (m = 0 ; m < 3 ; m++)
|
||||
{ int n ;
|
||||
|
||||
if ((k = sf_readf_int (file, data, 11)) != 11)
|
||||
{ printf ("Line %d: Incorrect read length (11 => %d).\n", __LINE__, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < 11 ; k++)
|
||||
if (error_function (data [k] / scale, orig [k + m * 11] / scale, margin))
|
||||
{ printf ("Line %d: Incorrect sample (m = %d) (#%d : %d => %d).\n", __LINE__, m, k + m * 11, orig [k + m * 11], data [k]) ;
|
||||
for (n = 0 ; n < 1 ; n++)
|
||||
printf ("%d ", data [n]) ;
|
||||
printf ("\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
seekpos = BUFFER_SIZE / 10 ;
|
||||
|
||||
/* Check seek from start of file. */
|
||||
if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
|
||||
{ printf ("Seek to start of file + %" PRId64 " failed (%d).\n", seekpos, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k = sf_readf_int (file, data, 1)) != 1)
|
||||
{ printf ("Line %d: sf_readf_int (file, data, 1) returned %d.\n", __LINE__, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (error_function ((double) data [0], (double) orig [seekpos], margin))
|
||||
{ printf ("Line %d: sf_seek (SEEK_SET) followed by sf_readf_int failed (%d, %d).\n", __LINE__, orig [1], data [0]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
|
||||
{ printf ("Line %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %" PRId64 ")\n", __LINE__, k, seekpos + 1) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
|
||||
k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
|
||||
sf_readf_int (file, data, 1) ;
|
||||
if (error_function ((double) data [0], (double) orig [seekpos], margin) || k != seekpos)
|
||||
{ printf ("Line %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %" PRId64 ").\n", __LINE__, data [0], orig [seekpos], k, seekpos + 1) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
|
||||
/* Check seek backward from current position. */
|
||||
k = sf_seek (file, -20, SEEK_CUR) ;
|
||||
sf_readf_int (file, data, 1) ;
|
||||
if (error_function ((double) data [0], (double) orig [seekpos], margin) || k != seekpos)
|
||||
{ printf ("sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %" PRId64 ").\n", data [0], orig [seekpos], k, seekpos) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check that read past end of file returns number of items. */
|
||||
sf_seek (file, (int) sfinfo.frames, SEEK_SET) ;
|
||||
|
||||
if ((k = sf_readf_int (file, data, datalen)) != 0)
|
||||
{ printf ("Line %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check seek backward from end. */
|
||||
if ((k = sf_seek (file, 5 - (int) sfinfo.frames, SEEK_END)) != 5)
|
||||
{ printf ("sf_seek (SEEK_END) returned %d instead of %d.\n", k, 5) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_readf_int (file, data, 1) ;
|
||||
if (error_function (data [0] / scale, orig [5] / scale, margin))
|
||||
{ printf ("Line %d: sf_seek (SEEK_END) followed by sf_readf_short failed (%d should be %d).\n", __LINE__, data [0], orig [5]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
} /* lcomp_test_int */
|
||||
|
||||
/*========================================================================================
|
||||
** Auxiliary functions
|
||||
*/
|
||||
|
||||
#define SIGNAL_MAXVAL 30000.0
|
||||
#define DECAY_COUNT 800
|
||||
|
||||
static int
|
||||
decay_response (int k)
|
||||
{ if (k < 1)
|
||||
return (int) (1.2 * SIGNAL_MAXVAL) ;
|
||||
if (k > DECAY_COUNT)
|
||||
return 0 ;
|
||||
return (int) (1.2 * SIGNAL_MAXVAL * (DECAY_COUNT - k) / (1.0 * DECAY_COUNT)) ;
|
||||
} /* decay_response */
|
||||
|
||||
static void
|
||||
gen_signal_double (double *data, double scale, int datalen)
|
||||
{ int k, ramplen ;
|
||||
double amp = 0.0 ;
|
||||
|
||||
ramplen = datalen / 18 ;
|
||||
|
||||
for (k = 0 ; k < datalen ; k++)
|
||||
{ if (k <= ramplen)
|
||||
amp = scale * k / ((double) ramplen) ;
|
||||
else if (k > datalen - ramplen)
|
||||
amp = scale * (datalen - k) / ((double) ramplen) ;
|
||||
|
||||
data [k] = amp * (0.4 * sin (33.3 * 2.0 * M_PI * ((double) (k + 1)) / ((double) SAMPLE_RATE))
|
||||
+ 0.3 * cos (201.1 * 2.0 * M_PI * ((double) (k + 1)) / ((double) SAMPLE_RATE))) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* gen_signal_double */
|
||||
|
||||
static int
|
||||
error_function (double data, double orig, double margin)
|
||||
{ double error ;
|
||||
|
||||
if (fabs (orig) <= 500.0)
|
||||
error = fabs (fabs (data) - fabs (orig)) / 2000.0 ;
|
||||
else if (fabs (orig) <= 1000.0)
|
||||
error = fabs (data - orig) / 3000.0 ;
|
||||
else
|
||||
error = fabs (data - orig) / fabs (orig) ;
|
||||
|
||||
if (error > margin)
|
||||
{ printf ("\n\n*******************\nError : %f\n", error) ;
|
||||
return 1 ;
|
||||
} ;
|
||||
return 0 ;
|
||||
} /* error_function */
|
||||
|
||||
32
Engine/lib/libsndfile/tests/floating_point_test.def
Normal file
32
Engine/lib/libsndfile/tests/floating_point_test.def
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
autogen definitions floating_point_test.tpl;
|
||||
|
||||
endian_type = {
|
||||
end_name = little ;
|
||||
end_type = SF_ENDIAN_LITTLE ;
|
||||
} ;
|
||||
|
||||
endian_type = {
|
||||
end_name = big ;
|
||||
end_type = SF_ENDIAN_BIG ;
|
||||
} ;
|
||||
|
||||
float_type = {
|
||||
float_name = float ;
|
||||
minor_type = SF_FORMAT_FLOAT ;
|
||||
} ;
|
||||
|
||||
float_type = {
|
||||
float_name = double ;
|
||||
minor_type = SF_FORMAT_DOUBLE ;
|
||||
} ;
|
||||
|
||||
int_type = {
|
||||
int_name = short ;
|
||||
int_max = "0x7FFF" ;
|
||||
} ;
|
||||
|
||||
int_type = {
|
||||
int_name = int ;
|
||||
int_max = "0x7FFFFFFF" ;
|
||||
} ;
|
||||
|
||||
380
Engine/lib/libsndfile/tests/floating_point_test.tpl
Normal file
380
Engine/lib/libsndfile/tests/floating_point_test.tpl
Normal file
|
|
@ -0,0 +1,380 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 1999-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "dft_cmp.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define SAMPLE_RATE 16000
|
||||
|
||||
static const char FPT_TEST_PREFIX[] = "fpt" ;
|
||||
|
||||
static void float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
|
||||
static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
|
||||
|
||||
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
|
||||
+]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float) ;
|
||||
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
|
||||
+]
|
||||
|
||||
static double double_data [DFT_DATA_LENGTH] ;
|
||||
static double double_test [DFT_DATA_LENGTH] ;
|
||||
|
||||
static float float_data [DFT_DATA_LENGTH] ;
|
||||
static float float_test [DFT_DATA_LENGTH] ;
|
||||
|
||||
static double double_data [DFT_DATA_LENGTH] ;
|
||||
static short short_data [DFT_DATA_LENGTH] ;
|
||||
static int int_data [DFT_DATA_LENGTH] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int allow_exit = 1 ;
|
||||
|
||||
if (argc == 2 && ! strstr (argv [1], "no-exit"))
|
||||
allow_exit = 0 ;
|
||||
|
||||
#if (HAVE_LRINTF == 0)
|
||||
puts ("*** Cannot run this test on this platform because it lacks lrintf().") ;
|
||||
exit (0) ;
|
||||
#endif
|
||||
|
||||
/* Float tests. */
|
||||
float_scaled_test ("float.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT,
|
||||
OS_IS_OPENBSD ? -98.0 : -163.0) ;
|
||||
|
||||
/* Test both signed and unsigned 8 bit files. */
|
||||
float_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
|
||||
float_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
|
||||
|
||||
float_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
|
||||
float_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, -138.0) ;
|
||||
float_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, -163.0) ;
|
||||
|
||||
float_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
|
||||
float_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
|
||||
|
||||
float_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
|
||||
float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
||||
float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
||||
|
||||
float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
|
||||
float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
|
||||
float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
||||
|
||||
/* PAF files do not use the same encoding method for 24 bit PCM data as other file
|
||||
** formats so we need to explicitly test it here.
|
||||
*/
|
||||
float_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
|
||||
float_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -149.0) ;
|
||||
|
||||
float_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
|
||||
float_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
|
||||
float_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
|
||||
|
||||
float_scaled_test ("adpcm.vox", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
|
||||
|
||||
float_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
|
||||
float_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
|
||||
|
||||
float_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
|
||||
float_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
|
||||
float_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -170.0) ;
|
||||
|
||||
float_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
|
||||
float_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -76.0) ;
|
||||
float_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
|
||||
float_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
|
||||
|
||||
#if HAVE_EXTERNAL_XIPH_LIBS
|
||||
float_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
|
||||
float_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
|
||||
float_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
|
||||
|
||||
float_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -31.0) ;
|
||||
|
||||
float_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
|
||||
#endif
|
||||
|
||||
#if HAVE_MPEG
|
||||
float_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
|
||||
#endif
|
||||
|
||||
float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
|
||||
|
||||
/*==============================================================================
|
||||
** Double tests.
|
||||
*/
|
||||
|
||||
double_scaled_test ("double.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
|
||||
|
||||
/* Test both signed (AIFF) and unsigned (WAV) 8 bit files. */
|
||||
double_scaled_test ("pcm_s8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_S8, -39.0) ;
|
||||
double_scaled_test ("pcm_u8.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_U8, -39.0) ;
|
||||
|
||||
double_scaled_test ("pcm_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_16, -87.0) ;
|
||||
double_scaled_test ("pcm_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_24, -135.0) ;
|
||||
double_scaled_test ("pcm_32.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_PCM_32, -184.0) ;
|
||||
|
||||
double_scaled_test ("ulaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ULAW, -50.0) ;
|
||||
double_scaled_test ("alaw.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_ALAW, -49.0) ;
|
||||
|
||||
double_scaled_test ("ima_adpcm.wav", allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM, -47.0) ;
|
||||
double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
||||
double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
||||
|
||||
double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
|
||||
double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
|
||||
double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
||||
|
||||
/* 24 bit PCM PAF files tested here. */
|
||||
double_scaled_test ("be_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
|
||||
double_scaled_test ("le_paf_24.paf", allow_exit, SF_FALSE, SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, -151.0) ;
|
||||
|
||||
double_scaled_test ("dwvw_12.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_12, -64.0) ;
|
||||
double_scaled_test ("dwvw_16.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_16, -92.0) ;
|
||||
double_scaled_test ("dwvw_24.raw", allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_DWVW_24, -151.0) ;
|
||||
|
||||
double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
|
||||
|
||||
double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
|
||||
double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
|
||||
|
||||
double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -89.0) ;
|
||||
double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -132.0) ;
|
||||
double_scaled_test ("pcm_24.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_24, -180.0) ;
|
||||
|
||||
double_scaled_test ("alac_16.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_16, -90.0) ;
|
||||
double_scaled_test ("alac_20.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_20, -125.0) ;
|
||||
double_scaled_test ("alac_24.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_24, -153.0) ;
|
||||
double_scaled_test ("alac_32.caf", allow_exit, SF_FALSE, SF_FORMAT_CAF | SF_FORMAT_ALAC_32, -186.0) ;
|
||||
|
||||
#if HAVE_EXTERNAL_XIPH_LIBS
|
||||
double_scaled_test ("flac_8.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, -39.0) ;
|
||||
double_scaled_test ("flac_16.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_16, -87.0) ;
|
||||
double_scaled_test ("flac_24.flac", allow_exit, SF_FALSE, SF_FORMAT_FLAC | SF_FORMAT_PCM_24, -138.0) ;
|
||||
|
||||
double_scaled_test ("vorbis.oga", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_VORBIS, -29.0) ;
|
||||
double_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
|
||||
#endif
|
||||
|
||||
#if HAVE_MPEG
|
||||
double_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
|
||||
#endif
|
||||
|
||||
double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
|
||||
|
||||
putchar ('\n') ;
|
||||
/* Float int tests. */
|
||||
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +]
|
||||
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au", SF_FALSE) ;
|
||||
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_replace.au", SF_TRUE) ;
|
||||
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
* Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
double snr ;
|
||||
int byterate ;
|
||||
|
||||
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
|
||||
print_test_name ("float_scaled_test", filename) ;
|
||||
|
||||
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = DFT_DATA_LENGTH ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
|
||||
test_write_float_or_die (file, 0, float_data, DFT_DATA_LENGTH, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (float_test, 0, sizeof (float_test)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_float_or_die (file, 0, float_test, DFT_DATA_LENGTH, __LINE__) ;
|
||||
|
||||
byterate = sf_current_byterate (file) ;
|
||||
exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
snr = dft_cmp_float (__LINE__, float_data, float_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
|
||||
|
||||
exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
|
||||
|
||||
printf ("% 6.1fdB SNR ... ok\n", snr) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* float_scaled_test */
|
||||
|
||||
static void
|
||||
double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
double snr ;
|
||||
int byterate ;
|
||||
|
||||
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
|
||||
print_test_name ("double_scaled_test", filename) ;
|
||||
|
||||
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = DFT_DATA_LENGTH ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
|
||||
test_write_double_or_die (file, 0, double_data, DFT_DATA_LENGTH, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (double_test, 0, sizeof (double_test)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < DFT_DATA_LENGTH, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, double_test, DFT_DATA_LENGTH, __LINE__) ;
|
||||
|
||||
byterate = sf_current_byterate (file) ;
|
||||
exit_if_true (byterate <= 0, "\n\nLine %d: byterate is zero.\n", __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
snr = dft_cmp_double (__LINE__, double_data, double_test, DFT_DATA_LENGTH, target_snr, allow_exit) ;
|
||||
|
||||
exit_if_true (snr > target_snr, "% 6.1fdB SNR\n\n Error : should be better than % 6.1fdB\n\n", snr, target_snr) ;
|
||||
|
||||
printf ("% 6.1fdB SNR ... ok\n", snr) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* double_scaled_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
|
||||
+]
|
||||
static void
|
||||
[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int max ;
|
||||
unsigned k ;
|
||||
|
||||
get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
|
||||
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
|
||||
|
||||
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = [+ (get "end_type") +] | SF_FORMAT_AU | [+ (get "minor_type") +] ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
test_write_[+ (get "float_name") +]_or_die (file, 0, [+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
|
||||
if (sfinfo.frames != ARRAY_LEN ([+ (get "float_name") +]_data))
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_command (file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
|
||||
|
||||
test_read_[+ (get "int_name") +]_or_die (file, 0, [+ (get "int_name") +]_data, ARRAY_LEN ([+ (get "int_name") +]_data), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
max = 0 ;
|
||||
for (k = 0 ; k < ARRAY_LEN ([+ (get "int_name") +]_data) ; k++)
|
||||
if (abs ([+ (get "int_name") +]_data [k]) > max)
|
||||
max = abs ([+ (get "int_name") +]_data [k]) ;
|
||||
|
||||
if (1.0 * abs (max - [+ (get "int_max") +]) / [+ (get "int_max") +] > 0.01)
|
||||
{ printf ("\n\nLine %d: Bad maximum (%d should be %d).\n\n", __LINE__, max, [+ (get "int_max") +]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test */
|
||||
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
|
||||
|
||||
166
Engine/lib/libsndfile/tests/format_check_test.c
Normal file
166
Engine/lib/libsndfile/tests/format_check_test.c
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
** Copyright (C) 2011-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include "sndfile.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void format_error_test (void) ;
|
||||
static void format_combo_test (void) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
format_error_test () ;
|
||||
format_combo_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
format_error_test (void)
|
||||
{ const char *filename = "format-error.wav" ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO info ;
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
memset (&info, 0, sizeof (info)) ;
|
||||
info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
||||
info.channels = 1 ;
|
||||
info.samplerate = 44100 ;
|
||||
|
||||
info.format = SF_FORMAT_WAV ;
|
||||
file = sf_open (filename, SFM_WRITE, &info) ;
|
||||
exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ;
|
||||
exit_if_true (
|
||||
strstr (sf_strerror (NULL), "minor format") == NULL,
|
||||
"\n\nLine %d : Error string should reference bad 'minor format'.\n\n", __LINE__
|
||||
) ;
|
||||
|
||||
info.format = SF_FORMAT_PCM_16 ;
|
||||
file = sf_open (filename, SFM_WRITE, &info) ;
|
||||
exit_if_true (file != NULL, "\n\nLine %d : Format should not be valid.\n\n", __LINE__) ;
|
||||
exit_if_true (
|
||||
strstr (sf_strerror (NULL), "major format") == NULL,
|
||||
"\n\nLine %d : Error string should reference bad 'major format'.\n\n", __LINE__
|
||||
) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* format_error_test */
|
||||
|
||||
static void
|
||||
format_combo_test (void)
|
||||
{ int container_max, codec_max, cont, codec ;
|
||||
|
||||
print_test_name (__func__, NULL) ;
|
||||
|
||||
sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &container_max, sizeof (container_max)) ;
|
||||
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &codec_max, sizeof (codec_max)) ;
|
||||
|
||||
for (cont = 0 ; cont < container_max + 10 ; cont ++)
|
||||
{ SF_FORMAT_INFO major_fmt_info ;
|
||||
|
||||
memset (&major_fmt_info, 0, sizeof (major_fmt_info)) ;
|
||||
major_fmt_info.format = cont ;
|
||||
(void) sf_command (NULL, SFC_GET_FORMAT_MAJOR, &major_fmt_info, sizeof (major_fmt_info)) ;
|
||||
|
||||
for (codec = 0 ; codec < codec_max + 10 ; codec ++)
|
||||
{ SF_FORMAT_INFO subtype_fmt_info ;
|
||||
SNDFILE * sndfile ;
|
||||
SF_INFO info ;
|
||||
char filename [128] ;
|
||||
int subtype_is_valid, check_is_valid ;
|
||||
|
||||
memset (&info, 0, sizeof (info)) ;
|
||||
memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ;
|
||||
subtype_fmt_info.format = codec ;
|
||||
subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ;
|
||||
|
||||
/* Opus only works with a fixed set of sample rates. */
|
||||
if (subtype_fmt_info.format == SF_FORMAT_OPUS)
|
||||
sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 24000, 1) ;
|
||||
else
|
||||
sf_info_setup (&info, major_fmt_info.format | subtype_fmt_info.format, 22050, 1) ;
|
||||
|
||||
check_is_valid = sf_format_check (&info) ;
|
||||
|
||||
exit_if_true (
|
||||
NOT (subtype_is_valid) && check_is_valid,
|
||||
"\n\nLine %d : Subtype is not valid but checks ok.\n",
|
||||
__LINE__
|
||||
) ;
|
||||
|
||||
/* Only have decode, not encode support for MPEG Layer I and II */
|
||||
if (subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_I ||
|
||||
subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_II)
|
||||
continue ;
|
||||
|
||||
/* MPEG Layer III in WAV is decode only currently */
|
||||
if (subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_III &&
|
||||
major_fmt_info.format == SF_FORMAT_WAV)
|
||||
continue ;
|
||||
|
||||
snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ;
|
||||
|
||||
sndfile = sf_open (filename, SFM_WRITE, &info) ;
|
||||
|
||||
sf_close (sndfile) ;
|
||||
unlink (filename) ;
|
||||
|
||||
if (major_fmt_info.extension != NULL && strcmp (major_fmt_info.extension, "sd2") == 0)
|
||||
{ snprintf (filename, sizeof (filename), "._format-check.%s", major_fmt_info.extension) ;
|
||||
unlink (filename) ;
|
||||
} ;
|
||||
|
||||
exit_if_true (
|
||||
sndfile && NOT (check_is_valid),
|
||||
"\n\nError : Format was not valid but file opened correctly.\n"
|
||||
" Container : %s\n"
|
||||
" Codec : %s\n\n",
|
||||
major_fmt_info.name, subtype_fmt_info.name
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
NOT (sndfile) && check_is_valid,
|
||||
"\n\nError : Format was valid but file failed to open.\n"
|
||||
" Container : %s\n"
|
||||
" Codec : %s\n\n",
|
||||
major_fmt_info.name, subtype_fmt_info.name
|
||||
) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* format_combo_test */
|
||||
|
||||
75
Engine/lib/libsndfile/tests/generate.c
Normal file
75
Engine/lib/libsndfile/tests/generate.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "generate.h"
|
||||
|
||||
#define SF_MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
static float crappy_snare (float *output, int len, int offset, float gain, float maxabs) ;
|
||||
|
||||
void
|
||||
generate_file (const char * filename, int format, int len)
|
||||
{ float * output ;
|
||||
float maxabs = 0.0 ;
|
||||
|
||||
output = calloc (len, sizeof (float)) ;
|
||||
|
||||
maxabs = crappy_snare (output, len, 0, 0.95f, maxabs) ;
|
||||
maxabs = crappy_snare (output, len, len / 4, 0.85f, maxabs) ;
|
||||
maxabs = crappy_snare (output, len, 2 * len / 4, 0.85f, maxabs) ;
|
||||
crappy_snare (output, len, 3 * len / 4, 0.85f, maxabs) ;
|
||||
|
||||
write_mono_file (filename, format, 44100, output, len) ;
|
||||
|
||||
free (output) ;
|
||||
} /* generate_file */
|
||||
|
||||
static inline float
|
||||
rand_float (void)
|
||||
{ return rand () / (0.5f * (float) RAND_MAX) - 1.0f ;
|
||||
} /* rand_float */
|
||||
|
||||
static float
|
||||
crappy_snare (float *output, int len, int offset, float gain, float maxabs)
|
||||
{ int k ;
|
||||
float env = 0.0f ;
|
||||
|
||||
for (k = offset ; k < len && env < gain ; k++)
|
||||
{ env += 0.03f ;
|
||||
output [k] += env * rand_float () ;
|
||||
maxabs = SF_MAX (maxabs, fabsf (output [k])) ;
|
||||
} ;
|
||||
|
||||
for ( ; k < len && env > 1e-8 ; k++)
|
||||
{ env *= 0.995f ;
|
||||
output [k] += env * rand_float () ;
|
||||
maxabs = SF_MAX (maxabs, fabsf (output [k])) ;
|
||||
} ;
|
||||
|
||||
return maxabs ;
|
||||
} /* crappy_snare */
|
||||
19
Engine/lib/libsndfile/tests/generate.h
Normal file
19
Engine/lib/libsndfile/tests/generate.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
void generate_file (const char * filename, int format, int len) ;
|
||||
22
Engine/lib/libsndfile/tests/header_test.def
Normal file
22
Engine/lib/libsndfile/tests/header_test.def
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
autogen definitions header_test.tpl;
|
||||
|
||||
data_type = {
|
||||
name = "short" ;
|
||||
format = "SF_FORMAT_PCM_16" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "int" ;
|
||||
format = "SF_FORMAT_PCM_32" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "float" ;
|
||||
format = "SF_FORMAT_FLOAT" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "double" ;
|
||||
format = "SF_FORMAT_DOUBLE" ;
|
||||
} ;
|
||||
|
||||
583
Engine/lib/libsndfile/tests/header_test.tpl
Normal file
583
Engine/lib/libsndfile/tests/header_test.tpl
Normal file
|
|
@ -0,0 +1,583 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 2001-2017 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
|
||||
** the Free Software Foundation ; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program ; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#if (defined (WIN32) || defined (_WIN32))
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void update_header_test (const char *filename, int typemajor) ;
|
||||
static void update_header_before_write_test (const char *filename, int typemajor) ;
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) ;
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
static void extra_header_test (const char *filename, int filetype) ;
|
||||
|
||||
static void header_shrink_test (const char *filename, int filetype) ;
|
||||
|
||||
/* Force the start of this buffer to be double aligned. Sparc-solaris will
|
||||
** choke if its not.
|
||||
*/
|
||||
static int data_out [BUFFER_LEN] ;
|
||||
static int data_in [BUFFER_LEN] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test WAV file peak chunk\n") ;
|
||||
printf (" aiff - test AIFF file PEAK chunk\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all= !strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ update_header_test ("header.wav", SF_FORMAT_WAV) ;
|
||||
update_seek_short_test ("header_short.wav", SF_FORMAT_WAV) ;
|
||||
update_seek_int_test ("header_int.wav", SF_FORMAT_WAV) ;
|
||||
update_seek_float_test ("header_float.wav", SF_FORMAT_WAV) ;
|
||||
update_seek_double_test ("header_double.wav", SF_FORMAT_WAV) ;
|
||||
header_shrink_test ("header_shrink.wav", SF_FORMAT_WAV) ;
|
||||
extra_header_test ("extra.wav", SF_FORMAT_WAV) ;
|
||||
|
||||
update_header_test ("header.wavex", SF_FORMAT_WAVEX) ;
|
||||
update_seek_short_test ("header_short.wavex", SF_FORMAT_WAVEX) ;
|
||||
update_seek_int_test ("header_int.wavex", SF_FORMAT_WAVEX) ;
|
||||
update_seek_float_test ("header_float.wavex", SF_FORMAT_WAVEX) ;
|
||||
update_seek_double_test ("header_double.wavex", SF_FORMAT_WAVEX) ;
|
||||
header_shrink_test ("header_shrink.wavex", SF_FORMAT_WAVEX) ;
|
||||
extra_header_test ("extra.wavex", SF_FORMAT_WAVEX) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ update_header_test ("header.aiff", SF_FORMAT_AIFF) ;
|
||||
update_seek_short_test ("header_short.aiff", SF_FORMAT_AIFF) ;
|
||||
update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ;
|
||||
update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ;
|
||||
update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ;
|
||||
header_shrink_test ("header_shrink.aiff", SF_FORMAT_AIFF) ;
|
||||
extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ update_header_test ("header.au", SF_FORMAT_AU) ;
|
||||
update_seek_short_test ("header_short.au", SF_FORMAT_AU) ;
|
||||
update_seek_int_test ("header_int.au", SF_FORMAT_AU) ;
|
||||
update_seek_float_test ("header_float.au", SF_FORMAT_AU) ;
|
||||
update_seek_double_test ("header_double.au", SF_FORMAT_AU) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "caf"))
|
||||
{ update_header_test ("header.caf", SF_FORMAT_CAF) ;
|
||||
update_seek_short_test ("header_short.caf", SF_FORMAT_CAF) ;
|
||||
update_seek_int_test ("header_int.caf", SF_FORMAT_CAF) ;
|
||||
update_seek_float_test ("header_float.caf", SF_FORMAT_CAF) ;
|
||||
update_seek_double_test ("header_double.caf", SF_FORMAT_CAF) ;
|
||||
/* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "nist"))
|
||||
{ update_header_test ("header.nist", SF_FORMAT_NIST) ;
|
||||
update_seek_short_test ("header_short.nist", SF_FORMAT_NIST) ;
|
||||
update_seek_int_test ("header_int.nist", SF_FORMAT_NIST) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "paf"))
|
||||
{ update_header_test ("header.paf", SF_FORMAT_PAF) ;
|
||||
update_seek_short_test ("header_short.paf", SF_FORMAT_PAF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ircam"))
|
||||
{ update_header_test ("header.ircam", SF_FORMAT_IRCAM) ;
|
||||
update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ update_header_test ("header.w64", SF_FORMAT_W64) ;
|
||||
update_seek_short_test ("header_short.w64", SF_FORMAT_W64) ;
|
||||
update_seek_int_test ("header_int.w64", SF_FORMAT_W64) ;
|
||||
update_seek_float_test ("header_float.w64", SF_FORMAT_W64) ;
|
||||
update_seek_double_test ("header_double.w64", SF_FORMAT_W64) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "rf64"))
|
||||
{ update_header_test ("header.rf64", SF_FORMAT_RF64) ;
|
||||
update_seek_short_test ("header_short.rf64", SF_FORMAT_RF64) ;
|
||||
update_seek_int_test ("header_int.rf64", SF_FORMAT_RF64) ;
|
||||
update_seek_float_test ("header_float.rf64", SF_FORMAT_RF64) ;
|
||||
update_seek_double_test ("header_double.rf64", SF_FORMAT_RF64) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat4"))
|
||||
{ update_header_test ("header.mat4", SF_FORMAT_MAT4) ;
|
||||
update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4) ;
|
||||
update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4) ;
|
||||
update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4) ;
|
||||
update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat5"))
|
||||
{ update_header_test ("header.mat5", SF_FORMAT_MAT5) ;
|
||||
update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5) ;
|
||||
update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5) ;
|
||||
update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5) ;
|
||||
update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "pvf"))
|
||||
{ update_header_test ("header.pvf", SF_FORMAT_PVF) ;
|
||||
update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "avr"))
|
||||
{ update_header_test ("header.avr", SF_FORMAT_AVR) ;
|
||||
update_seek_short_test ("header_short.avr", SF_FORMAT_AVR) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "htk"))
|
||||
{ update_header_test ("header.htk", SF_FORMAT_HTK) ;
|
||||
update_seek_short_test ("header_short.htk", SF_FORMAT_HTK) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "svx"))
|
||||
{ update_header_test ("header.svx", SF_FORMAT_SVX) ;
|
||||
update_seek_short_test ("header_short.svx", SF_FORMAT_SVX) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "voc"))
|
||||
{ update_header_test ("header.voc", SF_FORMAT_VOC) ;
|
||||
/*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "sds"))
|
||||
{ update_header_test ("header.sds", SF_FORMAT_SDS) ;
|
||||
/*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mpc2k"))
|
||||
{ update_header_test ("header.mpc", SF_FORMAT_MPC2K) ;
|
||||
update_seek_short_test ("header_short.mpc", SF_FORMAT_MPC2K) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "flac"))
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
update_header_before_write_test ("header.flac", SF_FORMAT_FLAC) ;
|
||||
else
|
||||
puts (" No FLAC tests because FLAC support was not compiled in.") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
update_header_sub (const char *filename, int typemajor, int write_mode)
|
||||
{ SNDFILE *outfile, *infile ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
data_out [k] = k + 1 ;
|
||||
test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
if (typemajor != SF_FORMAT_HTK)
|
||||
{ /* The HTK header is not correct when the file is first written. */
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_close (infile) ;
|
||||
} ;
|
||||
|
||||
sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
|
||||
|
||||
/*
|
||||
** Open file and check log buffer for an error. If header update failed
|
||||
** the the log buffer will contain errors.
|
||||
*/
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
check_log_buffer_or_die (infile, __LINE__) ;
|
||||
|
||||
if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50)
|
||||
{ printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ;
|
||||
dump_log_buffer (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ;
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
if (data_out [k] != k + 1)
|
||||
printf ("Error : line %d\n", __LINE__) ;
|
||||
|
||||
sf_close (infile) ;
|
||||
|
||||
/* Set auto update on. */
|
||||
sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
||||
|
||||
/* Write more data_out. */
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
data_out [k] = k + 2 ;
|
||||
test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
/* Open file again and make sure no errors in log buffer. */
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
check_log_buffer_or_die (infile, __LINE__) ;
|
||||
|
||||
if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50)
|
||||
{ printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 2 * BUFFER_LEN) ;
|
||||
dump_log_buffer (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (infile) ;
|
||||
|
||||
sf_close (outfile) ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* update_header_sub */
|
||||
|
||||
static void
|
||||
update_header_test (const char *filename, int typemajor)
|
||||
{
|
||||
print_test_name ("update_header_test", filename) ;
|
||||
|
||||
update_header_sub (filename, typemajor, SFM_WRITE) ;
|
||||
update_header_sub (filename, typemajor, SFM_RDWR) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* update_header_test */
|
||||
|
||||
static void
|
||||
update_header_before_write_test (const char *filename, int typemajor)
|
||||
{
|
||||
SNDFILE *outfile ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("update_header_before_write", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* FLAC can only write the header once; if the first call to sf_write() will
|
||||
** also attempt to write the header, it fails. FLAC-specific regression
|
||||
*/
|
||||
sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
data_out [k] = k + 1 ;
|
||||
test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_close (outfile) ;
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* update_header_before_write_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void
|
||||
update_seek_[+ (get "name") +]_test (const char *filename, int filetype)
|
||||
{ SNDFILE *outfile, *infile ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
[+ (get "name") +] buffer [8] ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("update_seek_[+ (get "name") +]_test", filename) ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Create sound outfile with no data. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = filetype | [+ (get "format") +] ;
|
||||
sfinfo.samplerate = 48000 ;
|
||||
sfinfo.channels = 2 ;
|
||||
|
||||
if (sf_format_check (&sfinfo) == SF_FALSE)
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
/* Open again for read/write. */
|
||||
outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/*
|
||||
** In auto header update mode, seeking to the end of the file with
|
||||
** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
|
||||
** will seek to 0 anyway
|
||||
*/
|
||||
if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
|
||||
{ printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Now write some frames. */
|
||||
frames = ARRAY_LEN (buffer) / sfinfo.channels ;
|
||||
|
||||
for (k = 0 ; k < 6 ; k++)
|
||||
{ test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;
|
||||
test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;
|
||||
|
||||
/* Open file again and make sure no errors in log buffer. */
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
check_log_buffer_or_die (infile, __LINE__) ;
|
||||
sf_close (infile) ;
|
||||
|
||||
if (sfinfo.frames != k * frames)
|
||||
{ printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", __LINE__, sfinfo.frames, k + frames) ;
|
||||
dump_log_buffer (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k & 1) == 0)
|
||||
test_write_[+ (get "name") +]_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;
|
||||
else
|
||||
test_writef_[+ (get "name") +]_or_die (outfile, k, buffer, frames, __LINE__) ;
|
||||
} ;
|
||||
|
||||
sf_close (outfile) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* update_seek_[+ (get "name") +]_test */
|
||||
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
static void
|
||||
header_shrink_test (const char *filename, int filetype)
|
||||
{ SNDFILE *outfile, *infile ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
float buffer [8], bufferin [8] ;
|
||||
|
||||
print_test_name ("header_shrink_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = filetype | SF_FORMAT_FLOAT ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
memset (buffer, 0xA0, sizeof (buffer)) ;
|
||||
|
||||
/* Now write some frames. */
|
||||
frames = ARRAY_LEN (buffer) / sfinfo.channels ;
|
||||
|
||||
/* Test the file with extra header data. */
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
|
||||
sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, SF_FALSE) ;
|
||||
sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
|
||||
test_writef_float_or_die (outfile, 0, buffer, frames, __LINE__) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
/* Open again for read. */
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_readf_float_or_die (infile, 0, bufferin, frames, __LINE__) ;
|
||||
sf_close (infile) ;
|
||||
|
||||
compare_float_or_die (buffer, bufferin, frames, __LINE__) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* header_shrink_test */
|
||||
|
||||
|
||||
static void
|
||||
extra_header_test (const char *filename, int filetype)
|
||||
{ SNDFILE *outfile, *infile ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
short buffer [8] ;
|
||||
int k = 0 ;
|
||||
|
||||
print_test_name ("extra_header_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
memset (buffer, 0xA0, sizeof (buffer)) ;
|
||||
|
||||
/* Now write some frames. */
|
||||
frames = ARRAY_LEN (buffer) / sfinfo.channels ;
|
||||
|
||||
/* Test the file with extra header data. */
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, [+ (tpl-file-line "%2$d") +]) ;
|
||||
sf_set_string (outfile, SF_STR_TITLE, filename) ;
|
||||
test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
|
||||
sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
#if 1
|
||||
/*
|
||||
** Erik de Castro Lopo <erikd@mega-nerd.com> May 23 2004.
|
||||
**
|
||||
** This file has extra string data in the header and therefore cannot
|
||||
** currently be opened in SFM_RDWR mode. This is fixable, but its in
|
||||
** a part of the code I don't want to fiddle with until the Ogg/Vorbis
|
||||
** integration is done.
|
||||
*/
|
||||
|
||||
if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL)
|
||||
{ printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
#else
|
||||
|
||||
hexdump_file (filename, 0, 100000) ;
|
||||
|
||||
/* Open again for read/write. */
|
||||
outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
|
||||
|
||||
/*
|
||||
** In auto header update mode, seeking to the end of the file with
|
||||
** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
|
||||
** will seek to 0 anyway
|
||||
*/
|
||||
if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
|
||||
{ printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Now write some frames. */
|
||||
frames = ARRAY_LEN (buffer) / sfinfo.channels ;
|
||||
|
||||
for (k = 1 ; k < 6 ; k++)
|
||||
{
|
||||
printf ("\n*** pass %d\n", k) ;
|
||||
memset (buffer, 0xA0 + k, sizeof (buffer)) ;
|
||||
|
||||
|
||||
test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
|
||||
test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
|
||||
|
||||
/* Open file again and make sure no errors in log buffer. */
|
||||
if (0)
|
||||
{ infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
|
||||
check_log_buffer_or_die (infile, [+ (tpl-file-line "%2$d") +]) ;
|
||||
sf_close (infile) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != k * frames)
|
||||
{ printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", [+ (tpl-file-line "%2$d") +], sfinfo.frames, k + frames) ;
|
||||
dump_log_buffer (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((k & 1) == 0)
|
||||
test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, [+ (tpl-file-line "%2$d") +]) ;
|
||||
else
|
||||
test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
|
||||
hexdump_file (filename, 0, 100000) ;
|
||||
} ;
|
||||
|
||||
sf_close (outfile) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
#endif
|
||||
} /* extra_header_test */
|
||||
187
Engine/lib/libsndfile/tests/headerless_test.c
Normal file
187
Engine/lib/libsndfile/tests/headerless_test.c
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (2000)
|
||||
|
||||
static void old_test (void) ;
|
||||
static void headerless_test (const char * filename, int format, int expected) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
old_test () ;
|
||||
|
||||
headerless_test ("headerless.vox", SF_FORMAT_VOX_ADPCM, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM) ;
|
||||
headerless_test ("headerless.gsm", SF_FORMAT_GSM610, SF_FORMAT_RAW | SF_FORMAT_GSM610) ;
|
||||
|
||||
headerless_test ("headerless.snd", SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
|
||||
headerless_test ("headerless.au" , SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
headerless_test (const char * filename, int format, int expected)
|
||||
{ static short buffer [BUFFER_SIZE] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
|
||||
format &= SF_FORMAT_SUBMASK ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
buffer [k] = k ;
|
||||
|
||||
sfinfo.samplerate = 8000 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = SF_FORMAT_RAW | format ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if ((k = (int) sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
|
||||
{ printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* We should be able to detect these so clear sfinfo. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != expected)
|
||||
{ printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, expected, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames < BUFFER_SIZE)
|
||||
{ printf ("Line %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_SIZE, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
unlink (filename) ;
|
||||
} /* headerless_test */
|
||||
|
||||
static void
|
||||
old_test (void)
|
||||
{ static short buffer [BUFFER_SIZE] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, filetype ;
|
||||
const char *filename = "headerless.wav" ;
|
||||
|
||||
print_test_name (__func__, "") ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
buffer [k] = k ;
|
||||
|
||||
filetype = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
||||
|
||||
sfinfo.samplerate = 32000 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if ((k = (int) sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
|
||||
{ printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Read as RAW but get the bit width and endian-ness correct. */
|
||||
sfinfo.format = filetype = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("Line %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames < BUFFER_SIZE)
|
||||
{ printf ("Line %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_SIZE, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if ((k = (int) sf_read_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
|
||||
{ printf ("Line %d: short read (%d).\n", __LINE__, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_SIZE - 22 ; k++)
|
||||
if (buffer [k + 22] != k)
|
||||
{ printf ("Line %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, k, buffer [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
unlink (filename) ;
|
||||
} /* old_test */
|
||||
|
||||
85
Engine/lib/libsndfile/tests/largefile_test.c
Normal file
85
Engine/lib/libsndfile/tests/largefile_test.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
** Copyright (C) 2006-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1024 * 1024)
|
||||
#define BUFFER_COUNT (768)
|
||||
|
||||
static void largefile_test (int filetype, const char * filename) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
largefile_test (SF_FORMAT_WAV, "largefile.wav") ;
|
||||
largefile_test (SF_FORMAT_AIFF, "largefile.aiff") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
largefile_test (int filetype, const char * filename)
|
||||
{ static float data [BUFFER_LEN] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("largefile_test", filename) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = (filetype | SF_FORMAT_PCM_32) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_COUNT ; k++)
|
||||
test_write_float_or_die (file, k, data, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if ((sfinfo.frames * sfinfo.channels) / BUFFER_LEN != BUFFER_COUNT)
|
||||
{ printf ("\n\nLine %d : bad frame count.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
|
||||
|
||||
return ;
|
||||
} /* largefile_test */
|
||||
|
||||
168
Engine/lib/libsndfile/tests/locale_test.c
Normal file
168
Engine/lib/libsndfile/tests/locale_test.c
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
** Copyright (C) 2005-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#if OS_IS_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "sndfile.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void utf8_test (void) ;
|
||||
static void wchar_test (void) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
utf8_test () ;
|
||||
wchar_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
wchar_test (void)
|
||||
{
|
||||
#if OS_IS_WIN32
|
||||
SNDFILE * file ;
|
||||
SF_INFO info ;
|
||||
LPCWSTR filename = L"test.wav" ;
|
||||
|
||||
print_test_name (__func__, "test.wav") ;
|
||||
|
||||
info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
|
||||
info.channels = 1 ;
|
||||
info.samplerate = 44100 ;
|
||||
|
||||
file = sf_wchar_open (filename, SFM_WRITE, &info) ;
|
||||
exit_if_true (file == NULL, "\n\nLine %d : sf_wchar_open failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* This should check that the file did in fact get created with a
|
||||
** wchar_t * filename.
|
||||
*/
|
||||
exit_if_true (
|
||||
GetFileAttributesW (filename) == INVALID_FILE_ATTRIBUTES,
|
||||
"\n\nLine %d : GetFileAttributes failed.\n\n", __LINE__
|
||||
) ;
|
||||
|
||||
/* Use this because the file was created with CreateFileW. */
|
||||
DeleteFileW (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
#endif
|
||||
} /* wchar_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ const char *locale ;
|
||||
int utf8 ;
|
||||
const char *filename ;
|
||||
int width ;
|
||||
} LOCALE_DATA ;
|
||||
|
||||
static void locale_test (const LOCALE_DATA * locdata) ;
|
||||
|
||||
static void
|
||||
utf8_test (void)
|
||||
{ LOCALE_DATA ldata [] =
|
||||
{ { "de_DE", 1, "F\303\274\303\237e.au", 7 },
|
||||
{ "en_AU", 1, "kangaroo.au", 11 },
|
||||
{ "POSIX", 0, "posix.au", 8 },
|
||||
{ "pt_PT", 1, "concei\303\247\303\243o.au", 12 },
|
||||
|
||||
#if OS_IS_WIN32 == 0
|
||||
{ "ja_JP", 1, "\343\201\212\343\201\257\343\202\210\343\201\206\343\201\224\343\201\226\343\201\204\343\201\276\343\201\231.au", 21 },
|
||||
#endif
|
||||
|
||||
{ "vi_VN", 1, "qu\341\273\221c ng\341\273\257.au", 11 },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
} ;
|
||||
int k ;
|
||||
|
||||
for (k = 0 ; ldata [k].locale != NULL ; k++)
|
||||
locale_test (ldata + k) ;
|
||||
} /* utf8_test */
|
||||
|
||||
|
||||
static void
|
||||
locale_test (const LOCALE_DATA * ldata)
|
||||
{
|
||||
#if (HAVE_LOCALE_H == 0 || HAVE_SETLOCALE == 0)
|
||||
locname = filename = NULL ;
|
||||
width = 0 ;
|
||||
return ;
|
||||
#else
|
||||
const short wdata [] = { 1, 2, 3, 4, 5, 6, 7, 8 } ;
|
||||
short rdata [ARRAY_LEN (wdata)] ;
|
||||
const char *old_locale ;
|
||||
char utf8_locname [32] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
snprintf (utf8_locname, sizeof (utf8_locname), "%s%s", ldata->locale, ldata->utf8 ? ".UTF-8" : "") ;
|
||||
|
||||
/* Change the locale saving the old one. */
|
||||
if ((old_locale = setlocale (LC_CTYPE, utf8_locname)) == NULL)
|
||||
return ;
|
||||
|
||||
printf (" locale_test %-8s : %s %*c ", ldata->locale, ldata->filename, 24 - ldata->width, ' ') ;
|
||||
fflush (stdout) ;
|
||||
|
||||
sfinfo.format = SF_FORMAT_AU | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
|
||||
file = test_open_file_or_die (ldata->filename, SFM_WRITE, &sfinfo, 0, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, wdata, ARRAY_LEN (wdata), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (ldata->filename, SFM_READ, &sfinfo, 0, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, rdata, ARRAY_LEN (rdata), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (ldata->filename) ;
|
||||
|
||||
/* Restore old locale. */
|
||||
setlocale (LC_CTYPE, old_locale) ;
|
||||
|
||||
puts ("ok") ;
|
||||
#endif
|
||||
} /* locale_test */
|
||||
|
||||
272
Engine/lib/libsndfile/tests/long_read_write_test.c
Normal file
272
Engine/lib/libsndfile/tests/long_read_write_test.c
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
** Copyright (C) 2015-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "dft_cmp.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LENGTH 10000
|
||||
#define SAMPLE_RATE 44010
|
||||
|
||||
static void short_lrw_test (const char *filename, int filetype, const short * output, int out_len) ;
|
||||
static void int_lrw_test (const char *filename, int filetype, const int * output, int out_len) ;
|
||||
static void float_lrw_test (const char *filename, int filetype, const float * output, int out_len) ;
|
||||
static void double_lrw_test (const char *filename, int filetype, const double * output, int out_len) ;
|
||||
|
||||
|
||||
static short short_data [BUFFER_LENGTH] ;
|
||||
static int int_data [BUFFER_LENGTH] ;
|
||||
static float float_data [BUFFER_LENGTH] ;
|
||||
static double double_data [BUFFER_LENGTH] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all ;
|
||||
size_t k ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" alac - test CAF/ALAC file functions\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (short_data) ; k++)
|
||||
{ int value = k / 32 ;
|
||||
int_data [k] = (value & 1 ? -1 : 1) * value ;
|
||||
short_data [k] = int_data [k] ;
|
||||
float_data [k] = int_data [k] / 32000.0f ;
|
||||
double_data [k] = int_data [k] / 32000.0 ;
|
||||
}
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "alac") == 0)
|
||||
{ short_lrw_test ("alac.caf", SF_FORMAT_CAF | SF_FORMAT_ALAC_16, short_data, ARRAY_LEN (short_data)) ;
|
||||
int_lrw_test ("alac.caf", SF_FORMAT_CAF | SF_FORMAT_ALAC_32, int_data, ARRAY_LEN (int_data)) ;
|
||||
float_lrw_test ("alac.caf", SF_FORMAT_CAF | SF_FORMAT_ALAC_32, float_data, ARRAY_LEN (float_data)) ;
|
||||
double_lrw_test ("alac.caf", SF_FORMAT_CAF | SF_FORMAT_ALAC_32, double_data, ARRAY_LEN (double_data)) ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
* Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
short_lrw_test (const char *filename, int filetype, const short * output, int out_len)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
short input [BUFFER_LENGTH] ;
|
||||
|
||||
print_test_name ("short_lrw_test", filename) ;
|
||||
|
||||
exit_if_true (BUFFER_LENGTH > out_len, "\n\nLine %d: Bad array length.\n", __LINE__) ;
|
||||
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = out_len ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_short_or_die (file, 0, output, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < out_len, "\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_short_or_die (file, 0, input, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
exit_if_true (input [k] != output [k],
|
||||
"\n\nLine: %d: Error on input %d, expected %d, got %d\n", __LINE__, k, output [k], input [k]) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* short_lrw_test */
|
||||
|
||||
static void
|
||||
int_lrw_test (const char *filename, int filetype, const int * output, int out_len)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
int input [BUFFER_LENGTH] ;
|
||||
|
||||
print_test_name ("int_lrw_test", filename) ;
|
||||
|
||||
exit_if_true (BUFFER_LENGTH > out_len, "\n\nLine %d: Bad array length.\n", __LINE__) ;
|
||||
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = out_len ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_int_or_die (file, 0, output, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < out_len, "\n\nLine %d: Incorrect number of frames in file (too int). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_int_or_die (file, 0, input, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
exit_if_true (input [k] != output [k],
|
||||
"\n\nLine: %d: Error on input %d, expected %d, got %d\n", __LINE__, k, output [k], input [k]) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* int_lrw_test */
|
||||
|
||||
static void
|
||||
float_lrw_test (const char *filename, int filetype, const float * output, int out_len)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
float input [BUFFER_LENGTH] ;
|
||||
|
||||
print_test_name ("float_lrw_test", filename) ;
|
||||
|
||||
exit_if_true (BUFFER_LENGTH > out_len, "\n\nLine %d: Bad array length.\n", __LINE__) ;
|
||||
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = out_len ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_float_or_die (file, 0, output, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < out_len, "\n\nLine %d: Incorrect number of frames in file (too float). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_float_or_die (file, 0, input, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
exit_if_true (fabs (input [k] - output [k]) > 0.00001,
|
||||
"\n\nLine: %d: Error on input %d, expected %f, got %f\n", __LINE__, k, output [k], input [k]) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* float_lrw_test */
|
||||
|
||||
static void
|
||||
double_lrw_test (const char *filename, int filetype, const double * output, int out_len)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
double input [BUFFER_LENGTH] ;
|
||||
|
||||
print_test_name ("double_lrw_test", filename) ;
|
||||
|
||||
exit_if_true (BUFFER_LENGTH > out_len, "\n\nLine %d: Bad array length.\n", __LINE__) ;
|
||||
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
sfinfo.frames = out_len ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_double_or_die (file, 0, output, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != filetype, "\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit_if_true (sfinfo.frames < out_len, "\n\nLine %d: Incorrect number of frames in file (too double). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, input, out_len, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
exit_if_true (fabs (input [k] - output [k]) > 0.00001,
|
||||
"\n\nLine: %d: Error on input %d, expected %f, got %f\n", __LINE__, k, output [k], input [k]) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* double_lrw_test */
|
||||
|
||||
2634
Engine/lib/libsndfile/tests/lossy_comp_test.c
Normal file
2634
Engine/lib/libsndfile/tests/lossy_comp_test.c
Normal file
File diff suppressed because it is too large
Load diff
533
Engine/lib/libsndfile/tests/misc_test.c
Normal file
533
Engine/lib/libsndfile/tests/misc_test.c
Normal file
|
|
@ -0,0 +1,533 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2017 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
|
||||
** the Free Software Foundation ; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program ; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#if (defined (WIN32) || defined (_WIN32))
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void zero_data_test (const char *filename, int format) ;
|
||||
static void filesystem_full_test (int format) ;
|
||||
static void permission_test (const char *filename, int typemajor) ;
|
||||
static void wavex_amb_test (const char *filename) ;
|
||||
static void rf64_downgrade_test (const char *filename) ;
|
||||
static void rf64_long_file_downgrade_test (const char *filename) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test WAV file peak chunk\n") ;
|
||||
printf (" aiff - test AIFF file PEAK chunk\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ zero_data_test ("zerolen.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.wav", SF_FORMAT_WAV) ;
|
||||
wavex_amb_test ("ambisonic.wav") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ zero_data_test ("zerolen.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.aiff", SF_FORMAT_AIFF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ zero_data_test ("zerolen.au", SF_FORMAT_AU | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_AU | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.au", SF_FORMAT_AU) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "caf"))
|
||||
{ zero_data_test ("zerolen.caf", SF_FORMAT_CAF | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_CAF | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.caf", SF_FORMAT_CAF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "svx"))
|
||||
{ zero_data_test ("zerolen.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_SVX | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.svx", SF_FORMAT_SVX) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "nist"))
|
||||
{ zero_data_test ("zerolen.nist", SF_FORMAT_NIST | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_NIST | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.nist", SF_FORMAT_NIST) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "paf"))
|
||||
{ zero_data_test ("zerolen.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_PAF | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.paf", SF_FORMAT_PAF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ircam"))
|
||||
{ zero_data_test ("zerolen.ircam", SF_FORMAT_IRCAM | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_IRCAM | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.ircam", SF_FORMAT_IRCAM) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "voc"))
|
||||
{ zero_data_test ("zerolen.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_VOC | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.voc", SF_FORMAT_VOC) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ zero_data_test ("zerolen.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.w64", SF_FORMAT_W64) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "rf64"))
|
||||
{ zero_data_test ("zerolen.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.rf64", SF_FORMAT_RF64) ;
|
||||
rf64_downgrade_test ("downgrade.wav") ;
|
||||
/* Disable this by default, because it needs to write 4 gigabytes of data. */
|
||||
if (SF_FALSE)
|
||||
rf64_long_file_downgrade_test ("no-downgrade.rf64") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat4"))
|
||||
{ zero_data_test ("zerolen.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.mat4", SF_FORMAT_MAT4) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat5"))
|
||||
{ zero_data_test ("zerolen.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.mat5", SF_FORMAT_MAT5) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "pvf"))
|
||||
{ zero_data_test ("zerolen.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_PVF | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.pvf", SF_FORMAT_PVF) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "htk"))
|
||||
{ zero_data_test ("zerolen.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_HTK | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.htk", SF_FORMAT_HTK) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "avr"))
|
||||
{ zero_data_test ("zerolen.avr", SF_FORMAT_AVR | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_AVR | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.avr", SF_FORMAT_AVR) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "sds"))
|
||||
{ zero_data_test ("zerolen.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_SDS | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.sds", SF_FORMAT_SDS) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mpc2k"))
|
||||
{ zero_data_test ("zerolen.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16) ;
|
||||
filesystem_full_test (SF_FORMAT_MPC2K | SF_FORMAT_PCM_16) ;
|
||||
permission_test ("readonly.mpc", SF_FORMAT_MPC2K) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ogg"))
|
||||
{ zero_data_test ("zerolen.oga", SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;
|
||||
/*-filesystem_full_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;-*/
|
||||
permission_test ("readonly.oga", SF_FORMAT_OGG) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
zero_data_test (const char *filename, int format)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
switch (format & SF_FORMAT_TYPEMASK)
|
||||
{ case SF_FORMAT_OGG :
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS == 0)
|
||||
return ;
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
print_test_name ("zero_data_test", filename) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* zero_data_test */
|
||||
|
||||
static void
|
||||
filesystem_full_test (int format)
|
||||
{
|
||||
#if (defined (WIN32) || defined (_WIN32))
|
||||
(void) format ;
|
||||
/* Can't run this test on Win32 so return. */
|
||||
return ;
|
||||
#else
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
struct stat buf ;
|
||||
|
||||
const char *filename = "/dev/full", *errorstr ;
|
||||
|
||||
/* Make sure errno is zero before doing anything else. */
|
||||
errno = 0 ;
|
||||
|
||||
print_test_name ("filesystem_full_test", filename) ;
|
||||
|
||||
if (stat (filename, &buf) != 0)
|
||||
{ puts ("/dev/full missing") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (S_ISCHR (buf.st_mode) == 0 && S_ISBLK (buf.st_mode) == 0)
|
||||
{ puts ("/dev/full is not a device file") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) != NULL)
|
||||
{ printf ("\n\nLine %d : Error, file should not have openned.\n", __LINE__ - 1) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
errorstr = sf_strerror (file) ;
|
||||
|
||||
if (strstr (errorstr, " space ") == NULL || strstr (errorstr, "device") == NULL)
|
||||
{ printf ("\n\nLine %d : Error bad error string : %s.\n", __LINE__ - 1, errorstr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
#endif
|
||||
} /* filesystem_full_test */
|
||||
|
||||
static void
|
||||
permission_test (const char *filename, int typemajor)
|
||||
{
|
||||
#if (OS_IS_WIN32)
|
||||
/* Avoid compiler warnings. */
|
||||
(void) filename ;
|
||||
(void) typemajor ;
|
||||
|
||||
/* Can't run this test on Win32 so return. */
|
||||
return ;
|
||||
#else
|
||||
|
||||
FILE *textfile ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
const char *errorstr ;
|
||||
|
||||
/* Make sure errno is zero before doing anything else. */
|
||||
errno = 0 ;
|
||||
|
||||
if (getuid () == 0)
|
||||
{ /* If running as root bypass this test.
|
||||
** Root is allowed to open a readonly file for write.
|
||||
*/
|
||||
return ;
|
||||
} ;
|
||||
|
||||
print_test_name ("permission_test", filename) ;
|
||||
|
||||
if (access (filename, F_OK) == 0)
|
||||
{ chmod (filename, S_IWUSR) ;
|
||||
unlink (filename) ;
|
||||
} ;
|
||||
|
||||
if ((textfile = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d : not able to open text file for write.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
fprintf (textfile, "This is a read only file.\n") ;
|
||||
fclose (textfile) ;
|
||||
|
||||
if (chmod (filename, S_IRUSR | S_IRGRP))
|
||||
{ printf ("\n\nLine %d : chmod failed", __LINE__) ;
|
||||
fflush (stdout) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) != NULL)
|
||||
{ printf ("\n\nLine %d : Error, file should not have opened.\n", __LINE__ - 1) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
errorstr = sf_strerror (file) ;
|
||||
|
||||
if (strstr (errorstr, "ermission denied") == NULL)
|
||||
{ printf ("\n\nLine %d : Error bad error string : %s.\n", __LINE__ - 1, errorstr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (chmod (filename, S_IWUSR | S_IWGRP))
|
||||
{ printf ("\n\nLine %d : chmod failed", __LINE__) ;
|
||||
fflush (stdout) ;
|
||||
perror ("") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
#endif
|
||||
} /* permission_test */
|
||||
|
||||
static void
|
||||
wavex_amb_test (const char *filename)
|
||||
{ static short buffer [800] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = SF_FORMAT_WAVEX | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.channels = 4 ;
|
||||
|
||||
frames = ARRAY_LEN (buffer) / sfinfo.channels ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_WAVEX_SET_AMBISONIC, NULL, SF_AMBISONIC_B_FORMAT) ;
|
||||
test_writef_short_or_die (file, 0, buffer, frames, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (
|
||||
sf_command (file, SFC_WAVEX_GET_AMBISONIC, NULL, 0) != SF_AMBISONIC_B_FORMAT,
|
||||
"\n\nLine %d : Error, this file should be in Ambisonic B format.\n", __LINE__
|
||||
) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* wavex_amb_test */
|
||||
|
||||
static void
|
||||
rf64_downgrade_test (const char *filename)
|
||||
{ static short output [BUFFER_LEN] ;
|
||||
static short input [BUFFER_LEN] ;
|
||||
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
sf_info_clear (&sfinfo) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = ARRAY_LEN (output) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_FALSE, "\n\nLine %d: sf_command failed.\n", __LINE__) ;
|
||||
exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ;
|
||||
|
||||
test_write_short_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ;
|
||||
|
||||
exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ;
|
||||
exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
sf_info_clear (&sfinfo) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != (SF_FORMAT_WAVEX | SF_FORMAT_PCM_16), "\n\nLine %d: RF64 to WAV downgrade failed.\n", __LINE__) ;
|
||||
exit_if_true (sfinfo.frames != ARRAY_LEN (output), "\n\nLine %d: Incorrect number of frames in file (too short). (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (output)) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_short_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
exit_if_true (input [k] != output [k],
|
||||
"\n\nLine: %d: Error on input %d, expected %d, got %d\n", __LINE__, k, output [k], input [k]) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* rf64_downgrade_test */
|
||||
|
||||
static void
|
||||
rf64_long_file_downgrade_test (const char *filename)
|
||||
{ static int output [BUFFER_LEN] ;
|
||||
static int input [1] = { 0 } ;
|
||||
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t output_frames = 0 ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
sf_info_clear (&sfinfo) ;
|
||||
|
||||
memset (output, 0, sizeof (output)) ;
|
||||
output [0] = 0x1020304 ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = ARRAY_LEN (output) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_32 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ;
|
||||
|
||||
while (output_frames * sizeof (output [0]) < 0x100000000)
|
||||
{ test_write_int_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ;
|
||||
output_frames += ARRAY_LEN (output) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
sf_info_clear (&sfinfo) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.format != (SF_FORMAT_RF64 | SF_FORMAT_PCM_32), "\n\nLine %d: RF64 to WAV downgrade should have failed.\n", __LINE__) ;
|
||||
exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit_if_true (sfinfo.frames != output_frames, "\n\nLine %d: Incorrect number of frames in file (%d should be %d).\n", __LINE__, (int) sfinfo.frames, (int) output_frames) ;
|
||||
|
||||
/* Check that the first sample read is the same as the first written. */
|
||||
test_read_int_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ;
|
||||
exit_if_true (input [0] != output [0], "\n\nLine %d: Bad first sample (0x%08x).\n", __LINE__, input [0]) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* rf64_long_file_downgrade_test */
|
||||
348
Engine/lib/libsndfile/tests/mpeg_test.c
Normal file
348
Engine/lib/libsndfile/tests/mpeg_test.c
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2019 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2019 John ffitch <jpff@codemist.co.uk>
|
||||
**
|
||||
** 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SAMPLE_RATE 44100
|
||||
#define DATA_LENGTH (SAMPLE_RATE / 8)
|
||||
|
||||
typedef union
|
||||
{ double d [DATA_LENGTH] ;
|
||||
float f [DATA_LENGTH] ;
|
||||
int i [DATA_LENGTH] ;
|
||||
short s [DATA_LENGTH] ;
|
||||
} BUFFER ;
|
||||
|
||||
static BUFFER data_out ;
|
||||
static BUFFER data_in ;
|
||||
|
||||
static void
|
||||
mpeg_short_test (void)
|
||||
{ const char * filename = "mpeg_short.mp3" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
short seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("mpeg_short_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7F00) ;
|
||||
|
||||
/* Convert to shorteger. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
|
||||
data_out.s [k] = lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, data_out.s, ARRAY_LEN (data_out.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, data_in.s, ARRAY_LEN (data_in.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("mpeg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_short_or_die (seek_data, data_in.s + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
/* Test seek to end of file. */
|
||||
test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* mpeg_short_test */
|
||||
|
||||
static void
|
||||
mpeg_int_test (void)
|
||||
{ const char * filename = "mpeg_int.mp3" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
int seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("mpeg_int_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7FFF0000) ;
|
||||
|
||||
/* Convert to integer. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.i) ; k++)
|
||||
data_out.i [k] = lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_int_or_die (file, 0, data_out.i, ARRAY_LEN (data_out.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, data_in.i, ARRAY_LEN (data_in.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("mpeg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_int_or_die (seek_data, data_in.i + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* mpeg_int_test */
|
||||
|
||||
static void
|
||||
mpeg_float_test (void)
|
||||
{ const char * filename = "mpeg_float.mp3" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
float seek_data [10] ;
|
||||
|
||||
print_test_name ("mpeg_float_test", filename) ;
|
||||
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, data_out.f, ARRAY_LEN (data_out.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, data_in.f, ARRAY_LEN (data_in.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("mpeg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_float_or_die (seek_data, data_in.f + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* mpeg_float_test */
|
||||
|
||||
static void
|
||||
mpeg_double_test (void)
|
||||
{ const char * filename = "mpeg_double.mp3" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
double seek_data [10] ;
|
||||
|
||||
print_test_name ("mpeg_double_test", filename) ;
|
||||
|
||||
gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, data_in.d, ARRAY_LEN (data_in.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("mpeg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_double_or_die (seek_data, data_in.d + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* mpeg_double_test */
|
||||
|
||||
|
||||
static void
|
||||
mpeg_stereo_seek_test (const char * filename, int format)
|
||||
{ static float data [SAMPLE_RATE] ;
|
||||
static float stereo_out [SAMPLE_RATE * 2] ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t pos ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
gen_windowed_sine_float (data, ARRAY_LEN (data), 0.95) ;
|
||||
for (k = 0 ; k < ARRAY_LEN (data) ; k++)
|
||||
{ stereo_out [2 * k] = data [k] ;
|
||||
stereo_out [2 * k + 1] = data [ARRAY_LEN (data) - k - 1] ;
|
||||
} ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open file in again for reading. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
/* Read in the whole file. */
|
||||
test_read_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
|
||||
/* Now hammer seeking code. */
|
||||
test_seek_or_die (file, 234, SEEK_SET, 234, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (234 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 442, SEEK_SET, 442, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (442 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 10 + 12, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 10 + 12) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 20 + 24, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 20 + 24) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 500 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 500, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (500 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 10 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (10 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
} /* mpeg_stereo_seek_test */
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (HAVE_MPEG)
|
||||
{ mpeg_short_test () ;
|
||||
mpeg_int_test () ;
|
||||
mpeg_float_test () ;
|
||||
mpeg_double_test () ;
|
||||
|
||||
mpeg_stereo_seek_test ("mpeg_seek.mp3", SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III) ;
|
||||
}
|
||||
else
|
||||
puts (" No MPEG tests because mpg123/lame support was not compiled in.") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
238
Engine/lib/libsndfile/tests/multi_file_test.c
Normal file
238
Engine/lib/libsndfile/tests/multi_file_test.c
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define DATA_LENGTH (512)
|
||||
|
||||
static void write_file_at_end (int fd, int filetype, int channels, int file_num) ;
|
||||
|
||||
static void multi_file_test (const char *filename, int *formats, int format_count) ;
|
||||
|
||||
static short data [DATA_LENGTH] ;
|
||||
|
||||
static int wav_formats [] =
|
||||
{ SF_FORMAT_WAV | SF_FORMAT_PCM_16,
|
||||
SF_FORMAT_WAV | SF_FORMAT_PCM_24,
|
||||
SF_FORMAT_WAV | SF_FORMAT_ULAW,
|
||||
SF_FORMAT_WAV | SF_FORMAT_ALAW,
|
||||
/* Lite remove start */
|
||||
SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM,
|
||||
SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM,
|
||||
/* Lite remove end */
|
||||
/*-SF_FORMAT_WAV | SF_FORMAT_GSM610 Doesn't work yet. -*/
|
||||
} ;
|
||||
|
||||
static int aiff_formats [] =
|
||||
{ SF_FORMAT_AIFF | SF_FORMAT_PCM_16,
|
||||
SF_FORMAT_AIFF | SF_FORMAT_PCM_24,
|
||||
SF_FORMAT_AIFF | SF_FORMAT_ULAW,
|
||||
SF_FORMAT_AIFF | SF_FORMAT_ALAW
|
||||
} ;
|
||||
|
||||
static int au_formats [] =
|
||||
{ SF_FORMAT_AU | SF_FORMAT_PCM_16,
|
||||
SF_FORMAT_AU | SF_FORMAT_PCM_24,
|
||||
SF_FORMAT_AU | SF_FORMAT_ULAW,
|
||||
SF_FORMAT_AU | SF_FORMAT_ALAW
|
||||
} ;
|
||||
|
||||
static int verbose = SF_FALSE ;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc == 3 && strcmp (argv [2], "-v") == 0)
|
||||
{ verbose = SF_TRUE ;
|
||||
argc -- ;
|
||||
} ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test WAV file functions (little endian)\n") ;
|
||||
printf (" aiff - test AIFF file functions (big endian)\n") ;
|
||||
printf (" au - test AU file functions\n") ;
|
||||
#if 0
|
||||
printf (" svx - test 8SVX/16SV file functions\n") ;
|
||||
printf (" nist - test NIST Sphere file functions\n") ;
|
||||
printf (" ircam - test IRCAM file functions\n") ;
|
||||
printf (" voc - Create Voice file functions\n") ;
|
||||
printf (" w64 - Sonic Foundry's W64 file functions\n") ;
|
||||
#endif
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = !strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ multi_file_test ("multi_wav.dat", wav_formats, ARRAY_LEN (wav_formats)) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ multi_file_test ("multi_aiff.dat", aiff_formats, ARRAY_LEN (aiff_formats)) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ multi_file_test ("multi_au.dat", au_formats, ARRAY_LEN (au_formats)) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*======================================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
multi_file_test (const char *filename, int *formats, int format_count)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_EMBED_FILE_INFO embed_info ;
|
||||
sf_count_t filelen ;
|
||||
int fd, k, file_count = 0 ;
|
||||
|
||||
print_test_name ("multi_file_test", filename) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
if ((fd = open (filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0)
|
||||
{ printf ("\n\nLine %d: open failed : %s\n", __LINE__, strerror (errno)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
k = write (fd, "1234", 4) ;
|
||||
|
||||
for (k = 0 ; k < format_count ; k++)
|
||||
write_file_at_end (fd, formats [k], 2, k) ;
|
||||
|
||||
filelen = file_length_fd (fd) ;
|
||||
|
||||
embed_info.offset = 4 ;
|
||||
embed_info.length = 0 ;
|
||||
|
||||
|
||||
for (file_count = 1 ; embed_info.offset + embed_info.length < filelen ; file_count ++)
|
||||
{
|
||||
if (verbose)
|
||||
{ puts ("\n------------------------------------") ;
|
||||
printf ("This offset : %" PRId64 "\n", embed_info.offset + embed_info.length) ;
|
||||
} ;
|
||||
|
||||
if (lseek (fd, (long) (embed_info.offset + embed_info.length), SEEK_SET) < 0)
|
||||
{ printf ("\n\nLine %d: lseek failed : %s\n", __LINE__, strerror (errno)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
if ((sndfile = sf_open_fd (fd, SFM_READ, &sfinfo, SF_FALSE)) == NULL)
|
||||
{ printf ("\n\nLine %d: sf_open_fd failed\n", __LINE__) ;
|
||||
printf ("Embedded file number : %d offset : %" PRId64 "\n", file_count, embed_info.offset) ;
|
||||
puts (sf_strerror (sndfile)) ;
|
||||
dump_log_buffer (sndfile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_command (sndfile, SFC_GET_EMBED_FILE_INFO, &embed_info, sizeof (embed_info)) ;
|
||||
|
||||
sf_close (sndfile) ;
|
||||
|
||||
if (verbose)
|
||||
printf ("\nNext offset : %" PRId64 "\nNext length : %" PRId64 "\n", embed_info.offset, embed_info.length) ;
|
||||
} ;
|
||||
|
||||
file_count -- ;
|
||||
|
||||
if (file_count != format_count)
|
||||
{ printf ("\n\nLine %d: file count (%d) not equal to %d.\n\n", __LINE__, file_count, format_count) ;
|
||||
printf ("Embedded file number : %d\n", file_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
close (fd) ;
|
||||
unlink (filename) ;
|
||||
printf ("ok\n") ;
|
||||
|
||||
return ;
|
||||
} /* multi_file_test */
|
||||
|
||||
/*======================================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
write_file_at_end (int fd, int filetype, int channels, int file_num)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
int frames, k ;
|
||||
|
||||
lseek (fd, 0, SEEK_END) ;
|
||||
|
||||
for (k = 0 ; k < DATA_LENGTH ; k++)
|
||||
data [k] = k ;
|
||||
|
||||
frames = DATA_LENGTH / channels ;
|
||||
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = channels ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
|
||||
if ((sndfile = sf_open_fd (fd, SFM_WRITE, &sfinfo, SF_FALSE)) == NULL)
|
||||
{ printf ("\n\nLine %d: sf_open_fd failed\n", __LINE__) ;
|
||||
printf ("Embedded file number : %d\n", file_num) ;
|
||||
puts (sf_strerror (sndfile)) ;
|
||||
dump_log_buffer (sndfile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sf_writef_short (sndfile, data, frames) != frames)
|
||||
{ printf ("\n\nLine %d: short write\n", __LINE__) ;
|
||||
printf ("Embedded file number : %d\n", file_num) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (sndfile) ;
|
||||
} /* write_file_at_end */
|
||||
|
||||
424
Engine/lib/libsndfile/tests/ogg_opus_test.c
Normal file
424
Engine/lib/libsndfile/tests/ogg_opus_test.c
Normal file
|
|
@ -0,0 +1,424 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2018 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SAMPLE_RATE 48000
|
||||
#define DATA_LENGTH (SAMPLE_RATE / 8)
|
||||
|
||||
typedef union
|
||||
{ double d [DATA_LENGTH] ;
|
||||
float f [DATA_LENGTH] ;
|
||||
int i [DATA_LENGTH] ;
|
||||
short s [DATA_LENGTH] ;
|
||||
} BUFFER ;
|
||||
|
||||
static BUFFER data_out ;
|
||||
static BUFFER data_in ;
|
||||
|
||||
static void
|
||||
ogg_opus_short_test (void)
|
||||
{ const char * filename = "ogg_opus_short.opus" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
short seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("ogg_opus_short_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7F00) ;
|
||||
|
||||
/* Convert to short. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
|
||||
data_out.s [k] = (short) lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_OPUS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, data_out.s, ARRAY_LEN (data_out.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, data_in.s, ARRAY_LEN (data_in.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_opus_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_short_or_die (seek_data, data_in.s + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
/* Test seek to end of file. */
|
||||
test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_short_test */
|
||||
|
||||
static void
|
||||
ogg_opus_int_test (void)
|
||||
{ const char * filename = "ogg_opus_int.opus" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
int seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("ogg_opus_int_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7FFF0000) ;
|
||||
|
||||
/* Convert to integer. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.i) ; k++)
|
||||
data_out.i [k] = lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_OPUS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_int_or_die (file, 0, data_out.i, ARRAY_LEN (data_out.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, data_in.i, ARRAY_LEN (data_in.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_opus_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_int_or_die (seek_data, data_in.i + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_int_test */
|
||||
|
||||
static void
|
||||
ogg_opus_float_test (void)
|
||||
{ const char * filename = "ogg_opus_float.opus" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
float seek_data [10] ;
|
||||
|
||||
print_test_name ("ogg_opus_float_test", filename) ;
|
||||
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_OPUS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, data_out.f, ARRAY_LEN (data_out.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, data_in.f, ARRAY_LEN (data_in.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_opus_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_float_or_die (seek_data, data_in.f + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_float_test */
|
||||
|
||||
static void
|
||||
ogg_opus_double_test (void)
|
||||
{ const char * filename = "ogg_opus_double.opus" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
double seek_data [10] ;
|
||||
|
||||
print_test_name ("ogg_opus_double_test", filename) ;
|
||||
|
||||
gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_OPUS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, data_in.d, ARRAY_LEN (data_in.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_opus_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_double_or_die (seek_data, data_in.d + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_double_test */
|
||||
|
||||
|
||||
static void
|
||||
ogg_opus_stereo_seek_test (const char * filename, int format)
|
||||
{ static float data [SAMPLE_RATE] ;
|
||||
static float stereo_out [SAMPLE_RATE * 2] ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t pos ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
gen_windowed_sine_float (data, ARRAY_LEN (data), 0.95) ;
|
||||
for (k = 0 ; k < ARRAY_LEN (data) ; k++)
|
||||
{ stereo_out [2 * k] = data [k] ;
|
||||
stereo_out [2 * k + 1] = data [ARRAY_LEN (data) - k - 1] ;
|
||||
} ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open file in again for reading. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
/* Read in the whole file. */
|
||||
test_read_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
|
||||
/* Now hammer seeking code. */
|
||||
test_seek_or_die (file, 234, SEEK_SET, 234, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (234 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 442, SEEK_SET, 442, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (442 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 10 + 12, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 10 + 12) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 20 + 24, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 20 + 24) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 500 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 500, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (500 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 10 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (10 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_stereo_seek_test */
|
||||
|
||||
|
||||
static void
|
||||
ogg_opus_original_samplerate_test (void)
|
||||
{ const char * filename = "ogg_opus_original_samplerate.opus" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
int original_samplerate = 54321 ;
|
||||
sf_count_t frames ;
|
||||
|
||||
print_test_name ("ogg_opus_original_samplerate_test", filename) ;
|
||||
|
||||
gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_OPUS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_ORIGINAL_SAMPLERATE, &original_samplerate, sizeof (original_samplerate)) != SF_TRUE)
|
||||
{ printf ("\nCommand SFC_SET_ORIGINAL_SAMPLERATE failed!\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_ORIGINAL_SAMPLERATE, &original_samplerate, sizeof (original_samplerate)) != SF_FALSE)
|
||||
{ printf ("\nCommand SFC_SET_ORIGINAL_SAMPLERATE succeeded when it should have failed!") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
original_samplerate = 0 ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
if (sf_command (file, SFC_GET_ORIGINAL_SAMPLERATE, &original_samplerate, sizeof (original_samplerate)) != SF_TRUE
|
||||
|| original_samplerate != 54321)
|
||||
{ printf ("\nCommand SFC_GET_ORIGINAL_SAMPLERATE failed!\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
test_read_double_or_die (file, 0, data_in.d, 8, __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_ORIGINAL_SAMPLERATE, &original_samplerate, sizeof (original_samplerate)) == SF_TRUE)
|
||||
{ printf ("\nCommand SFC_SET_ORIGINAL_SAMPLERATE succeeded when it should have failed!\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Test changing the decoder. */
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
frames = sfinfo.frames ;
|
||||
original_samplerate = 16000 ;
|
||||
if (sf_command (file, SFC_SET_ORIGINAL_SAMPLERATE, &original_samplerate, sizeof (original_samplerate)) != SF_TRUE)
|
||||
{ printf ("\nCommand SFC_SET_ORIGINAL_SAMPLERATE failed!\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (sf_command (file, SFC_GET_CURRENT_SF_INFO, &sfinfo, sizeof (sfinfo)))
|
||||
{ printf ("\nCommand SFC_GET_CURRENT_SF_INFO failed!\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (frames / (48000 / 16000) != sfinfo.frames)
|
||||
{ printf ("\nIncorrect frame count! (%" PRId64 " vs %" PRId64")\n", frames / (48000 / 16000), sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
test_read_double_or_die (file, 0, data_out.d, sfinfo.frames, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_opus_original_samplerate_test */
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ ogg_opus_short_test () ;
|
||||
ogg_opus_int_test () ;
|
||||
ogg_opus_float_test () ;
|
||||
ogg_opus_double_test () ;
|
||||
|
||||
ogg_opus_stereo_seek_test ("ogg_opus_seek.opus", SF_FORMAT_OGG | SF_FORMAT_OPUS) ;
|
||||
ogg_opus_original_samplerate_test () ;
|
||||
}
|
||||
else
|
||||
puts (" No Ogg/Opus tests because Ogg/Opus support was not compiled in.") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
348
Engine/lib/libsndfile/tests/ogg_test.c
Normal file
348
Engine/lib/libsndfile/tests/ogg_test.c
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
** Copyright (C) 2007-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SAMPLE_RATE 44100
|
||||
#define DATA_LENGTH (SAMPLE_RATE / 8)
|
||||
|
||||
typedef union
|
||||
{ double d [DATA_LENGTH] ;
|
||||
float f [DATA_LENGTH] ;
|
||||
int i [DATA_LENGTH] ;
|
||||
short s [DATA_LENGTH] ;
|
||||
} BUFFER ;
|
||||
|
||||
static BUFFER data_out ;
|
||||
static BUFFER data_in ;
|
||||
|
||||
static void
|
||||
ogg_short_test (void)
|
||||
{ const char * filename = "vorbis_short.oga" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
short seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("ogg_short_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7F00) ;
|
||||
|
||||
/* Convert to shorteger. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
|
||||
data_out.s [k] = (short) lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, data_out.s, ARRAY_LEN (data_out.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, data_in.s, ARRAY_LEN (data_in.s), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_short_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_short_or_die (seek_data, data_in.s + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
/* Test seek to end of file. */
|
||||
test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_short_test */
|
||||
|
||||
static void
|
||||
ogg_int_test (void)
|
||||
{ const char * filename = "vorbis_int.oga" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
int seek_data [10] ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name ("ogg_int_test", filename) ;
|
||||
|
||||
/* Generate float data. */
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7FFF0000) ;
|
||||
|
||||
/* Convert to integer. */
|
||||
for (k = 0 ; k < ARRAY_LEN (data_out.i) ; k++)
|
||||
data_out.i [k] = lrintf (data_out.f [k]) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_int_or_die (file, 0, data_out.i, ARRAY_LEN (data_out.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, data_in.i, ARRAY_LEN (data_in.i), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_int_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_int_or_die (seek_data, data_in.i + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_int_test */
|
||||
|
||||
static void
|
||||
ogg_float_test (void)
|
||||
{ const char * filename = "vorbis_float.oga" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
float seek_data [10] ;
|
||||
|
||||
print_test_name ("ogg_float_test", filename) ;
|
||||
|
||||
gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, data_out.f, ARRAY_LEN (data_out.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, data_in.f, ARRAY_LEN (data_in.f), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_float_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_float_or_die (seek_data, data_in.f + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_float_test */
|
||||
|
||||
static void
|
||||
ogg_double_test (void)
|
||||
{ const char * filename = "vorbis_double.oga" ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
double seek_data [10] ;
|
||||
|
||||
print_test_name ("ogg_double_test", filename) ;
|
||||
|
||||
gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Read the file in again. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, data_in.d, ARRAY_LEN (data_in.d), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
/* Test seeking. */
|
||||
print_test_name ("ogg_seek_test", filename) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
test_read_double_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
compare_double_or_die (seek_data, data_in.d + 10, ARRAY_LEN (seek_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
} /* ogg_double_test */
|
||||
|
||||
|
||||
static void
|
||||
ogg_stereo_seek_test (const char * filename, int format)
|
||||
{ static float data [SAMPLE_RATE] ;
|
||||
static float stereo_out [SAMPLE_RATE * 2] ;
|
||||
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t pos ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
gen_windowed_sine_float (data, ARRAY_LEN (data), 0.95) ;
|
||||
for (k = 0 ; k < ARRAY_LEN (data) ; k++)
|
||||
{ stereo_out [2 * k] = data [k] ;
|
||||
stereo_out [2 * k + 1] = data [ARRAY_LEN (data) - k - 1] ;
|
||||
} ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
/* Set up output file type. */
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.samplerate = SAMPLE_RATE ;
|
||||
|
||||
/* Write the output file. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
test_write_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open file in again for reading. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
/* Read in the whole file. */
|
||||
test_read_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
|
||||
|
||||
/* Now hammer seeking code. */
|
||||
test_seek_or_die (file, 234, SEEK_SET, 234, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (234 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 442, SEEK_SET, 442, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (442 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 10 + 12, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 10 + 12) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 12, SEEK_CUR, 442 + 20 + 24, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + ((442 + 20 + 24) * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 500 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 500, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (500 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
pos = 10 - sfinfo.frames ;
|
||||
test_seek_or_die (file, pos, SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
|
||||
compare_float_or_die (data, stereo_out + (10 * sfinfo.channels), 10, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
unlink (filename) ;
|
||||
} /* ogg_stereo_seek_test */
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
{ ogg_short_test () ;
|
||||
ogg_int_test () ;
|
||||
ogg_float_test () ;
|
||||
ogg_double_test () ;
|
||||
|
||||
/*-ogg_stereo_seek_test ("pcm.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;-*/
|
||||
ogg_stereo_seek_test ("vorbis_seek.ogg", SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;
|
||||
}
|
||||
else
|
||||
puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
34
Engine/lib/libsndfile/tests/pcm_test.def
Normal file
34
Engine/lib/libsndfile/tests/pcm_test.def
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
autogen definitions pcm_test.tpl;
|
||||
|
||||
data_type = {
|
||||
name = "bits_8" ;
|
||||
item_count = 127 ;
|
||||
short_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 8)" ;
|
||||
int_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 24)" ;
|
||||
float_func = "(k * ((k % 2) ? 1 : -1))" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "bits_16" ;
|
||||
item_count = 1024 ;
|
||||
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||
int_func = "arith_shift_left (k * ((k % 2) ? 3 : -3), 16)" ;
|
||||
float_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "bits_24" ;
|
||||
item_count = 1024 ;
|
||||
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||
int_func = "arith_shift_left (k * ((k % 2) ? 3333 : -3333), 8)" ;
|
||||
float_func = "(k * ((k % 2) ? 3333 : -3333))" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "bits_32" ;
|
||||
item_count = 1024 ;
|
||||
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||
int_func = "(k * ((k % 2) ? 333333 : -333333))" ;
|
||||
float_func = "(k * ((k % 2) ? 333333 : -333333))" ;
|
||||
} ;
|
||||
|
||||
919
Engine/lib/libsndfile/tests/pcm_test.tpl
Normal file
919
Engine/lib/libsndfile/tests/pcm_test.tpl
Normal file
|
|
@ -0,0 +1,919 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 1999-2013 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (1 << 12)
|
||||
|
||||
static void lrintf_test (void) ;
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash) ;
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ;
|
||||
static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ;
|
||||
|
||||
typedef union
|
||||
{ double d [BUFFER_SIZE + 1] ;
|
||||
float f [BUFFER_SIZE + 1] ;
|
||||
int i [BUFFER_SIZE + 1] ;
|
||||
short s [BUFFER_SIZE + 1] ;
|
||||
} BUFFER ;
|
||||
|
||||
/* Data written to the file. */
|
||||
static BUFFER data_out ;
|
||||
|
||||
/* Data read back from the file. */
|
||||
static BUFFER data_in ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
lrintf_test () ;
|
||||
|
||||
pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0xa335091249dbfLL) ;
|
||||
pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x48c433d695f3fLL) ;
|
||||
|
||||
pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xb956c881ebf08LL) ;
|
||||
pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x2f840c55750f8LL) ;
|
||||
|
||||
pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xb6a759ab496f8LL) ;
|
||||
pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xf3eaf9c30b6f8LL) ;
|
||||
|
||||
pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xaece1c1c17f08LL) ;
|
||||
pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x9ddf142d0b0f8LL) ;
|
||||
|
||||
/* Lite remove start */
|
||||
pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xad04f7554267aLL, SF_FALSE) ;
|
||||
pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xde3e248fa9186LL, SF_FALSE) ;
|
||||
|
||||
pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x2726f958f669cLL, SF_FALSE) ;
|
||||
pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x3583f8ee51164LL, SF_FALSE) ;
|
||||
|
||||
pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xad04f7554267aLL, SF_TRUE) ;
|
||||
pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0xde3e248fa9186LL, SF_TRUE) ;
|
||||
|
||||
pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x2726f958f669cLL, SF_TRUE) ;
|
||||
pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0x3583f8ee51164LL, SF_TRUE) ;
|
||||
/* Lite remove end */
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
lrintf_test (void)
|
||||
{ int k, items ;
|
||||
float *float_data ;
|
||||
int *int_data ;
|
||||
|
||||
print_test_name ("lrintf_test", "") ;
|
||||
|
||||
items = 1024 ;
|
||||
|
||||
float_data = data_out.f ;
|
||||
int_data = data_in.i ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
int_data [k] = lrintf (float_data [k]) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
if (fabs (int_data [k] - float_data [k]) > 1.0)
|
||||
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
} /* lrintf_test */
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void
|
||||
pcm_test_[+ (get "name") +] (const char *filename, int filetype, uint64_t hash)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, items, zero_count ;
|
||||
short *short_out, *short_in ;
|
||||
int *int_out, *int_in ;
|
||||
/* Lite remove start */
|
||||
float *float_out, *float_in ;
|
||||
double *double_out, *double_in ;
|
||||
/* Lite remove end */
|
||||
|
||||
print_test_name ("pcm_test_[+ (get "name") +]", filename) ;
|
||||
|
||||
items = [+ (get "item_count") +] ;
|
||||
|
||||
short_out = data_out.s ;
|
||||
short_in = data_in.s ;
|
||||
|
||||
zero_count = 0 ;
|
||||
for (k = 0 ; k < items ; k++)
|
||||
{ short_out [k] = [+ (get "short_func") +] ;
|
||||
zero_count = short_out [k] ? zero_count : zero_count + 1 ;
|
||||
} ;
|
||||
|
||||
if (zero_count > items / 4)
|
||||
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (short_in, 0, items * sizeof (short)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
if (short_out [k] != short_in [k])
|
||||
{ printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Finally, check the file hash. */
|
||||
check_file_hash_or_die (filename, hash, __LINE__) ;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
** Test sf_read/write_int ()
|
||||
*/
|
||||
zero_count = 0 ;
|
||||
|
||||
int_out = data_out.i ;
|
||||
int_in = data_in.i ;
|
||||
for (k = 0 ; k < items ; k++)
|
||||
{ int_out [k] = [+ (get "int_func") +] ;
|
||||
zero_count = int_out [k] ? zero_count : zero_count + 1 ;
|
||||
} ;
|
||||
|
||||
if (zero_count > items / 4)
|
||||
{ printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (int_in, 0, items * sizeof (int)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
if (int_out [k] != int_in [k])
|
||||
{ printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Lite remove start */
|
||||
/*--------------------------------------------------------------------------
|
||||
** Test sf_read/write_float ()
|
||||
*/
|
||||
zero_count = 0 ;
|
||||
|
||||
float_out = data_out.f ;
|
||||
float_in = data_in.f ;
|
||||
for (k = 0 ; k < items ; k++)
|
||||
{ float_out [k] = [+ (get "float_func") +] ;
|
||||
zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
|
||||
} ;
|
||||
|
||||
if (zero_count > items / 4)
|
||||
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
||||
|
||||
test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (float_in, 0, items * sizeof (float)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
|
||||
|
||||
test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
if (fabs (float_out [k] - float_in [k]) > 1e-10)
|
||||
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
** Test sf_read/write_double ()
|
||||
*/
|
||||
zero_count = 0 ;
|
||||
|
||||
double_out = data_out.d ;
|
||||
double_in = data_in.d ;
|
||||
for (k = 0 ; k < items ; k++)
|
||||
{ double_out [k] = [+ (get "float_func") +] ;
|
||||
zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
|
||||
} ;
|
||||
|
||||
if (zero_count > items / 4)
|
||||
{ printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
||||
|
||||
test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
memset (double_in, 0, items * sizeof (double)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %" PRId64 ")\n", __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
||||
|
||||
test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < items ; k++)
|
||||
if (fabs (double_out [k] - double_in [k]) > 1e-10)
|
||||
{ printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
/* Lite remove end */
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* pcm_test_[+ (get "name") +] */
|
||||
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, items, frames ;
|
||||
int sign ;
|
||||
double *data, error ;
|
||||
|
||||
print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
|
||||
|
||||
items = BUFFER_SIZE ;
|
||||
|
||||
data = data_out.d ;
|
||||
for (sign = 1, k = 0 ; k < items ; k++)
|
||||
{ data [k] = ((double) (k * sign)) / 100.0 ;
|
||||
sign = (sign > 0) ? -1 : 1 ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = items ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_write_double_or_die (file, 0, data, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (filename, hash, __LINE__) ;
|
||||
|
||||
memset (data, 0, items * sizeof (double)) ;
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data, items, __LINE__) ;
|
||||
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to end of file. */
|
||||
test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
|
||||
|
||||
/* Seek to start of file. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
||||
for (k = 0 ; k < 4 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from start of file. */
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
||||
for (k = 10 ; k < 14 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from current position. */
|
||||
test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from end of file. */
|
||||
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
||||
for (k = 10 ; k < 14 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now test Stereo. */
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
|
||||
{ printf ("ok\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
items = BUFFER_SIZE ;
|
||||
|
||||
data = data_out.d ;
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
data [k] = ((double) k) / 100.0 * (sign *= -1) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = items ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
frames = items / sfinfo.channels ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (filename, hash, __LINE__) ;
|
||||
|
||||
memset (data, 0, items * sizeof (double)) ;
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != frames)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, frames, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 2)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to start of file. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
|
||||
for (k = 0 ; k < 4 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from start of file. */
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from current position. */
|
||||
test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
|
||||
for (k = 40 ; k < 44 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from end of file. */
|
||||
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
unlink (filename) ;
|
||||
} /* pcm_test_float */
|
||||
|
||||
static void
|
||||
pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, items, frames ;
|
||||
int sign ;
|
||||
double *data, error ;
|
||||
|
||||
/* This is the best test routine. Other should be brought up to this standard. */
|
||||
|
||||
print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
|
||||
|
||||
items = BUFFER_SIZE ;
|
||||
|
||||
data = data_out.d ;
|
||||
for (sign = 1, k = 0 ; k < items ; k++)
|
||||
{ data [k] = ((double) (k * sign)) / 100.0 ;
|
||||
sign = (sign > 0) ? -1 : 1 ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = items ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_write_double_or_die (file, 0, data, items, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (filename, hash, __LINE__) ;
|
||||
|
||||
memset (data, 0, items * sizeof (double)) ;
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != items)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, items, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data, items, __LINE__) ;
|
||||
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to start of file. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
||||
for (k = 0 ; k < 4 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from start of file. */
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
||||
|
||||
test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
|
||||
|
||||
for (k = 10 ; k < 14 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from current position. */
|
||||
test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from end of file. */
|
||||
test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
||||
for (k = 10 ; k < 14 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now test Stereo. */
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
|
||||
{ printf ("ok\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
items = BUFFER_SIZE ;
|
||||
|
||||
data = data_out.d ;
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
data [k] = ((double) k) / 100.0 * (sign *= -1) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = items ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
frames = items / sfinfo.channels ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
check_file_hash_or_die (filename, hash, __LINE__) ;
|
||||
|
||||
memset (data, 0, items * sizeof (double)) ;
|
||||
|
||||
if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
|
||||
if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
|
||||
{ printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != frames)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %" PRId64 ")\n", __FILE__, __LINE__, frames, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 2)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
|
||||
|
||||
for (sign = -1, k = 0 ; k < items ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to start of file. */
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data, 4, __LINE__) ;
|
||||
for (k = 0 ; k < 4 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from start of file. */
|
||||
test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from current position. */
|
||||
test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
|
||||
for (k = 40 ; k < 44 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Seek to offset from end of file. */
|
||||
test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
|
||||
|
||||
test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
|
||||
for (k = 20 ; k < 24 ; k++)
|
||||
{ error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
|
||||
if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
|
||||
{ printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
unlink (filename) ;
|
||||
} /* pcm_test_double */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
371
Engine/lib/libsndfile/tests/peak_chunk_test.c
Normal file
371
Engine/lib/libsndfile/tests/peak_chunk_test.c
Normal file
|
|
@ -0,0 +1,371 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 15)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
|
||||
static void test_float_peak (const char *filename, int filetype) ;
|
||||
static void read_write_peak_test (const char *filename, int filetype) ;
|
||||
|
||||
static void check_logged_peaks (char *buffer) ;
|
||||
|
||||
/* Force the start of this buffer to be double aligned. Sparc-solaris will
|
||||
** choke if its not.
|
||||
*/
|
||||
static double data [BUFFER_LEN] ;
|
||||
static char log_buffer [LOG_BUFFER_SIZE] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" aiff - test AIFF file PEAK chunk\n") ;
|
||||
printf (" caf - test CAF file PEAK chunk\n") ;
|
||||
printf (" wav - test WAV file peak chunk\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ test_float_peak ("peak_float.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
|
||||
test_float_peak ("peak_float.wavex", SF_FORMAT_WAVEX | SF_FORMAT_FLOAT) ;
|
||||
test_float_peak ("peak_float.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
|
||||
|
||||
read_write_peak_test ("rw_peak.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ;
|
||||
read_write_peak_test ("rw_peak.wavex", SF_FORMAT_WAVEX | SF_FORMAT_FLOAT) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ test_float_peak ("peak_float.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ;
|
||||
|
||||
read_write_peak_test ("rw_peak.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "caf"))
|
||||
{ test_float_peak ("peak_float.caf", SF_FORMAT_CAF | SF_FORMAT_FLOAT) ;
|
||||
|
||||
read_write_peak_test ("rw_peak.caf", SF_FORMAT_CAF | SF_FORMAT_FLOAT) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "rf64"))
|
||||
{ test_float_peak ("peak_float.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ;
|
||||
|
||||
read_write_peak_test ("rw_peak.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
test_float_peak (const char *filename, int filetype)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, frames, count ;
|
||||
|
||||
print_test_name ("test_float_peak", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 4 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
frames = BUFFER_LEN / sfinfo.channels ;
|
||||
|
||||
/* Create some random data with a peak value of 0.66. */
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
data [k] = (rand () % 2000) / 3000.0 ;
|
||||
|
||||
/* Insert some larger peaks a know locations. */
|
||||
data [4 * (frames / 8) + 0] = (frames / 8) * 0.01 ; /* First channel */
|
||||
data [4 * (frames / 6) + 1] = (frames / 6) * 0.01 ; /* Second channel */
|
||||
data [4 * (frames / 4) + 2] = (frames / 4) * 0.01 ; /* Third channel */
|
||||
data [4 * (frames / 2) + 3] = (frames / 2) * 0.01 ; /* Fourth channel */
|
||||
|
||||
/* Write a file with PEAK chunks. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, 0, __LINE__) ;
|
||||
|
||||
/* Try to confuse the header writer by adding a removing the PEAK chunk. */
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
|
||||
|
||||
/* Write the data in four passed. The data is designed so that peaks will
|
||||
** be written in the different calls to sf_write_double ().
|
||||
*/
|
||||
for (count = 0 ; count < 4 ; count ++)
|
||||
test_write_double_or_die (file, 0, data + count * BUFFER_LEN / 4, BUFFER_LEN / 4, BUFFER_LEN / 4) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, 0, __LINE__) ;
|
||||
|
||||
if (sfinfo.format != filetype)
|
||||
{ printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != frames)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, frames, (long) sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 4)
|
||||
{ printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check these two commands. */
|
||||
if (sf_command (file, SFC_GET_SIGNAL_MAX, data, sizeof (double)) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d: Command should have returned SF_TRUE.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (data [0] - (frames / 2) * 0.01) > 0.01)
|
||||
{ printf ("\n\nLine %d: Bad peak value (%f should be %f) for command SFC_GET_SIGNAL_MAX.\n", __LINE__, data [0], (frames / 2) * 0.01) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sf_command (file, SFC_GET_MAX_ALL_CHANNELS, data, sizeof (double) * sfinfo.channels) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d: Command should have returned SF_TRUE.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (data [3] - (frames / 2) * 0.01) > 0.01)
|
||||
{ printf ("\n\nLine %d: Bad peak value (%f should be %f) for command SFC_GET_MAX_ALL_CHANNELS.\n", __LINE__, data [0], (frames / 2) * 0.01) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Get the log buffer data. */
|
||||
log_buffer [0] = 0 ;
|
||||
sf_command (file, SFC_GET_LOG_INFO, log_buffer, LOG_BUFFER_SIZE) ;
|
||||
|
||||
if (strlen (log_buffer) == 0)
|
||||
{ printf ("\n\nLine %d: Empty log buffer,\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_logged_peaks (log_buffer) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Write a file ***without*** PEAK chunks. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, 0, __LINE__) ;
|
||||
|
||||
/* Try to confuse the header writer by adding a removing the PEAK chunk. */
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
|
||||
/* Write the data in four passed. The data is designed so that peaks will
|
||||
** be written in the different calls to sf_write_double ().
|
||||
*/
|
||||
for (count = 0 ; count < 4 ; count ++)
|
||||
test_write_double_or_die (file, 0, data + count * BUFFER_LEN / 4, BUFFER_LEN / 4, BUFFER_LEN / 4) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, 0, __LINE__) ;
|
||||
|
||||
/* Check these two commands. */
|
||||
if (sf_command (file, SFC_GET_SIGNAL_MAX, data, sizeof (double)))
|
||||
{ printf ("\n\nLine %d: Command should have returned SF_FALSE.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sf_command (file, SFC_GET_MAX_ALL_CHANNELS, data, sizeof (double) * sfinfo.channels))
|
||||
{ printf ("\n\nLine %d: Command should have returned SF_FALSE.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Get the log buffer data. */
|
||||
log_buffer [0] = 0 ;
|
||||
sf_command (file, SFC_GET_LOG_INFO, log_buffer, LOG_BUFFER_SIZE) ;
|
||||
|
||||
if (strlen (log_buffer) == 0)
|
||||
{ printf ("\n\nLine %d: Empty log buffer,\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (strstr (log_buffer, "PEAK :") != NULL)
|
||||
{ printf ("\n\nLine %d: Should not have a PEAK chunk in this file.\n\n", __LINE__) ;
|
||||
puts (log_buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
printf ("ok\n") ;
|
||||
} /* test_float_peak */
|
||||
|
||||
static void
|
||||
check_logged_peaks (char *buffer)
|
||||
{ char *cptr ;
|
||||
int k, chan, channel_count, position ;
|
||||
float value ;
|
||||
|
||||
if (strstr (buffer, "should") || strstr (buffer, "*"))
|
||||
{ printf ("\n\nLine %d: Something wrong in buffer. Dumping.\n", __LINE__) ;
|
||||
puts (buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
channel_count = 0 ;
|
||||
cptr = strstr (buffer, "Channels") ;
|
||||
if (cptr && sscanf (cptr, "Channels : %d", &k) == 1)
|
||||
channel_count = k ;
|
||||
else if (cptr && sscanf (cptr, "Channels / frame : %d", &k) == 1)
|
||||
channel_count = k ;
|
||||
else
|
||||
{ printf ("\n\nLine %d: Couldn't find channel count.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (channel_count != 4)
|
||||
{ printf ("\n\nLine %d: Wrong channel count (4 ->%d).\n", __LINE__, channel_count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (! (cptr = strstr (buffer, "Ch Position Value")))
|
||||
{ printf ("\n\nLine %d: Can't find PEAK data.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < channel_count ; k++)
|
||||
{ if (! (cptr = strchr (cptr, '\n')))
|
||||
{ printf ("\n\nLine %d: Got lost.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (sscanf (cptr, "%d %d %f", &chan, &position, &value) != 3)
|
||||
{ printf ("\n\nLine %d: sscanf failed.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (position == 0)
|
||||
{ printf ("\n\nLine %d: peak position for channel %d should not be at offset 0.\n", __LINE__, chan) ;
|
||||
printf ("%s", buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (chan != k || fabs ((position) * 0.01 - value) > 1e-6)
|
||||
{ printf ("\n\nLine %d: Error : peak value incorrect!\n", __LINE__) ;
|
||||
printf ("%s", buffer) ;
|
||||
printf ("\n\nLine %d: %d %f %f\n", __LINE__, chan, position * 0.01, value) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
cptr ++ ; /* Move past current newline. */
|
||||
} ;
|
||||
|
||||
} /* check_logged_peaks */
|
||||
|
||||
static void
|
||||
read_write_peak_test (const char *filename, int filetype)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
double small_data [10], max_peak = 0.0 ;
|
||||
unsigned k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (small_data) ; k ++)
|
||||
small_data [k] = 0.1 ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
/* Open the file, add peak chunk and write samples with value 0.1. */
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
|
||||
|
||||
test_write_double_or_die (file, 0, small_data, ARRAY_LEN (small_data), __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open the fiel RDWR, write sample valied 1.25. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (small_data) ; k ++)
|
||||
small_data [k] = 1.0 ;
|
||||
|
||||
test_write_double_or_die (file, 0, small_data, ARRAY_LEN (small_data), __LINE__) ;
|
||||
|
||||
sf_command (file, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (max_peak)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
exit_if_true (max_peak < 0.1, "\n\nLine %d : max peak (%5.3f) should not be 0.1.\n\n", __LINE__, max_peak) ;
|
||||
|
||||
/* Open the file and test the values written to the PEAK chunk. */
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
exit_if_true (sfinfo.channels * sfinfo.frames != 2 * ARRAY_LEN (small_data),
|
||||
"Line %d : frame count is %" PRId64 ", should be %zd\n", __LINE__, sfinfo.frames, 2 * ARRAY_LEN (small_data)) ;
|
||||
|
||||
sf_command (file, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (double)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
exit_if_true (max_peak < 1.0, "\n\nLine %d : max peak (%5.3f) should be 1.0.\n\n", __LINE__, max_peak) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* read_write_peak_test */
|
||||
|
||||
58
Engine/lib/libsndfile/tests/pedantic-header-test.sh.in
Normal file
58
Engine/lib/libsndfile/tests/pedantic-header-test.sh.in
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright (C) 2010-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the author nor the names of any contributors may be used
|
||||
# to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
if test ! -f @top_srcdir@/tests/sfversion.c ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -n " Pedantic header test : "
|
||||
|
||||
# Only do this if the compiler is GCC.
|
||||
if test -n "@GCC_MAJOR_VERSION@" ; then
|
||||
|
||||
CC=`echo "@CC@" | sed "s/.*shave cc //"`
|
||||
# Compile with -Werror and -pedantic.
|
||||
$CC -std=c99 -Werror -pedantic -I@top_srcdir@/src -I@abs_top_builddir@/src -I@top_srcdir@/include -c @top_srcdir@/tests/sfversion.c -o /dev/null
|
||||
|
||||
# Check compiler return status.
|
||||
if test $? -ne 0 ; then
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "ok"
|
||||
else
|
||||
echo "n/a"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
14
Engine/lib/libsndfile/tests/pipe_test.def
Normal file
14
Engine/lib/libsndfile/tests/pipe_test.def
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
autogen definitions pipe_test.tpl;
|
||||
|
||||
data_type = {
|
||||
type_name = short ;
|
||||
};
|
||||
|
||||
data_type = {
|
||||
type_name = float ;
|
||||
};
|
||||
|
||||
data_type = {
|
||||
type_name = double ;
|
||||
};
|
||||
|
||||
362
Engine/lib/libsndfile/tests/pipe_test.tpl
Normal file
362
Engine/lib/libsndfile/tests/pipe_test.tpl
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 2001-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*==========================================================================
|
||||
** This is a test program which tests reading from and writing to pipes.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if (OS_IS_WIN32 || defined __OS2__ || HAVE_PIPE == 0 || HAVE_WAITPID == 0)
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts (" pipe_test : this test doesn't work on this OS.") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#else
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
typedef struct
|
||||
{ int format ;
|
||||
const char *ext ;
|
||||
} FILETYPE ;
|
||||
|
||||
static void useek_pipe_rw_test (int filetype, const char *ext) ;
|
||||
static void pipe_read_test (int filetype, const char *ext) ;
|
||||
static void pipe_write_test (const char *ext) ;
|
||||
static void pipe_test_others (FILETYPE*, FILETYPE*) ;
|
||||
|
||||
static FILETYPE read_write_types [] =
|
||||
{ { SF_FORMAT_RAW , "raw" },
|
||||
{ SF_FORMAT_AU , "au" },
|
||||
/* Lite remove start */
|
||||
{ SF_FORMAT_PAF , "paf" },
|
||||
{ SF_FORMAT_IRCAM , "ircam" },
|
||||
{ SF_FORMAT_PVF , "pvf" },
|
||||
/* Lite remove end */
|
||||
{ 0 , NULL }
|
||||
} ;
|
||||
|
||||
static FILETYPE read_only_types [] =
|
||||
{ { SF_FORMAT_RAW , "raw" },
|
||||
{ SF_FORMAT_AU , "au" },
|
||||
{ SF_FORMAT_AIFF , "aiff" },
|
||||
{ SF_FORMAT_WAV , "wav" },
|
||||
{ SF_FORMAT_W64 , "w64" },
|
||||
/* Lite remove start */
|
||||
{ SF_FORMAT_PAF , "paf" },
|
||||
{ SF_FORMAT_NIST , "nist" },
|
||||
{ SF_FORMAT_IRCAM , "ircam" },
|
||||
{ SF_FORMAT_MAT4 , "mat4" },
|
||||
{ SF_FORMAT_MAT5 , "mat5" },
|
||||
{ SF_FORMAT_SVX , "svx" },
|
||||
{ SF_FORMAT_PVF , "pvf" },
|
||||
/* Lite remove end */
|
||||
{ 0 , NULL }
|
||||
} ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ int k ;
|
||||
|
||||
for (k = 0 ; read_only_types [k].format ; k++)
|
||||
pipe_read_test (read_only_types [k].format, read_only_types [k].ext) ;
|
||||
|
||||
for (k = 0 ; read_write_types [k].format ; k++)
|
||||
pipe_write_test (read_write_types [k].ext) ;
|
||||
|
||||
for (k = 0 ; read_write_types [k].format ; k++)
|
||||
useek_pipe_rw_test (read_write_types [k].format, read_write_types [k].ext) ;
|
||||
|
||||
if (0)
|
||||
pipe_test_others (read_write_types, read_only_types) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
pipe_read_test (int filetype, const char *ext)
|
||||
{ static short data [PIPE_TEST_LEN] ;
|
||||
static char buffer [256] ;
|
||||
static char filename [256] ;
|
||||
|
||||
SNDFILE *outfile ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, retval ;
|
||||
|
||||
snprintf (filename, sizeof (filename), "pipe_in.%s", ext) ;
|
||||
print_test_name ("pipe_read_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = filetype | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
|
||||
for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
||||
data [k] = PIPE_INDEX (k) ;
|
||||
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
test_writef_short_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "cat %s | ./tests/stdin_test %s ", filename, ext) ;
|
||||
if ((retval = system (buffer)) != 0)
|
||||
{ retval = WEXITSTATUS (retval) ;
|
||||
printf ("\n\n Line %d : pipe test returned error for file type \"%s\".\n\n", __LINE__, ext) ;
|
||||
exit (retval) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* pipe_read_test */
|
||||
|
||||
static void
|
||||
pipe_write_test (const char *ext)
|
||||
{ static char buffer [256] ;
|
||||
|
||||
int retval ;
|
||||
|
||||
print_test_name ("pipe_write_test", ext) ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "./tests/stdout_test %s | ./tests/stdin_test %s ", ext, ext) ;
|
||||
if ((retval = system (buffer)))
|
||||
{ retval = WEXITSTATUS (retval) ;
|
||||
printf ("\n\n Line %d : pipe test returned error file type \"%s\".\n\n", __LINE__, ext) ;
|
||||
exit (retval) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* pipe_write_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
[+ FOR data_type +]
|
||||
static void
|
||||
useek_pipe_rw_[+ (get "type_name") +] (const char * ext, SF_INFO * psfinfo_write, SF_INFO * psfinfo_read)
|
||||
{ static [+ (get "type_name") +] buffer [PIPE_TEST_LEN] ;
|
||||
static [+ (get "type_name") +] data [PIPE_TEST_LEN] ;
|
||||
SNDFILE *outfile ;
|
||||
SNDFILE *infile_piped ;
|
||||
|
||||
int k, status = 0 ;
|
||||
int pipefd [2] ;
|
||||
pid_t pida ;
|
||||
|
||||
for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
||||
data [k] = PIPE_INDEX (k) ;
|
||||
|
||||
/*
|
||||
** Create the pipe.
|
||||
*/
|
||||
exit_if_true (pipe (pipefd) != 0, "\n\n%s %d : pipe failed : %s\n", __func__, __LINE__, strerror (errno)) ;
|
||||
|
||||
/*
|
||||
** Attach the write end of the pipe to be written to.
|
||||
*/
|
||||
if ((outfile = sf_open_fd (pipefd [1], SFM_WRITE, psfinfo_write, SF_TRUE)) == NULL)
|
||||
{ printf ("\n\n%s %d : unable to create unseekable pipe for write type \"%s\".\n", __func__, __LINE__, ext) ;
|
||||
printf ("\t%s\n\n", sf_strerror (outfile)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sf_error (outfile) != SF_ERR_NO_ERROR)
|
||||
{ printf ("\n\n%s %d : unable to open unseekable pipe for write type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/*
|
||||
** Attach the read end of the pipe to be read from.
|
||||
*/
|
||||
if ((infile_piped = sf_open_fd (pipefd [0], SFM_READ, psfinfo_read, SF_TRUE)) == NULL)
|
||||
{ printf ("\n\n%s %d : unable to create unseekable pipe for read type. \"%s\".\n\n", __func__, __LINE__, ext) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sf_error (infile_piped) != SF_ERR_NO_ERROR)
|
||||
{ printf ("\n\n%s %d : unable to open unseekable pipe for read type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Fork a child process that will write directly into the pipe. */
|
||||
if ((pida = fork ()) == 0) /* child process */
|
||||
{ test_writef_[+ (get "type_name") +]_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
/* In the parent process, read from the pipe and compare what is read
|
||||
** to what is written, if they match everything went as planned.
|
||||
*/
|
||||
test_readf_[+ (get "type_name") +]_or_die (infile_piped, 0, buffer, PIPE_TEST_LEN, __LINE__) ;
|
||||
if (memcmp (buffer, data, sizeof (buffer)) != 0)
|
||||
{ printf ("\n\n%s %d : unseekable pipe test failed for file type \"%s\".\n\n", __func__, __LINE__, ext) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Wait for the child process to return. */
|
||||
waitpid (pida, &status, 0) ;
|
||||
status = WEXITSTATUS (status) ;
|
||||
sf_close (outfile) ;
|
||||
sf_close (infile_piped) ;
|
||||
|
||||
if (status != 0)
|
||||
{ printf ("\n\n%s %d : status of child process is %d for file type %s.\n\n", __func__, __LINE__, status, ext) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* useek_pipe_rw_[+ (get "type_name") +] */
|
||||
|
||||
[+ ENDFOR data_type +]
|
||||
|
||||
|
||||
static void
|
||||
useek_pipe_rw_test (int filetype, const char *ext)
|
||||
{ SF_INFO sfinfo_write ;
|
||||
SF_INFO sfinfo_read ;
|
||||
|
||||
print_test_name ("useek_pipe_rw_test", ext) ;
|
||||
|
||||
/*
|
||||
** Setup the INFO structures for the filetype we will be
|
||||
** working with.
|
||||
*/
|
||||
sfinfo_write.format = filetype | SF_FORMAT_PCM_16 ;
|
||||
sfinfo_write.channels = 1 ;
|
||||
sfinfo_write.samplerate = 44100 ;
|
||||
|
||||
|
||||
sfinfo_read.format = 0 ;
|
||||
if (filetype == SF_FORMAT_RAW)
|
||||
{ sfinfo_read.format = filetype | SF_FORMAT_PCM_16 ;
|
||||
sfinfo_read.channels = 1 ;
|
||||
sfinfo_read.samplerate = 44100 ;
|
||||
} ;
|
||||
|
||||
useek_pipe_rw_short (ext, &sfinfo_write, &sfinfo_read) ;
|
||||
|
||||
sfinfo_read.format = sfinfo_write.format = filetype | SF_FORMAT_FLOAT ;
|
||||
if (sf_format_check (&sfinfo_read) != 0)
|
||||
useek_pipe_rw_float (ext, &sfinfo_write, &sfinfo_read) ;
|
||||
|
||||
sfinfo_read.format = sfinfo_write.format = filetype | SF_FORMAT_DOUBLE ;
|
||||
if (sf_format_check (&sfinfo_read) != 0)
|
||||
useek_pipe_rw_double (ext, &sfinfo_write, &sfinfo_read) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* useek_pipe_rw_test */
|
||||
|
||||
|
||||
|
||||
static void
|
||||
pipe_test_others (FILETYPE* list1, FILETYPE* list2)
|
||||
{ SF_FORMAT_INFO info ;
|
||||
int k, m, major_count, in_list ;
|
||||
|
||||
print_test_name ("pipe_test_others", "") ;
|
||||
|
||||
sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
|
||||
|
||||
for (k = 0 ; k < major_count ; k++)
|
||||
{ info.format = k ;
|
||||
|
||||
sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
|
||||
|
||||
in_list = SF_FALSE ;
|
||||
for (m = 0 ; list1 [m].format ; m++)
|
||||
if (info.format == list1 [m].format)
|
||||
in_list = SF_TRUE ;
|
||||
|
||||
for (m = 0 ; list2 [m].format ; m++)
|
||||
if (info.format == list2 [m].format)
|
||||
in_list = SF_TRUE ;
|
||||
|
||||
if (in_list)
|
||||
continue ;
|
||||
|
||||
printf ("%s %x\n", info.name, info.format) ;
|
||||
|
||||
if (1)
|
||||
{ static short data [PIPE_TEST_LEN] ;
|
||||
static char buffer [256] ;
|
||||
static const char *filename = "pipe_in.dat" ;
|
||||
|
||||
SNDFILE *outfile ;
|
||||
SF_INFO sfinfo ;
|
||||
int retval ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = info.format | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
|
||||
outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
test_writef_short_or_die (outfile, 0, data, PIPE_TEST_LEN, __LINE__) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "cat %s | ./tests/stdin_test %s %d ", filename, info.extension, PIPE_TEST_LEN) ;
|
||||
if ((retval = system (buffer)) == 0)
|
||||
{ retval = WEXITSTATUS (retval) ;
|
||||
printf ("\n\n Line %d : pipe test should have returned error file type \"%s\" but didn't.\n\n", __LINE__, info.name) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* pipe_test_others */
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
189
Engine/lib/libsndfile/tests/raw_test.c
Normal file
189
Engine/lib/libsndfile/tests/raw_test.c
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2014 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
static void raw_offset_test (const char *filename, int typeminor) ;
|
||||
static void bad_raw_test (void) ;
|
||||
|
||||
/* Force the start of this buffer to be double aligned. Sparc-solaris will
|
||||
** choke if its not.
|
||||
*/
|
||||
static short data [BUFFER_LEN] ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
raw_offset_test ("offset.raw", SF_FORMAT_PCM_16) ;
|
||||
bad_raw_test () ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
raw_offset_test (const char *filename, int typeminor)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t start ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("raw_offset_test", filename) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = SF_FORMAT_RAW | typeminor ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
start = 0 ;
|
||||
sf_command (sndfile, SFC_FILE_TRUNCATE, &start, sizeof (start)) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
data [k] = k ;
|
||||
test_write_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_close (sndfile) ;
|
||||
|
||||
sndfile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
check_log_buffer_or_die (sndfile, __LINE__) ;
|
||||
|
||||
if (ABS (BUFFER_LEN - sfinfo.frames) > 1)
|
||||
{ printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ;
|
||||
dump_log_buffer (sndfile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
memset (data, 0 , sizeof (data)) ;
|
||||
test_read_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ;
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
if (data [k] != k)
|
||||
printf ("Error : line %d\n", __LINE__) ;
|
||||
|
||||
/* Set dataoffset to 2 bytes from beginning of file. */
|
||||
start = 2 ;
|
||||
sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ;
|
||||
|
||||
/* Seek to new start */
|
||||
test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
memset (data, 0 , sizeof (data)) ;
|
||||
test_read_short_or_die (sndfile, 0, data, BUFFER_LEN - 1, __LINE__) ;
|
||||
for (k = 0 ; k < BUFFER_LEN - 1 ; k++)
|
||||
if (data [k] != k + 1)
|
||||
{ printf ("Error : line %d\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Set dataoffset to 4 bytes from beginning of file. */
|
||||
start = 4 ;
|
||||
sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ;
|
||||
|
||||
/* Seek to new start */
|
||||
test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
memset (data, 0 , sizeof (data)) ;
|
||||
test_read_short_or_die (sndfile, 0, data, BUFFER_LEN - 2, __LINE__) ;
|
||||
for (k = 0 ; k < BUFFER_LEN - 2 ; k++)
|
||||
if (data [k] != k + 2)
|
||||
{ printf ("Error : line %d\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Set dataoffset back to 0 bytes from beginning of file. */
|
||||
start = 0 ;
|
||||
sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &start, sizeof (start)) ;
|
||||
|
||||
/* Seek to new start */
|
||||
test_seek_or_die (sndfile, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
memset (data, 0 , sizeof (data)) ;
|
||||
test_read_short_or_die (sndfile, 0, data, BUFFER_LEN, __LINE__) ;
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
if (data [k] != k)
|
||||
{ printf ("Error : line %d\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (sndfile) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* raw_offset_test */
|
||||
|
||||
static void
|
||||
bad_raw_test (void)
|
||||
{ FILE *textfile ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
const char *errorstr, *filename = "bad.raw" ;
|
||||
|
||||
print_test_name ("bad_raw_test", filename) ;
|
||||
|
||||
if ((textfile = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d : not able to open text file for write.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
fprintf (textfile, "This is not a valid file.\n") ;
|
||||
fclose (textfile) ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = SF_FORMAT_RAW | 0xABCD ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_READ, &sfinfo)) != NULL)
|
||||
{ printf ("\n\nLine %d : Error, file should not have opened.\n", __LINE__ - 1) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
errorstr = sf_strerror (file) ;
|
||||
|
||||
if (strstr (errorstr, "Bad format field in SF_INFO struct") == NULL)
|
||||
{ printf ("\n\nLine %d : Error bad error string : %s.\n", __LINE__ - 1, errorstr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* bad_raw_test */
|
||||
|
||||
32
Engine/lib/libsndfile/tests/rdwr_test.def
Normal file
32
Engine/lib/libsndfile/tests/rdwr_test.def
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
autogen definitions rdwr_test.tpl;
|
||||
|
||||
data_type = {
|
||||
name = "short" ;
|
||||
type = "short" ;
|
||||
format = "SF_FORMAT_PCM_16" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "int" ;
|
||||
type = "int" ;
|
||||
format = "SF_FORMAT_PCM_32" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "float" ;
|
||||
type = "float" ;
|
||||
format = "SF_FORMAT_FLOAT" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "double" ;
|
||||
type = "double" ;
|
||||
format = "SF_FORMAT_DOUBLE" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "raw" ;
|
||||
type = "unsigned char" ;
|
||||
format = "SF_FORMAT_PCM_U8" ;
|
||||
} ;
|
||||
|
||||
105
Engine/lib/libsndfile/tests/rdwr_test.tpl
Normal file
105
Engine/lib/libsndfile/tests/rdwr_test.tpl
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 2010-2012 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
|
||||
** the Free Software Foundation ; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY ; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program ; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#if (defined (WIN32) || defined (_WIN32))
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void rdwr_[+ (get "name") +]_test (const char *filename) ;
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
rdwr_short_test ("rdwr_short.wav") ;
|
||||
rdwr_int_test ("rdwr_int.wav") ;
|
||||
rdwr_float_test ("rdwr_float.wav") ;
|
||||
rdwr_double_test ("rdwr_double.wav") ;
|
||||
rdwr_raw_test ("rdwr_raw.wav") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
[+ FOR data_type
|
||||
+]static void
|
||||
rdwr_[+ (get "name") +]_test (const char *filename)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
[+ (get "type") +] buffer [160] ;
|
||||
|
||||
print_test_name ("rdwr_[+ (get "name") +]_test", filename) ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Create sound file with no data. */
|
||||
sfinfo.format = SF_FORMAT_WAV | [+ (get "format") +] ;
|
||||
sfinfo.samplerate = 16000 ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
frames = ARRAY_LEN (buffer) ;
|
||||
|
||||
/* Open again for read/write. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
|
||||
|
||||
test_read_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* rdwr_[+ (get "name") +]_test */
|
||||
|
||||
[+ ENDFOR data_type
|
||||
+]
|
||||
|
||||
56
Engine/lib/libsndfile/tests/scale_clip_test.def
Normal file
56
Engine/lib/libsndfile/tests/scale_clip_test.def
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
autogen definitions scale_clip_test.tpl;
|
||||
|
||||
float_type = {
|
||||
float_type_name = "float" ;
|
||||
float_short_name = "flt" ;
|
||||
float_upper_name = "FLOAT" ;
|
||||
float_to_int = "lrintf" ;
|
||||
} ;
|
||||
|
||||
float_type = {
|
||||
float_type_name = "double" ;
|
||||
float_short_name = "dbl" ;
|
||||
float_upper_name = "DOUBLE" ;
|
||||
float_to_int = "lrint" ;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
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" ;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
data_type = {
|
||||
name = "16" ;
|
||||
bit_count = 16 ;
|
||||
error_val = "1.0 / 0x8000" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "24" ;
|
||||
bit_count = 24 ;
|
||||
error_val = "1.0 / 0x800000" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "32" ;
|
||||
bit_count = 32 ;
|
||||
error_val = "1.0 / 0x80000000" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
name = "08" ;
|
||||
bit_count = 8 ;
|
||||
error_val = "1.0 / 0x80" ;
|
||||
} ;
|
||||
|
||||
440
Engine/lib/libsndfile/tests/scale_clip_test.tpl
Normal file
440
Engine/lib/libsndfile/tests/scale_clip_test.tpl
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
[+ AutoGen5 template c +]
|
||||
/*
|
||||
** Copyright (C) 1999-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
#define HALF_BUFFER_SIZE (1 << 12)
|
||||
#define BUFFER_SIZE (2 * HALF_BUFFER_SIZE)
|
||||
|
||||
#define SINE_AMP 1.1
|
||||
#define MAX_ERROR 0.0202
|
||||
|
||||
[+ FOR float_type +]
|
||||
[+ FOR data_type
|
||||
+]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_short_name") +]_[+ (get "int_type_name") +]_clip_read_test (const char *filename, int filetype) ;
|
||||
[+ ENDFOR int_type
|
||||
+][+ ENDFOR float_type +]
|
||||
|
||||
[+ FOR int_type +]
|
||||
[+ FOR float_type
|
||||
+]static void [+ (get "int_type_name") +]_[+ (get "float_short_name") +]_scale_write_test (const char *filename, int filetype) ;
|
||||
[+ ENDFOR float_type
|
||||
+][+ ENDFOR int_type +]
|
||||
|
||||
typedef union
|
||||
{ double dbl [BUFFER_SIZE] ;
|
||||
float flt [BUFFER_SIZE] ;
|
||||
int i [BUFFER_SIZE] ;
|
||||
short s [BUFFER_SIZE] ;
|
||||
} BUFFER ;
|
||||
|
||||
/* Data buffer. */
|
||||
static BUFFER buffer_out ;
|
||||
static BUFFER buffer_in ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
flt_scale_clip_test_08 ("scale_clip_s8.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8, 1.0 * 0x80) ;
|
||||
flt_scale_clip_test_08 ("scale_clip_u8.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8, 1.0 * 0x80) ;
|
||||
|
||||
dbl_scale_clip_test_08 ("scale_clip_s8.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8, 1.0 * 0x80) ;
|
||||
dbl_scale_clip_test_08 ("scale_clip_u8.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8, 1.0 * 0x80) ;
|
||||
|
||||
/*
|
||||
** Now use SF_FORMAT_AU where possible because it allows both
|
||||
** big and little endian files.
|
||||
*/
|
||||
|
||||
flt_scale_clip_test_16 ("scale_clip_be16.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
||||
flt_scale_clip_test_16 ("scale_clip_le16.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
||||
flt_scale_clip_test_24 ("scale_clip_be24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
||||
flt_scale_clip_test_24 ("scale_clip_le24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
||||
flt_scale_clip_test_32 ("scale_clip_be32.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
||||
flt_scale_clip_test_32 ("scale_clip_le32.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, 1.0 * 0x80000000) ;
|
||||
|
||||
dbl_scale_clip_test_16 ("scale_clip_be16.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
||||
dbl_scale_clip_test_16 ("scale_clip_le16.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, 1.0 * 0x8000) ;
|
||||
dbl_scale_clip_test_24 ("scale_clip_be24.au", SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
||||
dbl_scale_clip_test_24 ("scale_clip_le24.au", SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, 1.0 * 0x800000) ;
|
||||
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) ;
|
||||
|
||||
flt_short_clip_read_test ("flt_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
flt_int_clip_read_test ("flt_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
dbl_short_clip_read_test ("dbl_short.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
||||
dbl_int_clip_read_test ("dbl_int.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
||||
|
||||
short_flt_scale_write_test ("short_flt.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
int_flt_scale_write_test ("int_flt.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
short_dbl_scale_write_test ("short_dbl.au" , SF_ENDIAN_BIG | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
||||
int_dbl_scale_write_test ("int_dbl.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
[+ FOR float_type +]
|
||||
[+ FOR data_type
|
||||
+]static void
|
||||
[+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +] (const char *filename, int filetype, float maxval)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
[+ (get "float_type_name") +] *data_out, *data_in ;
|
||||
double diff, clip_max_diff ;
|
||||
|
||||
print_test_name ("[+ (get "float_short_name") +]_scale_clip_test_[+ (get "name") +]", filename) ;
|
||||
|
||||
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] = 1.2 * sin (2 * M_PI * k / HALF_BUFFER_SIZE) ;
|
||||
data_out [k + HALF_BUFFER_SIZE] = data_out [k] * maxval ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = filetype ;
|
||||
|
||||
/*
|
||||
** Write two versions of the data:
|
||||
** normalized and clipped
|
||||
** un-normalized and clipped.
|
||||
*/
|
||||
|
||||
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 "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)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
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 => %" PRId64 ").\n\n", __LINE__, BUFFER_SIZE, 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__) ;
|
||||
|
||||
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. */
|
||||
clip_max_diff = 0.0 ;
|
||||
for (k = 0 ; k < HALF_BUFFER_SIZE ; k++)
|
||||
{ if (fabs (data_in [k]) > 1.0)
|
||||
{ printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (data_out [k] * data_in [k] < 0.0)
|
||||
{ printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (data_out [k]) > 1.0)
|
||||
continue ;
|
||||
|
||||
diff = fabs (data_out [k] - data_in [k]) ;
|
||||
if (diff > clip_max_diff)
|
||||
clip_max_diff = diff ;
|
||||
} ;
|
||||
|
||||
if (clip_max_diff < 1e-20)
|
||||
{ printf ("\n\nLine %d: Clipping difference (%e) too small (normalized).\n\n", __LINE__, clip_max_diff) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (clip_max_diff > [+ (get "error_val") +])
|
||||
{ printf ("\n\nLine %d: Clipping difference (%e) too large (normalized).\n\n", __LINE__, clip_max_diff) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check the un-normalized data. */
|
||||
clip_max_diff = 0.0 ;
|
||||
for (k = HALF_BUFFER_SIZE ; k < BUFFER_SIZE ; k++)
|
||||
{ if (fabs (data_in [k]) > maxval)
|
||||
{ printf ("\n\nLine %d: Input sample %d/%d (%f) has not been clipped.\n\n", __LINE__, k, BUFFER_SIZE, data_in [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (data_out [k] * data_in [k] < 0.0)
|
||||
{ printf ("\n\nLine %d: Data wrap around at index %d/%d.\n\n", __LINE__, k, BUFFER_SIZE) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (data_out [k]) > maxval)
|
||||
continue ;
|
||||
|
||||
diff = fabs (data_out [k] - data_in [k]) ;
|
||||
if (diff > clip_max_diff)
|
||||
clip_max_diff = diff ;
|
||||
} ;
|
||||
|
||||
if (clip_max_diff < 1e-20)
|
||||
{ printf ("\n\nLine %d: Clipping difference (%e) too small (un-normalized).\n\n", __LINE__, clip_max_diff) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (clip_max_diff > 1.0)
|
||||
{ printf ("\n\nLine %d: Clipping difference (%e) too large (un-normalised).\n\n", __LINE__, clip_max_diff) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("ok\n") ;
|
||||
unlink (filename) ;
|
||||
} /* [+ (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_short_name") +]_[+ (get "int_type_name") +]_clip_read_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_short_name") +]_[+ (get "int_type_name") +]_clip_read_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 => %" PRId64 ").\n\n", __LINE__, BUFFER_SIZE, 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]) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* [+ (get "float_short_name") +]_[+ (get "int_type_name") +]_clip_read_test */
|
||||
[+ ENDFOR int_type
|
||||
+][+ ENDFOR float_type +]
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
[+ FOR int_type +]
|
||||
[+ FOR float_type
|
||||
+]static void [+ (get "int_type_name") +]_[+ (get "float_short_name") +]_scale_write_test (const char *filename, int filetype)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
[+ (get "int_type_name") +] *data_out ;
|
||||
[+ (get "float_type_name") +] *data_in, max_value ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("[+ (get "int_type_name") +]_[+ (get "float_short_name") +]_clip_write_test", filename) ;
|
||||
|
||||
data_out = buffer_out.[+ (get "int_short_name") +] ;
|
||||
data_in = buffer_in.[+ (get "float_short_name") +] ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
data_out [k] = [+ (get "float_to_int") +] ([+ (get "int_max_value") +] * 0.995 * sin (4 * M_PI * k / BUFFER_SIZE)) ;
|
||||
|
||||
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 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
test_write_[+ (get "int_type_name") +]_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
||||
sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
|
||||
test_write_[+ (get "int_type_name") +]_or_die (file, 0, data_out, BUFFER_SIZE, __LINE__) ;
|
||||
sf_command (file, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_FALSE) ;
|
||||
test_write_[+ (get "int_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__) ;
|
||||
|
||||
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 != 3 * BUFFER_SIZE)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file (%d => %" PRId64 ").\n\n", __LINE__, 3 * BUFFER_SIZE, 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__) ;
|
||||
|
||||
/* Check the first section. */
|
||||
test_read_[+ (get "float_type_name") +]_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
||||
|
||||
max_value = 0.0 ;
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
||||
|
||||
if (max_value < 1000.0)
|
||||
{ printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check the second section. */
|
||||
test_read_[+ (get "float_type_name") +]_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
||||
|
||||
max_value = 0.0 ;
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
||||
|
||||
if (max_value > 1.0)
|
||||
{ printf ("\n\nLine %d: Max value (%f) > 1.0.\n\n", __LINE__, max_value) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check the third section. */
|
||||
test_read_[+ (get "float_type_name") +]_or_die (file, 0, data_in, BUFFER_SIZE, __LINE__) ;
|
||||
|
||||
max_value = 0.0 ;
|
||||
for (k = 0 ; k < BUFFER_SIZE ; k++)
|
||||
max_value = (max_value > fabs (data_in [k])) ? max_value : fabs (data_in [k]) ;
|
||||
|
||||
if (max_value < 1000.0)
|
||||
{ printf ("\n\nLine %d: Max value (%f) < 1000.0.\n\n", __LINE__, max_value) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* [+ (get "int_type_name") +]_[+ (get "float_short_name") +]_scale_write_test */
|
||||
[+ ENDFOR float_type
|
||||
+][+ ENDFOR int_type +]
|
||||
|
||||
|
||||
67
Engine/lib/libsndfile/tests/sftest.c
Normal file
67
Engine/lib/libsndfile/tests/sftest.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#define BUFFER_SIZE (1024)
|
||||
|
||||
|
||||
static short buffer [BUFFER_SIZE] ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, count, max = 0, total = 0 ;
|
||||
|
||||
if (argc < 2)
|
||||
{ printf ("Expecting input file name.\n") ;
|
||||
return 0 ;
|
||||
} ;
|
||||
|
||||
if (! (file = sf_open (argv [1], SFM_READ, &sfinfo)))
|
||||
{ printf ("sf_open_read failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
while ((count = sf_read_short (file, buffer, BUFFER_SIZE)))
|
||||
{ for (k = 0 ; k < count ; k++)
|
||||
if (abs (buffer [k]) > max)
|
||||
max = abs (buffer [k]) ;
|
||||
total += count ;
|
||||
} ;
|
||||
|
||||
printf ("Total : %d\n", total) ;
|
||||
printf ("Maximun value : %d\n", max) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
48
Engine/lib/libsndfile/tests/sfversion.c
Normal file
48
Engine/lib/libsndfile/tests/sfversion.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#define BUFFER_SIZE (256)
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ static char strbuffer [BUFFER_SIZE] ;
|
||||
const char * ver ;
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, strbuffer, sizeof (strbuffer)) ;
|
||||
ver = sf_version_string () ;
|
||||
|
||||
if (strcmp (ver, strbuffer) != 0)
|
||||
{ printf ("Version mismatch : '%s' != '%s'\n\n", ver, strbuffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("%s", strbuffer) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
206
Engine/lib/libsndfile/tests/stdin_test.c
Normal file
206
Engine/lib/libsndfile/tests/stdin_test.c
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 16)
|
||||
|
||||
static void stdin_test (int typemajor, int count) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0, test_count = 0 ;
|
||||
|
||||
if (BUFFER_LEN < PIPE_TEST_LEN)
|
||||
{ fprintf (stderr, "Error : BUFFER_LEN < PIPE_TEST_LEN.\n\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (argc != 2)
|
||||
{ fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
|
||||
fprintf (stderr, "to be run from the stdio_test program.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "raw"))
|
||||
{ stdin_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ stdin_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ stdin_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ stdin_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "paf"))
|
||||
{ stdin_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "svx"))
|
||||
{ stdin_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "nist"))
|
||||
{ stdin_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ircam"))
|
||||
{ stdin_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "voc"))
|
||||
{ stdin_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ stdin_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat4"))
|
||||
{ stdin_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat5"))
|
||||
{ stdin_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "pvf"))
|
||||
{ stdin_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "htk"))
|
||||
{ stdin_test (SF_FORMAT_HTK, PIPE_TEST_LEN) ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ fprintf (stderr, "\n*****************************************\n") ;
|
||||
fprintf (stderr, "* stdin_test : No '%s' test defined.\n", argv [1]) ;
|
||||
fprintf (stderr, "*****************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
stdin_test (int typemajor, int count)
|
||||
{ static short data [BUFFER_LEN] ;
|
||||
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, total, err ;
|
||||
|
||||
if (typemajor == SF_FORMAT_RAW)
|
||||
{ sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
}
|
||||
else
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
if ((file = sf_open_fd (fileno (stdin), SFM_READ, &sfinfo, SF_TRUE)) == NULL)
|
||||
{ fprintf (stderr, "sf_open_fd failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
dump_log_buffer (NULL) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
err = sf_error (file) ;
|
||||
if (err != SF_ERR_NO_ERROR)
|
||||
{ printf ("Line %d : unexpected error : %s\n", __LINE__, sf_error_number (err)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((sfinfo.format & SF_FORMAT_TYPEMASK) != typemajor)
|
||||
{ fprintf (stderr, "\n\nError : File type doesn't match.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.samplerate != 44100)
|
||||
{ fprintf (stderr, "\n\nError : Sample rate (%d) should be 44100\n", sfinfo.samplerate) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
{ fprintf (stderr, "\n\nError : Channels (%d) should be 1\n", sfinfo.channels) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames < count)
|
||||
{ fprintf (stderr, "\n\nError : Sample count (%ld) should be %d\n", (long) sfinfo.frames, count) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
total = 0 ;
|
||||
while ((k = (int) sf_read_short (file, data + total, BUFFER_LEN - total)) > 0)
|
||||
total += k ;
|
||||
|
||||
if (total != count)
|
||||
{ fprintf (stderr, "\n\nError : Expected %d frames, read %d.\n", count, total) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < total ; k++)
|
||||
if (data [k] != PIPE_INDEX (k))
|
||||
{ printf ("\n\nError : data [%d] == %d, should have been %d.\n\n", k, data [k], k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
return ;
|
||||
} /* stdin_test */
|
||||
|
||||
141
Engine/lib/libsndfile/tests/stdio_test.c
Normal file
141
Engine/lib/libsndfile/tests/stdio_test.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*==========================================================================
|
||||
** This is a test program which tests reading from stdin and writing to
|
||||
** stdout.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/* EMX is OS/2. */
|
||||
#if (OS_IS_WIN32) || defined (__EMX__)
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts (" stdio_test : this test doesn't work on win32.") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#else
|
||||
|
||||
#ifndef WIFEXITED
|
||||
#define WIFEXITED(s) (((s) & 0xff) == 0)
|
||||
#endif
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
|
||||
#endif
|
||||
|
||||
|
||||
static size_t file_length (const char *filename) ;
|
||||
static void stdio_test (const char *filetype) ;
|
||||
|
||||
static const char *filetypes [] =
|
||||
{ "raw", "wav", "aiff", "au", "paf", "svx", "nist", "ircam",
|
||||
"voc", "w64", "mat4", "mat5", "pvf",
|
||||
NULL
|
||||
} ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ int k ;
|
||||
|
||||
for (k = 0 ; filetypes [k] ; k++)
|
||||
stdio_test (filetypes [k]) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
static void
|
||||
stdio_test (const char *filetype)
|
||||
{ static char buffer [256] ;
|
||||
|
||||
int file_size, retval ;
|
||||
|
||||
print_test_name ("stdio_test", filetype) ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "./tests/stdout_test %s > stdio.%s", filetype, filetype) ;
|
||||
if ((retval = system (buffer)))
|
||||
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
||||
printf ("%s : %s", buffer, (strerror (retval))) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "stdio.%s", filetype) ;
|
||||
if ((file_size = file_length (buffer)) < PIPE_TEST_LEN)
|
||||
{ printf ("\n Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "./tests/stdin_test %s < stdio.%s", filetype, filetype) ;
|
||||
if ((retval = system (buffer)))
|
||||
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
||||
printf ("%s : %s", buffer, (strerror (retval))) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetype) ;
|
||||
if ((retval = system (buffer)))
|
||||
{ retval = WIFEXITED (retval) ? WEXITSTATUS (retval) : 1 ;
|
||||
printf ("%s : %s", buffer, (strerror (retval))) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* stdio_test */
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t
|
||||
file_length (const char *filename)
|
||||
{ struct stat buf ;
|
||||
|
||||
if (stat (filename, &buf))
|
||||
{ perror (filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return buf.st_size ;
|
||||
} /* file_length */
|
||||
|
||||
#endif
|
||||
|
||||
169
Engine/lib/libsndfile/tests/stdout_test.c
Normal file
169
Engine/lib/libsndfile/tests/stdout_test.c
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2014 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static void stdout_test (int typemajor, int count) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all, test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
|
||||
fprintf (stderr, "to be run from the stdio_test program.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "raw"))
|
||||
{ stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "au"))
|
||||
{ stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "paf"))
|
||||
{ stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "svx"))
|
||||
{ stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "nist"))
|
||||
{ stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ircam"))
|
||||
{ stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "voc"))
|
||||
{ stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat4"))
|
||||
{ stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mat5"))
|
||||
{ stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "pvf"))
|
||||
{ stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ fprintf (stderr, "\n******************************************\n") ;
|
||||
fprintf (stderr, "* stdout_test : No '%s' test defined.\n", argv [1]) ;
|
||||
fprintf (stderr, "******************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
stdout_test (int typemajor, int count)
|
||||
{ static short data [PIPE_TEST_LEN] ;
|
||||
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k, total, this_write ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
/* Create some random data. */
|
||||
for (k = 0 ; k < PIPE_TEST_LEN ; k++)
|
||||
data [k] = PIPE_INDEX (k) ;
|
||||
|
||||
if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ fprintf (stderr, "%s % d: sf_open_write failed with error : %s\n",
|
||||
__func__, __LINE__, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != 0)
|
||||
{ fprintf (stderr, "%s % d: Frames is %d (should be 0).\n",
|
||||
__func__, __LINE__, (int) sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
total = 0 ;
|
||||
|
||||
while (total < count)
|
||||
{ this_write = (count - total > 1024) ? 1024 : count - total ;
|
||||
if ((k = (int) sf_write_short (file, data + total, this_write)) != this_write)
|
||||
{ fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
total += k ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
return ;
|
||||
} /* stdout_test */
|
||||
|
||||
907
Engine/lib/libsndfile/tests/string_test.c
Normal file
907
Engine/lib/libsndfile/tests/string_test.c
Normal file
|
|
@ -0,0 +1,907 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2016 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
#define NULL_PRINTF_CHECK(X) (X ? X : "(null)")
|
||||
|
||||
static const char STR_TEST_PREFIX[] = "str" ;
|
||||
|
||||
static void string_start_test (const char *filename, int typemajor) ;
|
||||
static void string_start_end_test (const char *filename, int typemajor) ;
|
||||
static void string_multi_set_test (const char *filename, int typemajor) ;
|
||||
static void string_rdwr_test (const char *filename, int typemajor) ;
|
||||
static void string_short_rdwr_test (const char *filename, int typemajor) ;
|
||||
static void string_rdwr_grow_test (const char *filename, int typemajor) ;
|
||||
static void string_header_update (const char *filename, int typemajor) ;
|
||||
|
||||
static void software_string_test (const char *filename) ;
|
||||
|
||||
static int str_count (const char * haystack, const char * needle) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ int do_all = 0 ;
|
||||
int test_count = 0 ;
|
||||
|
||||
if (argc != 2)
|
||||
{ printf ("Usage : %s <test>\n", argv [0]) ;
|
||||
printf (" Where <test> is one of the following:\n") ;
|
||||
printf (" wav - test adding strings to WAV files\n") ;
|
||||
printf (" aiff - test adding strings to AIFF files\n") ;
|
||||
printf (" flac - test adding strings to FLAC files\n") ;
|
||||
printf (" ogg - test adding strings to OGG files\n") ;
|
||||
printf (" opus - test adding strings to OPUS files\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "wav"))
|
||||
{ string_start_end_test ("strings.wav", SF_FORMAT_WAV) ;
|
||||
string_multi_set_test ("multi.wav", SF_FORMAT_WAV) ;
|
||||
string_rdwr_test ("rdwr.wav", SF_FORMAT_WAV) ;
|
||||
string_short_rdwr_test ("short_rdwr.wav", SF_FORMAT_WAV) ;
|
||||
string_rdwr_grow_test ("rdwr_grow.wav", SF_FORMAT_WAV) ;
|
||||
string_header_update ("header_update.wav", SF_FORMAT_WAV) ;
|
||||
|
||||
string_start_end_test ("strings.wavex", SF_FORMAT_WAVEX) ;
|
||||
string_multi_set_test ("multi.wavex", SF_FORMAT_WAVEX) ;
|
||||
string_rdwr_test ("rdwr.wavex", SF_FORMAT_WAVEX) ;
|
||||
string_short_rdwr_test ("short_rdwr.wavex", SF_FORMAT_WAVEX) ;
|
||||
|
||||
string_start_end_test ("strings.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
|
||||
string_multi_set_test ("multi.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
|
||||
string_rdwr_test ("rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
|
||||
string_short_rdwr_test ("short_rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
|
||||
|
||||
software_string_test ("software_string.wav") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "aiff"))
|
||||
{ string_start_test ("strings.aiff", SF_FORMAT_AIFF) ;
|
||||
string_start_end_test ("strings.aiff", SF_FORMAT_AIFF) ;
|
||||
/*
|
||||
TODO : Fix src/aiff.c so these tests pass.
|
||||
string_multi_set_test ("multi.aiff", SF_FORMAT_AIFF) ;
|
||||
string_rdwr_test ("rdwr.aiff", SF_FORMAT_AIFF) ;
|
||||
string_short_rdwr_test ("short_rdwr.aiff", SF_FORMAT_AIFF) ;
|
||||
string_rdwr_grow_test ("rdwr_grow.aiff", SF_FORMAT_AIFF) ;
|
||||
string_header_update ("header_update.aiff", SF_FORMAT_AIFF) ;
|
||||
*/
|
||||
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "flac"))
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
string_start_test ("strings.flac", SF_FORMAT_FLAC) ;
|
||||
else
|
||||
puts (" No FLAC tests because FLAC support was not compiled in.") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "mpeg"))
|
||||
{ if (HAVE_MPEG)
|
||||
string_start_test ("mpeg.mp3", SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III) ;
|
||||
else
|
||||
puts (" No MP3 tests because MPEG support was not compiled in.") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "ogg"))
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
string_start_test ("vorbis.oga", SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;
|
||||
else
|
||||
puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "opus"))
|
||||
{ if (HAVE_EXTERNAL_XIPH_LIBS)
|
||||
string_start_test ("opus.opus", SF_FORMAT_OGG | SF_FORMAT_OPUS) ;
|
||||
else
|
||||
puts (" No Ogg/Opus tests because Ogg/Opus support was not compiled in.") ;
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "caf"))
|
||||
{ string_start_test ("strings.caf", SF_FORMAT_CAF) ;
|
||||
string_start_end_test ("strings.caf", SF_FORMAT_CAF) ;
|
||||
string_multi_set_test ("multi.caf", SF_FORMAT_CAF) ;
|
||||
/*
|
||||
TODO : Fix src/caf.c so these tests pass.
|
||||
string_rdwr_test ("rdwr.caf", SF_FORMAT_CAF) ;
|
||||
string_short_rdwr_test ("short_rdwr.caf", SF_FORMAT_CAF) ;
|
||||
string_header_update ("header_update.caf", SF_FORMAT_CAF) ;
|
||||
*/
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "rf64"))
|
||||
{ string_start_test ("strings.rf64", SF_FORMAT_RF64) ;
|
||||
string_start_end_test ("strings.rf64", SF_FORMAT_RF64) ;
|
||||
string_multi_set_test ("multi.rf64", SF_FORMAT_RF64) ;
|
||||
/*
|
||||
TODO : Fix src/rf64.c so these tests pass.
|
||||
string_rdwr_test ("rdwr.rf64", SF_FORMAT_RF64) ;
|
||||
string_short_rdwr_test ("short_rdwr.rf64", SF_FORMAT_RF64) ;
|
||||
string_header_update ("header_update.rf64", SF_FORMAT_RF64) ;
|
||||
*/
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || ! strcmp (argv [1], "w64"))
|
||||
{ puts ("\n\n **** String test not working yet for W64 format. ****\n") ;
|
||||
/*
|
||||
string_start_test ("strings.w64", SF_FORMAT_W64) ;
|
||||
string_start_end_test ("strings.w64", SF_FORMAT_W64) ;
|
||||
string_multi_set_test ("multi.w64", SF_FORMAT_W64) ;
|
||||
string_rdwr_test ("rdwr.w64", SF_FORMAT_W64) ;
|
||||
string_short_rdwr_test ("short_rdwr.w64", SF_FORMAT_W64) ;
|
||||
string_header_update ("header_update.w64", SF_FORMAT_W64) ;
|
||||
*/
|
||||
test_count++ ;
|
||||
} ;
|
||||
|
||||
if (test_count == 0)
|
||||
{ printf ("Mono : ************************************\n") ;
|
||||
printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
|
||||
printf ("Mono : ************************************\n") ;
|
||||
return 1 ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*============================================================================================
|
||||
** Here are the test functions.
|
||||
*/
|
||||
|
||||
static const char
|
||||
software [] = "software (libsndfile-X.Y.Z)",
|
||||
artist [] = "The Artist",
|
||||
copyright [] = "Copyright (c) 2001 Artist",
|
||||
comment [] = "Comment goes here!!!",
|
||||
date [] = "2001/01/27",
|
||||
album [] = "The Album",
|
||||
license [] = "The license",
|
||||
title [] = "This is the title",
|
||||
long_title [] = "This is a very long and very boring title for this file",
|
||||
long_artist [] = "The artist who kept on changing its name",
|
||||
genre [] = "The genre",
|
||||
trackno [] = "Track three",
|
||||
id3v1_genre [] = "Rock",
|
||||
year [] = "2001" ;
|
||||
|
||||
|
||||
static short data_out [BUFFER_LEN] ;
|
||||
|
||||
static void
|
||||
string_start_end_test (const char *filename, int typemajor)
|
||||
{ const char *cptr ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int errors = 0 ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name ("string_start_end_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Write stuff at start of file. */
|
||||
sf_set_string (file, SF_STR_TITLE, filename) ;
|
||||
sf_set_string (file, SF_STR_SOFTWARE, software) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, artist) ;
|
||||
sf_set_string (file, SF_STR_GENRE, genre) ;
|
||||
sf_set_string (file, SF_STR_TRACKNUMBER, trackno) ;
|
||||
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
|
||||
|
||||
/* Write more stuff at end of file. */
|
||||
sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
|
||||
sf_set_string (file, SF_STR_COMMENT, comment) ;
|
||||
sf_set_string (file, SF_STR_DATE, date) ;
|
||||
sf_set_string (file, SF_STR_ALBUM, album) ;
|
||||
sf_set_string (file, SF_STR_LICENSE, license) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_TITLE) ;
|
||||
if (cptr == NULL || strcmp (filename, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad filename : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
|
||||
if (cptr == NULL || strcmp (copyright, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad copyright : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
|
||||
if (cptr == NULL || strstr (cptr, software) != cptr)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad software : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
if (str_count (cptr, "libsndfile") != 1)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad software : %s\n", cptr) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_ARTIST) ;
|
||||
if (cptr == NULL || strcmp (artist, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad artist : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_COMMENT) ;
|
||||
if (cptr == NULL || strcmp (comment, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad comment : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
if (typemajor != SF_FORMAT_AIFF)
|
||||
{ cptr = sf_get_string (file, SF_STR_DATE) ;
|
||||
if (cptr == NULL || strcmp (date, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad date : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_GENRE) ;
|
||||
if (cptr == NULL || strcmp (genre, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad genre : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
switch (typemajor)
|
||||
{ case SF_FORMAT_AIFF :
|
||||
case SF_FORMAT_WAV :
|
||||
case SF_FORMAT_WAVEX :
|
||||
case SF_ENDIAN_BIG | SF_FORMAT_WAV :
|
||||
case SF_FORMAT_RF64 :
|
||||
/* These formats do not support the following. */
|
||||
break ;
|
||||
|
||||
default :
|
||||
cptr = sf_get_string (file, SF_STR_ALBUM) ;
|
||||
if (cptr == NULL || strcmp (album, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad album : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_LICENSE) ;
|
||||
if (cptr == NULL || strcmp (license, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad license : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_TRACKNUMBER) ;
|
||||
if (cptr == NULL || strcmp (trackno, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad track no. : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (errors > 0)
|
||||
{ printf ("\n*** Error count : %d ***\n\n", errors) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_start_end_test */
|
||||
|
||||
static void
|
||||
string_start_test (const char *filename, int formattype)
|
||||
{ const char *cptr ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int errors = 0 ;
|
||||
int typemajor = SF_FORMAT_TYPEMASK & formattype ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name ("string_start_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
switch (formattype)
|
||||
{ case SF_FORMAT_OGG | SF_FORMAT_OPUS :
|
||||
/* Opus only supports some discrete sample rates. */
|
||||
sfinfo.samplerate = 48000 ;
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_OGG | SF_FORMAT_VORBIS :
|
||||
case SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III :
|
||||
break ;
|
||||
|
||||
default :
|
||||
formattype |= SF_FORMAT_PCM_16 ;
|
||||
break ;
|
||||
} ;
|
||||
sfinfo.format = formattype ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Write stuff at start of file. */
|
||||
sf_set_string (file, SF_STR_TITLE, filename) ;
|
||||
sf_set_string (file, SF_STR_SOFTWARE, software) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, artist) ;
|
||||
sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
|
||||
sf_set_string (file, SF_STR_COMMENT, comment) ;
|
||||
sf_set_string (file, SF_STR_ALBUM, album) ;
|
||||
sf_set_string (file, SF_STR_LICENSE, license) ;
|
||||
if (typemajor == SF_FORMAT_MPEG)
|
||||
{ sf_set_string (file, SF_STR_GENRE, id3v1_genre) ;
|
||||
sf_set_string (file, SF_STR_DATE, year) ;
|
||||
}
|
||||
else
|
||||
{ sf_set_string (file, SF_STR_DATE, date) ;
|
||||
} ;
|
||||
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_TITLE) ;
|
||||
if (cptr == NULL || strcmp (filename, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad filename : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
if (typemajor != SF_FORMAT_MPEG)
|
||||
{ cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
|
||||
if (cptr == NULL || strcmp (copyright, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad copyright : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
|
||||
if (cptr == NULL || strstr (cptr, software) != cptr)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad software : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
if (cptr && str_count (cptr, "libsndfile") != 1)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad software : %s\n", cptr) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (typemajor == SF_FORMAT_MPEG)
|
||||
{ cptr = sf_get_string (file, SF_STR_GENRE) ;
|
||||
if (cptr == NULL || strcmp (id3v1_genre, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad genre : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_ARTIST) ;
|
||||
if (cptr == NULL || strcmp (artist, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad artist : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
cptr = sf_get_string (file, SF_STR_COMMENT) ;
|
||||
if (cptr == NULL || strcmp (comment, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad comment : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
|
||||
switch (typemajor)
|
||||
{ case SF_FORMAT_AIFF :
|
||||
/* not supported */
|
||||
break ;
|
||||
|
||||
case SF_FORMAT_MPEG :
|
||||
/* id3 only supports years */
|
||||
cptr = sf_get_string (file, SF_STR_DATE) ;
|
||||
if (cptr == NULL || strcmp (year, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad date : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
cptr = sf_get_string (file, SF_STR_DATE) ;
|
||||
if (cptr == NULL || strcmp (date, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad date : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF)
|
||||
{ cptr = sf_get_string (file, SF_STR_ALBUM) ;
|
||||
if (cptr == NULL || strcmp (album, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad album : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
switch (typemajor)
|
||||
{ case SF_FORMAT_WAV :
|
||||
case SF_FORMAT_AIFF :
|
||||
case SF_FORMAT_RF64 :
|
||||
case SF_FORMAT_MPEG :
|
||||
/* not supported */
|
||||
break ;
|
||||
|
||||
default:
|
||||
cptr = sf_get_string (file, SF_STR_LICENSE) ;
|
||||
if (cptr == NULL || strcmp (license, cptr) != 0)
|
||||
{ if (errors++ == 0)
|
||||
puts ("\n") ;
|
||||
printf (" Bad license : %s\n", NULL_PRINTF_CHECK(cptr)) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (errors > 0)
|
||||
{ printf ("\n*** Error count : %d ***\n\n", errors) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_start_test */
|
||||
|
||||
static void
|
||||
string_multi_set_test (const char *filename, int typemajor)
|
||||
{ static const char
|
||||
new_software [] = "new software (libsndfile-X.Y.Z)",
|
||||
new_copyright [] = "Copyright (c) 2001 New Artist",
|
||||
new_artist [] = "The New Artist",
|
||||
new_title [] = "This is the new title" ;
|
||||
|
||||
static char buffer [2048] ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int count ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
/* Write stuff at start of file. */
|
||||
sf_set_string (file, SF_STR_TITLE, title) ;
|
||||
sf_set_string (file, SF_STR_SOFTWARE, software) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, artist) ;
|
||||
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
/* Write it all again. */
|
||||
|
||||
sf_set_string (file, SF_STR_TITLE, new_title) ;
|
||||
sf_set_string (file, SF_STR_SOFTWARE, new_software) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, new_artist) ;
|
||||
|
||||
sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
|
||||
sf_set_string (file, SF_STR_COMMENT, comment) ;
|
||||
sf_set_string (file, SF_STR_DATE, date) ;
|
||||
sf_set_string (file, SF_STR_ALBUM, album) ;
|
||||
sf_set_string (file, SF_STR_LICENSE, license) ;
|
||||
sf_set_string (file, SF_STR_COPYRIGHT, new_copyright) ;
|
||||
sf_set_string (file, SF_STR_COMMENT, comment) ;
|
||||
sf_set_string (file, SF_STR_DATE, date) ;
|
||||
sf_set_string (file, SF_STR_ALBUM, album) ;
|
||||
sf_set_string (file, SF_STR_LICENSE, license) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_command (file, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
|
||||
sf_close (file) ;
|
||||
|
||||
count = str_count (buffer, new_title) ;
|
||||
exit_if_true (count < 1, "\n\nLine %d : Could not find new_title in :\n%s\n", __LINE__, buffer) ;
|
||||
exit_if_true (count > 1, "\n\nLine %d : new_title appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
|
||||
|
||||
count = str_count (buffer, software) ;
|
||||
exit_if_true (count < 1, "\n\nLine %d : Could not find new_software in :\n%s\n", __LINE__, buffer) ;
|
||||
exit_if_true (count > 1, "\n\nLine %d : new_software appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
|
||||
|
||||
count = str_count (buffer, new_artist) ;
|
||||
exit_if_true (count < 1, "\n\nLine %d : Could not find new_artist in :\n%s\n", __LINE__, buffer) ;
|
||||
exit_if_true (count > 1, "\n\nLine %d : new_artist appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
|
||||
|
||||
count = str_count (buffer, new_copyright) ;
|
||||
exit_if_true (count < 1, "\n\nLine %d : Could not find new_copyright in :\n%s\n", __LINE__, buffer) ;
|
||||
exit_if_true (count > 1, "\n\nLine %d : new_copyright appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_multi_set_test */
|
||||
|
||||
static void
|
||||
string_rdwr_test (const char *filename, int typemajor)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
const char * str ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
create_short_sndfile (filename, typemajor | SF_FORMAT_PCM_16, 2) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
frames = sfinfo.frames ;
|
||||
sf_set_string (file, SF_STR_TITLE, title) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
frames = sfinfo.frames ;
|
||||
sf_set_string (file, SF_STR_TITLE, title) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, artist) ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
str = sf_get_string (file, SF_STR_ARTIST) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_rdwr_test */
|
||||
|
||||
static void
|
||||
string_short_rdwr_test (const char *filename, int typemajor)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames = BUFFER_LEN ;
|
||||
const char * str ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = 0 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_set_string (file, SF_STR_TITLE, long_title) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, long_artist) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Open the file RDWR. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
str = sf_get_string (file, SF_STR_ARTIST) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, long_artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
/* Change title and artist. */
|
||||
sf_set_string (file, SF_STR_TITLE, title) ;
|
||||
sf_set_string (file, SF_STR_ARTIST, artist) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
str = sf_get_string (file, SF_STR_ARTIST) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_short_rdwr_test */
|
||||
|
||||
static int
|
||||
str_count (const char * haystack, const char * needle)
|
||||
{ int count = 0 ;
|
||||
|
||||
while ((haystack = strstr (haystack, needle)) != NULL)
|
||||
{ count ++ ;
|
||||
haystack ++ ;
|
||||
} ;
|
||||
|
||||
return count ;
|
||||
} /* str_count */
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
static void
|
||||
software_string_test (const char *filename)
|
||||
{ size_t k ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
for (k = 0 ; k < 50 ; k++)
|
||||
{ const char *result ;
|
||||
char sfname [64] = "" ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO info ;
|
||||
|
||||
sf_info_setup (&info, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 44100, 1) ;
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_TRUE, __LINE__) ;
|
||||
|
||||
snprintf (sfname, MIN (k, sizeof (sfname)), "%s", "abcdefghijklmnopqrestvwxyz0123456789abcdefghijklmnopqrestvwxyz") ;
|
||||
|
||||
exit_if_true (sf_set_string (file, SF_STR_SOFTWARE, sfname),
|
||||
"\n\nLine %d : sf_set_string (f, SF_STR_SOFTWARE, '%s') failed : %s\n", __LINE__, sfname, sf_strerror (file)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &info, SF_TRUE, __LINE__) ;
|
||||
result = sf_get_string (file, SF_STR_SOFTWARE) ;
|
||||
|
||||
exit_if_true (result == NULL, "\n\nLine %d : sf_get_string (file, SF_STR_SOFTWARE) returned NULL.\n\n", __LINE__) ;
|
||||
|
||||
exit_if_true (strstr (result, sfname) != result,
|
||||
"\n\nLine %d : Can't fine string '%s' in '%s'\n\n", __LINE__, sfname, result) ;
|
||||
sf_close (file) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* software_string_test */
|
||||
|
||||
|
||||
static void
|
||||
string_rdwr_grow_test (const char *filename, int typemajor)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
const char * str ;
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
/* Create a file that contains some strings. Then open the file in RDWR mode and
|
||||
grow the file by writing more audio data to it. Check that the audio data has
|
||||
been added to the file, and that the strings are still there. */
|
||||
|
||||
/* Create a short file that contains a string. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
/* Write data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
/* Write some strings at end of file. */
|
||||
sf_set_string (file, SF_STR_TITLE , title) ;
|
||||
sf_set_string (file, SF_STR_COMMENT, comment) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
/* Now open file again in SFM_RDWR mode and write more audio data to it. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
/* Write more data to file. */
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
/* Now open file again. It should now contain two BUFFER_LEN's worth of frames and the strings. */
|
||||
frames = 2 * BUFFER_LEN / sfinfo.channels ;
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
|
||||
/* Check the strings */
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
str = sf_get_string (file, SF_STR_COMMENT) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_COMMENT string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, comment) != 0, "\n\nLine %d : SF_STR_COMMENT doesn't match what was written.\n", __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* string_rdwr_grow_test */
|
||||
|
||||
static void
|
||||
string_header_update (const char *filename, int typemajor)
|
||||
{ SNDFILE *file , *file1 ;
|
||||
SF_INFO sfinfo , sfinfo1 ;
|
||||
sf_count_t frames ;
|
||||
const char * str ;
|
||||
const int GROW_BUFFER_AMOUNT = 4 ; /* this should be less than half the size of the string header */
|
||||
|
||||
get_unique_test_name (&filename, STR_TEST_PREFIX) ;
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
/* Create a short file. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.frames = 0 ;
|
||||
sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
|
||||
sf_set_string (file, SF_STR_TITLE, long_title) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
/* Check that SFC_UPDATE_HEADER_NOW correctly calculates datalength. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
/* Write a very small amount of new audio data that doesn't completely overwrite the existing header. */
|
||||
test_write_short_or_die (file, 0, data_out, GROW_BUFFER_AMOUNT, __LINE__) ;
|
||||
|
||||
/* Update the header without closing the file. */
|
||||
sf_command (file, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
|
||||
|
||||
/* The file should now contain BUFFER_LEN + GROW_BUFFER_AMOUNT frames.
|
||||
Open a second handle to the file and check the reported length. */
|
||||
memset (&sfinfo1, 0, sizeof (sfinfo1)) ;
|
||||
file1 = test_open_file_or_die (filename, SFM_READ, &sfinfo1, SF_TRUE, __LINE__) ;
|
||||
|
||||
frames = (BUFFER_LEN + GROW_BUFFER_AMOUNT) / sfinfo.channels ;
|
||||
exit_if_true (frames != sfinfo1.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo1.frames, frames) ;
|
||||
|
||||
/* The strings are probably not readable by the second soundfile handle because write_tailer has not yet been called.
|
||||
It's a design decision whether SFC_UPDATE_HEADER_NOW should write the tailer. I think it's fine that it doesn't. */
|
||||
|
||||
sf_close (file1) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
/* Check that sf_close correctly calculates datalength. */
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
/* Write a very small amount of new audio data that doesn't completely overwrite the existing header. */
|
||||
test_write_short_or_die (file, 0, data_out, GROW_BUFFER_AMOUNT, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
/* Open file again and verify data and string. */
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
frames = (BUFFER_LEN + 2*GROW_BUFFER_AMOUNT) / sfinfo.channels ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
str = sf_get_string (file, SF_STR_TITLE) ;
|
||||
exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
|
||||
exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
|
||||
sf_close (file) ;
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* string_header_update */
|
||||
380
Engine/lib/libsndfile/tests/test_wrapper.sh.in
Normal file
380
Engine/lib/libsndfile/tests/test_wrapper.sh.in
Normal file
|
|
@ -0,0 +1,380 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Copyright (C) 2008-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the author nor the names of any contributors may be used
|
||||
# to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
HOST_TRIPLET=@HOST_TRIPLET@
|
||||
PACKAGE_VERSION=@PACKAGE_VERSION@
|
||||
LIB_VERSION=$(echo $PACKAGE_VERSION | sed "s/[a-z].*//")
|
||||
ABS_TOP_SRCDIR=@abs_top_srcdir@
|
||||
PYTHON=@PYTHON@
|
||||
|
||||
sfversion=$(./tests/sfversion@EXEEXT@ | grep libsndfile | sed "s/-exp$//")
|
||||
|
||||
if test "$sfversion" != libsndfile-$PACKAGE_VERSION ; then
|
||||
echo "Error : sfversion ($sfversion) and PACKAGE_VERSION ($PACKAGE_VERSION) don't match."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Force exit on errors.
|
||||
set -e
|
||||
|
||||
# Check the header file.
|
||||
/usr/bin/env sh tests/pedantic-header-test.sh
|
||||
|
||||
# Need this for when we're running from files collected into the
|
||||
# libsndfile-testsuite-@PACKAGE_VERSION@ tarball.
|
||||
echo "Running unit tests from src/ directory of source code tree."
|
||||
./src/test_main@EXEEXT@
|
||||
|
||||
echo
|
||||
echo "Running end-to-end tests from tests/ directory."
|
||||
|
||||
./tests/error_test@EXEEXT@
|
||||
./tests/pcm_test@EXEEXT@
|
||||
./tests/ulaw_test@EXEEXT@
|
||||
./tests/alaw_test@EXEEXT@
|
||||
./tests/dwvw_test@EXEEXT@
|
||||
./tests/command_test@EXEEXT@ ver
|
||||
./tests/command_test@EXEEXT@ norm
|
||||
./tests/command_test@EXEEXT@ format
|
||||
./tests/command_test@EXEEXT@ peak
|
||||
./tests/command_test@EXEEXT@ trunc
|
||||
./tests/command_test@EXEEXT@ inst
|
||||
./tests/command_test@EXEEXT@ cue
|
||||
./tests/command_test@EXEEXT@ current_sf_info
|
||||
./tests/command_test@EXEEXT@ bext
|
||||
./tests/command_test@EXEEXT@ bextch
|
||||
./tests/command_test@EXEEXT@ chanmap
|
||||
./tests/command_test@EXEEXT@ cart
|
||||
./tests/floating_point_test@EXEEXT@
|
||||
./tests/checksum_test@EXEEXT@
|
||||
./tests/scale_clip_test@EXEEXT@
|
||||
./tests/headerless_test@EXEEXT@
|
||||
./tests/rdwr_test@EXEEXT@
|
||||
./tests/locale_test@EXEEXT@
|
||||
./tests/win32_ordinal_test@EXEEXT@
|
||||
./tests/external_libs_test@EXEEXT@
|
||||
./tests/format_check_test@EXEEXT@
|
||||
./tests/channel_test@EXEEXT@
|
||||
|
||||
# The w64 G++ compiler requires an extra runtime DLL which we don't have,
|
||||
# so skip this test.
|
||||
case "$HOST_TRIPLET" in
|
||||
x86_64-w64-mingw32)
|
||||
;;
|
||||
i686-w64-mingw32)
|
||||
;;
|
||||
*)
|
||||
./tests/cpp_test@EXEEXT@
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed common tests."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# aiff-tests
|
||||
./tests/write_read_test@EXEEXT@ aiff
|
||||
./tests/lossy_comp_test@EXEEXT@ aiff_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ aiff_alaw
|
||||
./tests/lossy_comp_test@EXEEXT@ aiff_gsm610
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " lossy_comp_test@EXEEXT@ aiff_ima"
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
./tests/peak_chunk_test@EXEEXT@ aiff
|
||||
./tests/header_test@EXEEXT@ aiff
|
||||
./tests/misc_test@EXEEXT@ aiff
|
||||
./tests/string_test@EXEEXT@ aiff
|
||||
./tests/multi_file_test@EXEEXT@ aiff
|
||||
./tests/aiff_rw_test@EXEEXT@
|
||||
./tests/chunk_test@EXEEXT@ aiff
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on AIFF files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# au-tests
|
||||
./tests/write_read_test@EXEEXT@ au
|
||||
./tests/lossy_comp_test@EXEEXT@ au_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ au_alaw
|
||||
./tests/lossy_comp_test@EXEEXT@ au_g721
|
||||
./tests/lossy_comp_test@EXEEXT@ au_g723
|
||||
./tests/header_test@EXEEXT@ au
|
||||
./tests/misc_test@EXEEXT@ au
|
||||
./tests/multi_file_test@EXEEXT@ au
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on AU files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# caf-tests
|
||||
./tests/write_read_test@EXEEXT@ caf
|
||||
./tests/lossy_comp_test@EXEEXT@ caf_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ caf_alaw
|
||||
./tests/header_test@EXEEXT@ caf
|
||||
./tests/peak_chunk_test@EXEEXT@ caf
|
||||
./tests/misc_test@EXEEXT@ caf
|
||||
./tests/chunk_test@EXEEXT@ caf
|
||||
./tests/string_test@EXEEXT@ caf
|
||||
./tests/long_read_write_test@EXEEXT@ alac
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on CAF files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# wav-tests
|
||||
./tests/write_read_test@EXEEXT@ wav
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_pcm
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_ima
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_msadpcm
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_alaw
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_gsm610
|
||||
./tests/lossy_comp_test@EXEEXT@ wav_g721
|
||||
./tests/peak_chunk_test@EXEEXT@ wav
|
||||
./tests/header_test@EXEEXT@ wav
|
||||
./tests/misc_test@EXEEXT@ wav
|
||||
./tests/string_test@EXEEXT@ wav
|
||||
./tests/multi_file_test@EXEEXT@ wav
|
||||
./tests/chunk_test@EXEEXT@ wav
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on WAV files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# w64-tests
|
||||
./tests/write_read_test@EXEEXT@ w64
|
||||
./tests/lossy_comp_test@EXEEXT@ w64_ima
|
||||
./tests/lossy_comp_test@EXEEXT@ w64_msadpcm
|
||||
./tests/lossy_comp_test@EXEEXT@ w64_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ w64_alaw
|
||||
./tests/lossy_comp_test@EXEEXT@ w64_gsm610
|
||||
./tests/header_test@EXEEXT@ w64
|
||||
./tests/misc_test@EXEEXT@ w64
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on W64 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# rf64-tests
|
||||
./tests/write_read_test@EXEEXT@ rf64
|
||||
./tests/header_test@EXEEXT@ rf64
|
||||
./tests/misc_test@EXEEXT@ rf64
|
||||
./tests/string_test@EXEEXT@ rf64
|
||||
./tests/peak_chunk_test@EXEEXT@ rf64
|
||||
./tests/chunk_test@EXEEXT@ rf64
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on RF64 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# raw-tests
|
||||
./tests/write_read_test@EXEEXT@ raw
|
||||
./tests/lossy_comp_test@EXEEXT@ raw_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ raw_alaw
|
||||
./tests/lossy_comp_test@EXEEXT@ raw_gsm610
|
||||
./tests/lossy_comp_test@EXEEXT@ vox_adpcm
|
||||
./tests/raw_test@EXEEXT@
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on RAW (header-less) files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# paf-tests
|
||||
./tests/write_read_test@EXEEXT@ paf
|
||||
./tests/header_test@EXEEXT@ paf
|
||||
./tests/misc_test@EXEEXT@ paf
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on PAF files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# svx-tests
|
||||
./tests/write_read_test@EXEEXT@ svx
|
||||
./tests/header_test@EXEEXT@ svx
|
||||
./tests/misc_test@EXEEXT@ svx
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on SVX files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# nist-tests
|
||||
./tests/write_read_test@EXEEXT@ nist
|
||||
./tests/lossy_comp_test@EXEEXT@ nist_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ nist_alaw
|
||||
./tests/header_test@EXEEXT@ nist
|
||||
./tests/misc_test@EXEEXT@ nist
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on NIST files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# ircam-tests
|
||||
./tests/write_read_test@EXEEXT@ ircam
|
||||
./tests/lossy_comp_test@EXEEXT@ ircam_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ ircam_alaw
|
||||
./tests/header_test@EXEEXT@ ircam
|
||||
./tests/misc_test@EXEEXT@ ircam
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on IRCAM files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# voc-tests
|
||||
./tests/write_read_test@EXEEXT@ voc
|
||||
./tests/lossy_comp_test@EXEEXT@ voc_ulaw
|
||||
./tests/lossy_comp_test@EXEEXT@ voc_alaw
|
||||
./tests/header_test@EXEEXT@ voc
|
||||
./tests/misc_test@EXEEXT@ voc
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on VOC files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# mat4-tests
|
||||
./tests/write_read_test@EXEEXT@ mat4
|
||||
./tests/header_test@EXEEXT@ mat4
|
||||
./tests/misc_test@EXEEXT@ mat4
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on MAT4 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# mat5-tests
|
||||
./tests/write_read_test@EXEEXT@ mat5
|
||||
./tests/header_test@EXEEXT@ mat5
|
||||
./tests/misc_test@EXEEXT@ mat5
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on MAT5 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# pvf-tests
|
||||
./tests/write_read_test@EXEEXT@ pvf
|
||||
./tests/header_test@EXEEXT@ pvf
|
||||
./tests/misc_test@EXEEXT@ pvf
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on PVF files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# xi-tests
|
||||
./tests/lossy_comp_test@EXEEXT@ xi_dpcm
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on XI files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# htk-tests
|
||||
./tests/write_read_test@EXEEXT@ htk
|
||||
./tests/header_test@EXEEXT@ htk
|
||||
./tests/misc_test@EXEEXT@ htk
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on HTK files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# avr-tests
|
||||
./tests/write_read_test@EXEEXT@ avr
|
||||
./tests/header_test@EXEEXT@ avr
|
||||
./tests/misc_test@EXEEXT@ avr
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on AVR files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# sds-tests
|
||||
./tests/write_read_test@EXEEXT@ sds
|
||||
./tests/header_test@EXEEXT@ sds
|
||||
./tests/misc_test@EXEEXT@ sds
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on SDS files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# sd2-tests
|
||||
./tests/write_read_test@EXEEXT@ sd2
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on SD2 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# wve-tests
|
||||
./tests/lossy_comp_test@EXEEXT@ wve
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on WVE files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# mpc2k-tests
|
||||
./tests/write_read_test@EXEEXT@ mpc2k
|
||||
./tests/header_test@EXEEXT@ mpc2k
|
||||
./tests/misc_test@EXEEXT@ mpc2k
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on MPC 2000 files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# flac-tests
|
||||
./tests/write_read_test@EXEEXT@ flac
|
||||
./tests/compression_size_test@EXEEXT@ flac
|
||||
./tests/string_test@EXEEXT@ flac
|
||||
./tests/header_test@EXEEXT@ flac
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on FLAC files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# vorbis-tests
|
||||
./tests/ogg_test@EXEEXT@
|
||||
./tests/compression_size_test@EXEEXT@ vorbis
|
||||
./tests/lossy_comp_test@EXEEXT@ ogg_vorbis
|
||||
./tests/string_test@EXEEXT@ ogg
|
||||
./tests/misc_test@EXEEXT@ ogg
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on OGG/VORBIS files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# opus-tests
|
||||
./tests/ogg_opus_test@EXEEXT@
|
||||
./tests/compression_size_test@EXEEXT@ opus
|
||||
./tests/lossy_comp_test@EXEEXT@ ogg_opus
|
||||
./tests/string_test@EXEEXT@ opus
|
||||
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on OPUS files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# mpeg-tests
|
||||
./tests/mpeg_test@EXEEXT@
|
||||
./tests/compression_size_test@EXEEXT@ mpeg
|
||||
./tests/string_test@EXEEXT@ mpeg
|
||||
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed tests on MPEG files."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
# io-tests
|
||||
./tests/stdio_test@EXEEXT@
|
||||
./tests/pipe_test@EXEEXT@
|
||||
./tests/virtual_io_test@EXEEXT@
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed stdio/pipe/vio tests."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
"${PYTHON}" "${ABS_TOP_SRCDIR}/src/binheader_writef_check.py" "${ABS_TOP_SRCDIR}/src"/*.c
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed binary header tests."
|
||||
echo "----------------------------------------------------------------------"
|
||||
|
||||
"${PYTHON}" "${ABS_TOP_SRCDIR}/programs/test-sndfile-metadata-set.py" "${HOST_TRIPLET}"
|
||||
echo "----------------------------------------------------------------------"
|
||||
echo " $sfversion passed sndfile metadata tests."
|
||||
echo "----------------------------------------------------------------------"
|
||||
259
Engine/lib/libsndfile/tests/ulaw_test.c
Normal file
259
Engine/lib/libsndfile/tests/ulaw_test.c
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2012 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_SIZE (65536)
|
||||
|
||||
static unsigned char ulaw_encode (int sample) ;
|
||||
static int ulaw_decode (unsigned int ulawbyte) ;
|
||||
|
||||
static short short_buffer [BUFFER_SIZE] ;
|
||||
static unsigned char ulaw_buffer [BUFFER_SIZE] ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
const char *filename ;
|
||||
int k ;
|
||||
|
||||
print_test_name ("ulaw_test", "encoder") ;
|
||||
|
||||
filename = "ulaw_test.raw" ;
|
||||
|
||||
sf_info_setup (&sfinfo, SF_FORMAT_RAW | SF_FORMAT_ULAW, 44100, 1) ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Generate a file containing all possible 16 bit sample values
|
||||
** and write it to disk as ulaw encoded.frames.
|
||||
*/
|
||||
|
||||
for (k = 0 ; k < 0x10000 ; k++)
|
||||
short_buffer [k] = k & 0xFFFF ;
|
||||
|
||||
sf_write_short (file, short_buffer, BUFFER_SIZE) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now open that file and compare the ulaw encoded sample values
|
||||
** with what they should be.
|
||||
*/
|
||||
|
||||
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sf_read_raw (file, ulaw_buffer, BUFFER_SIZE) != BUFFER_SIZE)
|
||||
{ printf ("sf_read_raw : ") ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < 0x10000 ; k++)
|
||||
if (ulaw_encode (short_buffer [k]) != ulaw_buffer [k])
|
||||
{ printf ("Encoder error : sample #%d (0x%02X should be 0x%02X)\n", k, ulaw_buffer [k], ulaw_encode (short_buffer [k])) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
print_test_name ("ulaw_test", "decoder") ;
|
||||
|
||||
/* Now generate a file containing all possible 8 bit encoded
|
||||
** sample values and write it to disk as ulaw encoded.frames.
|
||||
*/
|
||||
|
||||
if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < 256 ; k++)
|
||||
ulaw_buffer [k] = k & 0xFF ;
|
||||
|
||||
sf_write_raw (file, ulaw_buffer, 256) ;
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now open that file and compare the ulaw decoded sample values
|
||||
** with what they should be.
|
||||
*/
|
||||
|
||||
if (! (file = sf_open (filename, SFM_READ, &sfinfo)))
|
||||
{ printf ("sf_open_write failed with error : ") ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
|
||||
if (sf_read_short (file, short_buffer, 256) != 256)
|
||||
{ printf ("sf_read_short : ") ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
||||
for (k = 0 ; k < 256 ; k++)
|
||||
if (short_buffer [k] != ulaw_decode (ulaw_buffer [k]))
|
||||
{ printf ("Decoder error : sample #%d (0x%04X should be 0x%04X)\n", k, short_buffer [k], ulaw_decode (ulaw_buffer [k])) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
/*=================================================================================
|
||||
** The following routines came from the sox-12.15 (Sound eXcahcnge) distribution.
|
||||
**
|
||||
** This code is not compiled into libsndfile. It is only used to test the
|
||||
** libsndfile lookup tables for correctness.
|
||||
**
|
||||
** I have included the original authors comments.
|
||||
*/
|
||||
|
||||
/*
|
||||
** This routine converts from linear to ulaw.
|
||||
**
|
||||
** Craig Reese: IDA/Supercomputing Research Center
|
||||
** Joe Campbell: Department of Defense
|
||||
** 29 September 1989
|
||||
**
|
||||
** References:
|
||||
** 1) CCITT Recommendation G.711 (very difficult to follow)
|
||||
** 2) "A New Digital Technique for Implementation of Any
|
||||
** Continuous PCM Companding Law," Villeret, Michel,
|
||||
** et al. 1973 IEEE Int. Conf. on Communications, Vol 1,
|
||||
** 1973, pg. 11.12-11.17
|
||||
** 3) MIL-STD-188-113,"Interoperability and Performance Standards
|
||||
** for Analog-to_Digital Conversion Techniques,"
|
||||
** 17 February 1987
|
||||
**
|
||||
** Input: Signed 16 bit linear sample
|
||||
** Output: 8 bit ulaw sample
|
||||
*/
|
||||
|
||||
#define uBIAS 0x84 /* define the add-in bias for 16 bit.frames */
|
||||
#define uCLIP 32635
|
||||
|
||||
static
|
||||
unsigned char ulaw_encode (int sample)
|
||||
{ static int exp_lut [256] =
|
||||
{ 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
|
||||
} ;
|
||||
|
||||
int sign, exponent, mantissa ;
|
||||
unsigned char ulawbyte ;
|
||||
|
||||
/* Get the sample into sign-magnitude. */
|
||||
sign = (sample >> 8) & 0x80 ; /* set aside the sign */
|
||||
if (sign != 0)
|
||||
sample = -sample ; /* get magnitude */
|
||||
if (sample > uCLIP)
|
||||
sample = uCLIP ; /* clip the magnitude */
|
||||
|
||||
/* Convert from 16 bit linear to ulaw. */
|
||||
sample = sample + uBIAS ;
|
||||
exponent = exp_lut [(sample >> 7) & 0xFF] ;
|
||||
mantissa = (sample >> (exponent + 3)) & 0x0F ;
|
||||
ulawbyte = ~ (sign | (exponent << 4) | mantissa) ;
|
||||
|
||||
return ulawbyte ;
|
||||
} /* ulaw_encode */
|
||||
|
||||
|
||||
/*
|
||||
** This routine converts from ulaw to 16 bit linear.
|
||||
**
|
||||
** Craig Reese: IDA/Supercomputing Research Center
|
||||
** 29 September 1989
|
||||
**
|
||||
** References:
|
||||
** 1) CCITT Recommendation G.711 (very difficult to follow)
|
||||
** 2) MIL-STD-188-113,"Interoperability and Performance Standards
|
||||
** for Analog-to_Digital Conversion Techniques,"
|
||||
** 17 February 1987
|
||||
**
|
||||
** Input: 8 bit ulaw sample
|
||||
** Output: signed 16 bit linear sample
|
||||
*/
|
||||
|
||||
static
|
||||
int ulaw_decode (unsigned int ulawbyte)
|
||||
{ static int exp_lut [8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 } ;
|
||||
int sign, exponent, mantissa, sample ;
|
||||
|
||||
ulawbyte = ~ ulawbyte ;
|
||||
sign = (ulawbyte & 0x80) ;
|
||||
exponent = (ulawbyte >> 4) & 0x07 ;
|
||||
mantissa = ulawbyte & 0x0F ;
|
||||
sample = exp_lut [exponent] + (mantissa << (exponent + 3)) ;
|
||||
if (sign != 0)
|
||||
sample = -sample ;
|
||||
|
||||
return sample ;
|
||||
} /* ulaw_decode */
|
||||
|
||||
52
Engine/lib/libsndfile/tests/utils.def
Normal file
52
Engine/lib/libsndfile/tests/utils.def
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
autogen definitions utils.tpl;
|
||||
|
||||
float_type = {
|
||||
name = float ;
|
||||
};
|
||||
|
||||
float_type = {
|
||||
name = double ;
|
||||
};
|
||||
|
||||
/*----------------------------------*/
|
||||
|
||||
io_type = {
|
||||
io_element = short ;
|
||||
format_str = "\"% d\"" ;
|
||||
};
|
||||
|
||||
io_type = {
|
||||
io_element = int ;
|
||||
format_str = "\"% d\"" ;
|
||||
};
|
||||
|
||||
io_type = {
|
||||
io_element = float ;
|
||||
format_str = "\"% g\"" ;
|
||||
};
|
||||
|
||||
io_type = {
|
||||
io_element = double ;
|
||||
format_str = "\"% g\"" ;
|
||||
};
|
||||
|
||||
read_op = {
|
||||
op_element = read ;
|
||||
count_name = items ;
|
||||
};
|
||||
|
||||
read_op = {
|
||||
op_element = readf ;
|
||||
count_name = frames ;
|
||||
};
|
||||
|
||||
write_op = {
|
||||
op_element = write ;
|
||||
count_name = items ;
|
||||
};
|
||||
|
||||
write_op = {
|
||||
op_element = writef ;
|
||||
count_name = frames ;
|
||||
};
|
||||
|
||||
961
Engine/lib/libsndfile/tests/utils.tpl
Normal file
961
Engine/lib/libsndfile/tests/utils.tpl
Normal file
|
|
@ -0,0 +1,961 @@
|
|||
[+ AutoGen5 template h c +]
|
||||
/*
|
||||
** Copyright (C) 2002-2018 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Utility functions to make writing the test suite easier.
|
||||
**
|
||||
** The .c and .h files were generated automagically with Autogen from
|
||||
** the files utils.def and utils.tpl.
|
||||
*/
|
||||
|
||||
[+ CASE (suffix) +]
|
||||
[+ == h +]
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
|
||||
#define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x)))
|
||||
#define NOT(x) (! (x))
|
||||
#define ABS(x) ((x) >= 0 ? (x) : - (x))
|
||||
|
||||
#define PIPE_INDEX(x) ((x) + 500)
|
||||
#define PIPE_TEST_LEN 12345
|
||||
|
||||
|
||||
[+ FOR float_type
|
||||
+]void gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum) ;
|
||||
[+ ENDFOR float_type
|
||||
+]
|
||||
|
||||
void create_short_sndfile (const char *filename, int format, int channels) ;
|
||||
|
||||
void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ;
|
||||
|
||||
void print_test_name (const char *test, const char *filename) ;
|
||||
|
||||
void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ;
|
||||
|
||||
void write_mono_file (const char * filename, int format, int srate, float * output, int len) ;
|
||||
|
||||
#ifdef __GNUC__
|
||||
static inline void
|
||||
exit_if_true (int test, const char *format, ...)
|
||||
#if (defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO && !defined (__clang__))
|
||||
__attribute__ ((format (gnu_printf, 2, 3))) ;
|
||||
#else
|
||||
__attribute__ ((format (printf, 2, 3))) ;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
exit_if_true (int test, const char *format, ...)
|
||||
{ if (test)
|
||||
{ va_list argptr ;
|
||||
va_start (argptr, format) ;
|
||||
vprintf (format, argptr) ;
|
||||
va_end (argptr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} /* exit_if_true */
|
||||
|
||||
static inline int32_t
|
||||
arith_shift_left (int32_t x, int shift)
|
||||
{ return (int32_t) (((uint32_t) x) << shift) ;
|
||||
} /* arith_shift_left */
|
||||
|
||||
/*
|
||||
** Functions for saving two vectors of data in an ascii text file which
|
||||
** can then be loaded into GNU octave for comparison.
|
||||
*/
|
||||
|
||||
[+ FOR io_type
|
||||
+]int oct_save_[+ (get "io_element") +] (const [+ (get "io_element") +] *a, const [+ (get "io_element") +] *b, int len) ;
|
||||
[+ ENDFOR io_type
|
||||
+]
|
||||
|
||||
void delete_file (int format, const char *filename) ;
|
||||
|
||||
int truncate_file_to_zero (const char *fname) ;
|
||||
|
||||
void count_open_files (void) ;
|
||||
void increment_open_file_count (void) ;
|
||||
void check_open_file_count_or_die (int lineno) ;
|
||||
|
||||
void get_unique_test_name (const char ** filename, const char * test) ;
|
||||
|
||||
#ifdef SNDFILE_H
|
||||
|
||||
static inline void
|
||||
sf_info_clear (SF_INFO * info)
|
||||
{ memset (info, 0, sizeof (SF_INFO)) ;
|
||||
} /* sf_info_clear */
|
||||
|
||||
static inline void
|
||||
sf_info_setup (SF_INFO * info, int format, int samplerate, int channels)
|
||||
{ sf_info_clear (info) ;
|
||||
|
||||
info->format = format ;
|
||||
info->samplerate = samplerate ;
|
||||
info->channels = channels ;
|
||||
} /* sf_info_setup */
|
||||
|
||||
|
||||
void dump_log_buffer (SNDFILE *file) ;
|
||||
void check_log_buffer_or_die (SNDFILE *file, int line_num) ;
|
||||
int string_in_log_buffer (SNDFILE *file, const char *s) ;
|
||||
void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ;
|
||||
|
||||
void test_sf_format_or_die (const SF_INFO *info, int line_num) ;
|
||||
|
||||
SNDFILE *test_open_file_or_die
|
||||
(const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ;
|
||||
|
||||
void test_read_write_position_or_die
|
||||
(SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ;
|
||||
|
||||
void test_seek_or_die
|
||||
(SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ;
|
||||
|
||||
[+ FOR read_op +]
|
||||
[+ FOR io_type
|
||||
+]void test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die
|
||||
(SNDFILE *file, int pass, [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num) ;
|
||||
[+ ENDFOR io_type +][+ ENDFOR read_op +]
|
||||
|
||||
void
|
||||
test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ;
|
||||
|
||||
[+ FOR write_op +]
|
||||
[+ FOR io_type
|
||||
+]void test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die
|
||||
(SNDFILE *file, int pass, const [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num) ;
|
||||
[+ ENDFOR io_type +][+ ENDFOR write_op +]
|
||||
|
||||
void
|
||||
test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ;
|
||||
|
||||
[+ FOR io_type
|
||||
+]void compare_[+ (get "io_element") +]_or_die (const [+ (get "io_element") +] *expected, const [+ (get "io_element") +] *actual, unsigned count, int line_num) ;
|
||||
[+ ENDFOR io_type +]
|
||||
|
||||
|
||||
void gen_lowpass_signal_float (float *data, int len) ;
|
||||
|
||||
sf_count_t file_length (const char * fname) ;
|
||||
sf_count_t file_length_fd (int fd) ;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
[+ == c +]
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
#define LOG_BUFFER_SIZE 4096
|
||||
|
||||
/*
|
||||
** Neat solution to the Win32/OS2 binary file flage requirement.
|
||||
** If O_BINARY isn't already defined by the inclusion of the system
|
||||
** headers, set it to zero.
|
||||
*/
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Compare for equality, with epsilon
|
||||
*/
|
||||
static inline int
|
||||
equals_short (const short a, const short b)
|
||||
{ return (a == b);
|
||||
} /* equals_short */
|
||||
static inline int
|
||||
equals_int (const int a, const int b)
|
||||
{ return (a == b);
|
||||
} /* equals_int */
|
||||
static inline int
|
||||
equals_float (const float a, const float b)
|
||||
{ return (fabsf(a - b) <= FLT_EPSILON);
|
||||
} /* equals_float */
|
||||
static inline int
|
||||
equals_double (const double a, const double b)
|
||||
{ return (fabs(a - b) <= DBL_EPSILON);
|
||||
} /* equals_double */
|
||||
|
||||
|
||||
[+ FOR float_type +]
|
||||
void
|
||||
gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum)
|
||||
{ int k ;
|
||||
|
||||
memset (data, 0, len * sizeof ([+ (get "name") +])) ;
|
||||
|
||||
len = (5 * len) / 6 ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{ data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ;
|
||||
|
||||
/* Apply Hanning Window. */
|
||||
data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ;
|
||||
}
|
||||
|
||||
return ;
|
||||
} /* gen_windowed_sine_[+ (get "name") +] */
|
||||
[+ ENDFOR float_type +]
|
||||
|
||||
void
|
||||
create_short_sndfile (const char *filename, int format, int channels)
|
||||
{ short data [2 * 3 * 4 * 5 * 6 * 7] = { 0, } ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.channels = channels ;
|
||||
sfinfo.format = format ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("Error (%s, %d) : sf_open failed : %s\n", __FILE__, __LINE__, sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_write_short (file, data, ARRAY_LEN (data)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
} /* create_short_sndfile */
|
||||
|
||||
void
|
||||
check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num)
|
||||
{ static unsigned char buf [4096] ;
|
||||
uint64_t cksum ;
|
||||
FILE *file ;
|
||||
int k, read_count ;
|
||||
|
||||
memset (buf, 0, sizeof (buf)) ;
|
||||
|
||||
/* The 'b' in the mode string means binary for Win32. */
|
||||
if ((file = fopen (filename, "rb")) == NULL)
|
||||
{ printf ("\n\nLine %d: could not open file '%s'\n\n", line_num, filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
cksum = 0 ;
|
||||
|
||||
while ((read_count = fread (buf, 1, sizeof (buf), file)))
|
||||
for (k = 0 ; k < read_count ; k++)
|
||||
cksum = (cksum * 511 + buf [k]) & 0xfffffffffffff ;
|
||||
|
||||
fclose (file) ;
|
||||
|
||||
if (target_hash == 0)
|
||||
{ printf (" 0x%" PRIx64 "\n", cksum) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
if (cksum != target_hash)
|
||||
{ printf ("\n\nLine %d: incorrect hash value 0x%" PRIx64 " should be 0x%" PRIx64 ".\n\n", line_num, cksum, target_hash) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* check_file_hash_or_die */
|
||||
|
||||
void
|
||||
print_test_name (const char *test, const char *filename)
|
||||
{ int count ;
|
||||
|
||||
if (test == NULL)
|
||||
{ printf (__FILE__ ": bad test of filename parameter.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (filename == NULL || strlen (filename) == 0)
|
||||
{ printf (" %-30s : ", test) ;
|
||||
count = 25 ;
|
||||
}
|
||||
else
|
||||
{ printf (" %-30s : %s ", test, filename) ;
|
||||
count = 24 - strlen (filename) ;
|
||||
} ;
|
||||
|
||||
while (count -- > 0)
|
||||
putchar ('.') ;
|
||||
putchar (' ') ;
|
||||
|
||||
fflush (stdout) ;
|
||||
} /* print_test_name */
|
||||
|
||||
void
|
||||
dump_data_to_file (const char *filename, const void *data, unsigned int datalen)
|
||||
{ FILE *file ;
|
||||
|
||||
if ((file = fopen (filename, "wb")) == NULL)
|
||||
{ printf ("\n\nLine %d : could not open file : %s\n\n", __LINE__, filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fwrite (data, 1, datalen, file) != datalen)
|
||||
{ printf ("\n\nLine %d : fwrite failed.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
fclose (file) ;
|
||||
|
||||
} /* dump_data_to_file */
|
||||
|
||||
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
*/
|
||||
|
||||
static char octfilename [] = "error.dat" ;
|
||||
|
||||
[+ FOR io_type
|
||||
+]int
|
||||
oct_save_[+ (get "io_element") +] (const [+ (get "io_element") +] *a, const [+ (get "io_element") +] *b, int len)
|
||||
{ FILE *file ;
|
||||
int k ;
|
||||
|
||||
if (! (file = fopen (octfilename, "w")))
|
||||
return 1 ;
|
||||
|
||||
fprintf (file, "# Not created by Octave\n") ;
|
||||
|
||||
fprintf (file, "# name: a\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
fprintf (file, [+ (get "format_str") +] "\n", a [k]) ;
|
||||
|
||||
fprintf (file, "# name: b\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
fprintf (file, [+ (get "format_str") +] "\n", b [k]) ;
|
||||
|
||||
fclose (file) ;
|
||||
return 0 ;
|
||||
} /* oct_save_[+ (get "io_element") +] */
|
||||
[+ ENDFOR io_type
|
||||
+]
|
||||
|
||||
void
|
||||
check_log_buffer_or_die (SNDFILE *file, int line_num)
|
||||
{ static char buffer [LOG_BUFFER_SIZE] ;
|
||||
int count ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Get the log buffer data. */
|
||||
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
||||
|
||||
if (LOG_BUFFER_SIZE - count < 2)
|
||||
{ printf ("\n\nLine %d : Possible long log buffer.\n", line_num) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
/* Look for "Should" */
|
||||
if (strstr (buffer, "ould"))
|
||||
{ printf ("\n\nLine %d : Log buffer contains `ould'. Dumping.\n", line_num) ;
|
||||
puts (buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Look for "**" */
|
||||
if (strstr (buffer, "*"))
|
||||
{ printf ("\n\nLine %d : Log buffer contains `*'. Dumping.\n", line_num) ;
|
||||
puts (buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Look for "Should" */
|
||||
if (strstr (buffer, "nknown marker"))
|
||||
{ printf ("\n\nLine %d : Log buffer contains `nknown marker'. Dumping.\n", line_num) ;
|
||||
puts (buffer) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* check_log_buffer_or_die */
|
||||
|
||||
int
|
||||
string_in_log_buffer (SNDFILE *file, const char *s)
|
||||
{ static char buffer [LOG_BUFFER_SIZE] ;
|
||||
int count ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Get the log buffer data. */
|
||||
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
||||
|
||||
if (LOG_BUFFER_SIZE - count < 2)
|
||||
{ printf ("Possible long log buffer.\n") ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
/* Look for string */
|
||||
return strstr (buffer, s) ? SF_TRUE : SF_FALSE ;
|
||||
} /* string_in_log_buffer */
|
||||
|
||||
void
|
||||
hexdump_file (const char * filename, sf_count_t offset, sf_count_t length)
|
||||
{
|
||||
FILE * file ;
|
||||
char buffer [16] ;
|
||||
int k, m, ch, readcount ;
|
||||
|
||||
if (length > 1000000)
|
||||
{ printf ("\n\nError : length (%" PRId64 ") too long.\n\n", offset) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
{ printf ("\n\nError : hexdump_file (%s) could not open file for read.\n\n", filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fseek (file, offset, SEEK_SET) != 0)
|
||||
{ printf ("\n\nError : fseek(file, %" PRId64 ", SEEK_SET) failed : %s\n\n", offset, strerror (errno)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("\n\n") ;
|
||||
|
||||
for (k = 0 ; k < length ; k+= sizeof (buffer))
|
||||
{ readcount = fread (buffer, 1, sizeof (buffer), file) ;
|
||||
|
||||
printf ("%08" PRIx64 " : ", offset + k) ;
|
||||
|
||||
for (m = 0 ; m < readcount ; m++)
|
||||
printf ("%02x ", buffer [m] & 0xFF) ;
|
||||
|
||||
for (m = readcount ; m < SIGNED_SIZEOF (buffer) ; m++)
|
||||
printf (" ") ;
|
||||
|
||||
printf (" ") ;
|
||||
for (m = 0 ; m < readcount ; m++)
|
||||
{ ch = isprint (buffer [m]) ? buffer [m] : '.' ;
|
||||
putchar (ch) ;
|
||||
} ;
|
||||
|
||||
if (readcount < SIGNED_SIZEOF (buffer))
|
||||
break ;
|
||||
|
||||
putchar ('\n') ;
|
||||
} ;
|
||||
|
||||
puts ("\n") ;
|
||||
|
||||
fclose (file) ;
|
||||
} /* hexdump_file */
|
||||
|
||||
void
|
||||
dump_log_buffer (SNDFILE *file)
|
||||
{ static char buffer [LOG_BUFFER_SIZE] ;
|
||||
|
||||
memset (buffer, 0, sizeof (buffer)) ;
|
||||
|
||||
/* Get the log buffer data. */
|
||||
sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
||||
|
||||
if (strlen (buffer) < 1)
|
||||
puts ("Log buffer empty.\n") ;
|
||||
else
|
||||
puts (buffer) ;
|
||||
|
||||
return ;
|
||||
} /* dump_log_buffer */
|
||||
|
||||
void
|
||||
test_sf_format_or_die (const SF_INFO *info, int line_num)
|
||||
{ int res ;
|
||||
|
||||
if ((res = sf_format_check (info)) != 1)
|
||||
{ printf ("\n\nLine %d : sf_format_check returned error (%d)\n\n", line_num, res) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_sf_format_or_die */
|
||||
|
||||
SNDFILE *
|
||||
test_open_file_or_die (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num)
|
||||
{ static int count = 0 ;
|
||||
|
||||
SNDFILE *file ;
|
||||
const char *modestr, *func_name ;
|
||||
int oflags = 0, omode = 0, err ;
|
||||
|
||||
/*
|
||||
** Need to test both sf_open() and sf_open_fd().
|
||||
** Do so alternately.
|
||||
*/
|
||||
switch (mode)
|
||||
{ case SFM_READ :
|
||||
modestr = "SFM_READ" ;
|
||||
oflags = O_RDONLY | O_BINARY ;
|
||||
omode = 0 ;
|
||||
break ;
|
||||
|
||||
case SFM_WRITE :
|
||||
modestr = "SFM_WRITE" ;
|
||||
oflags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
|
||||
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
|
||||
break ;
|
||||
|
||||
case SFM_RDWR :
|
||||
modestr = "SFM_RDWR" ;
|
||||
oflags = O_RDWR | O_CREAT | O_BINARY ;
|
||||
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
|
||||
break ;
|
||||
default :
|
||||
printf ("\n\nLine %d: Bad mode.\n", line_num) ;
|
||||
fflush (stdout) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (OS_IS_WIN32)
|
||||
{ /* Windows does not understand and ignores the S_IRGRP flag, but Wine
|
||||
** gives a run time warning message, so just clear it.
|
||||
*/
|
||||
omode &= ~S_IRGRP ;
|
||||
} ;
|
||||
|
||||
if (allow_fd && ((++count) & 1) == 1)
|
||||
{ int fd ;
|
||||
|
||||
/* Only use the three argument open() function if omode != 0. */
|
||||
fd = (omode == 0) ? open (filename, oflags) : open (filename, oflags, omode) ;
|
||||
|
||||
if (fd < 0)
|
||||
{ printf ("\n\n%s : open failed : %s\n", __func__, strerror (errno)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
func_name = "sf_open_fd" ;
|
||||
file = sf_open_fd (fd, mode, sfinfo, SF_TRUE) ;
|
||||
}
|
||||
else
|
||||
{ func_name = "sf_open" ;
|
||||
file = sf_open (filename, mode, sfinfo) ;
|
||||
} ;
|
||||
|
||||
if (file == NULL)
|
||||
{ printf ("\n\nLine %d: %s (%s) failed : %s\n\n", line_num, func_name, modestr, sf_strerror (NULL)) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
err = sf_error (file) ;
|
||||
if (err != SF_ERR_NO_ERROR)
|
||||
{ printf ("\n\nLine %d : sf_error : %s\n\n", line_num, sf_error_number (err)) ;
|
||||
dump_log_buffer (file) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return file ;
|
||||
} /* test_open_file_or_die */
|
||||
|
||||
void
|
||||
test_read_write_position_or_die (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos)
|
||||
{ sf_count_t pos ;
|
||||
|
||||
/* Check the current read position. */
|
||||
if (read_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_READ)) != read_pos)
|
||||
{ printf ("\n\nLine %d ", line_num) ;
|
||||
if (pass > 0)
|
||||
printf ("(pass %d): ", pass) ;
|
||||
printf ("Read position (%" PRId64 ") should be %" PRId64 ".\n", pos, read_pos) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check the current write position. */
|
||||
if (write_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_WRITE)) != write_pos)
|
||||
{ printf ("\n\nLine %d", line_num) ;
|
||||
if (pass > 0)
|
||||
printf (" (pass %d)", pass) ;
|
||||
printf (" : Write position (%" PRId64 ") should be %" PRId64 ".\n", pos, write_pos) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_read_write_position */
|
||||
|
||||
void
|
||||
test_seek_or_die (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num)
|
||||
{ sf_count_t position ;
|
||||
const char *channel_name, *whence_name ;
|
||||
|
||||
switch (whence)
|
||||
{ case SEEK_SET :
|
||||
whence_name = "SEEK_SET" ;
|
||||
break ;
|
||||
case SEEK_CUR :
|
||||
whence_name = "SEEK_CUR" ;
|
||||
break ;
|
||||
case SEEK_END :
|
||||
whence_name = "SEEK_END" ;
|
||||
break ;
|
||||
|
||||
/* SFM_READ */
|
||||
case SEEK_SET | SFM_READ :
|
||||
whence_name = "SFM_READ | SEEK_SET" ;
|
||||
break ;
|
||||
case SEEK_CUR | SFM_READ :
|
||||
whence_name = "SFM_READ | SEEK_CUR" ;
|
||||
break ;
|
||||
case SEEK_END | SFM_READ :
|
||||
whence_name = "SFM_READ | SEEK_END" ;
|
||||
break ;
|
||||
|
||||
/* SFM_WRITE */
|
||||
case SEEK_SET | SFM_WRITE :
|
||||
whence_name = "SFM_WRITE | SEEK_SET" ;
|
||||
break ;
|
||||
case SEEK_CUR | SFM_WRITE :
|
||||
whence_name = "SFM_WRITE | SEEK_CUR" ;
|
||||
break ;
|
||||
case SEEK_END | SFM_WRITE :
|
||||
whence_name = "SFM_WRITE | SEEK_END" ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
printf ("\n\nLine %d: bad whence parameter.\n", line_num) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
channel_name = (channels == 1) ? "Mono" : "Stereo" ;
|
||||
|
||||
if ((position = sf_seek (file, offset, whence)) != new_pos)
|
||||
{ printf ("\n\nLine %d : %s : sf_seek (file, %" PRId64 ", %s) returned %" PRId64 " (should be %" PRId64 ").\n\n",
|
||||
line_num, channel_name, offset, whence_name, position, new_pos) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
} /* test_seek_or_die */
|
||||
|
||||
[+ FOR read_op +]
|
||||
[+ FOR io_type +]
|
||||
void
|
||||
test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die (SNDFILE *file, int pass, [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num)
|
||||
{ sf_count_t count ;
|
||||
|
||||
if ((count = sf_[+ (get "op_element") +]_[+ (get "io_element") +] (file, test, [+ (get "count_name") +])) != [+ (get "count_name") +])
|
||||
{ printf ("\n\nLine %d", line_num) ;
|
||||
if (pass > 0)
|
||||
printf (" (pass %d)", pass) ;
|
||||
printf (" : sf_[+ (get "op_element") +]_[+ (get "io_element") +] failed with short [+ (get "op_element") +] (%" PRId64 " => %" PRId64 ").\n",
|
||||
[+ (get "count_name") +], count) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die */
|
||||
[+ ENDFOR io_type +][+ ENDFOR read_op +]
|
||||
|
||||
void
|
||||
test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num)
|
||||
{ sf_count_t count ;
|
||||
|
||||
if ((count = sf_read_raw (file, test, items)) != items)
|
||||
{ printf ("\n\nLine %d", line_num) ;
|
||||
if (pass > 0)
|
||||
printf (" (pass %d)", pass) ;
|
||||
printf (" : sf_read_raw failed with short read (%" PRId64 " => %" PRId64 ").\n", items, count) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_read_raw_or_die */
|
||||
|
||||
[+ FOR write_op +]
|
||||
[+ FOR io_type +]
|
||||
void
|
||||
test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die (SNDFILE *file, int pass, const [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num)
|
||||
{ sf_count_t count ;
|
||||
|
||||
if ((count = sf_[+ (get "op_element") +]_[+ (get "io_element") +] (file, test, [+ (get "count_name") +])) != [+ (get "count_name") +])
|
||||
{ printf ("\n\nLine %d", line_num) ;
|
||||
if (pass > 0)
|
||||
printf (" (pass %d)", pass) ;
|
||||
printf (" : sf_[+ (get "op_element") +]_[+ (get "io_element") +] failed with short [+ (get "op_element") +] (%" PRId64 " => %" PRId64 ").\n",
|
||||
[+ (get "count_name") +], count) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die */
|
||||
[+ ENDFOR io_type +][+ ENDFOR write_op +]
|
||||
|
||||
void
|
||||
test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num)
|
||||
{ sf_count_t count ;
|
||||
|
||||
if ((count = sf_write_raw (file, test, items)) != items)
|
||||
{ printf ("\n\nLine %d", line_num) ;
|
||||
if (pass > 0)
|
||||
printf (" (pass %d)", pass) ;
|
||||
printf (" : sf_write_raw failed with short write (%" PRId64 " => %" PRId64 ").\n", items, count) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* test_write_raw_or_die */
|
||||
|
||||
|
||||
[+ FOR io_type
|
||||
+]void
|
||||
compare_[+ (get "io_element") +]_or_die (const [+ (get "io_element") +] *expected, const [+ (get "io_element") +] *actual, unsigned count, int line_num)
|
||||
{
|
||||
unsigned k ;
|
||||
|
||||
for (k = 0 ; k < count ; k++)
|
||||
if (!equals_[+ (get "io_element") +](expected [k], actual [k]))
|
||||
{ printf ("\n\nLine %d : Error at index %d, got " [+ (get "format_str") +] ", should be " [+ (get "format_str") +] "(delta=" [+ (get "format_str") +] " ).\n\n", line_num, k, actual [k], expected [k], actual [k] - expected [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* compare_[+ (get "io_element") +]_or_die */
|
||||
[+ ENDFOR io_type +]
|
||||
|
||||
|
||||
void
|
||||
delete_file (int format, const char *filename)
|
||||
{ char rsrc_name [512], *fname ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_SD2)
|
||||
return ;
|
||||
|
||||
/*
|
||||
** Now try for a resource fork stored as a separate file.
|
||||
** Grab the un-adulterated filename again.
|
||||
*/
|
||||
snprintf (rsrc_name, sizeof (rsrc_name), "%s", filename) ;
|
||||
|
||||
if ((fname = strrchr (rsrc_name, '/')) != NULL)
|
||||
fname ++ ;
|
||||
else if ((fname = strrchr (rsrc_name, '\\')) != NULL)
|
||||
fname ++ ;
|
||||
else
|
||||
fname = rsrc_name ;
|
||||
|
||||
memmove (fname + 2, fname, strlen (fname) + 1) ;
|
||||
fname [0] = '.' ;
|
||||
fname [1] = '_' ;
|
||||
|
||||
unlink (rsrc_name) ;
|
||||
} /* delete_file */
|
||||
|
||||
int
|
||||
truncate_file_to_zero (const char * fname)
|
||||
{ FILE * file ;
|
||||
|
||||
if ((file = fopen (fname, "w")) == NULL)
|
||||
return errno ;
|
||||
fclose (file) ;
|
||||
|
||||
return 0 ;
|
||||
} /* truncate_file_to_zero */
|
||||
|
||||
static int allowed_open_files = -1 ;
|
||||
|
||||
void
|
||||
count_open_files (void)
|
||||
{
|
||||
#if OS_IS_WIN32
|
||||
return ;
|
||||
#else
|
||||
int k, count = 0 ;
|
||||
struct stat statbuf ;
|
||||
|
||||
if (allowed_open_files > 0)
|
||||
return ;
|
||||
|
||||
for (k = 0 ; k < 1024 ; k++)
|
||||
if (fstat (k, &statbuf) == 0)
|
||||
count ++ ;
|
||||
|
||||
allowed_open_files = count ;
|
||||
#endif
|
||||
} /* count_open_files */
|
||||
|
||||
void
|
||||
increment_open_file_count (void)
|
||||
{ allowed_open_files ++ ;
|
||||
} /* increment_open_file_count */
|
||||
|
||||
void
|
||||
check_open_file_count_or_die (int lineno)
|
||||
{
|
||||
#if OS_IS_WIN32
|
||||
(void) lineno ;
|
||||
return ;
|
||||
#else
|
||||
int k, count = 0 ;
|
||||
struct stat statbuf ;
|
||||
|
||||
if (allowed_open_files < 0)
|
||||
count_open_files () ;
|
||||
|
||||
for (k = 0 ; k < 1024 ; k++)
|
||||
if (fstat (k, &statbuf) == 0)
|
||||
count ++ ;
|
||||
|
||||
if (count > allowed_open_files)
|
||||
{ printf ("\nLine %d : number of open files (%d) > allowed (%d).\n\n", lineno, count, allowed_open_files) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
#endif
|
||||
} /* check_open_file_count_or_die */
|
||||
|
||||
void
|
||||
get_unique_test_name (const char ** filename, const char * test)
|
||||
{ static char buffer [1024] ;
|
||||
|
||||
snprintf (buffer, sizeof (buffer), "%s_%s", test, *filename) ;
|
||||
|
||||
*filename = buffer ;
|
||||
} /* get_unique_test_name */
|
||||
|
||||
void
|
||||
write_mono_file (const char * filename, int format, int srate, float * output, int len)
|
||||
{ SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
sfinfo.samplerate = srate ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.format = format ;
|
||||
|
||||
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("sf_open (%s) : %s\n", filename, sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
sf_write_float (file, output, len) ;
|
||||
|
||||
sf_close (file) ;
|
||||
} /* write_mono_file */
|
||||
|
||||
void
|
||||
gen_lowpass_signal_float (float *data, int len)
|
||||
{ int64_t value = 0x1243456 ;
|
||||
double sample, last_val = 0.0 ;
|
||||
int k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{ /* Not a crypto quality RNG. */
|
||||
value = (11117 * value + 211231) & 0xffffffff ;
|
||||
value = (11117 * value + 211231) & 0xffffffff ;
|
||||
value = (11117 * value + 211231) & 0xffffffff ;
|
||||
|
||||
sample = value / (0x7fffffff * 1.000001) ;
|
||||
sample = 0.2 * sample - 0.9 * last_val ;
|
||||
|
||||
last_val = sample ;
|
||||
|
||||
data [k] = 0.5 * (sample + sin (2.0 * k * M_PI * 1.0 / 32.0)) ;
|
||||
} ;
|
||||
|
||||
} /* gen_lowpass_signal_float */
|
||||
|
||||
|
||||
/*
|
||||
** Windows is fucked.
|
||||
** If a file is opened R/W and data is written to it, then fstat will return
|
||||
** the correct file length, but stat will return zero.
|
||||
*/
|
||||
|
||||
sf_count_t
|
||||
file_length (const char * fname)
|
||||
{ struct stat data ;
|
||||
|
||||
if (stat (fname, &data) != 0)
|
||||
return 0 ;
|
||||
|
||||
return (sf_count_t) data.st_size ;
|
||||
} /* file_length */
|
||||
|
||||
sf_count_t
|
||||
file_length_fd (int fd)
|
||||
{ struct stat data ;
|
||||
|
||||
memset (&data, 0, sizeof (data)) ;
|
||||
if (fstat (fd, &data) != 0)
|
||||
return 0 ;
|
||||
|
||||
return (sf_count_t) data.st_size ;
|
||||
} /* file_length_fd */
|
||||
|
||||
|
||||
[+ ESAC +]
|
||||
|
||||
237
Engine/lib/libsndfile/tests/virtual_io_test.c
Normal file
237
Engine/lib/libsndfile/tests/virtual_io_test.c
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
** Copyright (C) 1999-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static void vio_test (const char *fname, int format) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
vio_test ("vio_pcm16.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
vio_test ("vio_pcm24.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ;
|
||||
vio_test ("vio_float.au", SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
vio_test ("vio_pcm24.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_24) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ sf_count_t offset, length ;
|
||||
unsigned char data [16 * 1024] ;
|
||||
} VIO_DATA ;
|
||||
|
||||
static sf_count_t
|
||||
vfget_filelen (void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *) user_data ;
|
||||
|
||||
return vf->length ;
|
||||
} /* vfget_filelen */
|
||||
|
||||
static sf_count_t
|
||||
vfseek (sf_count_t offset, int whence, void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *) user_data ;
|
||||
|
||||
switch (whence)
|
||||
{ case SEEK_SET :
|
||||
vf->offset = offset ;
|
||||
break ;
|
||||
|
||||
case SEEK_CUR :
|
||||
vf->offset = vf->offset + offset ;
|
||||
break ;
|
||||
|
||||
case SEEK_END :
|
||||
vf->offset = vf->length + offset ;
|
||||
break ;
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
return vf->offset ;
|
||||
} /* vfseek */
|
||||
|
||||
static sf_count_t
|
||||
vfread (void *ptr, sf_count_t count, void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *) user_data ;
|
||||
|
||||
/*
|
||||
** This will break badly for files over 2Gig in length, but
|
||||
** is sufficient for testing.
|
||||
*/
|
||||
if (vf->offset + count > vf->length)
|
||||
count = vf->length - vf->offset ;
|
||||
|
||||
memcpy (ptr, vf->data + vf->offset, count) ;
|
||||
vf->offset += count ;
|
||||
|
||||
return count ;
|
||||
} /* vfread */
|
||||
|
||||
static sf_count_t
|
||||
vfwrite (const void *ptr, sf_count_t count, void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *) user_data ;
|
||||
|
||||
/*
|
||||
** This will break badly for files over 2Gig in length, but
|
||||
** is sufficient for testing.
|
||||
*/
|
||||
if (vf->offset >= SIGNED_SIZEOF (vf->data))
|
||||
return 0 ;
|
||||
|
||||
if (vf->offset + count > SIGNED_SIZEOF (vf->data))
|
||||
count = sizeof (vf->data) - vf->offset ;
|
||||
|
||||
memcpy (vf->data + vf->offset, ptr, (size_t) count) ;
|
||||
vf->offset += count ;
|
||||
|
||||
if (vf->offset > vf->length)
|
||||
vf->length = vf->offset ;
|
||||
|
||||
return count ;
|
||||
} /* vfwrite */
|
||||
|
||||
static sf_count_t
|
||||
vftell (void *user_data)
|
||||
{ VIO_DATA *vf = (VIO_DATA *) user_data ;
|
||||
|
||||
return vf->offset ;
|
||||
} /* vftell */
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
gen_short_data (short * data, int len, int start)
|
||||
{ int k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
data [k] = start + k ;
|
||||
} /* gen_short_data */
|
||||
|
||||
|
||||
static void
|
||||
check_short_data (short * data, int len, int start, int line)
|
||||
{ int k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
if (data [k] != start + k)
|
||||
{ printf ("\n\nLine %d : data [%d] = %d (should be %d).\n\n", line, k, data [k], start + k) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} /* gen_short_data */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void
|
||||
vio_test (const char *fname, int format)
|
||||
{ static VIO_DATA vio_data ;
|
||||
static short data [256] ;
|
||||
|
||||
SF_VIRTUAL_IO vio ;
|
||||
SNDFILE * file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
print_test_name ("virtual i/o test", fname) ;
|
||||
|
||||
/* Set up pointers to the locally defined functions. */
|
||||
vio.get_filelen = vfget_filelen ;
|
||||
vio.seek = vfseek ;
|
||||
vio.read = vfread ;
|
||||
vio.write = vfwrite ;
|
||||
vio.tell = vftell ;
|
||||
|
||||
/* Set virtual file offset and length to zero. */
|
||||
vio_data.offset = 0 ;
|
||||
vio_data.length = 0 ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 2 ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
|
||||
if ((file = sf_open_virtual (&vio, SFM_WRITE, &sfinfo, &vio_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open_write failed with error : ", __LINE__) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (vfget_filelen (&vio_data) < 0)
|
||||
{ printf ("\n\nLine %d : vfget_filelen returned negative length.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
gen_short_data (data, ARRAY_LEN (data), 0) ;
|
||||
sf_write_short (file, data, ARRAY_LEN (data)) ;
|
||||
|
||||
gen_short_data (data, ARRAY_LEN (data), 1) ;
|
||||
sf_write_short (file, data, ARRAY_LEN (data)) ;
|
||||
|
||||
gen_short_data (data, ARRAY_LEN (data), 2) ;
|
||||
sf_write_short (file, data, ARRAY_LEN (data)) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
/* Now test read. */
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
|
||||
vio_data.offset = 0 ;
|
||||
|
||||
if ((file = sf_open_virtual (&vio, SFM_READ, &sfinfo, &vio_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : sf_open_write failed with error : ", __LINE__) ;
|
||||
fflush (stdout) ;
|
||||
puts (sf_strerror (NULL)) ;
|
||||
|
||||
dump_data_to_file (fname, vio_data.data, (unsigned int) vio_data.length) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
||||
sf_read_short (file, data, ARRAY_LEN (data)) ;
|
||||
check_short_data (data, ARRAY_LEN (data), 0, __LINE__) ;
|
||||
|
||||
sf_read_short (file, data, ARRAY_LEN (data)) ;
|
||||
check_short_data (data, ARRAY_LEN (data), 1, __LINE__) ;
|
||||
|
||||
sf_read_short (file, data, ARRAY_LEN (data)) ;
|
||||
check_short_data (data, ARRAY_LEN (data), 2, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* vio_test */
|
||||
|
||||
148
Engine/lib/libsndfile/tests/win32_ordinal_test.c
Normal file
148
Engine/lib/libsndfile/tests/win32_ordinal_test.c
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
** Copyright (C) 2006-2017 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_DIRECT_H
|
||||
#include <direct.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#if (defined (WIN32) || defined (_WIN32) || defined (__CYGWIN__))
|
||||
#define TEST_WIN32 1
|
||||
#else
|
||||
#define TEST_WIN32 0
|
||||
#endif
|
||||
|
||||
#if TEST_WIN32
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
static const char * locations [] =
|
||||
{ ".", "../src/", "src/", "../src/.libs/", "src/.libs/",
|
||||
NULL
|
||||
} ; /* locations. */
|
||||
|
||||
static int
|
||||
test_ordinal (HMODULE hmod, const char * func_name, int ordinal)
|
||||
{ char *lpmsg ;
|
||||
void *name, *ord ;
|
||||
|
||||
print_test_name ("win32_ordinal_test", func_name) ;
|
||||
|
||||
#if SIZEOF_VOIDP == 8
|
||||
#define LPCSTR_OF_ORDINAL(x) ((LPCSTR) ((int64_t) (x)))
|
||||
#else
|
||||
#define LPCSTR_OF_ORDINAL(x) ((LPCSTR) (x))
|
||||
#endif
|
||||
|
||||
ord = GetProcAddress (hmod, LPCSTR_OF_ORDINAL (ordinal)) ;
|
||||
if ((name = GetProcAddress (hmod, func_name)) == NULL)
|
||||
{ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (),
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpmsg, 0, NULL) ;
|
||||
/*-puts (lpmsg) ;-*/
|
||||
} ;
|
||||
|
||||
if (name != NULL && ord != NULL && name == ord)
|
||||
{ puts ("ok") ;
|
||||
return 0 ;
|
||||
} ;
|
||||
|
||||
puts ("fail") ;
|
||||
return 1 ;
|
||||
} /* test_ordinal */
|
||||
|
||||
static void
|
||||
win32_ordinal_test (void)
|
||||
{ static char buffer [1024] ;
|
||||
static char func_name [1024] ;
|
||||
HMODULE hmod = NULL ;
|
||||
FILE * file = NULL ;
|
||||
int k, ordinal, errors = 0 ;
|
||||
|
||||
for (k = 0 ; locations [k] != NULL ; k++)
|
||||
{ snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.def", locations [k]) ;
|
||||
if ((file = fopen (buffer, "r")) != NULL)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (file == NULL)
|
||||
{ puts ("\n\nError : cannot open DEF file.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; locations [k] != NULL ; k++)
|
||||
{ snprintf (buffer, sizeof (buffer), "%s/libsndfile-1.dll", locations [k]) ;
|
||||
if ((hmod = (HMODULE) LoadLibrary (buffer)) != NULL)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (hmod == NULL)
|
||||
{ printf ("\n\nError : cannot load DLL (cwd is %s).\n", getcwd (buffer, sizeof (buffer))) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
{ func_name [0] = 0 ;
|
||||
ordinal = 0 ;
|
||||
|
||||
if (sscanf (buffer, "%s @%d", func_name, &ordinal) != 2)
|
||||
continue ;
|
||||
|
||||
errors += test_ordinal (hmod, func_name, ordinal) ;
|
||||
} ;
|
||||
|
||||
FreeLibrary (hmod) ;
|
||||
|
||||
fclose (file) ;
|
||||
|
||||
if (errors > 0)
|
||||
{ printf ("\n\nErrors : %d\n\n", errors) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* win32_ordinal_test */
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
#if (TEST_WIN32 && WIN32_TARGET_DLL)
|
||||
win32_ordinal_test () ;
|
||||
#endif
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
318
Engine/lib/libsndfile/tests/win32_test.c
Normal file
318
Engine/lib/libsndfile/tests/win32_test.c
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2011 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
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "sfconfig.h"
|
||||
#include "sndfile.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if (HAVE_DECL_S_IRGRP == 0)
|
||||
#include <sf_unistd.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define SIGNED_SIZEOF(x) ((int) sizeof (x))
|
||||
|
||||
/* EMX is OS/2. */
|
||||
#if defined (__CYGWIN__) || defined (__EMX__)
|
||||
|
||||
#define LSEEK lseek
|
||||
#define FSTAT fstat
|
||||
|
||||
typedef struct stat STATBUF ;
|
||||
typedef off_t INT64 ;
|
||||
|
||||
static char dir_cmd [] = "ls -l" ;
|
||||
|
||||
#elif (defined (WIN32) || defined (_WIN32))
|
||||
|
||||
#define LSEEK _lseeki64
|
||||
#define FSTAT _fstati64
|
||||
|
||||
typedef struct _stati64 STATBUF ;
|
||||
typedef __int64 INT64 ;
|
||||
|
||||
static char dir_cmd [] = "dir" ;
|
||||
|
||||
#else
|
||||
|
||||
#define LSEEK lseek
|
||||
#define FSTAT fstat
|
||||
|
||||
typedef struct stat STATBUF ;
|
||||
typedef sf_count_t INT64 ;
|
||||
|
||||
#define O_BINARY 0
|
||||
static char dir_cmd [] = "ls -l" ;
|
||||
|
||||
#endif
|
||||
|
||||
static void show_fstat_error (void) ;
|
||||
static void show_lseek_error (void) ;
|
||||
static void show_stat_fstat_error (void) ;
|
||||
static void write_to_closed_file (void) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("\n\n\n\n"
|
||||
"This program shows up errors in the Win32 implementation of\n"
|
||||
"a couple of POSIX API functions on some versions of windoze.\n"
|
||||
"It can also be compiled on Linux (which works correctly) and\n"
|
||||
"other OSes just to provide a sanity check.\n"
|
||||
) ;
|
||||
|
||||
show_fstat_error () ;
|
||||
show_lseek_error () ;
|
||||
show_stat_fstat_error () ;
|
||||
write_to_closed_file () ;
|
||||
|
||||
puts ("\n\n") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
show_fstat_error (void)
|
||||
{ static const char *filename = "fstat.dat" ;
|
||||
static char data [256] ;
|
||||
|
||||
STATBUF statbuf ;
|
||||
int fd, mode, flags ;
|
||||
|
||||
if (sizeof (statbuf.st_size) != sizeof (INT64))
|
||||
{ printf ("\n\nLine %d: Error, sizeof (statbuf.st_size) != 8.\n\n", __LINE__) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
puts ("\n64 bit fstat() test.\n--------------------") ;
|
||||
|
||||
printf ("0) Create a file, write %d bytes and close it.\n", SIGNED_SIZEOF (data)) ;
|
||||
mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
|
||||
flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
|
||||
if ((fd = open (filename, mode, flags)) < 0)
|
||||
{ printf ("\n\nLine %d: open() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
assert (write (fd, data, sizeof (data)) > 0) ;
|
||||
close (fd) ;
|
||||
|
||||
printf ("1) Re-open file in read/write mode and write another %d bytes at the end.\n", SIGNED_SIZEOF (data)) ;
|
||||
mode = O_RDWR | O_BINARY ;
|
||||
flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
|
||||
if ((fd = open (filename, mode, flags)) < 0)
|
||||
{ printf ("\n\nLine %d: open() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
LSEEK (fd, 0, SEEK_END) ;
|
||||
assert (write (fd, data, sizeof (data)) > 0) ;
|
||||
|
||||
printf ("2) Now use system (\"%s %s\") to show the file length.\n\n", dir_cmd, filename) ;
|
||||
|
||||
/* Would use snprintf, but thats not really available on windows. */
|
||||
memset (data, 0, sizeof (data)) ;
|
||||
strncpy (data, dir_cmd, sizeof (data) - 1) ;
|
||||
strncat (data, " ", sizeof (data) - 1 - strlen (data)) ;
|
||||
strncat (data, filename, sizeof (data) - 1 - strlen (data)) ;
|
||||
|
||||
assert (system (data) >= 0) ;
|
||||
puts ("") ;
|
||||
|
||||
printf ("3) Now use fstat() to get the file length.\n") ;
|
||||
if (FSTAT (fd, &statbuf) != 0)
|
||||
{ printf ("\n\nLine %d: fstat() returned error : %s\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
printf ("4) According to fstat(), the file length is %ld, ", (long) statbuf.st_size) ;
|
||||
|
||||
close (fd) ;
|
||||
|
||||
if (statbuf.st_size != 2 * sizeof (data))
|
||||
printf ("but thats just plain ***WRONG***.\n\n") ;
|
||||
else
|
||||
{ printf ("which is correct.\n\n") ;
|
||||
unlink (filename) ;
|
||||
} ;
|
||||
|
||||
} /* show_fstat_error */
|
||||
|
||||
static void
|
||||
show_lseek_error (void)
|
||||
{ static const char *filename = "fstat.dat" ;
|
||||
static char data [256] ;
|
||||
|
||||
INT64 retval ;
|
||||
int fd, mode, flags ;
|
||||
|
||||
puts ("\n64 bit lseek() test.\n--------------------") ;
|
||||
|
||||
printf ("0) Create a file, write %d bytes and close it.\n", SIGNED_SIZEOF (data)) ;
|
||||
mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
|
||||
flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
|
||||
if ((fd = open (filename, mode, flags)) < 0)
|
||||
{ printf ("\n\nLine %d: open() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
assert (write (fd, data, sizeof (data)) > 0) ;
|
||||
close (fd) ;
|
||||
|
||||
printf ("1) Re-open file in read/write mode and write another %d bytes at the end.\n", SIGNED_SIZEOF (data)) ;
|
||||
mode = O_RDWR | O_BINARY ;
|
||||
flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
|
||||
if ((fd = open (filename, mode, flags)) < 0)
|
||||
{ printf ("\n\nLine %d: open() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
LSEEK (fd, 0, SEEK_END) ;
|
||||
assert (write (fd, data, sizeof (data)) > 0) ;
|
||||
|
||||
printf ("2) Now use system (\"%s %s\") to show the file length.\n\n", dir_cmd, filename) ;
|
||||
|
||||
/* Would use snprintf, but thats not really available on windows. */
|
||||
memset (data, 0, sizeof (data)) ;
|
||||
strncpy (data, dir_cmd, sizeof (data) - 1) ;
|
||||
strncat (data, " ", sizeof (data) - 1 - strlen (data)) ;
|
||||
strncat (data, filename, sizeof (data) - 1 - strlen (data)) ;
|
||||
|
||||
assert (system (data) >= 0) ;
|
||||
puts ("") ;
|
||||
|
||||
printf ("3) Now use lseek() to go to the end of the file.\n") ;
|
||||
retval = LSEEK (fd, 0, SEEK_END) ;
|
||||
|
||||
printf ("4) We are now at position %ld, ", (long) retval) ;
|
||||
|
||||
close (fd) ;
|
||||
|
||||
if (retval != 2 * sizeof (data))
|
||||
printf ("but thats just plain ***WRONG***.\n\n") ;
|
||||
else
|
||||
{ printf ("which is correct.\n\n") ;
|
||||
unlink (filename) ;
|
||||
} ;
|
||||
|
||||
} /* show_lseek_error */
|
||||
|
||||
static void
|
||||
show_stat_fstat_error (void)
|
||||
{ static const char *filename = "stat_fstat.dat" ;
|
||||
static char data [256] ;
|
||||
|
||||
int fd, mode, flags ;
|
||||
int stat_size, fstat_size ;
|
||||
struct stat buf ;
|
||||
|
||||
/* Known to fail on WinXP. */
|
||||
puts ("\nstat/fstat test.\n----------------") ;
|
||||
|
||||
printf ("0) Create a file and write %d bytes.\n", SIGNED_SIZEOF (data)) ;
|
||||
|
||||
mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
|
||||
flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ;
|
||||
if ((fd = open (filename, mode, flags)) < 0)
|
||||
{ printf ("\n\nLine %d: open() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
assert (write (fd, data, sizeof (data)) > 0) ;
|
||||
|
||||
printf ("1) Now call stat and fstat on the file and retreive the file lengths.\n") ;
|
||||
|
||||
if (stat (filename, &buf) != 0)
|
||||
{ printf ("\n\nLine %d: stat() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
goto error_exit ;
|
||||
} ;
|
||||
stat_size = buf.st_size ;
|
||||
|
||||
if (fstat (fd, &buf) != 0)
|
||||
{ printf ("\n\nLine %d: fstat() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
goto error_exit ;
|
||||
} ;
|
||||
fstat_size = buf.st_size ;
|
||||
|
||||
printf ("2) Size returned by stat and fstat is %d and %d, ", stat_size, fstat_size) ;
|
||||
|
||||
|
||||
if (stat_size == 0 || stat_size != fstat_size)
|
||||
printf ("but thats just plain ***WRONG***.\n\n") ;
|
||||
else
|
||||
printf ("which is correct.\n\n") ;
|
||||
|
||||
error_exit :
|
||||
|
||||
close (fd) ;
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* show_stat_fstat_error */
|
||||
|
||||
|
||||
static void
|
||||
write_to_closed_file (void)
|
||||
{ const char * filename = "closed_write_test.txt" ;
|
||||
struct stat buf ;
|
||||
FILE * file ;
|
||||
int fd ;
|
||||
|
||||
puts ("\nWrite to closed file test.\n--------------------------") ;
|
||||
|
||||
printf ("0) First we open file for write using fopen().\n") ;
|
||||
if ((file = fopen (filename, "w")) == NULL)
|
||||
{ printf ("\n\nLine %d: fopen() failed : %s\n\n", __LINE__, strerror (errno)) ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
printf ("1) Now we grab the file descriptor fileno().\n") ;
|
||||
fd = fileno (file) ;
|
||||
|
||||
printf ("2) Write some text via the file descriptor.\n") ;
|
||||
assert (write (fd, "a\n", 2) > 0) ;
|
||||
|
||||
printf ("3) Now we close the file using fclose().\n") ;
|
||||
fclose (file) ;
|
||||
|
||||
stat (filename, &buf) ;
|
||||
printf (" File size is %d bytes.\n", (int) buf.st_size) ;
|
||||
|
||||
printf ("4) Now write more data to the file descriptor which should fail.\n") ;
|
||||
if (write (fd, "b\n", 2) < 0)
|
||||
printf ("5) Good, write returned an error code as it should have.\n") ;
|
||||
else
|
||||
{ printf ("5) Attempting to write to a closed file should have failed but didn't! *** WRONG ***\n") ;
|
||||
|
||||
stat (filename, &buf) ;
|
||||
printf (" File size is %d bytes.\n", (int) buf.st_size) ;
|
||||
} ;
|
||||
|
||||
unlink (filename) ;
|
||||
|
||||
return ;
|
||||
} /* write_to_closed_file */
|
||||
75
Engine/lib/libsndfile/tests/write_read_test.def
Normal file
75
Engine/lib/libsndfile/tests/write_read_test.def
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
autogen definitions write_read_test.tpl;
|
||||
|
||||
data_type = {
|
||||
type_name = char ;
|
||||
data_type = short ;
|
||||
data_field = s ;
|
||||
error_func = CHAR_ERROR ;
|
||||
format_char = "0x%X" ;
|
||||
max_val = "32000.0" ;
|
||||
max_error = "255" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
type_name = short ;
|
||||
data_type = short ;
|
||||
data_field = s ;
|
||||
error_func = INT_ERROR ;
|
||||
format_char = "0x%X" ;
|
||||
max_val = "32000.0" ;
|
||||
max_error = "0" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
type_name = "20bit" ;
|
||||
data_type = int ;
|
||||
data_field = i ;
|
||||
error_func = BIT_20_ERROR ;
|
||||
format_char = "0x%X" ;
|
||||
max_val = "(1.0 * 0x7F00000)" ;
|
||||
max_error = "4096" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
type_name = "24bit" ;
|
||||
data_type = int ;
|
||||
data_field = i ;
|
||||
error_func = TRIBYTE_ERROR ;
|
||||
format_char = "0x%X" ;
|
||||
max_val = "(1.0 * 0x7F000000)" ;
|
||||
max_error = "256" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
type_name = int ;
|
||||
data_type = int ;
|
||||
data_field = i ;
|
||||
error_func = INT_ERROR ;
|
||||
format_char = "0x%X" ;
|
||||
max_val = "(1.0 * 0x7F000000)" ;
|
||||
max_error = "0" ;
|
||||
} ;
|
||||
|
||||
/* Lite remove start */
|
||||
|
||||
data_type = {
|
||||
type_name = float ;
|
||||
data_type = float ;
|
||||
data_field = f ;
|
||||
error_func = FLOAT_ERROR ;
|
||||
format_char = "%g" ;
|
||||
max_val = "1.0" ;
|
||||
max_error = "0" ;
|
||||
} ;
|
||||
|
||||
data_type = {
|
||||
type_name = double ;
|
||||
data_type = double ;
|
||||
data_field = d ;
|
||||
error_func = FLOAT_ERROR ;
|
||||
format_char = "%g" ;
|
||||
max_val = "1.0" ;
|
||||
max_error = "0" ;
|
||||
} ;
|
||||
|
||||
/* Lite remove end */
|
||||
1208
Engine/lib/libsndfile/tests/write_read_test.tpl
Normal file
1208
Engine/lib/libsndfile/tests/write_read_test.tpl
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue