- Timestamp:
- Jul 16, 2012, 2:55:13 AM (12 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 7839c61
- Parents:
- e3b5962
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_sndfile.c
re3b5962 r87dfc3f 30 30 #include "fvec.h" 31 31 32 #include "temporal/resampler.h" 33 32 34 #define MAX_CHANNELS 6 33 35 #define MAX_SIZE 4096 … … 44 46 uint_t scratch_size; 45 47 smpl_t *scratch_data; 48 49 smpl_t ratio; 50 51 #ifdef HAVE_SAMPLERATE 52 aubio_resampler_t *resampler; 53 fvec_t *resampled_data; 54 #endif /* HAVE_SAMPLERATE */ 46 55 }; 47 56 … … 70 79 } 71 80 72 if (sfinfo.channels > MAX_CHANNELS) { 81 if (sfinfo.channels > MAX_CHANNELS) { 73 82 AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS); 74 83 return NULL; … … 80 89 s->input_format = sfinfo.format; 81 90 82 if (s->samplerate != s->input_samplerate) { 83 AUBIO_ERR("resampling not implemented yet\n"); 91 s->ratio = s->samplerate/(float)s->input_samplerate; 92 93 if (s->ratio != 1) { 94 #ifdef HAVE_SAMPLERATE 95 s->resampler = new_aubio_resampler(s->ratio, 0); 96 s->resampled_data = new_fvec(s->hop_size / s->ratio); 97 if (s-> ratio > 1) { 98 AUBIO_WRN("upsampling from %d to % d\n", s->input_samplerate, s->samplerate); 99 } 100 #else 101 AUBIO_ERR("can not read %s at samplerate %dHz\n", s->path, s->samplerate); 102 AUBIO_ERR("aubio was compiled without aubio_resampler\n"); 84 103 return NULL; 104 #endif /* HAVE_SAMPLERATE */ 85 105 } 86 87 s->scratch_size = s->hop_size *s->input_channels;106 107 s->scratch_size = s->hop_size * s->input_channels / s->ratio; 88 108 /* allocate data for de/interleaving reallocated when needed. */ 89 109 if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) { … … 104 124 read_frames = sf_read_float (s->handle, s->scratch_data, s->scratch_size); 105 125 106 aread = (int)FLOOR(read_frames/(float)input_channels); 126 smpl_t *data; 127 128 #ifdef HAVE_SAMPLERATE 129 if (s->resampler) { 130 data = s->resampled_data->data; 131 } else 132 #endif /* HAVE_SAMPLERATE */ 133 { 134 data = read_data->data; 135 } 136 aread = (int)FLOOR(s->ratio * read_frames / (float)input_channels + .5); 107 137 108 138 /* de-interleaving and down-mixing data */ 109 for (j = 0; j < aread; j++) {110 read_data->data[j] = 0;139 for (j = 0; j < read_frames; j++) { 140 data[j] = 0; 111 141 for (i = 0; i < input_channels; i++) { 112 read_data->data[j] += (smpl_t)s->scratch_data[input_channels*j+i];142 data[j] += (smpl_t)s->scratch_data[input_channels*j+i]; 113 143 } 114 read_data->data[j] /= (smpl_t)input_channels;144 data[j] /= (smpl_t)input_channels; 115 145 } 146 147 #ifdef HAVE_SAMPLERATE 148 if (s->resampler) { 149 aubio_resampler_do(s->resampler, s->resampled_data, read_data); 150 data = s->resampled_data->data; 151 } 152 #endif /* HAVE_SAMPLERATE */ 153 116 154 *read = aread; 117 155 } … … 122 160 AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL)); 123 161 } 162 #ifdef HAVE_SAMPLERATE 163 if (s->resampler) { 164 del_aubio_resampler(s->resampler); 165 } 166 if (s->resampled_data) { 167 del_fvec(s->resampled_data); 168 } 169 #endif /* HAVE_SAMPLERATE */ 124 170 AUBIO_FREE(s->scratch_data); 125 171 AUBIO_FREE(s);
Note: See TracChangeset
for help on using the changeset viewer.