Jamoma API  0.6.0.a19
TTSoundfile.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSoundFileLib
4  *
5  * @brief Provides a common interface to soundfile data
6  *
7  * @details This object provides a common set of attributes and methods for working with soundfiles at a specific filepath.
8  * This allows us to access metadata and copy values in a common way without duplicating code. As with the rest of the
9  * SoundfileLib, it relies on the third-party <a href="http://www.mega-nerd.com/libsndfile/">libsndfile library</a>.@n
10  * Be aware that attributes and metadata are cached when the setFilePath method is called in order to provide efficiency, but this may lead to problems if the file somehow changes after the method call.
11  *
12  * @authors Nathan Wolek
13  *
14  * @copyright Copyright © 2013 by Nathan Wolek @n
15  * This code is licensed under the terms of the "New BSD License" @n
16  * http://creativecommons.org/licenses/BSD/
17  */
18 
19 #ifndef __TT_SOUNDFILE_H__
20 #define __TT_SOUNDFILE_H__
21 
22 #include "TTDSP.h"
23 
24 #ifdef uint
25 #undef uint
26 #endif
27 #include "../libsndfile/sndfile.h"
28 
29 /** Creates an interface to data in a soundfile from disk */
32 
33 protected:
34  TTSymbol mFilePath; ///< full POSIX path to the file, including file name
35  TTColumnID mNumChannels; ///< channels in the file
36  TTFloat64 mSampleRate; ///< samples per second
37  TTRowID mLengthInSamples; ///< length in samples
38  TTFloat64 mLengthInSeconds; ///< length in seconds
39  TTSymbol mTitle; ///< title if metadata is present in the file
40  TTSymbol mArtist; ///< artist if metadata is present in the file
41  TTSymbol mDate; ///< date if metadata is present in the file
42  TTSymbol mAnnotation; ///< comments if metadata is present in the file
43 
44 private:
45  SNDFILE* mSoundFile; ///< libsndfile handle for the actual file we open
46  SF_INFO mSoundFileInfo; ///< libsndfile metadata for the file we open
47 
48 public:
49  /** Atribute accessor. Send a filepath to the object and attempt to interface with the file.
50  @param newValue full POSIX path to the file, including file name
51  @return TTErr kTTErrInvalidValue is the filepath is invalid, otherwise kTTErrNone
52  */
53  TTErr setFilePath(const TTValue& newValue);
54 
55  /** Simple data accessor.
56  @return TTColumnID the number of channels in mSoundFile at mFilePath */
58  {
59  return mNumChannels;
60  };
61 
62  /** Simple data accessor.
63  @return TTFloat64 samples per second of mSoundFile at mFilePath */
65  {
66  return mSampleRate;
67  };
68 
69  /** Simple data accessor.
70  @return TTRowID the number of frames in mSoundFile at mFilePath */
72  {
73  return mLengthInSamples;
74  };
75 
76  /** Simple data accessor.
77  @return TTFloat64 duration in second of mSoundFile at mFilePath */
79  {
80  return mLengthInSeconds;
81  };
82 
83  /** Simple data accessor.
84  @return TTSymbol title pulled from the mSoundFile's metadata */
86  {
87  return mTitle;
88  };
89 
90  /** Simple data accessor.
91  @return TTSymbol artist pulled from the mSoundFile's metadata */
93  {
94  return mArtist;
95  };
96 
97  /** Simple data accessor.
98  @return TTSymbol date pulled from the mSoundFile's metadata */
100  {
101  return mDate;
102  };
103 
104  /** Simple data accessor.
105  @return TTSymbol comments pulled from the mSoundFile's metadata */
107  {
108  return mAnnotation;
109  };
110 
111  /** Get the value stored at a specified frame and channel. Modelled after the method found in #TTSampleMatrix. Note that both channels and samples use zero indexing. There is currently no boundary checking implemented.
112  @param[in] frame index of sample as count from the beginning of file. first sample = 0.
113  @param[in] channel channel within multichannel file.
114  @param[out] value used to return the value pulled from sound file.
115  @return TTErr returns kTTErrNone until futher notice
116  */
117  TTErr peek(const TTRowID frame, const TTColumnID channel, TTSampleValue& value);
118 
119  /** Interpolate a value using a floating-point frame and integer channel. Modelled after the method found in #TTSampleMatrix. Note that both channels and samples use zero indexing. There is currently no boundary checking implemented.
120  @param[in] frame index of sample as count from the beginning of file. first sample = 0.
121  @param[in] channel channel within multichannel file.
122  @param[out] value used to return the value pulled from sound file.
123  @return TTErr returns kTTErrNone until futher notice
124  */
125  TTErr peeki(const TTFloat64 frame, const TTColumnID channel, TTSampleValue& value);
126 
127  /** Unit test for this object.
128  @param[out] returnedTestInfo The outcome from the performed unit test.
129  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
130  */
131  virtual TTErr test(TTValue& returnedTestInfo);
132 
133 };
134 
135 typedef TTSoundfile* TTSoundfilePtr;
136 
137 #endif
TTSymbol getDate()
Simple data accessor.
Definition: TTSoundfile.h:99
TTSymbol mDate
date if metadata is present in the file
Definition: TTSoundfile.h:41
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTRowID getLengthInSamples()
Simple data accessor.
Definition: TTSoundfile.h:71
TTFloat64 mSampleRate
samples per second
Definition: TTSoundfile.h:36
TTSymbol mArtist
artist if metadata is present in the file
Definition: TTSoundfile.h:40
TTSymbol getTitle()
Simple data accessor.
Definition: TTSoundfile.h:85
TTInt32 TTColumnID
Datatype for any number used to indicate a column index within the matrix.
Definition: TTBase.h:216
TTErr peek(const TTRowID frame, const TTColumnID channel, TTSampleValue &value)
Get the value stored at a specified frame and channel.
TTInt32 TTRowID
Datatype for any number used to indicate a row index within a matrix.
Definition: TTBase.h:207
Jamoma DSP Library.
virtual TTErr test(TTValue &returnedTestInfo)
Unit test for this object.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTColumnID mNumChannels
channels in the file
Definition: TTSoundfile.h:35
TTSymbol getAnnotation()
Simple data accessor.
Definition: TTSoundfile.h:106
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTSymbol mTitle
title if metadata is present in the file
Definition: TTSoundfile.h:39
TTFloat64 getSampleRate()
Simple data accessor.
Definition: TTSoundfile.h:64
TTSymbol mAnnotation
comments if metadata is present in the file
Definition: TTSoundfile.h:42
TTColumnID getNumChannels()
Simple data accessor.
Definition: TTSoundfile.h:57
TTRowID mLengthInSamples
length in samples
Definition: TTSoundfile.h:37
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTFloat64 getLengthInSeconds()
Simple data accessor.
Definition: TTSoundfile.h:78
Creates an interface to data in a soundfile from disk.
Definition: TTSoundfile.h:30
TTErr setFilePath(const TTValue &newValue)
Atribute accessor.
Definition: TTSoundfile.cpp:68
TTErr peeki(const TTFloat64 frame, const TTColumnID channel, TTSampleValue &value)
Interpolate a value using a floating-point frame and integer channel.
TTFloat64 mLengthInSeconds
length in seconds
Definition: TTSoundfile.h:38
TTSymbol mFilePath
full POSIX path to the file, including file name
Definition: TTSoundfile.h:34
TTSymbol getArtist()
Simple data accessor.
Definition: TTSoundfile.h:92
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34