00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SPECTMORPH_ENCODER_HH
00019 #define SPECTMORPH_ENCODER_HH
00020
00021 #include <sys/types.h>
00022 #include <vector>
00023 #include <string>
00024 #include <bse/gsldatautils.h>
00025
00026 #include "smaudio.hh"
00027
00028 namespace SpectMorph
00029 {
00030
00036 struct EncoderParams
00037 {
00039 float mix_freq;
00040
00042 float frame_step_ms;
00043
00045 float frame_size_ms;
00046
00048 int zeropad;
00049
00051 size_t frame_step;
00052
00054 size_t frame_size;
00055
00057 size_t block_size;
00058
00060 double fundamental_freq;
00061 };
00062
00064 struct Tracksel {
00065 size_t frame;
00066 size_t d;
00067 double freq;
00068 double mag;
00069 double mag2;
00070 double phase;
00071 bool is_harmonic;
00072 Tracksel *prev, *next;
00073 };
00075
00084 class Encoder
00085 {
00086 EncoderParams enc_params;
00087 int loop_start;
00088 int loop_end;
00089
00090 bool check_harmonic (double freq, double& new_freq, double mix_freq);
00091
00092 std::vector< std::vector<Tracksel> > frame_tracksels;
00093
00094 struct Attack
00095 {
00096 double attack_start_ms;
00097 double attack_end_ms;
00098 };
00099 double attack_error (const std::vector< std::vector<double> >& unscaled_signal, const std::vector<float>& window, const Attack& attack, std::vector<double>& out_scale);
00100
00101 public:
00102 std::vector<AudioBlock> audio_blocks;
00103 Attack optimal_attack;
00104 size_t zero_values_at_start;
00105 size_t sample_count;
00106 std::vector<float> original_samples;
00107
00108 Encoder (const EncoderParams& enc_params);
00109
00110
00111 void compute_stft (GslDataHandle *dhandle, int channel, const std::vector<float>& window);
00112 void search_local_maxima();
00113 void link_partials();
00114 void validate_partials();
00115 void optimize_partials (const std::vector<float>& window, int optimization_level);
00116 void spectral_subtract (const std::vector<float>& window);
00117 void approx_noise (const std::vector<float>& window);
00118 void compute_attack_params (const std::vector<float>& window);
00119 void sort_freqs();
00120
00121
00122 void encode (GslDataHandle *dhandle, int channel, const std::vector<float>& window, int optimization_level,
00123 bool attack, bool track_sines);
00124
00125 void set_time_loop (int loop_start, int loop_end);
00126 void save (const std::string& filename, double fundamental_freq);
00127 };
00128
00129 }
00130
00131 #endif