| Chris@6 | 1 /* | 
| Chris@6 | 2 ** Copyright (C) 2005-2011 Erik de Castro Lopo <erikd@mega-nerd.com> | 
| Chris@6 | 3 ** | 
| Chris@6 | 4 ** All rights reserved. | 
| Chris@6 | 5 ** | 
| Chris@6 | 6 ** Redistribution and use in source and binary forms, with or without | 
| Chris@6 | 7 ** modification, are permitted provided that the following conditions are | 
| Chris@6 | 8 ** met: | 
| Chris@6 | 9 ** | 
| Chris@6 | 10 **     * Redistributions of source code must retain the above copyright | 
| Chris@6 | 11 **       notice, this list of conditions and the following disclaimer. | 
| Chris@6 | 12 **     * Redistributions in binary form must reproduce the above copyright | 
| Chris@6 | 13 **       notice, this list of conditions and the following disclaimer in | 
| Chris@6 | 14 **       the documentation and/or other materials provided with the | 
| Chris@6 | 15 **       distribution. | 
| Chris@6 | 16 **     * Neither the author nor the names of any contributors may be used | 
| Chris@6 | 17 **       to endorse or promote products derived from this software without | 
| Chris@6 | 18 **       specific prior written permission. | 
| Chris@6 | 19 ** | 
| Chris@6 | 20 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
| Chris@6 | 21 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 
| Chris@6 | 22 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
| Chris@6 | 23 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | 
| Chris@6 | 24 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 
| Chris@6 | 25 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 
| Chris@6 | 26 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 
| Chris@6 | 27 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 
| Chris@6 | 28 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 
| Chris@6 | 29 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 
| Chris@6 | 30 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| Chris@6 | 31 */ | 
| Chris@6 | 32 | 
| Chris@6 | 33 /* | 
| Chris@6 | 34 ** The above modified BSD style license (GPL and LGPL compatible) applies to | 
| Chris@6 | 35 ** this file. It does not apply to libsndfile itself which is released under | 
| Chris@6 | 36 ** the GNU LGPL or the libsndfile test suite which is released under the GNU | 
| Chris@6 | 37 ** GPL. | 
| Chris@6 | 38 ** This means that this header file can be used under this modified BSD style | 
| Chris@6 | 39 ** license, but the LGPL still holds for the libsndfile library itself. | 
| Chris@6 | 40 */ | 
| Chris@6 | 41 | 
| Chris@6 | 42 /* | 
| Chris@6 | 43 ** sndfile.hh -- A lightweight C++ wrapper for the libsndfile API. | 
| Chris@6 | 44 ** | 
| Chris@6 | 45 ** All the methods are inlines and all functionality is contained in this | 
| Chris@6 | 46 ** file. There is no separate implementation file. | 
| Chris@6 | 47 ** | 
| Chris@6 | 48 ** API documentation is in the doc/ directory of the source code tarball | 
| Chris@6 | 49 ** and at http://www.mega-nerd.com/libsndfile/api.html. | 
| Chris@6 | 50 */ | 
| Chris@6 | 51 | 
| Chris@6 | 52 #ifndef SNDFILE_HH | 
| Chris@6 | 53 #define SNDFILE_HH | 
| Chris@6 | 54 | 
| Chris@6 | 55 #include <sndfile.h> | 
| Chris@6 | 56 | 
| Chris@6 | 57 #include <string> | 
| Chris@6 | 58 #include <new> // for std::nothrow | 
| Chris@6 | 59 | 
| Chris@6 | 60 class SndfileHandle | 
| Chris@6 | 61 {	private : | 
| Chris@6 | 62 		struct SNDFILE_ref | 
| Chris@6 | 63 		{	SNDFILE_ref (void) ; | 
| Chris@6 | 64 			~SNDFILE_ref (void) ; | 
| Chris@6 | 65 | 
| Chris@6 | 66 			SNDFILE *sf ; | 
| Chris@6 | 67 			SF_INFO sfinfo ; | 
| Chris@6 | 68 			int ref ; | 
| Chris@6 | 69 			} ; | 
| Chris@6 | 70 | 
| Chris@6 | 71 		SNDFILE_ref *p ; | 
| Chris@6 | 72 | 
| Chris@6 | 73 	public : | 
| Chris@6 | 74 			/* Default constructor */ | 
| Chris@6 | 75 			SndfileHandle (void) : p (NULL) {} ; | 
| Chris@6 | 76 			SndfileHandle (const char *path, int mode = SFM_READ, | 
| Chris@6 | 77 							int format = 0, int channels = 0, int samplerate = 0) ; | 
| Chris@6 | 78 			SndfileHandle (std::string const & path, int mode = SFM_READ, | 
| Chris@6 | 79 							int format = 0, int channels = 0, int samplerate = 0) ; | 
| Chris@6 | 80 			SndfileHandle (int fd, bool close_desc, int mode = SFM_READ, | 
| Chris@6 | 81 							int format = 0, int channels = 0, int samplerate = 0) ; | 
| Chris@6 | 82 | 
| Chris@6 | 83 #ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES | 
| Chris@6 | 84 			SndfileHandle (LPCWSTR wpath, int mode = SFM_READ, | 
| Chris@6 | 85 							int format = 0, int channels = 0, int samplerate = 0) ; | 
| Chris@6 | 86 #endif | 
| Chris@6 | 87 | 
| Chris@6 | 88 			~SndfileHandle (void) ; | 
| Chris@6 | 89 | 
| Chris@6 | 90 			SndfileHandle (const SndfileHandle &orig) ; | 
| Chris@6 | 91 			SndfileHandle & operator = (const SndfileHandle &rhs) ; | 
| Chris@6 | 92 | 
| Chris@6 | 93 		/* Mainly for debugging/testing. */ | 
| Chris@6 | 94 		int refCount (void) const { return (p == NULL) ? 0 : p->ref ; } | 
| Chris@6 | 95 | 
| Chris@6 | 96 		operator bool () const { return (p != NULL) ; } | 
| Chris@6 | 97 | 
| Chris@6 | 98 		bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; } | 
| Chris@6 | 99 | 
| Chris@6 | 100 		sf_count_t	frames (void) const		{ return p ? p->sfinfo.frames : 0 ; } | 
| Chris@6 | 101 		int			format (void) const		{ return p ? p->sfinfo.format : 0 ; } | 
| Chris@6 | 102 		int			channels (void) const	{ return p ? p->sfinfo.channels : 0 ; } | 
| Chris@6 | 103 		int			samplerate (void) const { return p ? p->sfinfo.samplerate : 0 ; } | 
| Chris@6 | 104 | 
| Chris@6 | 105 		int error (void) const ; | 
| Chris@6 | 106 		const char * strError (void) const ; | 
| Chris@6 | 107 | 
| Chris@6 | 108 		int command (int cmd, void *data, int datasize) ; | 
| Chris@6 | 109 | 
| Chris@6 | 110 		sf_count_t	seek (sf_count_t frames, int whence) ; | 
| Chris@6 | 111 | 
| Chris@6 | 112 		void writeSync (void) ; | 
| Chris@6 | 113 | 
| Chris@6 | 114 		int setString (int str_type, const char* str) ; | 
| Chris@6 | 115 | 
| Chris@6 | 116 		const char* getString (int str_type) const ; | 
| Chris@6 | 117 | 
| Chris@6 | 118 		static int formatCheck (int format, int channels, int samplerate) ; | 
| Chris@6 | 119 | 
| Chris@6 | 120 		sf_count_t read (short *ptr, sf_count_t items) ; | 
| Chris@6 | 121 		sf_count_t read (int *ptr, sf_count_t items) ; | 
| Chris@6 | 122 		sf_count_t read (float *ptr, sf_count_t items) ; | 
| Chris@6 | 123 		sf_count_t read (double *ptr, sf_count_t items) ; | 
| Chris@6 | 124 | 
| Chris@6 | 125 		sf_count_t write (const short *ptr, sf_count_t items) ; | 
| Chris@6 | 126 		sf_count_t write (const int *ptr, sf_count_t items) ; | 
| Chris@6 | 127 		sf_count_t write (const float *ptr, sf_count_t items) ; | 
| Chris@6 | 128 		sf_count_t write (const double *ptr, sf_count_t items) ; | 
| Chris@6 | 129 | 
| Chris@6 | 130 		sf_count_t readf (short *ptr, sf_count_t frames) ; | 
| Chris@6 | 131 		sf_count_t readf (int *ptr, sf_count_t frames) ; | 
| Chris@6 | 132 		sf_count_t readf (float *ptr, sf_count_t frames) ; | 
| Chris@6 | 133 		sf_count_t readf (double *ptr, sf_count_t frames) ; | 
| Chris@6 | 134 | 
| Chris@6 | 135 		sf_count_t writef (const short *ptr, sf_count_t frames) ; | 
| Chris@6 | 136 		sf_count_t writef (const int *ptr, sf_count_t frames) ; | 
| Chris@6 | 137 		sf_count_t writef (const float *ptr, sf_count_t frames) ; | 
| Chris@6 | 138 		sf_count_t writef (const double *ptr, sf_count_t frames) ; | 
| Chris@6 | 139 | 
| Chris@6 | 140 		sf_count_t	readRaw		(void *ptr, sf_count_t bytes) ; | 
| Chris@6 | 141 		sf_count_t	writeRaw	(const void *ptr, sf_count_t bytes) ; | 
| Chris@6 | 142 | 
| Chris@6 | 143 		/**< Raw access to the handle. SndfileHandle keeps ownership. */ | 
| Chris@6 | 144 		SNDFILE * rawHandle (void) ; | 
| Chris@6 | 145 | 
| Chris@6 | 146 		/**< Take ownership of handle, iff reference count is 1. */ | 
| Chris@6 | 147 		SNDFILE * takeOwnership (void) ; | 
| Chris@6 | 148 } ; | 
| Chris@6 | 149 | 
| Chris@6 | 150 /*============================================================================== | 
| Chris@6 | 151 **	Nothing but implementation below. | 
| Chris@6 | 152 */ | 
| Chris@6 | 153 | 
| Chris@6 | 154 inline | 
| Chris@6 | 155 SndfileHandle::SNDFILE_ref::SNDFILE_ref (void) | 
| Chris@6 | 156 : ref (1) | 
| Chris@6 | 157 {} | 
| Chris@6 | 158 | 
| Chris@6 | 159 inline | 
| Chris@6 | 160 SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void) | 
| Chris@6 | 161 {	if (sf != NULL) sf_close (sf) ; } | 
| Chris@6 | 162 | 
| Chris@6 | 163 inline | 
| Chris@6 | 164 SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate) | 
| Chris@6 | 165 : p (NULL) | 
| Chris@6 | 166 { | 
| Chris@6 | 167 	p = new (std::nothrow) SNDFILE_ref () ; | 
| Chris@6 | 168 | 
| Chris@6 | 169 	if (p != NULL) | 
| Chris@6 | 170 	{	p->ref = 1 ; | 
| Chris@6 | 171 | 
| Chris@6 | 172 		p->sfinfo.frames = 0 ; | 
| Chris@6 | 173 		p->sfinfo.channels = chans ; | 
| Chris@6 | 174 		p->sfinfo.format = fmt ; | 
| Chris@6 | 175 		p->sfinfo.samplerate = srate ; | 
| Chris@6 | 176 		p->sfinfo.sections = 0 ; | 
| Chris@6 | 177 		p->sfinfo.seekable = 0 ; | 
| Chris@6 | 178 | 
| Chris@6 | 179 		p->sf = sf_open (path, mode, &p->sfinfo) ; | 
| Chris@6 | 180 		} ; | 
| Chris@6 | 181 | 
| Chris@6 | 182 	return ; | 
| Chris@6 | 183 } /* SndfileHandle const char * constructor */ | 
| Chris@6 | 184 | 
| Chris@6 | 185 inline | 
| Chris@6 | 186 SndfileHandle::SndfileHandle (std::string const & path, int mode, int fmt, int chans, int srate) | 
| Chris@6 | 187 : p (NULL) | 
| Chris@6 | 188 { | 
| Chris@6 | 189 	p = new (std::nothrow) SNDFILE_ref () ; | 
| Chris@6 | 190 | 
| Chris@6 | 191 	if (p != NULL) | 
| Chris@6 | 192 	{	p->ref = 1 ; | 
| Chris@6 | 193 | 
| Chris@6 | 194 		p->sfinfo.frames = 0 ; | 
| Chris@6 | 195 		p->sfinfo.channels = chans ; | 
| Chris@6 | 196 		p->sfinfo.format = fmt ; | 
| Chris@6 | 197 		p->sfinfo.samplerate = srate ; | 
| Chris@6 | 198 		p->sfinfo.sections = 0 ; | 
| Chris@6 | 199 		p->sfinfo.seekable = 0 ; | 
| Chris@6 | 200 | 
| Chris@6 | 201 		p->sf = sf_open (path.c_str (), mode, &p->sfinfo) ; | 
| Chris@6 | 202 		} ; | 
| Chris@6 | 203 | 
| Chris@6 | 204 	return ; | 
| Chris@6 | 205 } /* SndfileHandle std::string constructor */ | 
| Chris@6 | 206 | 
| Chris@6 | 207 inline | 
| Chris@6 | 208 SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int chans, int srate) | 
| Chris@6 | 209 : p (NULL) | 
| Chris@6 | 210 { | 
| Chris@6 | 211 	if (fd < 0) | 
| Chris@6 | 212 		return ; | 
| Chris@6 | 213 | 
| Chris@6 | 214 	p = new (std::nothrow) SNDFILE_ref () ; | 
| Chris@6 | 215 | 
| Chris@6 | 216 	if (p != NULL) | 
| Chris@6 | 217 	{	p->ref = 1 ; | 
| Chris@6 | 218 | 
| Chris@6 | 219 		p->sfinfo.frames = 0 ; | 
| Chris@6 | 220 		p->sfinfo.channels = chans ; | 
| Chris@6 | 221 		p->sfinfo.format = fmt ; | 
| Chris@6 | 222 		p->sfinfo.samplerate = srate ; | 
| Chris@6 | 223 		p->sfinfo.sections = 0 ; | 
| Chris@6 | 224 		p->sfinfo.seekable = 0 ; | 
| Chris@6 | 225 | 
| Chris@6 | 226 		p->sf = sf_open_fd (fd, mode, &p->sfinfo, close_desc) ; | 
| Chris@6 | 227 		} ; | 
| Chris@6 | 228 | 
| Chris@6 | 229 	return ; | 
| Chris@6 | 230 } /* SndfileHandle fd constructor */ | 
| Chris@6 | 231 | 
| Chris@6 | 232 inline | 
| Chris@6 | 233 SndfileHandle::~SndfileHandle (void) | 
| Chris@6 | 234 {	if (p != NULL && --p->ref == 0) | 
| Chris@6 | 235 		delete p ; | 
| Chris@6 | 236 } /* SndfileHandle destructor */ | 
| Chris@6 | 237 | 
| Chris@6 | 238 | 
| Chris@6 | 239 inline | 
| Chris@6 | 240 SndfileHandle::SndfileHandle (const SndfileHandle &orig) | 
| Chris@6 | 241 : p (orig.p) | 
| Chris@6 | 242 {	if (p != NULL) | 
| Chris@6 | 243 		++p->ref ; | 
| Chris@6 | 244 } /* SndfileHandle copy constructor */ | 
| Chris@6 | 245 | 
| Chris@6 | 246 inline SndfileHandle & | 
| Chris@6 | 247 SndfileHandle::operator = (const SndfileHandle &rhs) | 
| Chris@6 | 248 { | 
| Chris@6 | 249 	if (&rhs == this) | 
| Chris@6 | 250 		return *this ; | 
| Chris@6 | 251 	if (p != NULL && --p->ref == 0) | 
| Chris@6 | 252 		delete p ; | 
| Chris@6 | 253 | 
| Chris@6 | 254 	p = rhs.p ; | 
| Chris@6 | 255 	if (p != NULL) | 
| Chris@6 | 256 		++p->ref ; | 
| Chris@6 | 257 | 
| Chris@6 | 258 	return *this ; | 
| Chris@6 | 259 } /* SndfileHandle assignment operator */ | 
| Chris@6 | 260 | 
| Chris@6 | 261 inline int | 
| Chris@6 | 262 SndfileHandle::error (void) const | 
| Chris@6 | 263 {	return sf_error (p->sf) ; } | 
| Chris@6 | 264 | 
| Chris@6 | 265 inline const char * | 
| Chris@6 | 266 SndfileHandle::strError (void) const | 
| Chris@6 | 267 {	return sf_strerror (p->sf) ; } | 
| Chris@6 | 268 | 
| Chris@6 | 269 inline int | 
| Chris@6 | 270 SndfileHandle::command (int cmd, void *data, int datasize) | 
| Chris@6 | 271 {	return sf_command (p->sf, cmd, data, datasize) ; } | 
| Chris@6 | 272 | 
| Chris@6 | 273 inline sf_count_t | 
| Chris@6 | 274 SndfileHandle::seek (sf_count_t frame_count, int whence) | 
| Chris@6 | 275 {	return sf_seek (p->sf, frame_count, whence) ; } | 
| Chris@6 | 276 | 
| Chris@6 | 277 inline void | 
| Chris@6 | 278 SndfileHandle::writeSync (void) | 
| Chris@6 | 279 {	sf_write_sync (p->sf) ; } | 
| Chris@6 | 280 | 
| Chris@6 | 281 inline int | 
| Chris@6 | 282 SndfileHandle::setString (int str_type, const char* str) | 
| Chris@6 | 283 {	return sf_set_string (p->sf, str_type, str) ; } | 
| Chris@6 | 284 | 
| Chris@6 | 285 inline const char* | 
| Chris@6 | 286 SndfileHandle::getString (int str_type) const | 
| Chris@6 | 287 {	return sf_get_string (p->sf, str_type) ; } | 
| Chris@6 | 288 | 
| Chris@6 | 289 inline int | 
| Chris@6 | 290 SndfileHandle::formatCheck (int fmt, int chans, int srate) | 
| Chris@6 | 291 { | 
| Chris@6 | 292 	SF_INFO sfinfo ; | 
| Chris@6 | 293 | 
| Chris@6 | 294 	sfinfo.frames = 0 ; | 
| Chris@6 | 295 	sfinfo.channels = chans ; | 
| Chris@6 | 296 	sfinfo.format = fmt ; | 
| Chris@6 | 297 	sfinfo.samplerate = srate ; | 
| Chris@6 | 298 	sfinfo.sections = 0 ; | 
| Chris@6 | 299 	sfinfo.seekable = 0 ; | 
| Chris@6 | 300 | 
| Chris@6 | 301 	return sf_format_check (&sfinfo) ; | 
| Chris@6 | 302 } | 
| Chris@6 | 303 | 
| Chris@6 | 304 /*---------------------------------------------------------------------*/ | 
| Chris@6 | 305 | 
| Chris@6 | 306 inline sf_count_t | 
| Chris@6 | 307 SndfileHandle::read (short *ptr, sf_count_t items) | 
| Chris@6 | 308 {	return sf_read_short (p->sf, ptr, items) ; } | 
| Chris@6 | 309 | 
| Chris@6 | 310 inline sf_count_t | 
| Chris@6 | 311 SndfileHandle::read (int *ptr, sf_count_t items) | 
| Chris@6 | 312 {	return sf_read_int (p->sf, ptr, items) ; } | 
| Chris@6 | 313 | 
| Chris@6 | 314 inline sf_count_t | 
| Chris@6 | 315 SndfileHandle::read (float *ptr, sf_count_t items) | 
| Chris@6 | 316 {	return sf_read_float (p->sf, ptr, items) ; } | 
| Chris@6 | 317 | 
| Chris@6 | 318 inline sf_count_t | 
| Chris@6 | 319 SndfileHandle::read (double *ptr, sf_count_t items) | 
| Chris@6 | 320 {	return sf_read_double (p->sf, ptr, items) ; } | 
| Chris@6 | 321 | 
| Chris@6 | 322 inline sf_count_t | 
| Chris@6 | 323 SndfileHandle::write (const short *ptr, sf_count_t items) | 
| Chris@6 | 324 {	return sf_write_short (p->sf, ptr, items) ; } | 
| Chris@6 | 325 | 
| Chris@6 | 326 inline sf_count_t | 
| Chris@6 | 327 SndfileHandle::write (const int *ptr, sf_count_t items) | 
| Chris@6 | 328 {	return sf_write_int (p->sf, ptr, items) ; } | 
| Chris@6 | 329 | 
| Chris@6 | 330 inline sf_count_t | 
| Chris@6 | 331 SndfileHandle::write (const float *ptr, sf_count_t items) | 
| Chris@6 | 332 {	return sf_write_float (p->sf, ptr, items) ; } | 
| Chris@6 | 333 | 
| Chris@6 | 334 inline sf_count_t | 
| Chris@6 | 335 SndfileHandle::write (const double *ptr, sf_count_t items) | 
| Chris@6 | 336 {	return sf_write_double (p->sf, ptr, items) ; } | 
| Chris@6 | 337 | 
| Chris@6 | 338 inline sf_count_t | 
| Chris@6 | 339 SndfileHandle::readf (short *ptr, sf_count_t frame_count) | 
| Chris@6 | 340 {	return sf_readf_short (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 341 | 
| Chris@6 | 342 inline sf_count_t | 
| Chris@6 | 343 SndfileHandle::readf (int *ptr, sf_count_t frame_count) | 
| Chris@6 | 344 {	return sf_readf_int (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 345 | 
| Chris@6 | 346 inline sf_count_t | 
| Chris@6 | 347 SndfileHandle::readf (float *ptr, sf_count_t frame_count) | 
| Chris@6 | 348 {	return sf_readf_float (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 349 | 
| Chris@6 | 350 inline sf_count_t | 
| Chris@6 | 351 SndfileHandle::readf (double *ptr, sf_count_t frame_count) | 
| Chris@6 | 352 {	return sf_readf_double (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 353 | 
| Chris@6 | 354 inline sf_count_t | 
| Chris@6 | 355 SndfileHandle::writef (const short *ptr, sf_count_t frame_count) | 
| Chris@6 | 356 {	return sf_writef_short (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 357 | 
| Chris@6 | 358 inline sf_count_t | 
| Chris@6 | 359 SndfileHandle::writef (const int *ptr, sf_count_t frame_count) | 
| Chris@6 | 360 {	return sf_writef_int (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 361 | 
| Chris@6 | 362 inline sf_count_t | 
| Chris@6 | 363 SndfileHandle::writef (const float *ptr, sf_count_t frame_count) | 
| Chris@6 | 364 {	return sf_writef_float (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 365 | 
| Chris@6 | 366 inline sf_count_t | 
| Chris@6 | 367 SndfileHandle::writef (const double *ptr, sf_count_t frame_count) | 
| Chris@6 | 368 {	return sf_writef_double (p->sf, ptr, frame_count) ; } | 
| Chris@6 | 369 | 
| Chris@6 | 370 inline sf_count_t | 
| Chris@6 | 371 SndfileHandle::readRaw (void *ptr, sf_count_t bytes) | 
| Chris@6 | 372 {	return sf_read_raw (p->sf, ptr, bytes) ; } | 
| Chris@6 | 373 | 
| Chris@6 | 374 inline sf_count_t | 
| Chris@6 | 375 SndfileHandle::writeRaw (const void *ptr, sf_count_t bytes) | 
| Chris@6 | 376 {	return sf_write_raw (p->sf, ptr, bytes) ; } | 
| Chris@6 | 377 | 
| Chris@6 | 378 inline SNDFILE * | 
| Chris@6 | 379 SndfileHandle::rawHandle (void) | 
| Chris@6 | 380 {	return (p ? p->sf : NULL) ; } | 
| Chris@6 | 381 | 
| Chris@6 | 382 inline SNDFILE * | 
| Chris@6 | 383 SndfileHandle::takeOwnership (void) | 
| Chris@6 | 384 { | 
| Chris@6 | 385 	if (p == NULL || (p->ref != 1)) | 
| Chris@6 | 386 		return NULL ; | 
| Chris@6 | 387 | 
| Chris@6 | 388 	SNDFILE * sf = p->sf ; | 
| Chris@6 | 389 	p->sf = NULL ; | 
| Chris@6 | 390 	delete p ; | 
| Chris@6 | 391 	p = NULL ; | 
| Chris@6 | 392 	return sf ; | 
| Chris@6 | 393 } | 
| Chris@6 | 394 | 
| Chris@6 | 395 #ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES | 
| Chris@6 | 396 | 
| Chris@6 | 397 inline | 
| Chris@6 | 398 SndfileHandle::SndfileHandle (LPCWSTR wpath, int mode, int fmt, int chans, int srate) | 
| Chris@6 | 399 : p (NULL) | 
| Chris@6 | 400 { | 
| Chris@6 | 401 	p = new (std::nothrow) SNDFILE_ref () ; | 
| Chris@6 | 402 | 
| Chris@6 | 403 	if (p != NULL) | 
| Chris@6 | 404 	{	p->ref = 1 ; | 
| Chris@6 | 405 | 
| Chris@6 | 406 		p->sfinfo.frames = 0 ; | 
| Chris@6 | 407 		p->sfinfo.channels = chans ; | 
| Chris@6 | 408 		p->sfinfo.format = fmt ; | 
| Chris@6 | 409 		p->sfinfo.samplerate = srate ; | 
| Chris@6 | 410 		p->sfinfo.sections = 0 ; | 
| Chris@6 | 411 		p->sfinfo.seekable = 0 ; | 
| Chris@6 | 412 | 
| Chris@6 | 413 		p->sf = sf_wchar_open (wpath, mode, &p->sfinfo) ; | 
| Chris@6 | 414 		} ; | 
| Chris@6 | 415 | 
| Chris@6 | 416 	return ; | 
| Chris@6 | 417 } /* SndfileHandle const wchar_t * constructor */ | 
| Chris@6 | 418 | 
| Chris@6 | 419 #endif | 
| Chris@6 | 420 | 
| Chris@6 | 421 #endif	/* SNDFILE_HH */ | 
| Chris@6 | 422 |