mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
More sndfile.hh updates.
This commit is contained in:
parent
7947d0bc99
commit
cb54001ed9
@ -1,3 +1,9 @@
|
||||
2006-08-08 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/flac.c
|
||||
Remove inline from functions called by pointer. Thanks to Sampo Savolainen
|
||||
for notifying me of this.
|
||||
|
||||
2006-07-31 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/sndfile.hh
|
||||
|
@ -59,19 +59,19 @@
|
||||
class SndfileHandle
|
||||
{ private :
|
||||
struct SNDFILE_ref
|
||||
{ SNDFILE_ref (SNDFILE *psf) ;
|
||||
{ SNDFILE_ref (void) ;
|
||||
~SNDFILE_ref (void) ;
|
||||
|
||||
SNDFILE *sf ;
|
||||
SF_INFO sfinfo ;
|
||||
int ref ;
|
||||
} ;
|
||||
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE_ref *p ;
|
||||
|
||||
public :
|
||||
/* Default constructor */
|
||||
SndfileHandle (void) ;
|
||||
SndfileHandle (void) : p (NULL) {} ;
|
||||
SndfileHandle (const char *path, int mode = SFM_READ,
|
||||
int format = 0, int channels = 0, int samplerate = 0) ;
|
||||
~SndfileHandle (void) ;
|
||||
@ -86,10 +86,10 @@ class SndfileHandle
|
||||
|
||||
bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; }
|
||||
|
||||
sf_count_t frames (void) const { return sfinfo.frames ; }
|
||||
int format (void) const { return sfinfo.format ; }
|
||||
int channels (void) const { return sfinfo.channels ; }
|
||||
int samplerate (void) const { return sfinfo.samplerate ; }
|
||||
sf_count_t frames (void) const { return p ? p->sfinfo.frames : 0 ; }
|
||||
int format (void) const { return p ? p->sfinfo.format : 0 ; }
|
||||
int channels (void) const { return p ? p->sfinfo.channels : 0 ; }
|
||||
int samplerate (void) const { return p ? p->sfinfo.samplerate : 0 ; }
|
||||
|
||||
int error (void) const ;
|
||||
const char * strError (void) const ;
|
||||
@ -134,41 +134,35 @@ class SndfileHandle
|
||||
*/
|
||||
|
||||
inline
|
||||
SndfileHandle::SNDFILE_ref::SNDFILE_ref (SNDFILE *psf)
|
||||
: sf (psf), ref (1)
|
||||
SndfileHandle::SNDFILE_ref::SNDFILE_ref (void)
|
||||
: ref (1)
|
||||
{}
|
||||
|
||||
inline
|
||||
SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void)
|
||||
{ sf_close (sf) ; }
|
||||
|
||||
inline
|
||||
SndfileHandle::SndfileHandle (void)
|
||||
: p (NULL)
|
||||
{ sfinfo.frames = 0 ;
|
||||
sfinfo.channels = 0 ;
|
||||
sfinfo.format = 0 ;
|
||||
sfinfo.samplerate = 0 ;
|
||||
sfinfo.sections = 0 ;
|
||||
sfinfo.seekable = 0 ;
|
||||
} /* SndfileHandle constructor */
|
||||
{ if (sf != NULL) sf_close (sf) ; }
|
||||
|
||||
inline
|
||||
SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate)
|
||||
: p (NULL)
|
||||
{ sfinfo.frames = 0 ;
|
||||
sfinfo.channels = chans ;
|
||||
sfinfo.format = fmt ;
|
||||
sfinfo.samplerate = srate ;
|
||||
sfinfo.sections = 0 ;
|
||||
sfinfo.seekable = 0 ;
|
||||
{
|
||||
p = new (std::nothrow) SNDFILE_ref () ;
|
||||
|
||||
SNDFILE *psf = sf_open (path, mode, &sfinfo) ;
|
||||
if (psf != NULL)
|
||||
{ p = new (std::nothrow) SNDFILE_ref (psf) ;
|
||||
if (p == NULL)
|
||||
sf_close (psf) ;
|
||||
}
|
||||
if (p != NULL)
|
||||
{ p->ref = 1 ;
|
||||
|
||||
p->sfinfo.frames = 0 ;
|
||||
p->sfinfo.channels = chans ;
|
||||
p->sfinfo.format = fmt ;
|
||||
p->sfinfo.samplerate = srate ;
|
||||
p->sfinfo.sections = 0 ;
|
||||
p->sfinfo.seekable = 0 ;
|
||||
|
||||
if ((p->sf = sf_open (path, mode, &p->sfinfo)) == NULL)
|
||||
{ delete p ;
|
||||
p = NULL ;
|
||||
} ;
|
||||
} ;
|
||||
} /* SndfileHandle constructor */
|
||||
|
||||
inline
|
||||
@ -180,7 +174,7 @@ SndfileHandle::~SndfileHandle (void)
|
||||
|
||||
inline
|
||||
SndfileHandle::SndfileHandle (const SndfileHandle &orig)
|
||||
: sfinfo (orig.sfinfo), p (orig.p)
|
||||
: p (orig.p)
|
||||
{ if (p != NULL)
|
||||
++p->ref ;
|
||||
} /* SndfileHandle copy constructor */
|
||||
@ -193,7 +187,6 @@ SndfileHandle::operator = (const SndfileHandle &rhs)
|
||||
if (p != NULL && --p->ref == 0)
|
||||
delete p ;
|
||||
|
||||
sfinfo = rhs.sfinfo ;
|
||||
p = rhs.p ;
|
||||
if (p != NULL)
|
||||
++p->ref ;
|
||||
|
@ -93,15 +93,17 @@ read_file (const char * filename, int format)
|
||||
|
||||
file = SndfileHandle (filename) ;
|
||||
|
||||
SndfileHandle file2 = file ;
|
||||
if (1)
|
||||
{ SndfileHandle file2 = file ;
|
||||
|
||||
if (file.refCount () != 2)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
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 (file2.refCount () != 2)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be one.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user