Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:jamoma/JamomaCore into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
theod committed Jul 23, 2013
2 parents 6055352 + 581f6eb commit 134dc09
Show file tree
Hide file tree
Showing 23 changed files with 2,626 additions and 73 deletions.
16 changes: 16 additions & 0 deletions DSP/Tests/unit/soundfile.test.rb
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby -wKU
# encoding: utf-8

require 'Jamoma'

environment = TTObject.new "environment"
environment.set "benchmarking", 1

o = TTAudio.new "soundfile", 1
o.send "test"

err, cpu = o.send "getProcessingBenchmark", 1

puts
puts "time spent calculating audio process method: #{cpu} µs"
puts
16 changes: 16 additions & 0 deletions DSP/Tests/unit/soundfileloader.test.rb
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby -wKU
# encoding: utf-8

require 'Jamoma'

environment = TTObject.new "environment"
environment.set "benchmarking", 1

o = TTAudio.new "soundfile.loader", 1
o.send "test"

err, cpu = o.send "getProcessingBenchmark", 1

puts
puts "time spent calculating audio process method: #{cpu} µs"
puts
Expand Up @@ -168,11 +168,12 @@
/* Begin PBXLegacyTarget section */
A738FF55163739D100BD5C89 /* EffectsLib */ = {
isa = PBXLegacyTarget;
buildArgumentsString = "$(ACTION)";
buildArgumentsString = "$(CONFIGURATION) $(ACTION)";
buildConfigurationList = A738FF58163739D100BD5C89 /* Build configuration list for PBXLegacyTarget "EffectsLib" */;
buildPhases = (
);
buildToolPath = /usr/bin/make;
buildWorkingDirectory = "";
dependencies = (
);
name = EffectsLib;
Expand Down
4 changes: 4 additions & 0 deletions DSP/extensions/SoundfileLib/SoundfileLib.cpp
Expand Up @@ -8,6 +8,8 @@
*/

#include "TTDSP.h"
#include "TTSoundfile.h"
#include "TTSoundfileLoader.h"
#include "TTSoundfilePlayer.h"
#include "TTSoundfileRecorder.h"

Expand All @@ -16,6 +18,8 @@ extern "C" TT_EXTENSION_EXPORT TTErr TTLoadJamomaExtension_SoundfileLib(void)
{
TTDSPInit();

TTSoundfile::registerClass();
TTSoundfileLoader::registerClass();
TTSoundfilePlayer::registerClass();
TTSoundfileRecorder::registerClass();

Expand Down
10 changes: 7 additions & 3 deletions DSP/extensions/SoundfileLib/SoundfileLib.yml
@@ -1,11 +1,15 @@

sources:
- SoundfileLib.cpp
- TTSoundfilePlayer.cpp
- TTSoundfileRecorder.cpp
- sources/TTSoundfile.cpp
- sources/TTSoundfileLoader.cpp
- sources/TTSoundfilePlayer.cpp
- sources/TTSoundfileRecorder.cpp
- tests/TTSoundfile.test.cpp
- tests/TTSoundfileLoader.test.cpp

includes:
- "."
- "includes"
- "libsndfile"
- "../../library/includes"
- "../../../Foundation/library/includes"
Expand Down
1,073 changes: 1,073 additions & 0 deletions DSP/extensions/SoundfileLib/SoundfileLibIOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions DSP/extensions/SoundfileLib/includes/TTSoundfile.h
@@ -0,0 +1,137 @@
/** @file
*
* @ingroup dspSoundFileLib
*
* @brief Provides a common interface to soundfile data
*
* @details This object provides a common set of attributes and methods for working with soundfiles at a specific filepath.
* This allows us to access metadata and copy values in a common way without duplicating code. As with the rest of the
* SoundfileLib, it relies on the third-party <a href="http://www.mega-nerd.com/libsndfile/">libsndfile library</a>.@n
* 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.
*
* @authors Nathan Wolek
*
* @copyright Copyright © 2013 by Nathan Wolek @n
* This code is licensed under the terms of the "New BSD License" @n
* http://creativecommons.org/licenses/BSD/
*/

#ifndef __TT_SOUNDFILE_H__
#define __TT_SOUNDFILE_H__

#include "TTDSP.h"

#ifdef uint
#undef uint
#endif
#include "../libsndfile/sndfile.h"

/** Creates an interface to data in a soundfile from disk */
class TTSoundfile : public TTAudioObjectBase {
TTCLASS_SETUP(TTSoundfile)

protected:
TTSymbol mFilePath; ///< full POSIX path to the file, including file name
TTColumnID mNumChannels; ///< channels in the file
TTFloat64 mSampleRate; ///< samples per second
TTRowID mLengthInSamples; ///< length in samples
TTFloat64 mLengthInSeconds; ///< length in seconds
TTSymbol mTitle; ///< title if metadata is present in the file
TTSymbol mArtist; ///< artist if metadata is present in the file
TTSymbol mDate; ///< date if metadata is present in the file
TTSymbol mAnnotation; ///< comments if metadata is present in the file

private:
SNDFILE* mSoundFile; ///< libsndfile handle for the actual file we open
SF_INFO mSoundFileInfo; ///< libsndfile metadata for the file we open

public:
/** Atribute accessor. Send a filepath to the object and attempt to interface with the file.
@param newValue full POSIX path to the file, including file name
@return TTErr kTTErrInvalidValue is the filepath is invalid, otherwise kTTErrNone
*/
TTErr setFilePath(const TTValue& newValue);

/** Simple data accessor.
@return TTColumnID the number of channels in mSoundFile at mFilePath */
TTColumnID getNumChannels()
{
return mNumChannels;
};

/** Simple data accessor.
@return TTFloat64 samples per second of mSoundFile at mFilePath */
TTFloat64 getSampleRate()
{
return mSampleRate;
};

/** Simple data accessor.
@return TTRowID the number of frames in mSoundFile at mFilePath */
TTRowID getLengthInSamples()
{
return mLengthInSamples;
};

/** Simple data accessor.
@return TTFloat64 duration in second of mSoundFile at mFilePath */
TTFloat64 getLengthInSeconds()
{
return mLengthInSeconds;
};

/** Simple data accessor.
@return TTSymbol title pulled from the mSoundFile's metadata */
TTSymbol getTitle()
{
return mTitle;
};

/** Simple data accessor.
@return TTSymbol artist pulled from the mSoundFile's metadata */
TTSymbol getArtist()
{
return mArtist;
};

/** Simple data accessor.
@return TTSymbol date pulled from the mSoundFile's metadata */
TTSymbol getDate()
{
return mDate;
};

/** Simple data accessor.
@return TTSymbol comments pulled from the mSoundFile's metadata */
TTSymbol getAnnotation()
{
return mAnnotation;
};

/** 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.
@param[in] frame index of sample as count from the beginning of file. first sample = 0.
@param[in] channel channel within multichannel file.
@param[out] value used to return the value pulled from sound file.
@return TTErr returns kTTErrNone until futher notice
*/
TTErr peek(const TTRowID frame, const TTColumnID channel, TTSampleValue& value);

/** 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.
@param[in] frame index of sample as count from the beginning of file. first sample = 0.
@param[in] channel channel within multichannel file.
@param[out] value used to return the value pulled from sound file.
@return TTErr returns kTTErrNone until futher notice
*/
TTErr peeki(const TTFloat64 frame, const TTColumnID channel, TTSampleValue& value);

/** Unit test for this object.
@param[out] returnedTestInfo The outcome from the performed unit test.
@return #TTErr error code if the method fails to execute, else #kTTErrNone.
*/
virtual TTErr test(TTValue& returnedTestInfo);

};

typedef TTSoundfile* TTSoundfilePtr;

#endif
89 changes: 89 additions & 0 deletions DSP/extensions/SoundfileLib/includes/TTSoundfileLoader.h
@@ -0,0 +1,89 @@
/** @file
*
* @ingroup dspSoundFileLib
*
* @brief Loads soundfile data into a sample matrix
*
* @details This object collaborates with #TTSampleMatrix to load values from a sound file into the sample matrix. An extension of the #TTSoundfile object.
*
* @see TTSampleMatrix
*
* @authors Nathan Wolek
*
* @copyright Copyright © 2013 by Nathan Wolek @n
* This code is licensed under the terms of the "New BSD License" @n
* http://creativecommons.org/licenses/BSD/
*/

#ifndef __TT_SOUNDFILELOADER_H__
#define __TT_SOUNDFILELOADER_H__

#include "TTDSP.h"
#include "TTSoundfile.h"
#include "TTSampleMatrix.h"

/** Creates an interface to data in a soundfile from disk */
class TTSoundfileLoader : public TTSoundfile {
TTCLASS_SETUP(TTSoundfileLoader)

protected:
TTSampleMatrixPtr mTargetMatrix;
TTRowID mTargetMatrixLengthInSamples;
TTColumnID mTargetMatrixNumChannels;
TTFloat64 mTargetMatrixSampleRate;
TTRowID mStartCopyAtSampleIndex;
TTRowID mEndCopyAtSampleIndex;
TTColumnID mCopyFromChannelIndex;

/** Internal method that sets the class's pointer to the target sample matrix for loading sound file data.
@param newTargetMatrix pointer to the new matrix
@return TTErr kTTErrNone if the pointer was updated.
*/
TTErr setTargetMatrix(const TTSampleMatrixPtr newTargetMatrix);

/** Internal method that sets the class's pointer to the target sample matrix for loading sound file data. This version is a function overload so that setTargetMatrix() can accept a TTObjectBase* as an input parameter and test whether it points to an actual instance of TTSampleMatrix.
@param newTargetMatrix pointer to the new matrix
@return TTErr kTTErrNone if the pointer was updated. kTTErrInvalidValue if the pointer was not to a TTSampleMatrix.
*/
TTErr setTargetMatrix(const TTObjectBase* newTargetObjectPtr);

/** Internal method that copies values from the source TTSoundfile to the targetted TTSampleMatrix. Beware that the setFilePath() and setTargetMatrix() must be successfully executed before this method is called.
@return TTErr kTTErrNone if copy is successful. kTTErrGeneric if the source soundfile was too short to fill samplematrix.
*/
TTErr copyUntilFilled();

/** Internal method that copies values from the source TTSoundfile to the targetted TTSampleMatrix with the necessary interpolation to acheive the target's sample rate. Beware that the setFilePath() and setTargetMatrix() must be successfully executed before this method is called.
@return TTErr kTTErrNone if copy is successful. kTTErrGeneric if the source soundfile was too short to fill samplematrix.
*/
TTErr copyUntilFilledWithResampling();

public:
/** Atribute accessor. Send a filepath to the object and attempt to interface with the file. Overriding so that additional variable will be set when setting the filepath.
@param newValue full POSIX path to the file, including file name
@return TTErr kTTErrInvalidValue is the filepath is invalid, otherwise kTTErrNone
*/
TTErr setFilePath(const TTValue& newValue);

/** Public method used to trigger the load process. Copies samples from a sound file on the hard drive into a TTSampleMatrix.
@param[in] input Multi-item TTValue used to set the copy parameters:
-# TTObjectBasePtr to the target matrix
-# TTSymbol containing the filepath
-# (optional) channel to copy from source, default is 0
-# (optional) frame to start copy from source, default is 0
-# (optional) frame to stop copy from source, default is last
@param[out] unusedOutput not used
@return TTErr kTTErrNone load was successful. kTTErrInvalidFilepath if the filepath was invalid. kTTErrInvalidValue if the pointer to TTSampleMatrix was invalid.
*/
TTErr load(const TTValueRef input, TTValueRef unusedOutput);

/** Unit test for this object.
@param[out] returnedTestInfo The outcome from the performed unit test.
@return #TTErr error code if the method fails to execute, else #kTTErrNone.
*/
virtual TTErr test(TTValue& returnedTestInfo);

};

typedef TTSoundfileLoader* TTSoundfileLoaderPtr;

#endif /* defined(__TT_SOUNDFILELOADER_H__) */
Expand Up @@ -21,10 +21,10 @@
#ifdef uint
#undef uint
#endif
#include "libsndfile/sndfile.h"
#include "../libsndfile/sndfile.h"


/** The simplest of lowpass filters: a single-pole, no-zero algorithm. */
/** Enables user to play a soundfile from disk */
class TTSoundfilePlayer : public TTAudioObjectBase {
TTCLASS_SETUP(TTSoundfilePlayer)

Expand Down
Expand Up @@ -21,10 +21,10 @@
#ifdef uint
#undef uint
#endif
#include "libsndfile/sndfile.h"
#include "../libsndfile/sndfile.h"


/** The simplest of lowpass filters: a single-pole, no-zero algorithm. */
/** Enables user to record a soundfile to disk */
class TTSoundfileRecorder : public TTAudioObjectBase {
TTCLASS_SETUP(TTSoundfileRecorder)

Expand Down

0 comments on commit 134dc09

Please sign in to comment.