本文整理汇总了C++中SDL_MixAudio函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_MixAudio函数的具体用法?C++ SDL_MixAudio怎么用?C++ SDL_MixAudio使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_MixAudio函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nebu_assert
int SourceSample::Mix(Uint8 *data, int len) {
if(_buffer == NULL)
return 0;
int volume = (int)(_volume * SDL_MIX_MAXVOLUME);
nebu_assert(len < _buffersize);
if(len < _buffersize - _position) {
SDL_MixAudio(data, _buffer + _position, len, volume);
_position += len;
} else {
SDL_MixAudio(data, _buffer + _position, _buffersize - _position,
volume);
len -= _buffersize - _position;
// printf("end of sample reached!\n");
if(_loop) {
if(_loop != 255)
_loop--;
_position = 0;
SDL_MixAudio(data, _buffer + _position, len, volume);
_position += len;
} else {
_isPlaying = 0;
}
}
return 1;
}
示例2: sdlMix
void sdlMix(Uint8 *stream, int len, SoundDataRing* data, bool queueMode)
{
int mixed=0;
while(len>0 && data->size()>0)
{
QElement& elm = data->front();
int elm_left=elm.len-elm.pos;
//mix all that is possible from front then continue into next
if( len > elm_left)
{
SDL_MixAudio(stream+mixed, &elm.data[elm.pos], elm_left, SDL_MIX_MAXVOLUME);
//done with this one
data->pop();
//take rest from next element
len-=elm_left;
if (queueMode)mixed+=elm_left;
}
//take everything from this element
else
{
SDL_MixAudio(stream+mixed, &elm.data[elm.pos], len, SDL_MIX_MAXVOLUME);
elm.pos+=len;
len-=elm_left;
}
}
}
示例3: SDL_MixAudio
void SDLAudioDevice::real_callback(Uint8 *stream, int len)
{
// fprintf(stderr, "sdl cbk: %d bytes needed, size:%d\n", len, audio_offset);
if (len <= audio_offset) {
SDL_MixAudio(stream, (const Uint8 *)audio_buffer, len, SDL_MIX_MAXVOLUME);
audio_offset -= len;
if (audio_offset > 0) {
memcpy(audio_buffer, (audio_buffer + len), audio_offset);
}
else
audio_offset = 0;
}
else {
if (audio_offset > 0) {
SDL_MixAudio(stream, (const Uint8 *)audio_buffer, audio_offset, SDL_MIX_MAXVOLUME);
len -= audio_offset;
}
memset(stream + audio_offset, silence, len);
audio_offset = 0;
}
}
示例4: audioCallback
/**
* Callback used to provide data to the audio subsystem.
*
* @param userdata N/A
* @param stream Output stream
* @param len Length of data to be placed in the output stream
*/
void audioCallback (void * userdata, unsigned char * stream, int len) {
(void)userdata;
int count;
if (!music_paused) {
// Read the next portion of music into the audio stream
#if defined(USE_MODPLUG)
if (musicFile) ModPlug_Read(musicFile, stream, len);
#elif defined(USE_XMP)
if (xmp_get_player(xmpC, XMP_PLAYER_STATE) == XMP_STATE_PLAYING)
xmp_play_buffer(xmpC, stream, len, 0);
#endif
}
for (count = 0; count < 32; count++) {
if (sounds[count].data && (sounds[count].position >= 0)) {
// Add the next portion of the sound clip to the audio stream
if (len < sounds[count].length - sounds[count].position) {
// Play as much of the clip as possible
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, len,
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position += len;
} else {
// Play the remainder of the clip
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position,
sounds[count].length - sounds[count].position,
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position = -1;
}
}
}
return;
}
示例5: sdl_fill_audio
static void sdl_fill_audio( void *udata, uint8_t *stream, int len )
{
consumer_sdl self = udata;
// Get the volume
double volume = mlt_properties_get_double( self->properties, "volume" );
pthread_mutex_lock( &self->audio_mutex );
// Block until audio received
#ifdef __APPLE__
while ( self->running && len > self->audio_avail )
pthread_cond_wait( &self->audio_cond, &self->audio_mutex );
#endif
if ( self->audio_avail >= len )
{
// Place in the audio buffer
if ( volume != 1.0 )
SDL_MixAudio( stream, self->audio_buffer, len, ( int )( ( float )SDL_MIX_MAXVOLUME * volume ) );
else
memcpy( stream, self->audio_buffer, len );
// Remove len from the audio available
self->audio_avail -= len;
// Remove the samples
memmove( self->audio_buffer, self->audio_buffer + len, self->audio_avail );
}
else
{
// Just to be safe, wipe the stream first
memset( stream, 0, len );
// Mix the audio
SDL_MixAudio( stream, self->audio_buffer, self->audio_avail,
( int )( ( float )SDL_MIX_MAXVOLUME * volume ) );
// No audio left
self->audio_avail = 0;
}
// We're definitely playing now
self->playing = 1;
pthread_cond_broadcast( &self->audio_cond );
pthread_mutex_unlock( &self->audio_mutex );
}
示例6: my_play_sdl_audio_callback2
/*这个是从网上拷贝的加了缓冲区的音频回调函数, 说实话播放效果没听出有什么不同,不过避免了因为SDL
音频缓冲区过小而导致的段错误*/
void my_play_sdl_audio_callback2(void *userdata, Uint8 *stream, int max_len) {
AVCodecContext *aCodecCtx = (AVCodecContext *) userdata;
int len, len1, audio_size;
static uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
static unsigned int audio_buf_size = 0;
static unsigned int audio_buf_index = 0;
len = max_len;
while (len > 0) {
if (audio_buf_index >= audio_buf_size) {
/* We have already sent all our data; get more */
audio_size = ff_play_getaudiopkt2play((void *) audio_buf, max_len);
if (audio_size <= 0) {
/* If error, output silence */
audio_buf_size = 1024; // arbitrary?
memset(audio_buf, 0, audio_buf_size);
} else {
audio_buf_size = audio_size;
}
audio_buf_index = 0;
}
len1 = audio_buf_size - audio_buf_index;
if (len1 > len)
len1 = len;
SDL_MixAudio(stream,audio_buf,len1,SDL_MIX_MAXVOLUME);
//memcpy(stream, (uint8_t *) audio_buf + audio_buf_index, len1);
len -= len1;
stream += len1;
audio_buf_index += len1;
}
}
示例7: OGG_playAudio
/* Play some of a stream previously started with OGG_play() */
int OGG_playAudio(OGG_music *music, Uint8 *snd, int len)
{
int mixable;
while ( (len > 0) && music->playing ) {
if ( ! music->len_available ) {
OGG_getsome(music);
}
mixable = len;
if ( mixable > music->len_available ) {
mixable = music->len_available;
}
if ( music->volume == MIX_MAX_VOLUME ) {
memcpy(snd, music->snd_available, mixable);
} else {
SDL_MixAudio(snd, music->snd_available, mixable,
music->volume);
}
music->len_available -= mixable;
music->snd_available += mixable;
len -= mixable;
snd += mixable;
}
return len;
}
示例8: av_frame_alloc
int AudioHandler::DecodeAudio(uint8_t* audioBuffer)
{
AVPacket audioPacket;
AVFrame *frame = av_frame_alloc();
int frameFinished = 0;
int audioDecodedSize, dataSize = 0;
while (!isQuit)
{
packetQueue->Get(&audioPacket);
audioDecodedSize = avcodec_decode_audio4(codecContext, frame, &frameFinished, &audioPacket);
if(audioDecodedSize < 0)
{
av_free_packet(&audioPacket);
fprintf(stderr, "Failed to decode audio frame\n");
break;
}
if (frameFinished)
{
dataSize = av_samples_get_buffer_size(NULL, codecContext->channels, frame->nb_samples, codecContext->sample_fmt, 1);
//memcpy(audioBuffer, frame->data[0], dataSize);
SDL_MixAudio(audioBuffer, frame->data[0], dataSize, SDL_MIX_MAXVOLUME);
UpdateClock(&audioPacket, dataSize);
av_free_packet(&audioPacket);
}
return dataSize;
}
av_free(frame);
return 0;
}
示例9: audio_callback
void audio_callback(void *userdata, Uint8 *stream, int len)
{
AVCodecContext *aCodecCtx = (AVCodecContext *)userdata;
int len1, audio_size;
static uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
static unsigned int audio_buf_size = 0;
static unsigned int audio_buf_index = 0;
while(len > 0)
{
if(audio_buf_index >= audio_buf_size)
{
audio_size = audio_decode_frame(aCodecCtx, audio_buf,sizeof(audio_buf));
if(audio_size < 0)
{
audio_buf_size = 1024;
memset(audio_buf, 0, audio_buf_size);
}
else
{
audio_buf_size = audio_size;
}
audio_buf_index = 0;
}
len1 = audio_buf_size - audio_buf_index;
if(len1 > len)
len1 = len;
SDL_MixAudio(stream, (uint8_t * )audio_buf + audio_buf_index, len1, volume);
len -= len1;
stream += len1;
audio_buf_index += len1;
}
}
示例10: my_audio_callback
static void my_audio_callback(void *userdata, unsigned char *stream, int len)
{
if (!l_PluginInit)
return;
int newsamplerate = OutputFreq * 100 / speed_factor;
int oldsamplerate = GameFreq;
if (buffer_pos > (len * oldsamplerate) / newsamplerate)
{
int input_used;
if (VolumeControlType == VOLUME_TYPE_SDL)
{
input_used = resample(buffer, buffer_pos, oldsamplerate, mixBuffer, len, newsamplerate);
SDL_MixAudio(stream, mixBuffer, len, VolSDL);
}
else
{
input_used = resample(buffer, buffer_pos, oldsamplerate, stream, len, newsamplerate);
}
memmove(buffer, &buffer[input_used], buffer_pos - input_used);
buffer_pos -= input_used;
}
else
{
underrun_count++;
DebugMessage(M64MSG_VERBOSE, "Audio buffer underrun (%i).",underrun_count);
memset(stream , 0, len);
buffer_pos = 0;
}
}
示例11: introAudioCallback
void introAudioCallback(void *userdata, Uint8 *stream, int len)
{
if (played>=audio_len)
return;
SDL_MixAudio(stream, &audio_buf[played], played+len>audio_len?audio_len-played:len, volume);
played+=len;
}
示例12: my_audio_callback
void my_audio_callback(void *userdata, Uint8 *stream, int len)
{
int newsamplerate = OutputFreq * 100 / speed_factor;
int oldsamplerate = GameFreq;
if (buffer_pos > (len * oldsamplerate) / newsamplerate)
{
int input_used;
if (VolumeControlType == VOLUME_TYPE_SDL)
{
input_used = resample(buffer, buffer_pos, oldsamplerate, mixBuffer, len, newsamplerate);
SDL_MixAudio(stream, mixBuffer, len, VolSDL);
}
else
{
input_used = resample(buffer, buffer_pos, oldsamplerate, stream, len, newsamplerate);
}
memmove(buffer, &buffer[input_used], buffer_pos - input_used);
buffer_pos -= input_used;
}
else
{
#ifdef DEBUG
underrun_count++;
fprintf(stderr, "[JttL's SDL Audio plugin] Debug: Audio buffer underrun (%i).\n",underrun_count);
#endif
memset(stream , 0, len);
buffer_pos = 0;
}
}
示例13: SDL_LockAudio
void
SDLAudioDriver::PlaySample(AudioFile &file)
{
int16_t *sampleBuffer;
int sampleCount;
bool bFreeSampleBuffer = false;
if (file.sampleRate != this->obtainedAudioSpec.freq ||
file.bitsPerSample != 16 ||
file.isSignedPCM == false)
{
sampleBuffer = static_cast<int16_t*>(convertAudio(file.channelSamples[0], file.sampleCount, file.sampleRate, file.bitsPerSample, file.isSignedPCM, sampleCount, this->obtainedAudioSpec.freq, 16, true));
bFreeSampleBuffer = true;
}
else
{
sampleBuffer = reinterpret_cast<int16_t*>(file.channelSamples[0]);
sampleCount = file.sampleCount;
bFreeSampleBuffer = false;
}
{
SDL_LockAudio();
if ((int)this->sampleBuffer.size() < sampleCount)
{
this->sampleBuffer.resize(sampleCount);
}
SDL_MixAudio((Uint8*)&this->sampleBuffer[0], (const Uint8*)sampleBuffer, sampleCount*2, SDL_MIX_MAXVOLUME);
SDL_UnlockAudio();
}
if (bFreeSampleBuffer)
{
delete[] sampleBuffer;
}
}
示例14: AudioCallback
/*=========================================================================
// Name: AudioCallback()
// Desc: Audio callback function (very important!)
//=======================================================================*/
static void AudioCallback(void *user_data, Uint8 *audio, int length)
{
int i;
/* Clear audiobuffer */
memset(audio, 0, length);
/* Mix all sounds in the array together! */
for (i=0; i<MAX_PLAYING_SOUNDS; i++) {
if (sounds[i].active) { /* Only if sound is active... */
Uint8 *sound_buf;
Uint32 sound_len;
sound_buf = sounds[i].sound->samples;
sound_buf += sounds[i].position;
if ((sounds[i].position + length) > sounds[i].sound->length)
sound_len = sounds[i].sound->length - sounds[i].position;
else
sound_len = length;
/* Mix sound into stream */
SDL_MixAudio(audio, sound_buf, sound_len, VOLUME_PER_SOUND);
/* Update sound buffer position */
sounds[i].position += length;
/* Sound has reached end? */
if (sounds[i].position >= sounds[i].sound->length)
sounds[i].active = 0;
}
}
}
示例15: audioCallback
/**
* Callback used to provide data to the audio subsystem.
*
* @param userdata N/A
* @param stream Output stream
* @param len Length of data to be placed in the output stream
*/
void audioCallback (void * userdata, unsigned char * stream, int len) {
(void)userdata;
int count;
#ifdef USE_MODPLUG
// Read the next portion of music into the audio stream
if (musicFile) ModPlug_Read(musicFile, stream, len);
#endif
for (count = 0; count < nSounds; count++) {
if (sounds[count].position >= 0) {
// Add the next portion of the sound clip to the audio stream
if (len < sounds[count].length - sounds[count].position) {
// Play as much of the clip as possible
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, len,
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position += len;
} else {
// Play the remainder of the clip
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position,
sounds[count].length - sounds[count].position,
soundsVolume * SDL_MIX_MAXVOLUME / MAX_VOLUME);
sounds[count].position = -1;
}
}
}
return;
}