From 554c647128eeb1bccae87e31f7f8ab6b164b2682 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Fri, 16 Aug 2024 17:37:13 +0100 Subject: [PATCH] Fix GitHub Actions build warnings --- source/src/buffer/fftbuffer.cpp | 9 ++++++--- source/src/node/buffer/granulation/grainsegments.cpp | 4 ++-- source/src/node/buffer/segment-player.cpp | 4 ++-- source/src/node/fft/fft-scale-magnitudes.cpp | 2 +- source/src/node/io/input/soundio.cpp | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/src/buffer/fftbuffer.cpp b/source/src/buffer/fftbuffer.cpp index 86b9f478..4d5f4a0b 100644 --- a/source/src/buffer/fftbuffer.cpp +++ b/source/src/buffer/fftbuffer.cpp @@ -35,7 +35,6 @@ FFTBuffer::FFTBuffer(std::string filename, int fft_size, int hop_size) size_t file_size = ftell(fd); fseek(fd, 0, SEEK_SET); double num_frames_frac = (double) file_size / (this->num_bins * 2 * sizeof(float)); - printf("FFTBuffer: File size %zu bytes, %.2f frames\n", file_size, num_frames_frac); if (num_frames_frac != (int) num_frames_frac) { throw std::runtime_error("Error: Not an integer number of frames (found " + std::to_string(num_frames) + " frames)"); @@ -59,9 +58,13 @@ FFTBuffer::FFTBuffer(std::string filename, int fft_size, int hop_size) this->resize(num_frames); - for (int frame = 0; frame < num_frames; frame++) + for (unsigned int frame = 0; frame < num_frames; frame++) { - fread(this->data[frame], sizeof(float), this->num_bins * 2, fd); + size_t rv = fread(this->data[frame], sizeof(float), this->num_bins * 2, fd); + if (rv != this->num_bins * 2) + { + throw std::runtime_error("FFTBuffer: Read too few items"); + } } } diff --git a/source/src/node/buffer/granulation/grainsegments.cpp b/source/src/node/buffer/granulation/grainsegments.cpp index 94171028..f2a5b7d3 100644 --- a/source/src/node/buffer/granulation/grainsegments.cpp +++ b/source/src/node/buffer/granulation/grainsegments.cpp @@ -69,7 +69,7 @@ void SegmentedGranulator::process(Buffer &out, int num_frames) { this->triggered = false; int index = (int) this->index->out[0][frame]; - if (index < 0 || index >= this->onset_times.size()) + if (index < 0 || index >= (int) this->onset_times.size()) { throw std::runtime_error("Invalid segment index: " + std::to_string(index) + " (num_segments = " + std::to_string(this->onset_times.size()) + ")"); } @@ -135,7 +135,7 @@ void SegmentedGranulator::trigger(std::string name, float value) } int index = (int) value; - if (index < 0 || index >= this->onset_times.size()) + if (index < 0 || index >= (int) this->onset_times.size()) { throw std::runtime_error("Invalid segment index: " + std::to_string(index) + " (num_segments = " + std::to_string(this->onset_times.size()) + ")"); } diff --git a/source/src/node/buffer/segment-player.cpp b/source/src/node/buffer/segment-player.cpp index ae7efde9..fa394d43 100644 --- a/source/src/node/buffer/segment-player.cpp +++ b/source/src/node/buffer/segment-player.cpp @@ -92,14 +92,14 @@ void SegmentPlayer::trigger(std::string name, float value) std::vector onsets = onsetsref->float_array_value(); if (onsets.size() > 0) { - int segment_index; + unsigned int segment_index; /*-------------------------------------------------------------------------------- * If `value` is explicitly specified, use this as the segment index. * Otherwise, use the value of the `index` input, or a random value. *--------------------------------------------------------------------------------*/ if (value != SIGNALFLOW_NULL_FLOAT) { - segment_index = (int) value; + segment_index = (unsigned int) value; } else if (this->index) { diff --git a/source/src/node/fft/fft-scale-magnitudes.cpp b/source/src/node/fft/fft-scale-magnitudes.cpp index f96411dc..14d0410e 100644 --- a/source/src/node/fft/fft-scale-magnitudes.cpp +++ b/source/src/node/fft/fft-scale-magnitudes.cpp @@ -11,7 +11,7 @@ FFTScaleMagnitudes::FFTScaleMagnitudes(NodeRef input, : FFTOpNode(input), scale(scale) { this->name = "fft-scale-magnitudes"; - if (this->scale.size() != this->num_bins) + if (this->scale.size() != (unsigned int) this->num_bins) { throw std::runtime_error("FFTScaleMagnitudes: scale array must be same length as magnitude array (" + std::to_string(this->num_bins) + ")"); } diff --git a/source/src/node/io/input/soundio.cpp b/source/src/node/io/input/soundio.cpp index 8212443e..fa529c5d 100644 --- a/source/src/node/io/input/soundio.cpp +++ b/source/src/node/io/input/soundio.cpp @@ -49,7 +49,7 @@ void read_callback(struct SoundIoInStream *instream, for (int frame = 0; frame < frame_count; frame++) { - for (int channel = 0; channel < input->buffer->get_num_channels(); channel += 1) + for (unsigned int channel = 0; channel < input->buffer->get_num_channels(); channel += 1) { float *ptr = reinterpret_cast(areas[channel].ptr + areas[channel].step * frame); input->buffer->data[channel][input->write_pos] = *ptr; @@ -121,7 +121,7 @@ int AudioIn_SoundIO::init() throw audio_io_exception("libsoundio init error: unable to start device: " + std::string(soundio_strerror(err))); } - if (this->num_channels_requested > this->instream->layout.channel_count) + if (this->num_channels_requested > (unsigned int) this->instream->layout.channel_count) { throw audio_io_exception("AudioIn: Not enough input channels available (requested " + std::to_string(this->num_channels_requested) + ", available " + std::to_string(this->instream->layout.channel_count) + ")"); }