cvs: pecl /sndfile TODO config.m4 package.xml php_sndfile.h sndfile.c
| From: | Justin Hannus | Date: | Tue, 14 Sep 2004 02:07:00 +0000 |
| Subject: | cvs: pecl /sndfile TODO config.m4 package.xml php_sndfile.h sndfile.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1827@lists.php.net to get a copy of this message | ||
jhannus Mon Sep 13 22:07:00 2004 EDT
Added files:
/pecl/sndfile TODO config.m4 package.xml php_sndfile.h sndfile.c
Log:
Initial release.
http://cvs.php.net/co.php/pecl/sndfile/config.m4?r=1.1&p=1 Index: pecl/sndfile/config.m4 +++ pecl/sndfile/config.m4 PHP_ARG_WITH(sndfile, for libsndfile support, [ --with-sndfile Include libsndfile support]) if test "$PHP_SNDFILE" != "no"; then SEARCH_PATH="/usr/local /usr" SEARCH_FOR="/include/sndfile.h" if test -r $PHP_SNDFILE/$SEARCH_FOR; then SNDFILE_DIR=$PHP_SNDFILE else AC_MSG_CHECKING([for sndfile files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then SNDFILE_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$SNDFILE_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the libsndfile distribution]) fi PHP_ADD_INCLUDE($SNDFILE_DIR/include) LIBNAME=sndfile # you may want to change this LIBSYMBOL=sf_open_fd # you most likely want to change this PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SNDFILE_DIR/lib, SNDFILE_SHARED_LIBADD) AC_DEFINE(HAVE_SNDFILELIB,1,[ ]) ],[ AC_MSG_ERROR([wrong sndfile lib version or lib not found]) ],[ -L$SNDFILE_DIR/lib -lm -ldl ]) PHP_SUBST(SNDFILE_SHARED_LIBADD) PHP_NEW_EXTENSION(sndfile, sndfile.c, $ext_shared) fi http://cvs.php.net/co.php/pecl/sndfile/package.xml?r=1.1&p=1 Index: pecl/sndfile/package.xml +++ pecl/sndfile/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>sndfile</name> <summary>PHP interface for reading and writing sound files</summary> <description>The sndfile extension can read and write many different sound formats including wav, aiff and many many more.</description> <maintainers> <maintainer> <user>jhannus</user> <name>Justin Hannus</name> <email>jhannus@128kb.com</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <date>2004-08-26</date> <license>PHP</license> <state>alpha</state> <notes>Initial Release</notes> <deps> <dep type="php" rel="ge">4.3.0</dep> </deps> <filelist> <file role="src" md5sum="3c016455d36d5f4d2893d020860d3786" name="config.m4"/> <file role="src" md5sum="e7128270b22d1304692e10bd34575c79" name="php_sndfile.h"/> <file role="src" md5sum="a2e04fdc36d768d0a4b10c665c0f0041" name="sndfile.c"/> <file role="php" md5sum="aa251b6dfb90ef25c761c3968028795b" name="examples/process.php"/> <file role="php" md5sum="79cf093a8065ed8805c0e3d4c920bfb3" name="examples/make_cine.php"/> <file role="php" md5sum="3bf7673a96082c8b7d7436b2f9b6f86e" name="examples/make_cine_d.php"/> <file role="php" md5sum="72dc3b7b6950b0be42c7fe11145cff9f" name="examples/convert.php"/> </filelist> </release> </package> http://cvs.php.net/co.php/pecl/sndfile/php_sndfile.h?r=1.1&p=1 Index: pecl/sndfile/php_sndfile.h +++ pecl/sndfile/php_sndfile.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Justin Hannus <jhannus@php.net> | +----------------------------------------------------------------------+ */ #ifndef PHP_SNDFILE_H #define PHP_SNDFILE_H #include <sndfile.h> extern zend_module_entry sndfile_module_entry; #define phpext_sndfile_ptr &sndfile_module_entry PHP_MINIT_FUNCTION(sndfile); PHP_MSHUTDOWN_FUNCTION(sndfile); PHP_MINFO_FUNCTION(sndfile); PHP_FUNCTION(sndfile_open); PHP_FUNCTION(sndfile_close); PHP_FUNCTION(sndfile_buffer_create); PHP_FUNCTION(sndfile_buffer_free); PHP_FUNCTION(sndfile_buffer_type); PHP_FUNCTION(sndfile_buffer_size); PHP_FUNCTION(sndfile_convert_buffer2array); PHP_FUNCTION(sndfile_convert_array2buffer); PHP_FUNCTION(sndfile_buffer_set_pcm_at); PHP_FUNCTION(sndfile_buffer_get_pcm_at); PHP_FUNCTION(sndfile_command); PHP_FUNCTION(sndfile_error_str); PHP_FUNCTION(sndfile_error_code); PHP_FUNCTION(sndfile_get_info); PHP_FUNCTION(sndfile_format_check); PHP_FUNCTION(sndfile_set_string); PHP_FUNCTION(sndfile_get_string); PHP_FUNCTION(sndfile_read_int); PHP_FUNCTION(sndfile_read_double); PHP_FUNCTION(sndfile_write_int); PHP_FUNCTION(sndfile_write_double); PHP_FUNCTION(sndfile_readf_int); PHP_FUNCTION(sndfile_readf_double); PHP_FUNCTION(sndfile_writef_int); PHP_FUNCTION(sndfile_writef_double); PHP_FUNCTION(sndfile_rewind); PHP_FUNCTION(sndfile_eof); PHP_FUNCTION(sndfile_seek); #endif /* PHP_SNDFILE_H */ http://cvs.php.net/co.php/pecl/sndfile/sndfile.c?r=1.1&p=1 Index: pecl/sndfile/sndfile.c +++ pecl/sndfile/sndfile.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Justin Hannus <jhannus@php.net> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_globals.h" #include "ext/standard/php_standard.h" #include "ext/standard/info.h" #include "php_sndfile.h" #include <sndfile.h> #define SNDFILE_RSRC_NAME "sound file" #define SNDFILE_BUFF_RSRC_NAME "sound file buffer" #define READ_MODE_ITEMS 1 #define READ_MODE_FRAMES 2 #define WRITE_MODE_ITEMS 1 #define WRITE_MODE_FRAMES 2 #define BUFF_TYPE_INT 1 #define BUFF_TYPE_DOUBLE 2 #define php_sndfile_buffer_silent_realloc(_buf, _val, _size, _ptr, _type) \ if ((_ptr = (_type)erealloc(_buf->data._val, sizeof(_type) * (_buf->size + _size))) == NULL) { \ _size = _buf->size; \ } else { \ _buf->size = _size; \ _buf->data._val = _ptr; \ } typedef struct _php_sndfile { int eof; SF_INFO info; SNDFILE *sf; } php_sndfile; typedef struct _sndfile_buffer { int type; size_t size; union { double *dval; int *ival; } data; } sndfile_buffer; static int le_sndfile, le_sndfile_buffer; /* private functions */ static void _php_le_sndfile_close(zend_rsrc_list_entry *rsrc TSRMLS_DC); static void _php_le_sndfile_buffer_free(zend_rsrc_list_entry *rsrc TSRMLS_DC); static int php_sndfile_buffer_alloc_init(sndfile_buffer **, size_t, int TSRMLS_DC); static void php_sndfile_buffer_free(sndfile_buffer * TSRMLS_DC); static php_sndfile *php_sndfile_open(char *, char *, zval * TSRMLS_DC); static void php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode); static void php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode); static void php_sndfile_do_command(INTERNAL_FUNCTION_PARAMETERS, int TSRMLS_DC); #ifdef ZEND_ENGINE_2 static ZEND_BEGIN_ARG_INFO(third_arg_force_ref, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); static ZEND_BEGIN_ARG_INFO(first_arg_force_ref, 0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); #else static unsigned char third_arg_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; static unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE }; #endif /* {{{ php_sndfile_functions[] */ function_entry php_sndfile_functions[] = { PHP_FE(sndfile_open, third_arg_force_ref) PHP_FE(sndfile_close, NULL) PHP_FE(sndfile_buffer_create, NULL) PHP_FE(sndfile_buffer_free, NULL) PHP_FE(sndfile_buffer_type, NULL) PHP_FE(sndfile_buffer_size, NULL) PHP_FE(sndfile_buffer_set_pcm_at, NULL) PHP_FE(sndfile_buffer_get_pcm_at, NULL) PHP_FE(sndfile_convert_buffer2array, NULL) PHP_FE(sndfile_convert_array2buffer, first_arg_force_ref) PHP_FE(sndfile_command, NULL) PHP_FE(sndfile_error_str, NULL) PHP_FE(sndfile_error_code, NULL) PHP_FE(sndfile_get_info, NULL) PHP_FE(sndfile_format_check, NULL) PHP_FE(sndfile_read_int, NULL) PHP_FE(sndfile_write_int, NULL) PHP_FE(sndfile_read_double, NULL) PHP_FE(sndfile_write_double, NULL) PHP_FE(sndfile_readf_int, NULL) PHP_FE(sndfile_writef_int, NULL) PHP_FE(sndfile_readf_double, NULL) PHP_FE(sndfile_writef_double, NULL) PHP_FE(sndfile_set_string, NULL) PHP_FE(sndfile_get_string, NULL) PHP_FE(sndfile_rewind, NULL) PHP_FE(sndfile_eof, NULL) PHP_FE(sndfile_seek, NULL) { NULL, NULL, NULL } }; /* }}} */ /* {{{ sndfile_module_entry[] */ zend_module_entry sndfile_module_entry = { STANDARD_MODULE_HEADER, "sndfile", php_sndfile_functions, PHP_MINIT(sndfile), PHP_MSHUTDOWN(sndfile), NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(sndfile), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SNDFILE ZEND_GET_MODULE(sndfile) #endif PHP_MINIT_FUNCTION(sndfile) { le_sndfile = zend_register_list_destructors_ex(_php_le_sndfile_close, NULL, SNDFILE_RSRC_NAME, module_number); le_sndfile_buffer = zend_register_list_destructors_ex(_php_le_sndfile_buffer_free, NULL, SNDFILE_BUFF_RSRC_NAME, module_number); REGISTER_LONG_CONSTANT("SF_BUFFER_INT", BUFF_TYPE_INT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_BUFFER_DOUBLE", BUFF_TYPE_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_TITLE", SF_STR_TITLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_COPYRIGHT", SF_STR_COPYRIGHT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_SOFTWARE", SF_STR_SOFTWARE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_ARTIST", SF_STR_ARTIST, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_COMMENT", SF_STR_COMMENT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_DATE", SF_STR_DATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_WAV", SF_FORMAT_WAV, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_AIFF", SF_FORMAT_AIFF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_AU", SF_FORMAT_AU, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_RAW", SF_FORMAT_RAW, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PAF", SF_FORMAT_PAF, CONST_CS | CONST_PERSISTENT); /* Ensoniq PARIS file format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_SVX", SF_FORMAT_SVX, CONST_CS | CONST_PERSISTENT); /* Amiga IFF / SVX8 / SV16 format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_NIST", SF_FORMAT_NIST, CONST_CS | CONST_PERSISTENT); /* Sphere NIST format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_VOC", SF_FORMAT_VOC, CONST_CS | CONST_PERSISTENT); /* VOC files. */ REGISTER_LONG_CONSTANT("SF_FORMAT_IRCAM", SF_FORMAT_IRCAM, CONST_CS | CONST_PERSISTENT); /* Berkeley/IRCAM/CARL */ REGISTER_LONG_CONSTANT("SF_FORMAT_W64", SF_FORMAT_W64, CONST_CS | CONST_PERSISTENT); /* Sonic Foundry's 64 bit RIFF/WAV */ REGISTER_LONG_CONSTANT("SF_FORMAT_MAT4", SF_FORMAT_MAT4, CONST_CS | CONST_PERSISTENT); /* Matlab (tm) V4.2 / GNU Octave 2.0 */ REGISTER_LONG_CONSTANT("SF_FORMAT_MAT5", SF_FORMAT_MAT5, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_S8", SF_FORMAT_PCM_S8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_16", SF_FORMAT_PCM_16, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_24", SF_FORMAT_PCM_24, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_32", SF_FORMAT_PCM_32, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_U8", SF_FORMAT_PCM_U8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_SUBMASK", SF_FORMAT_SUBMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_TYPEMASK", SF_FORMAT_TYPEMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_ENDMASK", SF_FORMAT_ENDMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_FLOAT", SF_FORMAT_FLOAT, CONST_CS | CONST_PERSISTENT); /* 32 bit float data */ REGISTER_LONG_CONSTANT("SF_FORMAT_DOUBLE", SF_FORMAT_DOUBLE, CONST_CS | CONST_PERSISTENT); /* 64 bit float data */ REGISTER_LONG_CONSTANT("SF_FORMAT_ULAW", SF_FORMAT_ULAW, CONST_CS | CONST_PERSISTENT); /* U-Law encoded. */ REGISTER_LONG_CONSTANT("SF_FORMAT_ALAW", SF_FORMAT_ALAW, CONST_CS | CONST_PERSISTENT); /* A-Law encoded. */ REGISTER_LONG_CONSTANT("SF_FORMAT_IMA_ADPCM", SF_FORMAT_IMA_ADPCM, CONST_CS | CONST_PERSISTENT); /* IMA ADPCM. */ REGISTER_LONG_CONSTANT("SF_FORMAT_MS_ADPCM", SF_FORMAT_MS_ADPCM, CONST_CS | CONST_PERSISTENT); /* Microsoft ADPCM. */ REGISTER_LONG_CONSTANT("SF_FORMAT_GSM610", SF_FORMAT_GSM610, CONST_CS | CONST_PERSISTENT); /* GSM 6.10 encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_VOX_ADPCM", SF_FORMAT_VOX_ADPCM, CONST_CS | CONST_PERSISTENT); /* Oki Dialogic ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G721_32", SF_FORMAT_G721_32, CONST_CS | CONST_PERSISTENT); /* 32kbs G721 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G723_24", SF_FORMAT_G723_24, CONST_CS | CONST_PERSISTENT); /* 24kbs G723 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G723_40", SF_FORMAT_G723_40, CONST_CS | CONST_PERSISTENT); /* 40kbs G723 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_12", SF_FORMAT_DWVW_12, CONST_CS | CONST_PERSISTENT); /* 12 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_16", SF_FORMAT_DWVW_16, CONST_CS | CONST_PERSISTENT); /* 16 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_24", SF_FORMAT_DWVW_24, CONST_CS | CONST_PERSISTENT); /* 24 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_N", SF_FORMAT_DWVW_N, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_LIB_VERSION", SFC_GET_LIB_VERSION, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_LOG_INFO", SFC_GET_LOG_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_SIGNAL_MAX", SFC_CALC_SIGNAL_MAX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_NORM_SIGNAL_MAX", SFC_CALC_NORM_SIGNAL_MAX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_MAX_ALL_CHANNELS", SFC_CALC_MAX_ALL_CHANNELS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_NORM_MAX_ALL_CHANNELS", SFC_CALC_NORM_MAX_ALL_CHANNELS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_NORM_FLOAT", SFC_SET_NORM_FLOAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_NORM_DOUBLE", SFC_SET_NORM_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_NORM_FLOAT", SFC_GET_NORM_FLOAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_NORM_DOUBLE", SFC_GET_NORM_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_SIMPLE_FORMAT_COUNT", SFC_GET_SIMPLE_FORMAT_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_SIMPLE_FORMAT", SFC_GET_SIMPLE_FORMAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_INFO", SFC_GET_FORMAT_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_MAJOR_COUNT", SFC_GET_FORMAT_MAJOR_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_MAJOR", SFC_GET_FORMAT_MAJOR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_SUBTYPE_COUNT", SFC_GET_FORMAT_SUBTYPE_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_SUBTYPE", SFC_GET_FORMAT_SUBTYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_ADD_PEAK_CHUNK", SFC_SET_ADD_PEAK_CHUNK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_UPDATE_HEADER_NOW", SFC_UPDATE_HEADER_NOW, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_UPDATE_HEADER_AUTO", SFC_SET_UPDATE_HEADER_AUTO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_FILE_TRUNCATE", SFC_FILE_TRUNCATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_RAW_START_OFFSET", SFC_SET_RAW_START_OFFSET, CONST_CS | CONST_PERSISTENT); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(sndfile) { return SUCCESS; } PHP_MINFO_FUNCTION(sndfile) { char buffer[32]; sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); php_info_print_table_start(); php_info_print_table_row(2, "libsndfile Support", "enabled"); php_info_print_table_row(2, "LIB_VERSION", buffer); php_info_print_table_end(); } /* {{{ _php_le_sndfile_close() */ static void _php_le_sndfile_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) { php_sndfile *sndfile = (php_sndfile *)rsrc->ptr; if (sndfile != NULL && sndfile->sf) { sf_close(sndfile->sf); } efree(sndfile); } /* }}} */ /* {{{ _php_le_sndfile_buffer_free() */ static void _php_le_sndfile_buffer_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) { sndfile_buffer *buffer = (sndfile_buffer *)rsrc->ptr; if (buffer != NULL) { php_sndfile_buffer_free(buffer); } } /* }}} */ /* {{{ php_sndfile_buffer_alloc_init() */ static int php_sndfile_buffer_alloc_init(sndfile_buffer **buffer, size_t size, int type TSRMLS_DC) { if ((*buffer = (sndfile_buffer *)emalloc(sizeof(sndfile_buffer))) == NULL) { return FAILURE; } switch (type) { case BUFF_TYPE_DOUBLE: if (((*buffer)->data.dval = (double *)ecalloc(size, sizeof(double))) == NULL) { efree(buffer); return FAILURE; } break; case BUFF_TYPE_INT: if (((*buffer)->data.ival = (int *)ecalloc(size, sizeof(int))) == NULL) { efree(buffer); return FAILURE; } break; default: { efree(*buffer); *buffer = NULL; return FAILURE; } } (*buffer)->type = type; (*buffer)->size = size; return SUCCESS; } /* }}} */ /* {{{ php_sndfile_buffer_free() */ static void php_sndfile_buffer_free(sndfile_buffer *buffer TSRMLS_DC) { switch (buffer->type) { case BUFF_TYPE_DOUBLE: efree(buffer->data.dval); break; case BUFF_TYPE_INT: efree(buffer->data.ival); break; } efree(buffer); return; } /* }}} */ /* {{{ php_array_to_sfinfo_struct */ static inline SF_INFO php_array_to_sfinfo_struct(zval *zarray) { zval **entry = NULL; char *string_key = NULL; uint string_len; ulong num_key; SF_INFO sfinfo; HashPosition pos; memset(&sfinfo, 0, sizeof(sfinfo)); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zarray), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zarray), (void **)&entry, &pos) == SUCCESS) { if (zend_hash_get_current_key_ex(Z_ARRVAL_P(zarray), &string_key, &string_len, &num_key, 1, &pos) == HASH_KEY_IS_STRING) { if (strcmp(string_key, "samplerate") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.samplerate = Z_LVAL_PP(entry); } else if (strcmp(string_key, "frames") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.frames = Z_LVAL_PP(entry); } else if (strcmp(string_key, "channels") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.channels = Z_LVAL_PP(entry); } else if (strcmp(string_key, "format") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.format = Z_LVAL_PP(entry); } else if (strcmp(string_key, "sections") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.sections = Z_LVAL_PP(entry); } else if (strcmp(string_key, "seekable") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.seekable = Z_LVAL_PP(entry); } efree(string_key); } zend_hash_move_forward_ex(Z_ARRVAL_P(zarray), &pos); } return sfinfo; } /* }}} */ /* {{{ php_sfinfo_struct_to_array */ static inline void php_sfinfo_struct_to_array(SF_INFO *sfinfo, zval *zarray) { if (Z_TYPE_P(zarray) != IS_ARRAY) { array_init(zarray); } add_assoc_long(zarray, "frames", sfinfo->frames); add_assoc_long(zarray, "samplerate", sfinfo->samplerate); add_assoc_long(zarray, "channels", sfinfo->channels); add_assoc_long(zarray, "format", sfinfo->format); add_assoc_long(zarray, "sections", sfinfo->sections); add_assoc_long(zarray, "seekable", sfinfo->seekable); return; } /* }}} */ /* {{{ php_sndfile_open */ static php_sndfile *php_sndfile_open(char *path, char *mode, zval *zsfinfo TSRMLS_DC) { php_sndfile *sndfile = NULL; if (strchr(mode, '+') || ((strchr(mode, 'w') || strchr(mode, 'a')) && strchr(mode, 'r'))) { php_error(E_WARNING, "Invalid opening mode. Simultaneous read/write operations are not permitted."); return NULL; } sndfile = (php_sndfile *) emalloc(sizeof(php_sndfile)); if (strchr(mode, 'r')) { memset(&sndfile->info, 0, sizeof(sndfile->info)); sndfile->sf = sf_open(path, SFM_READ, &sndfile->info); php_sfinfo_struct_to_array(&sndfile->info, zsfinfo); } else { if (zsfinfo && Z_TYPE_P(zsfinfo) == IS_ARRAY) { sndfile->info = php_array_to_sfinfo_struct(zsfinfo); sndfile->sf = sf_open(path, SFM_WRITE, &sndfile->info); } else { php_error(E_WARNING, "No sfinfo context supplied while opening soundfile for writing."); return NULL; } } if (!sndfile->sf) { php_error(E_WARNING, "sndfile open failed: %s", sf_strerror(sndfile->sf)); efree(sndfile); return NULL; } sndfile->eof = 0; return sndfile; } /* }}} */ /* {{{ php_sndfile_read_pcm_data */ static void php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode TSRMLS_DC) { zval *zsndfile, *zbuffer = NULL; sndfile_buffer *buffer = NULL; php_sndfile *sndfile; sf_count_t read; long items; void *tmp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &zsndfile, &zbuffer, &items) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (sndfile == NULL || buffer == NULL) { RETURN_FALSE; } switch (mode) { case READ_MODE_ITEMS: switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, dval, items, tmp, double *) } read = sf_read_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, ival, items, tmp, int *) } read = sf_read_int(sndfile->sf, buffer->data.ival, items); break; } break; case READ_MODE_FRAMES: switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, dval, items, tmp, double *) } read = sf_readf_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, ival, items, tmp, int *) } read = sf_readf_int(sndfile->sf, buffer->data.ival, items); break; } break; } if (read < items && read != -1) { sndfile->eof = 1; } RETURN_LONG(read); } /* }}} */ /* {{{ php_sndfile_write_pcm_data */ static void php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode TSRMLS_DC) { zval *zsndfile, *zbuffer = NULL; sndfile_buffer *buffer = NULL; php_sndfile *sndfile = NULL; long items = 0; sf_count_t samples; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &zsndfile, &zbuffer, &items) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (sndfile == NULL || buffer == NULL) { RETURN_FALSE; } if (ZEND_NUM_ARGS() < 3 || items > buffer->size) { items = buffer->size; } switch (mode) { case WRITE_MODE_ITEMS: switch (mode) { case BUFF_TYPE_DOUBLE: samples = sf_write_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: samples = sf_write_int(sndfile->sf, buffer->data.ival, items); break; } break; case WRITE_MODE_FRAMES: switch (mode) { case BUFF_TYPE_DOUBLE: samples = sf_writef_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: samples = sf_writef_int(sndfile->sf, buffer->data.ival, items); break; } break; } RETURN_LONG(samples); } /* }}} */ /* {{{ proto resource sndfile_open(string filename, string mode [, array &sfinfo]) Opens a soundfile. */ PHP_FUNCTION(sndfile_open) { zval *info = NULL; php_sndfile *sndfile = NULL; char *path = NULL, *mode = NULL; int path_len, mode_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a!", &path, &path_len, &mode, &mode_len, &info) == FAILURE) { return; } if ((sndfile = php_sndfile_open(path, mode, info)) != NULL) { RETURN_RESOURCE(zend_list_insert(sndfile, le_sndfile)); } RETURN_FALSE; } /* }}} */ /* {{{ proto void sndfile_close(resource sndfile) Closes a soundfile. */ PHP_FUNCTION(sndfile_close) { zval *zsndfile = NULL; if (zend_parse_parameters(1 TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } zend_list_delete(Z_LVAL_P(zsndfile)); } /* }}} */ /* {{{ proto resource sndfile_buffer_create(int length, int type) Create a new sndfile buffer resource. */ PHP_FUNCTION(sndfile_buffer_create) { sndfile_buffer *buffer = NULL; int type; long length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &length, &type) == FAILURE) { return; } if (php_sndfile_buffer_alloc_init(&buffer, length, type) == SUCCESS) { RETURN_RESOURCE(zend_list_insert(buffer, le_sndfile_buffer)); } RETURN_FALSE; } /* }}} */ /* {{{ proto int sndfile_buffer_type(resource buffer) Gets the buffer type. */ PHP_FUNCTION(sndfile_buffer_type) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { RETURN_LONG(0); } RETURN_LONG(buffer->type); } /* }}} */ /* {{{ proto int sndfile_buffer_size(resource buffer) Gets the buffer size. */ PHP_FUNCTION(sndfile_buffer_size) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { RETURN_LONG(0); } RETURN_LONG(buffer->size); } /* }}} */ /* {{{ proto void sndfile_buffer_free(resource sndfile_buffer) Releases the resources held for sndfile buffer. */ PHP_FUNCTION(sndfile_buffer_free) { zval *zbuffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } zend_list_delete(Z_LVAL_P(zbuffer)); } /* }}} */ /* {{{ proto bool sndfile_buffer_set_pcm_at(resource sndfile_buffer, int index, mixed value) Sets the pcm data value at the given index of a sndfile_buffer. */ PHP_FUNCTION(sndfile_buffer_set_pcm_at) { zval *zbuffer, *zvalue = NULL; sndfile_buffer *buffer = NULL; long index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &zbuffer, &index, &zvalue) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL || index >= buffer->size) { php_error(E_NOTICE, "sndfile_buffer_set_pcm_at: undefined index %ld.", index); RETURN_FALSE; } switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (Z_TYPE_P(zvalue) != IS_DOUBLE) { convert_to_double(zvalue); } buffer->data.dval[index] = Z_DVAL_P(zvalue); break; case BUFF_TYPE_INT: /* shortening of long may occur here */ if (Z_TYPE_P(zvalue) != IS_LONG) { convert_to_long(zvalue); } buffer->data.ival[index] = (int)Z_LVAL_P(zvalue); break; default: php_error(E_NOTICE, "sndfile_buffer_set_pcm_at: unknown buffer type %d.", buffer->type); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto mixed sndfile_buffer_get_pcm_at(resource sndfile_buffer, int index) Gets the pcm data value at the given index of a sndfile_buffer. */ PHP_FUNCTION(sndfile_buffer_get_pcm_at) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; long index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbuffer, &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL || index >= buffer->size) { php_error(E_NOTICE, "sndfile_buffer_get_pcm_at: undefined index %ld.", index); RETURN_FALSE; } switch (buffer->type) { case BUFF_TYPE_DOUBLE: RETURN_DOUBLE(buffer->data.dval[index]); break; case BUFF_TYPE_INT: RETURN_LONG(buffer->data.ival[index]); break; default: php_error(E_NOTICE, "sndfile_buffer_get_pcm_at: unknown buffer type %d.", buffer->type); RETURN_FALSE; } RETURN_FALSE; } /* }}} */ /* {{{ proto array sndfile_convert_buffer2array(resource buffer) Convert a sndfile buffer to a php array. */ PHP_FUNCTION(sndfile_convert_buffer2array) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; long i; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { return; } array_init(return_value); for (i = 0; i < buffer->size; i++) { switch (buffer->type) { case BUFF_TYPE_DOUBLE: add_next_index_double(return_value, buffer->data.dval[i]); break; case BUFF_TYPE_INT: add_next_index_long(return_value, buffer->data.ival[i]); break; default: php_error(E_NOTICE, "sndfile_convert_buffer2array: unknown buffer type %d.", buffer->type); RETURN_FALSE; } } return; } /* }}} */ /* {{{ proto array sndfile_convert_array2buffer(array &data, int type) Convert a php array to a sndfile buffer. */ PHP_FUNCTION(sndfile_convert_array2buffer) { zval *zarray = NULL, **entry = NULL; sndfile_buffer *buffer = NULL; HashPosition pos; long type, i = 0, len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!l", &zarray, &type) == FAILURE) { return; } len = zend_hash_num_elements(Z_ARRVAL_P(zarray)); if (php_sndfile_buffer_alloc_init(&buffer, len, type) == FAILURE) { RETURN_NULL(); } zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zarray), &pos); while (i < len && zend_hash_get_current_data_ex(Z_ARRVAL_P(zarray), (void **)&entry, &pos) == SUCCESS) { switch (type) { case BUFF_TYPE_DOUBLE: if (Z_TYPE_PP(entry) != IS_DOUBLE) { convert_to_double_ex(entry); } buffer->data.dval[i++] = Z_DVAL_PP(entry); break; case BUFF_TYPE_INT: if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } /* shortening of long may occur here. */ buffer->data.ival[i++] = (int)Z_LVAL_PP(entry); break; default: php_error(E_NOTICE, "sndfile_convert_array2buffer: unknown buffer type %d.", buffer->type); RETURN_FALSE; } zend_hash_move_forward_ex(Z_ARRVAL_P(zarray), &pos); } RETURN_RESOURCE(zend_list_insert(buffer, le_sndfile_buffer)); } /* }}} */ /* {{{ proto void sndfile_rewind(resource sndfile) Rewinds a soundfile to the first frame. NOTE: a sound file may contain additional data, other than pcm data, before the first frame. So, essentially the sound file is not completely rewound, but just rewound to the first frame. */ PHP_FUNCTION(sndfile_rewind) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); if (sf_seek(sndfile->sf, 0, SEEK_SET) != -1) { sndfile->eof = 0; } return; } /* }}} */ /* {{{ proto bool sndfile_eof(resource sndfile) Checks for the end of file position in the soundfile stream. */ PHP_FUNCTION(sndfile_eof) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_BOOL(sndfile->eof); } /* }}} */ /* {{{ proto int sndfile_seek(resource sndfile, int frames, int whence) The file seek functions work much like lseek in unistd.h with the exception that the non-audio data is ignored and the seek only moves within the audio data section of the file. In addition, seeks are defined in number of (multichannel) frames. Therefore, a seek in a stereo file from the current position forward with an offset of 1 would skip forward by one sample of both channels. */ PHP_FUNCTION(sndfile_seek) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; long frames; int whence; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &zsndfile, &frames, &whence) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_LONG(sf_seek(sndfile->sf, frames, whence)); } /* }}} */ /* {{{ proto int sndfile_read_int(resource sndfile, resource sndfile_buffer, int items) Reads items from the sndfile and populates sndfile_buffer with ints. Returns the number of items read. */ PHP_FUNCTION(sndfile_read_int) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_read_double(resource sndfile, resource sndfile_buffer, int items) Reads items from the sndfile and populates sndfile_buffer with doubles. Returns the number of items read. */ PHP_FUNCTION(sndfile_read_double) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_write_int(resource sndfile, resource sndfile_buffer [, int items]) Writes items as ints from sndfile_buffer to sndfile. Returns the number of items written.*/ PHP_FUNCTION(sndfile_write_int) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_write_double(resource sndfile, resource sndfile_buffer [, int items]) Writes items as doubles from sndfile_buffer to sndfile. Returns the number of items written. */ PHP_FUNCTION(sndfile_write_double) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_readf_int(resource sndfile, resource sndfile_buffer, int items) Reads items amount of frames as ints to the sndfile_buffer. Returns the number of frames read.*/ PHP_FUNCTION(sndfile_readf_int) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_readf_double(resource sndfile, resource sndfile_buffer, int items) Reads items amount of frames as doubles to sndfile_buffer. Reterns the number of frames read. */ PHP_FUNCTION(sndfile_readf_double) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_writef_int(resource sndfile, resource sndfile_buffer [, int items]) Writes items amount of frames from sndfile_buffer to sndfile as ints. Returns the number of frames written. */ PHP_FUNCTION(sndfile_writef_int) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_writef_double(resource sndfile, resource sndfile_buffer [, int items]) Writes items amount of frames from sndfile_buffer to sndfile as doubles. Returns the number of frames written. */ PHP_FUNCTION(sndfile_writef_double) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_error_code(resource sndfile) Get the error code. */ PHP_FUNCTION(sndfile_error_code) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_LONG(sf_error(sndfile->sf)); } /* }}} */ /* {{{ proto string sndfile_error_str(int errorcode) Get the error string associated with errorcode. */ PHP_FUNCTION(sndfile_error_str) { char *errstr; int errorcode; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errorcode) == FAILURE) { return; } errstr = (char *) sf_error_number(errorcode); RETURN_STRING(errstr, 1); } /* }}} */ /* {{{ proto array sndfile_get_info(resource sndfile) Get information about the sound file. */ PHP_FUNCTION(sndfile_get_info) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); php_sfinfo_struct_to_array(&sndfile->info, return_value); } /* }}} */ /* {{{ proto boolean sndfile_format_check(array sfinfo) Checks an sfinfo array for the correct format. */ PHP_FUNCTION(sndfile_format_check) { zval *zsfinfo = NULL; SF_INFO info; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zsfinfo) == FAILURE) { return; } info = php_array_to_sfinfo_struct(zsfinfo); RETURN_BOOL(sf_format_check(&info)); } /* }}} */ /* {{{ proto bool sndfile_set_string(resource sndfile, int str_type, string value) Sets a string on files open for write and to be retrieved from files open for read where supported by the given file type. */ PHP_FUNCTION(sndfile_set_string) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; char *value = NULL; int str_type, value_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &zsndfile, &str_type, &value, &value_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_BOOL(sf_set_string(sndfile->sf, str_type, value) == 0); } /* }}} */ /* {{{ proto string sndfile_get_string(resource sndfile, int str_type) Gets a string from the sound file. */ PHP_FUNCTION(sndfile_get_string) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; char *errstr = NULL; int str_type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zsndfile, &str_type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); if ((errstr = (char *)sf_get_string(sndfile->sf, str_type)) == NULL) { RETURN_EMPTY_STRING(); } RETURN_STRING(errstr, 1); } /* }}} */ /* {{{ proto mixed sndfile_command(resource sndfile, int command [, mixed value]) Retrieve information from or change aspects of the library behaviour. */ PHP_FUNCTION(sndfile_command) { (void)php_sndfile_do_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto mixed sndfile_get_log_info(resource sndfile, int command [, mixed value]) Retrieve information from or change aspects of the library behaviour. */ PHP_FUNCTION(sndfile_get_log_info) { (void)php_sndfile_do_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, SFC_GET_LOG_INFO); } /* }}} */ /* {{{ php_sndfile_do_commmand() */ static void php_sndfile_do_command(INTERNAL_FUNCTION_PARAMETERS, int command TSRMLS_DC) { zval *zsndfile = NULL, *zvalue = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &zsndfile, &command, &zvalue) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); switch (command) { case SFC_GET_LOG_INFO: { convert_to_long(zvalue); char buffer[Z_LVAL_P(zvalue)]; sf_command(sndfile->sf, SFC_GET_LOG_INFO, buffer, Z_LVAL_P(zvalue)); RETURN_STRINGL(buffer, Z_LVAL_P(zvalue), 1); } case SFC_SET_UPDATE_HEADER_AUTO: case SFC_SET_ADD_PEAK_CHUNK: /* fall through */ case SFC_SET_NORM_DOUBLE: { convert_to_boolean(zvalue); RETURN_BOOL(sf_command(sndfile->sf, command, NULL, Z_LVAL_P(zvalue) == 0 ? SF_FALSE : SF_TRUE)); } case SFC_CALC_SIGNAL_MAX: { convert_to_double(zvalue); sf_command(sndfile->sf, SFC_CALC_SIGNAL_MAX, &Z_DVAL_P(zvalue), sizeof(Z_DVAL_P(zvalue))); RETURN_DOUBLE(Z_DVAL_P(zvalue)); } case SFC_GET_SIMPLE_FORMAT: case SFC_GET_FORMAT_SUBTYPE: case SFC_GET_FORMAT_MAJOR: /* fall through */ case SFC_GET_FORMAT_INFO: { SF_FORMAT_INFO info; sf_command(NULL, command, &info, sizeof(info)); array_init(return_value); add_assoc_long(return_value, "format", info.format); add_assoc_string(return_value, "name", (char *)info.name, 1); add_assoc_string(return_value, "extension", (char *)info.extension, 1); return; } case SFC_GET_SIMPLE_FORMAT_COUNT: case SFC_GET_FORMAT_SUBTYPE_COUNT: /* fall through */ case SFC_GET_FORMAT_MAJOR_COUNT: { int count; sf_command(NULL, command, &count, sizeof(int)); RETURN_LONG(count); } case SFC_GET_LIB_VERSION: { char buffer[128]; sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); RETURN_STRING(buffer, 1); } case SFC_UPDATE_HEADER_NOW: { sf_command(sndfile->sf, SFC_UPDATE_HEADER_NOW, NULL, 0); return; } case SFC_SET_RAW_START_OFFSET: /* fall through */ case SFC_FILE_TRUNCATE: { convert_to_boolean(zvalue); RETURN_BOOL(sf_command(sndfile->sf, command, &Z_LVAL_P(zvalue), sizeof(Z_LVAL_P(zvalue)))); } default: php_error(E_WARNING, "soundfile_command [%d] no implemented.", command); } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
http://cvs.php.net/co.php/pecl/sndfile/config.m4?r=1.1&p=1 Index: pecl/sndfile/config.m4 +++ pecl/sndfile/config.m4 PHP_ARG_WITH(sndfile, for libsndfile support, [ --with-sndfile Include libsndfile support]) if test "$PHP_SNDFILE" != "no"; then SEARCH_PATH="/usr/local /usr" SEARCH_FOR="/include/sndfile.h" if test -r $PHP_SNDFILE/$SEARCH_FOR; then SNDFILE_DIR=$PHP_SNDFILE else AC_MSG_CHECKING([for sndfile files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then SNDFILE_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$SNDFILE_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the libsndfile distribution]) fi PHP_ADD_INCLUDE($SNDFILE_DIR/include) LIBNAME=sndfile # you may want to change this LIBSYMBOL=sf_open_fd # you most likely want to change this PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, [ PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SNDFILE_DIR/lib, SNDFILE_SHARED_LIBADD) AC_DEFINE(HAVE_SNDFILELIB,1,[ ]) ],[ AC_MSG_ERROR([wrong sndfile lib version or lib not found]) ],[ -L$SNDFILE_DIR/lib -lm -ldl ]) PHP_SUBST(SNDFILE_SHARED_LIBADD) PHP_NEW_EXTENSION(sndfile, sndfile.c, $ext_shared) fi http://cvs.php.net/co.php/pecl/sndfile/package.xml?r=1.1&p=1 Index: pecl/sndfile/package.xml +++ pecl/sndfile/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>sndfile</name> <summary>PHP interface for reading and writing sound files</summary> <description>The sndfile extension can read and write many different sound formats including wav, aiff and many many more.</description> <maintainers> <maintainer> <user>jhannus</user> <name>Justin Hannus</name> <email>jhannus@128kb.com</email> <role>lead</role> </maintainer> </maintainers> <release> <version>0.1</version> <date>2004-08-26</date> <license>PHP</license> <state>alpha</state> <notes>Initial Release</notes> <deps> <dep type="php" rel="ge">4.3.0</dep> </deps> <filelist> <file role="src" md5sum="3c016455d36d5f4d2893d020860d3786" name="config.m4"/> <file role="src" md5sum="e7128270b22d1304692e10bd34575c79" name="php_sndfile.h"/> <file role="src" md5sum="a2e04fdc36d768d0a4b10c665c0f0041" name="sndfile.c"/> <file role="php" md5sum="aa251b6dfb90ef25c761c3968028795b" name="examples/process.php"/> <file role="php" md5sum="79cf093a8065ed8805c0e3d4c920bfb3" name="examples/make_cine.php"/> <file role="php" md5sum="3bf7673a96082c8b7d7436b2f9b6f86e" name="examples/make_cine_d.php"/> <file role="php" md5sum="72dc3b7b6950b0be42c7fe11145cff9f" name="examples/convert.php"/> </filelist> </release> </package> http://cvs.php.net/co.php/pecl/sndfile/php_sndfile.h?r=1.1&p=1 Index: pecl/sndfile/php_sndfile.h +++ pecl/sndfile/php_sndfile.h /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Justin Hannus <jhannus@php.net> | +----------------------------------------------------------------------+ */ #ifndef PHP_SNDFILE_H #define PHP_SNDFILE_H #include <sndfile.h> extern zend_module_entry sndfile_module_entry; #define phpext_sndfile_ptr &sndfile_module_entry PHP_MINIT_FUNCTION(sndfile); PHP_MSHUTDOWN_FUNCTION(sndfile); PHP_MINFO_FUNCTION(sndfile); PHP_FUNCTION(sndfile_open); PHP_FUNCTION(sndfile_close); PHP_FUNCTION(sndfile_buffer_create); PHP_FUNCTION(sndfile_buffer_free); PHP_FUNCTION(sndfile_buffer_type); PHP_FUNCTION(sndfile_buffer_size); PHP_FUNCTION(sndfile_convert_buffer2array); PHP_FUNCTION(sndfile_convert_array2buffer); PHP_FUNCTION(sndfile_buffer_set_pcm_at); PHP_FUNCTION(sndfile_buffer_get_pcm_at); PHP_FUNCTION(sndfile_command); PHP_FUNCTION(sndfile_error_str); PHP_FUNCTION(sndfile_error_code); PHP_FUNCTION(sndfile_get_info); PHP_FUNCTION(sndfile_format_check); PHP_FUNCTION(sndfile_set_string); PHP_FUNCTION(sndfile_get_string); PHP_FUNCTION(sndfile_read_int); PHP_FUNCTION(sndfile_read_double); PHP_FUNCTION(sndfile_write_int); PHP_FUNCTION(sndfile_write_double); PHP_FUNCTION(sndfile_readf_int); PHP_FUNCTION(sndfile_readf_double); PHP_FUNCTION(sndfile_writef_int); PHP_FUNCTION(sndfile_writef_double); PHP_FUNCTION(sndfile_rewind); PHP_FUNCTION(sndfile_eof); PHP_FUNCTION(sndfile_seek); #endif /* PHP_SNDFILE_H */ http://cvs.php.net/co.php/pecl/sndfile/sndfile.c?r=1.1&p=1 Index: pecl/sndfile/sndfile.c +++ pecl/sndfile/sndfile.c /* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2002 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Justin Hannus <jhannus@php.net> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_globals.h" #include "ext/standard/php_standard.h" #include "ext/standard/info.h" #include "php_sndfile.h" #include <sndfile.h> #define SNDFILE_RSRC_NAME "sound file" #define SNDFILE_BUFF_RSRC_NAME "sound file buffer" #define READ_MODE_ITEMS 1 #define READ_MODE_FRAMES 2 #define WRITE_MODE_ITEMS 1 #define WRITE_MODE_FRAMES 2 #define BUFF_TYPE_INT 1 #define BUFF_TYPE_DOUBLE 2 #define php_sndfile_buffer_silent_realloc(_buf, _val, _size, _ptr, _type) \ if ((_ptr = (_type)erealloc(_buf->data._val, sizeof(_type) * (_buf->size + _size))) == NULL) { \ _size = _buf->size; \ } else { \ _buf->size = _size; \ _buf->data._val = _ptr; \ } typedef struct _php_sndfile { int eof; SF_INFO info; SNDFILE *sf; } php_sndfile; typedef struct _sndfile_buffer { int type; size_t size; union { double *dval; int *ival; } data; } sndfile_buffer; static int le_sndfile, le_sndfile_buffer; /* private functions */ static void _php_le_sndfile_close(zend_rsrc_list_entry *rsrc TSRMLS_DC); static void _php_le_sndfile_buffer_free(zend_rsrc_list_entry *rsrc TSRMLS_DC); static int php_sndfile_buffer_alloc_init(sndfile_buffer **, size_t, int TSRMLS_DC); static void php_sndfile_buffer_free(sndfile_buffer * TSRMLS_DC); static php_sndfile *php_sndfile_open(char *, char *, zval * TSRMLS_DC); static void php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode); static void php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode); static void php_sndfile_do_command(INTERNAL_FUNCTION_PARAMETERS, int TSRMLS_DC); #ifdef ZEND_ENGINE_2 static ZEND_BEGIN_ARG_INFO(third_arg_force_ref, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); static ZEND_BEGIN_ARG_INFO(first_arg_force_ref, 0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); #else static unsigned char third_arg_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; static unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE }; #endif /* {{{ php_sndfile_functions[] */ function_entry php_sndfile_functions[] = { PHP_FE(sndfile_open, third_arg_force_ref) PHP_FE(sndfile_close, NULL) PHP_FE(sndfile_buffer_create, NULL) PHP_FE(sndfile_buffer_free, NULL) PHP_FE(sndfile_buffer_type, NULL) PHP_FE(sndfile_buffer_size, NULL) PHP_FE(sndfile_buffer_set_pcm_at, NULL) PHP_FE(sndfile_buffer_get_pcm_at, NULL) PHP_FE(sndfile_convert_buffer2array, NULL) PHP_FE(sndfile_convert_array2buffer, first_arg_force_ref) PHP_FE(sndfile_command, NULL) PHP_FE(sndfile_error_str, NULL) PHP_FE(sndfile_error_code, NULL) PHP_FE(sndfile_get_info, NULL) PHP_FE(sndfile_format_check, NULL) PHP_FE(sndfile_read_int, NULL) PHP_FE(sndfile_write_int, NULL) PHP_FE(sndfile_read_double, NULL) PHP_FE(sndfile_write_double, NULL) PHP_FE(sndfile_readf_int, NULL) PHP_FE(sndfile_writef_int, NULL) PHP_FE(sndfile_readf_double, NULL) PHP_FE(sndfile_writef_double, NULL) PHP_FE(sndfile_set_string, NULL) PHP_FE(sndfile_get_string, NULL) PHP_FE(sndfile_rewind, NULL) PHP_FE(sndfile_eof, NULL) PHP_FE(sndfile_seek, NULL) { NULL, NULL, NULL } }; /* }}} */ /* {{{ sndfile_module_entry[] */ zend_module_entry sndfile_module_entry = { STANDARD_MODULE_HEADER, "sndfile", php_sndfile_functions, PHP_MINIT(sndfile), PHP_MSHUTDOWN(sndfile), NULL, /* RINIT */ NULL, /* RSHUTDOWN */ PHP_MINFO(sndfile), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SNDFILE ZEND_GET_MODULE(sndfile) #endif PHP_MINIT_FUNCTION(sndfile) { le_sndfile = zend_register_list_destructors_ex(_php_le_sndfile_close, NULL, SNDFILE_RSRC_NAME, module_number); le_sndfile_buffer = zend_register_list_destructors_ex(_php_le_sndfile_buffer_free, NULL, SNDFILE_BUFF_RSRC_NAME, module_number); REGISTER_LONG_CONSTANT("SF_BUFFER_INT", BUFF_TYPE_INT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_BUFFER_DOUBLE", BUFF_TYPE_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_TITLE", SF_STR_TITLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_COPYRIGHT", SF_STR_COPYRIGHT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_SOFTWARE", SF_STR_SOFTWARE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_ARTIST", SF_STR_ARTIST, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_COMMENT", SF_STR_COMMENT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_STR_DATE", SF_STR_DATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_WAV", SF_FORMAT_WAV, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_AIFF", SF_FORMAT_AIFF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_AU", SF_FORMAT_AU, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_RAW", SF_FORMAT_RAW, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PAF", SF_FORMAT_PAF, CONST_CS | CONST_PERSISTENT); /* Ensoniq PARIS file format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_SVX", SF_FORMAT_SVX, CONST_CS | CONST_PERSISTENT); /* Amiga IFF / SVX8 / SV16 format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_NIST", SF_FORMAT_NIST, CONST_CS | CONST_PERSISTENT); /* Sphere NIST format. */ REGISTER_LONG_CONSTANT("SF_FORMAT_VOC", SF_FORMAT_VOC, CONST_CS | CONST_PERSISTENT); /* VOC files. */ REGISTER_LONG_CONSTANT("SF_FORMAT_IRCAM", SF_FORMAT_IRCAM, CONST_CS | CONST_PERSISTENT); /* Berkeley/IRCAM/CARL */ REGISTER_LONG_CONSTANT("SF_FORMAT_W64", SF_FORMAT_W64, CONST_CS | CONST_PERSISTENT); /* Sonic Foundry's 64 bit RIFF/WAV */ REGISTER_LONG_CONSTANT("SF_FORMAT_MAT4", SF_FORMAT_MAT4, CONST_CS | CONST_PERSISTENT); /* Matlab (tm) V4.2 / GNU Octave 2.0 */ REGISTER_LONG_CONSTANT("SF_FORMAT_MAT5", SF_FORMAT_MAT5, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_S8", SF_FORMAT_PCM_S8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_16", SF_FORMAT_PCM_16, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_24", SF_FORMAT_PCM_24, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_32", SF_FORMAT_PCM_32, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_PCM_U8", SF_FORMAT_PCM_U8, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_SUBMASK", SF_FORMAT_SUBMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_TYPEMASK", SF_FORMAT_TYPEMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_ENDMASK", SF_FORMAT_ENDMASK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SF_FORMAT_FLOAT", SF_FORMAT_FLOAT, CONST_CS | CONST_PERSISTENT); /* 32 bit float data */ REGISTER_LONG_CONSTANT("SF_FORMAT_DOUBLE", SF_FORMAT_DOUBLE, CONST_CS | CONST_PERSISTENT); /* 64 bit float data */ REGISTER_LONG_CONSTANT("SF_FORMAT_ULAW", SF_FORMAT_ULAW, CONST_CS | CONST_PERSISTENT); /* U-Law encoded. */ REGISTER_LONG_CONSTANT("SF_FORMAT_ALAW", SF_FORMAT_ALAW, CONST_CS | CONST_PERSISTENT); /* A-Law encoded. */ REGISTER_LONG_CONSTANT("SF_FORMAT_IMA_ADPCM", SF_FORMAT_IMA_ADPCM, CONST_CS | CONST_PERSISTENT); /* IMA ADPCM. */ REGISTER_LONG_CONSTANT("SF_FORMAT_MS_ADPCM", SF_FORMAT_MS_ADPCM, CONST_CS | CONST_PERSISTENT); /* Microsoft ADPCM. */ REGISTER_LONG_CONSTANT("SF_FORMAT_GSM610", SF_FORMAT_GSM610, CONST_CS | CONST_PERSISTENT); /* GSM 6.10 encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_VOX_ADPCM", SF_FORMAT_VOX_ADPCM, CONST_CS | CONST_PERSISTENT); /* Oki Dialogic ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G721_32", SF_FORMAT_G721_32, CONST_CS | CONST_PERSISTENT); /* 32kbs G721 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G723_24", SF_FORMAT_G723_24, CONST_CS | CONST_PERSISTENT); /* 24kbs G723 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_G723_40", SF_FORMAT_G723_40, CONST_CS | CONST_PERSISTENT); /* 40kbs G723 ADPCM encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_12", SF_FORMAT_DWVW_12, CONST_CS | CONST_PERSISTENT); /* 12 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_16", SF_FORMAT_DWVW_16, CONST_CS | CONST_PERSISTENT); /* 16 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_24", SF_FORMAT_DWVW_24, CONST_CS | CONST_PERSISTENT); /* 24 bit Delta Width Variable Word encoding. */ REGISTER_LONG_CONSTANT("SF_FORMAT_DWVW_N", SF_FORMAT_DWVW_N, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_LIB_VERSION", SFC_GET_LIB_VERSION, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_LOG_INFO", SFC_GET_LOG_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_SIGNAL_MAX", SFC_CALC_SIGNAL_MAX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_NORM_SIGNAL_MAX", SFC_CALC_NORM_SIGNAL_MAX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_MAX_ALL_CHANNELS", SFC_CALC_MAX_ALL_CHANNELS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_CALC_NORM_MAX_ALL_CHANNELS", SFC_CALC_NORM_MAX_ALL_CHANNELS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_NORM_FLOAT", SFC_SET_NORM_FLOAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_NORM_DOUBLE", SFC_SET_NORM_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_NORM_FLOAT", SFC_GET_NORM_FLOAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_NORM_DOUBLE", SFC_GET_NORM_DOUBLE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_SIMPLE_FORMAT_COUNT", SFC_GET_SIMPLE_FORMAT_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_SIMPLE_FORMAT", SFC_GET_SIMPLE_FORMAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_INFO", SFC_GET_FORMAT_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_MAJOR_COUNT", SFC_GET_FORMAT_MAJOR_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_MAJOR", SFC_GET_FORMAT_MAJOR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_SUBTYPE_COUNT", SFC_GET_FORMAT_SUBTYPE_COUNT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_GET_FORMAT_SUBTYPE", SFC_GET_FORMAT_SUBTYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_ADD_PEAK_CHUNK", SFC_SET_ADD_PEAK_CHUNK, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_UPDATE_HEADER_NOW", SFC_UPDATE_HEADER_NOW, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_UPDATE_HEADER_AUTO", SFC_SET_UPDATE_HEADER_AUTO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_FILE_TRUNCATE", SFC_FILE_TRUNCATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SFC_SET_RAW_START_OFFSET", SFC_SET_RAW_START_OFFSET, CONST_CS | CONST_PERSISTENT); return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(sndfile) { return SUCCESS; } PHP_MINFO_FUNCTION(sndfile) { char buffer[32]; sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); php_info_print_table_start(); php_info_print_table_row(2, "libsndfile Support", "enabled"); php_info_print_table_row(2, "LIB_VERSION", buffer); php_info_print_table_end(); } /* {{{ _php_le_sndfile_close() */ static void _php_le_sndfile_close(zend_rsrc_list_entry *rsrc TSRMLS_DC) { php_sndfile *sndfile = (php_sndfile *)rsrc->ptr; if (sndfile != NULL && sndfile->sf) { sf_close(sndfile->sf); } efree(sndfile); } /* }}} */ /* {{{ _php_le_sndfile_buffer_free() */ static void _php_le_sndfile_buffer_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) { sndfile_buffer *buffer = (sndfile_buffer *)rsrc->ptr; if (buffer != NULL) { php_sndfile_buffer_free(buffer); } } /* }}} */ /* {{{ php_sndfile_buffer_alloc_init() */ static int php_sndfile_buffer_alloc_init(sndfile_buffer **buffer, size_t size, int type TSRMLS_DC) { if ((*buffer = (sndfile_buffer *)emalloc(sizeof(sndfile_buffer))) == NULL) { return FAILURE; } switch (type) { case BUFF_TYPE_DOUBLE: if (((*buffer)->data.dval = (double *)ecalloc(size, sizeof(double))) == NULL) { efree(buffer); return FAILURE; } break; case BUFF_TYPE_INT: if (((*buffer)->data.ival = (int *)ecalloc(size, sizeof(int))) == NULL) { efree(buffer); return FAILURE; } break; default: { efree(*buffer); *buffer = NULL; return FAILURE; } } (*buffer)->type = type; (*buffer)->size = size; return SUCCESS; } /* }}} */ /* {{{ php_sndfile_buffer_free() */ static void php_sndfile_buffer_free(sndfile_buffer *buffer TSRMLS_DC) { switch (buffer->type) { case BUFF_TYPE_DOUBLE: efree(buffer->data.dval); break; case BUFF_TYPE_INT: efree(buffer->data.ival); break; } efree(buffer); return; } /* }}} */ /* {{{ php_array_to_sfinfo_struct */ static inline SF_INFO php_array_to_sfinfo_struct(zval *zarray) { zval **entry = NULL; char *string_key = NULL; uint string_len; ulong num_key; SF_INFO sfinfo; HashPosition pos; memset(&sfinfo, 0, sizeof(sfinfo)); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zarray), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zarray), (void **)&entry, &pos) == SUCCESS) { if (zend_hash_get_current_key_ex(Z_ARRVAL_P(zarray), &string_key, &string_len, &num_key, 1, &pos) == HASH_KEY_IS_STRING) { if (strcmp(string_key, "samplerate") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.samplerate = Z_LVAL_PP(entry); } else if (strcmp(string_key, "frames") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.frames = Z_LVAL_PP(entry); } else if (strcmp(string_key, "channels") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.channels = Z_LVAL_PP(entry); } else if (strcmp(string_key, "format") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.format = Z_LVAL_PP(entry); } else if (strcmp(string_key, "sections") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.sections = Z_LVAL_PP(entry); } else if (strcmp(string_key, "seekable") == 0) { if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } sfinfo.seekable = Z_LVAL_PP(entry); } efree(string_key); } zend_hash_move_forward_ex(Z_ARRVAL_P(zarray), &pos); } return sfinfo; } /* }}} */ /* {{{ php_sfinfo_struct_to_array */ static inline void php_sfinfo_struct_to_array(SF_INFO *sfinfo, zval *zarray) { if (Z_TYPE_P(zarray) != IS_ARRAY) { array_init(zarray); } add_assoc_long(zarray, "frames", sfinfo->frames); add_assoc_long(zarray, "samplerate", sfinfo->samplerate); add_assoc_long(zarray, "channels", sfinfo->channels); add_assoc_long(zarray, "format", sfinfo->format); add_assoc_long(zarray, "sections", sfinfo->sections); add_assoc_long(zarray, "seekable", sfinfo->seekable); return; } /* }}} */ /* {{{ php_sndfile_open */ static php_sndfile *php_sndfile_open(char *path, char *mode, zval *zsfinfo TSRMLS_DC) { php_sndfile *sndfile = NULL; if (strchr(mode, '+') || ((strchr(mode, 'w') || strchr(mode, 'a')) && strchr(mode, 'r'))) { php_error(E_WARNING, "Invalid opening mode. Simultaneous read/write operations are not permitted."); return NULL; } sndfile = (php_sndfile *) emalloc(sizeof(php_sndfile)); if (strchr(mode, 'r')) { memset(&sndfile->info, 0, sizeof(sndfile->info)); sndfile->sf = sf_open(path, SFM_READ, &sndfile->info); php_sfinfo_struct_to_array(&sndfile->info, zsfinfo); } else { if (zsfinfo && Z_TYPE_P(zsfinfo) == IS_ARRAY) { sndfile->info = php_array_to_sfinfo_struct(zsfinfo); sndfile->sf = sf_open(path, SFM_WRITE, &sndfile->info); } else { php_error(E_WARNING, "No sfinfo context supplied while opening soundfile for writing."); return NULL; } } if (!sndfile->sf) { php_error(E_WARNING, "sndfile open failed: %s", sf_strerror(sndfile->sf)); efree(sndfile); return NULL; } sndfile->eof = 0; return sndfile; } /* }}} */ /* {{{ php_sndfile_read_pcm_data */ static void php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode TSRMLS_DC) { zval *zsndfile, *zbuffer = NULL; sndfile_buffer *buffer = NULL; php_sndfile *sndfile; sf_count_t read; long items; void *tmp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &zsndfile, &zbuffer, &items) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (sndfile == NULL || buffer == NULL) { RETURN_FALSE; } switch (mode) { case READ_MODE_ITEMS: switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, dval, items, tmp, double *) } read = sf_read_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, ival, items, tmp, int *) } read = sf_read_int(sndfile->sf, buffer->data.ival, items); break; } break; case READ_MODE_FRAMES: switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, dval, items, tmp, double *) } read = sf_readf_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: if (buffer->size >= items) { php_sndfile_buffer_silent_realloc(buffer, ival, items, tmp, int *) } read = sf_readf_int(sndfile->sf, buffer->data.ival, items); break; } break; } if (read < items && read != -1) { sndfile->eof = 1; } RETURN_LONG(read); } /* }}} */ /* {{{ php_sndfile_write_pcm_data */ static void php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAMETERS, int mode TSRMLS_DC) { zval *zsndfile, *zbuffer = NULL; sndfile_buffer *buffer = NULL; php_sndfile *sndfile = NULL; long items = 0; sf_count_t samples; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &zsndfile, &zbuffer, &items) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (sndfile == NULL || buffer == NULL) { RETURN_FALSE; } if (ZEND_NUM_ARGS() < 3 || items > buffer->size) { items = buffer->size; } switch (mode) { case WRITE_MODE_ITEMS: switch (mode) { case BUFF_TYPE_DOUBLE: samples = sf_write_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: samples = sf_write_int(sndfile->sf, buffer->data.ival, items); break; } break; case WRITE_MODE_FRAMES: switch (mode) { case BUFF_TYPE_DOUBLE: samples = sf_writef_double(sndfile->sf, buffer->data.dval, items); break; case BUFF_TYPE_INT: samples = sf_writef_int(sndfile->sf, buffer->data.ival, items); break; } break; } RETURN_LONG(samples); } /* }}} */ /* {{{ proto resource sndfile_open(string filename, string mode [, array &sfinfo]) Opens a soundfile. */ PHP_FUNCTION(sndfile_open) { zval *info = NULL; php_sndfile *sndfile = NULL; char *path = NULL, *mode = NULL; int path_len, mode_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a!", &path, &path_len, &mode, &mode_len, &info) == FAILURE) { return; } if ((sndfile = php_sndfile_open(path, mode, info)) != NULL) { RETURN_RESOURCE(zend_list_insert(sndfile, le_sndfile)); } RETURN_FALSE; } /* }}} */ /* {{{ proto void sndfile_close(resource sndfile) Closes a soundfile. */ PHP_FUNCTION(sndfile_close) { zval *zsndfile = NULL; if (zend_parse_parameters(1 TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } zend_list_delete(Z_LVAL_P(zsndfile)); } /* }}} */ /* {{{ proto resource sndfile_buffer_create(int length, int type) Create a new sndfile buffer resource. */ PHP_FUNCTION(sndfile_buffer_create) { sndfile_buffer *buffer = NULL; int type; long length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &length, &type) == FAILURE) { return; } if (php_sndfile_buffer_alloc_init(&buffer, length, type) == SUCCESS) { RETURN_RESOURCE(zend_list_insert(buffer, le_sndfile_buffer)); } RETURN_FALSE; } /* }}} */ /* {{{ proto int sndfile_buffer_type(resource buffer) Gets the buffer type. */ PHP_FUNCTION(sndfile_buffer_type) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { RETURN_LONG(0); } RETURN_LONG(buffer->type); } /* }}} */ /* {{{ proto int sndfile_buffer_size(resource buffer) Gets the buffer size. */ PHP_FUNCTION(sndfile_buffer_size) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { RETURN_LONG(0); } RETURN_LONG(buffer->size); } /* }}} */ /* {{{ proto void sndfile_buffer_free(resource sndfile_buffer) Releases the resources held for sndfile buffer. */ PHP_FUNCTION(sndfile_buffer_free) { zval *zbuffer = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } zend_list_delete(Z_LVAL_P(zbuffer)); } /* }}} */ /* {{{ proto bool sndfile_buffer_set_pcm_at(resource sndfile_buffer, int index, mixed value) Sets the pcm data value at the given index of a sndfile_buffer. */ PHP_FUNCTION(sndfile_buffer_set_pcm_at) { zval *zbuffer, *zvalue = NULL; sndfile_buffer *buffer = NULL; long index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &zbuffer, &index, &zvalue) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL || index >= buffer->size) { php_error(E_NOTICE, "sndfile_buffer_set_pcm_at: undefined index %ld.", index); RETURN_FALSE; } switch (buffer->type) { case BUFF_TYPE_DOUBLE: if (Z_TYPE_P(zvalue) != IS_DOUBLE) { convert_to_double(zvalue); } buffer->data.dval[index] = Z_DVAL_P(zvalue); break; case BUFF_TYPE_INT: /* shortening of long may occur here */ if (Z_TYPE_P(zvalue) != IS_LONG) { convert_to_long(zvalue); } buffer->data.ival[index] = (int)Z_LVAL_P(zvalue); break; default: php_error(E_NOTICE, "sndfile_buffer_set_pcm_at: unknown buffer type %d.", buffer->type); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto mixed sndfile_buffer_get_pcm_at(resource sndfile_buffer, int index) Gets the pcm data value at the given index of a sndfile_buffer. */ PHP_FUNCTION(sndfile_buffer_get_pcm_at) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; long index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zbuffer, &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL || index >= buffer->size) { php_error(E_NOTICE, "sndfile_buffer_get_pcm_at: undefined index %ld.", index); RETURN_FALSE; } switch (buffer->type) { case BUFF_TYPE_DOUBLE: RETURN_DOUBLE(buffer->data.dval[index]); break; case BUFF_TYPE_INT: RETURN_LONG(buffer->data.ival[index]); break; default: php_error(E_NOTICE, "sndfile_buffer_get_pcm_at: unknown buffer type %d.", buffer->type); RETURN_FALSE; } RETURN_FALSE; } /* }}} */ /* {{{ proto array sndfile_convert_buffer2array(resource buffer) Convert a sndfile buffer to a php array. */ PHP_FUNCTION(sndfile_convert_buffer2array) { zval *zbuffer = NULL; sndfile_buffer *buffer = NULL; long i; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zbuffer) == FAILURE) { return; } ZEND_FETCH_RESOURCE(buffer, sndfile_buffer *, &zbuffer, -1, SNDFILE_BUFF_RSRC_NAME, le_sndfile_buffer); if (buffer == NULL) { return; } array_init(return_value); for (i = 0; i < buffer->size; i++) { switch (buffer->type) { case BUFF_TYPE_DOUBLE: add_next_index_double(return_value, buffer->data.dval[i]); break; case BUFF_TYPE_INT: add_next_index_long(return_value, buffer->data.ival[i]); break; default: php_error(E_NOTICE, "sndfile_convert_buffer2array: unknown buffer type %d.", buffer->type); RETURN_FALSE; } } return; } /* }}} */ /* {{{ proto array sndfile_convert_array2buffer(array &data, int type) Convert a php array to a sndfile buffer. */ PHP_FUNCTION(sndfile_convert_array2buffer) { zval *zarray = NULL, **entry = NULL; sndfile_buffer *buffer = NULL; HashPosition pos; long type, i = 0, len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!l", &zarray, &type) == FAILURE) { return; } len = zend_hash_num_elements(Z_ARRVAL_P(zarray)); if (php_sndfile_buffer_alloc_init(&buffer, len, type) == FAILURE) { RETURN_NULL(); } zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zarray), &pos); while (i < len && zend_hash_get_current_data_ex(Z_ARRVAL_P(zarray), (void **)&entry, &pos) == SUCCESS) { switch (type) { case BUFF_TYPE_DOUBLE: if (Z_TYPE_PP(entry) != IS_DOUBLE) { convert_to_double_ex(entry); } buffer->data.dval[i++] = Z_DVAL_PP(entry); break; case BUFF_TYPE_INT: if (Z_TYPE_PP(entry) != IS_LONG) { convert_to_long_ex(entry); } /* shortening of long may occur here. */ buffer->data.ival[i++] = (int)Z_LVAL_PP(entry); break; default: php_error(E_NOTICE, "sndfile_convert_array2buffer: unknown buffer type %d.", buffer->type); RETURN_FALSE; } zend_hash_move_forward_ex(Z_ARRVAL_P(zarray), &pos); } RETURN_RESOURCE(zend_list_insert(buffer, le_sndfile_buffer)); } /* }}} */ /* {{{ proto void sndfile_rewind(resource sndfile) Rewinds a soundfile to the first frame. NOTE: a sound file may contain additional data, other than pcm data, before the first frame. So, essentially the sound file is not completely rewound, but just rewound to the first frame. */ PHP_FUNCTION(sndfile_rewind) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); if (sf_seek(sndfile->sf, 0, SEEK_SET) != -1) { sndfile->eof = 0; } return; } /* }}} */ /* {{{ proto bool sndfile_eof(resource sndfile) Checks for the end of file position in the soundfile stream. */ PHP_FUNCTION(sndfile_eof) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_BOOL(sndfile->eof); } /* }}} */ /* {{{ proto int sndfile_seek(resource sndfile, int frames, int whence) The file seek functions work much like lseek in unistd.h with the exception that the non-audio data is ignored and the seek only moves within the audio data section of the file. In addition, seeks are defined in number of (multichannel) frames. Therefore, a seek in a stereo file from the current position forward with an offset of 1 would skip forward by one sample of both channels. */ PHP_FUNCTION(sndfile_seek) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; long frames; int whence; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &zsndfile, &frames, &whence) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_LONG(sf_seek(sndfile->sf, frames, whence)); } /* }}} */ /* {{{ proto int sndfile_read_int(resource sndfile, resource sndfile_buffer, int items) Reads items from the sndfile and populates sndfile_buffer with ints. Returns the number of items read. */ PHP_FUNCTION(sndfile_read_int) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_read_double(resource sndfile, resource sndfile_buffer, int items) Reads items from the sndfile and populates sndfile_buffer with doubles. Returns the number of items read. */ PHP_FUNCTION(sndfile_read_double) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_write_int(resource sndfile, resource sndfile_buffer [, int items]) Writes items as ints from sndfile_buffer to sndfile. Returns the number of items written.*/ PHP_FUNCTION(sndfile_write_int) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_write_double(resource sndfile, resource sndfile_buffer [, int items]) Writes items as doubles from sndfile_buffer to sndfile. Returns the number of items written. */ PHP_FUNCTION(sndfile_write_double) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_ITEMS TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_readf_int(resource sndfile, resource sndfile_buffer, int items) Reads items amount of frames as ints to the sndfile_buffer. Returns the number of frames read.*/ PHP_FUNCTION(sndfile_readf_int) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_readf_double(resource sndfile, resource sndfile_buffer, int items) Reads items amount of frames as doubles to sndfile_buffer. Reterns the number of frames read. */ PHP_FUNCTION(sndfile_readf_double) { (void)php_sndfile_read_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, READ_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_writef_int(resource sndfile, resource sndfile_buffer [, int items]) Writes items amount of frames from sndfile_buffer to sndfile as ints. Returns the number of frames written. */ PHP_FUNCTION(sndfile_writef_int) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_writef_double(resource sndfile, resource sndfile_buffer [, int items]) Writes items amount of frames from sndfile_buffer to sndfile as doubles. Returns the number of frames written. */ PHP_FUNCTION(sndfile_writef_double) { (void)php_sndfile_write_pcm_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, WRITE_MODE_FRAMES TSRMLS_CC); } /* }}} */ /* {{{ proto int sndfile_error_code(resource sndfile) Get the error code. */ PHP_FUNCTION(sndfile_error_code) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_LONG(sf_error(sndfile->sf)); } /* }}} */ /* {{{ proto string sndfile_error_str(int errorcode) Get the error string associated with errorcode. */ PHP_FUNCTION(sndfile_error_str) { char *errstr; int errorcode; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errorcode) == FAILURE) { return; } errstr = (char *) sf_error_number(errorcode); RETURN_STRING(errstr, 1); } /* }}} */ /* {{{ proto array sndfile_get_info(resource sndfile) Get information about the sound file. */ PHP_FUNCTION(sndfile_get_info) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsndfile) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); php_sfinfo_struct_to_array(&sndfile->info, return_value); } /* }}} */ /* {{{ proto boolean sndfile_format_check(array sfinfo) Checks an sfinfo array for the correct format. */ PHP_FUNCTION(sndfile_format_check) { zval *zsfinfo = NULL; SF_INFO info; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zsfinfo) == FAILURE) { return; } info = php_array_to_sfinfo_struct(zsfinfo); RETURN_BOOL(sf_format_check(&info)); } /* }}} */ /* {{{ proto bool sndfile_set_string(resource sndfile, int str_type, string value) Sets a string on files open for write and to be retrieved from files open for read where supported by the given file type. */ PHP_FUNCTION(sndfile_set_string) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; char *value = NULL; int str_type, value_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &zsndfile, &str_type, &value, &value_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); RETURN_BOOL(sf_set_string(sndfile->sf, str_type, value) == 0); } /* }}} */ /* {{{ proto string sndfile_get_string(resource sndfile, int str_type) Gets a string from the sound file. */ PHP_FUNCTION(sndfile_get_string) { zval *zsndfile = NULL; php_sndfile *sndfile = NULL; char *errstr = NULL; int str_type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zsndfile, &str_type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); if ((errstr = (char *)sf_get_string(sndfile->sf, str_type)) == NULL) { RETURN_EMPTY_STRING(); } RETURN_STRING(errstr, 1); } /* }}} */ /* {{{ proto mixed sndfile_command(resource sndfile, int command [, mixed value]) Retrieve information from or change aspects of the library behaviour. */ PHP_FUNCTION(sndfile_command) { (void)php_sndfile_do_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto mixed sndfile_get_log_info(resource sndfile, int command [, mixed value]) Retrieve information from or change aspects of the library behaviour. */ PHP_FUNCTION(sndfile_get_log_info) { (void)php_sndfile_do_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, SFC_GET_LOG_INFO); } /* }}} */ /* {{{ php_sndfile_do_commmand() */ static void php_sndfile_do_command(INTERNAL_FUNCTION_PARAMETERS, int command TSRMLS_DC) { zval *zsndfile = NULL, *zvalue = NULL; php_sndfile *sndfile = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &zsndfile, &command, &zvalue) == FAILURE) { return; } ZEND_FETCH_RESOURCE(sndfile, php_sndfile *, &zsndfile, -1, SNDFILE_RSRC_NAME, le_sndfile); switch (command) { case SFC_GET_LOG_INFO: { convert_to_long(zvalue); char buffer[Z_LVAL_P(zvalue)]; sf_command(sndfile->sf, SFC_GET_LOG_INFO, buffer, Z_LVAL_P(zvalue)); RETURN_STRINGL(buffer, Z_LVAL_P(zvalue), 1); } case SFC_SET_UPDATE_HEADER_AUTO: case SFC_SET_ADD_PEAK_CHUNK: /* fall through */ case SFC_SET_NORM_DOUBLE: { convert_to_boolean(zvalue); RETURN_BOOL(sf_command(sndfile->sf, command, NULL, Z_LVAL_P(zvalue) == 0 ? SF_FALSE : SF_TRUE)); } case SFC_CALC_SIGNAL_MAX: { convert_to_double(zvalue); sf_command(sndfile->sf, SFC_CALC_SIGNAL_MAX, &Z_DVAL_P(zvalue), sizeof(Z_DVAL_P(zvalue))); RETURN_DOUBLE(Z_DVAL_P(zvalue)); } case SFC_GET_SIMPLE_FORMAT: case SFC_GET_FORMAT_SUBTYPE: case SFC_GET_FORMAT_MAJOR: /* fall through */ case SFC_GET_FORMAT_INFO: { SF_FORMAT_INFO info; sf_command(NULL, command, &info, sizeof(info)); array_init(return_value); add_assoc_long(return_value, "format", info.format); add_assoc_string(return_value, "name", (char *)info.name, 1); add_assoc_string(return_value, "extension", (char *)info.extension, 1); return; } case SFC_GET_SIMPLE_FORMAT_COUNT: case SFC_GET_FORMAT_SUBTYPE_COUNT: /* fall through */ case SFC_GET_FORMAT_MAJOR_COUNT: { int count; sf_command(NULL, command, &count, sizeof(int)); RETURN_LONG(count); } case SFC_GET_LIB_VERSION: { char buffer[128]; sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer)); RETURN_STRING(buffer, 1); } case SFC_UPDATE_HEADER_NOW: { sf_command(sndfile->sf, SFC_UPDATE_HEADER_NOW, NULL, 0); return; } case SFC_SET_RAW_START_OFFSET: /* fall through */ case SFC_FILE_TRUNCATE: { convert_to_boolean(zvalue); RETURN_BOOL(sf_command(sndfile->sf, command, &Z_LVAL_P(zvalue), sizeof(Z_LVAL_P(zvalue)))); } default: php_error(E_WARNING, "soundfile_command [%d] no implemented.", command); } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */