Пример #1
0
void KX_SoundActuator::play()
{
	if (m_handle) {
		AUD_Handle_stop(m_handle);
		m_handle = NULL;
	}

	if (!m_sound)
		return;

	// this is the sound that will be played and not deleted afterwards
	AUD_Sound* sound = m_sound;

	bool loop = false;

	switch (m_type)
	{
	case KX_SOUNDACT_LOOPBIDIRECTIONAL:
	case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
		sound = AUD_Sound_pingpong(sound);
		ATTR_FALLTHROUGH;
	case KX_SOUNDACT_LOOPEND:
	case KX_SOUNDACT_LOOPSTOP:
		loop = true;
		break;
	case KX_SOUNDACT_PLAYSTOP:
	case KX_SOUNDACT_PLAYEND:
	default:
		break;
	}

	AUD_Device* device = AUD_Device_getCurrent();
	m_handle = AUD_Device_play(device, sound, false);
	AUD_Device_free(device);

	// in case of pingpong, we have to free the sound
	if (sound != m_sound)
		AUD_Sound_free(sound);

	if (m_handle != NULL) {
		if (m_is3d) {
			AUD_Handle_setRelative(m_handle, true);
			AUD_Handle_setVolumeMaximum(m_handle, m_3d.max_gain);
			AUD_Handle_setVolumeMinimum(m_handle, m_3d.min_gain);
			AUD_Handle_setDistanceReference(m_handle, m_3d.reference_distance);
			AUD_Handle_setDistanceMaximum(m_handle, m_3d.max_distance);
			AUD_Handle_setAttenuation(m_handle, m_3d.rolloff_factor);
			AUD_Handle_setConeAngleInner(m_handle, m_3d.cone_inner_angle);
			AUD_Handle_setConeAngleOuter(m_handle, m_3d.cone_outer_angle);
			AUD_Handle_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain);
		}

		if (loop)
			AUD_Handle_setLoopCount(m_handle, -1);
		AUD_Handle_setPitch(m_handle, m_pitch);
		AUD_Handle_setVolume(m_handle, m_volume);
	}

	m_isplaying = true;
}
Пример #2
0
static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit)
{
	PRINT("Closing ffmpeg...\n");

#if 0
	if (context->audio_stream) { /* SEE UPPER */
		write_audio_frames(context);
	}
#endif

#ifdef WITH_AUDASPACE
	if (is_autosplit == false) {
		if (context->audio_mixdown_device) {
			AUD_Device_free(context->audio_mixdown_device);
			context->audio_mixdown_device = 0;
		}
	}
#endif

	if (context->video_stream && context->video_stream->codec) {
		PRINT("Flushing delayed frames...\n");
		flush_ffmpeg(context);
	}
	
	if (context->outfile) {
		av_write_trailer(context->outfile);
	}
	
	/* Close the video codec */

	if (context->video_stream && context->video_stream->codec) {
		avcodec_close(context->video_stream->codec);
		PRINT("zero video stream %p\n", context->video_stream);
		context->video_stream = 0;
	}

	/* free the temp buffer */
	if (context->current_frame) {
		delete_picture(context->current_frame);
		context->current_frame = 0;
	}
	if (context->outfile && context->outfile->oformat) {
		if (!(context->outfile->oformat->flags & AVFMT_NOFILE)) {
			avio_close(context->outfile->pb);
		}
	}
	if (context->outfile) {
		avformat_free_context(context->outfile);
		context->outfile = 0;
	}
	if (context->audio_input_buffer) {
		av_free(context->audio_input_buffer);
		context->audio_input_buffer = 0;
	}
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
	if (context->audio_output_buffer) {
		av_free(context->audio_output_buffer);
		context->audio_output_buffer = 0;
	}
#endif

	if (context->audio_deinterleave_buffer) {
		av_free(context->audio_deinterleave_buffer);
		context->audio_deinterleave_buffer = 0;
	}

	if (context->img_convert_ctx) {
		sws_freeContext(context->img_convert_ctx);
		context->img_convert_ctx = 0;
	}
}