RafaMar + programmer friend Help button in Batch Render addition
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / resample.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22
23 // Generic resampling module
24
25 #ifndef RESAMPLE_H
26 #define RESAMPLE_H
27
28 #define BPC 160
29 #define BLACKSIZE 25
30
31 #include "resample.inc"
32 #include "samples.h"
33 #include <stdint.h>
34
35 class Resample
36 {
37 public:
38         Resample();
39         virtual ~Resample();
40
41 // All positions are in file sample rate
42 // This must reverse the buffer during reverse playback
43 // so the filter always renders forward.
44         virtual int read_samples(Samples *buffer,
45                 int64_t start, int64_t len, int direction);
46
47 // Resample from the file handler and store in *output.
48 // Returns 1 if the input reader failed.
49 // Starting sample in output samplerate
50 // If reverse, the end of the buffer.
51         int resample(Samples *samples,
52                 int64_t out_len, int in_rate, int out_rate,
53                 int64_t out_position, int direction);
54         static void reverse_buffer(double *buffer, int64_t len);
55
56 // Reset after seeking
57         void reset();
58
59 private:
60         void blackman(double fcn, int l);
61         int set_input_position(int64_t in_pos, int in_dir);
62 // Query output temp
63         int get_output_size();
64 //      void read_output(Samples *output, int size);
65 // Resamples input and dumps it to output_temp
66         void resample_chunk(Samples *input, int64_t in_len,
67                         int in_rate, int out_rate);
68
69         int direction;
70 // Unaligned resampled output
71         double *output_temp;
72 // Total samples in unaligned output
73         int64_t output_size;
74 // Allocation of unaligned output
75         int64_t output_allocation;
76 // History buffer for resampling.
77         Samples old;
78 // input chunk
79         Samples *input;
80         double itime;
81 // Position of source in source sample rate.
82         int64_t input_position;
83         int64_t input_size;
84         int64_t output_position;
85         int resample_init;
86 // Last sample ratio configured to
87         double last_ratio;
88         double blackfilt[2 * BPC + 1][BLACKSIZE];
89 };
90
91 #endif