Browse code

update for C++17 compliance, update to latest 2sf, add WINE cross-compile makefiles

Adam Higerd authored on 2021/02/11 15:36:17
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,244 +0,0 @@
1
-////////////////////////////////////////////////////////////////////////////////
2
-///
3
-/// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo
4
-/// while maintaining the original pitch by using a time domain WSOLA-like method
5
-/// with several performance-increasing tweaks.
6
-///
7
-/// Note : MMX/SSE optimized functions reside in separate, platform-specific files
8
-/// 'mmx_optimized.cpp' and 'sse_optimized.cpp'
9
-///
10
-/// Author        : Copyright (c) Olli Parviainen
11
-/// Author e-mail : oparviai 'at' iki.fi
12
-/// SoundTouch WWW: http://www.surina.net/soundtouch
13
-///
14
-////////////////////////////////////////////////////////////////////////////////
15
-//
16
-// Last changed  : $Date: 2012-04-01 16:49:30 -0300 (dom, 01 abr 2012) $
17
-// File revision : $Revision: 4 $
18
-//
19
-// $Id: TDStretch.h 137 2012-04-01 19:49:30Z oparviai $
20
-//
21
-////////////////////////////////////////////////////////////////////////////////
22
-//
23
-// License :
24
-//
25
-//  SoundTouch audio processing library
26
-//  Copyright (c) Olli Parviainen
27
-//
28
-//  This library is free software; you can redistribute it and/or
29
-//  modify it under the terms of the GNU Lesser General Public
30
-//  License as published by the Free Software Foundation; either
31
-//  version 2.1 of the License, or (at your option) any later version.
32
-//
33
-//  This library is distributed in the hope that it will be useful,
34
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
35
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36
-//  Lesser General Public License for more details.
37
-//
38
-//  You should have received a copy of the GNU Lesser General Public
39
-//  License along with this library; if not, write to the Free Software
40
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
41
-//
42
-////////////////////////////////////////////////////////////////////////////////
43
-
44
-#pragma once
45
-
46
-#include <memory>
47
-#include "FIFOSampleBuffer.h"
48
-
49
-namespace soundtouch
50
-{
51
-
52
-/// Default values for sound processing parameters:
53
-/// Notice that the default parameters are tuned for contemporary popular music
54
-/// processing. For speech processing applications these parameters suit better:
55
-///     #define DEFAULT_SEQUENCE_MS     40
56
-///     #define DEFAULT_SEEKWINDOW_MS   15
57
-///     #define DEFAULT_OVERLAP_MS      8
58
-///
59
-
60
-/// Giving this value for the sequence length sets automatic parameter value
61
-/// according to tempo setting (recommended)
62
-const int32_t USE_AUTO_SEQUENCE_LEN = 0;
63
-
64
-/// Default length of a single processing sequence, in milliseconds. This determines to how
65
-/// long sequences the original sound is chopped in the time-stretch algorithm.
66
-///
67
-/// The larger this value is, the lesser sequences are used in processing. In principle
68
-/// a bigger value sounds better when slowing down tempo, but worse when increasing tempo
69
-/// and vice versa.
70
-///
71
-/// Increasing this value reduces computational burden & vice versa.
72
-//#define DEFAULT_SEQUENCE_MS 40
73
-const int32_t DEFAULT_SEQUENCE_MS = USE_AUTO_SEQUENCE_LEN;
74
-
75
-/// Giving this value for the seek window length sets automatic parameter value
76
-/// according to tempo setting (recommended)
77
-const int32_t USE_AUTO_SEEKWINDOW_LEN = 0;
78
-
79
-/// Seeking window default length in milliseconds for algorithm that finds the best possible
80
-/// overlapping location. This determines from how wide window the algorithm may look for an
81
-/// optimal joining location when mixing the sound sequences back together.
82
-///
83
-/// The bigger this window setting is, the higher the possibility to find a better mixing
84
-/// position will become, but at the same time large values may cause a "drifting" artifact
85
-/// because consequent sequences will be taken at more uneven intervals.
86
-///
87
-/// If there's a disturbing artifact that sounds as if a constant frequency was drifting
88
-/// around, try reducing this setting.
89
-///
90
-/// Increasing this value increases computational burden & vice versa.
91
-//#define DEFAULT_SEEKWINDOW_MS       15
92
-const int32_t DEFAULT_SEEKWINDOW_MS = USE_AUTO_SEEKWINDOW_LEN;
93
-
94
-/// Overlap length in milliseconds. When the chopped sound sequences are mixed back together,
95
-/// to form a continuous sound stream, this parameter defines over how long period the two
96
-/// consecutive sequences are let to overlap each other.
97
-///
98
-/// This shouldn't be that critical parameter. If you reduce the DEFAULT_SEQUENCE_MS setting
99
-/// by a large amount, you might wish to try a smaller value on this.
100
-///
101
-/// Increasing this value increases computational burden & vice versa.
102
-const int32_t DEFAULT_OVERLAP_MS = 8;
103
-
104
-/// Class that does the time-stretch (tempo change) effect for the processed
105
-/// sound.
106
-class TDStretch : public FIFOProcessor
107
-{
108
-protected:
109
-	int32_t channels;
110
-	int32_t sampleReq;
111
-	float tempo;
112
-
113
-	SAMPLETYPE *pMidBuffer;
114
-	std::unique_ptr<SAMPLETYPE[]> pMidBufferUnaligned;
115
-	int32_t overlapLength;
116
-	int32_t seekLength;
117
-	int32_t seekWindowLength;
118
-	int32_t overlapDividerBits;
119
-	int32_t slopingDivider;
120
-	float nominalSkip;
121
-	float skipFract;
122
-	FIFOSampleBuffer outputBuffer;
123
-	FIFOSampleBuffer inputBuffer;
124
-	bool bQuickSeek;
125
-
126
-	int32_t sampleRate;
127
-	int32_t sequenceMs;
128
-	int32_t seekWindowMs;
129
-	int32_t overlapMs;
130
-	bool bAutoSeqSetting;
131
-	bool bAutoSeekSetting;
132
-
133
-	void acceptNewOverlapLength(int32_t newOverlapLength);
134
-
135
-	virtual void clearCrossCorrState();
136
-	void calculateOverlapLength(int32_t overlapMs);
137
-
138
-	virtual double calcCrossCorr(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
139
-
140
-	virtual int seekBestOverlapPositionFull(const SAMPLETYPE *refPos);
141
-	virtual int seekBestOverlapPositionQuick(const SAMPLETYPE *refPos);
142
-	int32_t seekBestOverlapPosition(const SAMPLETYPE *refPos);
143
-
144
-	virtual void overlapStereo(SAMPLETYPE *output, const SAMPLETYPE *input) const;
145
-	virtual void overlapMono(SAMPLETYPE *output, const SAMPLETYPE *input) const;
146
-
147
-	void clearMidBuffer();
148
-	void overlap(SAMPLETYPE *output, const SAMPLETYPE *input, uint32_t ovlPos) const;
149
-
150
-	void calcSeqParameters();
151
-
152
-	/// Changes the tempo of the given sound samples.
153
-	/// Returns amount of samples returned in the "output" buffer.
154
-	/// The maximum amount of samples that can be returned at a time is set by
155
-	/// the 'set_returnBuffer_size' function.
156
-	void processSamples();
157
-
158
-public:
159
-	TDStretch();
160
-	virtual ~TDStretch();
161
-
162
-	/// Operator 'new' is overloaded so that it automatically creates a suitable instance
163
-	/// depending on if we've a MMX/SSE/etc-capable CPU available or not.
164
-	static void *operator new(size_t s);
165
-
166
-	/// Use this function instead of "new" operator to create a new instance of this class.
167
-	/// This function automatically chooses a correct feature set depending on if the CPU
168
-	/// supports MMX/SSE/etc extensions.
169
-	static TDStretch *newInstance();
170
-
171
-	/// Returns the output buffer object
172
-	FIFOSamplePipe *getOutput() { return &this->outputBuffer; }
173
-
174
-	/// Returns the input buffer object
175
-	FIFOSamplePipe *getInput() { return &this->inputBuffer; }
176
-
177
-	/// Sets new target tempo. Normal tempo = 'SCALE', smaller values represent slower
178
-	/// tempo, larger faster tempo.
179
-	void setTempo(float newTempo);
180
-
181
-	/// Returns nonzero if there aren't any samples available for outputting.
182
-	virtual void clear();
183
-
184
-	/// Clears the input buffer
185
-	void clearInput();
186
-
187
-	/// Sets the number of channels, 1 = mono, 2 = stereo
188
-	void setChannels(int32_t numChannels);
189
-
190
-	/// Enables/disables the quick position seeking algorithm. Zero to disable,
191
-	/// nonzero to enable
192
-	void enableQuickSeek(bool enable);
193
-
194
-	/// Sets routine control parameters. These control are certain time constants
195
-	/// defining how the sound is stretched to the desired duration.
196
-	//
197
-	/// 'sampleRate' = sample rate of the sound
198
-	/// 'sequenceMS' = one processing sequence length in milliseconds
199
-	/// 'seekwindowMS' = seeking window length for scanning the best overlapping
200
-	///      position
201
-	/// 'overlapMS' = overlapping length
202
-	void setParameters(int32_t sampleRate,          ///< Samplerate of sound being processed (Hz)
203
-                       int32_t sequenceMS = -1,     ///< Single processing sequence length (ms)
204
-                       int32_t seekwindowMS = -1,   ///< Offset seeking window length (ms)
205
-                       int32_t overlapMS = -1       ///< Sequence overlapping length (ms)
206
-                       );
207
-
208
-	/// Get routine control parameters, see setParameters() function.
209
-	/// Any of the parameters to this function can be NULL, in such case corresponding parameter
210
-	/// value isn't returned.
211
-	void getParameters(int32_t *pSampleRate, int32_t *pSequenceMs, int32_t *pSeekWindowMs, int32_t *pOverlapMs);
212
-
213
-	/// Adds 'numsamples' pcs of samples from the 'samples' memory position into
214
-	/// the input of the object.
215
-	virtual void putSamples(
216
-            const SAMPLETYPE *samples,  ///< Input sample data
217
-            uint32_t numSamples                         ///< Number of samples in 'samples' so that one sample
218
-                                                       ///< contains both channels if stereo
219
-            );
220
-};
221
-
222
-// Implementation-specific class declarations:
223
-
224
-#ifdef SOUNDTOUCH_ALLOW_MMX
225
-/// Class that implements MMX optimized routines for 16bit integer samples type.
226
-class TDStretchMMX : public TDStretch
227
-{
228
-protected:
229
-	double calcCrossCorr(const short *mixingPos, const short *compare) const;
230
-	virtual void overlapStereo(short *output, const short *input) const;
231
-	virtual void clearCrossCorrState();
232
-};
233
-#endif /// SOUNDTOUCH_ALLOW_MMX
234
-
235
-#ifdef SOUNDTOUCH_ALLOW_SSE
236
-/// Class that implements SSE optimized routines for floating point samples type.
237
-class TDStretchSSE : public TDStretch
238
-{
239
-protected:
240
-	double calcCrossCorr(const float *mixingPos, const float *compare) const;
241
-};
242
-#endif ///  SOUNDTOUCH_ALLOW_SSE
243
-
244
-}
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -4,7 +4,7 @@
4 4
 /// while maintaining the original pitch by using a time domain WSOLA-like method
5 5
 /// with several performance-increasing tweaks.
6 6
 ///
7
-/// Note : MMX/SSE optimized functions reside in separate, platform-specific files 
7
+/// Note : MMX/SSE optimized functions reside in separate, platform-specific files
8 8
 /// 'mmx_optimized.cpp' and 'sse_optimized.cpp'
9 9
 ///
10 10
 /// Author        : Copyright (c) Olli Parviainen
... ...
@@ -44,13 +44,13 @@
44 44
 #pragma once
45 45
 
46 46
 #include <memory>
47
-#include "RateTransposer.h"
47
+#include "FIFOSampleBuffer.h"
48 48
 
49 49
 namespace soundtouch
50 50
 {
51 51
 
52 52
 /// Default values for sound processing parameters:
53
-/// Notice that the default parameters are tuned for contemporary popular music 
53
+/// Notice that the default parameters are tuned for contemporary popular music
54 54
 /// processing. For speech processing applications these parameters suit better:
55 55
 ///     #define DEFAULT_SEQUENCE_MS     40
56 56
 ///     #define DEFAULT_SEEKWINDOW_MS   15
... ...
@@ -76,26 +76,26 @@ const int32_t DEFAULT_SEQUENCE_MS = USE_AUTO_SEQUENCE_LEN;
76 76
 /// according to tempo setting (recommended)
77 77
 const int32_t USE_AUTO_SEEKWINDOW_LEN = 0;
78 78
 
79
-/// Seeking window default length in milliseconds for algorithm that finds the best possible 
80
-/// overlapping location. This determines from how wide window the algorithm may look for an 
81
-/// optimal joining location when mixing the sound sequences back together. 
79
+/// Seeking window default length in milliseconds for algorithm that finds the best possible
80
+/// overlapping location. This determines from how wide window the algorithm may look for an
81
+/// optimal joining location when mixing the sound sequences back together.
82 82
 ///
83 83
 /// The bigger this window setting is, the higher the possibility to find a better mixing
84 84
 /// position will become, but at the same time large values may cause a "drifting" artifact
85 85
 /// because consequent sequences will be taken at more uneven intervals.
86 86
 ///
87
-/// If there's a disturbing artifact that sounds as if a constant frequency was drifting 
87
+/// If there's a disturbing artifact that sounds as if a constant frequency was drifting
88 88
 /// around, try reducing this setting.
89 89
 ///
90 90
 /// Increasing this value increases computational burden & vice versa.
91 91
 //#define DEFAULT_SEEKWINDOW_MS       15
92 92
 const int32_t DEFAULT_SEEKWINDOW_MS = USE_AUTO_SEEKWINDOW_LEN;
93 93
 
94
-/// Overlap length in milliseconds. When the chopped sound sequences are mixed back together, 
95
-/// to form a continuous sound stream, this parameter defines over how long period the two 
96
-/// consecutive sequences are let to overlap each other. 
94
+/// Overlap length in milliseconds. When the chopped sound sequences are mixed back together,
95
+/// to form a continuous sound stream, this parameter defines over how long period the two
96
+/// consecutive sequences are let to overlap each other.
97 97
 ///
98
-/// This shouldn't be that critical parameter. If you reduce the DEFAULT_SEQUENCE_MS setting 
98
+/// This shouldn't be that critical parameter. If you reduce the DEFAULT_SEQUENCE_MS setting
99 99
 /// by a large amount, you might wish to try a smaller value on this.
100 100
 ///
101 101
 /// Increasing this value increases computational burden & vice versa.
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -41,8 +41,7 @@
41 41
 //
42 42
 ////////////////////////////////////////////////////////////////////////////////
43 43
 
44
-#ifndef TDStretch_H
45
-#define TDStretch_H
44
+#pragma once
46 45
 
47 46
 #include <memory>
48 47
 #include "RateTransposer.h"
... ...
@@ -243,5 +242,3 @@ protected:
243 242
 #endif ///  SOUNDTOUCH_ALLOW_SSE
244 243
 
245 244
 }
246
-
247
-#endif  /// TDStretch_H
Browse code

Some more code cleanup in DeSmuME.

Naram Qashat authored on 2013/04/23 00:07:41
Showing 1 changed files
... ...
@@ -46,7 +46,6 @@
46 46
 
47 47
 #include <memory>
48 48
 #include "RateTransposer.h"
49
-#include "FIFOSamplePipe.h"
50 49
 
51 50
 namespace soundtouch
52 51
 {
... ...
@@ -193,9 +192,6 @@ public:
193 192
 	/// nonzero to enable
194 193
 	void enableQuickSeek(bool enable);
195 194
 
196
-	/// Returns nonzero if the quick seeking algorithm is enabled.
197
-	bool isQuickSeekEnabled() const;
198
-
199 195
 	/// Sets routine control parameters. These control are certain time constants
200 196
 	/// defining how the sound is stretched to the desired duration.
201 197
 	//
... ...
@@ -222,18 +218,6 @@ public:
222 218
             uint32_t numSamples                         ///< Number of samples in 'samples' so that one sample
223 219
                                                        ///< contains both channels if stereo
224 220
             );
225
-
226
-	/// return nominal input sample requirement for triggering a processing batch
227
-	int32_t getInputSampleReq() const
228
-	{
229
-		return static_cast<int32_t>(this->nominalSkip + 0.5);
230
-	}
231
-
232
-	/// return nominal output sample amount when running a processing batch
233
-	int32_t getOutputBatchSize() const
234
-	{
235
-		return this->seekWindowLength - this->overlapLength;
236
-	}
237 221
 };
238 222
 
239 223
 // Implementation-specific class declarations:
Browse code

Updating in_2sf to use a newish version of DeSmuME, 0.9.9 from SVN. Somewhat cleaned up as well, but not everything because it's a pain in the ass.

Naram Qashat authored on 2013/04/18 17:22:55
Showing 1 changed files
... ...
@@ -4,8 +4,8 @@
4 4
 /// while maintaining the original pitch by using a time domain WSOLA-like method
5 5
 /// with several performance-increasing tweaks.
6 6
 ///
7
-/// Note : MMX optimized functions reside in a separate, platform-specific file,
8
-/// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
7
+/// Note : MMX/SSE optimized functions reside in separate, platform-specific files 
8
+/// 'mmx_optimized.cpp' and 'sse_optimized.cpp'
9 9
 ///
10 10
 /// Author        : Copyright (c) Olli Parviainen
11 11
 /// Author e-mail : oparviai 'at' iki.fi
... ...
@@ -13,10 +13,10 @@
13 13
 ///
14 14
 ////////////////////////////////////////////////////////////////////////////////
15 15
 //
16
-// Last changed  : $Date: 2006/02/05 16:44:06 $
17
-// File revision : $Revision: 1.16 $
16
+// Last changed  : $Date: 2012-04-01 16:49:30 -0300 (dom, 01 abr 2012) $
17
+// File revision : $Revision: 4 $
18 18
 //
19
-// $Id: TDStretch.h,v 1.16 2006/02/05 16:44:06 Olli Exp $
19
+// $Id: TDStretch.h 137 2012-04-01 19:49:30Z oparviai $
20 20
 //
21 21
 ////////////////////////////////////////////////////////////////////////////////
22 22
 //
... ...
@@ -44,14 +44,24 @@
44 44
 #ifndef TDStretch_H
45 45
 #define TDStretch_H
46 46
 
47
-#include "STTypes.h"
47
+#include <memory>
48 48
 #include "RateTransposer.h"
49 49
 #include "FIFOSamplePipe.h"
50 50
 
51 51
 namespace soundtouch
52 52
 {
53 53
 
54
-// Default values for sound processing parameters:
54
+/// Default values for sound processing parameters:
55
+/// Notice that the default parameters are tuned for contemporary popular music 
56
+/// processing. For speech processing applications these parameters suit better:
57
+///     #define DEFAULT_SEQUENCE_MS     40
58
+///     #define DEFAULT_SEEKWINDOW_MS   15
59
+///     #define DEFAULT_OVERLAP_MS      8
60
+///
61
+
62
+/// Giving this value for the sequence length sets automatic parameter value
63
+/// according to tempo setting (recommended)
64
+const int32_t USE_AUTO_SEQUENCE_LEN = 0;
55 65
 
56 66
 /// Default length of a single processing sequence, in milliseconds. This determines to how
57 67
 /// long sequences the original sound is chopped in the time-stretch algorithm.
... ...
@@ -61,55 +71,77 @@ namespace soundtouch
61 71
 /// and vice versa.
62 72
 ///
63 73
 /// Increasing this value reduces computational burden & vice versa.
64
-static const uint32_t DEFAULT_SEQUENCE_MS = 63;
74
+//#define DEFAULT_SEQUENCE_MS 40
75
+const int32_t DEFAULT_SEQUENCE_MS = USE_AUTO_SEQUENCE_LEN;
65 76
 
66
-static const uint32_t DEFAULT_SEEKWINDOW_MS = 17;
77
+/// Giving this value for the seek window length sets automatic parameter value
78
+/// according to tempo setting (recommended)
79
+const int32_t USE_AUTO_SEEKWINDOW_LEN = 0;
67 80
 
68
-static const uint32_t DEFAULT_OVERLAP_MS = 7;
81
+/// Seeking window default length in milliseconds for algorithm that finds the best possible 
82
+/// overlapping location. This determines from how wide window the algorithm may look for an 
83
+/// optimal joining location when mixing the sound sequences back together. 
84
+///
85
+/// The bigger this window setting is, the higher the possibility to find a better mixing
86
+/// position will become, but at the same time large values may cause a "drifting" artifact
87
+/// because consequent sequences will be taken at more uneven intervals.
88
+///
89
+/// If there's a disturbing artifact that sounds as if a constant frequency was drifting 
90
+/// around, try reducing this setting.
91
+///
92
+/// Increasing this value increases computational burden & vice versa.
93
+//#define DEFAULT_SEEKWINDOW_MS       15
94
+const int32_t DEFAULT_SEEKWINDOW_MS = USE_AUTO_SEEKWINDOW_LEN;
95
+
96
+/// Overlap length in milliseconds. When the chopped sound sequences are mixed back together, 
97
+/// to form a continuous sound stream, this parameter defines over how long period the two 
98
+/// consecutive sequences are let to overlap each other. 
99
+///
100
+/// This shouldn't be that critical parameter. If you reduce the DEFAULT_SEQUENCE_MS setting 
101
+/// by a large amount, you might wish to try a smaller value on this.
102
+///
103
+/// Increasing this value increases computational burden & vice versa.
104
+const int32_t DEFAULT_OVERLAP_MS = 8;
69 105
 
70 106
 /// Class that does the time-stretch (tempo change) effect for the processed
71 107
 /// sound.
72 108
 class TDStretch : public FIFOProcessor
73 109
 {
74 110
 protected:
75
-	uint32_t channels;
76
-	uint32_t sampleReq;
111
+	int32_t channels;
112
+	int32_t sampleReq;
77 113
 	float tempo;
78 114
 
79 115
 	SAMPLETYPE *pMidBuffer;
80
-	SAMPLETYPE *pRefMidBuffer;
81
-	SAMPLETYPE *pRefMidBufferUnaligned;
82
-	uint32_t overlapLength;
83
-	uint32_t overlapDividerBits;
84
-	uint32_t slopingDivider;
85
-	uint32_t seekLength;
86
-	uint32_t seekWindowLength;
87
-	uint32_t maxOffset;
116
+	std::unique_ptr<SAMPLETYPE[]> pMidBufferUnaligned;
117
+	int32_t overlapLength;
118
+	int32_t seekLength;
119
+	int32_t seekWindowLength;
120
+	int32_t overlapDividerBits;
121
+	int32_t slopingDivider;
88 122
 	float nominalSkip;
89 123
 	float skipFract;
90 124
 	FIFOSampleBuffer outputBuffer;
91 125
 	FIFOSampleBuffer inputBuffer;
92
-	bool bQuickseek;
93
-	bool bMidBufferDirty;
126
+	bool bQuickSeek;
94 127
 
95
-	uint32_t sampleRate;
96
-	uint32_t sequenceMs;
97
-	uint32_t seekWindowMs;
98
-	uint32_t overlapMs;
128
+	int32_t sampleRate;
129
+	int32_t sequenceMs;
130
+	int32_t seekWindowMs;
131
+	int32_t overlapMs;
132
+	bool bAutoSeqSetting;
133
+	bool bAutoSeekSetting;
99 134
 
100
-	void acceptNewOverlapLength(uint32_t newOverlapLength);
135
+	void acceptNewOverlapLength(int32_t newOverlapLength);
101 136
 
102 137
 	virtual void clearCrossCorrState();
103
-	void calculateOverlapLength(uint32_t overlapMs);
138
+	void calculateOverlapLength(int32_t overlapMs);
104 139
 
105
-	virtual LONG_SAMPLETYPE calcCrossCorrStereo(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
106
-	virtual LONG_SAMPLETYPE calcCrossCorrMono(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
140
+	virtual double calcCrossCorr(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
107 141
 
108
-	virtual uint32_t seekBestOverlapPositionStereo(const SAMPLETYPE *refPos);
109
-	virtual uint32_t seekBestOverlapPositionStereoQuick(const SAMPLETYPE *refPos);
110
-	virtual uint32_t seekBestOverlapPositionMono(const SAMPLETYPE *refPos);
111
-	virtual uint32_t seekBestOverlapPositionMonoQuick(const SAMPLETYPE *refPos);
112
-	uint32_t seekBestOverlapPosition(const SAMPLETYPE *refPos);
142
+	virtual int seekBestOverlapPositionFull(const SAMPLETYPE *refPos);
143
+	virtual int seekBestOverlapPositionQuick(const SAMPLETYPE *refPos);
144
+	int32_t seekBestOverlapPosition(const SAMPLETYPE *refPos);
113 145
 
114 146
 	virtual void overlapStereo(SAMPLETYPE *output, const SAMPLETYPE *input) const;
115 147
 	virtual void overlapMono(SAMPLETYPE *output, const SAMPLETYPE *input) const;
... ...
@@ -117,10 +149,7 @@ protected:
117 149
 	void clearMidBuffer();
118 150
 	void overlap(SAMPLETYPE *output, const SAMPLETYPE *input, uint32_t ovlPos) const;
119 151
 
120
-	void precalcCorrReferenceMono();
121
-	void precalcCorrReferenceStereo();
122
-
123
-	void processNominalTempo();
152
+	void calcSeqParameters();
124 153
 
125 154
 	/// Changes the tempo of the given sound samples.
126 155
 	/// Returns amount of samples returned in the "output" buffer.
... ...
@@ -134,7 +163,7 @@ public:
134 163
 
135 164
 	/// Operator 'new' is overloaded so that it automatically creates a suitable instance
136 165
 	/// depending on if we've a MMX/SSE/etc-capable CPU available or not.
137
-	void *operator new(size_t s);
166
+	static void *operator new(size_t s);
138 167
 
139 168
 	/// Use this function instead of "new" operator to create a new instance of this class.
140 169
 	/// This function automatically chooses a correct feature set depending on if the CPU
... ...
@@ -142,10 +171,10 @@ public:
142 171
 	static TDStretch *newInstance();
143 172
 
144 173
 	/// Returns the output buffer object
145
-	FIFOSamplePipe *getOutput() { return &outputBuffer; };
174
+	FIFOSamplePipe *getOutput() { return &this->outputBuffer; }
146 175
 
147 176
 	/// Returns the input buffer object
148
-	FIFOSamplePipe *getInput() { return &inputBuffer; };
177
+	FIFOSamplePipe *getInput() { return &this->inputBuffer; }
149 178
 
150 179
 	/// Sets new target tempo. Normal tempo = 'SCALE', smaller values represent slower
151 180
 	/// tempo, larger faster tempo.
... ...
@@ -158,7 +187,7 @@ public:
158 187
 	void clearInput();
159 188
 
160 189
 	/// Sets the number of channels, 1 = mono, 2 = stereo
161
-	void setChannels(uint32_t numChannels);
190
+	void setChannels(int32_t numChannels);
162 191
 
163 192
 	/// Enables/disables the quick position seeking algorithm. Zero to disable,
164 193
 	/// nonzero to enable
... ...
@@ -175,16 +204,16 @@ public:
175 204
 	/// 'seekwindowMS' = seeking window length for scanning the best overlapping
176 205
 	///      position
177 206
 	/// 'overlapMS' = overlapping length
178
-	void setParameters(uint32_t sampleRate,                             ///< Samplerate of sound being processed (Hz)
179
-                       uint32_t sequenceMS = DEFAULT_SEQUENCE_MS,       ///< Single processing sequence length (ms)
180
-                       uint32_t seekwindowMS = DEFAULT_SEEKWINDOW_MS,   ///< Offset seeking window length (ms)
181
-                       uint32_t overlapMS = DEFAULT_OVERLAP_MS          ///< Sequence overlapping length (ms)
207
+	void setParameters(int32_t sampleRate,          ///< Samplerate of sound being processed (Hz)
208
+                       int32_t sequenceMS = -1,     ///< Single processing sequence length (ms)
209
+                       int32_t seekwindowMS = -1,   ///< Offset seeking window length (ms)
210
+                       int32_t overlapMS = -1       ///< Sequence overlapping length (ms)
182 211
                        );
183 212
 
184 213
 	/// Get routine control parameters, see setParameters() function.
185 214
 	/// Any of the parameters to this function can be NULL, in such case corresponding parameter
186 215
 	/// value isn't returned.
187
-	void getParameters(uint32_t *pSampleRate, uint32_t *pSequenceMs, uint32_t *pSeekWindowMs, uint32_t *pOverlapMs);
216
+	void getParameters(int32_t *pSampleRate, int32_t *pSequenceMs, int32_t *pSeekWindowMs, int32_t *pOverlapMs);
188 217
 
189 218
 	/// Adds 'numsamples' pcs of samples from the 'samples' memory position into
190 219
 	/// the input of the object.
... ...
@@ -193,40 +222,41 @@ public:
193 222
             uint32_t numSamples                         ///< Number of samples in 'samples' so that one sample
194 223
                                                        ///< contains both channels if stereo
195 224
             );
196
-};
197 225
 
226
+	/// return nominal input sample requirement for triggering a processing batch
227
+	int32_t getInputSampleReq() const
228
+	{
229
+		return static_cast<int32_t>(this->nominalSkip + 0.5);
230
+	}
231
+
232
+	/// return nominal output sample amount when running a processing batch
233
+	int32_t getOutputBatchSize() const
234
+	{
235
+		return this->seekWindowLength - this->overlapLength;
236
+	}
237
+};
198 238
 
199 239
 // Implementation-specific class declarations:
200 240
 
201
-//#ifdef ALLOW_MMX
202
-//    /// Class that implements MMX optimized routines for 16bit integer samples type.
203
-//    class TDStretchMMX : public TDStretch
204
-//    {
205
-//    protected:
206
-//        long calcCrossCorrStereo(const short *mixingPos, const short *compare) const;
207
-//        virtual void overlapStereo(short *output, const short *input) const;
208
-//        virtual void clearCrossCorrState();
209
-//    };
210
-//#endif /// ALLOW_MMX
211
-//
212
-//
213
-//#ifdef ALLOW_3DNOW
214
-//    /// Class that implements 3DNow! optimized routines for floating point samples type.
215
-//    class TDStretch3DNow : public TDStretch
216
-//    {
217
-//    protected:
218
-//        double calcCrossCorrStereo(const float *mixingPos, const float *compare) const;
219
-//    };
220
-//#endif /// ALLOW_3DNOW
221
-
222
-#ifdef __SSE__
241
+#ifdef SOUNDTOUCH_ALLOW_MMX
242
+/// Class that implements MMX optimized routines for 16bit integer samples type.
243
+class TDStretchMMX : public TDStretch
244
+{
245
+protected:
246
+	double calcCrossCorr(const short *mixingPos, const short *compare) const;
247
+	virtual void overlapStereo(short *output, const short *input) const;
248
+	virtual void clearCrossCorrState();
249
+};
250
+#endif /// SOUNDTOUCH_ALLOW_MMX
251
+
252
+#ifdef SOUNDTOUCH_ALLOW_SSE
223 253
 /// Class that implements SSE optimized routines for floating point samples type.
224 254
 class TDStretchSSE : public TDStretch
225 255
 {
226 256
 protected:
227
-	double calcCrossCorrStereo(const float *mixingPos, const float *compare) const;
257
+	double calcCrossCorr(const float *mixingPos, const float *compare) const;
228 258
 };
229
-#endif /// ALLOW_SSE
259
+#endif ///  SOUNDTOUCH_ALLOW_SSE
230 260
 
231 261
 }
232 262
 
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,233 @@
1
+////////////////////////////////////////////////////////////////////////////////
2
+///
3
+/// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo
4
+/// while maintaining the original pitch by using a time domain WSOLA-like method
5
+/// with several performance-increasing tweaks.
6
+///
7
+/// Note : MMX optimized functions reside in a separate, platform-specific file,
8
+/// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
9
+///
10
+/// Author        : Copyright (c) Olli Parviainen
11
+/// Author e-mail : oparviai 'at' iki.fi
12
+/// SoundTouch WWW: http://www.surina.net/soundtouch
13
+///
14
+////////////////////////////////////////////////////////////////////////////////
15
+//
16
+// Last changed  : $Date: 2006/02/05 16:44:06 $
17
+// File revision : $Revision: 1.16 $
18
+//
19
+// $Id: TDStretch.h,v 1.16 2006/02/05 16:44:06 Olli Exp $
20
+//
21
+////////////////////////////////////////////////////////////////////////////////
22
+//
23
+// License :
24
+//
25
+//  SoundTouch audio processing library
26
+//  Copyright (c) Olli Parviainen
27
+//
28
+//  This library is free software; you can redistribute it and/or
29
+//  modify it under the terms of the GNU Lesser General Public
30
+//  License as published by the Free Software Foundation; either
31
+//  version 2.1 of the License, or (at your option) any later version.
32
+//
33
+//  This library is distributed in the hope that it will be useful,
34
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
35
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36
+//  Lesser General Public License for more details.
37
+//
38
+//  You should have received a copy of the GNU Lesser General Public
39
+//  License along with this library; if not, write to the Free Software
40
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
41
+//
42
+////////////////////////////////////////////////////////////////////////////////
43
+
44
+#ifndef TDStretch_H
45
+#define TDStretch_H
46
+
47
+#include "STTypes.h"
48
+#include "RateTransposer.h"
49
+#include "FIFOSamplePipe.h"
50
+
51
+namespace soundtouch
52
+{
53
+
54
+// Default values for sound processing parameters:
55
+
56
+/// Default length of a single processing sequence, in milliseconds. This determines to how
57
+/// long sequences the original sound is chopped in the time-stretch algorithm.
58
+///
59
+/// The larger this value is, the lesser sequences are used in processing. In principle
60
+/// a bigger value sounds better when slowing down tempo, but worse when increasing tempo
61
+/// and vice versa.
62
+///
63
+/// Increasing this value reduces computational burden & vice versa.
64
+static const uint32_t DEFAULT_SEQUENCE_MS = 63;
65
+
66
+static const uint32_t DEFAULT_SEEKWINDOW_MS = 17;
67
+
68
+static const uint32_t DEFAULT_OVERLAP_MS = 7;
69
+
70
+/// Class that does the time-stretch (tempo change) effect for the processed
71
+/// sound.
72
+class TDStretch : public FIFOProcessor
73
+{
74
+protected:
75
+	uint32_t channels;
76
+	uint32_t sampleReq;
77
+	float tempo;
78
+
79
+	SAMPLETYPE *pMidBuffer;
80
+	SAMPLETYPE *pRefMidBuffer;
81
+	SAMPLETYPE *pRefMidBufferUnaligned;
82
+	uint32_t overlapLength;
83
+	uint32_t overlapDividerBits;
84
+	uint32_t slopingDivider;
85
+	uint32_t seekLength;
86
+	uint32_t seekWindowLength;
87
+	uint32_t maxOffset;
88
+	float nominalSkip;
89
+	float skipFract;
90
+	FIFOSampleBuffer outputBuffer;
91
+	FIFOSampleBuffer inputBuffer;
92
+	bool bQuickseek;
93
+	bool bMidBufferDirty;
94
+
95
+	uint32_t sampleRate;
96
+	uint32_t sequenceMs;
97
+	uint32_t seekWindowMs;
98
+	uint32_t overlapMs;
99
+
100
+	void acceptNewOverlapLength(uint32_t newOverlapLength);
101
+
102
+	virtual void clearCrossCorrState();
103
+	void calculateOverlapLength(uint32_t overlapMs);
104
+
105
+	virtual LONG_SAMPLETYPE calcCrossCorrStereo(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
106
+	virtual LONG_SAMPLETYPE calcCrossCorrMono(const SAMPLETYPE *mixingPos, const SAMPLETYPE *compare) const;
107
+
108
+	virtual uint32_t seekBestOverlapPositionStereo(const SAMPLETYPE *refPos);
109
+	virtual uint32_t seekBestOverlapPositionStereoQuick(const SAMPLETYPE *refPos);
110
+	virtual uint32_t seekBestOverlapPositionMono(const SAMPLETYPE *refPos);
111
+	virtual uint32_t seekBestOverlapPositionMonoQuick(const SAMPLETYPE *refPos);
112
+	uint32_t seekBestOverlapPosition(const SAMPLETYPE *refPos);
113
+
114
+	virtual void overlapStereo(SAMPLETYPE *output, const SAMPLETYPE *input) const;
115
+	virtual void overlapMono(SAMPLETYPE *output, const SAMPLETYPE *input) const;
116
+
117
+	void clearMidBuffer();
118
+	void overlap(SAMPLETYPE *output, const SAMPLETYPE *input, uint32_t ovlPos) const;
119
+
120
+	void precalcCorrReferenceMono();
121
+	void precalcCorrReferenceStereo();
122
+
123
+	void processNominalTempo();
124
+
125
+	/// Changes the tempo of the given sound samples.
126
+	/// Returns amount of samples returned in the "output" buffer.
127
+	/// The maximum amount of samples that can be returned at a time is set by
128
+	/// the 'set_returnBuffer_size' function.
129
+	void processSamples();
130
+
131
+public:
132
+	TDStretch();
133
+	virtual ~TDStretch();
134
+
135
+	/// Operator 'new' is overloaded so that it automatically creates a suitable instance
136
+	/// depending on if we've a MMX/SSE/etc-capable CPU available or not.
137
+	void *operator new(size_t s);
138
+
139
+	/// Use this function instead of "new" operator to create a new instance of this class.
140
+	/// This function automatically chooses a correct feature set depending on if the CPU
141
+	/// supports MMX/SSE/etc extensions.
142
+	static TDStretch *newInstance();
143
+
144
+	/// Returns the output buffer object
145
+	FIFOSamplePipe *getOutput() { return &outputBuffer; };
146
+
147
+	/// Returns the input buffer object
148
+	FIFOSamplePipe *getInput() { return &inputBuffer; };
149
+
150
+	/// Sets new target tempo. Normal tempo = 'SCALE', smaller values represent slower
151
+	/// tempo, larger faster tempo.
152
+	void setTempo(float newTempo);
153
+
154
+	/// Returns nonzero if there aren't any samples available for outputting.
155
+	virtual void clear();
156
+
157
+	/// Clears the input buffer
158
+	void clearInput();
159
+
160
+	/// Sets the number of channels, 1 = mono, 2 = stereo
161
+	void setChannels(uint32_t numChannels);
162
+
163
+	/// Enables/disables the quick position seeking algorithm. Zero to disable,
164
+	/// nonzero to enable
165
+	void enableQuickSeek(bool enable);
166
+
167
+	/// Returns nonzero if the quick seeking algorithm is enabled.
168
+	bool isQuickSeekEnabled() const;
169
+
170
+	/// Sets routine control parameters. These control are certain time constants
171
+	/// defining how the sound is stretched to the desired duration.
172
+	//
173
+	/// 'sampleRate' = sample rate of the sound
174
+	/// 'sequenceMS' = one processing sequence length in milliseconds
175
+	/// 'seekwindowMS' = seeking window length for scanning the best overlapping
176
+	///      position
177
+	/// 'overlapMS' = overlapping length
178
+	void setParameters(uint32_t sampleRate,                             ///< Samplerate of sound being processed (Hz)
179
+                       uint32_t sequenceMS = DEFAULT_SEQUENCE_MS,       ///< Single processing sequence length (ms)
180
+                       uint32_t seekwindowMS = DEFAULT_SEEKWINDOW_MS,   ///< Offset seeking window length (ms)
181
+                       uint32_t overlapMS = DEFAULT_OVERLAP_MS          ///< Sequence overlapping length (ms)
182
+                       );
183
+
184
+	/// Get routine control parameters, see setParameters() function.
185
+	/// Any of the parameters to this function can be NULL, in such case corresponding parameter
186
+	/// value isn't returned.
187
+	void getParameters(uint32_t *pSampleRate, uint32_t *pSequenceMs, uint32_t *pSeekWindowMs, uint32_t *pOverlapMs);
188
+
189
+	/// Adds 'numsamples' pcs of samples from the 'samples' memory position into
190
+	/// the input of the object.
191
+	virtual void putSamples(
192
+            const SAMPLETYPE *samples,  ///< Input sample data
193
+            uint32_t numSamples                         ///< Number of samples in 'samples' so that one sample
194
+                                                       ///< contains both channels if stereo
195
+            );
196
+};
197
+
198
+
199
+// Implementation-specific class declarations:
200
+
201
+//#ifdef ALLOW_MMX
202
+//    /// Class that implements MMX optimized routines for 16bit integer samples type.
203
+//    class TDStretchMMX : public TDStretch
204
+//    {
205
+//    protected:
206
+//        long calcCrossCorrStereo(const short *mixingPos, const short *compare) const;
207
+//        virtual void overlapStereo(short *output, const short *input) const;
208
+//        virtual void clearCrossCorrState();
209
+//    };
210
+//#endif /// ALLOW_MMX
211
+//
212
+//
213
+//#ifdef ALLOW_3DNOW
214
+//    /// Class that implements 3DNow! optimized routines for floating point samples type.
215
+//    class TDStretch3DNow : public TDStretch
216
+//    {
217
+//    protected:
218
+//        double calcCrossCorrStereo(const float *mixingPos, const float *compare) const;
219
+//    };
220
+//#endif /// ALLOW_3DNOW
221
+
222
+#ifdef __SSE__
223
+/// Class that implements SSE optimized routines for floating point samples type.
224
+class TDStretchSSE : public TDStretch
225
+{
226
+protected:
227
+	double calcCrossCorrStereo(const float *mixingPos, const float *compare) const;
228
+};
229
+#endif /// ALLOW_SSE
230
+
231
+}
232
+
233
+#endif  /// TDStretch_H