mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
Complete sndfile.hh and add more tests.
This commit is contained in:
parent
576e6f6f68
commit
062e09c7c9
@ -1,3 +1,11 @@
|
||||
2006-07-28 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/sndfile.hh
|
||||
Complete it.
|
||||
|
||||
* tests/cpp_test.cc
|
||||
Add more tests.
|
||||
|
||||
2006-07-27 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* tests/utils.tpl
|
||||
|
@ -48,8 +48,8 @@ class Sndfile
|
||||
bool openWrite (const char *path) ;
|
||||
bool openReadWrite (const char *path) ;
|
||||
|
||||
static int error (void) ;
|
||||
const char * StrError (void) ;
|
||||
int error (void) ;
|
||||
const char * strError (void) ;
|
||||
|
||||
int command (int cmd, void *data, int datasize) ;
|
||||
|
||||
@ -137,10 +137,31 @@ Sndfile::close (void)
|
||||
psf = NULL ;
|
||||
} /* Sndfile::close */
|
||||
|
||||
inline int
|
||||
Sndfile::error (void)
|
||||
{ return sf_error (psf) ; }
|
||||
|
||||
inline const char *
|
||||
Sndfile::strError (void)
|
||||
{ return sf_strerror (psf) ; }
|
||||
|
||||
inline int
|
||||
Sndfile::command (int cmd, void *data, int datasize)
|
||||
{ return sf_command (psf, cmd, data, datasize) ; }
|
||||
|
||||
inline sf_count_t
|
||||
Sndfile::seek (sf_count_t frames, int whence)
|
||||
{ return sf_seek (psf, frames, whence) ; }
|
||||
|
||||
inline int
|
||||
Sndfile::setString (int str_type, const char* str)
|
||||
{ return sf_set_string (psf, str_type, str) ; }
|
||||
|
||||
inline const char*
|
||||
Sndfile::getString (int str_type)
|
||||
{ return sf_get_string (psf, str_type) ; }
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
inline sf_count_t
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <sndfile.hh>
|
||||
|
||||
@ -37,6 +38,8 @@ create_file (const char * filename, int format)
|
||||
file.sfinfo.samplerate = 48000 ;
|
||||
file.openWrite (filename) ;
|
||||
|
||||
file.setString (SF_STR_TITLE, filename) ;
|
||||
|
||||
/* Item write. */
|
||||
file.write (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
file.write (ibuffer, ARRAY_LEN (ibuffer)) ;
|
||||
@ -59,6 +62,8 @@ create_file (const char * filename, int format)
|
||||
static void
|
||||
read_file (const char * filename, int format)
|
||||
{ Sndfile file ;
|
||||
const char *title ;
|
||||
sf_count_t count ;
|
||||
|
||||
file.openRead (filename) ;
|
||||
|
||||
@ -78,6 +83,18 @@ read_file (const char * filename, int format)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
title = file.getString (SF_STR_TITLE) ;
|
||||
|
||||
if (title == NULL)
|
||||
{ printf ("\n\n%s %d : Error : No title.\n\n", __func__, __LINE__) ;
|
||||
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) ;
|
||||
} ;
|
||||
|
||||
/* Item read. */
|
||||
file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
file.read (ibuffer, ARRAY_LEN (ibuffer)) ;
|
||||
@ -90,6 +107,20 @@ read_file (const char * filename, int format)
|
||||
file.readf (fbuffer, ARRAY_LEN (fbuffer) / file.sfinfo.channels) ;
|
||||
file.readf (dbuffer, ARRAY_LEN (dbuffer) / file.sfinfo.channels) ;
|
||||
|
||||
count = file.seek (file.sfinfo.frames - 10, SEEK_SET) ;
|
||||
if (count != file.sfinfo.frames - 10)
|
||||
{ printf ("\n\n%s %d : Error : offset (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (count), SF_COUNT_TO_LONG (file.sfinfo.frames - 10)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
count = file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
if (count != 10 * file.sfinfo.channels)
|
||||
{ printf ("\n\n%s %d : Error : count (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (count), SF_COUNT_TO_LONG (10 * file.sfinfo.channels)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/*
|
||||
** An explict close() call is not really necessary as the Sndfile
|
||||
** destructor closes the file anyway.
|
||||
|
Loading…
Reference in New Issue
Block a user