No more SDL

This commit is contained in:
John Alanbrook 2022-06-23 01:39:18 +00:00
parent 0ad3f792ee
commit aa7d36b7d3
4 changed files with 90516 additions and 29 deletions

View file

@ -10,7 +10,7 @@ endif
UNAME_P != uname -m UNAME_P != uname -m
#CC specifies which compiler we're using #CC specifies which compiler we're using
CC = clang -std=c99 CC = musl-clang -std=c99
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
DEFFALGS += -DDEBUG DEFFALGS += -DDEBUG
@ -88,16 +88,16 @@ ifeq ($(UNAME), Windows_NT)
EXT = .exe EXT = .exe
else else
LINKER_FLAGS = LINKER_FLAGS =
ELIBS = editor engine ELIBS = editor engine glfw3 m pthread
CLIBS = glfw SDL2 SDL2_mixer m CLIBS =
EXT = EXT =
endif endif
ELIBS != $(call prefix, $(ELIBS), -l) ELIBS != $(call prefix, $(ELIBS), -l)
CLIBS != $(call prefix, $(CLIBS), -l) CLIBS != $(call prefix, $(CLIBS), -l)
#LELIBS = -Wl,-Bstatic $(ELIBS) -Wl,-Bdynamic $(CLIBS) #LELIBS = -Wl,-Bstatic $(ELIBS)# -Wl,-Bdynamic $(CLIBS)
LELIBS = $(ELIBS) $(CLIBS) LELIBS = $(ELIBS) #$(CLIBS)
objects = $(bsobjects) $(eobjects) $(pinobjects) objects = $(bsobjects) $(eobjects) $(pinobjects)
DEPENDS = $(objects:.o=.d) DEPENDS = $(objects:.o=.d)
@ -123,7 +123,7 @@ editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
$(CC) $< $(LINK) $(CC) $< $(LINK)
@echo Finished build @echo Finished build
$(ENGINE): $(eobjects) $(ENGINE): $(eobjects) bin/libglfw3.a
@echo Making library engine.a @echo Making library engine.a
@ar -r $(ENGINE) $(eobjects) @ar -r $(ENGINE) $(eobjects)
@cp -u -r $(ehead) $(INCLUDE) @cp -u -r $(ehead) $(INCLUDE)
@ -143,6 +143,11 @@ pinball: $(ENGINE) $(pinobjects)
@$(CC) $(pinobjects) $(LINK) -o $@ @$(CC) $(pinobjects) $(LINK) -o $@
@mv pinball paladin/pinball @mv pinball paladin/pinball
bin/libglfw3.a:
@echo Making GLFW
make glfw/build
cp glfw/build/src/libglfw3.a bin/libglfw3.a
$(objprefix)/%.o:%.c $(objprefix)/%.o:%.c
@mkdir -p $(@D) @mkdir -p $(@D)
@echo Making C object $@ @echo Making C object $@

90464
source/engine/miniaudio.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,6 @@
#define MINIAUDIO_IMPLEMENTATION
#include "sound.h" #include "sound.h"
#include "resources.h" #include "resources.h"
@ -7,31 +10,32 @@ static int mus_ch = -1;
void sound_init() void sound_init()
{ {
/*
int flags = MIX_INIT_MP3 | MIX_INIT_OGG; int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
int err = Mix_Init(flags); int err = Mix_Init(flags);
if ((err&flags) != flags) { if ((err&flags) != flags) {
printf("MIX did not init!!"); printf("MIX did not init!!");
} }
*/
//mus_ch = Mix_AllocateChannels(1);
mus_ch = Mix_AllocateChannels(1); //Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
} }
void audio_open(const char *device) void audio_open(const char *device)
{ {
Mix_OpenAudioDevice(44100, MIX_DEFAULT_FORMAT, 2, 2048, device, 0); //Mix_OpenAudioDevice(44100, MIX_DEFAULT_FORMAT, 2, 2048, device, 0);
} }
void audio_close() void audio_close()
{ {
Mix_CloseAudio(); //Mix_CloseAudio();
} }
struct sound *make_sound(const char *wav) struct sound *make_sound(const char *wav)
{ {
struct sound *new = calloc(1, sizeof(struct sound)); struct sound *new = calloc(1, sizeof(struct sound));
new->sound = Mix_LoadWAV(wav); //new->sound = Mix_LoadWAV(wav);
return new; return new;
} }
@ -39,20 +43,20 @@ struct sound *make_sound(const char *wav)
struct music *make_music(const char *ogg) struct music *make_music(const char *ogg)
{ {
struct music *sound = calloc(1, sizeof(struct music)); struct music *sound = calloc(1, sizeof(struct music));
sound->music = Mix_LoadMUS(make_path(ogg)); //sound->music = Mix_LoadMUS(make_path(ogg));
return sound; return sound;
} }
void play_sound(struct sound *sound) void play_sound(struct sound *sound)
{ {
Mix_VolumeChunk(sound->sound, sound->volume); //Mix_VolumeChunk(sound->sound, sound->volume);
Mix_PlayChannel(-1, sound->sound, 0); //Mix_PlayChannel(-1, sound->sound, 0);
} }
void play_music(struct sound *music) void play_music(struct sound *music)
{ {
Mix_PlayChannel(mus_ch, music->sound, -1); //Mix_PlayChannel(mus_ch, music->sound, -1);
} }
void music_set(struct sound *music) void music_set(struct sound *music)
@ -62,57 +66,60 @@ void music_set(struct sound *music)
void music_volume(unsigned char vol) void music_volume(unsigned char vol)
{ {
Mix_Volume(mus_ch, vol); //Mix_Volume(mus_ch, vol);
} }
int music_playing() int music_playing()
{ {
return Mix_Playing(mus_ch); //return Mix_Playing(mus_ch);
return 0;
} }
int music_paused() int music_paused()
{ {
return Mix_Paused(mus_ch); //return Mix_Paused(mus_ch);
return 0;
} }
void music_resume() void music_resume()
{ {
Mix_Resume(mus_ch); //Mix_Resume(mus_ch);
} }
void music_pause() void music_pause()
{ {
Mix_Pause(mus_ch); //Mix_Pause(mus_ch);
} }
void music_stop() void music_stop()
{ {
Mix_HaltChannel(mus_ch); //Mix_HaltChannel(mus_ch);
} }
void audio_init() void audio_init()
{ {
audioDriver = SDL_GetAudioDeviceName(0,0); //audioDriver = SDL_GetAudioDeviceName(0,0);
} }
void play_raw(int device, void *data, int size) void play_raw(int device, void *data, int size)
{ {
SDL_QueueAudio(device, data, size); //SDL_QueueAudio(device, data, size);
} }
void close_audio_device(int device) void close_audio_device(int device)
{ {
SDL_CloseAudioDevice(device); //SDL_CloseAudioDevice(device);
} }
void clear_raw(int device) void clear_raw(int device)
{ {
SDL_ClearQueuedAudio(device); //SDL_ClearQueuedAudio(device);
} }
int open_device(const char *adriver) int open_device(const char *adriver)
{ {
/*
SDL_AudioSpec audio_spec; SDL_AudioSpec audio_spec;
SDL_memset(&audio_spec, 0, sizeof(audio_spec)); SDL_memset(&audio_spec, 0, sizeof(audio_spec));
audio_spec.freq = 48000; audio_spec.freq = 48000;
@ -121,5 +128,8 @@ int open_device(const char *adriver)
audio_spec.samples = 4096; audio_spec.samples = 4096;
int dev = (int) SDL_OpenAudioDevice(adriver, 0, &audio_spec, NULL, 0); int dev = (int) SDL_OpenAudioDevice(adriver, 0, &audio_spec, NULL, 0);
SDL_PauseAudioDevice(dev, 0); SDL_PauseAudioDevice(dev, 0);
return dev; return dev;
*/
return 0;
} }

View file

@ -1,15 +1,23 @@
#ifndef SOUND_H #ifndef SOUND_H
#define SOUND_H #define SOUND_H
#include <SDL2/SDL_mixer.h> #include <miniaudio.h>
struct Mix_Chunk {
int i;
};
struct Mix_Music {
int i;
};
struct sound { struct sound {
Mix_Chunk *sound; struct Mix_Chunk *sound;
unsigned char volume; unsigned char volume;
}; };
struct music { struct music {
Mix_Music *music; struct Mix_Music *music;
unsigned char volume; unsigned char volume;
}; };