Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c27730025e
Fetching contributors…

Cannot retrieve contributors at this time

file 80 lines (65 sloc) 2.709 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
// -*- c++ -*-
// Folve - A fuse filesystem that convolves audio files on-the-fly.
//
// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef FOLVE_SOUND_PROCESSOR_H
#define FOLVE_SOUND_PROCESSOR_H

#include <sndfile.h>

#include <string>

#include "zita-config.h"

// The workhorse of processing data from soundfiles.
class SoundProcessor {
public:
  static SoundProcessor *Create(const std::string &config_file,
                                int samplerate, int channels);
  ~SoundProcessor();

  // Fill Buffer from given sound file. Returns number of samples read.
  int FillBuffer(SNDFILE *in);

  // Returns if the input buffer has enought samples for the FIR-filter
  // to process. If not, another call to FillBuffer() is needed.
  bool is_input_buffer_complete() const {
    return zita_config_.fragm == input_pos_;
  }

  // Number of samples that are pending. Typically once we have this passed
  // over to a new file.
  int pending_writes() const {
    return output_pos_ >= 0 ? zita_config_.fragm - output_pos_ : 0;
  }

  // Write number of processed samples out to given soundfile. Processes
  // the data first if necessary. assert(), that there is at least 1 sample
  // to process.
  void WriteProcessed(SNDFILE *out, int sample_count);

  // Reset procesor for re-use
  void Reset();

  // Maximum absolute output value observe (>= 0.0).
  float max_output_value() const { return max_out_value_observed_; }
  void ResetMaxValues();

  // Config file used to create this processor.
  const std::string &config_file() const { return config_file_; }

private:
  SoundProcessor(const ZitaConfig &config, const std::string &cfg_file);
  void Process();

  const ZitaConfig zita_config_;
  const std::string config_file_;
  float *const buffer_;
  const int channels_;
  // TODO: instead of two positions, better have one position and two states
  // READ, WRITE
  int input_pos_;
  int output_pos_; // written position. -1, if not processed yet.
  float max_out_value_observed_;
};

#endif // FOLVE_SOUND_PROCESSOR_H
Something went wrong with that request. Please try again.