Ardour  9.0-pre0-582-g084a23a80d
sndfile.hh
Go to the documentation of this file.
1 /*
2 ** Copyright (C) 2005-2007 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are
8 ** met:
9 **
10 ** * Redistributions of source code must retain the above copyright
11 ** notice, this list of conditions and the following disclaimer.
12 ** * Redistributions in binary form must reproduce the above copyright
13 ** notice, this list of conditions and the following disclaimer in
14 ** the documentation and/or other materials provided with the
15 ** distribution.
16 ** * Neither the author nor the names of any contributors may be used
17 ** to endorse or promote products derived from this software without
18 ** specific prior written permission.
19 **
20 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 /*
34 ** The above modified BSD style license (GPL and LGPL compatible) applies to
35 ** this file. It does not apply to libsndfile itself which is released under
36 ** the GNU LGPL or the libsndfile test suite which is released under the GNU
37 ** GPL.
38 ** This means that this header file can be used under this modified BSD style
39 ** license, but the LGPL still holds for the libsndfile library itself.
40 */
41 
42 /*
43 ** sndfile.hh -- A lightweight C++ wrapper for the libsndfile API.
44 **
45 ** All the methods are inlines and all functionality is contained in this
46 ** file. There is no separate implementation file.
47 **
48 ** API documentation is in the doc/ directory of the source code tarball
49 ** and at http://www.mega-nerd.com/libsndfile/api.html.
50 */
51 
52 #ifndef SNDFILE_HH
53 #define SNDFILE_HH
54 
56 
57 #include <sndfile.h>
58 
59 #include <string>
60 
61 // Prevent conflicts
62 namespace AudioGrapher {
63 
65 { private :
66  struct SNDFILE_ref
67  { SNDFILE_ref (void) ;
68  ~SNDFILE_ref (void) ;
69 
70  SNDFILE *sf ;
71  SF_INFO sfinfo ;
72  int ref ;
73  } ;
74 
76 
77  public :
78  /* Default constructor */
79  SndfileHandle (void) : p (NULL) {} ;
80  SndfileHandle (const char *path, int mode = SFM_READ,
81  int format = 0, int channels = 0, int samplerate = 0) ;
82  SndfileHandle (std::string const & path, int mode = SFM_READ,
83  int format = 0, int channels = 0, int samplerate = 0) ;
84  SndfileHandle (int fd, bool close_desc, int mode = SFM_READ,
85  int format = 0, int channels = 0, int samplerate = 0) ;
86  ~SndfileHandle (void) ;
87 
88  SndfileHandle (const SndfileHandle &orig) ;
89  SndfileHandle & operator = (const SndfileHandle &rhs) ;
90 
91  void close (void) ;
92 
93  /* Mainly for debugging/testing. */
94  int refCount (void) const { return (p == NULL) ? 0 : p->ref ; }
95 
96  operator bool () const { return (p != NULL) ; }
97 
98  bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; }
99 
100  sf_count_t frames (void) const { return p ? p->sfinfo.frames : 0 ; }
101  int format (void) const { return p ? p->sfinfo.format : 0 ; }
102  int channels (void) const { return p ? p->sfinfo.channels : 0 ; }
103  int samplerate (void) const { return p ? p->sfinfo.samplerate : 0 ; }
104 
105  int error (void) const ;
106  const char * strError (void) const ;
107 
108  int command (int cmd, void *data, int datasize) ;
109 
110  sf_count_t seek (sf_count_t frames, int whence) ;
111 
112  void writeSync (void) ;
113 
114  int setString (int str_type, const char* str) ;
115 
116  const char* getString (int str_type) const ;
117 
118  static int formatCheck (int format, int channels, int samplerate) ;
119 
120  sf_count_t read (short *ptr, sf_count_t items) ;
121  sf_count_t read (int *ptr, sf_count_t items) ;
122  sf_count_t read (float *ptr, sf_count_t items) ;
123  sf_count_t read (double *ptr, sf_count_t items) ;
124 
125  sf_count_t write (const short *ptr, sf_count_t items) ;
126  sf_count_t write (const int *ptr, sf_count_t items) ;
127  sf_count_t write (const float *ptr, sf_count_t items) ;
128  sf_count_t write (const double *ptr, sf_count_t items) ;
129 
130  sf_count_t readf (short *ptr, sf_count_t frames) ;
131  sf_count_t readf (int *ptr, sf_count_t frames) ;
132  sf_count_t readf (float *ptr, sf_count_t frames) ;
133  sf_count_t readf (double *ptr, sf_count_t frames) ;
134 
135  sf_count_t writef (const short *ptr, sf_count_t frames) ;
136  sf_count_t writef (const int *ptr, sf_count_t frames) ;
137  sf_count_t writef (const float *ptr, sf_count_t frames) ;
138  sf_count_t writef (const double *ptr, sf_count_t frames) ;
139 
140  sf_count_t readRaw (void *ptr, sf_count_t bytes) ;
141  sf_count_t writeRaw (const void *ptr, sf_count_t bytes) ;
142 
143 } ;
144 
145 } // namespace AudioGrapher
146 
147 #endif /* SNDFILE_HH */
148 
sf_count_t frames(void) const
Definition: sndfile.hh:100
int refCount(void) const
Definition: sndfile.hh:94
int command(int cmd, void *data, int datasize)
sf_count_t seek(sf_count_t frames, int whence)
sf_count_t writef(const short *ptr, sf_count_t frames)
sf_count_t writeRaw(const void *ptr, sf_count_t bytes)
sf_count_t read(short *ptr, sf_count_t items)
sf_count_t write(const int *ptr, sf_count_t items)
int samplerate(void) const
Definition: sndfile.hh:103
SndfileHandle(int fd, bool close_desc, int mode=SFM_READ, int format=0, int channels=0, int samplerate=0)
sf_count_t write(const float *ptr, sf_count_t items)
const char * getString(int str_type) const
sf_count_t readf(int *ptr, sf_count_t frames)
const char * strError(void) const
int setString(int str_type, const char *str)
SndfileHandle(std::string const &path, int mode=SFM_READ, int format=0, int channels=0, int samplerate=0)
sf_count_t readf(float *ptr, sf_count_t frames)
static int formatCheck(int format, int channels, int samplerate)
sf_count_t read(float *ptr, sf_count_t items)
sf_count_t readf(short *ptr, sf_count_t frames)
sf_count_t write(const double *ptr, sf_count_t items)
sf_count_t readf(double *ptr, sf_count_t frames)
sf_count_t writef(const double *ptr, sf_count_t frames)
sf_count_t write(const short *ptr, sf_count_t items)
SndfileHandle(const char *path, int mode=SFM_READ, int format=0, int channels=0, int samplerate=0)
sf_count_t writef(const float *ptr, sf_count_t frames)
int channels(void) const
Definition: sndfile.hh:102
sf_count_t read(double *ptr, sf_count_t items)
sf_count_t readRaw(void *ptr, sf_count_t bytes)
sf_count_t read(int *ptr, sf_count_t items)
int format(void) const
Definition: sndfile.hh:101
SndfileHandle(const SndfileHandle &orig)
sf_count_t writef(const int *ptr, sf_count_t frames)
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
minimum disk read bytes