No more SDL
This commit is contained in:
90464
source/engine/miniaudio.h
Normal file
90464
source/engine/miniaudio.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,6 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
|
||||
|
||||
#include "sound.h"
|
||||
#include "resources.h"
|
||||
|
||||
@@ -7,31 +10,32 @@ static int mus_ch = -1;
|
||||
|
||||
void sound_init()
|
||||
{
|
||||
/*
|
||||
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
|
||||
int err = Mix_Init(flags);
|
||||
if ((err&flags) != flags) {
|
||||
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)
|
||||
{
|
||||
Mix_OpenAudioDevice(44100, MIX_DEFAULT_FORMAT, 2, 2048, device, 0);
|
||||
//Mix_OpenAudioDevice(44100, MIX_DEFAULT_FORMAT, 2, 2048, device, 0);
|
||||
}
|
||||
|
||||
void audio_close()
|
||||
{
|
||||
Mix_CloseAudio();
|
||||
//Mix_CloseAudio();
|
||||
}
|
||||
|
||||
struct sound *make_sound(const char *wav)
|
||||
{
|
||||
struct sound *new = calloc(1, sizeof(struct sound));
|
||||
new->sound = Mix_LoadWAV(wav);
|
||||
//new->sound = Mix_LoadWAV(wav);
|
||||
|
||||
return new;
|
||||
}
|
||||
@@ -39,20 +43,20 @@ struct sound *make_sound(const char *wav)
|
||||
struct music *make_music(const char *ogg)
|
||||
{
|
||||
struct music *sound = calloc(1, sizeof(struct music));
|
||||
sound->music = Mix_LoadMUS(make_path(ogg));
|
||||
//sound->music = Mix_LoadMUS(make_path(ogg));
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
void play_sound(struct sound *sound)
|
||||
{
|
||||
Mix_VolumeChunk(sound->sound, sound->volume);
|
||||
Mix_PlayChannel(-1, sound->sound, 0);
|
||||
//Mix_VolumeChunk(sound->sound, sound->volume);
|
||||
//Mix_PlayChannel(-1, sound->sound, 0);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -62,57 +66,60 @@ void music_set(struct sound *music)
|
||||
|
||||
void music_volume(unsigned char vol)
|
||||
{
|
||||
Mix_Volume(mus_ch, vol);
|
||||
//Mix_Volume(mus_ch, vol);
|
||||
}
|
||||
|
||||
int music_playing()
|
||||
{
|
||||
return Mix_Playing(mus_ch);
|
||||
//return Mix_Playing(mus_ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int music_paused()
|
||||
{
|
||||
return Mix_Paused(mus_ch);
|
||||
//return Mix_Paused(mus_ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void music_resume()
|
||||
{
|
||||
Mix_Resume(mus_ch);
|
||||
//Mix_Resume(mus_ch);
|
||||
}
|
||||
|
||||
void music_pause()
|
||||
{
|
||||
Mix_Pause(mus_ch);
|
||||
//Mix_Pause(mus_ch);
|
||||
}
|
||||
|
||||
void music_stop()
|
||||
{
|
||||
Mix_HaltChannel(mus_ch);
|
||||
//Mix_HaltChannel(mus_ch);
|
||||
}
|
||||
|
||||
|
||||
void audio_init()
|
||||
{
|
||||
audioDriver = SDL_GetAudioDeviceName(0,0);
|
||||
//audioDriver = SDL_GetAudioDeviceName(0,0);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
SDL_CloseAudioDevice(device);
|
||||
//SDL_CloseAudioDevice(device);
|
||||
}
|
||||
|
||||
void clear_raw(int device)
|
||||
{
|
||||
SDL_ClearQueuedAudio(device);
|
||||
//SDL_ClearQueuedAudio(device);
|
||||
}
|
||||
|
||||
int open_device(const char *adriver)
|
||||
{
|
||||
/*
|
||||
SDL_AudioSpec audio_spec;
|
||||
SDL_memset(&audio_spec, 0, sizeof(audio_spec));
|
||||
audio_spec.freq = 48000;
|
||||
@@ -121,5 +128,8 @@ int open_device(const char *adriver)
|
||||
audio_spec.samples = 4096;
|
||||
int dev = (int) SDL_OpenAudioDevice(adriver, 0, &audio_spec, NULL, 0);
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
|
||||
return dev;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
#ifndef 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 {
|
||||
Mix_Chunk *sound;
|
||||
struct Mix_Chunk *sound;
|
||||
unsigned char volume;
|
||||
};
|
||||
|
||||
struct music {
|
||||
Mix_Music *music;
|
||||
struct Mix_Music *music;
|
||||
unsigned char volume;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user