SpectMorph
smaudio.hh
1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_AUDIO_HH
4 #define SPECTMORPH_AUDIO_HH
5 
6 #include <bse/bsecxxplugin.hh>
7 #include <vector>
8 
9 #include "smgenericin.hh"
10 #include "smgenericout.hh"
11 #include "smmath.hh"
12 
13 #define SPECTMORPH_BINARY_FILE_VERSION 13
14 
15 namespace SpectMorph
16 {
17 
27 {
28 public:
29  std::vector<uint16_t> noise;
30  std::vector<uint16_t> freqs;
31  std::vector<uint16_t> mags;
32  std::vector<uint16_t> phases;
33  std::vector<float> lpc_lsf_p;
34  std::vector<float> lpc_lsf_q;
35  std::vector<float> original_fft;
36  std::vector<float> debug_samples;
37 
38  void sort_freqs();
39 
40  double
41  freqs_f (size_t i) const
42  {
43  return sm_ifreq2freq (freqs[i]);
44  }
45 
46  double
47  mags_f (size_t i) const
48  {
49  return sm_idb2factor (mags[i]);
50  }
51 
52  double
53  phases_f (size_t i) const
54  {
55  const double factor = 2.0 * M_PI / 65536.0;
56  return phases[i] * factor;
57  }
58 
59  double
60  noise_f (size_t i) const
61  {
62  return sm_idb2factor (noise[i]);
63  }
64 };
65 
66 enum AudioLoadOptions
67 {
68  AUDIO_LOAD_DEBUG,
69  AUDIO_SKIP_DEBUG
70 };
71 
79 class Audio
80 {
81  RAPICORN_CLASS_NON_COPYABLE (Audio);
82 public:
83  Audio();
84  ~Audio();
85 
86  enum LoopType {
87  LOOP_NONE = 0,
88  LOOP_FRAME_FORWARD,
89  LOOP_FRAME_PING_PONG,
90  LOOP_TIME_FORWARD,
91  LOOP_TIME_PING_PONG,
92  };
93 
95  float mix_freq;
96  float frame_size_ms;
97  float frame_step_ms;
99  float attack_end_ms;
100  int zeropad;
101  LoopType loop_type;
103  int loop_end;
106  std::vector<float> original_samples;
108  std::vector<AudioBlock> contents;
109 
110  Bse::Error load (const std::string& filename, AudioLoadOptions load_options = AUDIO_LOAD_DEBUG);
111  Bse::Error load (SpectMorph::GenericIn *file, AudioLoadOptions load_options = AUDIO_LOAD_DEBUG);
112  Bse::Error save (const std::string& filename) const;
113  Bse::Error save (SpectMorph::GenericOut *file) const;
114 
115  Audio *clone() const; // create a deep copy
116 
117  static bool loop_type_to_string (LoopType loop_type, std::string& s);
118  static bool string_to_loop_type (const std::string& s, LoopType& loop_type);
119 };
120 
121 }
122 
123 #endif
std::vector< float > lpc_lsf_p
LPC line spectrum frequencies, P(z) roots.
Definition: smaudio.hh:33
LoopType loop_type
type of loop to be used during sustain phase of playback
Definition: smaudio.hh:101
std::vector< float > original_samples
original time domain signal as samples (debugging only)
Definition: smaudio.hh:106
Generic Input Stream.
Definition: smgenericin.hh:17
float attack_end_ms
end of attack in milliseconds
Definition: smaudio.hh:99
Audio sample containing many blocks.
Definition: smaudio.hh:79
float mix_freq
mix freq (sampling rate) of the original audio data
Definition: smaudio.hh:95
float original_samples_norm_db
normalization factor to be applied to original samples
Definition: smaudio.hh:107
float frame_step_ms
stepping of the audio frames in milliseconds
Definition: smaudio.hh:97
std::vector< float > original_fft
original zeropadded FFT data - for debugging only
Definition: smaudio.hh:35
std::vector< float > lpc_lsf_q
LPC line spectrum frequencies, Q(z) roots.
Definition: smaudio.hh:34
Block of audio data, encoded in SpectMorph parametric format.
Definition: smaudio.hh:26
float fundamental_freq
fundamental frequency (note which was encoded), or 0 if not available
Definition: smaudio.hh:94
std::vector< uint16_t > noise
noise envelope, representing the original signal minus sine components
Definition: smaudio.hh:29
std::vector< uint16_t > freqs
frequencies of the sine components of this frame
Definition: smaudio.hh:30
float attack_start_ms
start of attack in milliseconds
Definition: smaudio.hh:98
std::vector< AudioBlock > contents
the actual frame data
Definition: smaudio.hh:108
std::vector< uint16_t > phases
phases of the sine components
Definition: smaudio.hh:32
Definition: smaudio.hh:15
int loop_start
loop point to be used during sustain phase of playback
Definition: smaudio.hh:102
std::vector< uint16_t > mags
magnitudes of the sine components
Definition: smaudio.hh:31
int loop_end
loop point to be used during sustain phase of playback
Definition: smaudio.hh:103
Generic Output Stream.
Definition: smgenericout.hh:17
std::vector< float > debug_samples
original audio samples for this frame - for debugging only
Definition: smaudio.hh:36
int zero_values_at_start
number of zero values added by encoder (strip during decoding)
Definition: smaudio.hh:104
int sample_count
number of samples encoded (including zero_values_at_start)
Definition: smaudio.hh:105
int zeropad
FFT zeropadding used during analysis.
Definition: smaudio.hh:100
float frame_size_ms
length of each audio frame in milliseconds
Definition: smaudio.hh:96