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