Example #1
0
void Beeper::wait() // not sure what this is for
{
  int size;
  do {
    SDL_Delay(20); //wait 20ms
    SDL_LockAudio();
    size = beeps.size();
    SDL_UnlockAudio();
  } while (size > 0);

}
Example #2
0
void Beeper::wait()
{
    int size;
    do {
        SDL_Delay(10);
        SDL_LockAudio();
        size = beeps.size();
        SDL_UnlockAudio();
    } while (size > 0);
 
}
Example #3
0
void al_music_resume(void)
{
	SDL_LockAudio();

	if (audio_music_paused) {
		audio_music_paused=FALSE;
		audio_music_playing=TRUE;
	}

	SDL_UnlockAudio();
}
Example #4
0
static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
#ifdef AUDIO
	static const int selected_chan=1;
	int chan;
	int nsamp;
	if (mve_audio_canplay)
	{
		if (mve_audio_playing)
			SDL_LockAudio();

		chan = get_ushort(data + 2);
		nsamp = get_ushort(data + 4);
		if (chan & selected_chan)
		{
			/* HACK: +4 mveaudio_uncompress adds 4 more bytes */
			if (major == MVE_OPCODE_AUDIOFRAMEDATA) {
				if (mve_audio_compressed) {
					nsamp += 4;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */
				} else {
					nsamp -= 8;
					data += 8;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);
					memcpy(mve_audio_buffers[mve_audio_buftail], data, nsamp);
				}
			} else {
				mve_audio_buflens[mve_audio_buftail] = nsamp;
				mve_audio_buffers[mve_audio_buftail] = (short *)mve_alloc(nsamp);

				memset(mve_audio_buffers[mve_audio_buftail], 0, nsamp); /* XXX */
			}

			if (++mve_audio_buftail == TOTAL_AUDIO_BUFFERS)
				mve_audio_buftail = 0;

#ifndef WIN32
			if (mve_audio_buftail == mve_audio_bufhead)
				fprintf(stderr, "d'oh!  buffer ring overrun (%d)\n", mve_audio_bufhead);
#endif
		}

		if (mve_audio_playing)
			SDL_UnlockAudio();
	}
#endif

	return 1;
}
int _Mix_SetupChunk(int which, Mix_Chunk* chunk, int loops, int ticks, int fade_in, int loop_start)
{
	int loop_start_bytes;

	/* Lock the mixer while modifying the playing channels */
	SDL_LockAudio();
	{
		/* If which is -1, play on the first free channel */
		if ( which == -1 ) {
			which = get_available_channel();
			if ( which == -1 ) {
				Mix_SetError("No free channels available");
				which = -1;
			}
		}

        loop_start_bytes = milliseconds_to_bytes(loop_start);
        if (((Uint32) loop_start_bytes) >= chunk->alen) {
            loop_start_bytes = 0;
        }

		/* Queue up the audio data for this channel */
		if ( which >= 0 && which < num_channels ) {
			Uint32 sdl_ticks = SDL_GetTicks();
			if (Mix_Playing(which))
				_Mix_channel_done_playing(which);
			if (mix_channel[which].is_music) {
				mix_channel[which].music = NULL;
				mix_channel[which].sound = (Mix_Sound *) malloc(sizeof(Mix_Sound));
				mix_channel[which].is_music = SDL_FALSE;
			}
			mix_channel[which].sound->samples = chunk->abuf + loop_start_bytes;
			mix_channel[which].playing = chunk->alen - loop_start_bytes;
			mix_channel[which].looping = loops;
			mix_channel[which].loop_start = loop_start_bytes;
			mix_channel[which].sound->chunk = chunk;
			mix_channel[which].paused = 0;
			mix_channel[which].expire = (ticks>0) ? (sdl_ticks + ticks) : 0;
			if (fade_in){
				mix_channel[which].fading = MIX_FADING_IN;
				mix_channel[which].sound->fade_volume = mix_channel[which].volume;
				mix_channel[which].fade_volume_reset = mix_channel[which].volume;
				mix_channel[which].volume = 0;
				mix_channel[which].sound->fade_length = (Uint32)fade_in;
				mix_channel[which].sound->start_time = mix_channel[which].sound->ticks_fade = sdl_ticks;
			} else {
				mix_channel[which].fading = MIX_NO_FADING;
				mix_channel[which].sound->start_time = sdl_ticks;
			}
		}
	}
	SDL_UnlockAudio();
	return(which);
}
Example #6
0
void native_midi_stop()
{
    if (currentsong) {
        SDL_PauseAudio(1);
        SDL_UnlockAudio();
        MusicPlayerStop(currentsong->player);
        currentsong = NULL;
        SDL_LockAudio();
        SDL_PauseAudio(0);
    }
}
Example #7
0
void
SNDDMA_Shutdown (void)
{
    if (snd_inited) {
        SDL_PauseAudio (1);
        SDL_UnlockAudio ();
        SDL_CloseAudio ();
        snd_inited = 0;
        shm = NULL;
    }
}
Example #8
0
static void WriteVolume (int channel,int volume)
{
	if (!sound_on ||
		!channel_on[channel] || invalidfreq[channel])
		volume=0;
	volume=volume*mastervolume/15;
	SDL_LockAudio();	
	soundState.amp[channel] = volume;
	SDL_UnlockAudio();
	
}
Example #9
0
void FxSynth::playSfx(SynthCode* pCode, float volume, bool dontAbort)
{
	SDL_LockAudio();
	if(!m_pInstance->m_dontAbort)
	{
		m_pInstance->m_pCurrentCode = pCode;
		m_pInstance->m_volume = volume;
		m_pInstance->m_dontAbort = dontAbort;
	}
	SDL_UnlockAudio();
}
Example #10
0
int Mix_PlayingMusic(void)
{
	int playing = 0;

	SDL_LockAudio();
	if ( music_playing ) {
		playing = music_loops || music_internal_playing();
	}
	SDL_UnlockAudio();

	return(playing);
}
Example #11
0
Mix_Fading Mix_FadingMusic(void)
{
	Mix_Fading fading = MIX_NO_FADING;

	SDL_LockAudio();
	if ( music_playing ) {
		fading = music_playing->fading;
	}
	SDL_UnlockAudio();

	return(fading);
}
Example #12
0
void wxSoundBackendSDL::Stop()
{
    SDL_LockAudio();
    SDL_PauseAudio(1);
    m_playing = false;
    if (m_data)
    {
        m_data->DecRef();
        m_data = NULL;
    }
    SDL_UnlockAudio();
}
Example #13
0
/* Fade in a sound on a channel, over ms milliseconds */
int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int ticks)
{
	int i;

	/* Don't play null pointers :-) */
	if ( chunk == NULL ) {
		return(-1);
	}
	if ( !checkchunkintegral(chunk)) {
		Mix_SetError("Tried to play a chunk with a bad frame");
		return(-1);
	}

	/* Lock the mixer while modifying the playing channels */
	SDL_LockAudio();
	{
		/* If which is -1, play on the first free channel */
		if ( which == -1 ) {
			for ( i=reserved_channels; i<num_channels; ++i ) {
				if ( mix_channel[i].playing <= 0 )
					break;
			}
			if ( i == num_channels ) {
				which = -1;
			} else {
				which = i;
			}
		}

		/* Queue up the audio data for this channel */
		if ( which >= 0 && which < num_channels ) {
			Uint32 sdl_ticks = SDL_GetTicks();
			if (Mix_Playing(which))
				_Mix_channel_done_playing(which);
			mix_channel[which].samples = chunk->abuf;
			mix_channel[which].playing = chunk->alen;
			mix_channel[which].looping = loops;
			mix_channel[which].chunk = chunk;
			mix_channel[which].paused = 0;
			mix_channel[which].fading = MIX_FADING_IN;
			mix_channel[which].fade_volume = mix_channel[which].volume;
			mix_channel[which].fade_volume_reset = mix_channel[which].volume;
			mix_channel[which].volume = 0;
			mix_channel[which].fade_length = (Uint32)ms;
			mix_channel[which].start_time = mix_channel[which].ticks_fade = sdl_ticks;
			mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0;
		}
	}
	SDL_UnlockAudio();

	/* Return the channel on which the sound is being played */
	return(which);
}
void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len), void *arg)
{
	SDL_LockAudio();
	if ( mix_func != NULL ) {
		music_compat_data = arg;
		mix_compat_music = mix_func;
	} else {
		music_compat_data = NULL;
		mix_music = NULL;
	}
	SDL_UnlockAudio();
}
Example #15
0
void Mix_HookMusic(void (*mix_func)(void *udata), void *arg)
{
	SDL_LockAudio();
	if ( mix_func != NULL ) {
		music_data = arg;
		mix_music = mix_func;
	} else {
		music_data = NULL;
		mix_music = NULL;
	}
	SDL_UnlockAudio();
}
Example #16
0
static int Clear(SexyAL_device *device)
{
 SDLWrap *sw = (SDLWrap *)device->private_data;
 SDL_LockAudio();

 SDL_PauseAudio(1);
 sw->StartPaused = 1;
 sw->BufferRead = sw->BufferWrite = sw->BufferIn = 0;

 SDL_UnlockAudio();
 return(1);
}
Example #17
0
int Mix_HaltMusic(void)
{
	SDL_LockAudio();
	if ( music_playing ) {
		music_internal_halt();
		if ( music_finished_hook ) {
			music_finished_hook();
		}
	}
	SDL_UnlockAudio();

	return(0);
}
Example #18
0
void AudioEngine::setAudioEnabled(bool bEnabled)
{
    SDL_LockAudio();
    lock_guard lock(m_Mutex);
    AVG_ASSERT(m_AudioSources.empty());
    m_bEnabled = bEnabled;
    if (m_bEnabled) {
        play();
    } else {
        pause();
    }
    SDL_UnlockAudio();
}
/* Add your own music player or mixer function.
   If 'mix_func' is NULL, the default music player is re-enabled.
 */
void Mix_HookMusicCh(void (*mix_func)(void *udata, Mix_Music *music_playing, Uint8 *stream, int len, int channel),
                                                                void *arg)
{
	SDL_LockAudio();
	if ( mix_func != NULL ) {
		music_data = arg;
		mix_music = mix_func;
	} else {
		music_data = NULL;
		mix_music = music_mixer;
	}
	SDL_UnlockAudio();
}
Example #20
0
void
MPEGaudio:: Stop(void)
{
    if ( valid_stream ) {
        SDL_LockAudio();
        playing = false;
        SDL_UnlockAudio();
#ifdef THREADED_AUDIO
        StopDecoding();
#endif
    }
    ResetPause();
}
Example #21
0
void Audio::Silence ()
{
return;
#if 0
    if (!IsAvailable())
        return;

    SDL_LockAudio();
    memset(m_pbStart, 0x00, m_pbEnd-m_pbStart);
    m_pbNow = m_pbEnd;
    SDL_UnlockAudio();
#endif
}
Example #22
0
void GameAudio::playSound(std::string choice, float volume) {
	if(sounds.find(choice) == sounds.end())
		gameSystem->log(GameSystem::LOG_FATAL, std::string("Non-existent sound " + choice + " requested."));

	GameSoundPlaying playingSound;
	playingSound.sound = &sounds[choice];
	playingSound.volume = volume;
	playingSound.position = 0;

	SDL_LockAudio();
	effectsPlaying.push_back(playingSound);
	SDL_UnlockAudio();
}
Example #23
0
/**
 * writeSoundBuffer(): Write the sound buffer to the audio output.
 * @param dumpBuf Sound dumping buffer.
 * @return 1 on success.
 */
int Audio_SDL::writeSoundBuffer(void *dumpBuf)
{
	struct timespec rqtp = {0, 1000000};
	
	SDL_LockAudio();
	
	// TODO: Fix dumpBuf support.
#if 0
	if (dumpBuf)
	{
		if (m_stereo)
			dumpSoundStereo(dumpBuf, m_segLength);
		else
			dumpSoundMono(dumpBuf, m_segLength);
	}
#endif /* 0 */
	
	if (m_stereo)
	{
#ifdef GENS_X86_ASM
		if (CPU_Flags & CPUFLAG_MMX)
			writeSoundStereo_MMX(Seg_L, Seg_R, reinterpret_cast<short*>(pMsndOut), m_segLength);
		else
#endif
			writeSoundStereo(reinterpret_cast<short*>(pMsndOut), m_segLength);
	}
	else
	{
#ifdef GENS_X86_ASM
		if (CPU_Flags & CPUFLAG_MMX)
			writeSoundMono_MMX(Seg_L, Seg_R, reinterpret_cast<short*>(pMsndOut), m_segLength);
		else
#endif
			writeSoundMono(reinterpret_cast<short*>(pMsndOut), m_segLength);
	}
	
	memcpy(audiobuf + audio_len, pMsndOut, m_segLength * 4);
	audio_len += m_segLength * 4;
	
	SDL_UnlockAudio();
	
	// TODO: Figure out if there's a way to get rid of this.
	while (audio_len > 1024 * 2 * 2 * 4)
	{
		nanosleep(&rqtp, NULL);	
		if (fast_forward)
			audio_len = 1024;
	} //SDL_Delay(1); 
	
	return 1;
}
Example #24
0
/** Start a mod music channel */
static glui32 play_mod(schanid_t chan, long len)
{
    FILE *file;
    char *tn;
    char *tempdir;
    int music_busy;

    chan->status = CHANNEL_MUSIC;
    /* The fscking mikmod lib want to read the mod only from disk! */
    tempdir = getenv("TEMP");
    if (tempdir == NULL) tempdir = ".";
    tn = tempnam(tempdir, "gargtmp");
    file = fopen(tn, "wb");
    fwrite(chan->sdl_memory, 1, len, file);
    fclose(file);
    chan->music = Mix_LoadMUS(tn);
    remove(tn);
    free(tn);
    music_busy = Mix_PlayingMusic();
    if (music_busy)
        gli_strict_warning("MOD player already in use");
    if (!music_busy && chan->music)
    {
        SDL_LockAudio();
        music_channel = chan;
        SDL_UnlockAudio();
        Mix_VolumeMusic(chan->volume);
        Mix_HookMusicFinished(&music_completion_callback);
        if (Mix_PlayMusic(chan->music, chan->loop-1) >= 0)
            return 1;
    }
    gli_strict_warning("play mod failed");
    gli_strict_warning(Mix_GetError());
    SDL_LockAudio();
    cleanup_channel(chan);
    SDL_UnlockAudio();
    return 0;
}
Example #25
0
File: main.c Project: pikhq/cmako
void write_sound(uint8_t sample)
{
	if(sound_playing == -1)
		return;

	if(!inited_sdl)
		init_sdl();

	if(!sound_playing) {
		sound_playing = 1;
		SDL_PauseAudio(0);
	}
	SDL_LockAudio();
	while((snd_buf_w+1) % 1024 == snd_buf_r) {
		SDL_UnlockAudio();
		SDL_Delay(0);
		SDL_LockAudio();
	}
	snd_buf_w++;
	snd_buf_w %= 1024;
	snd_buf[snd_buf_w] = sample;
	SDL_UnlockAudio();
}
Example #26
0
void glk_schannel_stop(schanid_t chan)
{
    if (!chan)
    {
        gli_strict_warning("schannel_stop: invalid id.");
        return;
    }
    SDL_LockAudio();
    chan->buffered = 0;
    SDL_UnlockAudio();
    switch (chan->status)
    {
        case CHANNEL_SOUND:
            Mix_HaltChannel(chan->sdl_channel);
            break;
        case CHANNEL_MUSIC:
            Mix_HaltMusic();
            break;
    }
    SDL_LockAudio();
    cleanup_channel(chan);
    SDL_UnlockAudio();
}
Example #27
0
void Sound::Play()
{
    SDL_LockAudio();
    int channel = Mix_PlayChannel(-1, chunk, 0);
    if (channel == -1) {
        SDL_Log("No available channel for sound.");
    }
    else {
        playingSounds.reserve(channel + 1);
        playingSounds[channel] = shared_from_this();
        //SDL_Log("Sound is playing on channel %d", channel);
    }
    SDL_UnlockAudio();
}
Example #28
0
void
MPEGaudio:: Stop(void)
{
    if ( valid_stream ) {
        if ( sdl_audio )
            SDL_LockAudio();

        playing = false;

        if ( sdl_audio )
            SDL_UnlockAudio();
    }
    ResetPause();
}
Example #29
0
static void SDL_AudioCallbackX(void *, Uint8 *stream, int len)
{
    SDL_LockAudio();
    //short *target = (short *) stream;
    g_audioBuffer_lock.Lock();
    unsigned ate = len; // number of bytes
    if(ate > g_audioBuffer.size())
        ate = (unsigned)g_audioBuffer.size();
    for(unsigned a = 0; a < ate; ++a)
        stream[a] = g_audioBuffer[a];
    g_audioBuffer.erase(g_audioBuffer.begin(), g_audioBuffer.begin() + ate);
    g_audioBuffer_lock.Unlock();
    SDL_UnlockAudio();
}
Example #30
0
void Sound::deinit()
{
	playing = false;

	if(mSampleData != NULL)
	{
		SDL_LockAudio();
		delete[] mSampleData;
		mSampleData = NULL;
		mSampleLength = 0;
		mSamplePos = 0;
		SDL_UnlockAudio();
	}
}