Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (69 sloc) 2.917 kB
2fee1d6 @hzeller o extract sound processor
authored
1 // -*- c++ -*-
4d4d90b @hzeller o More legalese
authored
2 // Folve - A fuse filesystem that convolves audio files on-the-fly.
3 //
2fee1d6 @hzeller o extract sound processor
authored
4 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
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 3 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, see <http://www.gnu.org/licenses/>.
18
19 #ifndef FOLVE_SOUND_PROCESSOR_H
20 #define FOLVE_SOUND_PROCESSOR_H
21
22 #include <string>
950f192 @hzeller o Wire up processor-pool to folve-filesystem.
authored
23 #include <sndfile.h>
2fee1d6 @hzeller o extract sound processor
authored
24
25 #include "zita-config.h"
26
27 // The workhorse of processing data from soundfiles.
28 class SoundProcessor {
29 public:
30 static SoundProcessor *Create(const std::string &config_file,
31 int samplerate, int channels);
32 ~SoundProcessor();
33
34 // Fill Buffer from given sound file. Returns number of samples read.
35 int FillBuffer(SNDFILE *in);
36
37 // Returns if the input buffer has enought samples for the FIR-filter
38 // to process. If not, another call to FillBuffer() is needed.
39 bool is_input_buffer_complete() const {
40 return zita_config_.fragm == input_pos_;
41 }
42
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
43 // Number of samples that are pending. Typically once we have this passed
44 // over to a new file.
45 int pending_writes() const {
46 return output_pos_ >= 0 ? zita_config_.fragm - output_pos_ : 0;
47 }
48
2fee1d6 @hzeller o extract sound processor
authored
49 // Write number of processed samples out to given soundfile. Processes
50 // the data first if necessary. assert(), that there is at least 1 sample
51 // to process.
52 void WriteProcessed(SNDFILE *out, int sample_count);
53
54 // Reset procesor for re-use
55 void Reset();
56
57 // Maximum absolute output value observe (>= 0.0).
58 float max_output_value() const { return max_out_value_observed_; }
fb3fb9a @hzeller o Log clipping even if we pass on the processor.
authored
59 void ResetMaxValues();
2fee1d6 @hzeller o extract sound processor
authored
60
9af16fe @hzeller o Gapless string should break when configuration changes.
authored
61 // Config file used to create this processor.
62 const std::string &config_file() const { return config_file_; }
6dcf2e4 @hzeller o processor pool. Work in progress.
authored
63 const time_t config_file_timestamp() const { return config_file_timestamp_; }
9af16fe @hzeller o Gapless string should break when configuration changes.
authored
64
950f192 @hzeller o Wire up processor-pool to folve-filesystem.
authored
65 // Verifies if configuration is still up-to-date.
66 bool ConfigStillUpToDate() const;
67
2fee1d6 @hzeller o extract sound processor
authored
68 private:
9af16fe @hzeller o Gapless string should break when configuration changes.
authored
69 SoundProcessor(const ZitaConfig &config, const std::string &cfg_file);
2fee1d6 @hzeller o extract sound processor
authored
70 void Process();
71
72 const ZitaConfig zita_config_;
9af16fe @hzeller o Gapless string should break when configuration changes.
authored
73 const std::string config_file_;
950f192 @hzeller o Wire up processor-pool to folve-filesystem.
authored
74 const time_t config_file_timestamp_;
6dcf2e4 @hzeller o processor pool. Work in progress.
authored
75
2fee1d6 @hzeller o extract sound processor
authored
76 float *const buffer_;
77 const int channels_;
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
78 // TODO: instead of two positions, better have one position and two states
79 // READ, WRITE
2fee1d6 @hzeller o extract sound processor
authored
80 int input_pos_;
81 int output_pos_; // written position. -1, if not processed yet.
82 float max_out_value_observed_;
83 };
84
85 #endif // FOLVE_SOUND_PROCESSOR_H
Something went wrong with that request. Please try again.