-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathspcplayerlinux.c
113 lines (95 loc) · 2.19 KB
/
spcplayerlinux.c
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
/*Stephen B Melvin Jr, <[email protected]>
Version 0.2
*/
#ifdef __linux__
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/soundcard.h>
#include <fcntl.h>
#include "openspc.h"
#include <unistd.h>
#include <sys/stat.h>
#include <ctype.h>
#include <string.h>
#endif
int main(int argc, char *argv[])
{
int optionoffset=0,audio_fd,channels=2,rformat,rchannels,format=AFMT_S16_LE,speed=32000,fd;
char audio_device[]="/dev/dsp";
char ver[]="0.2";
char c;
void *ptr,*buf;
off_t size;
if((argc<2))
{
printf("\n[?] Usage: soap [sound device] SPC_FILE_NAME\n[?] Optional parameters are in brackets.\n[?] SOAP Version %s (2003) Steve B Melvin Jr\n\n",ver);
exit(1);
}
if((argc>2))
{
strcpy(audio_device,argv[1]);
optionoffset++;
}
if((audio_fd=open(audio_device, O_WRONLY, 0)) ==-1)
{
printf("[-] Could not open, %s.\n", audio_device);
exit(1);
}
printf("[+] Successfully opened, %s.\n",audio_device);
rformat=format;
if(ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1)
{
printf("[-] Could not set sound format.\n");
exit(1);
}
if(format!=rformat)
{
printf("[-] Could not set sound format.\n");
exit(1);
}
printf("[+] Successfully set sound format.\n");
rchannels=channels;
if(ioctl(audio_fd,SNDCTL_DSP_CHANNELS, &channels) == -1)
{
printf("[-] Could not set channels.\n");
exit(1);
}
if(channels!=rchannels)
{
printf("[-] Could not set channels.\n");
exit(1);
}
printf("[+] Successfully set channels.\n");
if(ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed)==-1)
{
printf("[-] Could not set speed.\n");
exit(1);
}
printf("[+] Using speed, {%iHz}\n",speed);
buf=malloc(32000);
fd=open(argv[1+optionoffset],O_RDONLY);
if(fd<0)
{
printf("[-] Could not open \'%s\'\n.",argv[1]);
exit(1);
}
size=lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
ptr=malloc(size);
read(fd,ptr,size);
close(fd);
fd=OSPC_Init(ptr,size);
free(ptr);
fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK);
printf("[+] Playing SPC, press Enter to quit.\n");
while((read(STDIN_FILENO,&c,1))<=0)
{
size=OSPC_Run(-1,buf,32000);
write(audio_fd,buf,size);
}
printf("\nGoodbye!\n");
return 0;
}