1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/* Copyright (C) 2015-2017 Sergey V. Mikayev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SAMPLE_RATE_CONVERTER_H
#define SAMPLE_RATE_CONVERTER_H
#include "globals.h"
#include "Types.h"
#include "Enumerations.h"
namespace MT32Emu {
class Synth;
/* SampleRateConverter class allows to convert the synthesiser output to any desired sample rate.
* It processes the completely mixed stereo output signal as it passes the analogue circuit emulation,
* so emulating the synthesiser output signal passing further through an ADC.
* Several conversion quality options are provided which allow to trade-off the conversion speed vs. the passband width.
* All the options except FASTEST guarantee full suppression of the aliasing noise in terms of the 16-bit integer samples.
*/
class MT32EMU_EXPORT SampleRateConverter {
public:
enum Quality {
// Use this only when the speed is more important than the audio quality.
FASTEST,
FAST,
GOOD,
BEST
};
// Returns the value of AnalogOutputMode for which the output signal may retain its full frequency spectrum
// at the sample rate specified by the targetSampleRate argument.
static AnalogOutputMode getBestAnalogOutputMode(double targetSampleRate);
// Creates a SampleRateConverter instance that converts output signal from the synth to the given sample rate
// with the specified conversion quality.
SampleRateConverter(Synth &synth, double targetSampleRate, Quality quality);
~SampleRateConverter();
// Fills the provided output buffer with the results of the sample rate conversion.
// The input samples are automatically retrieved from the synth as necessary.
void getOutputSamples(MT32Emu::Bit16s *buffer, unsigned int length);
// Fills the provided output buffer with the results of the sample rate conversion.
// The input samples are automatically retrieved from the synth as necessary.
void getOutputSamples(float *buffer, unsigned int length);
// Returns the number of samples produced at the internal synth sample rate (32000 Hz)
// that correspond to the number of samples at the target sample rate.
// Intended to facilitate audio time synchronisation.
double convertOutputToSynthTimestamp(double outputTimestamp) const;
// Returns the number of samples produced at the target sample rate
// that correspond to the number of samples at the internal synth sample rate (32000 Hz).
// Intended to facilitate audio time synchronisation.
double convertSynthToOutputTimestamp(double synthTimestamp) const;
private:
const double synthInternalToTargetSampleRateRatio;
void * const srcDelegate;
}; // class SampleRateConverter
} // namespace MT32Emu
#endif // SAMPLE_RATE_CONVERTER_H
|