Exemplo n.º 1
0
Arquivo: sound.c Projeto: wimh/instead
mus_t snd_load_mus(const char *fname)
{
	mus_t	mus = NULL;
	if (!sound_on)
		return NULL;
	mus = malloc(sizeof(struct _mus_t));
	if (!mus)
		return NULL;
	mus->rw = RWFromIdf(game_idf, fname);
	if (!mus->rw) 
		goto err;
#if MIXER_VERSION_ATLEAST(2,0,0)
	mus->mus = Mix_LoadMUS_RW(mus->rw, SDL_FALSE);
#else
	mus->mus = Mix_LoadMUS_RW(mus->rw);
#endif
	if (!mus->mus)
		goto err1;
	return mus;
err1:
	SDL_RWclose(mus->rw);
err:
	free(mus);
	return NULL;
}
Exemplo n.º 2
0
/*---------------------------------------------------------
 Function:

 Description:
 Load a MOD or UNIMOD file into memory and prepare it to
 be played.
---------------------------------------------------------*/
void s_loadmod(char *f)
{
#ifndef NO_SOUND
   myFile   myfile;
   SDL_RWops *mod = NULL;

   if (mf) s_unloadmod();
   if (!myfile.open(f)) error("(s_loadmod): not found: ", f);

   mod = SDL_RWFromMem(myfile.getMemory(), myfile.getsize());

   if(mod == NULL) error("SDL_RWFromMem: ", SDL_GetError());

   #ifdef PANDORA
   mf = Mix_LoadMUS_RW(mod); SDL_FreeRW(mod);
   #else
   mf = Mix_LoadMUS_RW(mod, SDL_TRUE);
   #endif

   if(!mf) {
      printf("Mix_LoadMUS_RW: %s\n", Mix_GetError());
   }

   myfile.close();
#endif
}
Exemplo n.º 3
0
musicp music_load (const char *file, const char *name_alias)
{
    if (name_alias) {
        musicp m = music_find(name_alias);
        if (m) {
            return (m);
        }
    }

    if (!file) {
        if (!name_alias) {
            ERR("no file for music");
        } else {
            ERR("no file for music loading %s", name_alias);
        }
    }

    if (!all_music) {
        all_music = tree_alloc(TREE_KEY_STRING, "TREE ROOT: music");
    }

    musicp m = (typeof(m)) myzalloc(sizeof(*m), "TREE NODE: music");
    m->tree.key = dupstr(name_alias, "TREE KEY: music");

    if (!tree_insert(all_music, &m->tree.node)) {
        ERR("music insert name_alias [%s] failed", name_alias);
    }

    m->data = ramdisk_load(file, &m->len);
    if (!m->data) {
        ERR("cannot load music %s", file);
    }

    SDL_RWops *rw;

    rw = SDL_RWFromMem(m->data, m->len);
    if (!rw) {
        ERR("cannot make RW music %s", file);
    }

#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2 /* { */
    m->music = Mix_LoadMUS_RW(rw);
#else
    m->music = Mix_LoadMUS_RW(rw, false);
#endif /* } */
    if (!m->music) {
        MSG_BOX("Mix_LoadMUS_RW fail %s: %s %s", file, Mix_GetError(),
            SDL_GetError());
        SDL_ClearError();
    }

    DBG("Load %s", file);

    return (m);
}
Exemplo n.º 4
0
void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) {
	if (file.empty() || file == "(OFF)")
	{
		BGM_Stop();
		return;
	}

	std::string const path = FileFinder::FindMusic(file);
	if (path.empty()) {
		//HACK: Polish RTP translation replaced (OFF) reserved string with (Brak)
		if (file != "(Brak)")
			Output::Warning("Music not found: %s", file.c_str());
		BGM_Stop();
		return;
	}

	SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb");
#if SDL_MIXER_MAJOR_VERSION>1
	bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic);
#else
	bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic);
#endif
	if (!bgm) {
		Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
#if SDL_MAJOR_VERSION>1
	// SDL2_mixer produces noise when playing wav.
	// Workaround: Use Mix_LoadWAV
	// https://bugzilla.libsdl.org/show_bug.cgi?id=2094
	if (bgs_playing) {
		BGS_Stop();
	}
	if (Mix_GetMusicType(bgm.get()) == MUS_WAV) {
		BGM_Stop();
		BGS_Play(file, volume, 0, fadein);
		return;
	}
#endif

	BGM_Volume(volume);
	if (!me_stopped_bgm &&
#ifdef _WIN32
	    (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6
	     ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein))
#else
	     Mix_FadeInMusic(bgm.get(), -1, fadein)
#endif
	     == -1) {
		Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
}
Exemplo n.º 5
0
bool CSound::LoadSong (ESong Song, int ResourceID)
{
    SDL_RWops *rwSong;

    // Check if the song slot is free
    ASSERT (m_CurrentSong == NULL);

    LPVOID pData;
    DWORD DataSize;

    // If we could not get the sound resource information
    if (!GetSoundResource (ResourceID, pData, DataSize))
    {
        // Get out
        return false;
    }
    
    // Convert pData to SDL_RWops
    rwSong = SDL_RWFromMem(pData, DataSize);
  
    // Open Sample
    m_CurrentSong = Mix_LoadMUS_RW(rwSong);
    SDL_FreeRW(rwSong);
	
    if (!m_CurrentSong) {
        // Log failure
        theLog.WriteLine ("Sound           => !!! Could not load song %d because %s.", ResourceID, Mix_GetError());
        
        // Get out
        return false;
    }
		
    // Everything went right
    return true;
}
Exemplo n.º 6
0
	Music::Music(asset::istream stream) throw(Music_loading_failed) :
	    _handle(nullptr, Mix_FreeMusic), _stream(std::make_unique<asset::istream>(std::move(stream))){

		auto id = _stream->aid();

#ifndef EMSCRIPTEN
		SDL_RWops *rwops = SDL_AllocRW();
		INVARIANT(rwops, "SDL_AllocRW failed");

		rwops->seek = istream_seek;
		rwops->read = istream_read;
		rwops->write = NULL;
		rwops->close = istream_close;
		rwops->hidden.unknown.data1 = _stream.get();

		_handle.reset(Mix_LoadMUS_RW(rwops, 1));

#else
		auto location = _stream->physical_location();
		_stream.reset();

		if(location.is_nothing())
			return;

		_handle.reset(Mix_LoadMUS(location.get_or_throw().c_str()));
#endif

		if(!_handle){
			WARN("Mix_LoadMUS_RW ("<<id.str()<<") failed: " << Mix_GetError());
		}

	}
Exemplo n.º 7
0
/*!
 * Loads the music from the given data.
 * \param musicdata The data from original resource
 * \param size The size of the data.
 * \return true if the music was loaded.
 */
bool SdlMixerMusic::loadMusic(uint8 * musicData, int size)
{
    SDL_RWops *rw = SDL_RWFromMem(musicData, size);
    if (!rw) {
        Audio::error("SdlMixerMusic", "loadMusic", "Failed creating SDL_RW buffer from memory");
        return false;
    }
    Mix_Music *newmusic = Mix_LoadMUS_RW(rw);

    if (!newmusic) {
        Audio::error("SdlMixerMusic", "loadMusic", "Failed loading music from SDL_RW buffer");
        SDL_FreeRW(rw);
        return false;
    }
    if (music_data_)
        Mix_FreeMusic(music_data_);

    if (rw_) {
        SDL_FreeRW(rw_);
        rw_ = NULL;
    }

    music_data_ = newmusic;
    rw_ = rw;

    return true;
}
Exemplo n.º 8
0
song::song(char const * filename)
{
    data = NULL;
    Name = strdup(filename);
    song_id = 0;

    rw = NULL;
    music = NULL;

    char realname[255];
    strcpy(realname, get_filename_prefix());
    strcat(realname, filename);

    uint32_t data_size;
    data = load_hmi(realname, data_size);

    if (!data)
    {
        printf("Sound: ERROR - could not load %s\n", realname);
        return;
    }

    rw = SDL_RWFromMem(data, data_size);
    music = Mix_LoadMUS_RW(rw, 0);

    if (!music)
    {
        printf("Sound: ERROR - %s while loading %s\n",
               Mix_GetError(), realname);
        return;
    }
}
Exemplo n.º 9
0
/*
 * @brief Handles the actual loading of .ogg music files.
 */
static _Bool S_LoadMusicFile(const char *name, void **buffer, SDL_RWops **rw, Mix_Music **music) {
	char path[MAX_QPATH];

	*music = NULL;

	StripExtension(name, path);
	g_snprintf(path, sizeof(path), "music/%s.ogg", name);

	int32_t len;
	if ((len = Fs_Load(path, buffer)) != -1) {

		if ((*rw = SDL_RWFromMem(*buffer, len))) {

			if ((*music = Mix_LoadMUS_RW(*rw))) {
				Com_Debug("Loaded %s\n", name);
			} else {
				Com_Warn("Failed to load %s: %s\n", name, Mix_GetError());
				SDL_FreeRW(*rw);
			}
		} else {
			Com_Warn("Failed to create SDL_RWops for %s\n", name);
			Fs_Free(*buffer);
		}
	} else {
		Com_Debug("Failed to load %s\n", name);
	}

	return *music != NULL;
}
Exemplo n.º 10
0
void *I_RegisterSong(void *data, int len)
{
    if (!music_initialized)
        return false;
    else
    {
        Mix_Music       *music = NULL;

        if (!memcmp(data, "MUS", 3))
        {
            ConvertMus(data, len, tempmusicfilename);
            music = Mix_LoadMUS(tempmusicfilename);
            remove(tempmusicfilename);
        }
        else
        {
            SDL_RWops   *rwops = SDL_RWFromMem(data, len);

            if (rwops)
                music = Mix_LoadMUS_RW(rwops, SDL_FALSE);
        }

        return music;
    }
}
Exemplo n.º 11
0
 SDLMusic(float *inData, int len)
 {
    IncRef();
    
    #ifndef EMSCRIPTEN
    #ifdef NME_SDL2
    mMusic = Mix_LoadMUS_RW(SDL_RWFromMem(inData, len),false);
    #else
    mMusic = Mix_LoadMUS_RW(SDL_RWFromMem(inData, len));
    #endif
    if ( mMusic == NULL )
    {
       mError = SDL_GetError();
       ELOG("Error in music with len (%d)", len );
    }
    #endif
 }
Exemplo n.º 12
0
//
// RegisterSong
//
static void RegisterSong(void *data, size_t size)
{
    if (music)
        UnregisterSong();

    rw = SDL_RWFromMem(data, (int)size);
    music = Mix_LoadMUS_RW(rw, SDL_FALSE);
}
Exemplo n.º 13
0
void SoundPlayer::play(const char* filename)
{
	stop();

	file = FS().open(filename);

	music = Music(Mix_LoadMUS_RW(file.get()), Mix_FreeMusic);
	Mix_PlayMusic(music.get(), 1);
}
Exemplo n.º 14
0
	void SoundSystem::SubmitMusic(const std::string& id, SDL_RWops* rw)
	{
		m_Music.emplace(id, Mix_SmartMusic {Mix_LoadMUS_RW(rw, 1)});

		// Check for errors
		if (!m_Music.at(id).get()) {
			LOG_WARNING(Mix_GetError());
		}
	}
Exemplo n.º 15
0
// Duke3D-specific.  --ryan.
// void MUSIC_PlayMusic(char *_filename)
int32_t MUSIC_PlaySong(char *song, int32_t loopflag)
{
//	initprintf("MUSIC_PlaySong");
    MUSIC_StopSong();

    if (external_midi)
    {
        FILE *fp;

#if defined FORK_EXEC_MIDI
        static int32_t sigchld_handler_set = 0;

        if (!sigchld_handler_set)
        {
            struct sigaction sa;
            sa.sa_handler=sigchld_handler;
            sa.sa_flags=0;
            sigemptyset(&sa.sa_mask);

            if (sigaction(SIGCHLD, &sa, NULL)==-1)
                initprintf("%s: sigaction: %s\n", __func__, strerror(errno));

            sigchld_handler_set = 1;
        }
#endif

        fp = Bfopen(external_midi_tempfn, "wb");
        if (fp)
        {
            fwrite(song, 1, g_musicSize, fp);
            Bfclose(fp);

#if defined FORK_EXEC_MIDI
            external_midi_restart = loopflag;
            playmusic();
#else
            music_musicchunk = Mix_LoadMUS(external_midi_tempfn);
            if (!music_musicchunk)
                initprintf("Mix_LoadMUS: %s\n", Mix_GetError());
#endif
        }
        else initprintf("%s: fopen: %s\n", __func__, strerror(errno));
    }
    else
        music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize)
#if (SDL_MAJOR_VERSION > 1)
            , SDL_FALSE
#endif
            );

    if (music_musicchunk != NULL)
        if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1)
            initprintf("Mix_PlayMusic: %s\n", Mix_GetError());

    return MUSIC_Ok;
}
Exemplo n.º 16
0
MUSIC	*music_load(const char *file)
{
	MUSIC *m;

	m = Mix_LoadMUS_RW(unz_open(file), 1);
	if (m == NULL)
		FATAL(Mix_GetError());

	return m;
}
Exemplo n.º 17
0
/**
 * Loads a music file from a specified memory chunk.
 * @param data Pointer to the music file in memory
 * @param size Size of the music file in bytes.
 */
void Music::load(const void *data, unsigned int size)
{
	SDL_RWops *rwops = SDL_RWFromConstMem(data, size);
	_music = Mix_LoadMUS_RW(rwops);
	SDL_FreeRW(rwops);
	if (_music == 0)
	{
		throw Exception(Mix_GetError());
	}
}
Exemplo n.º 18
0
inline void playBGM(ScenarioRunner* sr)
{
  uint32_t size=0;
  char* buffer = sr->getResourceManager()->getFile("music",sr->getString(),size);
  SDL_RWops* rw = SDL_RWFromMem(buffer,size);
  if (rw==0) ERROR("SDL_RWFromMem failed: "+string(SDL_GetError()));
  Mix_Music* music = Mix_LoadMUS_RW(rw,1);
  if (music==0) ERROR("SDL_LoadMUS_RW failed: "+string(SDL_GetError()));
  Mix_PlayMusic(music,-1);
}
Exemplo n.º 19
0
void loadingmusic(Mix_Music *bso[],Mix_Chunk *fx[]) {

	/* Musics */
    SDL_RWops *rw = SDL_RWFromMem(&_binary_sounds_PrayerofHopeN_ogg_start,
        (unsigned int)&_binary_sounds_PrayerofHopeN_ogg_end - (unsigned int)&_binary_sounds_PrayerofHopeN_ogg_start);
	bso[0] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_AreaIChurchN_ogg_start,
        (unsigned int)&_binary_sounds_AreaIChurchN_ogg_end - (unsigned int)&_binary_sounds_AreaIChurchN_ogg_start);
	bso[1] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_GameOverV2N_ogg_start,
        (unsigned int)&_binary_sounds_GameOverV2N_ogg_end - (unsigned int)&_binary_sounds_GameOverV2N_ogg_start);
	bso[2] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_HangmansTree_ogg_start,
        (unsigned int)&_binary_sounds_HangmansTree_ogg_end - (unsigned int)&_binary_sounds_HangmansTree_ogg_start);
	bso[3] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_AreaIICavesV2N_ogg_start,
        (unsigned int)&_binary_sounds_AreaIICavesV2N_ogg_end - (unsigned int)&_binary_sounds_AreaIICavesV2N_ogg_start);
	bso[4] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_EvilFightN_ogg_start,
        (unsigned int)&_binary_sounds_EvilFightN_ogg_end - (unsigned int)&_binary_sounds_EvilFightN_ogg_start);
	bso[5] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_AreaIIIHellN_ogg_start,
        (unsigned int)&_binary_sounds_AreaIIIHellN_ogg_end - (unsigned int)&_binary_sounds_AreaIIIHellN_ogg_start);
	bso[6] = Mix_LoadMUS_RW(rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_ManhuntwoodN_ogg_start,
        (unsigned int)&_binary_sounds_ManhuntwoodN_ogg_end - (unsigned int)&_binary_sounds_ManhuntwoodN_ogg_start);
	bso[7] = Mix_LoadMUS_RW(rw,1);

	/* Fxs */
    rw = SDL_RWFromMem(&_binary_sounds_shoot_ogg_start,
        (unsigned int)&_binary_sounds_shoot_ogg_end - (unsigned int)&_binary_sounds_shoot_ogg_start);
	fx[0] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_doorfx_ogg_start,
        (unsigned int)&_binary_sounds_doorfx_ogg_end - (unsigned int)&_binary_sounds_doorfx_ogg_start);
	fx[1] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_Item_ogg_start,
        (unsigned int)&_binary_sounds_Item_ogg_end - (unsigned int)&_binary_sounds_Item_ogg_start);
	fx[2] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_jump_ogg_start,
        (unsigned int)&_binary_sounds_jump_ogg_end - (unsigned int)&_binary_sounds_jump_ogg_start);
	fx[3] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_slash_ogg_start,
        (unsigned int)&_binary_sounds_slash_ogg_end - (unsigned int)&_binary_sounds_slash_ogg_start);
	fx[4] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_mechanismn_ogg_start,
        (unsigned int)&_binary_sounds_mechanismn_ogg_end - (unsigned int)&_binary_sounds_mechanismn_ogg_start);
	fx[5] = Mix_LoadWAV_RW (rw,1);
    rw = SDL_RWFromMem(&_binary_sounds_onedeathn_ogg_start,
        (unsigned int)&_binary_sounds_onedeathn_ogg_end - (unsigned int)&_binary_sounds_onedeathn_ogg_start);
	fx[6] = Mix_LoadWAV_RW (rw,1);

}
Exemplo n.º 20
0
bool C4MusicFileSDL::Play(bool loop)
{
	const SDL_version * link_version = Mix_Linked_Version();
	if (link_version->major < 1
	    || (link_version->major == 1 && link_version->minor < 2)
	    || (link_version->major == 1 && link_version->minor == 2 && link_version->patch < 7))
	{
		// Check existance and try extracting it
		if (!FileExists(FileName)) if (!ExtractFile())
				// Doesn't exist - or file is corrupt
			{
				LogF("Error reading %s", FileName);
				return false;
			}
		// Load
		Music = Mix_LoadMUS(SongExtracted ? Config.AtTempPath(C4CFN_TempMusic2) : FileName);
		// Load failed
		if (!Music)
		{
			LogF("SDL_mixer: %s", SDL_GetError());
			return false;
		}
		// Play Song
		if (Mix_PlayMusic(Music, loop? -1 : 1) == -1)
		{
			LogF("SDL_mixer: %s", SDL_GetError());
			return false;
		}
	}
	else
	{
		// Load Song
		// Fixme: Try loading this from the group incrementally for less lag
		size_t filesize;
		if (!C4Group_ReadFile(FileName, &Data, &filesize))
		{
			LogF("Error reading %s", FileName);
			return false;
		}
		// Mix_FreeMusic frees the RWop
		Music = Mix_LoadMUS_RW(SDL_RWFromConstMem(Data, filesize));
		if (!Music)
		{
			LogF("SDL_mixer: %s", SDL_GetError());
			return false;
		}
		if (Mix_PlayMusic(Music, loop? -1 : 1) == -1)
		{
			LogF("SDL_mixer: %s", SDL_GetError());
			return false;
		}
	}
	return true;
}
Exemplo n.º 21
0
   SDLMusic(unsigned char *inData, int len)
   {
      IncRef();

      mMusic = Mix_LoadMUS_RW(SDL_RWFromMem(inData, len));
      if ( mMusic == NULL )
      {
         mError = SDL_GetError();
         ELOG("Error in music with len (%d)", len );
      }
   }
Exemplo n.º 22
0
void MusicEntry::load(std::string musicURI)
{
	if (music)
	{
		logGlobal->traceStream()<<"Del-ing music file "<<currentName;
		Mix_FreeMusic(music);
		music = nullptr;
	}

	currentName = musicURI;

	logGlobal->traceStream()<<"Loading music file "<<musicURI;

	data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll();
	musicFile = SDL_RWFromConstMem(data.first.get(), data.second);
	
	#ifdef VCMI_SDL1
	music = Mix_LoadMUS_RW(musicFile);

	if(!music)
	{
		SDL_FreeRW(musicFile);
		musicFile = nullptr;
		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError();
		return;
	}

	#else
	music = Mix_LoadMUS_RW(musicFile, SDL_FALSE);

	if(!music)
	{
		SDL_FreeRW(musicFile);
		musicFile = nullptr;
		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError();
		return;
	}

	#endif // 0

}
Exemplo n.º 23
0
/**
 * Loads a music file from a specified memory chunk.
 * @param data Pointer to the music file in memory
 * @param size Size of the music file in bytes.
 */
void Music::load(const void *data, int size)
{
#ifndef __NO_MUSIC
	SDL_RWops *rwops = SDL_RWFromConstMem(data, size);
	_music = Mix_LoadMUS_RW(rwops);
	SDL_FreeRW(rwops);
	if (_music == 0)
	{
		throw Exception(Mix_GetError());
	}
#endif
}
Exemplo n.º 24
0
Resource *SDLMusic::load(SDL_RWops *const rw)
{
    if (Mix_Music *const music = Mix_LoadMUS_RW(rw))
    {
        return new SDLMusic(music);
    }
    else
    {
        logger->log("Error, failed to load music: %s", Mix_GetError());
        return nullptr;
    }
}
Exemplo n.º 25
0
// Play a music file
bool j1Audio::PlayMusic(const char* path, float fade_time)
{
	bool ret = true;

	if (!enabled)
		return false;

	if(music != NULL)
	{
		if(fade_time > 0.0f)
		{
			Mix_FadeOutMusic(int(fade_time * 1000.0f));
		}
		else
		{
			Mix_HaltMusic();
		}

		// this call blocks until fade out is done
		Mix_FreeMusic(music);
	}

	music = Mix_LoadMUS_RW(App->fs->Load(path), 1);

	if(music == NULL)
	{
		LOG("Cannot load music %s. Mix_GetError(): %s\n", path, Mix_GetError());
		ret = false;
	}
	else
	{
		if(fade_time > 0.0f)
		{
			if(Mix_FadeInMusic(music, -1, (int) (fade_time * 1000.0f)) < 0)
			{
				LOG("Cannot fade in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}
		}
		else
		{
			if(Mix_PlayMusic(music, -1) < 0)
			{
				LOG("Cannot play in music %s. Mix_GetError(): %s", path, Mix_GetError());
				ret = false;
			}
		}
	}

	LOG("Successfully playing %s", path);
	return ret;
}
Exemplo n.º 26
0
/**
 * @brief Loads the music by name.
 *
 *    @param name Name of the file to load.
 */
int music_mix_load( const char* name, SDL_RWops *rw )
{
   (void) name;

   /* Load the data */
   music_rw = rw;
#if SDL_VERSION_ATLEAST(2,0,0)
   music_music = Mix_LoadMUS_RW(music_rw, 1);
#else /* SDL_VERSION_ATLEAST(2,0,0) */
   music_music = Mix_LoadMUS_RW(music_rw);
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
   if (music_music == NULL) {
      WARN("SDL_Mixer: %s", Mix_GetError());
      Mix_HookMusicFinished(music_rechoose);
      return -1;
   }

   /* Rechoose music on finish. */
   Mix_HookMusicFinished(music_rechoose);

   return 0;
}
Exemplo n.º 27
0
static int load_music_async_thread(void* arg)
{
    load_music_async_t *async = (load_music_async_t*)arg;
    async->music = Mix_LoadMUS_RW(async->rwop);
    if(async->music == NULL)
        async->err = strdup(Mix_GetError());
    SDL_Event e;
    e.type = SDL_USEREVENT_CPCALL;
    e.user.data1 = (void*)l_load_music_async_callback;
    e.user.data2 = arg;
    SDL_PushEvent(&e);
    return 0;
}
Exemplo n.º 28
0
_Mix_Music* j1Audio::Load_music(SDL_RWops* rwops)
{
	_Mix_Music* song;
	song = Mix_LoadMUS_RW(rwops, 1);
	if (!song)
	{
		LOG("ERROR loading music from SDL_RWops");
	}



	return song;

}
Exemplo n.º 29
0
VALUE MSP::Music::rbf_create_from_buffer(VALUE self, VALUE v_buffer, VALUE v_buffer_size) {
    char* buffer = Util::value_to_c_str(v_buffer);
    int buffer_size = Util::value_to_int(v_buffer_size);
    char* allocated_buffer = new char[buffer_size];
    std::memcpy(allocated_buffer, buffer, buffer_size);
    SDL_RWops* rw = SDL_RWFromConstMem(allocated_buffer, buffer_size);
    if (!rw)
        rb_raise(rb_eTypeError, "Given buffer is not valid!");
    Mix_Music* music = Mix_LoadMUS_RW(rw, 0);
    if (!music)
        rb_raise(rb_eTypeError, "Failed to create music from given buffer!");
    s_valid_music[music] = new MusicData(nullptr, allocated_buffer, rw);
    return c_music_to_value(music);
}
Exemplo n.º 30
-1
void gameover (SDL_Window *screen,uint *state) {

	SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE); // SDL_RENDERER_PRESENTVSYNC);
	//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	//SDL_RenderSetLogicalSize(renderer, 256, 192);
	SDL_SetRenderDrawColor(renderer,0,0,0,255);

	SDL_RWops *rw = SDL_RWFromMem(&_binary_graphics_gameover_png_start,
        (unsigned int)&_binary_graphics_gameover_png_end - (unsigned int)&_binary_graphics_gameover_png_start);
	SDL_Texture *gameover = IMG_LoadTexture_RW(renderer,rw,1);

    rw = SDL_RWFromMem(&_binary_sounds_GameOverV2N_ogg_start,
        (unsigned int)&_binary_sounds_GameOverV2N_ogg_end - (unsigned int)&_binary_sounds_GameOverV2N_ogg_start);
	Mix_Music *bso = Mix_LoadMUS_RW(rw,1);

	SDL_RenderClear(renderer);
	SDL_RenderCopy(renderer,gameover,NULL,NULL);

	/* Flip */
	SDL_RenderPresent(renderer);
	Mix_PlayMusic(bso, 0);

	/* Wait */
	sleep(12);

	/* Cleaning */
	Mix_FreeMusic (bso);
	SDL_DestroyTexture(gameover);
	SDL_DestroyRenderer(renderer);

	*state = 0;

}