1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rubber Band Library
5     An audio time-stretching and pitch-shifting library.
6     Copyright 2007-2021 Particular Programs Ltd.
7 
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 
14     Alternatively, if you have a valid commercial licence for the
15     Rubber Band Library obtained by agreement with the copyright
16     holders, you may redistribute and/or modify it under the terms
17     described in that licence.
18 
19     If you wish to distribute code using the Rubber Band Library
20     under terms other than those of the GNU General Public License,
21     you must obtain a valid commercial licence before doing so.
22 */
23 
24 #include "AudioCurveCalculator.h"
25 
26 #include <iostream>
27 
28 namespace RubberBand
29 {
30 
31 static const int MaxPerceivedFreq = 16000;
32 
AudioCurveCalculator(Parameters parameters)33 AudioCurveCalculator::AudioCurveCalculator(Parameters parameters) :
34     m_sampleRate(parameters.sampleRate),
35     m_fftSize(parameters.fftSize)
36 {
37     recalculateLastPerceivedBin();
38 }
39 
~AudioCurveCalculator()40 AudioCurveCalculator::~AudioCurveCalculator()
41 {
42 }
43 
44 void
setSampleRate(int newRate)45 AudioCurveCalculator::setSampleRate(int newRate)
46 {
47     m_sampleRate = newRate;
48     recalculateLastPerceivedBin();
49 }
50 
51 void
setFftSize(int newSize)52 AudioCurveCalculator::setFftSize(int newSize)
53 {
54     m_fftSize = newSize;
55     recalculateLastPerceivedBin();
56 }
57 
58 void
recalculateLastPerceivedBin()59 AudioCurveCalculator::recalculateLastPerceivedBin()
60 {
61     if (m_sampleRate == 0) {
62         m_lastPerceivedBin = 0;
63         return;
64     }
65     m_lastPerceivedBin = ((MaxPerceivedFreq * m_fftSize) / m_sampleRate);
66     if (m_lastPerceivedBin > m_fftSize/2) {
67         m_lastPerceivedBin = m_fftSize/2;
68     }
69 }
70 
71 
72 }
73