diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c
index 35ef9e2d99bd62617a258a2294e193259670fd5b..ebad1225f348691fdb7fac8ea0fc6390b001d49b 100755
--- a/codecs/codec_gsm.c
+++ b/codecs/codec_gsm.c
@@ -177,10 +177,10 @@ static struct ast_frame *lintogsm_frameout(struct ast_translator_pvt *tmp)
 	while(tmp->tail >= 160) {
 		if ((x+1) * 33 >= sizeof(tmp->outbuf)) {
 			ast_log(LOG_WARNING, "Out of buffer space\n");
-			return NULL;
+			break;
 		}
 		/* Encode a frame of data */
-		gsm_encode(tmp->gsm, tmp->buf, (gsm_byte *) tmp->outbuf + (x * 33));
+		gsm_encode(tmp->gsm, tmp->buf, ((gsm_byte *) tmp->outbuf) + (x * 33));
 		/* Assume 8000 Hz -- 20 ms */
 		tmp->tail -= 160;
 		/* Move the data at the end of the buffer to the front */
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index a7292043a9c26e5b8c6745955a9f7c4b89cbc302..679b714a95985d86ba66e048de159018abda89bb 100755
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -504,6 +504,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
 {
 	int res;
 	char msdata[66];
+	int len =0;
 	if (f->frametype != AST_FRAME_VOICE) {
 		ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
 		return -1;
@@ -512,20 +513,23 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if (fs->secondhalf) {
-		memcpy(fs->gsm + 33, f->data, 33);
-		conv66(fs->gsm, msdata);
-		if ((res = write(fs->fd, msdata, 65)) != 65) {
-			ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
-			return -1;
+	while(len < f->datalen) {
+		if (fs->secondhalf) {
+			memcpy(fs->gsm + 33, f->data + len, 33);
+			conv66(fs->gsm, msdata);
+			if ((res = write(fs->fd, msdata, 65)) != 65) {
+				ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
+				return -1;
+			}
+			fs->bytes += 65;
+			update_header(fs->fd, fs->bytes);
+		} else {
+			/* Copy the data and do nothing */
+			memcpy(fs->gsm, f->data + len, 33);
 		}
-		fs->bytes += 65;
-		update_header(fs->fd, fs->bytes);
-	} else {
-		/* Copy the data and do nothing */
-		memcpy(fs->gsm, f->data, 33);
+		fs->secondhalf = !fs->secondhalf;
+		len += 33;
 	}
-	fs->secondhalf = !fs->secondhalf;
 	return 0;
 }