OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Scale volume with slew rate limiting | 5 // Scale volume with slew rate limiting |
6 | 6 |
7 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ | 7 #ifndef CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ |
8 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ | 8 #define CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 | 13 |
14 namespace chromecast { | 14 namespace chromecast { |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 class SlewVolume { | 17 class SlewVolume { |
18 public: | 18 public: |
19 SlewVolume(); | 19 SlewVolume(); |
20 SlewVolume(int max_slew_up_ms, int max_slew_down_ms); | 20 SlewVolume(int max_slew_up_ms, int max_slew_down_ms); |
21 ~SlewVolume() = default; | 21 ~SlewVolume() = default; |
22 | 22 |
23 void SetSampleRate(int sample_rate); | 23 void SetSampleRate(int sample_rate); |
24 void SetVolume(double volume_scale); | 24 void SetVolume(double volume_scale); |
25 | 25 |
| 26 // Called to indicate that the stream was interrupted; volume changes can be |
| 27 // applied immediately. |
| 28 void Interrupted(); |
| 29 |
26 // Assumes 1 channel float data that is 16-byte aligned. Smoothly calculates | 30 // Assumes 1 channel float data that is 16-byte aligned. Smoothly calculates |
27 // dest[i] += src[i] * volume_scaling | 31 // dest[i] += src[i] * volume_scaling |
28 // ProcessFMAC will be called once for each channel of audio present and | 32 // ProcessFMAC will be called once for each channel of audio present and |
29 // |repeat_transition| will be true for channels 2 through n. | 33 // |repeat_transition| will be true for channels 2 through n. |
30 void ProcessFMAC(bool repeat_transition, | 34 void ProcessFMAC(bool repeat_transition, |
31 const float* src, | 35 const float* src, |
32 int frames, | 36 int frames, |
33 float* dest); | 37 float* dest); |
34 | 38 |
35 // Assumes 2 channels. | 39 // Assumes 2 channels. |
36 bool ProcessInterleaved(int32_t* data, int frames); | 40 bool ProcessInterleaved(int32_t* data, int frames); |
37 | 41 |
38 private: | 42 private: |
39 double sample_rate_; | 43 double sample_rate_; |
40 double volume_scale_ = 1.0; | 44 double volume_scale_ = 1.0; |
41 double current_volume_ = 1.0; | 45 double current_volume_ = 1.0; |
42 double last_starting_volume_ = 1.0; | 46 double last_starting_volume_ = 1.0; |
43 int max_slew_time_up_ms_; | 47 int max_slew_time_up_ms_; |
44 int max_slew_time_down_ms_; | 48 int max_slew_time_down_ms_; |
45 double max_slew_up_; | 49 double max_slew_up_; |
46 double max_slew_down_; | 50 double max_slew_down_; |
| 51 bool interrupted_ = true; |
47 | 52 |
48 DISALLOW_COPY_AND_ASSIGN(SlewVolume); | 53 DISALLOW_COPY_AND_ASSIGN(SlewVolume); |
49 }; | 54 }; |
50 | 55 |
51 } // namespace media | 56 } // namespace media |
52 } // namespace chromecast | 57 } // namespace chromecast |
53 | 58 |
54 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ | 59 #endif // CHROMECAST_MEDIA_CMA_BACKEND_ALSA_SLEW_VOLUME_H_ |
OLD | NEW |