本文整理汇总了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);
}
示例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();
}
示例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
}
示例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;
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例10: SDL_Delay
void Beeper::wait()
{
int size;
do {
SDL_Delay(10);
SDL_LockAudio();
size = beeps.size();
SDL_UnlockAudio();
} while (size > 0);
}
示例11: SDL_Delay
void Synth::wait()
{
int size;
do {
SDL_Delay(20);
SDL_LockAudio();
size = beeps.size();
SDL_UnlockAudio();
} while (size > 0);
}
示例12: SDL_LockAudio
void AudioSdl::stopProcessing()
{
if( SDL_GetAudioStatus() == SDL_AUDIO_PLAYING )
{
m_stopSemaphore.acquire();
SDL_LockAudio();
SDL_PauseAudio( 1 );
SDL_UnlockAudio();
}
}
示例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();
}
示例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();
}
示例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);
}