コード例 #1
0
ファイル: mixer.c プロジェクト: jcemelanda/wormux
/* Change the group of a channel */
int Mix_GroupChannel(int which, int tag)
{
 if ( which < 0 || which > num_channels )
   return(0);

 SDL_LockAudio();
 mix_channel[which].tag = tag;
 SDL_UnlockAudio();
 return(1);
}
コード例 #2
0
void Jukebox::PlaySound(const char *file)
//Function to play the sound passed in a as a parameter.
{
	int index;
	SDL_AudioSpec wave;
	Uint8 *data;
	Uint32 dlen;
	SDL_AudioCVT cvt;

	/* Look for an empty (or finished) sound slot */
	for ( index=0; index<NUM_SOUNDS; ++index ) {
		
		if ( sounds[index].dpos == sounds[index].dlen ) {
			
			break;
			
		}
		
	}
	
	if ( index == NUM_SOUNDS ) {
	
		return;
	
	}

	/* Load the sound file and convert it to 16-bit stereo at 22kHz */
	if ( SDL_LoadWAV(file, &wave, &data, &dlen) == NULL ) {
		
		fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
		return;
		
	}
	
	SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq, AUDIO_S16, 2, 22050);
    cvt.buf = (Uint8*)malloc(dlen*cvt.len_mult);
	memcpy(cvt.buf, data, dlen);
	cvt.len = dlen;
	SDL_ConvertAudio(&cvt);
	SDL_FreeWAV(data);

	/* Put the sound data in the slot (it starts playing immediately) */
	if (sounds[index].data) {
		
		free(sounds[index].data);
		
	}
	
	SDL_LockAudio();
	sounds[index].data = cvt.buf;
	sounds[index].dlen = cvt.len_cvt;
	sounds[index].dpos = 0;
	SDL_UnlockAudio();
	
}
コード例 #3
0
	void SourceMusic::Idle(void) {
		if(_sample == NULL)
			return;
		
		// printf("idling\n");
		while( _isPlaying && 
					 (_read == _decoded || 
					 (_read - _decoded + _buffersize) % _buffersize >
					 _sample_buffersize ) )	{
			// if(_read == _decoded)	printf("_read == _decoded == %d\n", _read);
			// fill the buffer
			int count = Sound_Decode(_sample);
			// printf("adding %d bytes to buffer\n", count);
			if(count <= _buffersize - _decoded) {
				memcpy(_buffer + _decoded, _sample->buffer, count);
			} else {
				// wrapping around end of buffer (usually doesn't happen when 
				// _buffersize is a multiple of _sample_buffersize)
				// printf("wrapping around end of buffer\n");
				memcpy(_buffer + _decoded, _sample->buffer, _buffersize - _decoded);
				memcpy(_buffer, (Uint8*) _sample->buffer + _buffersize - _decoded,
							 count - (_buffersize - _decoded));
			}
			_decoded = (_decoded + count) % _buffersize;

			// check for end of sample, loop
			if((_sample->flags & SOUND_SAMPLEFLAG_ERROR) || 
			   (_sample->flags & SOUND_SAMPLEFLAG_EOF)) {
				// some error has occured, maybe end of sample reached
#ifndef macintosh
				SDL_SemWait(_sem);
#else
                SDL_LockAudio();
#endif
				// todo: let playback finish, because there's still data
				// in the buffer that has to be mixed
				CleanUp();
				// fprintf(stderr, "end of sample reached!\n");
				if(_loop) {
					// fprintf(stderr, "looping music\n");
					if(_loop != 255) 
						_loop--;
					CreateSample();
				} else {
					_isPlaying = 0;
					// todo: notify sound system (maybe load another song?)
				}
#ifndef macintosh
				SDL_SemPost(_sem);
#else
                SDL_UnlockAudio();
#endif
			}
		} // buffer has been filled
	}
コード例 #4
0
ファイル: sdl_audio.c プロジェクト: AbelFlos/RetroArch
static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
{
   sdl_audio_t *sdl = (sdl_audio_t*)data;

   ssize_t ret = 0;
   if (sdl->nonblock)
   {
      SDL_LockAudio();
      size_t avail = fifo_write_avail(sdl->buffer);
      size_t write_amt = avail > size ? size : avail;
      fifo_write(sdl->buffer, buf, write_amt);
      SDL_UnlockAudio();
      ret = write_amt;
   }
   else
   {
      size_t written = 0;
      while (written < size)
      {
         SDL_LockAudio();
         size_t avail = fifo_write_avail(sdl->buffer);

         if (avail == 0)
         {
            SDL_UnlockAudio();
            slock_lock(sdl->lock);
            scond_wait(sdl->cond, sdl->lock);
            slock_unlock(sdl->lock);
         }
         else
         {
            size_t write_amt = size - written > avail ? avail : size - written;
            fifo_write(sdl->buffer, (const char*)buf + written, write_amt);
            SDL_UnlockAudio();
            written += write_amt;
         }
      }
      ret = written;
   }

   return ret;
}
コード例 #5
0
ファイル: AdamSDLSound.c プロジェクト: CrashSerious/ColecoEm
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();
	
}
コード例 #6
0
void native_midi_stop()
{
    if (currentsong) {
        SDL_PauseAudio(1);
        SDL_UnlockAudio();
        MusicPlayerStop(currentsong->player);
        currentsong = NULL;
        SDL_LockAudio();
        SDL_PauseAudio(0);
    }
}
コード例 #7
0
ファイル: tones.cpp プロジェクト: fpdotmonkey/french-horn-bot
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);

}
コード例 #8
0
ファイル: mveplay.c プロジェクト: paud/d2x-xl
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;
}
コード例 #9
0
ファイル: AudioEngine.cpp プロジェクト: kostyll/libavg
int AudioEngine::addSource(AudioMsgQueue& dataQ, AudioMsgQueue& statusQ)
{
    SDL_LockAudio();
    lock_guard lock(m_Mutex);
    static int nextID = -1;
    nextID++;
    AudioSourcePtr pSrc(new AudioSource(dataQ, statusQ, m_AP.m_SampleRate));
    m_AudioSources[nextID] = pSrc;
    SDL_UnlockAudio();
    return nextID;
}
コード例 #10
0
ファイル: audio.cpp プロジェクト: farlepet/chip-8
void Beeper::wait()
{
    int size;
    do {
        SDL_Delay(10);
        SDL_LockAudio();
        size = beeps.size();
        SDL_UnlockAudio();
    } while (size > 0);
 
}
コード例 #11
0
ファイル: Synth.cpp プロジェクト: eriser/audio-1
void Synth::wait()
{
    int size;
    do {
        SDL_Delay(20);
        SDL_LockAudio();
        size = beeps.size();
        SDL_UnlockAudio();
    } while (size > 0);

}
コード例 #12
0
ファイル: AudioSdl.cpp プロジェクト: bhattigurjot/lmms
void AudioSdl::stopProcessing()
{
	if( SDL_GetAudioStatus() == SDL_AUDIO_PLAYING )
	{
		m_stopSemaphore.acquire();

		SDL_LockAudio();
		SDL_PauseAudio( 1 );
		SDL_UnlockAudio();
	}
}
コード例 #13
0
ファイル: al_music.c プロジェクト: prophile/dim3
void al_music_resume(void)
{
	SDL_LockAudio();

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

	SDL_UnlockAudio();
}
コード例 #14
0
ファイル: fxsynth.cpp プロジェクト: exoticorn/spidr
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();
}
コード例 #15
0
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);
}
コード例 #16
0
ファイル: music.c プロジェクト: iaco79/IrrGameDemo
int Mix_PlayingMusic(void)
{
	int playing = 0;

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

	return(playing);
}
コード例 #17
0
ファイル: sound_sdl.cpp プロジェクト: EEmmanuel7/wxWidgets
void wxSoundBackendSDL::Stop()
{
    SDL_LockAudio();
    SDL_PauseAudio(1);
    m_playing = false;
    if (m_data)
    {
        m_data->DecRef();
        m_data = NULL;
    }
    SDL_UnlockAudio();
}
コード例 #18
0
ファイル: music.c プロジェクト: iaco79/IrrGameDemo
Mix_Fading Mix_FadingMusic(void)
{
	Mix_Fading fading = MIX_NO_FADING;

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

	return(fading);
}
コード例 #19
0
ファイル: mixer.c プロジェクト: iaco79/IrrGameDemo
/* 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);
}
コード例 #20
0
ファイル: FAKE_mixer.c プロジェクト: arcadenea/fake_mixer
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();
}
コード例 #21
0
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();
}
コード例 #22
0
ファイル: sdl.cpp プロジェクト: BadyRaty/Mednafen-Core
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);
}
コード例 #23
0
ファイル: music.c プロジェクト: iaco79/IrrGameDemo
int Mix_HaltMusic(void)
{
	SDL_LockAudio();
	if ( music_playing ) {
		music_internal_halt();
		if ( music_finished_hook ) {
			music_finished_hook();
		}
	}
	SDL_UnlockAudio();

	return(0);
}
コード例 #24
0
ファイル: MPEGaudio.cpp プロジェクト: merusaia/Game
void
MPEGaudio:: Stop(void)
{
    if ( valid_stream ) {
        SDL_LockAudio();
        playing = false;
        SDL_UnlockAudio();
#ifdef THREADED_AUDIO
        StopDecoding();
#endif
    }
    ResetPause();
}
コード例 #25
0
ファイル: AudioEngine.cpp プロジェクト: kostyll/libavg
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();
}
コード例 #26
0
ファイル: Audio.cpp プロジェクト: libretro/libretro-simcoupe
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
}
コード例 #27
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();
}
コード例 #28
0
/* 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();
}
コード例 #29
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;
}
コード例 #30
0
ファイル: sndsdl.c プロジェクト: BeniEnge/as_son_of_hunkypunk
/** 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;
}