| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef _CST_WAVE_H__ |
| 41 |
#define _CST_WAVE_H__ |
| 42 |
|
| 43 |
#include "cst_file.h" |
| 44 |
#include "cst_error.h" |
| 45 |
#include "cst_alloc.h" |
| 46 |
#include "cst_endian.h" |
| 47 |
#include "cst_file.h" |
| 48 |
#include "cst_val.h" |
| 49 |
|
| 50 |
typedef struct cst_wave_struct { |
| 51 |
const char *type; |
| 52 |
int sample_rate; |
| 53 |
int num_samples; |
| 54 |
int num_channels; |
| 55 |
short *samples; |
| 56 |
} cst_wave; |
| 57 |
|
| 58 |
typedef struct cst_wave_header_struct { |
| 59 |
const char *type; |
| 60 |
int hsize; |
| 61 |
int num_bytes; |
| 62 |
int sample_rate; |
| 63 |
int num_samples; |
| 64 |
int num_channels; |
| 65 |
} cst_wave_header; |
| 66 |
|
| 67 |
cst_wave *new_wave(); |
| 68 |
cst_wave *copy_wave(const cst_wave *w); |
| 69 |
void delete_wave(cst_wave *val); |
| 70 |
cst_wave *concat_wave(cst_wave *dest, const cst_wave *src); |
| 71 |
|
| 72 |
#define cst_wave_num_samples(w) (w?w->num_samples:0) |
| 73 |
#define cst_wave_num_channels(w) (w?w->num_channels:0) |
| 74 |
#define cst_wave_sample_rate(w) (w?w->sample_rate:0) |
| 75 |
#define cst_wave_samples(w) (w->samples) |
| 76 |
|
| 77 |
#define cst_wave_set_num_samples(w,s) w->num_samples=s |
| 78 |
#define cst_wave_set_num_channels(w,s) w->num_channels=s |
| 79 |
#define cst_wave_set_sample_rate(w,s) w->sample_rate=s |
| 80 |
|
| 81 |
int cst_wave_save(cst_wave *w, const char *filename, const char *type); |
| 82 |
int cst_wave_save_riff(cst_wave *w, const char *filename); |
| 83 |
int cst_wave_save_raw(cst_wave *w, const char *filename); |
| 84 |
int cst_wave_append_riff(cst_wave *w,const char *filename); |
| 85 |
|
| 86 |
int cst_wave_save_riff_fd(cst_wave *w, cst_file fd); |
| 87 |
int cst_wave_save_raw_fd(cst_wave *w, cst_file fd); |
| 88 |
|
| 89 |
int cst_wave_load(cst_wave *w, const char *filename, const char *type); |
| 90 |
int cst_wave_load_riff(cst_wave *w, const char *filename); |
| 91 |
int cst_wave_load_raw(cst_wave *w, const char *filename, |
| 92 |
const char *bo, int sample_rate); |
| 93 |
|
| 94 |
int cst_wave_load_riff_header(cst_wave_header *header,cst_file fd); |
| 95 |
int cst_wave_load_riff_fd(cst_wave *w, cst_file fd); |
| 96 |
int cst_wave_load_raw_fd (cst_wave *w, cst_file fd, |
| 97 |
const char *bo, int sample_rate); |
| 98 |
|
| 99 |
void cst_wave_resize(cst_wave *w,int samples, int num_channels); |
| 100 |
void cst_wave_resample(cst_wave *w, int sample_rate); |
| 101 |
void cst_wave_rescale(cst_wave *w, int factor); |
| 102 |
|
| 103 |
|
| 104 |
typedef struct cst_rateconv_struct { |
| 105 |
int channels; |
| 106 |
int up, down; |
| 107 |
|
| 108 |
double gain; |
| 109 |
int lag; |
| 110 |
int *sin, *sout, *coep; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
int insize, outsize; |
| 115 |
int incount; |
| 116 |
int len; |
| 117 |
|
| 118 |
|
| 119 |
double fsin, fgk, fgg; |
| 120 |
|
| 121 |
int inbaseidx, inoffset, cycctr, outidx; |
| 122 |
} cst_rateconv; |
| 123 |
|
| 124 |
cst_rateconv * new_rateconv(int up, int down, int channels); |
| 125 |
void delete_rateconv(cst_rateconv *filt); |
| 126 |
int cst_rateconv_in(cst_rateconv *filt, const short *inptr, int max); |
| 127 |
int cst_rateconv_leadout(cst_rateconv *filt); |
| 128 |
int cst_rateconv_out(cst_rateconv *filt, short *outptr, int max); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
#define RIFF_FORMAT_PCM 0x0001 |
| 133 |
#define RIFF_FORMAT_ADPCM 0x0002 |
| 134 |
#define RIFF_FORMAT_MULAW 0x0006 |
| 135 |
#define RIFF_FORMAT_ALAW 0x0007 |
| 136 |
|
| 137 |
|
| 138 |
typedef struct { |
| 139 |
unsigned int magic; |
| 140 |
unsigned int hdr_size; |
| 141 |
int data_size; |
| 142 |
unsigned int encoding; |
| 143 |
unsigned int sample_rate; |
| 144 |
unsigned int channels; |
| 145 |
} snd_header; |
| 146 |
|
| 147 |
#define CST_SND_MAGIC (unsigned int)0x2e736e64 |
| 148 |
#define CST_SND_ULAW 1 |
| 149 |
#define CST_SND_UCHAR 2 |
| 150 |
#define CST_SND_SHORT 3 |
| 151 |
|
| 152 |
|
| 153 |
unsigned char cst_short_to_ulaw(short sample); |
| 154 |
short cst_ulaw_to_short(unsigned char ulawbyte); |
| 155 |
|
| 156 |
CST_VAL_USER_TYPE_DCLS(wave,cst_wave) |
| 157 |
|
| 158 |
#endif |