- Treballant en el canvi a JailAudio
This commit is contained in:
70
mini.cpp
70
mini.cpp
@@ -3,7 +3,8 @@
|
||||
#include <string.h>
|
||||
#include "lua.h"
|
||||
#include "gif.c"
|
||||
#include "SDL2/SDL_mixer.h"
|
||||
//#include "SDL2/SDL_mixer.h"
|
||||
#include "jail_audio.h"
|
||||
|
||||
#ifdef MACOS_BUNDLE
|
||||
#include <libgen.h>
|
||||
@@ -98,8 +99,8 @@ SDL_GameController *gamepad = NULL;
|
||||
int8_t pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
|
||||
#define MAX_SOUNDS 50
|
||||
Mix_Music *music = NULL;
|
||||
Mix_Chunk *sounds[MAX_SOUNDS];
|
||||
JA_Music_t *music = NULL;
|
||||
JA_Sound_t *sounds[MAX_SOUNDS];
|
||||
|
||||
int16_t beats, num_beats = 0;
|
||||
|
||||
@@ -112,19 +113,21 @@ char* get_value_from_line(char* line) {
|
||||
|
||||
void read_ini() {
|
||||
int size;
|
||||
printf("Carregant 'game.ini'...");
|
||||
FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r");
|
||||
char line[1024];
|
||||
if (f == NULL) return;
|
||||
if (f == NULL) { printf("FAIL!\n"); return; }
|
||||
printf("OK!\n");
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *value = get_value_from_line(line);
|
||||
if (value != NULL) {
|
||||
value[strlen(value)-1] = '\0';
|
||||
if (strcmp(line, "title") == 0) strcpy(window_title, value);
|
||||
else if (strcmp(line, "config") == 0) strcpy(config_folder, value);
|
||||
else if (strcmp(line, "width") == 0) screen_width = atoi(value);
|
||||
else if (strcmp(line, "height") == 0) screen_height = atoi(value);
|
||||
else if (strcmp(line, "zoom") == 0) screen_zoom = atoi(value);
|
||||
else if (strcmp(line, "fullscreen") == 0) screen_fullscreen = atoi(value);
|
||||
if (strcmp(line, "title") == 0) { strcpy(window_title, value); printf("-title=%s\n", window_title); }
|
||||
else if (strcmp(line, "config") == 0) { strcpy(config_folder, value); printf("-config=%s\n", config_folder); }
|
||||
else if (strcmp(line, "width") == 0) { screen_width = atoi(value); printf("-screen width=%i\n", screen_width); }
|
||||
else if (strcmp(line, "height") == 0) { screen_height = atoi(value); printf("-screen height=%i\n", screen_height); }
|
||||
else if (strcmp(line, "zoom") == 0) { screen_zoom = atoi(value); printf("-screen zoom=%i\n", screen_zoom); }
|
||||
else if (strcmp(line, "fullscreen") == 0) { screen_fullscreen = atoi(value); printf("-screen sullscreen=%i\n", screen_fullscreen); }
|
||||
//else if (strcmp(line, "files") == 0) {
|
||||
//lua_files = (char*)malloc(strlen(value));
|
||||
// strcpy(lua_files, value);
|
||||
@@ -132,6 +135,7 @@ void read_ini() {
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
printf("FET\n");
|
||||
}
|
||||
|
||||
void pset_fast(int x, int y) {
|
||||
@@ -149,6 +153,7 @@ void pset_pattern(int x, int y) {
|
||||
}
|
||||
|
||||
void reinit() {
|
||||
printf("REINIT\n");
|
||||
do_pset = pset_fast;
|
||||
ds::pen_color = 6;
|
||||
ds::back_color = 0;
|
||||
@@ -168,13 +173,14 @@ void reinit() {
|
||||
}
|
||||
|
||||
void initaudio() {
|
||||
Mix_OpenAudio(44100, AUDIO_S16, 1, 512);
|
||||
printf("Iniciant JailAudio...");
|
||||
JA_Init(44100, AUDIO_S16, 1);
|
||||
for (int i=0;i<MAX_SOUNDS;++i) sounds[i] = NULL;
|
||||
}
|
||||
void quitaudio() {
|
||||
if (music != NULL) Mix_FreeMusic(music);
|
||||
for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) Mix_FreeChunk(sounds[i]);
|
||||
Mix_CloseAudio();
|
||||
if (music != NULL) JA_DeleteMusic(music);
|
||||
for (int i=0;i<MAX_SOUNDS;++i) if (sounds[i]!=NULL) JA_DeleteSound(sounds[i]);
|
||||
JA_Quit();
|
||||
}
|
||||
|
||||
int scrw() {
|
||||
@@ -319,7 +325,7 @@ int main(int argc,char*argv[]){
|
||||
|
||||
initGamePad();
|
||||
|
||||
Mix_Init(MIX_INIT_OGG);
|
||||
//Mix_Init(MIX_INIT_OGG);
|
||||
|
||||
SDL_Event mini_eve;
|
||||
|
||||
@@ -423,7 +429,7 @@ int main(int argc,char*argv[]){
|
||||
lua_quit();
|
||||
quitaudio();
|
||||
|
||||
Mix_Quit();
|
||||
//Mix_Quit();
|
||||
|
||||
for (int i=0;i<10;++i) freesurf(i);
|
||||
dest_surface = source_surface = map_surface = NULL;
|
||||
@@ -1112,32 +1118,32 @@ int rnd(int x) {
|
||||
void playmusic(const char *filename, const int loop) {
|
||||
int size;
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
if (music != NULL) Mix_FreeMusic(music);
|
||||
music = Mix_LoadMUS_RW(SDL_RWFromMem(buffer, size), 1);
|
||||
Mix_PlayMusic(music, loop);
|
||||
if (music != NULL) JA_DeleteMusic(music);
|
||||
music = JA_LoadMusic((Uint8*)buffer, size);
|
||||
JA_PlayMusic(music, loop);
|
||||
}
|
||||
|
||||
void pausemusic() {
|
||||
Mix_PauseMusic();
|
||||
JA_PauseMusic();
|
||||
}
|
||||
|
||||
void resumemusic() {
|
||||
Mix_ResumeMusic();
|
||||
JA_ResumeMusic();
|
||||
}
|
||||
|
||||
void stopmusic(const int t) {
|
||||
//Mix_HaltMusic();
|
||||
Mix_FadeOutMusic(t);
|
||||
JA_StopMusic();
|
||||
//Mix_FadeOutMusic(t);
|
||||
}
|
||||
|
||||
void musicpos(float value)
|
||||
{
|
||||
Mix_SetMusicPosition(value);
|
||||
//Mix_SetMusicPosition(value);
|
||||
}
|
||||
|
||||
float musicpos()
|
||||
{
|
||||
return Mix_GetMusicPosition(music);
|
||||
return 0; //Mix_GetMusicPosition(music);
|
||||
}
|
||||
|
||||
int loadsound(const char *filename) {
|
||||
@@ -1145,24 +1151,26 @@ int loadsound(const char *filename) {
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
int i=0;
|
||||
while (i<MAX_SOUNDS && sounds[i]!=NULL) i++;
|
||||
if (i==MAX_SOUNDS) { i=0; Mix_FreeChunk(sounds[i]); }
|
||||
sounds[i]=Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||
if (i==MAX_SOUNDS) { i=0; JA_DeleteSound(sounds[i]); }
|
||||
sounds[i]=JA_LoadSound((Uint8*)buffer, size);
|
||||
return i;
|
||||
}
|
||||
|
||||
void freesound(int soundfile) {
|
||||
Mix_FreeChunk(sounds[soundfile]);
|
||||
JA_DeleteSound(sounds[soundfile]);
|
||||
sounds[soundfile] = NULL;
|
||||
}
|
||||
|
||||
int playsound(int soundfile, const int volume) {
|
||||
const int channel = Mix_PlayChannel(-1, sounds[soundfile], 0);
|
||||
Mix_Volume(channel, volume!=-1?volume:MIX_MAX_VOLUME);
|
||||
const int channel = JA_PlaySound(sounds[soundfile], 0);
|
||||
JA_SetSoundVolume(128);
|
||||
//Mix_Volume(channel, volume!=-1?volume:MIX_MAX_VOLUME);
|
||||
return channel;
|
||||
}
|
||||
|
||||
void stopsound(int soundchannel) {
|
||||
Mix_HaltChannel(soundchannel);
|
||||
JA_StopChannel(soundchannel);
|
||||
//Mix_HaltChannel(soundchannel);
|
||||
}
|
||||
|
||||
int getzoom() {
|
||||
|
||||
Reference in New Issue
Block a user