82 int free_when_destroyed)
132 cerr <<
"Attempt to access sample " << i <<
" of a " <<
num_samples() <<
" sample wave.\n";
139 cerr <<
"Attempt to access channel " << channel <<
" of a " <<
num_channels() <<
" channel wave.\n";
149 return ((
EST_Wave *)
this)->a(i,channel);
154 static short out_of_bound_value = 0;
159 out_of_bound_value = 0;
160 return out_of_bound_value;
187 if ((ts.
open(filename)) == -1)
189 cerr <<
"Wave load: can't open file \"" << filename <<
"\"" << endl;
193 stat =
load(ts,offset,length,rate);
214 if (! info->recognise)
222 if (ts.
seek(pos) != 0) {
226 stat = (*l_fun)(ts, *
this,
252 else if ((ts.
open(filename)) == -1)
254 cerr <<
"Wave load: can't open file \"" << filename <<
"\"" << endl;
258 stat =
load(ts,type,offset,length,rate);
272 cerr <<
"Unknown Wave file type " << type << endl;
280 cerr <<
"Can't load waves to files type " << type << endl;
285 return (*l_fun)(ts, *
this,
301 else if ((ts.
open(filename)) == -1)
303 cerr <<
"Wave load: can't open file \"" << filename <<
"\"" << endl;
307 stat =
load_file(ts,type,sample_rate,stype,bov,nc,offset,length);
324 cerr <<
"Unknown Wave file type " << type << endl;
332 cerr <<
"Can't load waves to files type " << type << endl;
336 return (*l_fun)(ts, *
this,
362 else if ((fp = fopen(filename,
"wb")) ==
NULL)
364 cerr <<
"Wave save: can't open output file \"" <<
365 filename <<
"\"" << endl;
377 EST_String save_type = (type ==
"") ? DEF_FILE_TYPE : type;
383 cerr <<
"Wave: unknown filetype in saving " << save_type << endl;
391 cerr <<
"Can't save waves to files type " << save_type << endl;
406 else if ((fp = fopen(filename, mode)) ==
NULL)
408 cerr <<
"Wave save: can't open output file \"" <<
409 filename <<
"\"" << endl;
428 cerr <<
"Unknown Wave file type " << ftype << endl;
436 cerr <<
"Can't save waves to files type " << ftype << endl;
452 cerr <<
"Unknown Wave file type " << ftype << endl;
460 cerr <<
"Can't save wave data to files type " << ftype << endl;
477 cerr <<
"Unknown Wave file type " << ftype << endl;
485 cerr <<
"Can't save wave header to files type " << ftype << endl;
498 cerr <<
"rateconv: failed to convert from " <<
p_sample_rate <<
499 " to " << new_freq <<
"\n";
519 if (fabs(max/32766.0-gain) < 0.001) {
523 factor *= 32766.0/(float)max;
534 else if (factor == -1.0)
540 ns = (
int)(nsf - 0.5);
542 ns = (
int)(nsf + 0.5);
556 ssize_t start_sample, end_sample;
557 float target1, target2, increment, factor, nsf;
565 EST_error(
"Factor contour track exceeds waveform length (%d samples)",
569 target1 = fc.
a(static_cast<ssize_t>(0),0);
571 for (
ssize_t k = 1; k<fc_length; ++k ){
575 increment = (target2-target1)/(end_sample-start_sample+1);
578 for(
ssize_t i=start_sample; i<end_sample; ++i, factor+=increment )
579 for(
ssize_t j=0; j<_num_channels; ++j ){
582 else if (factor == -1.0)
588 ns = (
int)(nsf - 0.5);
590 ns = (
int)(nsf + 0.5);
599 start_sample = end_sample;
619 cerr <<
"Cannot concatenate waveforms with differing numbers of channels\n";
647 resize(r_samples, r_channels);
651 a(i,k+o_channels) += w.
a(i, k);
659 p_values << sig(i) <<
"\n";
665 { (void)a; (void)b;
return 1; }
667 { (void)a; (void)b;
return 0; }
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
EST_Wave & operator+=(const EST_Wave &a)
void copy_setup(const EST_Wave &w)
void set_sample_rate(const int n)
Set sampling rate to n
EST_write_status save_file_data(FILE *fp, EST_String ftype, EST_String stype, int obo)
void copy_features(const EST_Featured &f)
The file was read in successfully.
ssize_t length() const
return number of frames in track
EST_TMatrix & add_rows(const EST_TMatrix &s)
The two versions of what might have been operator +=.
ssize_t length() const
return the size of the waveform, i.e. the number of samples.
void close(void)
Close stream.
EST_TNamedEnum< EST_sample_type_t > EST_sample_type_map
void copy(const EST_Wave &from)
void set_file_type(const EST_String t)
EST_FilePos tell(void) const
tell, synonym for filepos
EST_read_status Load_TokenStream(LoadWave_TokenStreamArgs)
ssize_t num_samples() const
return the number of samples in the waveform
void rescale(float gain, int normalize=0)
short & a(ssize_t i, ssize_t channel=0)
EST_write_status save(const EST_String filename, const EST_String EST_filetype="")
void channel(EST_TVector< short > &cv, ssize_t n)
void sub_wave(EST_Wave &sw, int offset=0, ssize_t num=EST_ALL, ssize_t start_c=0, ssize_t nchan=EST_ALL)
EST_Wave()
default constructor
EST_Wave & operator=(const EST_Wave &w)
Assignment operator.
short & a_safe(ssize_t i, ssize_t channel=0)
static const int default_sample_rate
ENUM token(VAL value) const
int open(const EST_String &filename)
open a EST_TokenStream for a file.
float max(float a, float b)
const EST_String DEF_SAMPLE_TYPE
An error occurred while reading.
EST_write_status save_file(const EST_String filename, EST_String filetype, EST_String sample_type, int bo, const char *mode="wb")
void fill(const T &v)
fill matrix with value v
float & t(ssize_t i=0)
return time position of frame i
float & a(ssize_t i, int c=0)
EST_read_status load_file(const EST_String filename, const EST_String filetype, int sample_rate, const EST_String sample_type, int bo, ssize_t nc, int offset=0, ssize_t length=0)
void default_vals(ssize_t n=0, ssize_t c=1)
const EST_SMatrix & values() const
void copy(const EST_TSimpleMatrix< T > &a)
copy one matrix into another
EST_write_status Save_TokenStream(SaveWave_TokenStreamArgs)
const EST_String DEF_FILE_TYPE
Save_TokenStream * save_data
INLINE short & a_no_check(ssize_t i, ssize_t channel=0)
void sub_matrix(EST_TMatrix< T > &sm, ssize_t r=0, ptrdiff_t numr=EST_ALL, ssize_t c=0, ptrdiff_t numc=EST_ALL)
Make the matrix sm a window into this matrix.
friend ostream & operator<<(ostream &p_values, const EST_Wave &sig)
print waveform
The file was not written successfully.
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
int sample_rate() const
return the sampling rate (frequency)
INFO & info(ENUM token) const
void set_memory(T *buffer, ptrdiff_t offset, ssize_t rows, ssize_t columns, int free_when_destroyed=0)
EST_write_status save_file_header(FILE *fp, EST_String ftype, EST_String stype, int obo)
float t(ssize_t i) const
return the time position in seconds of the ith sample
ssize_t num_channels() const
return the number of channels in the waveform
int operator!=(EST_Wave a, EST_Wave b)
INLINE const T & a_no_check(ssize_t row, ssize_t col) const
const access with no bounds check, care recommend
void resize(int rows, int cols, int set=1)
resize matrix
EST_Wave & operator|=(const EST_Wave &a)
int operator==(EST_Wave a, EST_Wave b)
void resample(int rate)
Resample waveform to rate
Save_TokenStream * save_header
void copy_data(const EST_Wave &w)
EST_String sample_type() const
int seek(int position)
seek, reposition file pointer
int rateconv(int old_sr, int new_sr)
void fill(short v=0, ssize_t channel=EST_ALL)
EST_read_status load(const EST_String filename, int offset=0, ssize_t length=0, int rate=default_sample_rate)
static EST_TNamedEnumI< EST_WaveFileType, Info > map