~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/soundtouch/source/SoundTouch/RateTransposer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////////////////////
2
 
///
3
 
/// Sample rate transposer. Changes sample rate by using linear interpolation
4
 
/// together with anti-alias filtering (first order interpolation with anti-
5
 
/// alias filtering should be quite adequate for this application)
6
 
///
7
 
/// Author        : Copyright (c) Olli Parviainen
8
 
/// Author e-mail : oparviai 'at' iki.fi
9
 
/// SoundTouch WWW: http://www.surina.net/soundtouch
10
 
///
11
 
////////////////////////////////////////////////////////////////////////////////
12
 
//
13
 
// Last changed  : $Date: 2006/09/18 22:29:22 $
14
 
// File revision : $Revision: 1.5 $
15
 
//
16
 
// $Id: RateTransposer.cpp,v 1.5 2006/09/18 22:29:22 martynshaw Exp $
17
 
//
18
 
////////////////////////////////////////////////////////////////////////////////
19
 
//
20
 
// License :
21
 
//
22
 
//  SoundTouch audio processing library
23
 
//  Copyright (c) Olli Parviainen
24
 
//
25
 
//  This library is free software; you can redistribute it and/or
26
 
//  modify it under the terms of the GNU Lesser General Public
27
 
//  License as published by the Free Software Foundation; either
28
 
//  version 2.1 of the License, or (at your option) any later version.
29
 
//
30
 
//  This library is distributed in the hope that it will be useful,
31
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33
 
//  Lesser General Public License for more details.
34
 
//
35
 
//  You should have received a copy of the GNU Lesser General Public
36
 
//  License along with this library; if not, write to the Free Software
37
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38
 
//
39
 
////////////////////////////////////////////////////////////////////////////////
40
 
 
41
 
#include <memory.h>
42
 
#include <assert.h>
43
 
#include <stdlib.h>
44
 
#include <stdio.h>
45
 
#include <limits.h>
46
 
#include "RateTransposer.h"
47
 
#include "AAFilter.h"
48
 
 
49
 
using namespace soundtouch;
50
 
 
51
 
 
52
 
/// A linear samplerate transposer class that uses integer arithmetics.
53
 
/// for the transposing.
54
 
class RateTransposerInteger : public RateTransposer
55
 
{
56
 
protected:
57
 
    int iSlopeCount;
58
 
    uint uRate;
59
 
    SAMPLETYPE sPrevSampleL, sPrevSampleR;
60
 
 
61
 
    virtual void resetRegisters();
62
 
 
63
 
    virtual uint transposeStereo(SAMPLETYPE *dest,
64
 
                         const SAMPLETYPE *src,
65
 
                         uint numSamples);
66
 
    virtual uint transposeMono(SAMPLETYPE *dest,
67
 
                       const SAMPLETYPE *src,
68
 
                       uint numSamples);
69
 
 
70
 
public:
71
 
    RateTransposerInteger();
72
 
    virtual ~RateTransposerInteger();
73
 
 
74
 
    /// Sets new target rate. Normal rate = 1.0, smaller values represent slower
75
 
    /// rate, larger faster rates.
76
 
    virtual void setRate(float newRate);
77
 
 
78
 
};
79
 
 
80
 
 
81
 
/// A linear samplerate transposer class that uses floating point arithmetics
82
 
/// for the transposing.
83
 
class RateTransposerFloat : public RateTransposer
84
 
{
85
 
protected:
86
 
    float fSlopeCount;
87
 
    float fRateStep;
88
 
    SAMPLETYPE sPrevSampleL, sPrevSampleR;
89
 
 
90
 
    virtual void resetRegisters();
91
 
 
92
 
    virtual uint transposeStereo(SAMPLETYPE *dest,
93
 
                         const SAMPLETYPE *src,
94
 
                         uint numSamples);
95
 
    virtual uint transposeMono(SAMPLETYPE *dest,
96
 
                       const SAMPLETYPE *src,
97
 
                       uint numSamples);
98
 
 
99
 
public:
100
 
    RateTransposerFloat();
101
 
    virtual ~RateTransposerFloat();
102
 
};
103
 
 
104
 
 
105
 
 
106
 
#ifndef min
107
 
#define min(a,b) ((a > b) ? b : a)
108
 
#define max(a,b) ((a < b) ? b : a)
109
 
#endif
110
 
 
111
 
 
112
 
// Operator 'new' is overloaded so that it automatically creates a suitable instance
113
 
// depending on if we've a MMX/SSE/etc-capable CPU available or not.
114
 
void * RateTransposer::operator new(size_t s)
115
 
{
116
 
    // Notice! don't use "new TDStretch" directly, use "newInstance" to create a new instance instead!
117
 
    assert(FALSE);
118
 
    return NULL;
119
 
}
120
 
 
121
 
 
122
 
RateTransposer *RateTransposer::newInstance()
123
 
{
124
 
#ifdef INTEGER_SAMPLES
125
 
    return ::new RateTransposerInteger;
126
 
#else
127
 
    return ::new RateTransposerFloat;
128
 
#endif
129
 
}
130
 
 
131
 
 
132
 
// Constructor
133
 
RateTransposer::RateTransposer() : FIFOProcessor(&outputBuffer)
134
 
{
135
 
    uChannels = 2;
136
 
    bUseAAFilter = TRUE;
137
 
 
138
 
    // Instantiates the anti-alias filter with default tap length
139
 
    // of 32
140
 
    pAAFilter = new AAFilter(32);
141
 
}
142
 
 
143
 
 
144
 
 
145
 
RateTransposer::~RateTransposer()
146
 
{
147
 
    delete pAAFilter;
148
 
}
149
 
 
150
 
 
151
 
 
152
 
/// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable
153
 
void RateTransposer::enableAAFilter(const BOOL newMode)
154
 
{
155
 
    bUseAAFilter = newMode;
156
 
}
157
 
 
158
 
 
159
 
/// Returns nonzero if anti-alias filter is enabled.
160
 
BOOL RateTransposer::isAAFilterEnabled() const
161
 
{
162
 
    return bUseAAFilter;
163
 
}
164
 
 
165
 
 
166
 
AAFilter *RateTransposer::getAAFilter() const
167
 
{
168
 
    return pAAFilter;
169
 
}
170
 
 
171
 
 
172
 
 
173
 
// Sets new target uRate. Normal uRate = 1.0, smaller values represent slower
174
 
// uRate, larger faster uRates.
175
 
void RateTransposer::setRate(float newRate)
176
 
{
177
 
    float fCutoff;
178
 
 
179
 
    fRate = newRate;
180
 
 
181
 
    // design a new anti-alias filter
182
 
    if (newRate > 1.0f)
183
 
    {
184
 
        fCutoff = 0.5f / newRate;
185
 
    }
186
 
    else
187
 
    {
188
 
        fCutoff = 0.5f * newRate;
189
 
    }
190
 
    pAAFilter->setCutoffFreq(fCutoff);
191
 
}
192
 
 
193
 
 
194
 
// Outputs as many samples of the 'outputBuffer' as possible, and if there's
195
 
// any room left, outputs also as many of the incoming samples as possible.
196
 
// The goal is to drive the outputBuffer empty.
197
 
//
198
 
// It's allowed for 'output' and 'input' parameters to point to the same
199
 
// memory position.
200
 
void RateTransposer::flushStoreBuffer()
201
 
{
202
 
    if (storeBuffer.isEmpty()) return;
203
 
 
204
 
    outputBuffer.moveSamples(storeBuffer);
205
 
}
206
 
 
207
 
 
208
 
// Adds 'numSamples' pcs of samples from the 'samples' memory position into
209
 
// the input of the object.
210
 
void RateTransposer::putSamples(const SAMPLETYPE *samples, uint numSamples)
211
 
{
212
 
    processSamples(samples, numSamples);
213
 
}
214
 
 
215
 
 
216
 
 
217
 
// Transposes up the sample rate, causing the observed playback 'rate' of the
218
 
// sound to decrease
219
 
void RateTransposer::upsample(const SAMPLETYPE *src, uint numSamples)
220
 
{
221
 
    int count, sizeTemp, num;
222
 
 
223
 
    // If the parameter 'uRate' value is smaller than 'SCALE', first transpose
224
 
    // the samples and then apply the anti-alias filter to remove aliasing.
225
 
 
226
 
    // First check that there's enough room in 'storeBuffer'
227
 
    // (+16 is to reserve some slack in the destination buffer)
228
 
    sizeTemp = (int)((float)numSamples / fRate + 16.0f);
229
 
 
230
 
    // Transpose the samples, store the result into the end of "storeBuffer"
231
 
    count = transpose(storeBuffer.ptrEnd(sizeTemp), src, numSamples);
232
 
    storeBuffer.putSamples(count);
233
 
 
234
 
    // Apply the anti-alias filter to samples in "store output", output the
235
 
    // result to "dest"
236
 
    num = storeBuffer.numSamples();
237
 
    count = pAAFilter->evaluate(outputBuffer.ptrEnd(num),
238
 
        storeBuffer.ptrBegin(), num, uChannels);
239
 
    outputBuffer.putSamples(count);
240
 
 
241
 
    // Remove the processed samples from "storeBuffer"
242
 
    storeBuffer.receiveSamples(count);
243
 
}
244
 
 
245
 
 
246
 
// Transposes down the sample rate, causing the observed playback 'rate' of the
247
 
// sound to increase
248
 
void RateTransposer::downsample(const SAMPLETYPE *src, uint numSamples)
249
 
{
250
 
    int count, sizeTemp;
251
 
 
252
 
    // If the parameter 'uRate' value is larger than 'SCALE', first apply the
253
 
    // anti-alias filter to remove high frequencies (prevent them from folding
254
 
    // over the lover frequencies), then transpose. */
255
 
 
256
 
    // Add the new samples to the end of the storeBuffer */
257
 
    storeBuffer.putSamples(src, numSamples);
258
 
 
259
 
    // Anti-alias filter the samples to prevent folding and output the filtered
260
 
    // data to tempBuffer. Note : because of the FIR filter length, the
261
 
    // filtering routine takes in 'filter_length' more samples than it outputs.
262
 
    assert(tempBuffer.isEmpty());
263
 
    sizeTemp = storeBuffer.numSamples();
264
 
 
265
 
    count = pAAFilter->evaluate(tempBuffer.ptrEnd(sizeTemp),
266
 
        storeBuffer.ptrBegin(), sizeTemp, uChannels);
267
 
 
268
 
    // Remove the filtered samples from 'storeBuffer'
269
 
    storeBuffer.receiveSamples(count);
270
 
 
271
 
    // Transpose the samples (+16 is to reserve some slack in the destination buffer)
272
 
    sizeTemp = (int)((float)numSamples / fRate + 16.0f);
273
 
    count = transpose(outputBuffer.ptrEnd(sizeTemp), tempBuffer.ptrBegin(), count);
274
 
    outputBuffer.putSamples(count);
275
 
}
276
 
 
277
 
 
278
 
// Transposes sample rate by applying anti-alias filter to prevent folding.
279
 
// Returns amount of samples returned in the "dest" buffer.
280
 
// The maximum amount of samples that can be returned at a time is set by
281
 
// the 'set_returnBuffer_size' function.
282
 
void RateTransposer::processSamples(const SAMPLETYPE *src, uint numSamples)
283
 
{
284
 
    uint count;
285
 
    uint sizeReq;
286
 
 
287
 
    if (numSamples == 0) return;
288
 
    assert(pAAFilter);
289
 
 
290
 
    // If anti-alias filter is turned off, simply transpose without applying
291
 
    // the filter
292
 
    if (bUseAAFilter == FALSE)
293
 
    {
294
 
        sizeReq = (int)((float)numSamples / fRate + 1.0f);
295
 
        count = transpose(outputBuffer.ptrEnd(sizeReq), src, numSamples);
296
 
        outputBuffer.putSamples(count);
297
 
        return;
298
 
    }
299
 
 
300
 
    // Transpose with anti-alias filter
301
 
    if (fRate < 1.0f)
302
 
    {
303
 
        upsample(src, numSamples);
304
 
    }
305
 
    else
306
 
    {
307
 
        downsample(src, numSamples);
308
 
    }
309
 
}
310
 
 
311
 
 
312
 
// Transposes the sample rate of the given samples using linear interpolation.
313
 
// Returns the number of samples returned in the "dest" buffer
314
 
inline uint RateTransposer::transpose(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples)
315
 
{
316
 
    if (uChannels == 2)
317
 
    {
318
 
        return transposeStereo(dest, src, numSamples);
319
 
    }
320
 
    else
321
 
    {
322
 
        return transposeMono(dest, src, numSamples);
323
 
    }
324
 
}
325
 
 
326
 
 
327
 
// Sets the number of channels, 1 = mono, 2 = stereo
328
 
void RateTransposer::setChannels(const uint numchannels)
329
 
{
330
 
    if (uChannels == numchannels) return;
331
 
 
332
 
    assert(numchannels == 1 || numchannels == 2);
333
 
    uChannels = numchannels;
334
 
 
335
 
    storeBuffer.setChannels(uChannels);
336
 
    tempBuffer.setChannels(uChannels);
337
 
    outputBuffer.setChannels(uChannels);
338
 
 
339
 
    // Inits the linear interpolation registers
340
 
    resetRegisters();
341
 
}
342
 
 
343
 
 
344
 
// Clears all the samples in the object
345
 
void RateTransposer::clear()
346
 
{
347
 
    outputBuffer.clear();
348
 
    storeBuffer.clear();
349
 
}
350
 
 
351
 
 
352
 
// Returns nonzero if there aren't any samples available for outputting.
353
 
uint RateTransposer::isEmpty()
354
 
{
355
 
    int res;
356
 
 
357
 
    res = FIFOProcessor::isEmpty();
358
 
    if (res == 0) return 0;
359
 
    return storeBuffer.isEmpty();
360
 
}
361
 
 
362
 
 
363
 
//////////////////////////////////////////////////////////////////////////////
364
 
//
365
 
// RateTransposerInteger - integer arithmetic implementation
366
 
//
367
 
 
368
 
/// fixed-point interpolation routine precision
369
 
#define SCALE    65536
370
 
 
371
 
// Constructor
372
 
RateTransposerInteger::RateTransposerInteger() : RateTransposer()
373
 
{
374
 
    // call these here as these are virtual functions; calling these
375
 
    // from the base class constructor wouldn't execute the overloaded
376
 
    // versions (<master yoda>peculiar C++ can be</my>).
377
 
    resetRegisters();
378
 
    setRate(1.0f);
379
 
}
380
 
 
381
 
 
382
 
RateTransposerInteger::~RateTransposerInteger()
383
 
{
384
 
}
385
 
 
386
 
 
387
 
void RateTransposerInteger::resetRegisters()
388
 
{
389
 
    iSlopeCount = 0;
390
 
    sPrevSampleL =
391
 
    sPrevSampleR = 0;
392
 
}
393
 
 
394
 
 
395
 
 
396
 
// Transposes the sample rate of the given samples using linear interpolation.
397
 
// 'Mono' version of the routine. Returns the number of samples returned in
398
 
// the "dest" buffer
399
 
uint RateTransposerInteger::transposeMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples)
400
 
{
401
 
    unsigned int i, used;
402
 
    LONG_SAMPLETYPE temp, vol1;
403
 
 
404
 
    used = 0;
405
 
    i = 0;
406
 
 
407
 
    // Process the last sample saved from the previous call first...
408
 
    while (iSlopeCount <= SCALE)
409
 
    {
410
 
        vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
411
 
        temp = vol1 * sPrevSampleL + iSlopeCount * src[0];
412
 
        dest[i] = (SAMPLETYPE)(temp / SCALE);
413
 
        i++;
414
 
        iSlopeCount += uRate;
415
 
    }
416
 
    // now always (iSlopeCount > SCALE)
417
 
    iSlopeCount -= SCALE;
418
 
 
419
 
    while (1)
420
 
    {
421
 
        while (iSlopeCount > SCALE)
422
 
        {
423
 
            iSlopeCount -= SCALE;
424
 
            used ++;
425
 
            if (used >= numSamples - 1) goto end;
426
 
        }
427
 
        vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
428
 
        temp = src[used] * vol1 + iSlopeCount * src[used + 1];
429
 
        dest[i] = (SAMPLETYPE)(temp / SCALE);
430
 
 
431
 
        i++;
432
 
        iSlopeCount += uRate;
433
 
    }
434
 
end:
435
 
    // Store the last sample for the next round
436
 
    sPrevSampleL = src[numSamples - 1];
437
 
 
438
 
    return i;
439
 
}
440
 
 
441
 
 
442
 
// Transposes the sample rate of the given samples using linear interpolation.
443
 
// 'Stereo' version of the routine. Returns the number of samples returned in
444
 
// the "dest" buffer
445
 
uint RateTransposerInteger::transposeStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples)
446
 
{
447
 
    unsigned int srcPos, i, used;
448
 
    LONG_SAMPLETYPE temp, vol1;
449
 
 
450
 
    if (numSamples == 0) return 0;  // no samples, no work
451
 
 
452
 
    used = 0;
453
 
    i = 0;
454
 
 
455
 
    // Process the last sample saved from the sPrevSampleLious call first...
456
 
    while (iSlopeCount <= SCALE)
457
 
    {
458
 
        vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
459
 
        temp = vol1 * sPrevSampleL + iSlopeCount * src[0];
460
 
        dest[2 * i] = (SAMPLETYPE)(temp / SCALE);
461
 
        temp = vol1 * sPrevSampleR + iSlopeCount * src[1];
462
 
        dest[2 * i + 1] = (SAMPLETYPE)(temp / SCALE);
463
 
        i++;
464
 
        iSlopeCount += uRate;
465
 
    }
466
 
    // now always (iSlopeCount > SCALE)
467
 
    iSlopeCount -= SCALE;
468
 
 
469
 
    while (1)
470
 
    {
471
 
        while (iSlopeCount > SCALE)
472
 
        {
473
 
            iSlopeCount -= SCALE;
474
 
            used ++;
475
 
            if (used >= numSamples - 1) goto end;
476
 
        }
477
 
        srcPos = 2 * used;
478
 
        vol1 = (LONG_SAMPLETYPE)(SCALE - iSlopeCount);
479
 
        temp = src[srcPos] * vol1 + iSlopeCount * src[srcPos + 2];
480
 
        dest[2 * i] = (SAMPLETYPE)(temp / SCALE);
481
 
        temp = src[srcPos + 1] * vol1 + iSlopeCount * src[srcPos + 3];
482
 
        dest[2 * i + 1] = (SAMPLETYPE)(temp / SCALE);
483
 
 
484
 
        i++;
485
 
        iSlopeCount += uRate;
486
 
    }
487
 
end:
488
 
    // Store the last sample for the next round
489
 
    sPrevSampleL = src[2 * numSamples - 2];
490
 
    sPrevSampleR = src[2 * numSamples - 1];
491
 
 
492
 
    return i;
493
 
}
494
 
 
495
 
 
496
 
// Sets new target uRate. Normal uRate = 1.0, smaller values represent slower
497
 
// uRate, larger faster uRates.
498
 
void RateTransposerInteger::setRate(float newRate)
499
 
{
500
 
    uRate = (int)(newRate * SCALE + 0.5f);
501
 
    RateTransposer::setRate(newRate);
502
 
}
503
 
 
504
 
 
505
 
//////////////////////////////////////////////////////////////////////////////
506
 
//
507
 
// RateTransposerFloat - floating point arithmetic implementation
508
 
//
509
 
//////////////////////////////////////////////////////////////////////////////
510
 
 
511
 
// Constructor
512
 
RateTransposerFloat::RateTransposerFloat() : RateTransposer()
513
 
{
514
 
    // call these here as these are virtual functions; calling these
515
 
    // from the base class constructor wouldn't execute the overloaded
516
 
    // versions (<master yoda>peculiar C++ can be</my>).
517
 
    resetRegisters();
518
 
    setRate(1.0f);
519
 
}
520
 
 
521
 
 
522
 
RateTransposerFloat::~RateTransposerFloat()
523
 
{
524
 
}
525
 
 
526
 
 
527
 
void RateTransposerFloat::resetRegisters()
528
 
{
529
 
    fSlopeCount = 0;
530
 
    sPrevSampleL =
531
 
    sPrevSampleR = 0;
532
 
}
533
 
 
534
 
 
535
 
 
536
 
// Transposes the sample rate of the given samples using linear interpolation.
537
 
// 'Mono' version of the routine. Returns the number of samples returned in
538
 
// the "dest" buffer
539
 
uint RateTransposerFloat::transposeMono(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples)
540
 
{
541
 
    unsigned int i, used;
542
 
 
543
 
    used = 0;
544
 
    i = 0;
545
 
 
546
 
    // Process the last sample saved from the previous call first...
547
 
    while (fSlopeCount <= 1.0f)
548
 
    {
549
 
        dest[i] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleL + fSlopeCount * src[0]);
550
 
        i++;
551
 
        fSlopeCount += fRate;
552
 
    }
553
 
    fSlopeCount -= 1.0f;
554
 
 
555
 
    if (numSamples == 1) goto end;
556
 
 
557
 
    while (1)
558
 
    {
559
 
        while (fSlopeCount > 1.0f)
560
 
        {
561
 
            fSlopeCount -= 1.0f;
562
 
            used ++;
563
 
            if (used >= numSamples - 1) goto end;
564
 
        }
565
 
        dest[i] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[used] + fSlopeCount * src[used + 1]);
566
 
        i++;
567
 
        fSlopeCount += fRate;
568
 
    }
569
 
end:
570
 
    // Store the last sample for the next round
571
 
    sPrevSampleL = src[numSamples - 1];
572
 
 
573
 
    return i;
574
 
}
575
 
 
576
 
 
577
 
// Transposes the sample rate of the given samples using linear interpolation.
578
 
// 'Mono' version of the routine. Returns the number of samples returned in
579
 
// the "dest" buffer
580
 
uint RateTransposerFloat::transposeStereo(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples)
581
 
{
582
 
    unsigned int srcPos, i, used;
583
 
 
584
 
    if (numSamples == 0) return 0;  // no samples, no work
585
 
 
586
 
    used = 0;
587
 
    i = 0;
588
 
 
589
 
    // Process the last sample saved from the sPrevSampleLious call first...
590
 
    while (fSlopeCount <= 1.0f)
591
 
    {
592
 
        dest[2 * i] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleL + fSlopeCount * src[0]);
593
 
        dest[2 * i + 1] = (SAMPLETYPE)((1.0f - fSlopeCount) * sPrevSampleR + fSlopeCount * src[1]);
594
 
        i++;
595
 
        fSlopeCount += fRate;
596
 
    }
597
 
    // now always (iSlopeCount > 1.0f)
598
 
    fSlopeCount -= 1.0f;
599
 
 
600
 
    if (numSamples == 1) goto end;
601
 
 
602
 
    while (1)
603
 
    {
604
 
        while (fSlopeCount > 1.0f)
605
 
        {
606
 
            fSlopeCount -= 1.0f;
607
 
            used ++;
608
 
            if (used >= numSamples - 1) goto end;
609
 
        }
610
 
        srcPos = 2 * used;
611
 
 
612
 
        dest[2 * i] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[srcPos]
613
 
            + fSlopeCount * src[srcPos + 2]);
614
 
        dest[2 * i + 1] = (SAMPLETYPE)((1.0f - fSlopeCount) * src[srcPos + 1]
615
 
            + fSlopeCount * src[srcPos + 3]);
616
 
 
617
 
        i++;
618
 
        fSlopeCount += fRate;
619
 
    }
620
 
end:
621
 
    // Store the last sample for the next round
622
 
    sPrevSampleL = src[2 * numSamples - 2];
623
 
    sPrevSampleR = src[2 * numSamples - 1];
624
 
 
625
 
    return i;
626
 
}