2 Copyright (C) 2016 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
21 #include "aubio_priv.h"
25 aubio_io_validate_samplerate(const char_t *kind, const char_t *path, uint_t samplerate)
27 if ((sint_t)(samplerate) <= 0) {
28 AUBIO_ERR("%s: failed creating %s, samplerate should be positive, not %d\n",
29 kind, path, samplerate);
32 if ((sint_t)samplerate > AUBIO_MAX_SAMPLERATE) {
33 AUBIO_ERR("%s: failed creating %s, samplerate %dHz is too large\n",
34 kind, path, samplerate);
41 aubio_io_validate_channels(const char_t *kind, const char_t *path, uint_t channels)
43 if ((sint_t)(channels) <= 0) {
44 AUBIO_ERR("sink_%s: failed creating %s, channels should be positive, not %d\n",
45 kind, path, channels);
48 if (channels > AUBIO_MAX_CHANNELS) {
49 AUBIO_ERR("sink_%s: failed creating %s, too many channels (%d but %d available)\n",
50 kind, path, channels, AUBIO_MAX_CHANNELS);
57 aubio_source_validate_input_length(const char_t *kind, const char_t *path,
58 uint_t hop_size, uint_t read_data_length)
60 uint_t length = hop_size;
61 if (hop_size < read_data_length) {
62 AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"
63 " hop_size is %d\n", kind, path, read_data_length, hop_size);
64 } else if (hop_size > read_data_length) {
65 AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"
66 " a buffer of length %d\n", kind, path, hop_size, read_data_length);
67 length = read_data_length;
73 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
74 uint_t source_channels, uint_t read_data_height)
76 uint_t channels = source_channels;
77 if (read_data_height < source_channels) {
78 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
79 " but found output of height %d\n", kind, path, source_channels,
81 channels = read_data_height;
82 } else if (read_data_height > source_channels) {
83 // do not show a warning when trying to read into more channels than
86 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
87 " but found output of height %d\n", kind, path, source_channels,
90 channels = source_channels;
96 aubio_source_pad_output (fvec_t *read_data, uint_t source_read)
98 if (source_read < read_data->length) {
99 AUBIO_MEMSET(read_data->data + source_read, 0, read_data->length -
105 aubio_source_pad_multi_output (fmat_t *read_data,
106 uint_t source_channels, uint_t source_read) {
108 if (source_read < read_data->length) {
109 for (i = 0; i < read_data->height; i++) {
110 AUBIO_MEMSET(read_data->data[i] + source_read, 0,
111 read_data->length - source_read);
117 aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
118 uint_t max_size, uint_t write_data_length, uint_t write)
120 uint_t can_write = write;
122 if (write > max_size) {
123 AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
124 " at most %d can be written at once\n", kind, path, write, max_size);
125 can_write = max_size;
128 if (can_write > write_data_length) {
129 AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
130 " but found input of length %d\n", kind, path, write,
132 can_write = write_data_length;
139 aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
140 uint_t sink_channels, uint_t write_data_height)
142 uint_t channels = sink_channels;
143 if (write_data_height < sink_channels) {
144 AUBIO_WRN("%s: partial write to %s, trying to write %d channels,"
145 " but found input of height %d\n", kind, path, sink_channels,
147 channels = write_data_height;