[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39105] branches/soc-2011-pepper: 3D Audio GSoC:
Joerg Mueller
nexyon at gmail.com
Sat Aug 6 19:57:21 CEST 2011
Revision: 39105
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39105
Author: nexyon
Date: 2011-08-06 17:57:20 +0000 (Sat, 06 Aug 2011)
Log Message:
-----------
3D Audio GSoC:
Mixdown functionality.
* Mixdown possible via libsndfile and ffmpeg!
* Fixed some ffmpeg deprecation warnings
* Mixdown UI only shows working Container, Codec and Format combinations!
* Minor bugs and warnings fixed
Modified Paths:
--------------
branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterFunctions.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_IReader.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_NULLDevice.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_NULLDevice.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_Space.h
branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_scene.py
branches/soc-2011-pepper/source/blender/editors/sound/CMakeLists.txt
branches/soc-2011-pepper/source/blender/editors/sound/sound_ops.c
Added Paths:
-----------
branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_FileWriter.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_FileWriter.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_IWriter.h
branches/soc-2011-pepper/intern/audaspace/sndfile/AUD_SndFileWriter.cpp
branches/soc-2011-pepper/intern/audaspace/sndfile/AUD_SndFileWriter.h
Modified: branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt 2011-08-06 16:00:00 UTC (rev 39104)
+++ branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt 2011-08-06 17:57:20 UTC (rev 39105)
@@ -88,12 +88,15 @@
intern/AUD_ConverterReader.h
intern/AUD_FileFactory.cpp
intern/AUD_FileFactory.h
+ intern/AUD_FileWriter.cpp
+ intern/AUD_FileWriter.h
intern/AUD_I3DDevice.h
intern/AUD_I3DHandle.h
intern/AUD_IDevice.h
intern/AUD_IFactory.h
intern/AUD_IHandle.h
intern/AUD_IReader.h
+ intern/AUD_IWriter.h
intern/AUD_JOSResampleFactory.cpp
intern/AUD_JOSResampleFactory.h
intern/AUD_JOSResampleReader.cpp
@@ -184,9 +187,11 @@
list(APPEND SRC
ffmpeg/AUD_FFMPEGFactory.cpp
ffmpeg/AUD_FFMPEGReader.cpp
+ ffmpeg/AUD_FFMPEGWriter.cpp
ffmpeg/AUD_FFMPEGFactory.h
ffmpeg/AUD_FFMPEGReader.h
+ ffmpeg/AUD_FFMPEGWriter.h
)
endif()
@@ -246,9 +251,11 @@
list(APPEND SRC
sndfile/AUD_SndFileFactory.cpp
sndfile/AUD_SndFileReader.cpp
+ sndfile/AUD_SndFileWriter.cpp
sndfile/AUD_SndFileFactory.h
sndfile/AUD_SndFileReader.h
+ sndfile/AUD_SndFileWriter.h
)
endif()
Modified: branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp 2011-08-06 16:00:00 UTC (rev 39104)
+++ branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp 2011-08-06 17:57:20 UTC (rev 39105)
@@ -176,11 +176,11 @@
AUD_FFMPEGReader::AUD_FFMPEGReader(std::string filename) :
m_pkgbuf(AVCODEC_MAX_AUDIO_FRAME_SIZE<<1),
- m_byteiocontext(NULL),
+ m_aviocontext(NULL),
m_membuf(NULL)
{
// open file
- if(av_open_input_file(&m_formatCtx, filename.c_str(), NULL, 0, NULL)!=0)
+ if(avformat_open_input(&m_formatCtx, filename.c_str(), NULL, NULL)!=0)
AUD_THROW(AUD_ERROR_FILE, fileopen_error);
try
@@ -204,25 +204,20 @@
{
m_membuf = reinterpret_cast<data_t*>(av_malloc(FF_MIN_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE));
- m_byteiocontext = av_alloc_put_byte(m_membuf, FF_MIN_BUFFER_SIZE, 0, this,
- read_packet, NULL, seek_packet);
+ m_aviocontext = avio_alloc_context(m_membuf, FF_MIN_BUFFER_SIZE, 0, this,
+ read_packet, NULL, seek_packet);
- if(!m_byteiocontext)
+ if(!m_aviocontext)
{
- av_free(m_byteiocontext);
+ av_free(m_aviocontext);
AUD_THROW(AUD_ERROR_FILE, fileopen_error);
}
- AVProbeData probe_data;
- probe_data.filename = "";
- probe_data.buf = reinterpret_cast<data_t*>(buffer.get()->getBuffer());
- probe_data.buf_size = buffer.get()->getSize();
- AVInputFormat* fmt = av_probe_input_format(&probe_data, 1);
-
- // open stream
- if(av_open_input_stream(&m_formatCtx, m_byteiocontext, "", fmt, NULL)!=0)
+ m_formatCtx = avformat_alloc_context();
+ m_formatCtx->pb = m_aviocontext;
+ if(avformat_open_input(&m_formatCtx, "", NULL, NULL)!=0)
{
- av_free(m_byteiocontext);
+ av_free(m_aviocontext);
AUD_THROW(AUD_ERROR_FILE, streamopen_error);
}
@@ -233,7 +228,7 @@
catch(AUD_Exception&)
{
av_close_input_stream(m_formatCtx);
- av_free(m_byteiocontext);
+ av_free(m_aviocontext);
throw;
}
}
@@ -242,10 +237,10 @@
{
avcodec_close(m_codecCtx);
- if(m_byteiocontext)
+ if(m_aviocontext)
{
av_close_input_stream(m_formatCtx);
- av_free(m_byteiocontext);
+ av_free(m_aviocontext);
}
else
av_close_input_file(m_formatCtx);
Modified: branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h 2011-08-06 16:00:00 UTC (rev 39104)
+++ branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h 2011-08-06 17:57:20 UTC (rev 39105)
@@ -86,9 +86,9 @@
AVCodecContext* m_codecCtx;
/**
- * The ByteIOContext to read the data from.
+ * The AVIOContext to read the data from.
*/
- ByteIOContext* m_byteiocontext;
+ AVIOContext* m_aviocontext;
/**
* The stream ID in the file.
Added: branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp (rev 0)
+++ branches/soc-2011-pepper/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp 2011-08-06 17:57:20 UTC (rev 39105)
@@ -0,0 +1,303 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * Copyright 2009-2011 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * Audaspace is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Audaspace; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
+ * \ingroup audffmpeg
+ */
+
+
+// needed for INT64_C
+#ifndef __STDC_CONSTANT_MACROS
+#define __STDC_CONSTANT_MACROS
+#endif
+
+#include "AUD_FFMPEGWriter.h"
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libavformat/avio.h>
+}
+
+static const char* context_error = "AUD_FFMPEGWriter: Couldn't allocate context.";
+static const char* codec_error = "AUD_FFMPEGWriter: Invalid codec or codec not found.";
+static const char* stream_error = "AUD_FFMPEGWriter: Couldn't allocate stream.";
+static const char* format_error = "AUD_FFMPEGWriter: Unsupported sample format.";
+static const char* file_error = "AUD_FFMPEGWriter: File couldn't be written.";
+static const char* write_error = "AUD_FFMPEGWriter: Error writing packet.";
+
+AUD_FFMPEGWriter::AUD_FFMPEGWriter(std::string filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate) :
+ m_position(0),
+ m_specs(specs),
+ m_input_samples(0)
+{
+ static const char* formats[] = { NULL, "ac3", "flac", "matroska", "mp2", "mp3", "ogg", "wav" };
+
+ if(avformat_alloc_output_context2(&m_formatCtx, NULL, formats[format], filename.c_str()))
+ AUD_THROW(AUD_ERROR_FFMPEG, context_error);
+
+ m_outputFmt = m_formatCtx->oformat;
+
+ switch(codec)
+ {
+ case AUD_CODEC_AAC:
+ m_outputFmt->audio_codec = CODEC_ID_AAC;
+ break;
+ case AUD_CODEC_AC3:
+ m_outputFmt->audio_codec = CODEC_ID_AC3;
+ break;
+ case AUD_CODEC_FLAC:
+ m_outputFmt->audio_codec = CODEC_ID_FLAC;
+ break;
+ case AUD_CODEC_MP2:
+ m_outputFmt->audio_codec = CODEC_ID_MP2;
+ break;
+ case AUD_CODEC_MP3:
+ m_outputFmt->audio_codec = CODEC_ID_MP3;
+ break;
+ case AUD_CODEC_PCM:
+ switch(specs.format)
+ {
+ case AUD_FORMAT_U8:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_U8;
+ break;
+ case AUD_FORMAT_S16:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_S16LE;
+ break;
+ case AUD_FORMAT_S24:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_S24LE;
+ break;
+ case AUD_FORMAT_S32:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_S32LE;
+ break;
+ case AUD_FORMAT_FLOAT32:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_F32LE;
+ break;
+ case AUD_FORMAT_FLOAT64:
+ m_outputFmt->audio_codec = CODEC_ID_PCM_F64LE;
+ break;
+ default:
+ m_outputFmt->audio_codec = CODEC_ID_NONE;
+ break;
+ }
+ break;
+ case AUD_CODEC_VORBIS:
+ m_outputFmt->audio_codec = CODEC_ID_VORBIS;
+ break;
+ default:
+ m_outputFmt->audio_codec = CODEC_ID_NONE;
+ break;
+ }
+
+ try
+ {
+ if(m_outputFmt->audio_codec == CODEC_ID_NONE)
+ AUD_THROW(AUD_ERROR_SPECS, codec_error);
+
+ m_stream = av_new_stream(m_formatCtx, 0);
+ if(!m_stream)
+ AUD_THROW(AUD_ERROR_FFMPEG, stream_error);
+
+ m_codecCtx = m_stream->codec;
+ m_codecCtx->codec_id = m_outputFmt->audio_codec;
+ m_codecCtx->codec_type = AVMEDIA_TYPE_AUDIO;
+ m_codecCtx->bit_rate = bitrate;
+ m_codecCtx->sample_rate = int(m_specs.rate);
+ m_codecCtx->channels = m_specs.channels;
+ m_codecCtx->time_base = (AVRational){1, m_codecCtx->sample_rate};
+
+ switch(m_specs.format)
+ {
+ case AUD_FORMAT_U8:
+ m_convert = AUD_convert_float_u8;
+ m_codecCtx->sample_fmt = SAMPLE_FMT_U8;
+ break;
+ case AUD_FORMAT_S16:
+ m_convert = AUD_convert_float_s16;
+ m_codecCtx->sample_fmt = SAMPLE_FMT_S16;
+ break;
+ case AUD_FORMAT_S32:
+ m_convert = AUD_convert_float_s32;
+ m_codecCtx->sample_fmt = SAMPLE_FMT_S32;
+ break;
+ case AUD_FORMAT_FLOAT32:
+ m_convert = AUD_convert_copy<float>;
+ m_codecCtx->sample_fmt = SAMPLE_FMT_FLT;
+ break;
+ case AUD_FORMAT_FLOAT64:
+ m_convert = AUD_convert_float_double;
+ m_codecCtx->sample_fmt = SAMPLE_FMT_DBL;
+ break;
+ default:
+ AUD_THROW(AUD_ERROR_FFMPEG, format_error);
+ }
+
+ try
+ {
+ if(m_formatCtx->oformat->flags & AVFMT_GLOBALHEADER)
+ m_codecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
+ AVCodec* codec = avcodec_find_encoder(m_codecCtx->codec_id);
+ if(!codec)
+ AUD_THROW(AUD_ERROR_FFMPEG, codec_error);
+
+ if(avcodec_open(m_codecCtx, codec))
+ AUD_THROW(AUD_ERROR_FFMPEG, codec_error);
+
+ m_output_buffer.resize(FF_MIN_BUFFER_SIZE);
+ int samplesize = AUD_MAX(AUD_SAMPLE_SIZE(m_specs), AUD_DEVICE_SAMPLE_SIZE(m_specs));
+
+ if(m_codecCtx->frame_size <= 1)
+ m_input_size = 0;
+ else
+ {
+ m_input_buffer.resize(m_codecCtx->frame_size * samplesize);
+ m_input_size = m_codecCtx->frame_size;
+ }
+
+ try
+ {
+ if(avio_open(&m_formatCtx->pb, filename.c_str(), AVIO_WRONLY))
+ AUD_THROW(AUD_ERROR_FILE, file_error);
+
+ avformat_write_header(m_formatCtx, NULL);
+ }
+ catch(AUD_Exception&)
+ {
+ avcodec_close(m_codecCtx);
+ av_freep(&m_formatCtx->streams[0]->codec);
+ throw;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ av_freep(&m_formatCtx->streams[0]);
+ throw;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ av_free(m_formatCtx);
+ throw;
+ }
+}
+
+AUD_FFMPEGWriter::~AUD_FFMPEGWriter()
+{
+ // writte missing data
+ if(m_input_samples)
+ {
+ sample_t* buf = m_input_buffer.getBuffer();
+ memset(buf + m_specs.channels * m_input_samples, 0,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list