- [FIX] JAudio no usava JFile
- Comence a afegir música i só
This commit is contained in:
BIN
data/ingame.ogg
Normal file
BIN
data/ingame.ogg
Normal file
Binary file not shown.
BIN
data/walk.wav
Normal file
BIN
data/walk.wav
Normal file
Binary file not shown.
1365
source/actor.cpp
1365
source/actor.cpp
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_mixer.h>
|
#include <SDL2/SDL_mixer.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "jfile.h"
|
||||||
|
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
@@ -15,11 +16,14 @@ namespace audio
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char *music_buffer = nullptr;
|
||||||
|
|
||||||
// Inicialitza el sistema de só
|
// Inicialitza el sistema de só
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
int result = Mix_Init(MIX_INIT_OGG | MIX_INIT_WAVPACK);
|
||||||
// Al final he ficat la configuració automàtica i au. Si en el futur necesitem canviar-ho pos se canvia
|
// Al final he ficat la configuració automàtica i au. Si en el futur necesitem canviar-ho pos se canvia
|
||||||
Mix_OpenAudio(48000, AUDIO_S16, 2, 1024);
|
result = Mix_OpenAudio(48000, AUDIO_S16, 2, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tanca el sistema de só (no shit, sherlock)
|
// Tanca el sistema de só (no shit, sherlock)
|
||||||
@@ -31,11 +35,17 @@ namespace audio
|
|||||||
// Carrega un arxiu de música en format OGG
|
// Carrega un arxiu de música en format OGG
|
||||||
const music *loadMusic(const std::string filename)
|
const music *loadMusic(const std::string filename)
|
||||||
{
|
{
|
||||||
return (music *)Mix_LoadMUS(filename.c_str());
|
int size;
|
||||||
|
if (music_buffer) free(music_buffer);
|
||||||
|
music_buffer = file::getFileBuffer(filename, size);
|
||||||
|
auto rwops = SDL_RWFromMem(music_buffer, size);
|
||||||
|
auto mus = Mix_LoadMUS_RW(rwops, 1);
|
||||||
|
//free(buffer);
|
||||||
|
return (music *)mus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comença a reproduïr la música en questió
|
// Comença a reproduïr la música en questió
|
||||||
void playMusic(music *mus, const int loop)
|
void playMusic(const music *mus, const int loop)
|
||||||
{
|
{
|
||||||
Mix_PlayMusic((Mix_Music *)mus, loop);
|
Mix_PlayMusic((Mix_Music *)mus, loop);
|
||||||
}
|
}
|
||||||
@@ -82,9 +92,11 @@ namespace audio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carrega un só des d'un arxiu WAV
|
// Carrega un só des d'un arxiu WAV
|
||||||
const sound *loadSound(const std::string filename)
|
sound *loadSound(const std::string filename)
|
||||||
{
|
{
|
||||||
return (sound *)Mix_LoadWAV(filename.c_str());
|
int size;
|
||||||
|
char *buffer = file::getFileBuffer(filename, size);
|
||||||
|
return (sound *)Mix_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comença a reproduïr el só especificat
|
// Comença a reproduïr el só especificat
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace audio
|
|||||||
/// @brief Comença a reproduïr la música en questió
|
/// @brief Comença a reproduïr la música en questió
|
||||||
/// @param mus punter a la música
|
/// @param mus punter a la música
|
||||||
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
/// @param loop quants bucles farà (-1=infinit, 0=no repeteix, 1=repeteix 1 vegada...)
|
||||||
void playMusic(music *mus, const int loop = -1);
|
void playMusic(const music *mus, const int loop = -1);
|
||||||
|
|
||||||
/// @brief Pausa la música que està sonant ara
|
/// @brief Pausa la música que està sonant ara
|
||||||
void pauseMusic();
|
void pauseMusic();
|
||||||
@@ -61,7 +61,7 @@ namespace audio
|
|||||||
/// @brief Carrega un só des d'un arxiu WAV
|
/// @brief Carrega un só des d'un arxiu WAV
|
||||||
/// @param filename nom de l'arxiu
|
/// @param filename nom de l'arxiu
|
||||||
/// @return un punter al só
|
/// @return un punter al só
|
||||||
const sound *loadSound(const std::string filename);
|
sound *loadSound(const std::string filename);
|
||||||
|
|
||||||
/// @brief Comença a reproduïr el só especificat
|
/// @brief Comença a reproduïr el só especificat
|
||||||
/// @param snd punter al só a reproduïr
|
/// @param snd punter al só a reproduïr
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "jgame.h"
|
#include "jgame.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
|
#include "jaudio.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
@@ -35,6 +36,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
game::init();
|
game::init();
|
||||||
input::init();
|
input::init();
|
||||||
|
audio::init();
|
||||||
|
|
||||||
static unsigned int current_ticks = SDL_GetTicks();
|
static unsigned int current_ticks = SDL_GetTicks();
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "jutil.h"
|
#include "jutil.h"
|
||||||
|
#include "jaudio.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
@@ -40,6 +41,9 @@ namespace modules
|
|||||||
gifs.push_back(std::string(buffer));
|
gifs.push_back(std::string(buffer));
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
} else {
|
||||||
|
auto musica = audio::loadMusic("ingame.ogg");
|
||||||
|
audio::playMusic(musica);
|
||||||
}
|
}
|
||||||
|
|
||||||
actor::hero::init();
|
actor::hero::init();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include "jaudio.h"
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
namespace menu
|
namespace menu
|
||||||
@@ -17,6 +17,7 @@ namespace modules
|
|||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
audio::stopMusic();
|
||||||
selected_option = OPTION_JUGAR;
|
selected_option = OPTION_JUGAR;
|
||||||
::game::setUpdateTicks(64);
|
::game::setUpdateTicks(64);
|
||||||
draw::loadPalette("test.gif");
|
draw::loadPalette("test.gif");
|
||||||
|
|||||||
Reference in New Issue
Block a user