SpectMorph
|
00001 /* 00002 * Copyright (C) 2010 Stefan Westerfeld 00003 * 00004 * This library is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License as published by the 00006 * Free Software Foundation; either version 3 of the License, or (at your 00007 * option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00012 * for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 00019 #ifndef SPECTMORPH_LIVEDECODER_HH 00020 #define SPECTMORPH_LIVEDECODER_HH 00021 00022 #include "smwavset.hh" 00023 #include "smsinedecoder.hh" 00024 #include "smnoisedecoder.hh" 00025 #include "smlivedecodersource.hh" 00026 #include "smpolyphaseinter.hh" 00027 #include <birnet/birnet.hh> 00028 #include <vector> 00029 00030 namespace SpectMorph { 00031 00032 class LiveDecoder 00033 { 00034 struct PartialState 00035 { 00036 float freq; 00037 float phase; 00038 }; 00039 std::vector<PartialState> pstate[2], *last_pstate; 00040 00041 WavSet *smset; 00042 Audio *audio; 00043 00044 IFFTSynth *ifft_synth; 00045 NoiseDecoder *noise_decoder; 00046 LiveDecoderSource *source; 00047 PolyPhaseInter *pp_inter; 00048 00049 bool sines_enabled; 00050 bool noise_enabled; 00051 bool debug_fft_perf_enabled; 00052 bool original_samples_enabled; 00053 00054 size_t frame_size, frame_step; 00055 size_t zero_values_at_start_scaled; 00056 size_t loop_start_scaled; 00057 size_t loop_end_scaled; 00058 int loop_point; 00059 float current_freq; 00060 float current_mix_freq; 00061 float latency_ms; 00062 00063 size_t have_samples; 00064 size_t block_size; 00065 size_t pos; 00066 size_t env_pos; 00067 size_t frame_idx; 00068 double original_sample_pos; 00069 00070 size_t latency_zero_samples; 00071 int noise_seed; 00072 00073 Birnet::AlignedArray<float,16> *sse_samples; 00074 public: 00075 LiveDecoder (WavSet *smset); 00076 LiveDecoder (LiveDecoderSource *source); 00077 ~LiveDecoder(); 00078 00079 void enable_noise (bool ne); 00080 void enable_sines (bool se); 00081 void enable_debug_fft_perf (bool dfp); 00082 void enable_original_samples (bool eos); 00083 void set_noise_seed (int seed); 00084 void set_latency_ms (float latency_ms); 00085 00086 void precompute_tables (float mix_freq); 00087 void retrigger (int channel, float freq, int midi_velocity, float mix_freq); 00088 void process (size_t n_values, 00089 const float *freq_in, 00090 const float *freq_mod_in, 00091 float *audio_out); 00092 00093 static size_t compute_loop_frame_index (size_t index, Audio *audio); 00094 // later: bool done(); 00095 }; 00096 00097 } 00098 #endif