* #29743 modified config.h of libsnd, UI adjustements
diff --git a/jni/Android.mk b/jni/Android.mk
index 551dc54..4cf0842 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -213,7 +213,8 @@
 					$(MY_LIBSNDFILE)/src/G72x/g723_16.c \
 					$(MY_LIBSNDFILE)/src/float32.c \
 					$(MY_LIBSNDFILE)/src/chanmap.c $(MY_LIBSNDFILE)/src/test_endswap.c $(MY_LIBSNDFILE)/src/rf64.c \
-					$(MY_LIBSNDFILE)/src/sndfile.c $(MY_LIBSNDFILE)/src/htk.c $(MY_LIBSNDFILE)/src/dither.c \
+					$(MY_LIBSNDFILE)/src/sndfile.c \
+					$(MY_LIBSNDFILE)/src/htk.c $(MY_LIBSNDFILE)/src/dither.c \
        				$(MY_LIBSNDFILE)/src/test_log_printf.c $(MY_LIBSNDFILE)/src/txw.c \
 					$(MY_LIBSNDFILE)/src/ms_adpcm.c $(MY_LIBSNDFILE)/src/ima_adpcm.c \
 					$(MY_LIBSNDFILE)/src/flac.c $(MY_LIBSNDFILE)/src/aiff.c \
@@ -252,6 +253,7 @@
 					$(MY_LIBSNDFILE)/src/ircam.c $(MY_LIBSNDFILE)/src/xi.c $(MY_LIBSNDFILE)/src/ima_oki_adpcm.c
 
 LOCAL_C_INCLUDES += $(APP_PROJECT_PATH)/jni/$(MY_LIBSNDFILE)/src \
+					$(APP_PROJECT_PATH)/jni/sflphone/daemon/src
 
 LOCAL_LDLIBS  += -L$(APP_PROJECT_PATH)/obj/local/armeabi \
 			
diff --git a/jni/libsndfile-1.0.25/M4/Makefile b/jni/libsndfile-1.0.25/M4/Makefile
index cf26f2f..4041b86 100644
--- a/jni/libsndfile-1.0.25/M4/Makefile
+++ b/jni/libsndfile-1.0.25/M4/Makefile
@@ -65,7 +65,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/Makefile b/jni/libsndfile-1.0.25/Makefile
index c797305..19d07a6 100644
--- a/jni/libsndfile-1.0.25/Makefile
+++ b/jni/libsndfile-1.0.25/Makefile
@@ -145,7 +145,7 @@
 distcleancheck_listfiles = find . -type f -print
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/Octave/Makefile b/jni/libsndfile-1.0.25/Octave/Makefile
index 101d0f9..3b11eaa 100644
--- a/jni/libsndfile-1.0.25/Octave/Makefile
+++ b/jni/libsndfile-1.0.25/Octave/Makefile
@@ -89,7 +89,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/Win32/Makefile b/jni/libsndfile-1.0.25/Win32/Makefile
index ff710f4..c23356b 100644
--- a/jni/libsndfile-1.0.25/Win32/Makefile
+++ b/jni/libsndfile-1.0.25/Win32/Makefile
@@ -65,7 +65,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/config.log b/jni/libsndfile-1.0.25/config.log
index fe2b906..129b854 100644
--- a/jni/libsndfile-1.0.25/config.log
+++ b/jni/libsndfile-1.0.25/config.log
@@ -4,7 +4,7 @@
 It was created by libsndfile configure 1.0.25, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
-  $ ./configure --disable-external-libs --disable-alsa
+  $ ./configure --disable-external-libs
 
 ## --------- ##
 ## Platform. ##
@@ -48,7 +48,6 @@
 PATH: /home/lisional/Dev/ADT/sdk/platform-tools
 PATH: /home/lisional/Dev/ADT/ndk
 PATH: /home/lisional/.local/bin
-PATH: /home/lisional/Dev/ADT/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/
 
 
 ## ----------- ##
@@ -1176,9 +1175,19 @@
 | 		}
 | 
 configure:18739: result: none
+configure:18816: checking alsa/asoundlib.h usability
+configure:18816: gcc -c -g -O2  conftest.c >&5
+configure:18816: $? = 0
+configure:18816: result: yes
+configure:18816: checking alsa/asoundlib.h presence
+configure:18816: gcc -E  conftest.c
+configure:18816: $? = 0
+configure:18816: result: yes
+configure:18816: checking for alsa/asoundlib.h
+configure:18816: result: yes
 configure:18838: checking sndio.h usability
 configure:18838: gcc -c -g -O2  conftest.c >&5
-conftest.c:123:19: fatal error: sndio.h: No such file or directory
+conftest.c:124:19: fatal error: sndio.h: No such file or directory
 compilation terminated.
 configure:18838: $? = 1
 configure: failed program was:
@@ -1270,6 +1279,7 @@
 | #define OS_IS_WIN32 0
 | #define OS_IS_MACOSX 0
 | #define USE_WINDOWS_API 0
+| #define HAVE_ALSA_ASOUNDLIB_H 1
 | /* end confdefs.h.  */
 | #include <stdio.h>
 | #ifdef HAVE_SYS_TYPES_H
@@ -1308,7 +1318,7 @@
 configure:18838: result: no
 configure:18838: checking sndio.h presence
 configure:18838: gcc -E  conftest.c
-conftest.c:90:19: fatal error: sndio.h: No such file or directory
+conftest.c:91:19: fatal error: sndio.h: No such file or directory
 compilation terminated.
 configure:18838: $? = 1
 configure: failed program was:
@@ -1400,6 +1410,7 @@
 | #define OS_IS_WIN32 0
 | #define OS_IS_MACOSX 0
 | #define USE_WINDOWS_API 0
+| #define HAVE_ALSA_ASOUNDLIB_H 1
 | /* end confdefs.h.  */
 | #include <sndio.h>
 configure:18838: result: no
@@ -1449,28 +1460,28 @@
 
 on pcal
 
-config.status:1358: creating src/Makefile
-config.status:1358: creating man/Makefile
-config.status:1358: creating examples/Makefile
-config.status:1358: creating tests/Makefile
-config.status:1358: creating regtest/Makefile
-config.status:1358: creating M4/Makefile
-config.status:1358: creating doc/Makefile
-config.status:1358: creating Win32/Makefile
-config.status:1358: creating Octave/Makefile
-config.status:1358: creating programs/Makefile
-config.status:1358: creating Makefile
-config.status:1358: creating src/version-metadata.rc
-config.status:1358: creating tests/test_wrapper.sh
-config.status:1358: creating tests/pedantic-header-test.sh
-config.status:1358: creating doc/libsndfile.css
-config.status:1358: creating build-test-tarball.mk
-config.status:1358: creating libsndfile.spec
-config.status:1358: creating sndfile.pc
-config.status:1358: creating src/sndfile.h
-config.status:1358: creating src/config.h
-config.status:1587: executing depfiles commands
-config.status:1587: executing libtool commands
+config.status:1359: creating src/Makefile
+config.status:1359: creating man/Makefile
+config.status:1359: creating examples/Makefile
+config.status:1359: creating tests/Makefile
+config.status:1359: creating regtest/Makefile
+config.status:1359: creating M4/Makefile
+config.status:1359: creating doc/Makefile
+config.status:1359: creating Win32/Makefile
+config.status:1359: creating Octave/Makefile
+config.status:1359: creating programs/Makefile
+config.status:1359: creating Makefile
+config.status:1359: creating src/version-metadata.rc
+config.status:1359: creating tests/test_wrapper.sh
+config.status:1359: creating tests/pedantic-header-test.sh
+config.status:1359: creating doc/libsndfile.css
+config.status:1359: creating build-test-tarball.mk
+config.status:1359: creating libsndfile.spec
+config.status:1359: creating sndfile.pc
+config.status:1359: creating src/sndfile.h
+config.status:1359: creating src/config.h
+config.status:1588: executing depfiles commands
+config.status:1588: executing libtool commands
 configure:22287: result:
 -=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=-
 
@@ -1483,7 +1494,7 @@
     Host OS : ............................. linux-gnu
 
     Experimental code : ................... no
-    Using ALSA in example programs : ...... no
+    Using ALSA in example programs : ...... yes
     External FLAC/Ogg/Vorbis : ............ no
 
 configure:22341: result:
@@ -1596,6 +1607,7 @@
 ac_cv_func_waitpid=yes
 ac_cv_func_write=yes
 ac_cv_have_decl_S_IRGRP=yes
+ac_cv_header_alsa_asoundlib_h=yes
 ac_cv_header_byteswap_h=yes
 ac_cv_header_dlfcn_h=yes
 ac_cv_header_endian_h=yes
@@ -1701,7 +1713,7 @@
 
 ACLOCAL='${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11'
 ACLOCAL_AMFLAGS='-I M4'
-ALSA_LIBS=''
+ALSA_LIBS='-lasound'
 AMDEPBACKSLASH='\'
 AMDEP_FALSE='#'
 AMDEP_TRUE=''
@@ -1976,6 +1988,7 @@
 #define OS_IS_WIN32 0
 #define OS_IS_MACOSX 0
 #define USE_WINDOWS_API 0
+#define HAVE_ALSA_ASOUNDLIB_H 1
 #define WIN32_TARGET_DLL 0
 #define COMPILER_IS_GCC 1
 
diff --git a/jni/libsndfile-1.0.25/config.status b/jni/libsndfile-1.0.25/config.status
index 5545c9d..96a4f42 100755
--- a/jni/libsndfile-1.0.25/config.status
+++ b/jni/libsndfile-1.0.25/config.status
@@ -440,7 +440,7 @@
 Report bugs to <sndfile@mega-nerd.com>.
 libsndfile home page: <http://www.mega-nerd.com/libsndfile/>."
 
-ac_cs_config="'--disable-external-libs' '--disable-alsa'"
+ac_cs_config="'--disable-external-libs'"
 ac_cs_version="\
 libsndfile config.status 1.0.25
 configured by ./configure, generated by GNU Autoconf 2.68,
@@ -532,7 +532,7 @@
 fi
 
 if $ac_cs_recheck; then
-  set X '/bin/sh' './configure'  '--disable-external-libs' '--disable-alsa' $ac_configure_extra_args --no-create --no-recursion
+  set X '/bin/sh' './configure'  '--disable-external-libs' $ac_configure_extra_args --no-create --no-recursion
   shift
   $as_echo "running CONFIG_SHELL=/bin/sh $*" >&6
   CONFIG_SHELL='/bin/sh'
@@ -960,7 +960,7 @@
 S["EXTERNAL_LIBS"]=""
 S["EXTERNAL_CFLAGS"]=""
 S["SNDIO_LIBS"]=""
-S["ALSA_LIBS"]=""
+S["ALSA_LIBS"]="-lasound"
 S["OS_SPECIFIC_LINKS"]=""
 S["OS_SPECIFIC_CFLAGS"]=""
 S["WIN_RC_VERSION"]="1,0,25"
@@ -1266,6 +1266,7 @@
 D["OS_IS_WIN32"]=" 0"
 D["OS_IS_MACOSX"]=" 0"
 D["USE_WINDOWS_API"]=" 0"
+D["HAVE_ALSA_ASOUNDLIB_H"]=" 1"
 D["WIN32_TARGET_DLL"]=" 0"
 D["COMPILER_IS_GCC"]=" 1"
   for (key in D) D_is_set[key] = 1
diff --git a/jni/libsndfile-1.0.25/doc/Makefile b/jni/libsndfile-1.0.25/doc/Makefile
index b95a254..8b47c85 100644
--- a/jni/libsndfile-1.0.25/doc/Makefile
+++ b/jni/libsndfile-1.0.25/doc/Makefile
@@ -90,7 +90,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/examples/Makefile b/jni/libsndfile-1.0.25/examples/Makefile
index 3b5e5fe..9a3f735 100644
--- a/jni/libsndfile-1.0.25/examples/Makefile
+++ b/jni/libsndfile-1.0.25/examples/Makefile
@@ -133,7 +133,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/man/Makefile b/jni/libsndfile-1.0.25/man/Makefile
index ce3165e..53e1937 100644
--- a/jni/libsndfile-1.0.25/man/Makefile
+++ b/jni/libsndfile-1.0.25/man/Makefile
@@ -90,7 +90,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/programs/Makefile b/jni/libsndfile-1.0.25/programs/Makefile
index 99c0ce2..19b2ca0 100644
--- a/jni/libsndfile-1.0.25/programs/Makefile
+++ b/jni/libsndfile-1.0.25/programs/Makefile
@@ -147,7 +147,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/regtest/Makefile b/jni/libsndfile-1.0.25/regtest/Makefile
index 2132948..b298c89 100644
--- a/jni/libsndfile-1.0.25/regtest/Makefile
+++ b/jni/libsndfile-1.0.25/regtest/Makefile
@@ -103,7 +103,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/src/Makefile b/jni/libsndfile-1.0.25/src/Makefile
index 4d151ce..d09e019 100644
--- a/jni/libsndfile-1.0.25/src/Makefile
+++ b/jni/libsndfile-1.0.25/src/Makefile
@@ -179,7 +179,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/jni/libsndfile-1.0.25/src/config.h b/jni/libsndfile-1.0.25/src/config.h
index c253a1d..5e0c727 100644
--- a/jni/libsndfile-1.0.25/src/config.h
+++ b/jni/libsndfile-1.0.25/src/config.h
@@ -20,7 +20,7 @@
 #define ENABLE_EXPERIMENTAL_CODE 0
 
 /* Define to 1 if you have the <alsa/asoundlib.h> header file. */
-/* #undef HAVE_ALSA_ASOUNDLIB_H */
+#define HAVE_ALSA_ASOUNDLIB_H 1
 
 /* Define to 1 if you have the <byteswap.h> header file. */
 #define HAVE_BYTESWAP_H 1
@@ -237,7 +237,7 @@
 #define SIZEOF_LONG_LONG 8
 
 /* The size of `off64_t', as computed by sizeof. */
-/* #undef SIZEOF_OFF64_T */
+#define SIZEOF_OFF64_T 8
 
 /* The size of `off_t', as computed by sizeof. */
 #define SIZEOF_OFF_T 8
diff --git a/jni/libsndfile-1.0.25/src/file_io.c b/jni/libsndfile-1.0.25/src/file_io.c
index 44f1b5a..4717c17 100644
--- a/jni/libsndfile-1.0.25/src/file_io.c
+++ b/jni/libsndfile-1.0.25/src/file_io.c
@@ -81,13 +81,11 @@
 {
 	psf->error = 0 ;
 	psf->file.filedes = psf_open_fd (&psf->file) ;
-
 	if (psf->file.filedes == - SFE_BAD_OPEN_MODE)
 	{	psf->error = SFE_BAD_OPEN_MODE ;
 		psf->file.filedes = -1 ;
 		return psf->error ;
 		} ;
-
 	if (psf->file.filedes == -1)
 		psf_log_syserr (psf, errno) ;
 
@@ -532,18 +530,16 @@
 static int
 psf_open_fd (PSF_FILE * pfile)
 {	int fd, oflag, mode ;
-
 	/*
 	** Sanity check. If everything is OK, this test and the printfs will
 	** be optimised out. This is meant to catch the problems caused by
 	** "sfconfig.h" being included after <stdio.h>.
 	*/
-	if (sizeof (off_t) != sizeof (sf_count_t))
+	if (sizeof (off64_t) != sizeof (sf_count_t))
 	{	puts ("\n\n*** Fatal error : sizeof (off_t) != sizeof (sf_count_t)") ;
 		puts ("*** This means that libsndfile was not configured correctly.\n") ;
 		exit (1) ;
 		} ;
-
 	switch (pfile->mode)
 	{	case SFM_READ :
 				oflag = O_RDONLY | O_BINARY ;
diff --git a/jni/libsndfile-1.0.25/src/flac.c~ b/jni/libsndfile-1.0.25/src/flac.c~
deleted file mode 100644
index 7949b0a..0000000
--- a/jni/libsndfile-1.0.25/src/flac.c~
+++ /dev/null
@@ -1,1324 +0,0 @@
-/*
-** Copyright (C) 2004-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
-** Copyright (C) 2004 Tobias Gehrig <tgehrig@ira.uka.de>
-**
-** This program is free software ; you can redistribute it and/or modify
-** it under the terms of the GNU Lesser General Public License as published by
-** the Free Software Foundation ; either version 2.1 of the License, or
-** (at your option) any later version.
-**
-** This program 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 Lesser General Public License for more details.
-**
-** You should have received a copy of the GNU Lesser General Public License
-** along with this program ; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include	"sfconfig.h"
-
-#include	<stdio.h>
-#include	<stdlib.h>
-#include	<fcntl.h>
-#include	<string.h>
-#include	<ctype.h>
-#include	<math.h>
-
-#include	"sndfile.h"
-#include	"common.h"
-
-#if HAVE_EXTERNAL_LIBS
-
-#include	<FLAC/stream_decoder.h>
-#include	<FLAC/stream_encoder.h>
-#include	<FLAC/metadata.h>
-
-/*------------------------------------------------------------------------------
-** Private static functions.
-*/
-
-#define ENC_BUFFER_SIZE 8192
-
-typedef enum
-{	PFLAC_PCM_SHORT = 50,
-	PFLAC_PCM_INT = 51,
-	PFLAC_PCM_FLOAT = 52,
-	PFLAC_PCM_DOUBLE = 53
-} PFLAC_PCM ;
-
-typedef struct
-{
-	FLAC__StreamDecoder *fsd ;
-	FLAC__StreamEncoder *fse ;
-
-	PFLAC_PCM pcmtype ;
-	void* ptr ;
-	unsigned pos, len, remain ;
-
-	FLAC__StreamMetadata *metadata ;
-
-	const FLAC__int32 * const * wbuffer ;
-	FLAC__int32 * rbuffer [FLAC__MAX_CHANNELS] ;
-
-	FLAC__int32* encbuffer ;
-	unsigned bufferpos ;
-
-	const FLAC__Frame *frame ;
-	FLAC__bool bufferbackup ;
-} FLAC_PRIVATE ;
-
-typedef struct
-{	const char *tag ;
-	int type ;
-} FLAC_TAG ;
-
-static sf_count_t	flac_seek (SF_PRIVATE *psf, int mode, sf_count_t offset) ;
-static int			flac_close (SF_PRIVATE *psf) ;
-
-static int			flac_enc_init (SF_PRIVATE *psf) ;
-static int			flac_read_header (SF_PRIVATE *psf) ;
-
-static sf_count_t	flac_read_flac2s (SF_PRIVATE *psf, short *ptr, sf_count_t len) ;
-static sf_count_t	flac_read_flac2i (SF_PRIVATE *psf, int *ptr, sf_count_t len) ;
-static sf_count_t	flac_read_flac2f (SF_PRIVATE *psf, float *ptr, sf_count_t len) ;
-static sf_count_t	flac_read_flac2d (SF_PRIVATE *psf, double *ptr, sf_count_t len) ;
-
-static sf_count_t	flac_write_s2flac (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
-static sf_count_t	flac_write_i2flac (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
-static sf_count_t	flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
-static sf_count_t	flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
-
-static void		f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-static void		d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
-
-static int flac_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
-
-/* Decoder Callbacks */
-static FLAC__StreamDecoderReadStatus sf_flac_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer [], size_t *bytes, void *client_data) ;
-static FLAC__StreamDecoderSeekStatus sf_flac_seek_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) ;
-static FLAC__StreamDecoderTellStatus sf_flac_tell_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ;
-static FLAC__StreamDecoderLengthStatus sf_flac_length_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) ;
-static FLAC__bool sf_flac_eof_callback (const FLAC__StreamDecoder *decoder, void *client_data) ;
-static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ;
-static void sf_flac_meta_callback (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ;
-static void sf_flac_error_callback (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ;
-
-/* Encoder Callbacks */
-static FLAC__StreamEncoderSeekStatus sf_flac_enc_seek_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) ;
-static FLAC__StreamEncoderTellStatus sf_flac_enc_tell_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ;
-static FLAC__StreamEncoderWriteStatus sf_flac_enc_write_callback (const FLAC__StreamEncoder *encoder, const FLAC__byte buffer [], size_t bytes, unsigned samples, unsigned current_frame, void *client_data) ;
-
-static void
-s2flac8_array (const short *src, FLAC__int32 *dest, int count)
-{	while (--count >= 0)
-		dest [count] = src [count] >> 8 ;
-} /* s2flac8_array */
-
-static void
-s2flac16_array (const short *src, FLAC__int32 *dest, int count)
-{	while (--count >= 0)
-		dest [count] = src [count] ;
-} /* s2flac16_array */
-
-static void
-s2flac24_array (const short *src, FLAC__int32 *dest, int count)
-{	while (--count >= 0)
-		dest [count] = src [count] << 8 ;
-} /* s2flac24_array */
-
-static void
-i2flac8_array (const int *src, FLAC__int32 *dest, int count)
-{	while (--count >= 0)
-		dest [count] = src [count] >> 24 ;
-} /* i2flac8_array */
-
-static void
-i2flac16_array (const int *src, FLAC__int32 *dest, int count)
-{
-  while (--count >= 0)
-    dest [count] = src [count] >> 16 ;
-} /* i2flac16_array */
-
-static void
-i2flac24_array (const int *src, FLAC__int32 *dest, int count)
-{	while (--count >= 0)
-		dest [count] = src [count] >> 8 ;
-} /* i2flac24_array */
-
-static sf_count_t
-flac_buffer_copy (SF_PRIVATE *psf)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	const FLAC__Frame *frame = pflac->frame ;
-	const FLAC__int32* const *buffer = pflac->wbuffer ;
-	unsigned i = 0, j, offset ;
-
-	/*
-	**	frame->header.blocksize is variable and we're using a constant blocksize
-	**	of FLAC__MAX_BLOCK_SIZE.
-	**	Check our assumptions here.
-	*/
-	if (frame->header.blocksize > FLAC__MAX_BLOCK_SIZE)
-	{	psf_log_printf (psf, "Ooops : frame->header.blocksize (%d) > FLAC__MAX_BLOCK_SIZE (%d)\n", __func__, __LINE__, frame->header.blocksize, FLAC__MAX_BLOCK_SIZE) ;
-		psf->error = SFE_INTERNAL ;
-		return 0 ;
-		} ;
-
-	if (pflac->ptr == NULL)
-	{	/*
-		**	Not sure why this code is here and not elsewhere.
-		**	Removing it causes valgrind errors.
-		*/
-		pflac->bufferbackup = SF_TRUE ;
-		for (i = 0 ; i < frame->header.channels ; i++)
-		{
-			if (pflac->rbuffer [i] == NULL)
-				pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (FLAC__int32)) ;
-
-			memcpy (pflac->rbuffer [i], buffer [i], frame->header.blocksize * sizeof (FLAC__int32)) ;
-			} ;
-		pflac->wbuffer = (const FLAC__int32* const*) pflac->rbuffer ;
-
-		return 0 ;
-		} ;
-
-	switch (pflac->pcmtype)
-	{	case PFLAC_PCM_SHORT :
-			{	short *retpcm = (short*) pflac->ptr ;
-				int shift = 16 - frame->header.bits_per_sample ;
-				if (shift < 0)
-				{	shift = abs (shift) ;
-					for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
-					{	offset = pflac->pos + i * frame->header.channels ;
-
-						if (pflac->bufferpos >= frame->header.blocksize)
-							break ;
-
-						for (j = 0 ; j < frame->header.channels ; j++)
-							retpcm [offset + j] = buffer [j][pflac->bufferpos] >> shift ;
-						pflac->remain -= frame->header.channels ;
-						pflac->bufferpos++ ;
-						}
-					}
-				else
-				{	for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
-					{	offset = pflac->pos + i * frame->header.channels ;
-
-						if (pflac->bufferpos >= frame->header.blocksize)
-							break ;
-
-						for (j = 0 ; j < frame->header.channels ; j++)
-							retpcm [offset + j] = (buffer [j][pflac->bufferpos]) << shift ;
-
-						pflac->remain -= frame->header.channels ;
-						pflac->bufferpos++ ;
-						} ;
-					} ;
-				} ;
-			break ;
-
-		case PFLAC_PCM_INT :
-			{	int *retpcm = (int*) pflac->ptr ;
-				int shift = 32 - frame->header.bits_per_sample ;
-				for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
-				{	offset = pflac->pos + i * frame->header.channels ;
-
-					if (pflac->bufferpos >= frame->header.blocksize)
-						break ;
-
-					for (j = 0 ; j < frame->header.channels ; j++)
-						retpcm [offset + j] = buffer [j][pflac->bufferpos] << shift ;
-					pflac->remain -= frame->header.channels ;
-					pflac->bufferpos++ ;
-					} ;
-				} ;
-			break ;
-
-		case PFLAC_PCM_FLOAT :
-			{	float *retpcm = (float*) pflac->ptr ;
-				float norm = (psf->norm_float == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
-
-				for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
-				{	offset = pflac->pos + i * frame->header.channels ;
-
-					if (pflac->bufferpos >= frame->header.blocksize)
-						break ;
-
-					for (j = 0 ; j < frame->header.channels ; j++)
-						retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
-					pflac->remain -= frame->header.channels ;
-					pflac->bufferpos++ ;
-					} ;
-				} ;
-			break ;
-
-		case PFLAC_PCM_DOUBLE :
-			{	double *retpcm = (double*) pflac->ptr ;
-				double norm = (psf->norm_double == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
-
-				for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
-				{	offset = pflac->pos + i * frame->header.channels ;
-
-					if (pflac->bufferpos >= frame->header.blocksize)
-						break ;
-
-					for (j = 0 ; j < frame->header.channels ; j++)
-						retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
-					pflac->remain -= frame->header.channels ;
-					pflac->bufferpos++ ;
-					} ;
-				} ;
-			break ;
-
-		default :
-			return 0 ;
-		} ;
-
-	offset = i * frame->header.channels ;
-	pflac->pos += i * frame->header.channels ;
-
-	return offset ;
-} /* flac_buffer_copy */
-
-
-static FLAC__StreamDecoderReadStatus
-sf_flac_read_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__byte buffer [], size_t *bytes, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	*bytes = psf_fread (buffer, 1, *bytes, psf) ;
-	if (*bytes > 0 && psf->error == 0)
-		return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE ;
-
-    return FLAC__STREAM_DECODER_READ_STATUS_ABORT ;
-} /* sf_flac_read_callback */
-
-static FLAC__StreamDecoderSeekStatus
-sf_flac_seek_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 absolute_byte_offset, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	psf_fseek (psf, absolute_byte_offset, SEEK_SET) ;
-	if (psf->error)
-		return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR ;
-
-	return FLAC__STREAM_DECODER_SEEK_STATUS_OK ;
-} /* sf_flac_seek_callback */
-
-static FLAC__StreamDecoderTellStatus
-sf_flac_tell_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *absolute_byte_offset, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	*absolute_byte_offset = psf_ftell (psf) ;
-	if (psf->error)
-		return FLAC__STREAM_DECODER_TELL_STATUS_ERROR ;
-
-	return FLAC__STREAM_DECODER_TELL_STATUS_OK ;
-} /* sf_flac_tell_callback */
-
-static FLAC__StreamDecoderLengthStatus
-sf_flac_length_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *stream_length, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	if ((*stream_length = psf->filelength) == 0)
-		return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR ;
-
-	return FLAC__STREAM_DECODER_LENGTH_STATUS_OK ;
-} /* sf_flac_length_callback */
-
-static FLAC__bool
-sf_flac_eof_callback (const FLAC__StreamDecoder *UNUSED (decoder), void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	if (psf_ftell (psf) == psf->filelength)
-		return SF_TRUE ;
-
-    return SF_FALSE ;
-} /* sf_flac_eof_callback */
-
-static FLAC__StreamDecoderWriteStatus
-sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-
-	pflac->frame = frame ;
-	pflac->bufferpos = 0 ;
-
-	pflac->bufferbackup = SF_FALSE ;
-	pflac->wbuffer = buffer ;
-
-	flac_buffer_copy (psf) ;
-
-	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE ;
-} /* sf_flac_write_callback */
-
-static void
-sf_flac_meta_get_vorbiscomments (SF_PRIVATE *psf, const FLAC__StreamMetadata *metadata)
-{	FLAC_TAG tags [] =
-	{ 	{ "title", SF_STR_TITLE },
-		{ "copyright", SF_STR_COPYRIGHT },
-		{ "software", SF_STR_SOFTWARE },
-		{ "artist", SF_STR_ARTIST },
-		{ "comment", SF_STR_COMMENT },
-		{ "date", SF_STR_DATE },
-		{ "album", SF_STR_ALBUM },
-		{ "license", SF_STR_LICENSE },
-		{ "tracknumber", SF_STR_TRACKNUMBER },
-		{ "genre", SF_STR_GENRE }
-		} ;
-
-	const char *value, *cptr ;
-	int k, tag_num ;
-
-	for (k = 0 ; k < ARRAY_LEN (tags) ; k++)
-	{	tag_num = FLAC__metadata_object_vorbiscomment_find_entry_from (metadata, 0, tags [k].tag) ;
-
-		if (tag_num < 0)
-			continue ;
-
-		value = (const char*) metadata->data.vorbis_comment.comments [tag_num].entry ;
-		if ((cptr = strchr (value, '=')) != NULL)
-			value = cptr + 1 ;
-
-		psf_log_printf (psf, "  %-10s : %s\n", tags [k].tag, value) ;
-		psf_store_string (psf, tags [k].type, value) ;
-		} ;
-
-	return ;
-} /* sf_flac_meta_get_vorbiscomments */
-
-static void
-sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-	int bitwidth = 0 ;
-
-	switch (metadata->type)
-	{	case FLAC__METADATA_TYPE_STREAMINFO :
-			psf->sf.channels = metadata->data.stream_info.channels ;
-			psf->sf.samplerate = metadata->data.stream_info.sample_rate ;
-			psf->sf.frames = metadata->data.stream_info.total_samples ;
-
-			psf_log_printf (psf, "FLAC Stream Metadata\n  Channels    : %d\n  Sample rate : %d\n", psf->sf.channels, psf->sf.samplerate) ;
-
-			if (psf->sf.frames == 0)
-			{	psf_log_printf (psf, "  Frames      : 0 (bumping to SF_COUNT_MAX)\n") ;
-				psf->sf.frames = SF_COUNT_MAX ;
-				}
-			else
-				psf_log_printf (psf, "  Frames      : %D\n", psf->sf.frames) ;
-
-			switch (metadata->data.stream_info.bits_per_sample)
-			{	case 8 :
-					psf->sf.format |= SF_FORMAT_PCM_S8 ;
-					bitwidth = 8 ;
-					break ;
-				case 16 :
-					psf->sf.format |= SF_FORMAT_PCM_16 ;
-					bitwidth = 16 ;
-					break ;
-				case 24 :
-					psf->sf.format |= SF_FORMAT_PCM_24 ;
-					bitwidth = 24 ;
-					break ;
-				default :
-					psf_log_printf (psf, "sf_flac_meta_callback : bits_per_sample %d not yet implemented.\n", metadata->data.stream_info.bits_per_sample) ;
-					break ;
-				} ;
-
-			if (bitwidth > 0)
-				psf_log_printf (psf, "  Bit width   : %d\n", bitwidth) ;
-			break ;
-
-		case FLAC__METADATA_TYPE_VORBIS_COMMENT :
-			psf_log_printf (psf, "Vorbis Comment Metadata\n") ;
-			sf_flac_meta_get_vorbiscomments (psf, metadata) ;
-			break ;
-
-		case FLAC__METADATA_TYPE_PADDING :
-			psf_log_printf (psf, "Padding Metadata\n") ;
-			break ;
-
-		case FLAC__METADATA_TYPE_APPLICATION :
-			psf_log_printf (psf, "Application Metadata\n") ;
-			break ;
-
-		case FLAC__METADATA_TYPE_SEEKTABLE :
-			psf_log_printf (psf, "Seektable Metadata\n") ;
-			break ;
-
-		case FLAC__METADATA_TYPE_CUESHEET :
-			psf_log_printf (psf, "Cuesheet Metadata\n") ;
-			break ;
-
-		case FLAC__METADATA_TYPE_PICTURE :
-			psf_log_printf (psf, "Picture Metadata\n") ;
-			break ;
-
-		case FLAC__METADATA_TYPE_UNDEFINED :
-			psf_log_printf (psf, "Undefined Metadata\n") ;
-			break ;
-
-		default :
-			psf_log_printf (psf, "sf_flac_meta_callback : metadata-type %d not yet implemented.\n", metadata->type) ;
-			break ;
-		} ;
-
-	return ;
-} /* sf_flac_meta_callback */
-
-static void
-sf_flac_error_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__StreamDecoderErrorStatus status, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	psf_log_printf (psf, "ERROR : %s\n", FLAC__StreamDecoderErrorStatusString [status]) ;
-
-	switch (status)
-	{	case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC :
-			psf->error = SFE_FLAC_LOST_SYNC ;
-			break ;
-		case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER :
-			psf->error = SFE_FLAC_BAD_HEADER ;
-			break ;
-		default :
-			psf->error = SFE_FLAC_UNKOWN_ERROR ;
-			break ;
-		} ;
-
-	return ;
-} /* sf_flac_error_callback */
-
-static FLAC__StreamEncoderSeekStatus
-sf_flac_enc_seek_callback (const FLAC__StreamEncoder * UNUSED (encoder), FLAC__uint64 absolute_byte_offset, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	psf_fseek (psf, absolute_byte_offset, SEEK_SET) ;
-	if (psf->error)
-		return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR ;
-
-    return FLAC__STREAM_ENCODER_SEEK_STATUS_OK ;
-} /* sf_flac_enc_seek_callback */
-
-static FLAC__StreamEncoderTellStatus
-sf_flac_enc_tell_callback (const FLAC__StreamEncoder *UNUSED (encoder), FLAC__uint64 *absolute_byte_offset, void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	*absolute_byte_offset = psf_ftell (psf) ;
-	if (psf->error)
-		return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR ;
-
-	return FLAC__STREAM_ENCODER_TELL_STATUS_OK ;
-} /* sf_flac_enc_tell_callback */
-
-static FLAC__StreamEncoderWriteStatus
-sf_flac_enc_write_callback (const FLAC__StreamEncoder * UNUSED (encoder), const FLAC__byte buffer [], size_t bytes, unsigned UNUSED (samples), unsigned UNUSED (current_frame), void *client_data)
-{	SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
-
-	if (psf_fwrite (buffer, 1, bytes, psf) == (sf_count_t) bytes && psf->error == 0)
-		return FLAC__STREAM_ENCODER_WRITE_STATUS_OK ;
-
-	return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR ;
-} /* sf_flac_enc_write_callback */
-
-static void
-flac_write_strings (SF_PRIVATE *psf, FLAC_PRIVATE* pflac)
-{	FLAC__StreamMetadata_VorbisComment_Entry entry ;
-	int	k, string_count = 0 ;
-
-	for (k = 0 ; k < SF_MAX_STRINGS ; k++)
-	{	if (psf->strings [k].type != 0)
-			string_count ++ ;
-		} ;
-
-	if (string_count == 0)
-		return ;
-
-	if (pflac->metadata == NULL && (pflac->metadata = FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT)) == NULL)
-	{	psf_log_printf (psf, "FLAC__metadata_object_new returned NULL\n") ;
-		return ;
-		} ;
-
-	for (k = 0 ; k < SF_MAX_STRINGS && psf->strings [k].type != 0 ; k++)
-	{	const char * key, * value ;
-
-		switch (psf->strings [k].type)
-		{	case SF_STR_SOFTWARE :
-				key = "software" ;
-				break ;
-			case SF_STR_TITLE :
-				key = "title" ;
-				break ;
-			case SF_STR_COPYRIGHT :
-				key = "copyright" ;
-				break ;
-			case SF_STR_ARTIST :
-				key = "artist" ;
-				break ;
-			case SF_STR_COMMENT :
-				key = "comment" ;
-				break ;
-			case SF_STR_DATE :
-				key = "date" ;
-				break ;
-			case SF_STR_ALBUM :
-				key = "album" ;
-				break ;
-			case SF_STR_LICENSE :
-				key = "license" ;
-				break ;
-			case SF_STR_TRACKNUMBER :
-				key = "tracknumber" ;
-				break ;
-			case SF_STR_GENRE :
-				key = "genre" ;
-				break ;
-			default :
-				continue ;
-			} ;
-
-		value = psf->strings [k].str ;
-
-		FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair (&entry, key, value) ;
-		FLAC__metadata_object_vorbiscomment_append_comment (pflac->metadata, entry, /* copy */ SF_FALSE) ;
-		} ;
-
-	if (! FLAC__stream_encoder_set_metadata (pflac->fse, &pflac->metadata, 1))
-	{	printf ("%s %d : fail\n", __func__, __LINE__) ;
-		return ;
-		} ;
-
-	return ;
-} /* flac_write_strings */
-
-static int
-flac_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	int err ;
-
-	flac_write_strings (psf, pflac) ;
-
-	if ((err = FLAC__stream_encoder_init_stream (pflac->fse, sf_flac_enc_write_callback, sf_flac_enc_seek_callback, sf_flac_enc_tell_callback, NULL, psf)) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
-	{	psf_log_printf (psf, "Error : FLAC encoder init returned error : %s\n", FLAC__StreamEncoderInitStatusString [err]) ;
-		return SFE_FLAC_INIT_DECODER ;
-		} ;
-
-	if (psf->error == 0)
-		psf->dataoffset = psf_ftell (psf) ;
-	pflac->encbuffer = calloc (ENC_BUFFER_SIZE, sizeof (FLAC__int32)) ;
-
-	return psf->error ;
-} /* flac_write_header */
-
-/*------------------------------------------------------------------------------
-** Public function.
-*/
-
-int
-flac_open	(SF_PRIVATE *psf)
-{	int		subformat ;
-	int		error = 0 ;
-
-	FLAC_PRIVATE* pflac = calloc (1, sizeof (FLAC_PRIVATE)) ;
-	psf->codec_data = pflac ;
-
-	if (psf->file.mode == SFM_RDWR)
-		return SFE_BAD_MODE_RW ;
-
-	if (psf->file.mode == SFM_READ)
-	{	if ((error = flac_read_header (psf)))
-			return error ;
-		} ;
-
-	subformat = SF_CODEC (psf->sf.format) ;
-
-	if (psf->file.mode == SFM_WRITE)
-	{	if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_FLAC)
-			return	SFE_BAD_OPEN_FORMAT ;
-
-		psf->endian = SF_ENDIAN_BIG ;
-		psf->sf.seekable = 0 ;
-
-		psf->str_flags = SF_STR_ALLOW_START ;
-
-		if ((error = flac_enc_init (psf)))
-			return error ;
-
-		psf->write_header = flac_write_header ;
-		} ;
-
-	psf->datalength = psf->filelength ;
-	psf->dataoffset = 0 ;
-	psf->blockwidth = 0 ;
-	psf->bytewidth = 1 ;
-
-	psf->container_close = flac_close ;
-	psf->seek = flac_seek ;
-	psf->command = flac_command ;
-
-	psf->blockwidth = psf->bytewidth * psf->sf.channels ;
-
-	switch (subformat)
-	{	case SF_FORMAT_PCM_S8 :	/* 8-bit FLAC.  */
-		case SF_FORMAT_PCM_16 :	/* 16-bit FLAC. */
-		case SF_FORMAT_PCM_24 :	/* 24-bit FLAC. */
-			error = flac_init (psf) ;
-			break ;
-
-		default : return SFE_UNIMPLEMENTED ;
-		} ;
-
-	return error ;
-} /* flac_open */
-
-/*------------------------------------------------------------------------------
-*/
-
-static int
-flac_close	(SF_PRIVATE *psf)
-{	FLAC_PRIVATE* pflac ;
-	int k ;
-
-	if ((pflac = (FLAC_PRIVATE*) psf->codec_data) == NULL)
-		return 0 ;
-
-	if (pflac->metadata != NULL)
-		FLAC__metadata_object_delete (pflac->metadata) ;
-
-	if (psf->file.mode == SFM_WRITE)
-	{	FLAC__stream_encoder_finish (pflac->fse) ;
-		FLAC__stream_encoder_delete (pflac->fse) ;
-
-		if (pflac->encbuffer)
-			free (pflac->encbuffer) ;
-		} ;
-
-	if (psf->file.mode == SFM_READ)
-	{	FLAC__stream_decoder_finish (pflac->fsd) ;
-		FLAC__stream_decoder_delete (pflac->fsd) ;
-		} ;
-
-	for (k = 0 ; k < ARRAY_LEN (pflac->rbuffer) ; k++)
-		free (pflac->rbuffer [k]) ;
-
-	free (pflac) ;
-	psf->codec_data = NULL ;
-
-	return 0 ;
-} /* flac_close */
-
-static int
-flac_enc_init (SF_PRIVATE *psf)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	unsigned bps ;
-
-	/* To cite the flac FAQ at
-	** http://flac.sourceforge.net/faq.html#general__samples
-	**     "FLAC supports linear sample rates from 1Hz - 655350Hz in 1Hz
-	**     increments."
-	*/
-	if ( psf->sf.samplerate < 1 || psf->sf.samplerate > 655350 )
-	{	psf_log_printf (psf, "flac sample rate out of range.\n", psf->sf.samplerate) ;
-		return SFE_FLAC_BAD_SAMPLE_RATE ;
-		} ;
-
-	psf_fseek (psf, 0, SEEK_SET) ;
-
-	switch (SF_CODEC (psf->sf.format))
-	{	case SF_FORMAT_PCM_S8 :
-			bps = 8 ;
-			break ;
-		case SF_FORMAT_PCM_16 :
-			bps = 16 ;
-			break ;
-		case SF_FORMAT_PCM_24 :
-			bps = 24 ;
-			break ;
-
-		default :
-			bps = 0 ;
-			break ;
-		} ;
-
-	if ((pflac->fse = FLAC__stream_encoder_new ()) == NULL)
-		return SFE_FLAC_NEW_DECODER ;
-
-	if (! FLAC__stream_encoder_set_channels (pflac->fse, psf->sf.channels))
-	{	psf_log_printf (psf, "FLAC__stream_encoder_set_channels (%d) return false.\n", psf->sf.channels) ;
-		return SFE_FLAC_INIT_DECODER ;
-		} ;
-
-	if (! FLAC__stream_encoder_set_sample_rate (pflac->fse, psf->sf.samplerate))
-	{	psf_log_printf (psf, "FLAC__stream_encoder_set_sample_rate (%d) returned false.\n", psf->sf.samplerate) ;
-		return SFE_FLAC_BAD_SAMPLE_RATE ;
-		} ;
-
-	if (! FLAC__stream_encoder_set_bits_per_sample (pflac->fse, bps))
-	{	psf_log_printf (psf, "FLAC__stream_encoder_set_bits_per_sample (%d) return false.\n", bps) ;
-		return SFE_FLAC_INIT_DECODER ;
-		} ;
-
-	return 0 ;
-} /* flac_enc_init */
-
-static int
-flac_read_header (SF_PRIVATE *psf)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-
-	psf_fseek (psf, 0, SEEK_SET) ;
-	if ((pflac->fsd = FLAC__stream_decoder_new ()) == NULL)
-		return SFE_FLAC_NEW_DECODER ;
-
-	FLAC__stream_decoder_set_metadata_respond_all (pflac->fsd) ;
-
-	if (FLAC__stream_decoder_init_stream (pflac->fsd, sf_flac_read_callback, sf_flac_seek_callback, sf_flac_tell_callback, sf_flac_length_callback, sf_flac_eof_callback, sf_flac_write_callback, sf_flac_meta_callback, sf_flac_error_callback, psf) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
-		return SFE_FLAC_INIT_DECODER ;
-
-	FLAC__stream_decoder_process_until_end_of_metadata (pflac->fsd) ;
-
-	psf_log_printf (psf, "End\n") ;
-
-	if (psf->error == 0)
-	{	FLAC__uint64 position ;
-
-		FLAC__stream_decoder_get_decode_position (pflac->fsd, &position) ;
-		psf->dataoffset = position ;
-		} ;
-
-	return psf->error ;
-} /* flac_read_header */
-
-static int
-flac_command (SF_PRIVATE * UNUSED (psf), int UNUSED (command), void * UNUSED (data), int UNUSED (datasize))
-{
-	return 0 ;
-} /* flac_command */
-
-int
-flac_init (SF_PRIVATE *psf)
-{
-	if (psf->file.mode == SFM_RDWR)
-		return SFE_BAD_MODE_RW ;
-
-	if (psf->file.mode == SFM_READ)
-	{	psf->read_short		= flac_read_flac2s ;
-		psf->read_int		= flac_read_flac2i ;
-		psf->read_float		= flac_read_flac2f ;
-		psf->read_double	= flac_read_flac2d ;
-		} ;
-
-	if (psf->file.mode == SFM_WRITE)
-	{	psf->write_short	= flac_write_s2flac ;
-		psf->write_int		= flac_write_i2flac ;
-		psf->write_float	= flac_write_f2flac ;
-		psf->write_double	= flac_write_d2flac ;
-		} ;
-
-	psf->bytewidth = 1 ;
-	psf->blockwidth = psf->sf.channels ;
-
-	if (psf->filelength > psf->dataoffset)
-		psf->datalength = (psf->dataend) ? psf->dataend - psf->dataoffset : psf->filelength - psf->dataoffset ;
-	else
-		psf->datalength = 0 ;
-
-	return 0 ;
-} /* flac_init */
-
-static unsigned
-flac_read_loop (SF_PRIVATE *psf, unsigned len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-
-	pflac->pos = 0 ;
-	pflac->len = len ;
-	pflac->remain = len ;
-	if (pflac->frame != NULL && pflac->bufferpos < pflac->frame->header.blocksize)
-		flac_buffer_copy (psf) ;
-
-	while (pflac->pos < pflac->len)
-	{	if (FLAC__stream_decoder_process_single (pflac->fsd) == 0)
-			break ;
-		if (FLAC__stream_decoder_get_state (pflac->fsd) >= FLAC__STREAM_DECODER_END_OF_STREAM)
-			break ;
-		} ;
-
-	pflac->ptr = NULL ;
-
-	return pflac->pos ;
-} /* flac_read_loop */
-
-static sf_count_t
-flac_read_flac2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	sf_count_t total = 0, current ;
-	unsigned readlen ;
-
-	pflac->pcmtype = PFLAC_PCM_SHORT ;
-
-	while (total < len)
-	{	pflac->ptr = ptr + total ;
-		readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
-		current = flac_read_loop (psf, readlen) ;
-		if (current == 0)
-			break ;
-		total += current ;
-		} ;
-
-	return total ;
-} /* flac_read_flac2s */
-
-static sf_count_t
-flac_read_flac2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	sf_count_t total = 0, current ;
-	unsigned readlen ;
-
-	pflac->pcmtype = PFLAC_PCM_INT ;
-
-	while (total < len)
-	{	pflac->ptr = ptr + total ;
-		readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
-		current = flac_read_loop (psf, readlen) ;
-		if (current == 0)
-			break ;
-		total += current ;
-		} ;
-
-	return total ;
-} /* flac_read_flac2i */
-
-static sf_count_t
-flac_read_flac2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	sf_count_t total = 0, current ;
-	unsigned readlen ;
-
-	pflac->pcmtype = PFLAC_PCM_FLOAT ;
-
-	while (total < len)
-	{	pflac->ptr = ptr + total ;
-		readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
-		current = flac_read_loop (psf, readlen) ;
-		if (current == 0)
-			break ;
-		total += current ;
-		} ;
-
-	return total ;
-} /* flac_read_flac2f */
-
-static sf_count_t
-flac_read_flac2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	sf_count_t total = 0, current ;
-	unsigned readlen ;
-
-	pflac->pcmtype = PFLAC_PCM_DOUBLE ;
-
-	while (total < len)
-	{	pflac->ptr = ptr + total ;
-		readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
-		current = flac_read_loop (psf, readlen) ;
-		if (current == 0)
-			break ;
-		total += current ;
-		} ;
-
-	return total ;
-} /* flac_read_flac2d */
-
-static sf_count_t
-flac_write_s2flac (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	void (*convert) (const short *, FLAC__int32 *, int) ;
-	int bufferlen, writecount, thiswrite ;
-	sf_count_t	total = 0 ;
-	FLAC__int32* buffer = pflac->encbuffer ;
-
-	switch (SF_CODEC (psf->sf.format))
-	{	case SF_FORMAT_PCM_S8 :
-			convert = s2flac8_array ;
-			break ;
-		case SF_FORMAT_PCM_16 :
-			convert = s2flac16_array ;
-			break ;
-			case SF_FORMAT_PCM_24 :
-			convert = s2flac24_array ;
-			break ;
-		default :
-			return -1 ;
-		} ;
-
-	bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
-	bufferlen *= psf->sf.channels ;
-
-	while (len > 0)
-	{	writecount = (len >= bufferlen) ? bufferlen : (int) len ;
-		convert (ptr + total, buffer, writecount) ;
-		if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels))
-			thiswrite = writecount ;
-		else
-			break ;
-		total += thiswrite ;
-		if (thiswrite < writecount)
-			break ;
-
-		len -= thiswrite ;
-		} ;
-
-	return total ;
-} /* flac_write_s2flac */
-
-static sf_count_t
-flac_write_i2flac (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	void (*convert) (const int *, FLAC__int32 *, int) ;
-	int bufferlen, writecount, thiswrite ;
-	sf_count_t	total = 0 ;
-	FLAC__int32* buffer = pflac->encbuffer ;
-
-	switch (SF_CODEC (psf->sf.format))
-	{	case SF_FORMAT_PCM_S8 :
-			convert = i2flac8_array ;
-			break ;
-		case SF_FORMAT_PCM_16 :
-			convert = i2flac16_array ;
-			break ;
-		case SF_FORMAT_PCM_24 :
-			convert = i2flac24_array ;
-			break ;
-		default :
-			return -1 ;
-		} ;
-
-	bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
-	bufferlen *= psf->sf.channels ;
-
-	while (len > 0)
-	{	writecount = (len >= bufferlen) ? bufferlen : (int) len ;
-		convert (ptr + total, buffer, writecount) ;
-		if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels))
-			thiswrite = writecount ;
-		else
-			break ;
-		total += thiswrite ;
-		if (thiswrite < writecount)
-			break ;
-
-		len -= thiswrite ;
-		} ;
-
-	return total ;
-} /* flac_write_i2flac */
-
-static sf_count_t
-flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	void (*convert) (const float *, FLAC__int32 *, int, int) ;
-	int bufferlen, writecount, thiswrite ;
-	sf_count_t	total = 0 ;
-	FLAC__int32* buffer = pflac->encbuffer ;
-
-	switch (SF_CODEC (psf->sf.format))
-	{	case SF_FORMAT_PCM_S8 :
-			convert = (psf->add_clipping) ? f2flac8_clip_array : f2flac8_array ;
-			break ;
-		case SF_FORMAT_PCM_16 :
-			convert = (psf->add_clipping) ? f2flac16_clip_array : f2flac16_array ;
-			break ;
-		case SF_FORMAT_PCM_24 :
-			convert = (psf->add_clipping) ? f2flac24_clip_array : f2flac24_array ;
-			break ;
-		default :
-			return -1 ;
-		} ;
-
-	bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
-	bufferlen *= psf->sf.channels ;
-
-	while (len > 0)
-	{	writecount = (len >= bufferlen) ? bufferlen : (int) len ;
-		convert (ptr + total, buffer, writecount, psf->norm_float) ;
-		if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels))
-			thiswrite = writecount ;
-		else
-			break ;
-		total += thiswrite ;
-		if (thiswrite < writecount)
-			break ;
-
-		len -= thiswrite ;
-		} ;
-
-	return total ;
-} /* flac_write_f2flac */
-
-static void
-f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{	float normfact, scaled_value ;
-
-	normfact = normalize ? (8.0 * 0x10) : 1.0 ;
-
-	while (--count >= 0)
-	{	scaled_value = src [count] * normfact ;
-		if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
-		{	dest [count] = 0x7F ;
-			continue ;
-			} ;
-		if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
-		{	dest [count] = 0x80 ;
-			continue ;
-			} ;
-		dest [count] = lrintf (scaled_value) ;
-		} ;
-
-	return ;
-} /* f2flac8_clip_array */
-
-static void
-f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{
-  float normfact, scaled_value ;
-
-  normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
-
-  while (--count >= 0) {
-    scaled_value = src [count] * normfact ;
-    if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF)) {
-      dest [count] = 0x7FFF ;
-      continue ;
-    }
-    if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000)) {
-      dest [count] = 0x8000 ;
-      continue ;
-    }
-    dest [count] = lrintf (scaled_value) ;
-  }
-} /* f2flac16_clip_array */
-
-static void
-f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{	float normfact, scaled_value ;
-
-	normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
-
-	while (--count >= 0)
-	{	scaled_value = src [count] * normfact ;
-		if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
-		{	dest [count] = 0x7FFFFF ;
-			continue ;
-			} ;
-
-		if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
-		{	dest [count] = 0x800000 ;
-			continue ;
-			}
-		dest [count] = lrintf (scaled_value) ;
-		} ;
-
-	return ;
-} /* f2flac24_clip_array */
-
-static void
-f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{	float normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrintf (src [count] * normfact) ;
-} /* f2flac8_array */
-
-static void
-f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{	float normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrintf (src [count] * normfact) ;
-} /* f2flac16_array */
-
-static void
-f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize)
-{	float normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrintf (src [count] * normfact) ;
-} /* f2flac24_array */
-
-static sf_count_t
-flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-	void (*convert) (const double *, FLAC__int32 *, int, int) ;
-	int bufferlen, writecount, thiswrite ;
-	sf_count_t	total = 0 ;
-	FLAC__int32* buffer = pflac->encbuffer ;
-
-	switch (SF_CODEC (psf->sf.format))
-	{	case SF_FORMAT_PCM_S8 :
-			convert = (psf->add_clipping) ? d2flac8_clip_array : d2flac8_array ;
-			break ;
-		case SF_FORMAT_PCM_16 :
-			convert = (psf->add_clipping) ? d2flac16_clip_array : d2flac16_array ;
-			break ;
-		case SF_FORMAT_PCM_24 :
-			convert = (psf->add_clipping) ? d2flac24_clip_array : d2flac24_array ;
-			break ;
-		default :
-			return -1 ;
-		} ;
-
-	bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
-	bufferlen *= psf->sf.channels ;
-
-	while (len > 0)
-	{	writecount = (len >= bufferlen) ? bufferlen : (int) len ;
-		convert (ptr + total, buffer, writecount, psf->norm_double) ;
-		if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels))
-			thiswrite = writecount ;
-		else
-			break ;
-		total += thiswrite ;
-		if (thiswrite < writecount)
-			break ;
-
-		len -= thiswrite ;
-		} ;
-
-	return total ;
-} /* flac_write_d2flac */
-
-static void
-d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact, scaled_value ;
-
-	normfact = normalize ? (8.0 * 0x10) : 1.0 ;
-
-	while (--count >= 0)
-	{	scaled_value = src [count] * normfact ;
-		if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
-		{	dest [count] = 0x7F ;
-			continue ;
-			} ;
-		if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
-		{	dest [count] = 0x80 ;
-			continue ;
-			} ;
-		dest [count] = lrint (scaled_value) ;
-		} ;
-
-	return ;
-} /* d2flac8_clip_array */
-
-static void
-d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact, scaled_value ;
-
-	normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
-
-	while (--count >= 0)
-	{	scaled_value = src [count] * normfact ;
-		if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
-		{	dest [count] = 0x7FFF ;
-			continue ;
-			} ;
-		if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
-		{	dest [count] = 0x8000 ;
-			continue ;
-			} ;
-		dest [count] = lrint (scaled_value) ;
-		} ;
-
-	return ;
-} /* d2flac16_clip_array */
-
-static void
-d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact, scaled_value ;
-
-	normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
-
-	while (--count >= 0)
-	{	scaled_value = src [count] * normfact ;
-		if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
-		{	dest [count] = 0x7FFFFF ;
-			continue ;
-			} ;
-		if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
-		{	dest [count] = 0x800000 ;
-			continue ;
-			} ;
-		dest [count] = lrint (scaled_value) ;
-		} ;
-
-	return ;
-} /* d2flac24_clip_array */
-
-static void
-d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrint (src [count] * normfact) ;
-} /* d2flac8_array */
-
-static void
-d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrint (src [count] * normfact) ;
-} /* d2flac16_array */
-
-static void
-d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize)
-{	double normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
-
-	while (--count >= 0)
-		dest [count] = lrint (src [count] * normfact) ;
-} /* d2flac24_array */
-
-static sf_count_t
-flac_seek (SF_PRIVATE *psf, int UNUSED (mode), sf_count_t offset)
-{	FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
-
-	if (pflac == NULL)
-		return 0 ;
-
-	if (psf->dataoffset < 0)
-	{	psf->error = SFE_BAD_SEEK ;
-		return ((sf_count_t) -1) ;
-		} ;
-
-	pflac->frame = NULL ;
-
-	if (psf->file.mode == SFM_READ)
-	{	FLAC__uint64 position ;
-		if (FLAC__stream_decoder_seek_absolute (pflac->fsd, offset))
-		{	FLAC__stream_decoder_get_decode_position (pflac->fsd, &position) ;
-			return offset ;
-			} ;
-
-		return ((sf_count_t) -1) ;
-		} ;
-
-	/* Seeking in write mode not yet supported. */
-	psf->error = SFE_BAD_SEEK ;
-
-	return ((sf_count_t) -1) ;
-} /* flac_seek */
-
-#else /* HAVE_EXTERNAL_LIBS */
-
-int
-flac_open	(SF_PRIVATE *psf)
-{
-	psf_log_printf (psf, "This version of libsndfile was compiled without FLAC support.\n") ;
-	return SFE_UNIMPLEMENTED ;
-} /* flac_open */
-
-#endif
diff --git a/jni/libsndfile-1.0.25/src/sndfile.c b/jni/libsndfile-1.0.25/src/sndfile.c
index d88a16c..1f373f9 100644
--- a/jni/libsndfile-1.0.25/src/sndfile.c
+++ b/jni/libsndfile-1.0.25/src/sndfile.c
@@ -304,31 +304,31 @@
 **	Public functions.
 */
 
-SNDFILE*
+SNDFILE* 
 sf_open	(const char *path, int mode, SF_INFO *sfinfo)
-{	SF_PRIVATE 	*psf ;
+{	
+
+	SF_PRIVATE 	*psf ;
 
 	/* Ultimate sanity check. */
 	assert (sizeof (sf_count_t) == 8) ;
-
 	if ((psf = calloc (1, sizeof (SF_PRIVATE))) == NULL)
 	{	sf_errno = SFE_MALLOC_FAILED ;
 		return	NULL ;
 		} ;
-
 	memset (psf, 0, sizeof (SF_PRIVATE)) ;
 	psf_init_files (psf) ;
 
-	psf_log_printf (psf, "File : %s\n", path) ;
+	psf_log_printf (psf, "File : %s\n", path);
 
 	copy_filename (psf, path) ;
 
 	psf->file.mode = mode ;
-	if (strcmp (path, "-") == 0)
+	if (strcmp (path, "-") == 0){
 		psf->error = psf_set_stdio (psf) ;
-	else
+	}else{
 		psf->error = psf_fopen (psf) ;
-
+	}
 	return psf_open_file (psf, sfinfo) ;
 } /* sf_open */
 
@@ -538,7 +538,6 @@
 int
 sf_format_check	(const SF_INFO *info)
 {	int	subformat, endian ;
-
 	subformat = SF_CODEC (info->format) ;
 	endian = SF_ENDIAN (info->format) ;
 
@@ -2566,22 +2565,22 @@
 
 	sf_errno = error = 0 ;
 	sf_logbuffer [0] = 0 ;
-
+__android_log_print(3,"TAG","psf_open_file 1");
 	if (psf->error)
 	{	error = psf->error ;
 		goto error_exit ;
 		} ;
-
+__android_log_print(3,"TAG","psf_open_file 2");
 	if (psf->file.mode != SFM_READ && psf->file.mode != SFM_WRITE && psf->file.mode != SFM_RDWR)
 	{	error = SFE_BAD_OPEN_MODE ;
 		goto error_exit ;
 		} ;
-
+__android_log_print(3,"TAG","psf_open_file 3");
 	if (sfinfo == NULL)
 	{	error = SFE_BAD_SF_INFO_PTR ;
 		goto error_exit ;
 		} ;
-
+__android_log_print(3,"TAG","psf_open_file 4");
 	/* Zero out these fields. */
 	sfinfo->frames = 0 ;
 	sfinfo->sections = 0 ;
diff --git a/jni/libsndfile-1.0.25/src/sndfile.h b/jni/libsndfile-1.0.25/src/sndfile.h
index d0b26de..7fbac4c 100644
--- a/jni/libsndfile-1.0.25/src/sndfile.h
+++ b/jni/libsndfile-1.0.25/src/sndfile.h
@@ -315,7 +315,7 @@
 typedef __int64		sf_count_t ;
 #define SF_COUNT_MAX		0x7fffffffffffffffi64
 #else
-typedef int64_t	sf_count_t ;
+typedef off64_t	sf_count_t ;
 #define SF_COUNT_MAX		0x7FFFFFFFFFFFFFFFLL
 #endif
 
diff --git a/jni/libsndfile-1.0.25/src/sndfile.hh b/jni/libsndfile-1.0.25/src/sndfile.hh
index d80ec4c..06c51d4 100644
--- a/jni/libsndfile-1.0.25/src/sndfile.hh
+++ b/jni/libsndfile-1.0.25/src/sndfile.hh
@@ -175,8 +175,10 @@
 		p->sfinfo.samplerate = srate ;
 		p->sfinfo.sections = 0 ;
 		p->sfinfo.seekable = 0 ;
-
+		
 		p->sf = sf_open (path, mode, &p->sfinfo) ;
+
+		//sf_format_check(&p->sfinfo);
 		} ;
 
 	return ;
diff --git a/jni/libsndfile-1.0.25/tests/Makefile b/jni/libsndfile-1.0.25/tests/Makefile
index 28981af..b557f7e 100644
--- a/jni/libsndfile-1.0.25/tests/Makefile
+++ b/jni/libsndfile-1.0.25/tests/Makefile
@@ -282,7 +282,7 @@
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run aclocal-1.11
 ACLOCAL_AMFLAGS = -I M4
-ALSA_LIBS = 
+ALSA_LIBS = -lasound
 AMTAR = ${SHELL} /home/lisional/git/sflphone-android/jni/libsndfile-1.0.25/Cfg/missing --run tar
 AM_DEFAULT_VERBOSITY = 0
 AR = ar
diff --git a/res/drawable-hdpi/ic_phones_call_transfer_icon.png b/res/drawable-hdpi/ic_phones_call_transfer_icon.png
new file mode 100644
index 0000000..9eda48d
--- /dev/null
+++ b/res/drawable-hdpi/ic_phones_call_transfer_icon.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_phones_call_transfer_icon.png b/res/drawable-mdpi/ic_phones_call_transfer_icon.png
new file mode 100644
index 0000000..1567622
--- /dev/null
+++ b/res/drawable-mdpi/ic_phones_call_transfer_icon.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_phones_call_transfer_icon.png b/res/drawable-xhdpi/ic_phones_call_transfer_icon.png
new file mode 100644
index 0000000..145c09a
--- /dev/null
+++ b/res/drawable-xhdpi/ic_phones_call_transfer_icon.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_phones_call_transfer_icon.png b/res/drawable-xxhdpi/ic_phones_call_transfer_icon.png
new file mode 100644
index 0000000..63e6819
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_phones_call_transfer_icon.png
Binary files differ
diff --git a/src/com/savoirfairelinux/sflphone/client/CallActivity.java b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
index 9c2c0c3..5f5d78b 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
@@ -412,8 +412,8 @@
     public void onRecordCall(SipCall call) {
         try {
 
-            service.setRecordPath(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
-            Log.w(TAG, "Recording path" + service.getRecordPath());
+//            service.setRecordPath(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
+            Log.w(TAG, "Recording path " + service.getRecordPath());
             service.toggleRecordingCall(call.getCallId());
 
         } catch (RemoteException e) {
diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
index a7c22ee..7dd4f0e 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java
@@ -31,8 +31,12 @@
 
 package com.savoirfairelinux.sflphone.fragments;
 
+import java.util.ArrayList;
+
 import android.app.Activity;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.PointF;
@@ -63,6 +67,8 @@
     float BUBBLE_SIZE = 75;
     static final float ATTRACTOR_SIZE = 40;
 
+    public static final int REQUEST_TRANSFER = 10;
+
     private Conference conf;
 
     private CounterTextView callStatusTxt;
@@ -75,7 +81,7 @@
 
     boolean accepted = false;
 
-    private Bitmap hangup_icon, separate_icon;
+    private Bitmap hangup_icon, transfer_icon;
     private Bitmap call_icon;
 
     @Override
@@ -196,6 +202,45 @@
     }
 
     @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        SipCall transfer = null;
+        if (requestCode == REQUEST_TRANSFER) {
+            switch (resultCode) {
+            case 0:
+                Conference c = data.getParcelableExtra("target");
+                transfer = data.getParcelableExtra("transfer");
+                try {
+
+                    mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId());
+
+                } catch (RemoteException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
+                break;
+
+            case 1:
+                String to = data.getStringExtra("to_number");
+                transfer = data.getParcelableExtra("transfer");
+                try {
+                    Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to, Toast.LENGTH_SHORT).show();
+                    mCallbacks.getService().transfer(transfer.getCallId(), to);
+                    mCallbacks.getService().hangUp(transfer.getCallId());
+                } catch (RemoteException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                break;
+
+            default:
+                break;
+            }
+        }
+    }
+
+    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
 
@@ -208,7 +253,7 @@
 
         hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup);
         call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
-        separate_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_separate);
+        transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon);
 
         // Do nothing here, the view is not initialized yet.
         return rootView;
@@ -237,7 +282,7 @@
         }
 
         model.clearAttractors();
-        model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
+        model.addAttractor(new Attractor(new PointF(model.width * .2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
             @Override
             public boolean onBubbleSucked(Bubble b) {
                 Log.w(TAG, "Bubble sucked ! ");
@@ -249,6 +294,8 @@
                             mCallbacks.getService().hangUpConference(conf.getId());
                         else
                             mCallbacks.onCallEnded(conf.getParticipants().get(0));
+
+                        model.clearAttractors();
                     } catch (RemoteException e) {
                         e.printStackTrace();
                     }
@@ -261,6 +308,15 @@
             }
         }, hangup_icon));
 
+        model.addAttractor(new Attractor(new PointF(model.width * .8f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
+            @Override
+            public boolean onBubbleSucked(Bubble b) {
+                Log.w(TAG, "Bubble sucked ! ");
+                makeTransfer(b);
+                return true;
+            }
+        }, transfer_icon));
+
         // if (conf.hasMultipleParticipants()) {
         // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() {
         // @Override
@@ -332,6 +388,7 @@
         }
 
         model.clearAttractors();
+
         model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * .9f), 40, new Attractor.Callback() {
             @Override
             public boolean onBubbleSucked(Bubble b) {
@@ -453,6 +510,19 @@
 
     }
 
+    public void makeTransfer(Bubble contact) {
+        FragmentManager fm = getFragmentManager();
+        TransferDFragment editName = new TransferDFragment();
+
+        Bundle b = new Bundle();
+        b.putParcelableArrayList("calls", new ArrayList<Conference>());
+        b.putParcelable("call_selected", contact.associated_call);
+        editName.setArguments(b);
+        editName.setTargetFragment(this, REQUEST_TRANSFER);
+        editName.show(fm, "");
+
+    }
+
     @Override
     public void surfaceCreated(SurfaceHolder holder) {
     }
@@ -465,5 +535,4 @@
         return view;
 
     }
-
 }
diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java
index 4b3f516..d31cfb7 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java
@@ -489,13 +489,13 @@
             if (call.getParticipants().size() == 1) {
                 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
             } else {
-                String tmp = "Conference with "+ call.getParticipants().size()+" participants";
-//                for (SipCall c : call.getParticipants()) {
-//                    tmp += c.getContact().getmDisplayName() + " ";
-//                }
+                String tmp = "Conference with " + call.getParticipants().size() + " participants";
+                // for (SipCall c : call.getParticipants()) {
+                // tmp += c.getContact().getmDisplayName() + " ";
+                // }
                 ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
             }
-//            ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
+            // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
             ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
             convertView.setOnDragListener(dragListener);
 
diff --git a/src/com/savoirfairelinux/sflphone/fragments/TransferDFragment.java b/src/com/savoirfairelinux/sflphone/fragments/TransferDFragment.java
index c410211..904bb1a 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/TransferDFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/TransferDFragment.java
@@ -67,7 +67,7 @@
         View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_transfer, null);
 
         ArrayList<Conference> calls = getArguments().getParcelableArrayList("calls");
-        final Conference call_selected = getArguments().getParcelable("call_selected");
+        final SipCall call_selected = getArguments().getParcelable("call_selected");
 
         mAdapter = new SimpleCallListAdapter(getActivity(), calls);
         ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
@@ -90,7 +90,7 @@
         mEditText.setAdapter(autoCompleteAdapter);
 
         final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView)
-                .setTitle("Transfer " + call_selected.getParticipants().get(0).getContact().getmDisplayName())
+                .setTitle("Transfer " + call_selected.getContact().getmDisplayName())
                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int whichButton) {
                         
diff --git a/src/com/savoirfairelinux/sflphone/model/BubblesView.java b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
index a29d8ab..235b680 100644
--- a/src/com/savoirfairelinux/sflphone/model/BubblesView.java
+++ b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
@@ -404,6 +404,7 @@
                         ((CallActivity) callback.getActivity()).onRecordCall(expand.associated_call);

                         break;

                     case 3:

+                        callback.makeTransfer(expand);

                         Toast.makeText(getContext(), "Not implemented here", Toast.LENGTH_SHORT).show();

                         break;

                     }