- Timestamp:
- Feb 23, 2014, 5:00:26 PM (11 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:
- f3bb92c
- Parents:
- 870ad70
- Location:
- src/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_sndfile.c
r870ad70 r14ac1db 1 1 /* 2 Copyright (C) 2012 Paul Brossier <piem@aubio.org>2 Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 45 45 }; 46 46 47 uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s); 48 47 49 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) { 48 50 aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t); 49 SF_INFO sfinfo; 51 s->max_size = MAX_SIZE; 52 s->path = path; 50 53 51 54 if (path == NULL) { … … 54 57 } 55 58 59 s->samplerate = 0; 60 s->channels = 0; 61 62 // negative samplerate given, abort 63 if ((sint_t)samplerate < 0) goto beach; 64 // zero samplerate given. do not open yet 65 if ((sint_t)samplerate == 0) return s; 66 56 67 s->samplerate = samplerate; 57 s->max_size = MAX_SIZE;58 68 s->channels = 1; 59 s->path = path;60 69 70 if (aubio_sink_sndfile_open(s) != AUBIO_OK) {; 71 goto beach; 72 } 73 return s; 74 75 beach: 76 del_aubio_sink_sndfile(s); 77 return NULL; 78 } 79 80 uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate) 81 { 82 if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL; 83 s->samplerate = samplerate; 84 // automatically open when both samplerate and channels have been set 85 if (s->samplerate != 0 && s->channels != 0) { 86 return aubio_sink_sndfile_open(s); 87 } 88 return AUBIO_OK; 89 } 90 91 uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels) 92 { 93 if ((sint_t)(channels) <= 0) return AUBIO_FAIL; 94 s->channels = channels; 95 // automatically open when both samplerate and channels have been set 96 if (s->samplerate != 0 && s->channels != 0) { 97 return aubio_sink_sndfile_open(s); 98 } 99 return AUBIO_OK; 100 } 101 102 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s) 103 { 104 return s->samplerate; 105 } 106 107 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s) 108 { 109 return s->channels; 110 } 111 112 uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s) { 61 113 /* set output format */ 114 SF_INFO sfinfo; 62 115 AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo)); 63 116 sfinfo.samplerate = s->samplerate; … … 71 124 /* show libsndfile err msg */ 72 125 AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL)); 73 AUBIO_FREE(s); 74 return NULL; 126 return AUBIO_FAIL; 75 127 } 76 128 … … 80 132 AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n", 81 133 s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS); 82 AUBIO_FREE(s); 83 return NULL; 134 return AUBIO_FAIL; 84 135 } 85 136 s->scratch_data = AUBIO_ARRAY(float,s->scratch_size); 86 137 87 return s;138 return AUBIO_OK; 88 139 } 89 140 -
src/io/sink_sndfile.h
r870ad70 r14ac1db 1 1 /* 2 Copyright (C) 2012-201 3Paul Brossier <piem@aubio.org>2 Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 39 39 #endif 40 40 41 /** sink_sndfile object */ 41 42 typedef struct _aubio_sink_sndfile_t aubio_sink_sndfile_t; 42 43 … … 52 53 Creates a new sink object. 53 54 55 If samplerate is set to 0, the creation of the file will be delayed until 56 both ::aubio_sink_preset_samplerate and ::aubio_sink_preset_channels have 57 been called. 58 54 59 */ 55 60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * uri, uint_t samplerate); 61 62 /** 63 64 preset sink samplerate 65 66 \param s sink, created with ::new_aubio_sink_sndfile 67 \param samplerate samplerate to preset the sink to, in Hz 68 69 \return 0 on success, 1 on error 70 71 Preset the samplerate of the sink. The file should have been created using a 72 samplerate of 0. 73 74 The file will be opened only when both samplerate and channels have been set. 75 76 */ 77 uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate); 78 79 /** 80 81 preset sink channels 82 83 \param s sink, created with ::new_aubio_sink_sndfile 84 \param channels number of channels to preset the sink to 85 86 \return 0 on success, 1 on error 87 88 Preset the samplerate of the sink. The file should have been created using a 89 samplerate of 0. 90 91 The file will be opened only when both samplerate and channels have been set. 92 93 */ 94 uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels); 95 96 /** 97 98 get samplerate of sink object 99 100 \param s sink object, created with ::new_aubio_sink_sndfile 101 \return samplerate, in Hz 102 103 */ 104 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s); 105 106 /** 107 108 get channels of sink object 109 110 \param s sink object, created with ::new_aubio_sink_sndfile 111 \return number of channels 112 113 */ 114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s); 56 115 57 116 /** … … 65 124 */ 66 125 void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t write); 126 127 /** 128 129 write polyphonic vector of length hop_size to sink 130 131 \param s sink, created with ::new_aubio_sink_sndfile 132 \param write_data ::fmat_t samples to write to sink 133 \param write number of frames to write 134 135 */ 136 void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t * s, fmat_t * write_data, uint_t write); 67 137 68 138 /**
Note: See TracChangeset
for help on using the changeset viewer.