aboutsummaryrefslogtreecommitdiff
path: root/audio/stymulator/files/patch-ymplayer.cpp
blob: dff56c8f7dac82c04f29f43fdc0025b404484662 (plain) (blame)
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
--- ymplayer.cpp.orig	2016-07-26 16:04:42 UTC
+++ ymplayer.cpp
@@ -6,7 +6,6 @@
 	Project Page: http://atariarea.krap.pl/stymulator
 	
 	Original ST-Sound GPL library by Arnaud Carre (http://leonard.oxg.free.fr)
-	ALSA (Advanced Linux Sound Architecture) library (http://www.alsa-project.org/)
 
 -----------------------------------------------------------------------------
  *   STYMulator is free software; you can redistribute it and/or modify    *
@@ -35,12 +34,16 @@
 #include "stsoundlib/StSoundLibrary.h"
 #include "ui.h"
 #include "sound.h"
-#include <alsa/asoundlib.h>
+#include <sys/soundcard.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-extern snd_pcm_uframes_t period_size;
+extern int period_size;
 bool digi;
 
 int main(int argc, char **argv)
@@ -55,7 +58,7 @@ bool playing;
 bool ff = false;
 bool rew = false;
 	
-char *platform;
+const char *platform;
 
 	if (PLATFORM)
 		platform = "64bit";
@@ -69,30 +72,22 @@ char *platform;
 		return -1;
 	}
 
-	snd_pcm_t *pcm_handle;
-	snd_pcm_hw_params_t *hwparams;
-	snd_pcm_hw_params_alloca(&hwparams);
+        int audio_fd;
 
 	int err;
 	unsigned int buf;
 
-	snd_output_t *output = NULL;
-	char pcm_name[] = "default";
+	char pcm_name[] = "/dev/dsp";
 
 	YMMUSIC *pMusic = ymMusicCreate();
 
 	if (ymMusicLoad(pMusic,argv[1])) {
-
-		if ((err = snd_output_stdio_attach(&output, stdout, 0)) < 0) {
-			printf("Output failed: %s\n", snd_strerror(err));
-			return 0;
-		}
-		if ((err = snd_pcm_open(&pcm_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-			printf("Playback open error: %s\n", snd_strerror(err));
+		if ((audio_fd = open(pcm_name, O_WRONLY)) < 0) {
+			printf("device open error: %s\n", strerror(errno));
 			return 0;
 		}
-		if ((err = alsa_init(pcm_handle, hwparams)) < 0) {
-			printf("Setting of hwparams failed: %s\n", snd_strerror(err));
+		if (oss_init(audio_fd) < 0) {
+			printf("Setting of hwparams failed: %s\n", strerror(errno));
 			exit(EXIT_FAILURE);
 		}
 
@@ -113,15 +108,10 @@ char *platform;
 			if (digi)
 				draw_time(ymMusicGetPos(pMusic) / 1000);
 
-			if ((err = snd_pcm_writei(pcm_handle, convertBuffer, buf)) == -EPIPE) {
-				err = snd_pcm_prepare(pcm_handle);
-			} else if (err == -ESTRPIPE) {
-				while ((err = snd_pcm_resume(pcm_handle)) == -EAGAIN)
-				sleep(1);
-				if (err < 0) {
-					err = snd_pcm_prepare(pcm_handle);
-				}
-			}
+			if (write(audio_fd, convertBuffer, buf*2) < 0) {
+                            perror("audio device not ready for data");
+                        }
+                        
 			switch(getch()) {
 				case 27: case 'q':	quit = true; break;
 				case 'z':	pmode = true;	break; //play
@@ -132,6 +122,7 @@ char *platform;
 				case 'n':	rew = true; break;
 			}
 			if (rmode)
+			{
 				if (repeat) {
 					ymMusicSetLoopMode(pMusic,YMTRUE);
 					mvaddstr(pos_y+7,pos_x+67,"Yes");
@@ -143,7 +134,7 @@ char *platform;
 					rmode = false;
 					repeat = true;
 				}
-
+			}
 			if (!stop && playing) {
 				if (pmode && !paused)
 					mvaddstr(pos_y+6,pos_x+67,"Play");	//play
@@ -168,18 +159,20 @@ char *platform;
 				pmode = false;
 			}
 
-			if (ymMusicIsSeekable(pMusic) && digi) 
+			if (ymMusicIsSeekable(pMusic) && digi)
+			{
 				if (ff) {
-				ymMusicSeek(pMusic, ymMusicGetPos(pMusic) + 1000);
-				ff = false;
-			} else if (rew) {
-				ymMusicSeek(pMusic, ymMusicGetPos(pMusic) - 1000);
-				rew = false;
+					ymMusicSeek(pMusic, ymMusicGetPos(pMusic) + 1000);
+					ff = false;
+				} else if (rew) {
+					ymMusicSeek(pMusic, ymMusicGetPos(pMusic) - 1000);
+					rew = false;
+				}
 			}
 		}	
 	
 		ymMusicStop(pMusic);
-		snd_pcm_close(pcm_handle);
+		close(audio_fd);
 		delete convertBuffer;
 		ui_end();