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
|
$NetBSD: patch-ab,v 1.3 2007/09/29 11:31:09 rillig Exp $
--- src/linux/main_linux.c.orig 2004-05-02 01:53:54.000000000 +0200
+++ src/linux/main_linux.c 2007-09-29 13:23:40.000000000 +0200
@@ -3,6 +3,7 @@
UNIX systems */
#include <ctype.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -218,12 +219,12 @@ static void open_hardware(const char *de
exit(1);
}
}
- /* if it's not a char device and it's not /dev/dsp */
- /* The second check is because when run with esddsp, /dev/dsp
+ /* if it's not a char device and it's not /dev/sound */
+ /* The second check is because when run with esddsp, /dev/sound
doesn't show up as a char device. The original author (Matthew Conte) seems
to have thought that esddsp should work without this hack. Is doing this
bad? --Matthew Strait */
- if( !S_ISCHR(status.st_mode) && strcmp("/dev/dsp", device))
+ if( !S_ISCHR(status.st_mode) && strcmp("/dev/sound", device))
{
printf("%s is not a character device.\n", device);
exit(1);
@@ -305,7 +306,7 @@ static void show_help(void)
printf("\t-h \tHelp\n");
printf("\t-v \tVersion information\n");
printf("\n\t-t x\tStart playing track x (default: 1)\n");
- printf("\n\t-d x\tUse device x (default: /dev/dsp)\n");
+ printf("\n\t-d x\tUse device x (default: /dev/sound)\n");
printf("\t-s x\tPlay at x times the normal speed.\n");
printf("\t-f x\tUse x sampling rate (default: 44100)\n");
printf("\t-l x\tLimit total playing time to x seconds (0 = unlimited)\n");
@@ -342,12 +343,59 @@ static void show_info(void)
static void printsonginfo(int current_frame, int total_frames, int limited)
{
/*Why not printf directly? Our termios hijinks for input kills the output*/
+
+ /*
+ * Once again, the termios hijinks cause trouble for NetBSD. \r
+ * sometimes doesn't get printed. Following is a mostly complete
+ * rewrite of the text output section as presented in my NetBSD
+ * pkgsrc package for version 1.92i-mls. The fix was suggested by
+ * Bruce J.A. Nourish. I'm David Griffith.
+ */
+
char *hi = (char *)malloc(255);
char blank[82];
memset(blank, ' ', 80);
blank[80] = '\r';
blank[81] = '\0';
+ if (total_frames !=0) {
+ if (limited) {
+ snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/%d seconds, %d/%d frames\r",
+ nsf->current_song, nsf->num_songs,
+ enabled[0]?'1':'-', enabled[1]?'2':'-',
+ enabled[2]?'3':'-', enabled[3]?'4':'-',
+ enabled[4]?'5':'-', enabled[5]?'6':'-',
+ (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate),
+ (int)((float)(total_frames + nsf->playback_rate - 1)/(float)nsf->playback_rate),
+ current_frame,
+ total_frames);
+ } else {
+ snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d/? seconds, %d/? frames\r",
+ nsf->current_song, nsf->num_songs,
+ enabled[0]?'1':'-', enabled[1]?'2':'-',
+ enabled[2]?'3':'-', enabled[3]?'4':'-',
+ enabled[4]?'5':'-', enabled[5]?'6':'-',
+ (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate),
+ current_frame);
+ }
+ } else {
+ snprintf(hi, 254, "\rPlaying track %d of %d, channels %c%c%c%c%c%c, %d seconds, %d frames\r",
+ nsf->current_song, nsf->num_songs,
+ enabled[0]?'1':'-', enabled[1]?'2':'-',
+ enabled[2]?'3':'-', enabled[3]?'4':'-',
+ enabled[4]?'5':'-', enabled[5]?'6':'-',
+ (int)((float)(current_frame + nsf->playback_rate - 1)/(float)nsf->playback_rate),
+ current_frame);
+ }
+
+
+/*
+ * Not only does the following section do funny things to terminals,
+ * it's a good example of how to use the trinary operator to make your
+ * code very hard to understand. Please don't use the trinary operator
+ * when if-then-else will do.
+ */
+#ifdef __REALLY_BIG_COMMENT__
snprintf(hi, 254,
total_frames != 0 ?
"Playing track %d/%d, channels %c%c%c%c%c%c, %d/%d sec, %d/%d frames\r":
@@ -363,9 +411,16 @@ static void printsonginfo(int current_fr
current_frame,
total_frames
);
+#endif /* __REALLY_BIG_COMMENT__ */
+
+/*
+ * I'm not sure what this is supposed to do. Under NetBSD it garbles
+ * the screen, but not to the degree as the above commented-out code.
+/*
if(!(current_frame%10))
write(STDOUT_FILENO, (void *)blank, strlen(blank));
+*/
write(STDOUT_FILENO, (void *)hi, strlen(hi));
free(hi);
@@ -565,7 +620,7 @@ static void close_nsf_file(void)
/* HAS ROOT PERMISSIONS -- BE CAREFUL */
int main(int argc, char **argv)
{
- char *device = "/dev/dsp";
+ char *device = "/dev/sound";
char *filename;
int track = 1;
int done = 0;
|