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"
24 aubio_io_validate_samplerate(const char_t *kind, const char_t *path, uint_t samplerate)
26 if ((sint_t)(samplerate) <= 0) {
27 AUBIO_ERR("%s: failed creating %s, samplerate should be positive, not %d\n",
28 kind, path, samplerate);
31 if ((sint_t)samplerate > AUBIO_MAX_SAMPLERATE) {
32 AUBIO_ERR("%s: failed creating %s, samplerate %dHz is too large\n",
33 kind, path, samplerate);
40 aubio_io_validate_channels(const char_t *kind, const char_t *path, uint_t channels)
42 if ((sint_t)(channels) <= 0) {
43 AUBIO_ERR("sink_%s: failed creating %s, channels should be positive, not %d\n",
44 kind, path, channels);
47 if (channels > AUBIO_MAX_CHANNELS) {
48 AUBIO_ERR("sink_%s: failed creating %s, too many channels (%d but %d available)\n",
49 kind, path, channels, AUBIO_MAX_CHANNELS);
56 aubio_source_validate_input_length(const char_t *kind, const char_t *path,
57 uint_t hop_size, uint_t read_data_length)
59 uint_t length = hop_size;
60 if (hop_size < read_data_length) {
61 AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"
62 " hop_size is %d\n", kind, path, read_data_length, hop_size);
63 } else if (hop_size > read_data_length) {
64 AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"
65 " a buffer of length %d\n", kind, path, hop_size, read_data_length);
66 length = read_data_length;
72 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
73 uint_t source_channels, uint_t read_data_height)
75 uint_t channels = source_channels;
76 if (read_data_height < source_channels) {
77 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
78 " but found output of height %d\n", kind, path, source_channels,
80 channels = read_data_height;
81 } else if (read_data_height > source_channels) {
82 // do not show a warning when trying to read into more channels than
85 AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
86 " but found output of height %d\n", kind, path, source_channels,
89 channels = source_channels;
95 aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
96 uint_t max_size, uint_t write_data_length, uint_t write)
98 uint_t can_write = write;
100 if (write > max_size) {
101 AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
102 " at most %d can be written at once\n", kind, path, write, max_size);
103 can_write = max_size;
106 if (can_write > write_data_length) {
107 AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
108 " but found input of length %d\n", kind, path, write,
110 can_write = write_data_length;
117 aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
118 uint_t sink_channels, uint_t write_data_height)
120 uint_t channels = sink_channels;
121 if (write_data_height < sink_channels) {
122 AUBIO_WRN("%s: partial write to %s, trying to write %d channels,"
123 " but found input of height %d\n", kind, path, sink_channels,
125 channels = write_data_height;