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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
# Patch by J. Dru Lemley.
#PATCHOPTIONS: -p1
diff -Nuar gramofile-1.6/Makefile mygramofile-1.6/Makefile
--- gramofile-1.6/Makefile Tue Mar 28 14:23:58 2000
+++ mygramofile-1.6/Makefile Fri Mar 2 11:51:15 2001
@@ -19,7 +19,7 @@
########## CHOOSE YOUR ARCHITECTURE: (NOTE: also see bplaysrc/Makefile!)
# For Linux (and maybe others), use these:
-CFLAGS = -Wall -O2 -DTURBO_MEDIAN -DTURBO_BUFFER
+CFLAGS = -Wall -O2 -funroll-loops -DTURBO_MEDIAN -DTURBO_BUFFER
DEPS = $(OBJS) makebplay
LIBS = -lncurses -lm
COPY_A = -a
diff -Nuar gramofile-1.6/endian.h mygramofile-1.6/endian.h
--- gramofile-1.6/endian.h Thu Mar 29 22:17:08 2001
+++ mygramofile-1.6/endian.h Thu Mar 29 21:37:41 2001
@@ -10,4 +10,10 @@
extern uint32_t SwapFourBytes (uint32_t);
extern sample_t SwapSample (sample_t);
+/* macro to swap endianness of values in a sample_t with */
+/* a few 32-bit operations -- very fast */
+#define SWAPSAMPLEREF(s) *((uint32_t *)(s)) = \
+ ((*((uint32_t *)(s)) & 0xff00ff00) >> 8) | \
+ ((*((uint32_t *)(s)) & 0x00ff00ff) << 8)
+
#endif
diff -Nuar gramofile-1.6/signpr_wav.c mygramofile-1.6/signpr_wav.c
--- gramofile-1.6/signpr_wav.c Tue Mar 28 15:07:26 2000
+++ mygramofile-1.6/signpr_wav.c Thu Mar 29 21:38:28 2001
@@ -22,6 +22,8 @@
/* ----- SOURCE & READING -------------------------------------------------- */
FILE *sourcefile;
+int num_read_samples_buffered = 0;
+sample_t readsamplebuffer[44100];
int
openwavsource (char *filename)
@@ -106,6 +108,7 @@
}
/* Well, everything seems to be OK */
+ num_read_samples_buffered = 0;
return 1;
}
@@ -113,6 +116,7 @@
closewavsource ()
{
fclose (sourcefile);
+ num_read_samples_buffered = 0;
}
int
@@ -121,6 +125,9 @@
{
struct stat buf;
+ /* throw away buffer on fseek */
+ num_read_samples_buffered = 0;
+
if (fstat (fileno (sourcefile), &buf))
return 0;
@@ -135,22 +142,28 @@
sample_t
readsamplesource ()
-{
- sample_t sample;
-
- if (fread (&sample, 1, 4, sourcefile) != 4)
- {
- /* reading after end of file - this just happens when using
- pre-read buffers! */
- sample.left = 0;
- sample.right = 0;
- }
+{
+ /* millions of calls to fread sure slow things down.... buffer it a little */
+ static int i;
+
+ if (i >= num_read_samples_buffered)
+ {
+ num_read_samples_buffered = fread(readsamplebuffer, 4, sizeof(readsamplebuffer)/4, sourcefile);
+ i = 0;
+ if (!num_read_samples_buffered)
+ {
+ /* reading after end of file - this just happens when using
+ pre-read buffers! */
+ readsamplebuffer[0].left = 0;
+ readsamplebuffer[0].right = 0;
+ return readsamplebuffer[0];
+ }
+ }
#ifdef SWAP_ENDIAN
- sample = SwapSample (sample);
+ SWAPSAMPLEREF (readsamplebuffer+i);
#endif
-
- return sample;
+ return readsamplebuffer[i++];
}
@@ -158,6 +171,8 @@
FILE *destfile;
int destfileispipe; /* remember open() - - -> close() */
+int num_write_samples_buffered = 0;
+sample_t writesamplebuffer[44100];
int
openwavdest (char *filename, long bcount)
@@ -216,12 +231,20 @@
fwrite (&header, sizeof (header), 1, destfile);
+ num_write_samples_buffered = 0; /* just in case */
return 1;
}
+void flushwritebuffer()
+{
+ fwrite(writesamplebuffer, 4 * num_write_samples_buffered, 1, destfile);
+ num_write_samples_buffered = 0;
+}
+
void
closewavdest ()
{
+ flushwritebuffer();
if (destfileispipe)
pclose (destfile);
else
@@ -233,8 +256,9 @@
{
#ifdef SWAP_ENDIAN
- sample = SwapSample (sample);
+ SWAPSAMPLEREF(&sample);
#endif
-
- fwrite (&sample, 4, 1, destfile);
+ if (num_write_samples_buffered == (sizeof (writesamplebuffer) / 4))
+ flushwritebuffer();
+ writesamplebuffer[num_write_samples_buffered++] = sample;
}
|