[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22686] branches/blender2.5/blender: Audio file loading backend libsndfile!
Joerg Mueller
nexyon at gmail.com
Fri Aug 21 21:39:28 CEST 2009
Revision: 22686
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22686
Author: nexyon
Date: 2009-08-21 21:39:28 +0200 (Fri, 21 Aug 2009)
Log Message:
-----------
Audio file loading backend libsndfile!
Modified Paths:
--------------
branches/blender2.5/blender/CMake/macros.cmake
branches/blender2.5/blender/CMakeLists.txt
branches/blender2.5/blender/intern/audaspace/CMakeLists.txt
branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp
branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h
branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
branches/blender2.5/blender/intern/audaspace/intern/AUD_C-API.cpp
Added Paths:
-----------
branches/blender2.5/blender/intern/audaspace/intern/AUD_FileFactory.cpp
branches/blender2.5/blender/intern/audaspace/intern/AUD_FileFactory.h
branches/blender2.5/blender/intern/audaspace/sndfile/
branches/blender2.5/blender/intern/audaspace/sndfile/AUD_SndFileFactory.cpp
branches/blender2.5/blender/intern/audaspace/sndfile/AUD_SndFileFactory.h
branches/blender2.5/blender/intern/audaspace/sndfile/AUD_SndFileReader.cpp
branches/blender2.5/blender/intern/audaspace/sndfile/AUD_SndFileReader.h
Modified: branches/blender2.5/blender/CMake/macros.cmake
===================================================================
--- branches/blender2.5/blender/CMake/macros.cmake 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/CMake/macros.cmake 2009-08-21 19:39:28 UTC (rev 22686)
@@ -70,6 +70,9 @@
IF(WITH_JACK)
LINK_DIRECTORIES(${JACK_LIBPATH})
ENDIF(WITH_JACK)
+ IF(WITH_SNDFILE)
+ LINK_DIRECTORIES(${SNDFILE_LIBPATH})
+ ENDIF(WITH_SNDFILE)
IF(WITH_FFTW3)
LINK_DIRECTORIES(${FFTW3_LIBPATH})
ENDIF(WITH_FFTW3)
@@ -118,6 +121,9 @@
IF(WITH_JACK)
TARGET_LINK_LIBRARIES(${target} ${JACK_LIB})
ENDIF(WITH_JACK)
+ IF(WITH_SNDFILE)
+ TARGET_LINK_LIBRARIES(${target} ${SNDFILE_LIB})
+ ENDIF(WITH_SNDFILE)
IF(WITH_SDL)
TARGET_LINK_LIBRARIES(${target} ${SDL_LIBRARY})
ENDIF(WITH_SDL)
Modified: branches/blender2.5/blender/CMakeLists.txt
===================================================================
--- branches/blender2.5/blender/CMakeLists.txt 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/CMakeLists.txt 2009-08-21 19:39:28 UTC (rev 22686)
@@ -70,6 +70,7 @@
OPTION(WITH_WEBPLUGIN "Enable Web Plugin (Unix only)" OFF)
OPTION(WITH_FFTW3 "Enable FFTW3 support" OFF)
OPTION(WITH_JACK "Enable Jack Support (http://www.jackaudio.org)" OFF)
+OPTION(WITH_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation" OFF)
OPTION(WITH_INSTALL "Install accompanying scripts and language files needed to run blender" ON)
@@ -109,6 +110,13 @@
SET(JACK_LIBPATH ${JACK}/lib)
ENDIF(WITH_JACK)
+ IF(WITH_SNDFILE)
+ SET(SNDFILE /usr)
+ SET(SNDFILE_INC ${SNDFILE}/include)
+ SET(SNDFILE_LIB sndfile)
+ SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
+ ENDIF(WITH_SNDFILE)
+
FIND_LIBRARY(INTL_LIBRARY
NAMES intl
PATHS
@@ -247,6 +255,13 @@
SET(JACK_LIBPATH ${JACK}/lib)
ENDIF(WITH_JACK)
+ IF(WITH_SNDFILE)
+ SET(SNDFILE ${LIBDIR}/sndfile)
+ SET(SNDFILE_INC ${SNDFILE}/include)
+ SET(SNDFILE_LIB sndfile)
+ SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
+ ENDIF(WITH_SNDFILE)
+
IF(CMAKE_CL_64)
SET(PNG_LIBRARIES libpng)
ELSE(CMAKE_CL_64)
@@ -392,6 +407,13 @@
SET(JACK_LIBPATH ${JACK}/lib)
ENDIF(WITH_JACK)
+ IF(WITH_SNDFILE)
+ SET(SNDFILE /usr)
+ SET(SNDFILE_INC ${SNDFILE}/include)
+ SET(SNDFILE_LIB sndfile)
+ SET(SNDFILE_LIBPATH ${SNDFILE}/lib)
+ ENDIF(WITH_SNDFILE)
+
SET(PYTHON_VERSION 3.1)
IF(PYTHON_VERSION MATCHES 3.1)
Modified: branches/blender2.5/blender/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/blender2.5/blender/intern/audaspace/CMakeLists.txt 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/CMakeLists.txt 2009-08-21 19:39:28 UTC (rev 22686)
@@ -53,6 +53,12 @@
ADD_DEFINITIONS(-DWITH_JACK)
ENDIF(WITH_JACK)
-SET(SRC ${SRC} ${FFMPEGSRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
+IF(WITH_SNDFILE)
+ SET(INC ${INC} sndfile ${SNDFILE_INC})
+ FILE(GLOB SNDFILESRC sndfile/*.cpp)
+ ADD_DEFINITIONS(-DWITH_SNDFILE)
+ENDIF(WITH_SNDFILE)
+SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
+
BLENDERLIB(bf_audaspace "${SRC}" "${INC}")
Modified: branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp
===================================================================
--- branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.cpp 2009-08-21 19:39:28 UTC (rev 22686)
@@ -25,31 +25,24 @@
#include "AUD_FFMPEGFactory.h"
#include "AUD_FFMPEGReader.h"
-#include "AUD_Space.h"
+#include "AUD_Buffer.h"
-extern "C" {
-#include <libavformat/avformat.h>
-}
-
AUD_FFMPEGFactory::AUD_FFMPEGFactory(const char* filename)
{
- if(filename != 0)
+ if(filename != NULL)
{
m_filename = new char[strlen(filename)+1]; AUD_NEW("string")
strcpy(m_filename, filename);
}
else
- m_filename = 0;
- m_buffer = 0;
- m_size = 0;
+ m_filename = NULL;
}
AUD_FFMPEGFactory::AUD_FFMPEGFactory(unsigned char* buffer, int size)
{
- m_filename = 0;
- m_buffer = (unsigned char*)av_malloc(size); AUD_NEW("buffer")
- m_size = size;
- memcpy(m_buffer, buffer, size);
+ m_filename = NULL;
+ m_buffer = AUD_Reference<AUD_Buffer>(new AUD_Buffer(size));
+ memcpy(m_buffer.get()->getBuffer(), buffer, size);
}
AUD_FFMPEGFactory::~AUD_FFMPEGFactory()
@@ -58,31 +51,15 @@
{
delete[] m_filename; AUD_DELETE("string")
}
- if(m_buffer)
- {
- av_free(m_buffer); AUD_DELETE("buffer")
- }
}
AUD_IReader* AUD_FFMPEGFactory::createReader()
{
- try
- {
- AUD_IReader* reader;
- if(m_filename)
- reader = new AUD_FFMPEGReader(m_filename);
- else
- reader = new AUD_FFMPEGReader(m_buffer, m_size);
- AUD_NEW("reader")
- return reader;
- }
- catch(AUD_Exception e)
- {
- // return 0 if ffmpeg cannot read the file
- if(e.error == AUD_ERROR_FFMPEG)
- return 0;
- // but throw an exception if the file doesn't exist
- else
- throw;
- }
+ AUD_IReader* reader;
+ if(m_filename)
+ reader = new AUD_FFMPEGReader(m_filename);
+ else
+ reader = new AUD_FFMPEGReader(m_buffer);
+ AUD_NEW("reader")
+ return reader;
}
Modified: branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h
===================================================================
--- branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGFactory.h 2009-08-21 19:39:28 UTC (rev 22686)
@@ -27,6 +27,8 @@
#define AUD_FFMPEGFACTORY
#include "AUD_IFactory.h"
+#include "AUD_Reference.h"
+class AUD_Buffer;
/**
* This factory reads a sound file via ffmpeg.
@@ -44,13 +46,8 @@
/**
* The buffer to read from.
*/
- unsigned char* m_buffer;
+ AUD_Reference<AUD_Buffer> m_buffer;
- /**
- * The size of the buffer.
- */
- int m_size;
-
public:
/**
* Creates a new factory.
Modified: branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
===================================================================
--- branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp 2009-08-21 19:39:28 UTC (rev 22686)
@@ -158,21 +158,22 @@
AUD_NEW("buffer")
}
-AUD_FFMPEGReader::AUD_FFMPEGReader(unsigned char* buffer, int size)
+AUD_FFMPEGReader::AUD_FFMPEGReader(AUD_Reference<AUD_Buffer> buffer)
{
m_position = 0;
m_pkgbuf_left = 0;
m_byteiocontext = (ByteIOContext*)av_mallocz(sizeof(ByteIOContext));
AUD_NEW("byteiocontext")
+ m_membuffer = buffer;
- if(init_put_byte(m_byteiocontext, buffer, size, 0,
+ if(init_put_byte(m_byteiocontext, buffer.get()->getBuffer(), buffer.get()->getSize(), 0,
NULL, NULL, NULL, NULL) != 0)
AUD_THROW(AUD_ERROR_FILE);
AVProbeData probe_data;
probe_data.filename = "";
- probe_data.buf = buffer;
- probe_data.buf_size = size;
+ probe_data.buf = buffer.get()->getBuffer();
+ probe_data.buf_size = buffer.get()->getSize();
AVInputFormat* fmt = av_probe_input_format(&probe_data, 1);
// open stream
Modified: branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
===================================================================
--- branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.h 2009-08-21 19:39:28 UTC (rev 22686)
@@ -27,7 +27,9 @@
#define AUD_FFMPEGREADER
#include "AUD_IReader.h"
+#include "AUD_Reference.h"
class AUD_Buffer;
+
struct AVCodecContext;
extern "C" {
#include <libavformat/avformat.h>
@@ -90,6 +92,11 @@
int m_stream;
/**
+ * The memory file to read from, only saved to keep the buffer alive.
+ */
+ AUD_Reference<AUD_Buffer> m_membuffer;
+
+ /**
* Decodes a packet into the given buffer.
* \param packet The AVPacket to decode.
* \param buffer The target buffer.
@@ -109,11 +116,10 @@
/**
* Creates a new reader.
* \param buffer The buffer to read from.
- * \param size The size of the buffer.
* \exception AUD_Exception Thrown if the buffer specified cannot be read
* with ffmpeg.
*/
- AUD_FFMPEGReader(unsigned char* buffer, int size);
+ AUD_FFMPEGReader(AUD_Reference<AUD_Buffer> buffer);
/**
* Destroys the reader and closes the file.
Modified: branches/blender2.5/blender/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/blender2.5/blender/intern/audaspace/intern/AUD_C-API.cpp 2009-08-21 18:35:40 UTC (rev 22685)
+++ branches/blender2.5/blender/intern/audaspace/intern/AUD_C-API.cpp 2009-08-21 19:39:28 UTC (rev 22686)
@@ -25,6 +25,7 @@
#include "AUD_NULLDevice.h"
#include "AUD_I3DDevice.h"
+#include "AUD_FileFactory.h"
#include "AUD_StreamBufferFactory.h"
#include "AUD_DelayFactory.h"
#include "AUD_LimiterFactory.h"
@@ -48,7 +49,6 @@
#endif
#ifdef WITH_FFMPEG
-#include "AUD_FFMPEGFactory.h"
extern "C" {
#include <libavformat/avformat.h>
}
@@ -187,21 +187,13 @@
AUD_Sound* AUD_load(const char* filename)
{
assert(filename);
-#ifdef WITH_FFMPEG
- return new AUD_FFMPEGFactory(filename);
-#else
- return NULL;
-#endif
+ return new AUD_FileFactory(filename);
}
AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
{
assert(buffer);
-#ifdef WITH_FFMPEG
- return new AUD_FFMPEGFactory(buffer, size);
-#else
- return NULL;
-#endif
+ return new AUD_FileFactory(buffer, size);
}
AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
Added: branches/blender2.5/blender/intern/audaspace/intern/AUD_FileFactory.cpp
===================================================================
--- branches/blender2.5/blender/intern/audaspace/intern/AUD_FileFactory.cpp (rev 0)
+++ branches/blender2.5/blender/intern/audaspace/intern/AUD_FileFactory.cpp 2009-08-21 19:39:28 UTC (rev 22686)
@@ -0,0 +1,95 @@
+/*
+ * $Id: AUD_FFMPEGFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * AudaSpace is free software: you can redistribute it and/or modify
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list