]> git.sesse.net Git - nageru/blobdiff - resampling_queue.h
Write 1.4.0 changelog.
[nageru] / resampling_queue.h
index c085eceb6755838ea12001cf6aa6d39a6f21e1d5..8462152e0fe91bee15bc24474db7e18254b9f5f2 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <stdint.h>
-#include <stdlib.h>
 #include <sys/types.h>
 #include <zita-resampler/vresampler.h>
 #include <deque>
 #include <memory>
 
+#include "defs.h"
+
 class ResamplingQueue {
 public:
-       ResamplingQueue(unsigned freq_in, unsigned freq_out, unsigned num_channels = 2);
+       // card_num is for debugging outputs only.
+       ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels = 2);
+
+       // If policy is DO_NOT_ADJUST_RATE, the resampling rate will not be changed.
+       // This is primarily useful if you have an extraordinary situation, such as
+       // dropped frames.
+       enum RateAdjustmentPolicy {
+               DO_NOT_ADJUST_RATE,
+               ADJUST_RATE
+       };
 
        // Note: pts is always in seconds.
        void add_input_samples(double pts, const float *samples, ssize_t num_samples);
-       bool get_output_samples(double pts, float *samples, ssize_t num_samples);  // Returns false if underrun.
+       // Returns false if underrun.
+       bool get_output_samples(double pts, float *samples, ssize_t num_samples, RateAdjustmentPolicy rate_adjustment_policy);
 
 private:
        void init_loop_filter(double bandwidth_hz);
 
        VResampler vresampler;
 
+       unsigned card_num;
        unsigned freq_in, freq_out, num_channels;
 
        bool first_input = true, first_output = true;
@@ -81,7 +92,7 @@ private:
        // How much delay we are expected to have, in input samples.
        // If actual delay drifts too much away from this, we will start
        // changing the resampling ratio to compensate.
-       double expected_delay = 4800.0;
+       double expected_delay = OUTPUT_FREQUENCY * 0.1;  // 100 ms.
 
        // Input samples not yet fed into the resampler.
        // TODO: Use a circular buffer instead, for efficiency.