| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,238 +0,0 @@ |
| 1 |
-////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
-/// |
|
| 3 |
-/// SoundTouch - main class for tempo/pitch/rate adjusting routines. |
|
| 4 |
-/// |
|
| 5 |
-/// Notes: |
|
| 6 |
-/// - Initialize the SoundTouch object instance by setting up the sound stream |
|
| 7 |
-/// parameters with functions 'setSampleRate' and 'setChannels', then set |
|
| 8 |
-/// desired tempo/pitch/rate settings with the corresponding functions. |
|
| 9 |
-/// |
|
| 10 |
-/// - The SoundTouch class behaves like a first-in-first-out pipeline: The |
|
| 11 |
-/// samples that are to be processed are fed into one of the pipe by calling |
|
| 12 |
-/// function 'putSamples', while the ready processed samples can be read |
|
| 13 |
-/// from the other end of the pipeline with function 'receiveSamples'. |
|
| 14 |
-/// |
|
| 15 |
-/// - The SoundTouch processing classes require certain sized 'batches' of |
|
| 16 |
-/// samples in order to process the sound. For this reason the classes buffer |
|
| 17 |
-/// incoming samples until there are enough of samples available for |
|
| 18 |
-/// processing, then they carry out the processing step and consequently |
|
| 19 |
-/// make the processed samples available for outputting. |
|
| 20 |
-/// |
|
| 21 |
-/// - For the above reason, the processing routines introduce a certain |
|
| 22 |
-/// 'latency' between the input and output, so that the samples input to |
|
| 23 |
-/// SoundTouch may not be immediately available in the output, and neither |
|
| 24 |
-/// the amount of outputtable samples may not immediately be in direct |
|
| 25 |
-/// relationship with the amount of previously input samples. |
|
| 26 |
-/// |
|
| 27 |
-/// - The tempo/pitch/rate control parameters can be altered during processing. |
|
| 28 |
-/// Please notice though that they aren't currently protected by semaphores, |
|
| 29 |
-/// so in multi-thread application external semaphore protection may be |
|
| 30 |
-/// required. |
|
| 31 |
-/// |
|
| 32 |
-/// - This class utilizes classes 'TDStretch' for tempo change (without modifying |
|
| 33 |
-/// pitch) and 'RateTransposer' for changing the playback rate (that is, both |
|
| 34 |
-/// tempo and pitch in the same ratio) of the sound. The third available control |
|
| 35 |
-/// 'pitch' (change pitch but maintain tempo) is produced by a combination of |
|
| 36 |
-/// combining the two other controls. |
|
| 37 |
-/// |
|
| 38 |
-/// Author : Copyright (c) Olli Parviainen |
|
| 39 |
-/// Author e-mail : oparviai 'at' iki.fi |
|
| 40 |
-/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 41 |
-/// |
|
| 42 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
-// |
|
| 44 |
-// Last changed : $Date: 2012-12-28 17:32:59 -0200 (sex, 28 dez 2012) $ |
|
| 45 |
-// File revision : $Revision: 4 $ |
|
| 46 |
-// |
|
| 47 |
-// $Id: SoundTouch.h 163 2012-12-28 19:32:59Z oparviai $ |
|
| 48 |
-// |
|
| 49 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
-// |
|
| 51 |
-// License : |
|
| 52 |
-// |
|
| 53 |
-// SoundTouch audio processing library |
|
| 54 |
-// Copyright (c) Olli Parviainen |
|
| 55 |
-// |
|
| 56 |
-// This library is free software; you can redistribute it and/or |
|
| 57 |
-// modify it under the terms of the GNU Lesser General Public |
|
| 58 |
-// License as published by the Free Software Foundation; either |
|
| 59 |
-// version 2.1 of the License, or (at your option) any later version. |
|
| 60 |
-// |
|
| 61 |
-// This library is distributed in the hope that it will be useful, |
|
| 62 |
-// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 63 |
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 64 |
-// Lesser General Public License for more details. |
|
| 65 |
-// |
|
| 66 |
-// You should have received a copy of the GNU Lesser General Public |
|
| 67 |
-// License along with this library; if not, write to the Free Software |
|
| 68 |
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 69 |
-// |
|
| 70 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 71 |
- |
|
| 72 |
-#pragma once |
|
| 73 |
- |
|
| 74 |
-#include <memory> |
|
| 75 |
-#include "FIFOSamplePipe.h" |
|
| 76 |
-#include "RateTransposer.h" |
|
| 77 |
-#include "TDStretch.h" |
|
| 78 |
- |
|
| 79 |
-namespace soundtouch |
|
| 80 |
-{
|
|
| 81 |
- |
|
| 82 |
-/// Soundtouch library version string |
|
| 83 |
-const char *const SOUNDTOUCH_VERSION = "1.7.1"; |
|
| 84 |
- |
|
| 85 |
-/// SoundTouch library version id |
|
| 86 |
-const uint32_t SOUNDTOUCH_VERSION_ID = 010701; |
|
| 87 |
- |
|
| 88 |
-// Available setting IDs for the 'setSetting' & 'get_setting' functions: |
|
| 89 |
- |
|
| 90 |
-/// Enable/disable anti-alias filter in pitch transposer (0 = disable) |
|
| 91 |
-const int32_t SETTING_USE_AA_FILTER = 0; |
|
| 92 |
- |
|
| 93 |
-/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32) |
|
| 94 |
-const int32_t SETTING_AA_FILTER_LENGTH = 1; |
|
| 95 |
- |
|
| 96 |
-/// Enable/disable quick seeking algorithm in tempo changer routine |
|
| 97 |
-/// (enabling quick seeking lowers CPU utilization but causes a minor sound |
|
| 98 |
-/// quality compromising) |
|
| 99 |
-const int32_t SETTING_USE_QUICKSEEK = 2; |
|
| 100 |
- |
|
| 101 |
-/// Time-stretch algorithm single processing sequence length in milliseconds. This determines |
|
| 102 |
-/// to how long sequences the original sound is chopped in the time-stretch algorithm. |
|
| 103 |
-/// See "STTypes.h" or README for more information. |
|
| 104 |
-const int32_t SETTING_SEQUENCE_MS = 3; |
|
| 105 |
- |
|
| 106 |
-/// Time-stretch algorithm seeking window length in milliseconds for algorithm that finds the |
|
| 107 |
-/// best possible overlapping location. This determines from how wide window the algorithm |
|
| 108 |
-/// may look for an optimal joining location when mixing the sound sequences back together. |
|
| 109 |
-/// See "STTypes.h" or README for more information. |
|
| 110 |
-const int32_t SETTING_SEEKWINDOW_MS = 4; |
|
| 111 |
- |
|
| 112 |
-/// Time-stretch algorithm overlap length in milliseconds. When the chopped sound sequences |
|
| 113 |
-/// are mixed back together, to form a continuous sound stream, this parameter defines over |
|
| 114 |
-/// how long period the two consecutive sequences are let to overlap each other. |
|
| 115 |
-/// See "STTypes.h" or README for more information. |
|
| 116 |
-const int32_t SETTING_OVERLAP_MS = 5; |
|
| 117 |
- |
|
| 118 |
-/// Call "getSetting" with this ID to query nominal average processing sequence |
|
| 119 |
-/// size in samples. This value tells approcimate value how many input samples |
|
| 120 |
-/// SoundTouch needs to gather before it does DSP processing run for the sample batch. |
|
| 121 |
-/// |
|
| 122 |
-/// Notices: |
|
| 123 |
-/// - This is read-only parameter, i.e. setSetting ignores this parameter |
|
| 124 |
-/// - Returned value is approximate average value, exact processing batch |
|
| 125 |
-/// size may wary from time to time |
|
| 126 |
-/// - This parameter value is not constant but may change depending on |
|
| 127 |
-/// tempo/pitch/rate/samplerate settings. |
|
| 128 |
-const int32_t SETTING_NOMINAL_INPUT_SEQUENCE = 6; |
|
| 129 |
- |
|
| 130 |
-/// Call "getSetting" with this ID to query nominal average processing output |
|
| 131 |
-/// size in samples. This value tells approcimate value how many output samples |
|
| 132 |
-/// SoundTouch outputs once it does DSP processing run for a batch of input samples. |
|
| 133 |
-/// |
|
| 134 |
-/// Notices: |
|
| 135 |
-/// - This is read-only parameter, i.e. setSetting ignores this parameter |
|
| 136 |
-/// - Returned value is approximate average value, exact processing batch |
|
| 137 |
-/// size may wary from time to time |
|
| 138 |
-/// - This parameter value is not constant but may change depending on |
|
| 139 |
-/// tempo/pitch/rate/samplerate settings. |
|
| 140 |
-const int32_t SETTING_NOMINAL_OUTPUT_SEQUENCE = 7; |
|
| 141 |
- |
|
| 142 |
-class SoundTouch : public FIFOProcessor |
|
| 143 |
-{
|
|
| 144 |
-private: |
|
| 145 |
- /// Rate transposer class instance |
|
| 146 |
- std::unique_ptr<RateTransposer> pRateTransposer; |
|
| 147 |
- |
|
| 148 |
- /// Time-stretch class instance |
|
| 149 |
- std::unique_ptr<TDStretch> pTDStretch; |
|
| 150 |
- |
|
| 151 |
- /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 152 |
- float virtualRate; |
|
| 153 |
- |
|
| 154 |
- /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 155 |
- float virtualTempo; |
|
| 156 |
- |
|
| 157 |
- /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 158 |
- float virtualPitch; |
|
| 159 |
- |
|
| 160 |
- /// Flag: Has sample rate been set? |
|
| 161 |
- bool bSrateSet; |
|
| 162 |
- |
|
| 163 |
- /// Calculates effective rate & tempo valuescfrom 'virtualRate', 'virtualTempo' and |
|
| 164 |
- /// 'virtualPitch' parameters. |
|
| 165 |
- void calcEffectiveRateAndTempo(); |
|
| 166 |
- |
|
| 167 |
-protected: |
|
| 168 |
- /// Number of channels |
|
| 169 |
- uint32_t channels; |
|
| 170 |
- |
|
| 171 |
- /// Effective 'rate' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch' |
|
| 172 |
- float rate; |
|
| 173 |
- |
|
| 174 |
- /// Effective 'tempo' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch' |
|
| 175 |
- float tempo; |
|
| 176 |
- |
|
| 177 |
-public: |
|
| 178 |
- SoundTouch(); |
|
| 179 |
- |
|
| 180 |
- /// Sets new rate control value. Normal rate = 1.0, smaller values |
|
| 181 |
- /// represent slower rate, larger faster rates. |
|
| 182 |
- void setRate(float newRate); |
|
| 183 |
- |
|
| 184 |
- /// Sets new tempo control value. Normal tempo = 1.0, smaller values |
|
| 185 |
- /// represent slower tempo, larger faster tempo. |
|
| 186 |
- void setTempo(float newTempo); |
|
| 187 |
- |
|
| 188 |
- /// Sets the number of channels, 1 = mono, 2 = stereo |
|
| 189 |
- void setChannels(uint32_t numChannels); |
|
| 190 |
- |
|
| 191 |
- /// Sets sample rate. |
|
| 192 |
- void setSampleRate(uint32_t srate); |
|
| 193 |
- |
|
| 194 |
- /// Flushes the last samples from the processing pipeline to the output. |
|
| 195 |
- /// Clears also the internal processing buffers. |
|
| 196 |
- // |
|
| 197 |
- /// Note: This function is meant for extracting the last samples of a sound |
|
| 198 |
- /// stream. This function may introduce additional blank samples in the end |
|
| 199 |
- /// of the sound stream, and thus it's not recommended to call this function |
|
| 200 |
- /// in the middle of a sound stream. |
|
| 201 |
- void flush(); |
|
| 202 |
- |
|
| 203 |
- /// Adds 'numSamples' pcs of samples from the 'samples' memory position into |
|
| 204 |
- /// the input of the object. Notice that sample rate _has_to_ be set before |
|
| 205 |
- /// calling this function, otherwise throws a runtime_error exception. |
|
| 206 |
- void putSamples( |
|
| 207 |
- const SAMPLETYPE *samples, ///< Pointer to sample buffer. |
|
| 208 |
- uint32_t numSamples ///< Number of samples in buffer. Notice |
|
| 209 |
- ///< that in case of stereo-sound a single sample |
|
| 210 |
- ///< contains data for both channels. |
|
| 211 |
- ); |
|
| 212 |
- |
|
| 213 |
- /// Clears all the samples in the object's output and internal processing |
|
| 214 |
- /// buffers. |
|
| 215 |
- void clear(); |
|
| 216 |
- |
|
| 217 |
- /// Changes a setting controlling the processing system behaviour. See the |
|
| 218 |
- /// 'SETTING_...' defines for available setting ID's. |
|
| 219 |
- /// |
|
| 220 |
- /// \return 'true' if the setting was succesfully changed |
|
| 221 |
- bool setSetting(int32_t settingId, ///< Setting ID number. see SETTING_... defines. |
|
| 222 |
- int32_t value ///< New setting value. |
|
| 223 |
- ); |
|
| 224 |
- |
|
| 225 |
- /// Returns number of samples currently unprocessed. |
|
| 226 |
- uint32_t numUnprocessedSamples() const; |
|
| 227 |
- |
|
| 228 |
- /// Other handy functions that are implemented in the ancestor classes (see |
|
| 229 |
- /// classes 'FIFOProcessor' and 'FIFOSamplePipe') |
|
| 230 |
- /// |
|
| 231 |
- /// - receiveSamples() : Use this function to receive 'ready' processed samples from SoundTouch. |
|
| 232 |
- /// - numSamples() : Get number of 'ready' samples that can be received with |
|
| 233 |
- /// function 'receiveSamples()' |
|
| 234 |
- /// - isEmpty() : Returns nonzero if there aren't any 'ready' samples. |
|
| 235 |
- /// - clear() : Clears all samples from ready/processing buffers. |
|
| 236 |
-}; |
|
| 237 |
- |
|
| 238 |
-} |
* [2SF] Used more up-to-date asmjit, despite the ugly looking code.
| ... | ... |
@@ -73,6 +73,8 @@ |
| 73 | 73 |
|
| 74 | 74 |
#include <memory> |
| 75 | 75 |
#include "FIFOSamplePipe.h" |
| 76 |
+#include "RateTransposer.h" |
|
| 77 |
+#include "TDStretch.h" |
|
| 76 | 78 |
|
| 77 | 79 |
namespace soundtouch |
| 78 | 80 |
{
|
| ... | ... |
@@ -114,32 +116,29 @@ const int32_t SETTING_SEEKWINDOW_MS = 4; |
| 114 | 116 |
const int32_t SETTING_OVERLAP_MS = 5; |
| 115 | 117 |
|
| 116 | 118 |
/// Call "getSetting" with this ID to query nominal average processing sequence |
| 117 |
-/// size in samples. This value tells approcimate value how many input samples |
|
| 119 |
+/// size in samples. This value tells approcimate value how many input samples |
|
| 118 | 120 |
/// SoundTouch needs to gather before it does DSP processing run for the sample batch. |
| 119 | 121 |
/// |
| 120 |
-/// Notices: |
|
| 122 |
+/// Notices: |
|
| 121 | 123 |
/// - This is read-only parameter, i.e. setSetting ignores this parameter |
| 122 | 124 |
/// - Returned value is approximate average value, exact processing batch |
| 123 | 125 |
/// size may wary from time to time |
| 124 |
-/// - This parameter value is not constant but may change depending on |
|
| 126 |
+/// - This parameter value is not constant but may change depending on |
|
| 125 | 127 |
/// tempo/pitch/rate/samplerate settings. |
| 126 | 128 |
const int32_t SETTING_NOMINAL_INPUT_SEQUENCE = 6; |
| 127 | 129 |
|
| 128 |
-/// Call "getSetting" with this ID to query nominal average processing output |
|
| 129 |
-/// size in samples. This value tells approcimate value how many output samples |
|
| 130 |
+/// Call "getSetting" with this ID to query nominal average processing output |
|
| 131 |
+/// size in samples. This value tells approcimate value how many output samples |
|
| 130 | 132 |
/// SoundTouch outputs once it does DSP processing run for a batch of input samples. |
| 131 |
-/// |
|
| 132 |
-/// Notices: |
|
| 133 |
+/// |
|
| 134 |
+/// Notices: |
|
| 133 | 135 |
/// - This is read-only parameter, i.e. setSetting ignores this parameter |
| 134 | 136 |
/// - Returned value is approximate average value, exact processing batch |
| 135 | 137 |
/// size may wary from time to time |
| 136 |
-/// - This parameter value is not constant but may change depending on |
|
| 138 |
+/// - This parameter value is not constant but may change depending on |
|
| 137 | 139 |
/// tempo/pitch/rate/samplerate settings. |
| 138 | 140 |
const int32_t SETTING_NOMINAL_OUTPUT_SEQUENCE = 7; |
| 139 | 141 |
|
| 140 |
-class RateTransposer; |
|
| 141 |
-class TDStretch; |
|
| 142 |
- |
|
| 143 | 142 |
class SoundTouch : public FIFOProcessor |
| 144 | 143 |
{
|
| 145 | 144 |
private: |
| ... | ... |
@@ -69,8 +69,7 @@ |
| 69 | 69 |
// |
| 70 | 70 |
//////////////////////////////////////////////////////////////////////////////// |
| 71 | 71 |
|
| 72 |
-#ifndef SoundTouch_H |
|
| 73 |
-#define SoundTouch_H |
|
| 72 |
+#pragma once |
|
| 74 | 73 |
|
| 75 | 74 |
#include <memory> |
| 76 | 75 |
#include "FIFOSamplePipe.h" |
| ... | ... |
@@ -238,5 +237,3 @@ public: |
| 238 | 237 |
}; |
| 239 | 238 |
|
| 240 | 239 |
} |
| 241 |
- |
|
| 242 |
-#endif |
| ... | ... |
@@ -178,7 +178,6 @@ protected: |
| 178 | 178 |
|
| 179 | 179 |
public: |
| 180 | 180 |
SoundTouch(); |
| 181 |
- virtual ~SoundTouch(); |
|
| 182 | 181 |
|
| 183 | 182 |
/// Sets new rate control value. Normal rate = 1.0, smaller values |
| 184 | 183 |
/// represent slower rate, larger faster rates. |
| ... | ... |
@@ -188,27 +187,6 @@ public: |
| 188 | 187 |
/// represent slower tempo, larger faster tempo. |
| 189 | 188 |
void setTempo(float newTempo); |
| 190 | 189 |
|
| 191 |
- /// Sets new rate control value as a difference in percents compared |
|
| 192 |
- /// to the original rate (-50 .. +100 %) |
|
| 193 |
- void setRateChange(float newRate); |
|
| 194 |
- |
|
| 195 |
- /// Sets new tempo control value as a difference in percents compared |
|
| 196 |
- /// to the original tempo (-50 .. +100 %) |
|
| 197 |
- void setTempoChange(float newTempo); |
|
| 198 |
- |
|
| 199 |
- /// Sets new pitch control value. Original pitch = 1.0, smaller values |
|
| 200 |
- /// represent lower pitches, larger values higher pitch. |
|
| 201 |
- void setPitch(float newPitch); |
|
| 202 |
- |
|
| 203 |
- /// Sets pitch change in octaves compared to the original pitch |
|
| 204 |
- /// (-1.00 .. +1.00) |
|
| 205 |
- void setPitchOctaves(float newPitch); |
|
| 206 |
- |
|
| 207 |
- /// Sets pitch change in semi-tones compared to the original pitch |
|
| 208 |
- /// (-12 .. +12) |
|
| 209 |
- void setPitchSemiTones(int newPitch); |
|
| 210 |
- void setPitchSemiTones(float newPitch); |
|
| 211 |
- |
|
| 212 | 190 |
/// Sets the number of channels, 1 = mono, 2 = stereo |
| 213 | 191 |
void setChannels(uint32_t numChannels); |
| 214 | 192 |
|
| ... | ... |
@@ -227,7 +205,7 @@ public: |
| 227 | 205 |
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into |
| 228 | 206 |
/// the input of the object. Notice that sample rate _has_to_ be set before |
| 229 | 207 |
/// calling this function, otherwise throws a runtime_error exception. |
| 230 |
- virtual void putSamples( |
|
| 208 |
+ void putSamples( |
|
| 231 | 209 |
const SAMPLETYPE *samples, ///< Pointer to sample buffer. |
| 232 | 210 |
uint32_t numSamples ///< Number of samples in buffer. Notice |
| 233 | 211 |
///< that in case of stereo-sound a single sample |
| ... | ... |
@@ -236,7 +214,7 @@ public: |
| 236 | 214 |
|
| 237 | 215 |
/// Clears all the samples in the object's output and internal processing |
| 238 | 216 |
/// buffers. |
| 239 |
- virtual void clear(); |
|
| 217 |
+ void clear(); |
|
| 240 | 218 |
|
| 241 | 219 |
/// Changes a setting controlling the processing system behaviour. See the |
| 242 | 220 |
/// 'SETTING_...' defines for available setting ID's. |
| ... | ... |
@@ -246,15 +224,8 @@ public: |
| 246 | 224 |
int32_t value ///< New setting value. |
| 247 | 225 |
); |
| 248 | 226 |
|
| 249 |
- /// Reads a setting controlling the processing system behaviour. See the |
|
| 250 |
- /// 'SETTING_...' defines for available setting ID's. |
|
| 251 |
- /// |
|
| 252 |
- /// \return the setting value. |
|
| 253 |
- int32_t getSetting(int32_t settingId ///< Setting ID number, see SETTING_... defines. |
|
| 254 |
- ) const; |
|
| 255 |
- |
|
| 256 | 227 |
/// Returns number of samples currently unprocessed. |
| 257 |
- virtual uint32_t numUnprocessedSamples() const; |
|
| 228 |
+ uint32_t numUnprocessedSamples() const; |
|
| 258 | 229 |
|
| 259 | 230 |
/// Other handy functions that are implemented in the ancestor classes (see |
| 260 | 231 |
/// classes 'FIFOProcessor' and 'FIFOSamplePipe') |
| ... | ... |
@@ -41,10 +41,10 @@ |
| 41 | 41 |
/// |
| 42 | 42 |
//////////////////////////////////////////////////////////////////////////////// |
| 43 | 43 |
// |
| 44 |
-// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 45 |
-// File revision : $Revision: 1.14 $ |
|
| 44 |
+// Last changed : $Date: 2012-12-28 17:32:59 -0200 (sex, 28 dez 2012) $ |
|
| 45 |
+// File revision : $Revision: 4 $ |
|
| 46 | 46 |
// |
| 47 |
-// $Id: SoundTouch.h,v 1.14 2006/02/05 16:44:06 Olli Exp $ |
|
| 47 |
+// $Id: SoundTouch.h 163 2012-12-28 19:32:59Z oparviai $ |
|
| 48 | 48 |
// |
| 49 | 49 |
//////////////////////////////////////////////////////////////////////////////// |
| 50 | 50 |
// |
| ... | ... |
@@ -72,57 +72,83 @@ |
| 72 | 72 |
#ifndef SoundTouch_H |
| 73 | 73 |
#define SoundTouch_H |
| 74 | 74 |
|
| 75 |
+#include <memory> |
|
| 75 | 76 |
#include "FIFOSamplePipe.h" |
| 76 |
-#include "STTypes.h" |
|
| 77 | 77 |
|
| 78 | 78 |
namespace soundtouch |
| 79 | 79 |
{
|
| 80 | 80 |
|
| 81 | 81 |
/// Soundtouch library version string |
| 82 |
-static const char *const SOUNDTOUCH_VERSION = "1.3.1"; |
|
| 82 |
+const char *const SOUNDTOUCH_VERSION = "1.7.1"; |
|
| 83 | 83 |
|
| 84 | 84 |
/// SoundTouch library version id |
| 85 |
-static const uint32_t SOUNDTOUCH_VERSION_ID = 010301; |
|
| 85 |
+const uint32_t SOUNDTOUCH_VERSION_ID = 010701; |
|
| 86 | 86 |
|
| 87 |
-// |
|
| 88 | 87 |
// Available setting IDs for the 'setSetting' & 'get_setting' functions: |
| 89 | 88 |
|
| 90 | 89 |
/// Enable/disable anti-alias filter in pitch transposer (0 = disable) |
| 91 |
-static const uint32_t SETTING_USE_AA_FILTER = 0; |
|
| 90 |
+const int32_t SETTING_USE_AA_FILTER = 0; |
|
| 92 | 91 |
|
| 93 | 92 |
/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32) |
| 94 |
-static const uint32_t SETTING_AA_FILTER_LENGTH = 1; |
|
| 93 |
+const int32_t SETTING_AA_FILTER_LENGTH = 1; |
|
| 95 | 94 |
|
| 96 | 95 |
/// Enable/disable quick seeking algorithm in tempo changer routine |
| 97 | 96 |
/// (enabling quick seeking lowers CPU utilization but causes a minor sound |
| 98 | 97 |
/// quality compromising) |
| 99 |
-static const uint32_t SETTING_USE_QUICKSEEK = 2; |
|
| 98 |
+const int32_t SETTING_USE_QUICKSEEK = 2; |
|
| 100 | 99 |
|
| 101 | 100 |
/// Time-stretch algorithm single processing sequence length in milliseconds. This determines |
| 102 | 101 |
/// to how long sequences the original sound is chopped in the time-stretch algorithm. |
| 103 | 102 |
/// See "STTypes.h" or README for more information. |
| 104 |
-static const uint32_t SETTING_SEQUENCE_MS = 3; |
|
| 103 |
+const int32_t SETTING_SEQUENCE_MS = 3; |
|
| 105 | 104 |
|
| 106 | 105 |
/// Time-stretch algorithm seeking window length in milliseconds for algorithm that finds the |
| 107 | 106 |
/// best possible overlapping location. This determines from how wide window the algorithm |
| 108 | 107 |
/// may look for an optimal joining location when mixing the sound sequences back together. |
| 109 | 108 |
/// See "STTypes.h" or README for more information. |
| 110 |
-static const uint32_t SETTING_SEEKWINDOW_MS = 4; |
|
| 109 |
+const int32_t SETTING_SEEKWINDOW_MS = 4; |
|
| 111 | 110 |
|
| 112 | 111 |
/// Time-stretch algorithm overlap length in milliseconds. When the chopped sound sequences |
| 113 | 112 |
/// are mixed back together, to form a continuous sound stream, this parameter defines over |
| 114 | 113 |
/// how long period the two consecutive sequences are let to overlap each other. |
| 115 | 114 |
/// See "STTypes.h" or README for more information. |
| 116 |
-static const uint32_t SETTING_OVERLAP_MS = 5; |
|
| 115 |
+const int32_t SETTING_OVERLAP_MS = 5; |
|
| 116 |
+ |
|
| 117 |
+/// Call "getSetting" with this ID to query nominal average processing sequence |
|
| 118 |
+/// size in samples. This value tells approcimate value how many input samples |
|
| 119 |
+/// SoundTouch needs to gather before it does DSP processing run for the sample batch. |
|
| 120 |
+/// |
|
| 121 |
+/// Notices: |
|
| 122 |
+/// - This is read-only parameter, i.e. setSetting ignores this parameter |
|
| 123 |
+/// - Returned value is approximate average value, exact processing batch |
|
| 124 |
+/// size may wary from time to time |
|
| 125 |
+/// - This parameter value is not constant but may change depending on |
|
| 126 |
+/// tempo/pitch/rate/samplerate settings. |
|
| 127 |
+const int32_t SETTING_NOMINAL_INPUT_SEQUENCE = 6; |
|
| 128 |
+ |
|
| 129 |
+/// Call "getSetting" with this ID to query nominal average processing output |
|
| 130 |
+/// size in samples. This value tells approcimate value how many output samples |
|
| 131 |
+/// SoundTouch outputs once it does DSP processing run for a batch of input samples. |
|
| 132 |
+/// |
|
| 133 |
+/// Notices: |
|
| 134 |
+/// - This is read-only parameter, i.e. setSetting ignores this parameter |
|
| 135 |
+/// - Returned value is approximate average value, exact processing batch |
|
| 136 |
+/// size may wary from time to time |
|
| 137 |
+/// - This parameter value is not constant but may change depending on |
|
| 138 |
+/// tempo/pitch/rate/samplerate settings. |
|
| 139 |
+const int32_t SETTING_NOMINAL_OUTPUT_SEQUENCE = 7; |
|
| 140 |
+ |
|
| 141 |
+class RateTransposer; |
|
| 142 |
+class TDStretch; |
|
| 117 | 143 |
|
| 118 | 144 |
class SoundTouch : public FIFOProcessor |
| 119 | 145 |
{
|
| 120 | 146 |
private: |
| 121 | 147 |
/// Rate transposer class instance |
| 122 |
- class RateTransposer *pRateTransposer; |
|
| 148 |
+ std::unique_ptr<RateTransposer> pRateTransposer; |
|
| 123 | 149 |
|
| 124 | 150 |
/// Time-stretch class instance |
| 125 |
- class TDStretch *pTDStretch; |
|
| 151 |
+ std::unique_ptr<TDStretch> pTDStretch; |
|
| 126 | 152 |
|
| 127 | 153 |
/// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
| 128 | 154 |
float virtualRate; |
| ... | ... |
@@ -134,15 +160,15 @@ private: |
| 134 | 160 |
float virtualPitch; |
| 135 | 161 |
|
| 136 | 162 |
/// Flag: Has sample rate been set? |
| 137 |
- bool bSrateSet; |
|
| 163 |
+ bool bSrateSet; |
|
| 138 | 164 |
|
| 139 | 165 |
/// Calculates effective rate & tempo valuescfrom 'virtualRate', 'virtualTempo' and |
| 140 | 166 |
/// 'virtualPitch' parameters. |
| 141 | 167 |
void calcEffectiveRateAndTempo(); |
| 142 | 168 |
|
| 143 |
-protected : |
|
| 169 |
+protected: |
|
| 144 | 170 |
/// Number of channels |
| 145 |
- uint32_t channels; |
|
| 171 |
+ uint32_t channels; |
|
| 146 | 172 |
|
| 147 | 173 |
/// Effective 'rate' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch' |
| 148 | 174 |
float rate; |
| ... | ... |
@@ -154,12 +180,6 @@ public: |
| 154 | 180 |
SoundTouch(); |
| 155 | 181 |
virtual ~SoundTouch(); |
| 156 | 182 |
|
| 157 |
- /// Get SoundTouch library version string |
|
| 158 |
- static const char *getVersionString(); |
|
| 159 |
- |
|
| 160 |
- /// Get SoundTouch library version Id |
|
| 161 |
- static uint32_t getVersionId(); |
|
| 162 |
- |
|
| 163 | 183 |
/// Sets new rate control value. Normal rate = 1.0, smaller values |
| 164 | 184 |
/// represent slower rate, larger faster rates. |
| 165 | 185 |
void setRate(float newRate); |
| ... | ... |
@@ -222,15 +242,15 @@ public: |
| 222 | 242 |
/// 'SETTING_...' defines for available setting ID's. |
| 223 | 243 |
/// |
| 224 | 244 |
/// \return 'true' if the setting was succesfully changed |
| 225 |
- bool setSetting(uint32_t settingId, ///< Setting ID number. see SETTING_... defines. |
|
| 226 |
- uint32_t value ///< New setting value. |
|
| 245 |
+ bool setSetting(int32_t settingId, ///< Setting ID number. see SETTING_... defines. |
|
| 246 |
+ int32_t value ///< New setting value. |
|
| 227 | 247 |
); |
| 228 | 248 |
|
| 229 | 249 |
/// Reads a setting controlling the processing system behaviour. See the |
| 230 | 250 |
/// 'SETTING_...' defines for available setting ID's. |
| 231 | 251 |
/// |
| 232 | 252 |
/// \return the setting value. |
| 233 |
- uint32_t getSetting(uint32_t settingId ///< Setting ID number, see SETTING_... defines. |
|
| 253 |
+ int32_t getSetting(int32_t settingId ///< Setting ID number, see SETTING_... defines. |
|
| 234 | 254 |
) const; |
| 235 | 255 |
|
| 236 | 256 |
/// Returns number of samples currently unprocessed. |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,251 @@ |
| 1 |
+////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
+/// |
|
| 3 |
+/// SoundTouch - main class for tempo/pitch/rate adjusting routines. |
|
| 4 |
+/// |
|
| 5 |
+/// Notes: |
|
| 6 |
+/// - Initialize the SoundTouch object instance by setting up the sound stream |
|
| 7 |
+/// parameters with functions 'setSampleRate' and 'setChannels', then set |
|
| 8 |
+/// desired tempo/pitch/rate settings with the corresponding functions. |
|
| 9 |
+/// |
|
| 10 |
+/// - The SoundTouch class behaves like a first-in-first-out pipeline: The |
|
| 11 |
+/// samples that are to be processed are fed into one of the pipe by calling |
|
| 12 |
+/// function 'putSamples', while the ready processed samples can be read |
|
| 13 |
+/// from the other end of the pipeline with function 'receiveSamples'. |
|
| 14 |
+/// |
|
| 15 |
+/// - The SoundTouch processing classes require certain sized 'batches' of |
|
| 16 |
+/// samples in order to process the sound. For this reason the classes buffer |
|
| 17 |
+/// incoming samples until there are enough of samples available for |
|
| 18 |
+/// processing, then they carry out the processing step and consequently |
|
| 19 |
+/// make the processed samples available for outputting. |
|
| 20 |
+/// |
|
| 21 |
+/// - For the above reason, the processing routines introduce a certain |
|
| 22 |
+/// 'latency' between the input and output, so that the samples input to |
|
| 23 |
+/// SoundTouch may not be immediately available in the output, and neither |
|
| 24 |
+/// the amount of outputtable samples may not immediately be in direct |
|
| 25 |
+/// relationship with the amount of previously input samples. |
|
| 26 |
+/// |
|
| 27 |
+/// - The tempo/pitch/rate control parameters can be altered during processing. |
|
| 28 |
+/// Please notice though that they aren't currently protected by semaphores, |
|
| 29 |
+/// so in multi-thread application external semaphore protection may be |
|
| 30 |
+/// required. |
|
| 31 |
+/// |
|
| 32 |
+/// - This class utilizes classes 'TDStretch' for tempo change (without modifying |
|
| 33 |
+/// pitch) and 'RateTransposer' for changing the playback rate (that is, both |
|
| 34 |
+/// tempo and pitch in the same ratio) of the sound. The third available control |
|
| 35 |
+/// 'pitch' (change pitch but maintain tempo) is produced by a combination of |
|
| 36 |
+/// combining the two other controls. |
|
| 37 |
+/// |
|
| 38 |
+/// Author : Copyright (c) Olli Parviainen |
|
| 39 |
+/// Author e-mail : oparviai 'at' iki.fi |
|
| 40 |
+/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 41 |
+/// |
|
| 42 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
+// |
|
| 44 |
+// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 45 |
+// File revision : $Revision: 1.14 $ |
|
| 46 |
+// |
|
| 47 |
+// $Id: SoundTouch.h,v 1.14 2006/02/05 16:44:06 Olli Exp $ |
|
| 48 |
+// |
|
| 49 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
+// |
|
| 51 |
+// License : |
|
| 52 |
+// |
|
| 53 |
+// SoundTouch audio processing library |
|
| 54 |
+// Copyright (c) Olli Parviainen |
|
| 55 |
+// |
|
| 56 |
+// This library is free software; you can redistribute it and/or |
|
| 57 |
+// modify it under the terms of the GNU Lesser General Public |
|
| 58 |
+// License as published by the Free Software Foundation; either |
|
| 59 |
+// version 2.1 of the License, or (at your option) any later version. |
|
| 60 |
+// |
|
| 61 |
+// This library is distributed in the hope that it will be useful, |
|
| 62 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 63 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 64 |
+// Lesser General Public License for more details. |
|
| 65 |
+// |
|
| 66 |
+// You should have received a copy of the GNU Lesser General Public |
|
| 67 |
+// License along with this library; if not, write to the Free Software |
|
| 68 |
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 69 |
+// |
|
| 70 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 71 |
+ |
|
| 72 |
+#ifndef SoundTouch_H |
|
| 73 |
+#define SoundTouch_H |
|
| 74 |
+ |
|
| 75 |
+#include "FIFOSamplePipe.h" |
|
| 76 |
+#include "STTypes.h" |
|
| 77 |
+ |
|
| 78 |
+namespace soundtouch |
|
| 79 |
+{
|
|
| 80 |
+ |
|
| 81 |
+/// Soundtouch library version string |
|
| 82 |
+static const char *const SOUNDTOUCH_VERSION = "1.3.1"; |
|
| 83 |
+ |
|
| 84 |
+/// SoundTouch library version id |
|
| 85 |
+static const uint32_t SOUNDTOUCH_VERSION_ID = 010301; |
|
| 86 |
+ |
|
| 87 |
+// |
|
| 88 |
+// Available setting IDs for the 'setSetting' & 'get_setting' functions: |
|
| 89 |
+ |
|
| 90 |
+/// Enable/disable anti-alias filter in pitch transposer (0 = disable) |
|
| 91 |
+static const uint32_t SETTING_USE_AA_FILTER = 0; |
|
| 92 |
+ |
|
| 93 |
+/// Pitch transposer anti-alias filter length (8 .. 128 taps, default = 32) |
|
| 94 |
+static const uint32_t SETTING_AA_FILTER_LENGTH = 1; |
|
| 95 |
+ |
|
| 96 |
+/// Enable/disable quick seeking algorithm in tempo changer routine |
|
| 97 |
+/// (enabling quick seeking lowers CPU utilization but causes a minor sound |
|
| 98 |
+/// quality compromising) |
|
| 99 |
+static const uint32_t SETTING_USE_QUICKSEEK = 2; |
|
| 100 |
+ |
|
| 101 |
+/// Time-stretch algorithm single processing sequence length in milliseconds. This determines |
|
| 102 |
+/// to how long sequences the original sound is chopped in the time-stretch algorithm. |
|
| 103 |
+/// See "STTypes.h" or README for more information. |
|
| 104 |
+static const uint32_t SETTING_SEQUENCE_MS = 3; |
|
| 105 |
+ |
|
| 106 |
+/// Time-stretch algorithm seeking window length in milliseconds for algorithm that finds the |
|
| 107 |
+/// best possible overlapping location. This determines from how wide window the algorithm |
|
| 108 |
+/// may look for an optimal joining location when mixing the sound sequences back together. |
|
| 109 |
+/// See "STTypes.h" or README for more information. |
|
| 110 |
+static const uint32_t SETTING_SEEKWINDOW_MS = 4; |
|
| 111 |
+ |
|
| 112 |
+/// Time-stretch algorithm overlap length in milliseconds. When the chopped sound sequences |
|
| 113 |
+/// are mixed back together, to form a continuous sound stream, this parameter defines over |
|
| 114 |
+/// how long period the two consecutive sequences are let to overlap each other. |
|
| 115 |
+/// See "STTypes.h" or README for more information. |
|
| 116 |
+static const uint32_t SETTING_OVERLAP_MS = 5; |
|
| 117 |
+ |
|
| 118 |
+class SoundTouch : public FIFOProcessor |
|
| 119 |
+{
|
|
| 120 |
+private: |
|
| 121 |
+ /// Rate transposer class instance |
|
| 122 |
+ class RateTransposer *pRateTransposer; |
|
| 123 |
+ |
|
| 124 |
+ /// Time-stretch class instance |
|
| 125 |
+ class TDStretch *pTDStretch; |
|
| 126 |
+ |
|
| 127 |
+ /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 128 |
+ float virtualRate; |
|
| 129 |
+ |
|
| 130 |
+ /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 131 |
+ float virtualTempo; |
|
| 132 |
+ |
|
| 133 |
+ /// Virtual pitch parameter. Effective rate & tempo are calculated from these parameters. |
|
| 134 |
+ float virtualPitch; |
|
| 135 |
+ |
|
| 136 |
+ /// Flag: Has sample rate been set? |
|
| 137 |
+ bool bSrateSet; |
|
| 138 |
+ |
|
| 139 |
+ /// Calculates effective rate & tempo valuescfrom 'virtualRate', 'virtualTempo' and |
|
| 140 |
+ /// 'virtualPitch' parameters. |
|
| 141 |
+ void calcEffectiveRateAndTempo(); |
|
| 142 |
+ |
|
| 143 |
+protected : |
|
| 144 |
+ /// Number of channels |
|
| 145 |
+ uint32_t channels; |
|
| 146 |
+ |
|
| 147 |
+ /// Effective 'rate' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch' |
|
| 148 |
+ float rate; |
|
| 149 |
+ |
|
| 150 |
+ /// Effective 'tempo' value calculated from 'virtualRate', 'virtualTempo' and 'virtualPitch' |
|
| 151 |
+ float tempo; |
|
| 152 |
+ |
|
| 153 |
+public: |
|
| 154 |
+ SoundTouch(); |
|
| 155 |
+ virtual ~SoundTouch(); |
|
| 156 |
+ |
|
| 157 |
+ /// Get SoundTouch library version string |
|
| 158 |
+ static const char *getVersionString(); |
|
| 159 |
+ |
|
| 160 |
+ /// Get SoundTouch library version Id |
|
| 161 |
+ static uint32_t getVersionId(); |
|
| 162 |
+ |
|
| 163 |
+ /// Sets new rate control value. Normal rate = 1.0, smaller values |
|
| 164 |
+ /// represent slower rate, larger faster rates. |
|
| 165 |
+ void setRate(float newRate); |
|
| 166 |
+ |
|
| 167 |
+ /// Sets new tempo control value. Normal tempo = 1.0, smaller values |
|
| 168 |
+ /// represent slower tempo, larger faster tempo. |
|
| 169 |
+ void setTempo(float newTempo); |
|
| 170 |
+ |
|
| 171 |
+ /// Sets new rate control value as a difference in percents compared |
|
| 172 |
+ /// to the original rate (-50 .. +100 %) |
|
| 173 |
+ void setRateChange(float newRate); |
|
| 174 |
+ |
|
| 175 |
+ /// Sets new tempo control value as a difference in percents compared |
|
| 176 |
+ /// to the original tempo (-50 .. +100 %) |
|
| 177 |
+ void setTempoChange(float newTempo); |
|
| 178 |
+ |
|
| 179 |
+ /// Sets new pitch control value. Original pitch = 1.0, smaller values |
|
| 180 |
+ /// represent lower pitches, larger values higher pitch. |
|
| 181 |
+ void setPitch(float newPitch); |
|
| 182 |
+ |
|
| 183 |
+ /// Sets pitch change in octaves compared to the original pitch |
|
| 184 |
+ /// (-1.00 .. +1.00) |
|
| 185 |
+ void setPitchOctaves(float newPitch); |
|
| 186 |
+ |
|
| 187 |
+ /// Sets pitch change in semi-tones compared to the original pitch |
|
| 188 |
+ /// (-12 .. +12) |
|
| 189 |
+ void setPitchSemiTones(int newPitch); |
|
| 190 |
+ void setPitchSemiTones(float newPitch); |
|
| 191 |
+ |
|
| 192 |
+ /// Sets the number of channels, 1 = mono, 2 = stereo |
|
| 193 |
+ void setChannels(uint32_t numChannels); |
|
| 194 |
+ |
|
| 195 |
+ /// Sets sample rate. |
|
| 196 |
+ void setSampleRate(uint32_t srate); |
|
| 197 |
+ |
|
| 198 |
+ /// Flushes the last samples from the processing pipeline to the output. |
|
| 199 |
+ /// Clears also the internal processing buffers. |
|
| 200 |
+ // |
|
| 201 |
+ /// Note: This function is meant for extracting the last samples of a sound |
|
| 202 |
+ /// stream. This function may introduce additional blank samples in the end |
|
| 203 |
+ /// of the sound stream, and thus it's not recommended to call this function |
|
| 204 |
+ /// in the middle of a sound stream. |
|
| 205 |
+ void flush(); |
|
| 206 |
+ |
|
| 207 |
+ /// Adds 'numSamples' pcs of samples from the 'samples' memory position into |
|
| 208 |
+ /// the input of the object. Notice that sample rate _has_to_ be set before |
|
| 209 |
+ /// calling this function, otherwise throws a runtime_error exception. |
|
| 210 |
+ virtual void putSamples( |
|
| 211 |
+ const SAMPLETYPE *samples, ///< Pointer to sample buffer. |
|
| 212 |
+ uint32_t numSamples ///< Number of samples in buffer. Notice |
|
| 213 |
+ ///< that in case of stereo-sound a single sample |
|
| 214 |
+ ///< contains data for both channels. |
|
| 215 |
+ ); |
|
| 216 |
+ |
|
| 217 |
+ /// Clears all the samples in the object's output and internal processing |
|
| 218 |
+ /// buffers. |
|
| 219 |
+ virtual void clear(); |
|
| 220 |
+ |
|
| 221 |
+ /// Changes a setting controlling the processing system behaviour. See the |
|
| 222 |
+ /// 'SETTING_...' defines for available setting ID's. |
|
| 223 |
+ /// |
|
| 224 |
+ /// \return 'true' if the setting was succesfully changed |
|
| 225 |
+ bool setSetting(uint32_t settingId, ///< Setting ID number. see SETTING_... defines. |
|
| 226 |
+ uint32_t value ///< New setting value. |
|
| 227 |
+ ); |
|
| 228 |
+ |
|
| 229 |
+ /// Reads a setting controlling the processing system behaviour. See the |
|
| 230 |
+ /// 'SETTING_...' defines for available setting ID's. |
|
| 231 |
+ /// |
|
| 232 |
+ /// \return the setting value. |
|
| 233 |
+ uint32_t getSetting(uint32_t settingId ///< Setting ID number, see SETTING_... defines. |
|
| 234 |
+ ) const; |
|
| 235 |
+ |
|
| 236 |
+ /// Returns number of samples currently unprocessed. |
|
| 237 |
+ virtual uint32_t numUnprocessedSamples() const; |
|
| 238 |
+ |
|
| 239 |
+ /// Other handy functions that are implemented in the ancestor classes (see |
|
| 240 |
+ /// classes 'FIFOProcessor' and 'FIFOSamplePipe') |
|
| 241 |
+ /// |
|
| 242 |
+ /// - receiveSamples() : Use this function to receive 'ready' processed samples from SoundTouch. |
|
| 243 |
+ /// - numSamples() : Get number of 'ready' samples that can be received with |
|
| 244 |
+ /// function 'receiveSamples()' |
|
| 245 |
+ /// - isEmpty() : Returns nonzero if there aren't any 'ready' samples. |
|
| 246 |
+ /// - clear() : Clears all samples from ready/processing buffers. |
|
| 247 |
+}; |
|
| 248 |
+ |
|
| 249 |
+} |
|
| 250 |
+ |
|
| 251 |
+#endif |