mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
fix pedantic warnings
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include "audio.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL_audio.h>
|
||||
#include <SDL_error.h>
|
||||
#include <SDL_stdinc.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../errors.h"
|
||||
|
||||
@@ -13,19 +18,19 @@ typedef struct {
|
||||
} AudioCallbackData;
|
||||
|
||||
// audio callback from SDL_AudioSpec; called when the audio device needs more data
|
||||
static void audio_mixer(void* userdata, Uint8* stream, int len) {
|
||||
static void audio_mixer(void* userdata, uint8_t* stream, int32_t len) {
|
||||
memset(stream, 0, len); // clear the playing audio
|
||||
AudioDevice* device = userdata; // get the callback data
|
||||
AudioData* audio = device->playing_audio;
|
||||
|
||||
for (int i = 0; i < MAX_SOUNDS; i++) {
|
||||
for (int32_t i = 0; i < MAX_SOUNDS; i++) {
|
||||
// skip if the audio doesn't conain any further data
|
||||
if (audio[i].length <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the length of which we shall be mixing
|
||||
Uint32 mix_length = SDL_min(audio[i].length, len);
|
||||
uint32_t mix_length = SDL_min(audio[i].length, len);
|
||||
|
||||
// mix the audio with the stream
|
||||
SDL_MixAudioFormat(stream, audio[i].buffer, device->format, mix_length, SDL_MIX_MAXVOLUME);
|
||||
@@ -35,14 +40,15 @@ static void audio_mixer(void* userdata, Uint8* stream, int len) {
|
||||
}
|
||||
|
||||
// converts the audio to the format of the audio device
|
||||
static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, Uint8** wav_buffer, Uint32* wav_length) {
|
||||
static void convert_audio(const AudioDevice* audio_device, const SDL_AudioSpec wav_spec, uint8_t** wav_buffer, uint32_t* wav_length) {
|
||||
// build the audio converter with the audio given
|
||||
SDL_AudioCVT cvt = {0};
|
||||
SDL_BuildAudioCVT(&cvt, wav_spec.format, wav_spec.channels, wav_spec.freq, audio_device->format, audio_device->channels, audio_device->freq);
|
||||
|
||||
cvt.len = (*wav_length) * wav_spec.channels; // the buffer length
|
||||
cvt.buf = (Uint8*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer
|
||||
memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer;
|
||||
// suddenly becomes signed
|
||||
cvt.len = (*wav_length) * wav_spec.channels; // the buffer length
|
||||
cvt.buf = (uint8_t*)SDL_malloc(cvt.len * cvt.len_mult); // allocate size for the new buffer
|
||||
memcpy(cvt.buf, *wav_buffer, *wav_length); // copy wav data to cvt buffer;
|
||||
|
||||
// convert
|
||||
SDL_ConvertAudio(&cvt);
|
||||
@@ -67,7 +73,7 @@ AudioData audio_load_wav(const AudioDevice* audio_device, const char* file_path)
|
||||
}
|
||||
|
||||
// initializes the audio device
|
||||
AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, const Uint8 channels, const Uint16 samples) {
|
||||
AudioDevice* audio_device_init(const int32_t freq, const SDL_AudioFormat format, const uint8_t channels, const Uint16 samples) {
|
||||
// allocate memory for the audio device
|
||||
AudioDevice* audio_device = malloc(sizeof(AudioDevice));
|
||||
|
||||
@@ -100,10 +106,9 @@ AudioDevice* audio_device_init(const int freq, const SDL_AudioFormat format, con
|
||||
void audio_play(const AudioDevice* audio_device, const AudioData audio) {
|
||||
AudioData* playing_audio = audio_device->playing_audio;
|
||||
|
||||
for (int i = 0; i < MAX_SOUNDS; i++) {
|
||||
for (int32_t i = 0; i < MAX_SOUNDS; i++) {
|
||||
// overrite audio that has been deallocated
|
||||
if (playing_audio[i].length <= 0) {
|
||||
|
||||
// override the audio
|
||||
playing_audio[i] = audio;
|
||||
break; // don't continue. :3
|
||||
|
||||
Reference in New Issue
Block a user