当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_LockAudio函数代码示例

本文整理汇总了C++中SDL_LockAudio函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_LockAudio函数的具体用法?C++ SDL_LockAudio怎么用?C++ SDL_LockAudio使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_LockAudio函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Mix_GroupChannel

/* 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);
}
开发者ID:jcemelanda,项目名称:wormux,代码行数:11,代码来源:mixer.c

示例2: fprintf

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();
	
}
开发者ID:danthemango,项目名称:Kitten-Pirateer,代码行数:55,代码来源:Jukebox.cpp

示例3: while

	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
	}
开发者ID:BackupTheBerlios,项目名称:gltron-svn,代码行数:55,代码来源:SourceMusic.cpp

示例4: sdl_audio_write

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;
}
开发者ID:AbelFlos,项目名称:RetroArch,代码行数:42,代码来源:sdl_audio.c

示例5: WriteVolume

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();
	
}
开发者ID:CrashSerious,项目名称:ColecoEm,代码行数:11,代码来源:AdamSDLSound.c

示例6: native_midi_stop

void native_midi_stop()
{
    if (currentsong) {
        SDL_PauseAudio(1);
        SDL_UnlockAudio();
        MusicPlayerStop(currentsong->player);
        currentsong = NULL;
        SDL_LockAudio();
        SDL_PauseAudio(0);
    }
}
开发者ID:lighthouse64,项目名称:PGE-Project,代码行数:11,代码来源:native_midi_macosx.c

示例7: SDL_Delay

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);

}
开发者ID:fpdotmonkey,项目名称:french-horn-bot,代码行数:11,代码来源:tones.cpp

示例8: audio_data_handler

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;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:54,代码来源:mveplay.c

示例9: SDL_LockAudio

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;
}
开发者ID:kostyll,项目名称:libavg,代码行数:11,代码来源:AudioEngine.cpp

示例10: SDL_Delay

void Beeper::wait()
{
    int size;
    do {
        SDL_Delay(10);
        SDL_LockAudio();
        size = beeps.size();
        SDL_UnlockAudio();
    } while (size > 0);
 
}
开发者ID:farlepet,项目名称:chip-8,代码行数:11,代码来源:audio.cpp

示例11: SDL_Delay

void Synth::wait()
{
    int size;
    do {
        SDL_Delay(20);
        SDL_LockAudio();
        size = beeps.size();
        SDL_UnlockAudio();
    } while (size > 0);

}
开发者ID:eriser,项目名称:audio-1,代码行数:11,代码来源:Synth.cpp

示例12: SDL_LockAudio

void AudioSdl::stopProcessing()
{
	if( SDL_GetAudioStatus() == SDL_AUDIO_PLAYING )
	{
		m_stopSemaphore.acquire();

		SDL_LockAudio();
		SDL_PauseAudio( 1 );
		SDL_UnlockAudio();
	}
}
开发者ID:bhattigurjot,项目名称:lmms,代码行数:11,代码来源:AudioSdl.cpp

示例13: al_music_resume

void al_music_resume(void)
{
	SDL_LockAudio();

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

	SDL_UnlockAudio();
}
开发者ID:prophile,项目名称:dim3,代码行数:11,代码来源:al_music.c

示例14: SDL_LockAudio

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();
}
开发者ID:exoticorn,项目名称:spidr,代码行数:11,代码来源:fxsynth.cpp

示例15: _Mix_SetupChunk

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);
}
开发者ID:segafan,项目名称:wmelite_hcdaniel-dependencies-repo,代码行数:54,代码来源:mixer.c


注:本文中的SDL_LockAudio函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。