SpectMorph

lib/smaudio.hh

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 #ifndef SPECTMORPH_AUDIO_HH
00019 #define SPECTMORPH_AUDIO_HH
00020 
00021 #include <bse/bsecxxplugin.hh>
00022 #include <vector>
00023 
00024 #include "smgenericin.hh"
00025 #include "smgenericout.hh"
00026 
00027 #define SPECTMORPH_BINARY_FILE_VERSION 11
00028 
00029 namespace SpectMorph
00030 {
00031 
00040 class AudioBlock
00041 {
00042 public:
00043   std::vector<float> noise;          
00044   std::vector<float> freqs;          
00045   std::vector<float> mags;           
00046   std::vector<float> phases;         
00047   std::vector<float> lpc_lsf_p;      
00048   std::vector<float> lpc_lsf_q;      
00049   std::vector<float> original_fft;   
00050   std::vector<float> debug_samples;  
00051 };
00052 
00053 enum AudioLoadOptions
00054 {
00055   AUDIO_LOAD_DEBUG,
00056   AUDIO_SKIP_DEBUG
00057 };
00058 
00066 class Audio
00067 {
00068   BIRNET_PRIVATE_CLASS_COPY (Audio);
00069 public:
00070   Audio();
00071   ~Audio();
00072 
00073   enum LoopType {
00074     LOOP_NONE = 0,
00075     LOOP_FRAME_FORWARD,
00076     LOOP_FRAME_PING_PONG,
00077     LOOP_TIME_FORWARD,
00078     LOOP_TIME_PING_PONG,
00079   };
00080 
00081   float    fundamental_freq;            
00082   float    mix_freq;                    
00083   float    frame_size_ms;               
00084   float    frame_step_ms;               
00085   float    attack_start_ms;             
00086   float    attack_end_ms;               
00087   float    start_ms;                    
00088   int      zeropad;                     
00089   LoopType loop_type;                   
00090   int      loop_start;                  
00091   int      loop_end;                    
00092   int      zero_values_at_start;        
00093   int      sample_count;                
00094   std::vector<float> original_samples;  
00095   std::vector<AudioBlock> contents;     
00096 
00097   BseErrorType load (const std::string& filename, AudioLoadOptions load_options = AUDIO_LOAD_DEBUG);
00098   BseErrorType load (SpectMorph::GenericIn *file, AudioLoadOptions load_options = AUDIO_LOAD_DEBUG);
00099   BseErrorType save (const std::string& filename) const;
00100   BseErrorType save (SpectMorph::GenericOut *file) const;
00101 
00102   Audio *clone() const; // create a deep copy
00103 
00104   static bool loop_type_to_string (LoopType loop_type, std::string& s);
00105   static bool string_to_loop_type (const std::string& s, LoopType& loop_type);
00106 };
00107 
00108 }
00109 
00110 #endif
 All Classes Functions Variables Enumerations Enumerator