[asterisk-commits] kpfleming: trunk r96862 - /trunk/formats/format_sln16.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 7 10:17:32 CST 2008


Author: kpfleming
Date: Mon Jan  7 10:17:31 2008
New Revision: 96862

URL: http://svn.digium.com/view/asterisk?view=rev&rev=96862
Log:
add a file-format driver for 16KHz signed linear... which may or may not work

Added:
    trunk/formats/format_sln16.c
      - copied, changed from r96860, trunk/formats/format_sln.c

Copied: trunk/formats/format_sln16.c (from r96860, trunk/formats/format_sln.c)
URL: http://svn.digium.com/view/asterisk/trunk/formats/format_sln16.c?view=diff&rev=96862&p1=trunk/formats/format_sln.c&r1=96860&p2=trunk/formats/format_sln16.c&r2=96862
==============================================================================
--- trunk/formats/format_sln.c (original)
+++ trunk/formats/format_sln16.c Mon Jan  7 10:17:31 2008
@@ -1,8 +1,9 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Anthony Minessale
+ * Copyright (C) 1999 - 2008, Anthony Minessale and Digium, Inc.
  * Anthony Minessale (anthmct at yahoo.com)
+ * Kevin P. Fleming <kpfleming at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -17,8 +18,8 @@
 
 /*! \file
  *
- * \brief RAW SLINEAR Format
- * \arg File name extensions: sln, raw
+ * \brief RAW SLINEAR 16 Format
+ * \arg File name extensions: sln16
  * \ingroup formats
  */
  
@@ -30,8 +31,8 @@
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
 
-#define BUF_SIZE	320		/* 320 bytes, 160 samples */
-#define	SLIN_SAMPLES	160
+#define BUF_SIZE	640		/* 640 bytes, 320 samples */
+#define	SLIN_SAMPLES	320
 
 static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext)
 {
@@ -39,7 +40,7 @@
 	/* Send a frame from the file to the appropriate channel */
 
 	s->fr.frametype = AST_FRAME_VOICE;
-	s->fr.subclass = AST_FORMAT_SLINEAR;
+	s->fr.subclass = AST_FORMAT_SLINEAR16;
 	s->fr.mallocd = 0;
 	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) < 1) {
@@ -55,12 +56,13 @@
 static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
 {
 	int res;
+
 	if (f->frametype != AST_FRAME_VOICE) {
 		ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
 		return -1;
 	}
-	if (f->subclass != AST_FORMAT_SLINEAR) {
-		ast_log(LOG_WARNING, "Asked to write non-slinear frame (%d)!\n", f->subclass);
+	if (f->subclass != AST_FORMAT_SLINEAR16) {
+		ast_log(LOG_WARNING, "Asked to write non-slinear16 frame (%d)!\n", f->subclass);
 		return -1;
 	}
 	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
@@ -72,7 +74,7 @@
 
 static int slinear_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
 {
-	off_t offset=0,min,cur,max;
+	off_t offset=0, min, cur, max;
 
 	min = 0;
 	sample_offset <<= 1;
@@ -90,6 +92,7 @@
 	}
 	/* always protect against seeking past begining. */
 	offset = (offset < min)?min:offset;
+
 	return fseeko(fs->f, offset, SEEK_SET);
 }
 
@@ -104,9 +107,9 @@
 }
 
 static const struct ast_format slin_f = {
-	.name = "sln",
-	.exts = "sln|raw",
-	.format = AST_FORMAT_SLINEAR,
+	.name = "sln16",
+	.exts = "sln16",
+	.format = AST_FORMAT_SLINEAR16,
 	.write = slinear_write,
 	.seek = slinear_seek,
 	.trunc = slinear_trunc,
@@ -119,6 +122,7 @@
 {
 	if (ast_format_register(&slin_f))
 		return AST_MODULE_LOAD_FAILURE;
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -127,4 +131,4 @@
 	return ast_format_unregister(slin_f.name);
 }	
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Raw Signed Linear Audio support (SLN)");
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Raw Signed Linear 16KHz Audio support (SLN16)");




More information about the asterisk-commits mailing list