Ejemplo n.º 1
0
void AudioMixer::playACMMusic(std::string filename, bool loop)
{
    Mix_HookMusic(NULL, NULL);
    auto acm = ResourceManager::acmFileType(Game::getInstance()->settings()->musicPath()+filename);
    if (!acm) return;
    _loop = loop;
    musicCallback = std::bind(&AudioMixer::_musicCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
    acm->init();
    acm->rewind();
    Mix_HookMusic(myMusicPlayer, (void *)(acm.get()));
}
Ejemplo n.º 2
0
void SDLAudio::music_callback(void *udata, unsigned short *stream, int len) {
	SDLAudio *driver = (SDLAudio *)udata;
	SDL_mutexP(driver->OurMutex);

	do {

		// TODO: conversion? mutexes? sanity checks? :)
		int num_samples = len / 2;
		int cnt = driver->MusicReader->read_samples(( short* ) stream, num_samples);

		// Done?
		if (cnt == num_samples)
			break;

		// TODO: this shouldn't be in the callback (see also the openal thread)
		printMessage("SDLAudio", "Playing Next Music\n", WHITE );
		core->GetMusicMgr()->PlayNext();

		stream = stream + cnt;
		len = len - (cnt * 2);

		if (!driver->MusicPlaying) {
			printMessage( "SDLAudio", "No Other Music to play\n", WHITE );
			memset(stream, 0, len);
			Mix_HookMusic(NULL, NULL);
			break;
		}

	} while(true);

	SDL_mutexV(driver->OurMutex);
}
Ejemplo n.º 3
0
static void OPL_SDL_Shutdown(void)
{
    Mix_HookMusic(NULL, NULL);

    if (sdl_was_initialized)
    {
        Mix_CloseAudio();
        SDL_QuitSubSystem(SDL_INIT_AUDIO);
        OPL_Queue_Destroy(callback_queue);
        free(mix_buffer);
        sdl_was_initialized = 0;
    }

/*
    if (opl_chip != NULL)
    {
        OPLDestroy(opl_chip);
        opl_chip = NULL;
    }
    */

    if (callback_mutex != NULL)
    {
        SDL_DestroyMutex(callback_mutex);
        callback_mutex = NULL;
    }

    if (callback_queue_mutex != NULL)
    {
        SDL_DestroyMutex(callback_queue_mutex);
        callback_queue_mutex = NULL;
    }
}
Ejemplo n.º 4
0
bool SDLAudio::Play()
{
	MusicPlaying = true;
	Mix_HookMusic((void (*)(void*, Uint8*, int))music_callback, this);
	// TODO
	return true;
}
Ejemplo n.º 5
0
void FlcPlayer::initAudio(Uint16 format, Uint8 channels)
{
	int err;

	err = Mix_OpenAudio(_audioData.sampleRate, format, channels, _audioFrameSize *2);
	_videoDelay = 1000 / (_audioData.sampleRate / _audioFrameSize );

	if (err)
	{
		printf("Failed to open audio (%d)\n", err);
		return;
	}

	/* Start runnable */
	_audioData.sharedLock = SDL_CreateSemaphore(1);

	_audioData.loadingBuffer = new AudioBuffer();
	_audioData.loadingBuffer->currSamplePos = 0;
	_audioData.loadingBuffer->sampleCount = 0;
	_audioData.loadingBuffer->samples = (Sint16 *)malloc(_audioFrameSize * 2);
	_audioData.loadingBuffer->sampleBufSize = _audioFrameSize * 2;

	_audioData.playingBuffer = new AudioBuffer();
	_audioData.playingBuffer->currSamplePos = 0;
	_audioData.playingBuffer->sampleCount = 0;
	_audioData.playingBuffer->samples = (Sint16 *)malloc(_audioFrameSize * 2);
	_audioData.playingBuffer->sampleBufSize = _audioFrameSize * 2;

	Mix_HookMusic(FlcPlayer::audioCallback, &_audioData);
}
Ejemplo n.º 6
0
void FlcPlayer::deInitAudio()
{
	if (_game)
	{
		Mix_HookMusic(NULL, NULL);
		Mix_CloseAudio();
		_game->initAudio();
	}
  else if(_audioData.sharedLock)
		SDL_DestroySemaphore(_audioData.sharedLock);

	if (_audioData.loadingBuffer)
	{
		free(_audioData.loadingBuffer->samples);
		delete _audioData.loadingBuffer;
		_audioData.loadingBuffer = 0;
	}

	if (_audioData.playingBuffer)
	{
		free(_audioData.playingBuffer->samples);
		delete _audioData.playingBuffer;
		_audioData.playingBuffer = 0;
	}
	
}
Ejemplo n.º 7
0
bool SDLAudio::Stop()
{
	// TODO
	MusicPlaying = false;
	Mix_HookMusic(NULL, NULL);
	return true;
}
Ejemplo n.º 8
0
int AVIWrapper::play(bool click_flag)
{
    int ret = 0;
    time_start = 0;
    status = AVI_PLAYING;
    if (v_stream)
        thread_id = SDL_CreateThread(::playVideo, this);

    if (a_stream)
        Mix_HookMusic(::audioCallback, this);

    bool done_flag = false;
    while (!(done_flag & click_flag) && status == AVI_PLAYING) {
        SDL_Event event;

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_RETURN
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_KP_ENTER
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_SPACE
                    || ((SDL_KeyboardEvent*) &event)->keysym.sym == SDLK_ESCAPE)
                    done_flag = true;

                break;
            case SDL_QUIT:
                ret = 1;
            case SDL_MOUSEBUTTONDOWN:
                done_flag = true;
                break;
            default:
                break;
            }
        }
        SDL_Delay(10);
    }

    status = AVI_STOP;
    if (v_stream)
        SDL_WaitThread(thread_id, NULL);

    if (a_stream)
        Mix_HookMusic(NULL, NULL);

    return ret;
}
Ejemplo n.º 9
0
void M_StopMusicStream (musicStream_t* userdata)
{
	if (userdata != nullptr)
		userdata->playing = false;
	music.playingStream = false;
	music.interruptStream = false;
	Mix_HookMusic(nullptr, nullptr);
}
Ejemplo n.º 10
0
AudioMixer::~AudioMixer()
{
    for (auto& x: _sfx)
    {
        Mix_FreeChunk(x.second);
    }
    Mix_HookMusic(NULL,NULL);
    Mix_CloseAudio();
}
Ejemplo n.º 11
0
void SoundEngine::StopMusic()
{
    if (nosound)
    {
        return;
	}
    Mix_HookMusic(NULL, NULL);
    musicDecoder.Close();
}
Ejemplo n.º 12
0
SDLAudio::~SDLAudio(void)
{
	// TODO
	delete ambim;
	Mix_HookMusic(NULL, NULL);
	FreeBuffers();
	SDL_DestroyMutex(OurMutex);
	Mix_ChannelFinished(NULL);
}
Ejemplo n.º 13
0
void sound_init(void(*sound_cb)(void *udata, Uint8 *stream, int len))
{
    if(Mix_OpenAudio(FREQ,AUDIO_S16SYS,CHANNELS,CHUNKSIZE)==-1)
    {
	printf("Mix_OpenAudio: %s\n", Mix_GetError());
	exit(2);
    }
    Mix_AllocateChannels(N_CHANNELS);
    Mix_HookMusic(sound_cb,NULL);
}
Ejemplo n.º 14
0
static void M_PlayMusicStream (musicStream_t* userdata)
{
	if (userdata->playing)
		return;

	M_Stop();

	userdata->playing = true;
	music.playingStream = true;
	Mix_HookMusic((void (*)(void*, Uint8*, int)) M_MusicStreamCallback, userdata);
}
Ejemplo n.º 15
0
/**
 * Resumes music playback when game gains focus.
 */
void Music::resume()
{
#ifndef __NO_MUSIC
	if (!Options::mute)
	{
		Mix_ResumeMusic();
		if (Mix_GetMusicType(0) == MUS_NONE)
			Mix_HookMusic(AdlibMusic::player, NULL);
	}
#endif
}
Ejemplo n.º 16
0
/**
 * Stops all music playing.
 */
void Music::stop()
{
#ifndef __NO_MUSIC
	if (!Options::mute)
	{
		func_mute();
		Mix_HookMusic(NULL, NULL);
		Mix_HaltMusic();
	}
#endif
}
Ejemplo n.º 17
0
/**
 * Pauses music playback when game loses focus.
 */
void Music::pause()
{
#ifndef __NO_MUSIC
	if (!Options::mute)
	{
		Mix_PauseMusic();
		if (Mix_GetMusicType(0) == MUS_NONE)
			Mix_HookMusic(NULL, NULL);
	}
#endif
}
Ejemplo n.º 18
0
void AudioMixer::_movieCallback(void *udata, uint8_t *stream, uint32_t len)
{
    auto pmve = (MvePlayer*)(udata);
    if (pmve->samplesLeft() <= 0)
    {
        Logger::debug("AUDIO") << "buffer underrun?" << std::endl;
        Mix_HookMusic(NULL, NULL);
        return;
    }

    pmve->getAudio(stream, len);
}
Ejemplo n.º 19
0
/**
 * Plays the contained music track.
 * @param loop Amount of times to loop the track. -1 = infinite
 */
void AdlibMusic::play(int loop) const
{
#ifndef __NO_MUSIC
	if (!Options::mute)
	{
		stop();
		func_setup_music((unsigned char*)_data, _size);
		func_set_music_volume(127 * _volume);
		Mix_HookMusic(player, (void*)this);
	}
#endif
}
Ejemplo n.º 20
0
void ADLPlayer::setMusic(bool value) {
	musicOn = value;

	if(musicOn) {
		changeMusic(MUSIC_RANDOM);
	} else {
	    Mix_HookMusic(NULL, NULL);

	    delete pSoundAdlibPC;
	    pSoundAdlibPC = NULL;
	}
}
Ejemplo n.º 21
0
///////////////////////////////////////////////////////////////////////////
//
//      SD_Startup() - starts up the Sound Mgr
//              Detects all additional sound hardware and installs my ISR
//
///////////////////////////////////////////////////////////////////////////
void
SD_Startup(void)
{
    int     i;

    if (SD_Started)
        return;

    if((audioMutex = SDL_CreateMutex()) == NULL)
    {
        printf("Unable to create audio mutex\n");
        return;
    }

    if(Mix_OpenAudio(param_samplerate, AUDIO_S16, 2, param_audiobuffer))
    {
        printf("Unable to open audio: %s\n", Mix_GetError());
        return;
    }

    Mix_ReserveChannels(2);  // reserve player and boss weapon channels
    Mix_GroupChannels(2, MIX_CHANNELS-1, 1); // group remaining channels

    // Init music
    if(YM3812Init(1,3579545,param_samplerate))
    {
        printf("Unable to create virtual OPL!!\n");
    }

    for(i=1; i<0xf6; i++)
        YM3812Write(oplChip,i,0,MAX_VOLUME);

    YM3812Write(oplChip,1,0x20,MAX_VOLUME); // Set WSE=1
//    YM3812Write(0,8,0); // Set CSM=0 & SEL=0		 // already set in for statement

    samplesPerMusicTick = param_samplerate / MUSIC_RATE;    // SDL_t0FastAsmService played at 700Hz
    Mix_HookMusic(SDL_IMFMusicPlayer, 0);
    Mix_ChannelFinished(SD_ChannelFinished);
    AdLibPresent = true;
    SoundBlasterPresent = true;

    alTimeCount = 0;

    SD_SetSoundMode(sdm_Off);
    SD_SetMusicMode(smm_Off);

    SD_Started = true;

    SoundInfo.Init();
    SoundSeq.Init();
}
Ejemplo n.º 22
0
void sound_unmute(void){
#ifdef Z80_EMULATED
//puts("sound_unmute");
	if (sound_muted&0x2)
	{
#ifdef MENU_MUSIC
		SDL_PauseAudio(1);
		Mix_HookMusic(&update_sdl_stream,NULL);
#endif
		SDL_PauseAudio(0);
	}
	sound_muted=0;
#endif
}
Ejemplo n.º 23
0
void sound_enable(void) {
#ifdef Z80_EMULATED
//puts("sound_enable");
	if ((sound_muted&0x1)&&(!(sound_muted&0x2)))
	{
#ifdef MENU_MUSIC
		SDL_PauseAudio(1);
		Mix_HookMusic(&update_sdl_stream,NULL);
#endif
		SDL_PauseAudio(0);
	}
	sound_muted&=0xFE;
#endif
}
Ejemplo n.º 24
0
bool Sound_initialization(void)
{
    char SoundcardName[256];
	int audio_rate = 44100;
	int audio_channels = 2;
	int audio_bufsize = AUDIO_BUFFER;
	Uint16 audio_format = AUDIO_S16;
	SDL_version compile_version;

	sound_enabled=true;
	fprintf (stderr, "Initializing SDL_mixer.\n");

	int flags = MIX_INIT_OGG | MIX_INIT_MOD;
	int initted = Mix_Init(flags);
	if (initted & flags != flags) {
		printf("Mix_Init: Failed to init required ogg and mod support!\n");
		printf("Mix_Init: %s\n", Mix_GetError());
		sound_enabled = false;
		return false;
	}

	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_bufsize))  {
	  fprintf (stderr, "Unable to open audio: %s\n", Mix_GetError());
	  sound_enabled=false;
	  fprintf (stderr, "Running the game without audio.\n");
	  return false;	
	} /* if */ 

	SDL_AudioDriverName (SoundcardName, sizeof (SoundcardName));
	Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
	fprintf (stderr, "    opened %s at %d Hz %d bit %s, %d bytes audio buffer\n",
			 SoundcardName, audio_rate, audio_format & 0xFF,
			 audio_channels > 1 ? "stereo" : "mono", audio_bufsize);
	MIX_VERSION (&compile_version);
	fprintf (stderr, "    compiled with SDL_mixer version: %d.%d.%d\n",
			 compile_version.major,
			 compile_version.minor,
			 compile_version.patch);
	fprintf (stderr, "    running with SDL_mixer version: %d.%d.%d\n",
			 Mix_Linked_Version()->major,
			 Mix_Linked_Version()->minor,
			 Mix_Linked_Version()->patch);

	Sound_Init();
	Mix_HookMusic(myMusicPlayer, 0);

	return true;
} /* Sound_init */ 
Ejemplo n.º 25
0
SoundEngine::~SoundEngine()
{
    if (nosound)
    {
        return;
    }

    // Stop all playback
    Mix_HaltChannel(-1);
    Mix_HookMusic(0, 0);

    // Clean up the sound cache
    for_each(soundCache.begin(), soundCache.end(), SoundCacheCleaner());

    Mix_CloseAudio();
}
Ejemplo n.º 26
0
bool SDLAudio::ReleaseStream(int stream, bool HardStop)
{
	if (stream != 0) {
		return false;
	}

	print("SDLAudio releasing stream\n");

	(void)HardStop;

	assert(!MusicPlaying);

	Mix_HookMusic(NULL, NULL);
	FreeBuffers();

	return true;
}
Ejemplo n.º 27
0
game::game()
{
	SDL_Init(SDL_INIT_VIDEO);
	SDL_WM_SetCaption( "Bass Invaders", NULL );
	pScreen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_HWSURFACE|SDL_DOUBLEBUF);
	bg = new background(SCREEN_WIDTH, SCREEN_HEIGHT);
	SoundSource * source = new SoundSource(INSERT_YOUR_SONG_PATH_HERE);
    Mix_OpenAudio( source->spec.freq, MIX_DEFAULT_FORMAT, source->spec.channels, source->spec.samples);
	int historyBuffer = 1.0 / ((double)(source->spec.samples)/(double)(source->spec.freq));
	au = new audio_processor (source->spec.freq, source->spec.samples*4, BANDS, historyBuffer, SENSITIVITY );
    soundIter = new SoundSourceIterator(source, source->spec.samples*4);
    Mix_HookMusic(MusicPlayer, this);

	sprite *s = new sprite(this);
	sprite_list.push_back(s);
	SDL_Color c = {55, 255, 25};
	h = new hud("Batang.ttf", 20, c, pScreen);
}
Ejemplo n.º 28
0
PyObject *
_wrap_smpeg_new (PyObject *self, PyObject *args)
{
	   PyObject *py_e;
	   PyObject *py_v;
	   char     *filename;
	   int       audio;
	   
	   if (!PyArg_ParseTuple (args, "OOsi:new", &py_e, &py_v, &filename, &audio)) return NULL;
	   GLASSERT (py_e && py_e != Py_None);
	   GLASSERT (py_v && py_v != Py_None);
	   GLASSERT (filename);

	   KrEngine *engine = AS_PTR(KrEngine, py_e);
	   GLASSERT (engine);
	   
	   SDL_Surface *surface = AS_PTR(SDL_Surface, py_v);
	   GLASSERT (surface);
	   
	   SMPEG_Info info;
	   SMPEG *smpeg = SMPEG_new (filename, &info, 0);
	   GLASSERT (smpeg);

	   if (audio) {
			 SDL_AudioSpec spec;

			 SMPEG_enableaudio (smpeg, 0);

			 Mix_QuerySpec (&spec.freq, &spec.format, (int *)&spec.channels);
			 SMPEG_actualSpec(smpeg, &spec);

			 Mix_HookMusic (SMPEG_playAudioSDL, smpeg);
			 
			 SMPEG_enableaudio (smpeg, 1);
	   } else {
			 SMPEG_enableaudio (smpeg, 0);
	   }

	   SMPEG_setdisplay (smpeg, surface, NULL, NULL);

			 
	   return PyCObject_FromVoidPtr (smpeg, NULL);
}
Ejemplo n.º 29
0
void sound_mute(void){
#ifdef Z80_EMULATED
//puts("sound_mute");
	if (!(sound_muted&0x2))
	{
#ifdef MENU_MUSIC
		SDL_PauseAudio(1);
#ifdef DREAMCAST
		SDL_DC_RestoreSoundBuffer();
#endif
		Mix_HookMusic(NULL,NULL);
		SDL_PauseAudio(0);
		Mix_VolumeMusic(MUSIC_VOLUME);
#else
		SDL_PauseAudio(1);
#endif
	}
	sound_muted=0x3;
#endif
}
Ejemplo n.º 30
0
/**
 * @param sound The soundtrack to play
 */
void SoundEngine::PlayTrack(const string& sound)
{
    if (nosound == true)
    {
        return;
    }

    StopMusic();

    if (sound == "No theme")
    {
        PlayMusic();
        return;
    }

    if (musicDecoder.Open(sound))
    {
        musicFinished = false;
        Mix_HookMusic(MusicHook, reinterpret_cast<void*>(&musicFinished));
    }
}