added reaaly basic audio
This commit is contained in:
parent
46e26e41e5
commit
9bfcd5552e
8 changed files with 111 additions and 3 deletions
7
src/audio/sdl/audio.c
Normal file
7
src/audio/sdl/audio.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "arc/audio/audio.h"
|
||||
#include "arc/audio/sdl/audio.h"
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
void ARC_Audio_Play(ARC_Audio *audio){
|
||||
Mix_PlayChannel(-1, audio->chunk, 0);
|
||||
}
|
||||
43
src/audio/sdl/config.c
Normal file
43
src/audio/sdl/config.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "arc/audio/config.h"
|
||||
#include "arc/audio/sdl/audio.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "arc/std/config.h"
|
||||
#include "arc/std/errno.h"
|
||||
#include "arc/audio/audio.h"
|
||||
|
||||
// #define ARC_DEFAULT_CONFIG
|
||||
#include "arc/std/defaults/config.h"
|
||||
|
||||
void ARC_AudioConfig_Init(ARC_Config *config){
|
||||
ARC_Config_AddKeyCString(config, (char *)"ARC_Audio", 9, ARC_Audio_Read, ARC_Audio_Delete);
|
||||
}
|
||||
|
||||
uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){
|
||||
ARC_Config_Get(config, string, value);
|
||||
if(*value){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
|
||||
ARC_DEBUG_LOG(arc_errno, "in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data);
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARC_Audio *audio = (ARC_Audio *)malloc(sizeof(ARC_Audio));
|
||||
|
||||
ARC_String *path;
|
||||
ARC_String_CopySubstring(&path, string, 1, string->length - 2);
|
||||
audio->chunk = Mix_LoadWAV(path->data);
|
||||
|
||||
//TODO: get error message if not loaded
|
||||
|
||||
*value = (void *)audio;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ARC_Audio_Delete(ARC_Config* config, ARC_String *string, void *value){
|
||||
Mix_FreeChunk(((ARC_Audio *)value)->chunk);
|
||||
free((ARC_Audio *)value);
|
||||
}
|
||||
|
|
@ -15,8 +15,8 @@
|
|||
#include "arc/input/sdl/mouse.h"
|
||||
#include "arc/input/sdl/keyboard.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#elif ARC_OPENGL
|
||||
#include "arc/graphics/opengl/window.h"
|
||||
#include "arc/graphics/opengl/renderer.h"
|
||||
|
|
@ -43,6 +43,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
|
|||
//TEMP
|
||||
#ifdef ARC_SDL
|
||||
TTF_Init();
|
||||
Mix_Init(0);
|
||||
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
|
||||
#endif
|
||||
|
||||
#ifdef ARC_SDL
|
||||
|
|
@ -85,6 +87,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
|
|||
void ARC_EngineData_Destroy(ARC_EngineData *data){
|
||||
#ifdef ARC_SDL
|
||||
free(data->mouse->event);
|
||||
TTF_Quit();
|
||||
Mix_Quit();
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Mouse_Destroy(data->mouse);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
|
|||
return;
|
||||
}
|
||||
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0){
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
|
||||
arc_errno = ARC_ERRNO_INIT;
|
||||
printf("Error: initializing SDL\nSDL Error: %s\n", SDL_GetError());
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue