[cf19b8a] | 1 | /* |
---|
| 2 | Copyright (C) 2016 Paul Brossier <piem@aubio.org> |
---|
| 3 | |
---|
| 4 | This file is part of aubio. |
---|
| 5 | |
---|
| 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. |
---|
| 10 | |
---|
| 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. |
---|
| 15 | |
---|
| 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/>. |
---|
| 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "aubio_priv.h" |
---|
| 22 | |
---|
| 23 | uint_t |
---|
| 24 | aubio_io_validate_samplerate(const char_t *kind, const char_t *path, uint_t samplerate) |
---|
| 25 | { |
---|
| 26 | if ((sint_t)(samplerate) <= 0) { |
---|
| 27 | AUBIO_ERR("%s: failed creating %s, samplerate should be positive, not %d\n", |
---|
| 28 | kind, path, samplerate); |
---|
| 29 | return AUBIO_FAIL; |
---|
| 30 | } |
---|
| 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); |
---|
| 34 | return AUBIO_FAIL; |
---|
| 35 | } |
---|
| 36 | return AUBIO_OK; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | uint_t |
---|
| 40 | aubio_io_validate_channels(const char_t *kind, const char_t *path, uint_t channels) |
---|
| 41 | { |
---|
| 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); |
---|
| 45 | return AUBIO_FAIL; |
---|
| 46 | } |
---|
| 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); |
---|
| 50 | return AUBIO_FAIL; |
---|
| 51 | } |
---|
| 52 | return AUBIO_OK; |
---|
| 53 | } |
---|
[b5de3a9] | 54 | |
---|
| 55 | uint_t |
---|
| 56 | aubio_sink_validate_input_length(const char_t *kind, const char_t *path, |
---|
| 57 | uint_t max_size, uint_t write_data_length, uint_t write) |
---|
| 58 | { |
---|
| 59 | uint_t can_write = write; |
---|
| 60 | |
---|
| 61 | if (write > max_size) { |
---|
| 62 | AUBIO_WRN("%s: partial write to %s, trying to write %d frames," |
---|
| 63 | " at most %d can be written at once\n", kind, path, write, max_size); |
---|
| 64 | can_write = max_size; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if (can_write > write_data_length) { |
---|
| 68 | AUBIO_WRN("%s: partial write to %s, trying to write %d frames," |
---|
| 69 | " but found input of length %d\n", kind, path, write, |
---|
| 70 | write_data_length); |
---|
| 71 | can_write = write_data_length; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | return can_write; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | uint_t |
---|
| 78 | aubio_sink_validate_input_channels(const char_t *kind, const char_t *path, |
---|
| 79 | uint_t sink_channels, uint_t write_data_height) |
---|
| 80 | { |
---|
| 81 | uint_t channels = sink_channels; |
---|
| 82 | if (write_data_height < sink_channels) { |
---|
| 83 | AUBIO_WRN("%s: partial write to %s, trying to write %d channels," |
---|
| 84 | " but found input of height %d\n", kind, path, sink_channels, |
---|
| 85 | write_data_height); |
---|
| 86 | channels = write_data_height; |
---|
| 87 | } |
---|
| 88 | return channels; |
---|
| 89 | } |
---|