File: 08_audiofile.dpatch

package info (click to toggle)
alsaplayer 0.99.76-9%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,752 kB
  • ctags: 2,970
  • sloc: ansic: 16,775; sh: 10,709; cpp: 9,442; makefile: 694
file content (48 lines) | stat: -rw-r--r-- 1,450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /bin/sh /usr/share/dpatch/dpatch-run
## 01_flac_input.dpatch by Paul Brossier <piem@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Patch audiofile to play mono files correctly

@DPATCH@

--- alsaplayer-0.99.76.orig/input/audiofile/audiofile_engine.c	2003-02-16 12:49:00.000000000 +0100
+++ alsaplayer-0.99.76/input/audiofile/audiofile_engine.c	2004-03-07 18:03:27.831230314 +0100
@@ -162,12 +162,33 @@ static int audiofile_play_frame (input_o
 	if (!buffer)
 		return 0;
 
-	bytes_to_read = FRAME_COUNT;
+	bytes_to_read = FRAME_COUNT * obj->nr_channels / 2;
 
 	frames_read = afReadFrames(data->filehandle, AF_DEFAULT_TRACK, buffer,
-		 bytes_to_read / data->frameSize);
-	if (buf)
-		memcpy(buf, buffer,  FRAME_COUNT);
+		 bytes_to_read / data->frameSize) * 2 / obj->nr_channels;
+	if (buf) {
+		if (obj->nr_channels == 2)
+			memcpy(buf, buffer,  FRAME_COUNT);
+		else { /* mono, so double  */
+			int i;
+			if (data->frameSize == 1) {
+				unsigned char *us = (unsigned char *)buffer;
+				short *d = (short *)buf;
+				for (i=0; i < FRAME_COUNT; i+=4) {
+					short c = *d++ = ((*us ^ 0x80) << 8) | *us;
+					us++;
+					*d++ = c;
+				}
+			} else {
+				short *s = (short *)buffer;
+				short *d = (short *)buf;
+				for (i=0; i < FRAME_COUNT; i+=4) {
+						*d++ = *s;
+						*d++ = *s++; /* Copy twice */
+				}
+			}
+		}
+	}
 
 	if (frames_read * data->frameSize < FRAME_COUNT)
 		return 0;