Changeset 0da5208
- Timestamp:
- Dec 18, 2018, 1:01:35 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- dbad82c
- Parents:
- 20ce2ad
- Location:
- src/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_sndfile.c
r20ce2ad r0da5208 49 49 uint_t scratch_size; 50 50 smpl_t *scratch_data; 51 int format; 51 52 }; 52 53 53 54 uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s); 55 56 uint_t aubio_str_extension_matches(const char_t *ext, 57 const char_t *pattern); 58 const char_t *aubio_str_get_extension(const char_t *filename); 54 59 55 60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) { … … 67 72 s->samplerate = 0; 68 73 s->channels = 0; 74 75 aubio_sink_sndfile_preset_format(s, aubio_str_get_extension(path)); 69 76 70 77 // zero samplerate given. do not open yet … … 112 119 if (s->samplerate != 0 /* && s->channels != 0 */) { 113 120 return aubio_sink_sndfile_open(s); 121 } 122 return AUBIO_OK; 123 } 124 125 uint_t aubio_sink_sndfile_preset_format(aubio_sink_sndfile_t *s, 126 const char_t *fmt) 127 { 128 if (aubio_str_extension_matches(fmt, "wav")) { 129 s->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; 130 } else if (aubio_str_extension_matches(fmt, "aiff")) { 131 s->format = SF_FORMAT_AIFF | SF_FORMAT_PCM_16; 132 } else if (aubio_str_extension_matches(fmt, "flac")) { 133 s->format = SF_FORMAT_FLAC | SF_FORMAT_PCM_16; 134 } else if (aubio_str_extension_matches(fmt, "ogg")) { 135 s->format = SF_FORMAT_OGG | SF_FORMAT_VORBIS; 136 } else if (atoi(fmt) > 0x010000) { 137 s->format = atoi(fmt); 138 } else { 139 AUBIO_WRN("sink_sndfile: could not guess format for %s," 140 " using default (wav)\n", s->path); 141 s->format = SF_FORMAT_WAV | SF_FORMAT_PCM_16; 142 return AUBIO_FAIL; 114 143 } 115 144 return AUBIO_OK; … … 132 161 sfinfo.samplerate = s->samplerate; 133 162 sfinfo.channels = s->channels; 134 sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;163 sfinfo.format = s->format; 135 164 136 165 /* try creating the file */ -
src/io/sink_sndfile.h
r20ce2ad r0da5208 96 96 /** 97 97 98 preset sink format 99 100 \param s sink, created with ::new_aubio_sink_sndfile 101 \param fmt format of the file to create 102 103 \return 0 on success, 1 on error 104 105 Preset the format of the sink. Supported format strings: 106 - "wav": 16 bit (default) 107 - "aiff": aiff, 16 bit 108 - "flac": flac, 16 bit 109 - "ogg": ogg vorbis stream 110 111 Alternatively, any sndfile format can be set by passing the corresponding 112 integer as a string: 113 114 \code{.c} 115 char_t fmt[10]; 116 snprintf(fmt, sizeof(fmt), "%d", SF_FORMAT_FLAC | SF_FORMAT_PCM_24); 117 aubio_sink_sndfile_preset_format(s, fmt); 118 \endcode 119 120 The file should have been created using a samplerate of 0. 121 122 This function should be called before aubio_sink_sndfile_preset_samplerate() 123 and aubio_sink_sndfile_preset_channels(). 124 125 */ 126 uint_t aubio_sink_sndfile_preset_format(aubio_sink_sndfile_t *s, 127 const char_t* fmt); 128 129 /** 130 98 131 get samplerate of sink object 99 132
Note: See TracChangeset
for help on using the changeset viewer.