identity sh-f11=cam/sh-f12=proj keyframes, odd jpeg fix, zoom submenu, shudmp
[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.inc"
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, int64_t start, int64_t len);
45
46 // Resample from the file handler and store in *output.
47 // Returns 1 if the input reader failed.
48         int resample(Samples *samples,
49                 int64_t out_len,
50                 int in_rate,
51                 int out_rate,
52 // Starting sample in output samplerate
53 // If reverse, the end of the buffer.
54                 int64_t out_position,
55                 int direction);
56
57         int get_direction();
58
59         static void reverse_buffer(double *buffer, int64_t len);
60
61 // Reset after seeking
62         void reset();
63
64 private:
65         double blackman(int i, double offset, double fcn, int l);
66 // Query output temp
67         int get_output_size();
68 //      void read_output(Samples *output, int size);
69 // Resamples input and dumps it to output_temp
70         void resample_chunk(Samples *input,
71                 int64_t in_len,
72                 int in_rate,
73                 int out_rate);
74         int read_chunk(Samples *input,
75                 int64_t len);
76
77 // History buffer for resampling.
78         double *old;
79         double itime;
80
81
82
83 // Unaligned resampled output
84         double *output_temp;
85
86
87 // Total samples in unaligned output
88         int64_t output_size;
89
90         int direction;
91 // Allocation of unaligned output
92         int64_t output_allocation;
93 // input chunk
94         Samples *input;
95 // Position of source in source sample rate.
96         int64_t input_position;
97         int64_t input_size;
98         int64_t output_position;
99         int resample_init;
100 // Last sample ratio configured to
101         double last_ratio;
102         double blackfilt[2 * BPC + 1][BLACKSIZE];
103 };
104
105 #endif