Skip to content

Commit

Permalink
Sound system improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xdanep committed Dec 27, 2022
1 parent b617e9c commit dd4b9d2
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
"-pipe",
"-flto",
"-fPIC",
"-DLIBBSD_OVERLAY",
"-I/usr/include/bsd",
"-g",
"*.c",
"-lncursesw",
"-lSDL2_mixer",
"-lSDL2",
"-lbsd",
"-o",
"${fileDirname}/main"
],
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Below you can find compiling commands.

### -`sdl2_mixer`

### -`libbsd`

# To compile:

### $`make`
Expand Down
10 changes: 5 additions & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
##

CC=gcc
CLIBS=-lncursesw -lSDL2_mixer -lSDL2
CFLAGS=-pipe -O2 -flto -Wall -Wextra -fPIC -std=gnu17
LLIBS=-lncursesw -lSDL2_mixer -lSDL2 -lbsd
CFLAGS=-pipe -O2 -flto -Wall -Wextra -fPIC -std=gnu17 -DLIBBSD_OVERLAY -I/usr/include/bsd

OBJS= \
cmd.o \
Expand All @@ -18,14 +18,14 @@ OBJS= \
main.o \
menu.o \
screen.o \
sound.o
sound.o

default: all

all: main

main: $(OBJS)
$(CC) $(CFLAGS) -o vector $(OBJS) $(CLIBS)
$(CC) $(CFLAGS) -o vector $(OBJS) $(LLIBS)

clean:
@rm -rf *.o vector
Expand All @@ -46,4 +46,4 @@ uninstall:
@sudo rm /usr/share/icons/logo.png
@sudo rm /usr/share/applications/vector.desktop
@sudo rm ~/.config/vector/ -r
@sudo rm /opt/vector/ -r
@sudo rm /opt/vector/ -r
18 changes: 12 additions & 6 deletions src/cmd.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//
// cmd.c
// Vector
// cmd.c -- Terminal Arguments
//
// Created by Aarch-64 on 18/12/2022.
// This file is owned by the vector project
//
// Created by Aarch-64 on 18/12/2022
// Copyright (C) 2022 Agustín Gutíerrez. All rights reserved.
//

Expand Down Expand Up @@ -45,12 +46,12 @@ void extended(void)
/* CLI arguments */
void cmd(int argc, char *argv[])
{
if (argc == 2)
if (argc > 1)
{
/* if (argument cmd 1) == argv_help */
if (!strcmp(argv[1], argv_help) || !strcmp(argv[1], argv_hel)) // || if (argument cmd 1) == argv_hel...
{
printf("--version\t\t\tProgram version\n");
puts("--version\t\t\tProgram version\n");
exit(EXIT_SUCCESS);
}

Expand All @@ -61,5 +62,10 @@ void cmd(int argc, char *argv[])
extended();
exit(EXIT_SUCCESS);
}
else
{
puts("invalid argument\n");
exit(EXIT_FAILURE);
}
}
}
}
4 changes: 2 additions & 2 deletions src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ unsigned short int LoadOptions(OPTION *O)

if (O->mstate) // music initializator
{
sound(SONG1, SOUNDFREQ, SOUNDBUFLEN);
sound(music_ini, SOUNDFREQ, SOUNDBUFLEN);
}

return 0;
Expand Down Expand Up @@ -190,4 +190,4 @@ void saveScore(PLAYER P, int score)
fprintf(fPtr, "%s score: %d\n", P.name, score); // reading PLAYER structure

fclose(fPtr); // closing save file
}
}
16 changes: 8 additions & 8 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ long int start()
clear_s(); // clear screen

if (O.mstate)
sound(SONG2, SOUNDFREQ, SOUNDBUFLEN); // start music
sound(music_game, SOUNDFREQ, SOUNDBUFLEN); // start music

// setting colors
init_pair(1, P.cstate, COLOR_BLACK); // user's choice text on black background
Expand Down Expand Up @@ -231,7 +231,7 @@ long int start()
if (O.mstate)
{
cleansound();
wsound(SONG3, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
wsound(music_game_over, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
sleep(1);
cleansound(); // closing vlc
}
Expand All @@ -250,7 +250,7 @@ long int start()
if (O.mstate)
{
cleansound();
wsound(SONG3, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
wsound(music_game_over, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
sleep(1);
cleansound(); // closing vlc
}
Expand All @@ -269,9 +269,9 @@ long int start()
if (O.mstate)
{
cleansound();
wsound(SONG3, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
wsound(music_game_over, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
sleep(1);
cleansound(); // closing vlc
cleansound(); // closing sdl
}
sleep(2);

Expand Down Expand Up @@ -303,8 +303,8 @@ long int start()

if (O.mstate)
{
cleansound(); // closing vlc
sound(SONG1, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
cleansound(); // closing sdl
sound(music_ini, SOUNDFREQ, SOUNDBUFLEN); // starting main menu music
}

// restoring default screen options
Expand All @@ -318,4 +318,4 @@ long int start()
// score = 0;

return score;
}
}
2 changes: 1 addition & 1 deletion src/include/cmd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// DEFINE FOR CLI ARGUMENTS
#define PROJNAME "Vector"
#define DISTVERSION "1.1.1"
#define DISTVERSION "1.1.2"
#define BUILDVERSION 1
#define RELSTATUS "release"
#define BUILDPTFORM "x86_64-pc-linux-gnu"
Expand Down
24 changes: 19 additions & 5 deletions src/include/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@
#include <stdlib.h>
#include <unistd.h>
#include <ncurses.h>
#include <stdbool.h>
#include <string.h>
#include <syslog.h>

#define SONG1 "/opt/vector/music/menusound.xm"
#define SONG2 "/opt/vector/music/gamesound.mp3"
#define SONG3 "/opt/vector/music/gameover.wav"
// #define SONG1 "SelfControl.mp3"
// #define SONG2 "Vitality_-_Electro_Shock_Sport_Dance.ogg"

#define SONG1 "menusound.xm"
#define SONG2 "gamesound.mp3"
#define SONG3 "gameover.wav"

#define MAXCHAN 32
#define SOUNDFREQ 44100
#define SOUNDBUFLEN 1024
// music.mp3, 44100, 1024
#define SOUNDBUFLEN 2048

extern char out_sound_dir[70];
extern char music_ini[70];
extern char music_game[70];
extern char music_game_over[70];

extern bool nosound;

// music.mp3, 44100, 1024
void sound(void *sound, int sound_freq, int soundbufferlen); // sound(SONG1, SOUNDFREQ, SOUNDBUFFLEN);
void wsound(void *sound, int sound_freq, int soundbufferlen);
void stop_sound(void *sound); // stop_sound(SONG1);
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char *argv[])

if (O.mstate)
{
sound(SONG1, SOUNDFREQ, SOUNDBUFLEN);
sound(music_ini, SOUNDFREQ, SOUNDBUFLEN);
}
}

Expand Down Expand Up @@ -122,4 +122,4 @@ int main(int argc, char *argv[])

exit_s();
exit(EXIT_SUCCESS);
}
}
4 changes: 2 additions & 2 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void setmusic(OPTION *O)

sprint("Music On\n");

sound(SONG1, SOUNDFREQ, SOUNDBUFLEN);
sound(music_ini, SOUNDFREQ, SOUNDBUFLEN);
}

else
Expand Down Expand Up @@ -208,4 +208,4 @@ void controls()

setbuf(stdin, NULL);
getchar();
}
}
Loading

0 comments on commit dd4b9d2

Please sign in to comment.