From 0f67af1a2312bbde7f8c0c8344bc5fcf9a880256 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 25 Sep 2012 21:16:34 +1000 Subject: [PATCH] src/sndfile.hh : Added a constructor to allow the use of SF_VIRTUAL_IO. --- ChangeLog | 6 ++++++ src/sndfile.hh | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0968c85a..77d6f899 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-25 Erik de Castro Lopo + + * src/sndfile.hh + Added a constructor to allow the use of SF_VIRTUAL_IO. Patch from + DannyDaemonic : https://github.com/erikd/libsndfile/pull/20 + 2012-08-23 Erik de Castro Lopo * doc/octave.html diff --git a/src/sndfile.hh b/src/sndfile.hh index fdb9a80d..0a0c62d7 100644 --- a/src/sndfile.hh +++ b/src/sndfile.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2005-2011 Erik de Castro Lopo +** Copyright (C) 2005-2012 Erik de Castro Lopo ** ** All rights reserved. ** @@ -79,6 +79,8 @@ class SndfileHandle 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 (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode = SFM_READ, + int format = 0, int channels = 0, int samplerate = 0) ; #ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES SndfileHandle (LPCWSTR wpath, int mode = SFM_READ, @@ -229,6 +231,28 @@ SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int ch return ; } /* SndfileHandle fd constructor */ +inline +SndfileHandle::SndfileHandle (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode, int fmt, int chans, int srate) +: p (NULL) +{ + 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_virtual (&sfvirtual, mode, &p->sfinfo, user_data) ; + } ; + + return ; +} /* SndfileHandle std::string constructor */ + inline SndfileHandle::~SndfileHandle (void) { if (p != NULL && --p->ref == 0)