door sound

This commit is contained in:
Quinten Mennen 2025-06-11 19:31:32 +02:00
parent f60fb4c1b6
commit 61b127c6fd
19 changed files with 8 additions and 93721 deletions

BIN
assets/sounds/door.wav Normal file

Binary file not shown.

View File

@ -1,38 +0,0 @@
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2025/06/02 13:18:45 by whaffman #+# #+# #
# Updated: 2025/06/11 17:41:19 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
NAME := audio
CC := cc
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)
CFLAGS := -Wall -Wextra -Werror
LDLIBS := -lm -ldl -lpthread -L../lib/libft -lft
INCLUDES := -I../inc -I../lib/libft/inc
RM := rm -f
.PHONY: all clean fclean re
all: $(NAME)
$(NAME): $(OBJS)
$(CC) $(CFLAGS) $(LDLIBS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
clean:
$(RM) $(OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean all

Binary file not shown.

View File

@ -1,140 +0,0 @@
#include "audio.h"
#include "libft.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
t_audio *audio_init(void)
{
t_audio *audio;
ma_engine_config config;
audio = (t_audio *)malloc(sizeof(t_audio));
if (!audio)
return (NULL);
memset(audio, 0, sizeof(t_audio));
config = ma_engine_config_init();
// config.pUserData = audio;
// config.pLogCallback = NULL;
// config.logLevel = MA_LOG_LEVEL_INFO;
if (ma_engine_init(&config, &audio->engine) != MA_SUCCESS)
{
free(audio);
return (NULL);
}
return (audio);
}
void audio_uninit(t_audio *audio)
{
int i;
if (!audio)
return ;
i = 0;
while (i < SND_SIZE)
{
if (&audio->sounds[i])
{
ma_sound_uninit(&audio->sounds[i]);
}
i++;
}
ma_engine_uninit(&audio->engine);
free(audio);
}
int audio_load_sounds(t_audio *audio)
{
int i;
const char *sound_files[SND_SIZE] = {
"sounds/walk.wav",
"sounds/flash.wav",
"sounds/damage.wav",
"sounds/death.wav",
"sounds/enemy.mp3",
"sounds/pickup.wav",
"sounds/hum.wav",
"sounds/noise.wav"};
if (!audio)
return (FAILURE);
i = 0;
while (i < SND_SIZE)
{
printf("Loading sound: %s\n", sound_files[i]);
if (ma_sound_init_from_file(&audio->engine, sound_files[i],
0, NULL, NULL, &audio->sounds[i]) != MA_SUCCESS)
{
audio_uninit(audio);
return (FAILURE);
}
i++;
}
return (SUCCESS);
}
int audio_play(t_audio *audio, t_sound sound)
{
if (!audio || sound < 0 || sound >= SND_SIZE || !&audio->sounds[sound])
return (FAILURE);
ma_sound_seek_to_pcm_frame(&audio->sounds[sound], 0);
if (ma_sound_start(&audio->sounds[sound]) != MA_SUCCESS)
return (FAILURE);
return (SUCCESS);
}
int audio_stop(t_audio *audio, t_sound sound)
{
if (!audio || sound < 0 || sound >= SND_SIZE || !&audio->sounds[sound])
return (FAILURE);
ma_sound_seek_to_pcm_frame(&audio->sounds[sound], 0);
if (ma_sound_stop(&audio->sounds[sound]) != MA_SUCCESS)
return (FAILURE);
return (SUCCESS);
}
int audio_is_playing(t_audio *audio, t_sound sound)
{
if (!audio || sound < 0 || sound >= SND_SIZE || !&audio->sounds[sound])
return (FAILURE);
if (ma_sound_is_playing(&audio->sounds[sound]))
return (SUCCESS);
return (FAILURE);
}
int audio_loop(t_audio *audio, t_sound sound, int loop)
{
if (!audio || sound < 0 || sound >= SND_SIZE || !&audio->sounds[sound])
return (FAILURE);
ma_sound_set_looping(&audio->sounds[sound], loop);
return (SUCCESS);
}
int audio_handle_queues(t_audio *audio)
{
int i;
if (!audio)
return (FAILURE);
i = 0;
while (i < SND_SIZE)
{
if (audio->play_queue[i])
{
audio_play(audio, i);
audio->play_queue[i] = 0;
}
if (audio->stop_queue[i])
{
audio_stop(audio, i);
audio->stop_queue[i] = 0;
}
audio->is_playing[i] = ma_sound_is_playing(&audio->sounds[i]);
i++;
}
return (SUCCESS);
}

View File

@ -1,39 +0,0 @@
#include "miniaudio.h"
#define SND_SIZE 8
#define SUCCESS 1
#define FAILURE 0
typedef enum s_sound {
SND_WALK,
SND_FLASH,
SND_DAMAGE,
SND_DEATH,
SND_ENEMY,
SND_PICKUP,
SND_HUM,
SND_NOISE
} t_sound;
typedef struct s_audio {
ma_engine engine; // The audio engine instance
ma_sound sounds[SND_SIZE]; // Array of sounds
char play_queue[SND_SIZE]; // Queue for playing sounds
char stop_queue[SND_SIZE]; // Queue for stopping sounds
char is_playing[SND_SIZE]; // Array to check if sounds are playing
} t_audio;
t_audio *audio_init(void);
int audio_load_sounds(t_audio *audio);
int audio_stop(t_audio *audio, t_sound sound);
int audio_is_playing(t_audio *audio, t_sound sound);
int audio_loop(t_audio *audio, t_sound sound, int loop);
int audio_handle_queues(t_audio *audio);
void audio_uninit(t_audio *audio);
// typedef struct s_audio {
// ma_engine_config config; // Configuration for the audio engine
// ma_engine engine; // The audio engine instance
// } t_audio;

View File

@ -1,30 +0,0 @@
#include "audio.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // For sleep function
int main(void)
{
t_audio *audio;
audio = audio_init();
if (!audio)
{
fprintf(stderr, "Failed to initialize audio.\n");
return 1;
}
if (audio_load_sounds(audio) != SUCCESS)
{
fprintf(stderr, "Failed to load sounds.\n");
return 1;
}
printf("Audio initialized and sounds loaded successfully.\n");
audio->play_queue[SND_ENEMY] = 1; // Example to play enemy sound
audio_handle_queues(audio);
sleep(10); // Keep the program running to hear the sound
audio_uninit(audio);
}

View File

@ -1,2 +0,0 @@
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
#include "miniaudio.h"
#define SND_SIZE 8
#define SND_SIZE 9
#define SUCCESS 1
#define FAILURE 0
@ -12,7 +12,8 @@ typedef enum s_sound {
SND_ENEMY,
SND_PICKUP,
SND_HUM,
SND_NOISE
SND_NOISE,
SND_DOOR,
} t_sound;
typedef struct s_audio {

View File

@ -56,7 +56,9 @@ int audio_load_sounds(t_audio *audio)
"assets/sounds/enemy.mp3",
"assets/sounds/pickup.wav",
"assets/sounds/hum.wav",
"assets/sounds/noise.wav"};
"assets/sounds/noise.wav",
"assets/sounds/door.wav",
};
if (!audio)
return (FAILURE);

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
/* Updated: 2025/06/11 16:26:14 by qmennen ### ########.fr */
/* Updated: 2025/06/11 19:27:27 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,6 +36,7 @@ void interact_door(t_game *game)
pos = vec2_to_int(add(game->player->pos, game->player->dir));
if (game->map->grid[pos.y][pos.x] == TILE_DOOR)
{
game->audio->play_queue[SND_DOOR] = 1;
game->map->grid[pos.y][pos.x] = TILE_EMPTY;
game->scoreboard->tiles_visited++;
}