src/sndfile.hh : Add a constructor which takes an existing file descriptor and then calls sf_open_fd().

This commit is contained in:
Erik de Castro Lopo 2010-01-26 07:55:02 +11:00
parent 77ec10e93f
commit ffc0453edb
2 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2010-01-26 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sndfile.hh
Add a constructor which takes an existing file descriptor and then calls
sf_open_fd(). Patch from Sakari Bergen.
2010-01-10 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* programs/sndfile-deinterleave.c programs/sndfile-interleave.c

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2005-2007 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2005-2010 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** All rights reserved.
**
@ -77,6 +77,8 @@ class SndfileHandle
int format = 0, int channels = 0, int samplerate = 0) ;
SndfileHandle (std::string const & path, int mode = SFM_READ,
int format = 0, int channels = 0, int samplerate = 0) ;
SndfileHandle (int fd, bool close_desc, int mode = SFM_READ,
int format = 0, int channels = 0, int samplerate = 0) ;
~SndfileHandle (void) ;
SndfileHandle (const SndfileHandle &orig) ;
@ -191,6 +193,30 @@ SndfileHandle::SndfileHandle (std::string const & path, int mode, int fmt, int c
return ;
} /* SndfileHandle std::string constructor */
SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int chans, int srate)
: p (NULL)
{
if (fd < 0)
return ;
p = new (std::nothrow) SNDFILE_ref () ;
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 ;
p->sf = sf_open_fd (fd, mode, &p->sfinfo, close_desc) ;
} ;
return ;
} /* SndfileHandle fd constructor */
inline
SndfileHandle::~SndfileHandle (void)
{ if (p != NULL && --p->ref == 0)
@ -249,7 +275,7 @@ SndfileHandle::getString (int str_type) const
{ return sf_get_string (p->sf, str_type) ; }
inline int
SndfileHandle::formatCheck(int fmt, int chans, int srate)
SndfileHandle::formatCheck (int fmt, int chans, int srate)
{
SF_INFO sfinfo ;