diff --git a/formats/format_g723.c b/formats/format_g723.c
index 594f3d1c0bb6810666a32d86966f7a8a145e7365..4beba0c648d7a7879605f4b11c8334774bea7251 100644
--- a/formats/format_g723.c
+++ b/formats/format_g723.c
@@ -76,7 +76,7 @@ static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_G723_1;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, size);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, size);
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != size) {
 		ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
 		return NULL;
diff --git a/formats/format_g726.c b/formats/format_g726.c
index 135e0a8fe2ab3159f79a84d44573ad1b633c3377..d72f48991908480e332720c09e3e1234909a9407 100644
--- a/formats/format_g726.c
+++ b/formats/format_g726.c
@@ -137,7 +137,7 @@ static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_G726;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, frame_size[fs->rate]);
 	s->fr.samples = 8 * FRAME_TIME;
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
 		if (res)
diff --git a/formats/format_g729.c b/formats/format_g729.c
index f2eef83e43bf43cd1c6c7a6d401e88ac9232c636..1719e3a5c80727304fc469741380783d3767c673 100644
--- a/formats/format_g729.c
+++ b/formats/format_g729.c
@@ -62,7 +62,7 @@ static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
 	s->fr.subclass = AST_FORMAT_G729A;
 	s->fr.mallocd = 0;
 	s->fr.samples = G729A_SAMPLES;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+	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)) != s->fr.datalen) {
 		if (res && (res != 10))	/* XXX what for ? */
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_gsm.c b/formats/format_gsm.c
index bc91d1f0b2b71dbbb57e1a9d44cd73fdf88cc94d..423088c1788c53500cd8c0d4f87be84fb48c6d15 100644
--- a/formats/format_gsm.c
+++ b/formats/format_gsm.c
@@ -67,7 +67,7 @@ static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext)
 
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_GSM;
-	FR_SET_BUF(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE)
+	AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE)
 	s->fr.mallocd = 0;
 	if ((res = fread(s->fr.data, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) {
 		if (res)
diff --git a/formats/format_h263.c b/formats/format_h263.c
index ee455beb3ae31b49e3ce098e12d8d1ee2467ff52..c64e001fdebd9ed3540d2c74aaf8fcf89273264e 100644
--- a/formats/format_h263.c
+++ b/formats/format_h263.c
@@ -88,7 +88,7 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VIDEO;
 	s->fr.subclass = AST_FORMAT_H263;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_h264.c b/formats/format_h264.c
index 3e358086ea1196607d32371260401c8db75a9877..26db782e5a101fd785f759a9ffecf91a26d3dbf3 100644
--- a/formats/format_h264.c
+++ b/formats/format_h264.c
@@ -84,7 +84,7 @@ static struct ast_frame *h264_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VIDEO;
 	s->fr.subclass = AST_FORMAT_H264;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d of %d) (%s)!\n", res, len, strerror(errno));
diff --git a/formats/format_ilbc.c b/formats/format_ilbc.c
index 2a027cb994030f37183082bd0e60fbab1b628033..940abf25f5358b154aa37b75778d704cc066e779 100644
--- a/formats/format_ilbc.c
+++ b/formats/format_ilbc.c
@@ -60,7 +60,7 @@ static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_ILBC;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, ILBC_BUF_SIZE);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, ILBC_BUF_SIZE);
 	if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_ogg_vorbis.c b/formats/format_ogg_vorbis.c
index 2ca0cce34b5991e6e4f7da5eedd1a487b32d7242..ee12e6a8fced504e233b74c3bcfbd7ad3791812a 100644
--- a/formats/format_ogg_vorbis.c
+++ b/formats/format_ogg_vorbis.c
@@ -436,7 +436,7 @@ static struct ast_frame *ogg_vorbis_read(struct ast_filestream *fs,
 	fs->fr.frametype = AST_FRAME_VOICE;
 	fs->fr.subclass = AST_FORMAT_SLINEAR;
 	fs->fr.mallocd = 0;
-	FR_SET_BUF(&fs->fr, fs->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+	AST_FRAME_SET_BUFFER(&fs->fr, fs->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
 
 	while (samples_out != SAMPLES_MAX) {
 		float **pcm;
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 493d8afe9d1ee0bc2068ee9126d3f1ba7f9d69b7..889e7afc2ecfe1bc0b8629536ff7aa62019d5534 100644
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -95,7 +95,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = s->fmt->format;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+	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) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_sln.c b/formats/format_sln.c
index 939a121bb98fc42071ed1bccd1914489d9f15940..3e4d2e0c9a74fd539defff9d71c2ed96943a4775 100644
--- a/formats/format_sln.c
+++ b/formats/format_sln.c
@@ -54,7 +54,7 @@ static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_SLINEAR;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+	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) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_vox.c b/formats/format_vox.c
index 5afc1e322dcf3789ae3d6b399f940fcde13b66f9..b1f7e688a209dcfc416f0140434aaa9aef695f9c 100644
--- a/formats/format_vox.c
+++ b/formats/format_vox.c
@@ -56,7 +56,7 @@ static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_ADPCM;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE);
+	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) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
diff --git a/formats/format_wav.c b/formats/format_wav.c
index f56cdae4ddbd0893c87a1b5df1e92bd7c691ca46..eb3b2d5ad5971bf6403a535fecc6b995ef3b1799 100644
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -369,7 +369,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass = AST_FORMAT_SLINEAR;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, bytes);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, bytes);
 	
 	if ( (res = fread(s->fr.data, 1, s->fr.datalen, s->f)) <= 0 ) {
 		if (res)
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index 85b9902c7abc94be57294085078e7e0cb401751a..d2fa1c0ce216b1da66c46005400ed35d4967723c 100644
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -379,7 +379,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.samples = GSM_SAMPLES;
 	s->fr.mallocd = 0;
-	FR_SET_BUF(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
+	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE);
 	if (fs->secondhalf) {
 		/* Just return a frame based on the second GSM frame */
 		s->fr.data = (char *)s->fr.data + GSM_FRAME_SIZE;
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index 21b59692863a1057f154b347bcc1d0cddb0af443..099e20080de54039ee04a5a9d8bd0026cfb174a9 100644
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -111,7 +111,15 @@ struct ast_frame {
 	struct ast_frame *next;			
 };
 
-#define	FR_SET_BUF(fr, _base, _ofs, _datalen)	\
+/*!
+ * Set the various field of a frame to point to a buffer.
+ * Typically you set the base address of the buffer, the offset as
+ * AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued.
+ * The remaining things (to be done manually) is set the number of
+ * samples, which cannot be derived from the datalen unless you know
+ * the number of bits per sample.
+ */
+#define	AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)	\
 	{					\
 	(fr)->data = (char *)_base + (_ofs);	\
 	(fr)->offset = (_ofs);			\