ScummVM API documentation
rate.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AUDIO_RATE_H
23 #define AUDIO_RATE_H
24 
25 #include "common/frac.h"
26 
27 namespace Audio {
36 class AudioStream;
37 
38 typedef int16 st_sample_t;
39 typedef uint16 st_volume_t;
40 typedef uint32 st_size_t;
41 typedef uint32 st_rate_t;
42 
43 /* Minimum and maximum values a sample can hold. */
44 enum {
45  ST_SAMPLE_MAX = 0x7fffL,
46  ST_SAMPLE_MIN = (-ST_SAMPLE_MAX - 1L)
47 };
48 
49 static inline void clampedAdd(int16& a, int b) {
50  int val;
51 #ifdef OUTPUT_UNSIGNED_AUDIO
52  val = (a ^ 0x8000) + b;
53 #else
54  val = a + b;
55 #endif
56 
57  if (val > ST_SAMPLE_MAX)
58  val = ST_SAMPLE_MAX;
59  else if (val < ST_SAMPLE_MIN)
60  val = ST_SAMPLE_MIN;
61 
62 #ifdef OUTPUT_UNSIGNED_AUDIO
63  a = ((int16)val) ^ 0x8000;
64 #else
65  a = val;
66 #endif
67 }
68 
76 public:
77  RateConverter() {}
78  virtual ~RateConverter() {}
79 
91  virtual int convert(AudioStream &input, st_sample_t *outBuffer, st_size_t numSamples, st_volume_t vol_l, st_volume_t vol_r) = 0;
92 
93  virtual void setInputRate(st_rate_t inputRate) = 0;
94  virtual void setOutputRate(st_rate_t outputRate) = 0;
95 
96  virtual st_rate_t getInputRate() const = 0;
97  virtual st_rate_t getOutputRate() const = 0;
98 
104  virtual bool needsDraining() const = 0;
105 };
106 
107 RateConverter *makeRateConverter(st_rate_t inRate, st_rate_t outRate, bool inStereo, bool outStereo, bool reverseStereo);
108 
110 } // End of namespace Audio
111 
112 #endif
Definition: rate.h:75
Definition: audiostream.h:50
virtual bool needsDraining() const =0
virtual int convert(AudioStream &input, st_sample_t *outBuffer, st_size_t numSamples, st_volume_t vol_l, st_volume_t vol_r)=0
Definition: system.h:38