From 08226bc6b0147b69a1afb74d83c6a8821e93601b Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Mon, 29 Oct 2018 02:05:45 +0100 Subject: Simplify some statements --- examples/alrecord.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'examples/alrecord.c') diff --git a/examples/alrecord.c b/examples/alrecord.c index 43b26d35..f60a3055 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -133,7 +133,7 @@ int main(int argc, char **argv) break; else if(strcmp(argv[0], "--channels") == 0 || strcmp(argv[0], "-c") == 0) { - if(!(argc > 1)) + if(argc < 2) { fprintf(stderr, "Missing argument for option: %s\n", argv[0]); return 1; @@ -150,7 +150,7 @@ int main(int argc, char **argv) } else if(strcmp(argv[0], "--bits") == 0 || strcmp(argv[0], "-b") == 0) { - if(!(argc > 1)) + if(argc < 2) { fprintf(stderr, "Missing argument for option: %s\n", argv[0]); return 1; @@ -168,7 +168,7 @@ int main(int argc, char **argv) } else if(strcmp(argv[0], "--rate") == 0 || strcmp(argv[0], "-r") == 0) { - if(!(argc > 1)) + if(argc < 2) { fprintf(stderr, "Missing argument for option: %s\n", argv[0]); return 1; @@ -185,7 +185,7 @@ int main(int argc, char **argv) } else if(strcmp(argv[0], "--time") == 0 || strcmp(argv[0], "-t") == 0) { - if(!(argc > 1)) + if(argc < 2) { fprintf(stderr, "Missing argument for option: %s\n", argv[0]); return 1; @@ -202,7 +202,7 @@ int main(int argc, char **argv) } else if(strcmp(argv[0], "--outfile") == 0 || strcmp(argv[0], "-o") == 0) { - if(!(argc > 1)) + if(argc < 2) { fprintf(stderr, "Missing argument for option: %s\n", argv[0]); return 1; -- cgit v1.2.3 From d7d99adc915583416dd8c70491ec7fc4ac71a543 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 26 Nov 2018 23:18:51 -0800 Subject: Avoid including threads.h in the example helpers --- examples/alrecord.c | 1 + examples/common/alhelpers.c | 1 + examples/common/alhelpers.h | 10 +++++----- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'examples/alrecord.c') diff --git a/examples/alrecord.c b/examples/alrecord.c index f60a3055..30f5f792 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "AL/al.h" diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index 657c10d3..6a583497 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -29,6 +29,7 @@ * channel configs and sample types. */ #include +#include #include #include "AL/al.h" diff --git a/examples/common/alhelpers.h b/examples/common/alhelpers.h index e3e638ac..14edf5d9 100644 --- a/examples/common/alhelpers.h +++ b/examples/common/alhelpers.h @@ -1,15 +1,15 @@ #ifndef ALHELPERS_H #define ALHELPERS_H +#include + #include "AL/alc.h" #include "AL/al.h" #include "AL/alext.h" -#include "threads.h" - #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif /* Some helper functions to get the name from the format enums. */ const char *FormatName(ALenum type); @@ -30,7 +30,7 @@ int altimespec_get(struct timespec *ts, int base); void al_nssleep(unsigned long nsec); #ifdef __cplusplus -} -#endif /* __cplusplus */ +} // extern "C" +#endif #endif /* ALHELPERS_H */ -- cgit v1.2.3 From 90b1bc7b7a009113932b15208e3bdfbed2b3b65b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 30 Jun 2019 23:32:09 -0700 Subject: Make sure a variable is set before use --- examples/alrecord.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/alrecord.c') diff --git a/examples/alrecord.c b/examples/alrecord.c index 30f5f792..c4984f99 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -317,6 +317,7 @@ int main(int argc, char **argv) recorder.mRecTime, (recorder.mRecTime != 1.0f) ? "s" : "" ); + err = ALC_NO_ERROR; alcCaptureStart(recorder.mDevice); while((double)recorder.mDataSize/(double)recorder.mSampleRate < recorder.mRecTime && (err=alcGetError(recorder.mDevice)) == ALC_NO_ERROR && !ferror(recorder.mFile)) -- cgit v1.2.3 From 40e937c63a2a74ef2ff94ba8a056cce0a07832ed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Jul 2019 08:16:39 -0700 Subject: Cleanup the examples' includes --- examples/alffplay.cpp | 31 +++++++++++++++++++++++-------- examples/alhrtf.c | 7 +++++-- examples/allatency.c | 5 +++-- examples/alloopback.c | 7 +++++-- examples/almultireverb.c | 9 ++++++--- examples/alplay.c | 5 +++-- examples/alrecord.c | 1 - examples/alreverb.c | 6 ++++-- examples/alstream.c | 7 +++---- examples/common/alhelpers.c | 6 ++---- examples/common/alhelpers.h | 2 -- 11 files changed, 54 insertions(+), 32 deletions(-) (limited to 'examples/alrecord.c') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index eb5004c6..cdb228e1 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -8,29 +8,44 @@ #include #include #include +#include #include +#include #include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include #include -#include -#include #include #include -#include +#include +#include +#include extern "C" { #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libavformat/avio.h" -#include "libavutil/time.h" +#include "libavformat/version.h" +#include "libavutil/avutil.h" +#include "libavutil/error.h" +#include "libavutil/frame.h" +#include "libavutil/mem.h" #include "libavutil/pixfmt.h" -#include "libavutil/avstring.h" +#include "libavutil/rational.h" +#include "libavutil/samplefmt.h" +#include "libavutil/time.h" +#include "libavutil/version.h" #include "libavutil/channel_layout.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" + +struct SwsContext; } #include "SDL.h" diff --git a/examples/alhrtf.c b/examples/alhrtf.c index f9150ae1..96cf0255 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -24,11 +24,14 @@ /* This file contains an example for selecting an HRTF. */ -#include #include #include +#include +#include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" #include "AL/alc.h" diff --git a/examples/allatency.c b/examples/allatency.c index d561373f..2bc76289 100644 --- a/examples/allatency.c +++ b/examples/allatency.c @@ -27,10 +27,11 @@ #include #include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" -#include "AL/alc.h" #include "AL/alext.h" #include "common/alhelpers.h" diff --git a/examples/alloopback.c b/examples/alloopback.c index 16553f9b..313b89d5 100644 --- a/examples/alloopback.c +++ b/examples/alloopback.c @@ -26,11 +26,14 @@ * output handling. */ -#include #include #include +#include -#include +#include "SDL.h" +#include "SDL_audio.h" +#include "SDL_error.h" +#include "SDL_stdinc.h" #include "AL/al.h" #include "AL/alc.h" diff --git a/examples/almultireverb.c b/examples/almultireverb.c index f1b1872f..efd3bf16 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -29,15 +29,18 @@ * listener. */ -#include #include #include +#include +#include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" #include "AL/alc.h" -#include "AL/alext.h" +#include "AL/efx.h" #include "AL/efx-presets.h" #include "common/alhelpers.h" diff --git a/examples/alplay.c b/examples/alplay.c index 81cb56d5..4ff8fb7f 100644 --- a/examples/alplay.c +++ b/examples/alplay.c @@ -27,10 +27,11 @@ #include #include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" -#include "AL/alc.h" #include "common/alhelpers.h" diff --git a/examples/alrecord.c b/examples/alrecord.c index c4984f99..d65414c9 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "AL/al.h" #include "AL/alc.h" diff --git a/examples/alreverb.c b/examples/alreverb.c index e6c9e606..e1d3c207 100644 --- a/examples/alreverb.c +++ b/examples/alreverb.c @@ -27,11 +27,13 @@ #include #include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" #include "AL/alc.h" -#include "AL/alext.h" +#include "AL/efx.h" #include "AL/efx-presets.h" #include "common/alhelpers.h" diff --git a/examples/alstream.c b/examples/alstream.c index 68115e8d..cb447355 100644 --- a/examples/alstream.c +++ b/examples/alstream.c @@ -27,14 +27,13 @@ #include #include #include -#include #include -#include +#include "SDL_sound.h" +#include "SDL_audio.h" +#include "SDL_stdinc.h" #include "AL/al.h" -#include "AL/alc.h" -#include "AL/alext.h" #include "common/alhelpers.h" diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index 3077d0b7..b387fd2d 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -28,16 +28,14 @@ * finding an appropriate buffer format, and getting readable strings for * channel configs and sample types. */ -#include +#include "alhelpers.h" + #include #include #include #include "AL/al.h" #include "AL/alc.h" -#include "AL/alext.h" - -#include "alhelpers.h" /* InitAL opens a device and sets up a context using default attributes, making diff --git a/examples/common/alhelpers.h b/examples/common/alhelpers.h index 5caeda38..3752d218 100644 --- a/examples/common/alhelpers.h +++ b/examples/common/alhelpers.h @@ -1,9 +1,7 @@ #ifndef ALHELPERS_H #define ALHELPERS_H -#include "AL/alc.h" #include "AL/al.h" -#include "AL/alext.h" #ifdef __cplusplus extern "C" { -- cgit v1.2.3 From 4c76f32ddac5145231609b1cb4f28028abed814b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 03:14:01 -0700 Subject: Avoid implicit conversions with the examples and utils --- examples/alffplay.cpp | 86 +++++++++++++++++++++++---------------------- examples/alhrtf.c | 13 ++++--- examples/allatency.c | 4 +-- examples/alloopback.c | 2 +- examples/almultireverb.c | 18 +++++----- examples/alplay.c | 4 +-- examples/alrecord.c | 24 ++++++------- examples/alreverb.c | 8 ++--- examples/alstream.c | 17 +++++---- examples/altonegen.c | 8 ++--- examples/common/alhelpers.c | 4 +-- utils/makemhr/loadsofa.cpp | 2 +- utils/openal-info.c | 2 +- 13 files changed, 99 insertions(+), 93 deletions(-) (limited to 'examples/alrecord.c') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index cdb228e1..655ffc96 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -213,7 +213,7 @@ class PacketQueue { void pop() { AVPacket *pkt = &mPackets.front(); - mTotalSize -= pkt->size; + mTotalSize -= static_cast(pkt->size); av_packet_unref(pkt); mPackets.pop_front(); } @@ -267,7 +267,7 @@ public: return true; } - mTotalSize += mPackets.back().size; + mTotalSize += static_cast(mPackets.back().size); } mCondVar.notify_one(); return true; @@ -299,7 +299,7 @@ struct AudioState { SwrContextPtr mSwresCtx; /* Conversion format, for what gets fed to OpenAL */ - int mDstChanLayout{0}; + uint64_t mDstChanLayout{0}; AVSampleFormat mDstSampleFmt{AV_SAMPLE_FMT_NONE}; /* Storage of converted samples */ @@ -310,14 +310,14 @@ struct AudioState { /* OpenAL format */ ALenum mFormat{AL_NONE}; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; std::mutex mSrcMutex; std::condition_variable mSrcCond; std::atomic_flag mConnected; ALuint mSource{0}; std::vector mBuffers; - ALsizei mBufferIdx{0}; + ALuint mBufferIdx{0}; AudioState(MovieState &movie) : mMovie(movie) { mConnected.test_and_set(std::memory_order_relaxed); } @@ -326,7 +326,7 @@ struct AudioState { if(mSource) alDeleteSources(1, &mSource); if(!mBuffers.empty()) - alDeleteBuffers(mBuffers.size(), mBuffers.data()); + alDeleteBuffers(static_cast(mBuffers.size()), mBuffers.data()); av_freep(&mSamples); } @@ -348,7 +348,7 @@ struct AudioState { int getSync(); int decodeFrame(); - bool readAudio(uint8_t *samples, int length); + bool readAudio(uint8_t *samples, unsigned int length); int handler(); }; @@ -441,7 +441,7 @@ struct MovieState { nanoseconds getDuration(); - int streamComponentOpen(int stream_index); + int streamComponentOpen(unsigned int stream_index); int parse_handler(); }; @@ -618,17 +618,17 @@ int AudioState::decodeFrame() * multiple of the template type size. */ template -static void sample_dup(uint8_t *out, const uint8_t *in, int count, int frame_size) +static void sample_dup(uint8_t *out, const uint8_t *in, unsigned int count, size_t frame_size) { - const T *sample = reinterpret_cast(in); - T *dst = reinterpret_cast(out); + auto *sample = reinterpret_cast(in); + auto *dst = reinterpret_cast(out); if(frame_size == sizeof(T)) std::fill_n(dst, count, *sample); else { /* NOTE: frame_size is a multiple of sizeof(T). */ - int type_mult = frame_size / sizeof(T); - int i = 0; + size_t type_mult{frame_size / sizeof(T)}; + size_t i{0}; std::generate_n(dst, count*type_mult, [sample,type_mult,&i]() -> T { @@ -641,10 +641,10 @@ static void sample_dup(uint8_t *out, const uint8_t *in, int count, int frame_siz } -bool AudioState::readAudio(uint8_t *samples, int length) +bool AudioState::readAudio(uint8_t *samples, unsigned int length) { - int sample_skip = getSync(); - int audio_size = 0; + int sample_skip{getSync()}; + unsigned int audio_size{0}; /* Read the next chunk of data, refill the buffer, and queue it * on the source */ @@ -669,16 +669,17 @@ bool AudioState::readAudio(uint8_t *samples, int length) continue; } - int rem = length - audio_size; + unsigned int rem{length - audio_size}; if(mSamplesPos >= 0) { - int len = mSamplesLen - mSamplesPos; + const auto len = static_cast(mSamplesLen - mSamplesPos); if(rem > len) rem = len; - memcpy(samples, mSamples + mSamplesPos*mFrameSize, rem*mFrameSize); + std::copy_n(mSamples + static_cast(mSamplesPos)*mFrameSize, + rem*mFrameSize, samples); } else { - rem = std::min(rem, -mSamplesPos); + rem = std::min(rem, static_cast(-mSamplesPos)); /* Add samples by copying the first sample */ if((mFrameSize&7) == 0) @@ -692,7 +693,7 @@ bool AudioState::readAudio(uint8_t *samples, int length) } mSamplesPos += rem; - mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate; + mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; samples += rem*mFrameSize; audio_size += rem; } @@ -701,10 +702,10 @@ bool AudioState::readAudio(uint8_t *samples, int length) if(audio_size < length) { - int rem = length - audio_size; + const unsigned int rem{length - audio_size}; std::fill_n(samples, rem*mFrameSize, (mDstSampleFmt == AV_SAMPLE_FMT_U8) ? 0x80 : 0x00); - mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate; + mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; audio_size += rem; } return true; @@ -928,8 +929,8 @@ int AudioState::handler() } } void *samples{nullptr}; - ALsizei buffer_len = std::chrono::duration_cast>( - mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize; + ALsizei buffer_len = static_cast(std::chrono::duration_cast( + mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize); mSamples = nullptr; mSamplesMax = 0; @@ -968,9 +969,9 @@ int AudioState::handler() } else mSwresCtx.reset(swr_alloc_set_opts(nullptr, - mDstChanLayout, mDstSampleFmt, mCodecCtx->sample_rate, - mCodecCtx->channel_layout ? mCodecCtx->channel_layout : - static_cast(av_get_default_channel_layout(mCodecCtx->channels)), + static_cast(mDstChanLayout), mDstSampleFmt, mCodecCtx->sample_rate, + mCodecCtx->channel_layout ? static_cast(mCodecCtx->channel_layout) : + av_get_default_channel_layout(mCodecCtx->channels), mCodecCtx->sample_fmt, mCodecCtx->sample_rate, 0, nullptr)); if(!mSwresCtx || swr_init(mSwresCtx.get()) != 0) @@ -980,7 +981,7 @@ int AudioState::handler() } mBuffers.assign(AudioBufferTotalTime / AudioBufferTime, 0); - alGenBuffers(mBuffers.size(), mBuffers.data()); + alGenBuffers(static_cast(mBuffers.size()), mBuffers.data()); alGenSources(1, &mSource); if(EnableDirectOut) @@ -1003,12 +1004,12 @@ int AudioState::handler() if(alGetError() != AL_NO_ERROR) { fprintf(stderr, "Failed to use mapped buffers\n"); - samples = av_malloc(buffer_len); + samples = av_malloc(static_cast(buffer_len)); } } else #endif - samples = av_malloc(buffer_len); + samples = av_malloc(static_cast(buffer_len)); /* Prefill the codec buffer. */ do { @@ -1053,14 +1054,15 @@ int AudioState::handler() { auto ptr = static_cast(alMapBufferSOFT(bufid, 0, buffer_len, AL_MAP_WRITE_BIT_SOFT)); - bool got_audio{readAudio(ptr, buffer_len)}; + bool got_audio{readAudio(ptr, static_cast(buffer_len))}; alUnmapBufferSOFT(bufid); if(!got_audio) break; } else #endif { - if(!readAudio(static_cast(samples), buffer_len)) + auto ptr = static_cast(samples); + if(!readAudio(ptr, static_cast(buffer_len))) break; alBufferData(bufid, mFormat, samples, buffer_len, mCodecCtx->sample_rate); } @@ -1138,27 +1140,27 @@ void VideoState::display(SDL_Window *screen, SDL_Renderer *renderer) if(!mImage) return; - float aspect_ratio; + double aspect_ratio; int win_w, win_h; int w, h, x, y; if(mCodecCtx->sample_aspect_ratio.num == 0) - aspect_ratio = 0.0f; + aspect_ratio = 0.0; else { aspect_ratio = av_q2d(mCodecCtx->sample_aspect_ratio) * mCodecCtx->width / mCodecCtx->height; } - if(aspect_ratio <= 0.0f) - aspect_ratio = static_cast(mCodecCtx->width) / static_cast(mCodecCtx->height); + if(aspect_ratio <= 0.0) + aspect_ratio = static_cast(mCodecCtx->width) / mCodecCtx->height; SDL_GetWindowSize(screen, &win_w, &win_h); h = win_h; - w = (static_cast(rint(h * aspect_ratio)) + 3) & ~3; + w = (static_cast(std::rint(h * aspect_ratio)) + 3) & ~3; if(w > win_w) { w = win_w; - h = (static_cast(rint(w / aspect_ratio)) + 3) & ~3; + h = (static_cast(std::rint(w / aspect_ratio)) + 3) & ~3; } x = (win_w - w) / 2; y = (win_h - h) / 2; @@ -1460,9 +1462,9 @@ nanoseconds MovieState::getMasterClock() nanoseconds MovieState::getDuration() { return std::chrono::duration>(mFormatCtx->duration); } -int MovieState::streamComponentOpen(int stream_index) +int MovieState::streamComponentOpen(unsigned int stream_index) { - if(stream_index < 0 || static_cast(stream_index) >= mFormatCtx->nb_streams) + if(stream_index >= mFormatCtx->nb_streams) return -1; /* Get a pointer to the codec context for the stream, and open the @@ -1499,7 +1501,7 @@ int MovieState::streamComponentOpen(int stream_index) return -1; } - return stream_index; + return static_cast(stream_index); } int MovieState::parse_handler() diff --git a/examples/alhrtf.c b/examples/alhrtf.c index 96cf0255..f09f3e99 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -112,7 +112,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -132,6 +132,7 @@ static ALuint LoadSound(const char *filename) int main(int argc, char **argv) { ALCdevice *device; + ALCcontext *context; ALboolean has_angle_ext; ALuint source, buffer; const char *soundname; @@ -153,7 +154,8 @@ int main(int argc, char **argv) if(InitAL(&argv, &argc) != 0) return 1; - device = alcGetContextsDevice(alcGetCurrentContext()); + context = alcGetCurrentContext(); + device = alcGetContextsDevice(context); if(!alcIsExtensionPresent(device, "ALC_SOFT_HRTF")) { fprintf(stderr, "Error: ALC_SOFT_HRTF not supported\n"); @@ -171,7 +173,7 @@ int main(int argc, char **argv) * stereo sources. */ has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES"); - printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not"); + printf("AL_EXT_STEREO_ANGLES %sfound\n", has_angle_ext?"":"not "); /* Check for user-preferred HRTF */ if(strcmp(argv[0], "-hrtf") == 0) @@ -255,7 +257,7 @@ int main(int argc, char **argv) alGenSources(1, &source); alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); alSource3f(source, AL_POSITION, 0.0f, 0.0f, -1.0f); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ @@ -264,6 +266,8 @@ int main(int argc, char **argv) do { al_nssleep(10000000); + alcSuspendContext(context); + /* Rotate the source around the listener by about 1/4 cycle per second, * and keep it within -pi...+pi. */ @@ -282,6 +286,7 @@ int main(int argc, char **argv) ALfloat angles[2] = { (ALfloat)(M_PI/6.0 - angle), (ALfloat)(-M_PI/6.0 - angle) }; alSourcefv(source, AL_STEREO_ANGLES, angles); } + alcProcessContext(context); alGetSourcei(source, AL_SOURCE_STATE, &state); } while(alGetError() == AL_NO_ERROR && state == AL_PLAYING); diff --git a/examples/allatency.c b/examples/allatency.c index 2bc76289..ad700cc1 100644 --- a/examples/allatency.c +++ b/examples/allatency.c @@ -115,7 +115,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -188,7 +188,7 @@ int main(int argc, char **argv) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alloopback.c b/examples/alloopback.c index 313b89d5..426a2af9 100644 --- a/examples/alloopback.c +++ b/examples/alloopback.c @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/almultireverb.c b/examples/almultireverb.c index efd3bf16..b967a050 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -211,7 +211,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -443,8 +443,8 @@ static void UpdateListenerAndEffects(float timediff, const ALuint slots[2], cons } /* Finally, update the effect slots with the updated effect parameters. */ - alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]); - alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]); + alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, (ALint)effects[0]); + alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, (ALint)effects[1]); } @@ -598,8 +598,8 @@ int main(int argc, char **argv) * effect properties. Modifying or deleting the effect object afterward * won't directly affect the effect slot until they're reapplied like this. */ - alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]); - alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]); + alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, (ALint)effects[0]); + alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, (ALint)effects[1]); assert(alGetError()==AL_NO_ERROR && "Failed to set effect slot"); /* For the purposes of this example, prepare a filter that optionally @@ -621,8 +621,8 @@ int main(int argc, char **argv) alGenSources(1, &source); alSourcei(source, AL_LOOPING, AL_TRUE); alSource3f(source, AL_POSITION, -5.0f, 0.0f, -2.0f); - alSourcei(source, AL_DIRECT_FILTER, direct_filter); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_DIRECT_FILTER, (ALint)direct_filter); + alSourcei(source, AL_BUFFER, (ALint)buffer); /* Connect the source to the effect slots. Here, we connect source send 0 * to Zone 0's slot, and send 1 to Zone 1's slot. Filters can be specified @@ -631,8 +631,8 @@ int main(int argc, char **argv) * can only see a zone through a window or thin wall may be attenuated for * that zone. */ - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[0], 0, AL_FILTER_NULL); - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[1], 1, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slots[0], 0, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slots[1], 1, AL_FILTER_NULL); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Get the current time as the base for timing in the main loop. */ diff --git a/examples/alplay.c b/examples/alplay.c index 4ff8fb7f..09ad96b4 100644 --- a/examples/alplay.c +++ b/examples/alplay.c @@ -101,7 +101,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -151,7 +151,7 @@ int main(int argc, char **argv) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alrecord.c b/examples/alrecord.c index d65414c9..627f8540 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -73,9 +73,9 @@ typedef struct Recorder { ALuint mDataSize; float mRecTime; - int mChannels; - int mBits; - int mSampleRate; + ALuint mChannels; + ALuint mBits; + ALuint mSampleRate; ALuint mFrameSize; ALbyte *mBuffer; ALsizei mBufferSize; @@ -139,7 +139,7 @@ int main(int argc, char **argv) return 1; } - recorder.mChannels = strtol(argv[1], &end, 0); + recorder.mChannels = (ALuint)strtoul(argv[1], &end, 0); if((recorder.mChannels != 1 && recorder.mChannels != 2) || (end && *end != '\0')) { fprintf(stderr, "Invalid channels: %s\n", argv[1]); @@ -156,7 +156,7 @@ int main(int argc, char **argv) return 1; } - recorder.mBits = strtol(argv[1], &end, 0); + recorder.mBits = (ALuint)strtoul(argv[1], &end, 0); if((recorder.mBits != 8 && recorder.mBits != 16 && recorder.mBits != 32) || (end && *end != '\0')) { @@ -174,7 +174,7 @@ int main(int argc, char **argv) return 1; } - recorder.mSampleRate = strtol(argv[1], &end, 0); + recorder.mSampleRate = (ALuint)strtoul(argv[1], &end, 0); if(!(recorder.mSampleRate >= 8000 && recorder.mSampleRate <= 96000) || (end && *end != '\0')) { fprintf(stderr, "Invalid sample rate: %s\n", argv[1]); @@ -285,15 +285,15 @@ int main(int argc, char **argv) // 16-bit val, format type id (1 = integer PCM, 3 = float PCM) fwrite16le((recorder.mBits == 32) ? 0x0003 : 0x0001, recorder.mFile); // 16-bit val, channel count - fwrite16le(recorder.mChannels, recorder.mFile); + fwrite16le((ALushort)recorder.mChannels, recorder.mFile); // 32-bit val, frequency fwrite32le(recorder.mSampleRate, recorder.mFile); // 32-bit val, bytes per second fwrite32le(recorder.mSampleRate * recorder.mFrameSize, recorder.mFile); // 16-bit val, frame size - fwrite16le(recorder.mFrameSize, recorder.mFile); + fwrite16le((ALushort)recorder.mFrameSize, recorder.mFile); // 16-bit val, bits per sample - fwrite16le(recorder.mBits, recorder.mFile); + fwrite16le((ALushort)recorder.mBits, recorder.mFile); // 16-bit val, extra byte count fwrite16le(0, recorder.mFile); @@ -331,7 +331,7 @@ int main(int argc, char **argv) } if(count > recorder.mBufferSize) { - ALbyte *data = calloc(recorder.mFrameSize, count); + ALbyte *data = calloc(recorder.mFrameSize, (ALuint)count); free(recorder.mBuffer); recorder.mBuffer = data; recorder.mBufferSize = count; @@ -365,7 +365,7 @@ int main(int argc, char **argv) } } #endif - recorder.mDataSize += (ALuint)fwrite(recorder.mBuffer, recorder.mFrameSize, count, + recorder.mDataSize += (ALuint)fwrite(recorder.mBuffer, recorder.mFrameSize, (ALuint)count, recorder.mFile); } alcCaptureStop(recorder.mDevice); @@ -385,7 +385,7 @@ int main(int argc, char **argv) { fwrite32le(recorder.mDataSize*recorder.mFrameSize, recorder.mFile); if(fseek(recorder.mFile, 4, SEEK_SET) == 0) - fwrite32le(total_size - 8, recorder.mFile); + fwrite32le((ALuint)total_size - 8, recorder.mFile); } fclose(recorder.mFile); diff --git a/examples/alreverb.c b/examples/alreverb.c index e1d3c207..68f0269f 100644 --- a/examples/alreverb.c +++ b/examples/alreverb.c @@ -209,7 +209,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -309,18 +309,18 @@ int main(int argc, char **argv) * effectively copies the effect properties. You can modify or delete the * effect object afterward without affecting the effect slot. */ - alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, effect); + alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, (ALint)effect); assert(alGetError()==AL_NO_ERROR && "Failed to set effect slot"); /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); /* Connect the source to the effect slot. This tells the source to use the * effect slot 'slot', on send #0 with the AL_FILTER_NULL filter object. */ - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slot, 0, AL_FILTER_NULL); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alstream.c b/examples/alstream.c index cb447355..56505ddb 100644 --- a/examples/alstream.c +++ b/examples/alstream.c @@ -160,10 +160,10 @@ static int OpenPlayerFile(StreamPlayer *player, const char *filename) fprintf(stderr, "Unsupported channel count: %d\n", player->sample->actual.channels); goto error; } - player->srate = player->sample->actual.rate; + player->srate = (ALsizei)player->sample->actual.rate; frame_size = player->sample->actual.channels * - SDL_AUDIO_BITSIZE(player->sample->actual.format) / 8; + SDL_AUDIO_BITSIZE(player->sample->actual.format) / 8; /* Set the buffer size, given the desired millisecond length. */ Sound_SetBufferSize(player->sample, (Uint32)((Uint64)player->srate*BUFFER_TIME_MS/1000) * @@ -191,7 +191,7 @@ static void ClosePlayerFile(StreamPlayer *player) /* Prebuffers some audio from the file, and starts playing the source */ static int StartPlayer(StreamPlayer *player) { - size_t i; + ALsizei i; /* Rewind the source position and clear the buffer queue */ alSourceRewind(player->source); @@ -204,8 +204,8 @@ static int StartPlayer(StreamPlayer *player) Uint32 slen = Sound_Decode(player->sample); if(slen == 0) break; - alBufferData(player->buffers[i], player->format, - player->sample->buffer, slen, player->srate); + alBufferData(player->buffers[i], player->format, player->sample->buffer, (ALsizei)slen, + player->srate); } if(alGetError() != AL_NO_ERROR) { @@ -255,8 +255,8 @@ static int UpdatePlayer(StreamPlayer *player) slen = Sound_Decode(player->sample); if(slen > 0) { - alBufferData(bufid, player->format, player->sample->buffer, slen, - player->srate); + alBufferData(bufid, player->format, player->sample->buffer, (ALsizei)slen, + player->srate); alSourceQueueBuffers(player->source, 1, &bufid); } if(alGetError() != AL_NO_ERROR) @@ -323,8 +323,7 @@ int main(int argc, char **argv) else namepart = argv[i]; - printf("Playing: %s (%s, %dhz)\n", namepart, FormatName(player->format), - player->srate); + printf("Playing: %s (%s, %dhz)\n", namepart, FormatName(player->format), player->srate); fflush(stdout); if(!StartPlayer(player)) diff --git a/examples/altonegen.c b/examples/altonegen.c index 628e695d..aacc3496 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -91,7 +91,7 @@ static void ApplySin(ALfloat *data, ALdouble g, ALuint srate, ALuint freq) static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) { ALuint seed = 22222; - ALint data_size; + ALuint data_size; ALfloat *data; ALuint buffer; ALenum err; @@ -142,7 +142,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) /* Buffer the audio data into a new buffer object. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, AL_FORMAT_MONO_FLOAT32, data, data_size, srate); + alBufferData(buffer, AL_FORMAT_MONO_FLOAT32, data, (ALsizei)data_size, (ALsizei)srate); free(data); /* Check if an error occured, and clean up if so. */ @@ -257,7 +257,7 @@ int main(int argc, char *argv[]) srate = dev_rate; /* Load the sound into a buffer. */ - buffer = CreateWave(wavetype, tone_freq, srate); + buffer = CreateWave(wavetype, (ALuint)tone_freq, (ALuint)srate); if(!buffer) { CloseAL(); @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound for a while. */ diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index b387fd2d..730d2e13 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -159,12 +159,12 @@ int altime_get(void) struct timespec ts; int ret = clock_gettime(CLOCK_REALTIME, &ts); if(ret != 0) return 0; - cur_time = ts.tv_sec*1000 + ts.tv_nsec/1000000; + cur_time = (int)(ts.tv_sec*1000 + ts.tv_nsec/1000000); #else /* _POSIX_TIMERS > 0 */ struct timeval tv; int ret = gettimeofday(&tv, NULL); if(ret != 0) return 0; - cur_time = tv.tv_sec*1000 + tv.tv_usec/1000; + cur_time = (int)(tv.tv_sec*1000 + tv.tv_usec/1000); #endif if(!start_time) diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index e82376aa..02911e12 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -50,7 +50,7 @@ static const char *SofaErrorStr(int err) * of other axes as necessary. The epsilons are used to constrain the * equality of unique elements. */ -static uint GetUniquelySortedElems(const uint m, const float *triplets, const int axis, +static uint GetUniquelySortedElems(const uint m, const float *triplets, const uint axis, const double *const (&filters)[3], const double (&epsilons)[3], float *elems) { uint count{0u}; diff --git a/utils/openal-info.c b/utils/openal-info.c index 12dc6311..cc628b6e 100644 --- a/utils/openal-info.c +++ b/utils/openal-info.c @@ -124,7 +124,7 @@ static void printList(const char *list, char separator) next = strchr(list, separator); if(next) { - len = next-list; + len = (size_t)(next-list); do { next++; } while(*next == separator); -- cgit v1.2.3 From 2c348cecb68bd3a71d388547d6b3330f9cebbfad Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 16:55:28 -0700 Subject: Fix some more implicit conversions noted by GCC --- al/source.cpp | 6 +++--- alc/alc.cpp | 34 +++++++++++++++++-------------- alc/alu.cpp | 10 ++++----- alc/backends/alsa.cpp | 2 +- alc/backends/coreaudio.cpp | 17 ++++++++-------- alc/backends/opensl.cpp | 6 +++--- alc/backends/pulseaudio.cpp | 2 +- alc/bs2b.cpp | 4 ++-- alc/converter.cpp | 2 +- alc/effects/autowah.cpp | 9 +++++---- alc/effects/chorus.cpp | 32 +++++++++++++++-------------- alc/effects/echo.cpp | 6 ++++-- alc/effects/fshifter.cpp | 3 ++- alc/effects/modulator.cpp | 2 +- alc/effects/pshifter.cpp | 19 +++++++++--------- alc/effects/vmorpher.cpp | 14 +++++++------ alc/hrtf.cpp | 49 ++++++++++++++++++++++++--------------------- alc/mastering.cpp | 3 +-- alc/mastering.h | 3 +-- alc/mixer/mixer_c.cpp | 9 +++++---- alc/mixer/mixer_neon.cpp | 13 ++++++------ alc/mixer/mixer_sse.cpp | 7 ++++--- alc/mixer/mixer_sse2.cpp | 2 +- alc/mixer/mixer_sse41.cpp | 2 +- alc/mixvoice.cpp | 18 +++++++++-------- common/almalloc.cpp | 6 +++--- examples/alrecord.c | 5 +++-- examples/altonegen.c | 2 +- examples/common/alhelpers.c | 4 ++-- 29 files changed, 156 insertions(+), 135 deletions(-) (limited to 'examples/alrecord.c') diff --git a/al/source.cpp b/al/source.cpp index 478ee3d2..733758f7 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -310,8 +310,8 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) const ALbufferlistitem *BufferList{Source->queue}; const ALbuffer *BufferFmt{nullptr}; - ALboolean readFin{AL_FALSE}; ALuint totalBufferLen{0u}; + bool readFin{false}; while(BufferList) { @@ -1662,7 +1662,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_SEC_OFFSET_CLOCK_SOFT: CHECKSIZE(values, 2); values[0] = GetSourceSecOffset(Source, Context, &srcclock); - values[1] = srcclock.count() / 1000000000.0; + values[1] = static_cast(srcclock.count()) / 1000000000.0; return true; case AL_POSITION: @@ -2851,7 +2851,7 @@ START_API_FUNC if(device->AvgSpeakerDist > 0.0f) { const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency)}; + (device->AvgSpeakerDist * static_cast(device->Frequency))}; auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void { chandata.mDryParams.NFCtrlFilter.init(w1); }; std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, diff --git a/alc/alc.cpp b/alc/alc.cpp index 408b3ca3..8e9d3963 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1587,9 +1587,9 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode) static std::unique_ptr CreateDeviceLimiter(const ALCdevice *device, const ALfloat threshold) { - return CompressorInit(static_cast(device->RealOut.Buffer.size()), device->Frequency, - AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, 0.002f, 0.0f, 0.0f, threshold, - INFINITY, 0.0f, 0.020f, 0.200f); + return CompressorInit(static_cast(device->RealOut.Buffer.size()), + static_cast(device->Frequency), AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, + 0.002f, 0.0f, 0.0f, threshold, INFINITY, 0.0f, 0.020f, 0.200f); } /* UpdateClockBase @@ -2145,17 +2145,21 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(old_sends != device->NumAuxSends) { - if(source->Send.size() > static_cast(device->NumAuxSends)) - std::for_each(source->Send.begin()+device->NumAuxSends, source->Send.end(), - [](ALsource::SendData &send) -> void - { - if(send.Slot) - DecrementRef(send.Slot->ref); - send.Slot = nullptr; - }); - - source->Send.resize(static_cast(device->NumAuxSends), - ALsource::SendData{nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF}); + if(source->Send.size() > device->NumAuxSends) + { + auto clear_send = [](ALsource::SendData &send) -> void + { + if(send.Slot) + DecrementRef(send.Slot->ref); + send.Slot = nullptr; + }; + auto send_begin = source->Send.begin() + + static_cast(device->NumAuxSends); + std::for_each(send_begin, source->Send.end(), clear_send); + } + + source->Send.resize(device->NumAuxSends, + {nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF}); source->Send.shrink_to_fit(); } @@ -2209,7 +2213,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { /* Reinitialize the NFC filters for new parameters. */ const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency)}; + (device->AvgSpeakerDist * static_cast(device->Frequency))}; auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void { chandata.mDryParams.NFCtrlFilter.init(w1); }; std::for_each(voice.mChans.begin(), voice.mChans.begin()+voice.mNumChannels, diff --git a/alc/alu.cpp b/alc/alu.cpp index 0def577e..d7acf8d3 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -201,19 +201,19 @@ void ALCdevice::ProcessBs2b(const size_t SamplesToDo) */ void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table) { - ALsizei si{BSINC_SCALE_COUNT - 1}; - ALfloat sf{0.0f}; + size_t si{BSINC_SCALE_COUNT - 1}; + float sf{0.0f}; if(increment > FRACTIONONE) { - sf = static_castFRACTIONONE / increment; + sf = FRACTIONONE / static_cast(increment); sf = maxf(0.0f, (BSINC_SCALE_COUNT-1) * (sf-table->scaleBase) * table->scaleRange); - si = float2int(sf); + si = float2uint(sf); /* The interpolation factor is fit to this diagonally-symmetric curve * to reduce the transition ripple caused by interpolating different * scales of the sinc function. */ - sf = 1.0f - std::cos(std::asin(sf - si)); + sf = 1.0f - std::cos(std::asin(sf - static_cast(si))); } state->sf = sf; diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index cd85afaf..b797c768 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -1112,7 +1112,7 @@ ALCenum AlsaCapture::captureSamples(ALCvoid *buffer, ALCuint samples) } buffer = static_cast(buffer) + amt; - samples -= amt; + samples -= static_cast(amt); } if(samples > 0) std::fill_n(static_cast(buffer), snd_pcm_frames_to_bytes(mPcmHandle, samples), diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 39f6241a..99b06b7a 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -177,7 +177,7 @@ ALCboolean CoreAudioPlayback::reset() { mDevice->BufferSize = static_cast(uint64_t{mDevice->BufferSize} * streamFormat.mSampleRate / mDevice->Frequency); - mDevice->Frequency = streamFormat.mSampleRate; + mDevice->Frequency = static_cast(streamFormat.mSampleRate); } /* FIXME: How to tell what channels are what in the output device, and how @@ -357,7 +357,8 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, } audiobuf = { { 0 } }; auto rec_vec = mRing->getWriteVector(); - inNumberFrames = minz(inNumberFrames, rec_vec.first.len+rec_vec.second.len); + inNumberFrames = static_cast(minz(inNumberFrames, + rec_vec.first.len+rec_vec.second.len)); // Fill the ringbuffer's two segments with data from the input device if(rec_vec.first.len >= inNumberFrames) @@ -369,7 +370,7 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, } else { - const size_t remaining{inNumberFrames-rec_vec.first.len}; + const auto remaining = static_cast(inNumberFrames - rec_vec.first.len); audiobuf.list.mNumberBuffers = 2; audiobuf.list.mBuffers[0].mNumberChannels = mFormat.mChannelsPerFrame; audiobuf.list.mBuffers[0].mData = rec_vec.first.buf; @@ -594,7 +595,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) // Set the AudioUnit output format frame count uint64_t FrameCount64{mDevice->UpdateSize}; - FrameCount64 = (FrameCount64*outputFormat.mSampleRate + mDevice->Frequency-1) / + FrameCount64 = static_cast(FrameCount64*outputFormat.mSampleRate + mDevice->Frequency-1) / mDevice->Frequency; FrameCount64 += MAX_RESAMPLE_PADDING*2; if(FrameCount64 > std::numeric_limits::max()/2) @@ -615,8 +616,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) // Set up sample converter if needed if(outputFormat.mSampleRate != mDevice->Frequency) mConverter = CreateSampleConverter(mDevice->FmtType, mDevice->FmtType, - mFormat.mChannelsPerFrame, hardwareFormat.mSampleRate, mDevice->Frequency, - BSinc24Resampler); + mFormat.mChannelsPerFrame, static_cast(hardwareFormat.mSampleRate), + mDevice->Frequency, BSinc24Resampler); mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); if(!mRing) return ALC_INVALID_VALUE; @@ -671,8 +672,8 @@ ALCenum CoreAudioCapture::captureSamples(void *buffer, ALCuint samples) ALCuint CoreAudioCapture::availableSamples() { - if(!mConverter) return mRing->readSpace(); - return mConverter->availableOut(mRing->readSpace()); + if(!mConverter) return static_cast(mRing->readSpace()); + return mConverter->availableOut(static_cast(mRing->readSpace())); } } // namespace diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 3ec2177f..06d5cd40 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -170,7 +170,7 @@ struct OpenSLPlayback final : public BackendBase { RingBufferPtr mRing{nullptr}; al::semaphore mSem; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; std::atomic mKillNow{true}; std::thread mThread; @@ -630,7 +630,7 @@ struct OpenSLCapture final : public BackendBase { RingBufferPtr mRing{nullptr}; ALCuint mSplOffset{0u}; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; DEF_NEWDEL(OpenSLCapture) }; @@ -851,7 +851,7 @@ void OpenSLCapture::stop() ALCenum OpenSLCapture::captureSamples(void *buffer, ALCuint samples) { - ALsizei chunk_size = mDevice->UpdateSize * mFrameSize; + ALuint chunk_size{mDevice->UpdateSize * mFrameSize}; SLAndroidSimpleBufferQueueItf bufferQueue; SLresult result; ALCuint i; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 08420748..30c13a69 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -1324,7 +1324,7 @@ ALCenum PulseCapture::captureSamples(ALCvoid *buffer, ALCuint samples) /* Capture is done in fragment-sized chunks, so we loop until we get all * that's available */ - mLastReadable -= dstbuf.size(); + mLastReadable -= static_cast(dstbuf.size()); std::lock_guard _{pulse_lock}; while(!dstbuf.empty()) { diff --git a/alc/bs2b.cpp b/alc/bs2b.cpp index fb75188c..00207bc0 100644 --- a/alc/bs2b.cpp +++ b/alc/bs2b.cpp @@ -91,11 +91,11 @@ static void init(struct bs2b *bs2b) * $d = 1 / 2 / pi / $fc; * $x = exp(-1 / $d); */ - x = std::exp(-al::MathDefs::Tau() * Fc_lo / bs2b->srate); + x = std::exp(-al::MathDefs::Tau() * Fc_lo / static_cast(bs2b->srate)); bs2b->b1_lo = x; bs2b->a0_lo = G_lo * (1.0f - x) * g; - x = std::exp(-al::MathDefs::Tau() * Fc_hi / bs2b->srate); + x = std::exp(-al::MathDefs::Tau() * Fc_hi / static_cast(bs2b->srate)); bs2b->b1_hi = x; bs2b->a0_hi = (1.0f - G_hi * (1.0f - x)) * g; bs2b->a1_hi = -x * g; diff --git a/alc/converter.cpp b/alc/converter.cpp index 2913f533..2ad2ac3b 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -27,7 +27,7 @@ template<> inline ALfloat LoadSample(DevFmtTypeTraits::T template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val * (1.0f/32768.0f); } template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept -{ return val * (1.0f/2147483648.0f); } +{ return static_cast(val) * (1.0f/2147483648.0f); } template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val; } diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index f28cfd54..5e396d0c 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -107,16 +107,17 @@ ALboolean ALautowahState::deviceUpdate(const ALCdevice*) void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { const ALCdevice *device{context->mDevice.get()}; + const auto frequency = static_cast(device->Frequency); const ALfloat ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)}; - mAttackRate = expf(-1.0f / (props->Autowah.AttackTime*device->Frequency)); - mReleaseRate = expf(-1.0f / (ReleaseTime*device->Frequency)); + mAttackRate = std::exp(-1.0f / (props->Autowah.AttackTime*frequency)); + mReleaseRate = std::exp(-1.0f / (ReleaseTime*frequency)); /* 0-20dB Resonance Peak gain */ mResonanceGain = std::sqrt(std::log10(props->Autowah.Resonance)*10.0f / 3.0f); mPeakGain = 1.0f - std::log10(props->Autowah.PeakGain/AL_AUTOWAH_MAX_PEAK_GAIN); - mFreqMinNorm = MIN_FREQ / device->Frequency; - mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / device->Frequency; + mFreqMinNorm = MIN_FREQ / frequency; + mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / frequency; mOutTarget = target.Main->Buffer; for(size_t i{0u};i < slot->Wet.Buffer.size();++i) diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 6e73f1f0..0e3c9d89 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -64,8 +64,8 @@ void GetTriangleDelays(ALuint *delays, const ALuint start_offset, const ALuint l auto gen_lfo = [&offset,lfo_range,lfo_scale,depth,delay]() -> ALuint { offset = (offset+1)%lfo_range; - return static_cast( - fastf2i((1.0f - std::abs(2.0f - lfo_scale*offset)) * depth) + delay); + const float offset_norm{static_cast(offset) * lfo_scale}; + return static_cast(fastf2i((1.0f-std::abs(2.0f-offset_norm)) * depth) + delay); }; std::generate_n(delays, todo, gen_lfo); } @@ -80,7 +80,8 @@ void GetSinusoidDelays(ALuint *delays, const ALuint start_offset, const ALuint l auto gen_lfo = [&offset,lfo_range,lfo_scale,depth,delay]() -> ALuint { offset = (offset+1)%lfo_range; - return static_cast(fastf2i(std::sin(lfo_scale*offset) * depth) + delay); + const float offset_norm{static_cast(offset) * lfo_scale}; + return static_cast(fastf2i(std::sin(offset_norm)*depth) + delay); }; std::generate_n(delays, todo, gen_lfo); } @@ -118,7 +119,8 @@ ALboolean ChorusState::deviceUpdate(const ALCdevice *Device) { constexpr ALfloat max_delay{maxf(AL_CHORUS_MAX_DELAY, AL_FLANGER_MAX_DELAY)}; - const size_t maxlen{NextPowerOf2(float2uint(max_delay*2.0f*Device->Frequency) + 1u)}; + const auto frequency = static_cast(Device->Frequency); + const size_t maxlen{NextPowerOf2(float2uint(max_delay*2.0f*frequency) + 1u)}; if(maxlen != mSampleBuffer.size()) { mSampleBuffer.resize(maxlen); @@ -153,9 +155,11 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co * delay and depth to allow enough padding for resampling. */ const ALCdevice *device{Context->mDevice.get()}; - const auto frequency = static_cast(device->Frequency); + const auto frequency = static_cast(device->Frequency); + mDelay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), mindelay); - mDepth = minf(props->Chorus.Depth * mDelay, static_cast(mDelay - mindelay)); + mDepth = minf(props->Chorus.Depth * static_cast(mDelay), + static_cast(mDelay - mindelay)); mFeedback = props->Chorus.Feedback; @@ -188,10 +192,10 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co switch(mWaveform) { case WaveForm::Triangle: - mLfoScale = 4.0f / mLfoRange; + mLfoScale = 4.0f / static_cast(mLfoRange); break; case WaveForm::Sinusoid: - mLfoScale = al::MathDefs::Tau() / mLfoRange; + mLfoScale = al::MathDefs::Tau() / static_cast(mLfoRange); break; } @@ -229,7 +233,7 @@ void ChorusState::process(const size_t samplesToDo, const al::span(todo)) % mLfoRange; alignas(16) ALfloat temps[2][256]; for(size_t i{0u};i < todo;i++) @@ -239,17 +243,15 @@ void ChorusState::process(const size_t samplesToDo, const al::span>FRACTIONBITS)}; - ALfloat mu{(moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE)}; + ALfloat mu{static_cast(moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE)}; temps[0][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask], - delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], - mu); + delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu); // Tap for the right output. delay = offset - (moddelays[1][i]>>FRACTIONBITS); - mu = (moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); + mu = static_cast(moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); temps[1][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask], - delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], - mu); + delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu); // Accumulate feedback from the average delay of the taps. delaybuf[offset&bufmask] += delaybuf[(offset-avgdelay) & bufmask] * feedback; diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 47c0fedb..a9213df5 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -66,10 +66,12 @@ struct EchoState final : public EffectState { ALboolean EchoState::deviceUpdate(const ALCdevice *Device) { + const auto frequency = static_cast(Device->Frequency); + // Use the next power of 2 for the buffer length, so the tap offsets can be // wrapped using a mask instead of a modulo - const ALuint maxlen{NextPowerOf2(float2uint(AL_ECHO_MAX_DELAY*Device->Frequency + 0.5f) + - float2uint(AL_ECHO_MAX_LRDELAY*Device->Frequency + 0.5f))}; + const ALuint maxlen{NextPowerOf2(float2uint(AL_ECHO_MAX_DELAY*frequency + 0.5f) + + float2uint(AL_ECHO_MAX_LRDELAY*frequency + 0.5f))}; if(maxlen != mSampleBuffer.size()) { mSampleBuffer.resize(maxlen); diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index c015831c..1b935047 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -51,7 +51,8 @@ std::array InitHannWindow() /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(size_t i{0};i < HIL_SIZE>>1;i++) { - const double val{std::sin(al::MathDefs::Pi() * i / double{HIL_SIZE-1})}; + constexpr double scale{al::MathDefs::Pi() / double{HIL_SIZE-1}}; + const double val{std::sin(static_cast(i) * scale)}; ret[i] = ret[HIL_SIZE-1-i] = val * val; } return ret; diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index fbc6377c..8042378a 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -146,7 +146,7 @@ void ModulatorState::process(const size_t samplesToDo, const al::span(mStep * td); mIndex &= WAVEFORM_FRACMASK; auto chandata = std::addressof(mChans[0]); diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index a4d66706..d7ba072e 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -57,7 +57,8 @@ std::array InitHannWindow() /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(size_t i{0};i < STFT_SIZE>>1;i++) { - const double val{std::sin(al::MathDefs::Pi() * i / ALdouble{STFT_SIZE-1})}; + constexpr double scale{al::MathDefs::Pi() / double{STFT_SIZE-1}}; + const double val{std::sin(static_cast(i) * scale)}; ret[i] = ret[STFT_SIZE-1-i] = val * val; } return ret; @@ -129,7 +130,7 @@ ALboolean PshifterState::deviceUpdate(const ALCdevice *device) mCount = FIFO_LATENCY; mPitchShiftI = FRACTIONONE; mPitchShift = 1.0f; - mFreqPerBin = device->Frequency / static_cast(STFT_SIZE); + mFreqPerBin = static_cast(device->Frequency) / float{STFT_SIZE}; std::fill(std::begin(mInFIFO), std::end(mInFIFO), 0.0f); std::fill(std::begin(mOutFIFO), std::end(mOutFIFO), 0.0f); @@ -152,7 +153,7 @@ void PshifterState::update(const ALCcontext*, const ALeffectslot *slot, const Ef static_cast(props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune) / 1200.0f )}; mPitchShiftI = fastf2u(pitch*FRACTIONONE); - mPitchShift = mPitchShiftI * (1.0f/FRACTIONONE); + mPitchShift = static_cast(mPitchShiftI) * (1.0f/FRACTIONONE); ALfloat coeffs[MAX_AMBI_CHANNELS]; CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs); @@ -187,7 +188,7 @@ void PshifterState::process(const size_t samplesToDo, const al::spanVmorpher.Waveform == AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE)*/ mGetSamples = Oscillate; - const ALfloat pitchA{std::pow(2.0f, props->Vmorpher.PhonemeACoarseTuning / 12.0f)}; - const ALfloat pitchB{std::pow(2.0f, props->Vmorpher.PhonemeBCoarseTuning / 12.0f)}; + const ALfloat pitchA{std::pow(2.0f, + static_cast(props->Vmorpher.PhonemeACoarseTuning) / 12.0f)}; + const ALfloat pitchB{std::pow(2.0f, + static_cast(props->Vmorpher.PhonemeBCoarseTuning) / 12.0f)}; auto vowelA = getFiltersByPhoneme(props->Vmorpher.PhonemeA, frequency, pitchA); auto vowelB = getFiltersByPhoneme(props->Vmorpher.PhonemeB, frequency, pitchB); @@ -255,7 +257,7 @@ void VmorpherState::process(const size_t samplesToDo, const al::span(mStep * td); mIndex &= WAVEFORM_FRACMASK; auto chandata = std::addressof(mChans[0]); diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index bd6ecb3a..e20bf0a9 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -182,10 +182,11 @@ struct IdxBlend { ALsizei idx; ALfloat blend; }; */ IdxBlend CalcEvIndex(ALsizei evcount, ALfloat ev) { - ev = (al::MathDefs::Pi()*0.5f + ev) * (evcount-1) / al::MathDefs::Pi(); + ev = (al::MathDefs::Pi()*0.5f + ev) * static_cast(evcount-1) / + al::MathDefs::Pi(); ALsizei idx{float2int(ev)}; - return IdxBlend{mini(idx, evcount-1), ev-idx}; + return IdxBlend{mini(idx, evcount-1), ev-static_cast(idx)}; } /* Calculate the azimuth index given the polar azimuth in radians. This will @@ -193,10 +194,11 @@ IdxBlend CalcEvIndex(ALsizei evcount, ALfloat ev) */ IdxBlend CalcAzIndex(ALsizei azcount, ALfloat az) { - az = (al::MathDefs::Tau()+az) * azcount / al::MathDefs::Tau(); + az = (al::MathDefs::Tau()+az) * static_cast(azcount) / + al::MathDefs::Tau(); ALsizei idx{float2int(az)}; - return IdxBlend{idx%azcount, az-idx}; + return IdxBlend{idx%azcount, az-static_cast(idx)}; } } // namespace @@ -303,24 +305,25 @@ void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALuin ASSUME(NumChannels > 0); ASSUME(AmbiCount > 0); - auto &field = Hrtf->field[0]; ALuint min_delay{HRTF_HISTORY_LENGTH}; ALuint max_delay{0}; auto idx = al::vector(AmbiCount); - auto calc_idxs = [Hrtf,&field,&max_delay,&min_delay](const AngularPoint &pt) noexcept -> ALuint + auto calc_idxs = [Hrtf,&max_delay,&min_delay](const AngularPoint &pt) noexcept -> ALuint { + auto &field = Hrtf->field[0]; /* Calculate elevation index. */ - const auto evidx = clampi(float2int((90.0f+pt.Elev)*(field.evCount-1)/180.0f + 0.5f), - 0, field.evCount-1); + const auto ev_limit = static_cast(field.evCount-1); + const ALuint evidx{float2uint(clampf((90.0f+pt.Elev)/180.0f, 0.0f, 1.0f)*ev_limit + 0.5f)}; const ALuint azcount{Hrtf->elev[evidx].azCount}; const ALuint iroffset{Hrtf->elev[evidx].irOffset}; /* Calculate azimuth index for this elevation. */ - const auto azidx = static_cast((360.0f+pt.Azim)*azcount/360.0f + 0.5f) % azcount; + const float az_norm{(360.0f*pt.Azim) / 360.0f}; + const ALuint azidx{float2uint(az_norm*static_cast(azcount) + 0.5f) % azcount}; /* Calculate the index for the impulse response. */ - ALuint idx{iroffset + azidx}; + const ALuint idx{iroffset + azidx}; min_delay = minu(min_delay, minu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); max_delay = maxu(max_delay, maxu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); @@ -594,7 +597,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector evOffset(evCount); + auto evOffset = al::vector(evCount); for(auto &val : evOffset) val = GetLE_ALushort(data); if(!data || data.eof()) @@ -619,10 +622,10 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector azCount(evCount); + auto azCount = al::vector(evCount); for(size_t i{1};i < evCount;i++) { - azCount[i-1] = evOffset[i] - evOffset[i-1]; + azCount[i-1] = static_cast(evOffset[i] - evOffset[i-1]); if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT) { ERR("Unsupported azimuth count: azCount[%zd]=%d (%d to %d)\n", @@ -630,7 +633,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) failed = AL_TRUE; } } - azCount.back() = irCount - evOffset.back(); + azCount.back() = static_cast(irCount - evOffset.back()); if(azCount.back() < MIN_AZ_COUNT || azCount.back() > MAX_AZ_COUNT) { ERR("Unsupported azimuth count: azCount[%zu]=%d (%d to %d)\n", @@ -640,8 +643,8 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector> coeffs(irSize*irCount); - al::vector> delays(irCount); + auto coeffs = al::vector>(irSize*irCount); + auto delays = al::vector>(irCount); for(auto &val : coeffs) val[0] = GetLE_ALshort(data) / 32768.0f; for(auto &val : delays) @@ -711,7 +714,7 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector azCount(evCount); + auto azCount = al::vector(evCount); std::generate(azCount.begin(), azCount.end(), std::bind(GetLE_ALubyte, std::ref(data))); if(!data || data.eof()) { @@ -735,12 +738,12 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) ALushort irCount{azCount[0]}; for(size_t i{1};i < evCount;i++) { - evOffset[i] = evOffset[i-1] + azCount[i-1]; + evOffset[i] = static_cast(evOffset[i-1] + azCount[i-1]); irCount += azCount[i]; } - al::vector> coeffs(irSize*irCount); - al::vector> delays(irCount); + auto coeffs = al::vector>(irSize*irCount); + auto delays = al::vector>(irCount); for(auto &val : coeffs) val[0] = GetLE_ALshort(data) / 32768.0f; for(auto &val : delays) @@ -903,7 +906,7 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) else if(sampleType == SAMPLETYPE_S24) { for(auto &val : coeffs) - val[0] = GetLE_ALint24(data) / 8388608.0f; + val[0] = static_cast(GetLE_ALint24(data)) / 8388608.0f; } for(auto &val : delays) val[0] = GetLE_ALubyte(data); @@ -935,8 +938,8 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) { for(auto &val : coeffs) { - val[0] = GetLE_ALint24(data) / 8388608.0f; - val[1] = GetLE_ALint24(data) / 8388608.0f; + val[0] = static_cast(GetLE_ALint24(data)) / 8388608.0f; + val[1] = static_cast(GetLE_ALint24(data)) / 8388608.0f; } } for(auto &val : delays) diff --git a/alc/mastering.cpp b/alc/mastering.cpp index 2f575f35..d0a2f78a 100644 --- a/alc/mastering.cpp +++ b/alc/mastering.cpp @@ -337,7 +337,7 @@ void SignalDelay(Compressor *Comp, const ALuint SamplesToDo, FloatBufferLine *Ou * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when * automating release time. */ -std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint SampleRate, +std::unique_ptr CompressorInit(const ALuint NumChans, const ALfloat SampleRate, const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease, const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime, const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb, @@ -363,7 +363,6 @@ std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint S auto Comp = std::unique_ptr{new (al_calloc(16, size)) Compressor{}}; Comp->mNumChans = NumChans; - Comp->mSampleRate = SampleRate; Comp->mAuto.Knee = AutoKnee != AL_FALSE; Comp->mAuto.Attack = AutoAttack != AL_FALSE; Comp->mAuto.Release = AutoRelease != AL_FALSE; diff --git a/alc/mastering.h b/alc/mastering.h index 6c8fc628..851381e9 100644 --- a/alc/mastering.h +++ b/alc/mastering.h @@ -24,7 +24,6 @@ struct SlidingHold; */ struct Compressor { ALuint mNumChans{0u}; - ALuint mSampleRate{0u}; struct { bool Knee : 1; @@ -94,7 +93,7 @@ struct Compressor { * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when * automating release time. */ -std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint SampleRate, +std::unique_ptr CompressorInit(const ALuint NumChans, const ALfloat SampleRate, const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease, const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime, const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb, diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 720b264b..74315dd5 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -16,9 +16,9 @@ namespace { inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALuint) { return vals[0]; } inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) -{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } +{ return lerp(vals[0], vals[1], static_cast(frac)*(1.0f/FRACTIONONE)); } inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) -{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } +{ return cubic(vals[0], vals[1], vals[2], vals[3], static_cast(frac)*(1.0f/FRACTIONONE)); } inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALuint frac) { ASSUME(istate.bsinc.m > 0); @@ -26,10 +26,11 @@ inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(istate.bsinc.m)*pi*4}; const ALfloat *scd{fil + istate.bsinc.m}; const ALfloat *phd{scd + istate.bsinc.m}; const ALfloat *spd{phd + istate.bsinc.m}; diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index 852bef38..2f11273a 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -55,10 +55,10 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES if(dst_iter != dst.end()) { src += static_cast(vgetq_lane_s32(pos4, 0)); - frac = vgetq_lane_s32(frac4, 0); + frac = static_cast(vgetq_lane_s32(frac4, 0)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; @@ -84,14 +84,15 @@ const ALfloat *Resample_(const InterpState *state, const ALflo // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(pi*4)}; const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; @@ -179,8 +180,8 @@ void Mix_(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const bool reached_target{InSamples.size() >= Counter}; const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); - const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3u) + - InSamples.begin(); + const auto aligned_end = minz(static_cast(min_end-InSamples.begin()+3) & ~3u, + InSamples.size()) + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 368b8dfe..65eb0dee 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -29,7 +29,8 @@ const ALfloat *Resample_(const InterpState *state, const ALfloa // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const bool reached_target{InSamples.size() >= Counter}; const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); - const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3u) + - InSamples.begin(); + const auto aligned_end = minz(static_cast(min_end-InSamples.begin()+3) & ~3u, + InSamples.size()) + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; diff --git a/alc/mixer/mixer_sse2.cpp b/alc/mixer/mixer_sse2.cpp index 38d77fd9..897cd1f7 100644 --- a/alc/mixer/mixer_sse2.cpp +++ b/alc/mixer/mixer_sse2.cpp @@ -72,7 +72,7 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES frac = static_cast(_mm_cvtsi128_si32(frac4)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; diff --git a/alc/mixer/mixer_sse41.cpp b/alc/mixer/mixer_sse41.cpp index 0a87f76f..cfa21e99 100644 --- a/alc/mixer/mixer_sse41.cpp +++ b/alc/mixer/mixer_sse41.cpp @@ -77,7 +77,7 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES frac = static_cast(_mm_cvtsi128_si32(frac4)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 7bdeea5e..d7a32f35 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -287,33 +287,35 @@ struct FmtTypeTraits { }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) { return (val-128) * (1.0f/128.0f); } + static constexpr ALfloat to_float(const Type val) noexcept + { return val*(1.0f/128.0f) - 128.0f; } }; template<> struct FmtTypeTraits { using Type = ALshort; - static constexpr ALfloat to_float(const Type val) { return val * (1.0f/32768.0f); } + static constexpr ALfloat to_float(const Type val) noexcept { return val*(1.0f/32768.0f); } }; template<> struct FmtTypeTraits { using Type = ALfloat; - static constexpr ALfloat to_float(const Type val) { return val; } + static constexpr ALfloat to_float(const Type val) noexcept { return val; } }; template<> struct FmtTypeTraits { using Type = ALdouble; - static constexpr ALfloat to_float(const Type val) { return static_cast(val); } + static constexpr ALfloat to_float(const Type val) noexcept + { return static_cast(val); } }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) + static constexpr ALfloat to_float(const Type val) noexcept { return muLawDecompressionTable[val] * (1.0f/32768.0f); } }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) + static constexpr ALfloat to_float(const Type val) noexcept { return aLawDecompressionTable[val] * (1.0f/32768.0f); } }; @@ -363,7 +365,7 @@ const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter, ALfloat template inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, - const size_t samples) + const size_t samples) noexcept { using SampleType = typename FmtTypeTraits::Type; @@ -373,7 +375,7 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, const si } void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, FmtType srctype, - const size_t samples) + const size_t samples) noexcept { #define HANDLE_FMT(T) case T: LoadSampleArray(dst, src, srcstep, samples); break switch(srctype) diff --git a/common/almalloc.cpp b/common/almalloc.cpp index 8700bddc..842fb400 100644 --- a/common/almalloc.cpp +++ b/common/almalloc.cpp @@ -30,11 +30,11 @@ void *al_malloc(size_t alignment, size_t size) #elif defined(HAVE__ALIGNED_MALLOC) return _aligned_malloc(size, alignment); #else - char *ret = static_cast(malloc(size+alignment)); + auto *ret = static_cast(malloc(size+alignment)); if(ret != nullptr) { *(ret++) = 0x00; - while((reinterpret_cast(ret)&(alignment-1)) != 0) + while((reinterpret_cast(ret)&(alignment-1)) != 0) *(ret++) = 0x55; } return ret; @@ -57,7 +57,7 @@ void al_free(void *ptr) noexcept #else if(ptr != nullptr) { - char *finder = static_cast(ptr); + auto *finder = static_cast(ptr); do { --finder; } while(*finder == 0x55); diff --git a/examples/alrecord.c b/examples/alrecord.c index 627f8540..a66e5471 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -54,13 +54,14 @@ static float msvc_strtof(const char *str, char **end) static void fwrite16le(ALushort val, FILE *f) { - ALubyte data[2] = { val&0xff, (val>>8)&0xff }; + ALubyte data[2] = { (ALubyte)(val&0xff), (ALubyte)((val>>8)&0xff) }; fwrite(data, 1, 2, f); } static void fwrite32le(ALuint val, FILE *f) { - ALubyte data[4] = { val&0xff, (val>>8)&0xff, (val>>16)&0xff, (val>>24)&0xff }; + ALubyte data[4] = { (ALubyte)(val&0xff), (ALubyte)((val>>8)&0xff), (ALubyte)((val>>16)&0xff), + (ALubyte)((val>>24)&0xff) }; fwrite(data, 1, 4, f); } diff --git a/examples/altonegen.c b/examples/altonegen.c index aacc3496..26ae788d 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -97,7 +97,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) ALenum err; ALuint i; - data_size = srate * sizeof(ALfloat); + data_size = (ALuint)(srate * sizeof(ALfloat)); data = calloc(1, data_size); switch(type) { diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index 730d2e13..0febef43 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -175,8 +175,8 @@ int altime_get(void) void al_nssleep(unsigned long nsec) { struct timespec ts, rem; - ts.tv_sec = nsec / 1000000000ul; - ts.tv_nsec = nsec % 1000000000ul; + ts.tv_sec = (time_t)(nsec / 1000000000ul); + ts.tv_nsec = (long)(nsec % 1000000000ul); while(nanosleep(&ts, &rem) == -1 && errno == EINTR) ts = rem; } -- cgit v1.2.3