Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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