aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/mt32/SampleRateConverter.h
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2017-02-27 12:32:06 +0100
committerWillem Jan Palenstijn2017-02-28 18:40:04 +0100
commit867511d2d0a5d063e37b07115b8b98f5930d415b (patch)
tree2fd96da5f26b8320b8c3524a2acb20f37c59e61c /audio/softsynth/mt32/SampleRateConverter.h
parente2a72393d298a5c338e55b73ae910c9ef4e1b45e (diff)
downloadscummvm-rg350-867511d2d0a5d063e37b07115b8b98f5930d415b.tar.gz
scummvm-rg350-867511d2d0a5d063e37b07115b8b98f5930d415b.tar.bz2
scummvm-rg350-867511d2d0a5d063e37b07115b8b98f5930d415b.zip
MT32: Update Munt to 2.0.3
This update uses upstream commit 777c51cdb4dbb4e02a53c23edea9086f0b600e26. The new SampleRateConverter is added, but not built as we don't use it. Also, building it without source changes will need additional include directories. This update of Munt reduces the stack size, and thus fixes bug #9630.
Diffstat (limited to 'audio/softsynth/mt32/SampleRateConverter.h')
-rw-r--r--audio/softsynth/mt32/SampleRateConverter.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/audio/softsynth/mt32/SampleRateConverter.h b/audio/softsynth/mt32/SampleRateConverter.h
new file mode 100644
index 0000000000..24bce0891b
--- /dev/null
+++ b/audio/softsynth/mt32/SampleRateConverter.h
@@ -0,0 +1,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