diff options
Diffstat (limited to 'apps/plugins/mikmod/mdriver.c')
-rw-r--r-- | apps/plugins/mikmod/mdriver.c | 189 |
1 files changed, 96 insertions, 93 deletions
diff --git a/apps/plugins/mikmod/mdriver.c b/apps/plugins/mikmod/mdriver.c index 2e8e9b5e41..2e1f8063b9 100644 --- a/apps/plugins/mikmod/mdriver.c +++ b/apps/plugins/mikmod/mdriver.c | |||
@@ -1,17 +1,17 @@ | |||
1 | /* MikMod sound library | 1 | /* MikMod sound library |
2 | (c) 1998, 1999, 2000, 2001 Miodrag Vallat and others - see file AUTHORS | 2 | (c) 1998-2014 Miodrag Vallat and others - see file AUTHORS |
3 | for complete list. | 3 | for a complete list. |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or modify | 5 | This library is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU Library General Public License as | 6 | it under the terms of the GNU Library General Public License as |
7 | published by the Free Software Foundation; either version 2 of | 7 | published by the Free Software Foundation; either version 2 of |
8 | the License, or (at your option) any later version. | 8 | the License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU Library General Public License for more details. | 13 | GNU Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public | 15 | You should have received a copy of the GNU Library General Public |
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
@@ -20,8 +20,6 @@ | |||
20 | 20 | ||
21 | /*============================================================================== | 21 | /*============================================================================== |
22 | 22 | ||
23 | $Id: mdriver.c,v 1.4 2007/12/03 20:59:05 denis111 Exp $ | ||
24 | |||
25 | These routines are used to access the available soundcard drivers. | 23 | These routines are used to access the available soundcard drivers. |
26 | 24 | ||
27 | ==============================================================================*/ | 25 | ==============================================================================*/ |
@@ -34,54 +32,59 @@ | |||
34 | #include <unistd.h> | 32 | #include <unistd.h> |
35 | #endif | 33 | #endif |
36 | 34 | ||
37 | #if 0 | ||
38 | #if defined unix || (defined __APPLE__ && defined __MACH__) | ||
39 | #include <pwd.h> | ||
40 | #include <sys/stat.h> | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | #include <string.h> | 35 | #include <string.h> |
45 | #ifdef HAVE_STRINGS_H | ||
46 | #include <strings.h> | ||
47 | #endif | ||
48 | 36 | ||
49 | #include "mikmod_internals.h" | 37 | #include "mikmod_internals.h" |
50 | 38 | ||
39 | #if (MIKMOD_UNIX) | ||
40 | #include <pwd.h> | ||
41 | #include <sys/stat.h> | ||
42 | #endif | ||
43 | |||
51 | #ifdef SUNOS | 44 | #ifdef SUNOS |
52 | extern int fprintf(FILE *, const char *, ...); | 45 | extern int fprintf(FILE *, const char *, ...); |
53 | #endif | 46 | #endif |
54 | 47 | ||
55 | static MDRIVER *firstdriver=NULL; | ||
56 | MIKMODAPI MDRIVER *md_driver=NULL; | ||
57 | extern MODULE *pf; /* modfile being played */ | 48 | extern MODULE *pf; /* modfile being played */ |
58 | 49 | ||
50 | /* EXPORTED GLOBALS */ | ||
51 | MIKMODAPI MDRIVER *md_driver = NULL; | ||
52 | |||
59 | /* Initial global settings */ | 53 | /* Initial global settings */ |
60 | MIKMODAPI UWORD md_device = 0; /* autodetect */ | 54 | MIKMODAPI UWORD md_device = 0; /* autodetect */ |
61 | MIKMODAPI UWORD md_mixfreq = 44100; | 55 | MIKMODAPI ULONG md_mixfreq = 44100; |
62 | MIKMODAPI UWORD md_mode = DMODE_STEREO | DMODE_16BITS | | 56 | MIKMODAPI UWORD md_mode = DMODE_STEREO | DMODE_16BITS | |
63 | DMODE_SURROUND |DMODE_SOFT_MUSIC | | 57 | DMODE_SURROUND | |
64 | DMODE_SOFT_SNDFX; | 58 | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; |
65 | MIKMODAPI UBYTE md_pansep = 128; /* 128 == 100% (full left/right) */ | 59 | MIKMODAPI UBYTE md_pansep = 128; /* 128 == 100% (full left/right) */ |
66 | MIKMODAPI UBYTE md_reverb = 0; /* no reverb */ | 60 | MIKMODAPI UBYTE md_reverb = 0; /* no reverb */ |
67 | MIKMODAPI UBYTE md_volume = 128; /* global sound volume (0-128) */ | 61 | MIKMODAPI UBYTE md_volume = 128; /* global sound volume (0-128) */ |
68 | MIKMODAPI UBYTE md_musicvolume = 128; /* volume of song */ | 62 | MIKMODAPI UBYTE md_musicvolume = 128; /* volume of song */ |
69 | MIKMODAPI UBYTE md_sndfxvolume = 128; /* volume of sound effects */ | 63 | MIKMODAPI UBYTE md_sndfxvolume = 128; /* volume of sound effects */ |
70 | UWORD md_bpm = 125; /* tempo */ | 64 | |
71 | 65 | /* INTERNAL GLOBALS */ | |
72 | /* Do not modify the numchn variables yourself! use MD_SetVoices() */ | 66 | UWORD md_bpm = 125; /* tempo */ |
73 | UBYTE md_numchn=0,md_sngchn=0,md_sfxchn=0; | 67 | |
74 | UBYTE md_hardchn=0,md_softchn=0; | 68 | /* Do not modify the numchn variables yourself! use MikMod_SetNumVoices() */ |
75 | 69 | UBYTE md_numchn = 0, md_sngchn = 0, md_sfxchn = 0; | |
76 | void (*md_player)(void) = Player_HandleTick; | 70 | UBYTE md_hardchn = 0, md_softchn= 0; |
77 | static volatile int isplaying=0, initialized = 0; | 71 | |
78 | static UBYTE *sfxinfo; | 72 | MikMod_player_t md_player = Player_HandleTick; |
79 | static int sfxpool; | 73 | |
80 | 74 | MikMod_callback_t vc_callback = NULL; | |
81 | static SAMPLE **md_sample = NULL; | 75 | |
76 | /* PRIVATE VARS */ | ||
77 | static MDRIVER *firstdriver = NULL; | ||
78 | |||
79 | static volatile int isplaying = 0, initialized = 0; | ||
80 | |||
81 | static UBYTE *sfxinfo; | ||
82 | static int sfxpool; | ||
83 | |||
84 | static SAMPLE **md_sample = NULL; | ||
82 | 85 | ||
83 | /* Previous driver in use */ | 86 | /* Previous driver in use */ |
84 | static SWORD olddevice = -1; | 87 | static SWORD olddevice = -1; |
85 | 88 | ||
86 | /* Limits the number of hardware voices to the specified amount. | 89 | /* Limits the number of hardware voices to the specified amount. |
87 | This function should only be used by the low-level drivers. */ | 90 | This function should only be used by the low-level drivers. */ |
@@ -183,17 +186,18 @@ MIKMODAPI CHAR* MikMod_InfoDriver(void) | |||
183 | 186 | ||
184 | MUTEX_LOCK(lists); | 187 | MUTEX_LOCK(lists); |
185 | /* compute size of buffer */ | 188 | /* compute size of buffer */ |
186 | for(l=firstdriver;l;l=l->next) | 189 | for(l = firstdriver; l; l = l->next) |
187 | len+=4+(l->next?1:0)+strlen(l->Version); | 190 | len += 4 + (l->next ? 1 : 0) + strlen(l->Version); |
188 | 191 | ||
189 | if(len) | 192 | if(len) |
190 | if((list=MikMod_malloc(len*sizeof(CHAR)))) { | 193 | if((list=(CHAR*)MikMod_malloc(len*sizeof(CHAR))) != NULL) { |
191 | list[0]=0; | 194 | CHAR *list_end = list; |
192 | /* list all registered device drivers : */ | 195 | list[0] = 0; |
193 | for(t=1,l=firstdriver;l;l=l->next,t++) | 196 | /* list all registered device drivers : */ |
194 | sprintf(list,(l->next)?"%s%2d %s\n":"%s%2d %s", | 197 | for(t = 1, l = firstdriver; l; l = l->next, t++) { |
195 | list,t,l->Version); | 198 | list_end += sprintf(list_end, "%2d %s%s", t, l->Version, (l->next)? "\n" : ""); |
196 | } | 199 | } |
200 | } | ||
197 | MUTEX_UNLOCK(lists); | 201 | MUTEX_UNLOCK(lists); |
198 | return list; | 202 | return list; |
199 | } | 203 | } |
@@ -214,7 +218,7 @@ void _mm_registerdriver(struct MDRIVER* drv) | |||
214 | } | 218 | } |
215 | cruise->next = drv; | 219 | cruise->next = drv; |
216 | } else | 220 | } else |
217 | firstdriver = drv; | 221 | firstdriver = drv; |
218 | } | 222 | } |
219 | } | 223 | } |
220 | 224 | ||
@@ -230,7 +234,7 @@ MIKMODAPI void MikMod_RegisterDriver(struct MDRIVER* drv) | |||
230 | MUTEX_UNLOCK(lists); | 234 | MUTEX_UNLOCK(lists); |
231 | } | 235 | } |
232 | 236 | ||
233 | MIKMODAPI int MikMod_DriverFromAlias(CHAR *alias) | 237 | MIKMODAPI int MikMod_DriverFromAlias(const CHAR *alias) |
234 | { | 238 | { |
235 | int rank=1; | 239 | int rank=1; |
236 | MDRIVER *cruise; | 240 | MDRIVER *cruise; |
@@ -252,18 +256,17 @@ MIKMODAPI int MikMod_DriverFromAlias(CHAR *alias) | |||
252 | 256 | ||
253 | MIKMODAPI MDRIVER *MikMod_DriverByOrdinal(int ordinal) | 257 | MIKMODAPI MDRIVER *MikMod_DriverByOrdinal(int ordinal) |
254 | { | 258 | { |
255 | MDRIVER *cruise; | 259 | MDRIVER *cruise; |
256 | 260 | ||
257 | /* Allow only driver ordinals > 0 */ | 261 | /* Allow only driver ordinals > 0 */ |
258 | if (!ordinal) | 262 | if (!ordinal) return NULL; |
259 | return 0; | ||
260 | 263 | ||
261 | MUTEX_LOCK(lists); | 264 | MUTEX_LOCK(lists); |
262 | cruise = firstdriver; | 265 | cruise = firstdriver; |
263 | while (cruise && --ordinal) | 266 | while (cruise && --ordinal) |
264 | cruise = cruise->next; | 267 | cruise = cruise->next; |
265 | MUTEX_UNLOCK(lists); | 268 | MUTEX_UNLOCK(lists); |
266 | return cruise; | 269 | return cruise; |
267 | } | 270 | } |
268 | 271 | ||
269 | SWORD MD_SampleLoad(SAMPLOAD* s, int type) | 272 | SWORD MD_SampleLoad(SAMPLOAD* s, int type) |
@@ -496,14 +499,12 @@ MIKMODAPI ULONG Voice_RealVolume(SBYTE voice) | |||
496 | return result; | 499 | return result; |
497 | } | 500 | } |
498 | 501 | ||
499 | extern MikMod_callback_t vc_callback; | ||
500 | |||
501 | MIKMODAPI void VC_SetCallback(MikMod_callback_t callback) | 502 | MIKMODAPI void VC_SetCallback(MikMod_callback_t callback) |
502 | { | 503 | { |
503 | vc_callback = callback; | 504 | vc_callback = callback; |
504 | } | 505 | } |
505 | 506 | ||
506 | static int _mm_init(CHAR *cmdline) | 507 | static int _mm_init(const CHAR *cmdline) |
507 | { | 508 | { |
508 | UWORD t; | 509 | UWORD t; |
509 | 510 | ||
@@ -561,7 +562,7 @@ static int _mm_init(CHAR *cmdline) | |||
561 | return 0; | 562 | return 0; |
562 | } | 563 | } |
563 | 564 | ||
564 | MIKMODAPI int MikMod_Init(CHAR *cmdline) | 565 | MIKMODAPI int MikMod_Init(const CHAR *cmdline) |
565 | { | 566 | { |
566 | int result; | 567 | int result; |
567 | 568 | ||
@@ -581,8 +582,8 @@ void MikMod_Exit_internal(void) | |||
581 | md_numchn = md_sfxchn = md_sngchn = 0; | 582 | md_numchn = md_sfxchn = md_sngchn = 0; |
582 | md_driver = &drv_nos; | 583 | md_driver = &drv_nos; |
583 | 584 | ||
584 | if(sfxinfo) MikMod_free(sfxinfo); | 585 | MikMod_free(sfxinfo); |
585 | if(md_sample) MikMod_free(md_sample); | 586 | MikMod_free(md_sample); |
586 | md_sample = NULL; | 587 | md_sample = NULL; |
587 | sfxinfo = NULL; | 588 | sfxinfo = NULL; |
588 | 589 | ||
@@ -598,14 +599,14 @@ MIKMODAPI void MikMod_Exit(void) | |||
598 | MUTEX_UNLOCK(vars); | 599 | MUTEX_UNLOCK(vars); |
599 | } | 600 | } |
600 | 601 | ||
601 | /* Reset the driver using the new global variable settings. | 602 | /* Reset the driver using the new global variable settings. |
602 | If the driver has not been initialized, it will be now. */ | 603 | If the driver has not been initialized, it will be now. */ |
603 | static int _mm_reset(CHAR *cmdline) | 604 | static int _mm_reset(const CHAR *cmdline) |
604 | { | 605 | { |
605 | int wasplaying = 0; | 606 | int wasplaying = 0; |
606 | 607 | ||
607 | if(!initialized) return _mm_init(cmdline); | 608 | if(!initialized) return _mm_init(cmdline); |
608 | 609 | ||
609 | if (isplaying) { | 610 | if (isplaying) { |
610 | wasplaying = 1; | 611 | wasplaying = 1; |
611 | md_driver->PlayStop(); | 612 | md_driver->PlayStop(); |
@@ -629,12 +630,12 @@ static int _mm_reset(CHAR *cmdline) | |||
629 | return 1; | 630 | return 1; |
630 | } | 631 | } |
631 | } | 632 | } |
632 | 633 | ||
633 | if (wasplaying) md_driver->PlayStart(); | 634 | if (wasplaying) return md_driver->PlayStart(); |
634 | return 0; | 635 | return 0; |
635 | } | 636 | } |
636 | 637 | ||
637 | MIKMODAPI int MikMod_Reset(CHAR *cmdline) | 638 | MIKMODAPI int MikMod_Reset(const CHAR *cmdline) |
638 | { | 639 | { |
639 | int result; | 640 | int result; |
640 | 641 | ||
@@ -661,8 +662,8 @@ int MikMod_SetNumVoices_internal(int music, int sfx) | |||
661 | resume = 1; | 662 | resume = 1; |
662 | } | 663 | } |
663 | 664 | ||
664 | if(sfxinfo) MikMod_free(sfxinfo); | 665 | MikMod_free(sfxinfo); |
665 | if(md_sample) MikMod_free(md_sample); | 666 | MikMod_free(md_sample); |
666 | md_sample = NULL; | 667 | md_sample = NULL; |
667 | sfxinfo = NULL; | 668 | sfxinfo = NULL; |
668 | 669 | ||
@@ -764,7 +765,7 @@ MIKMODAPI int MikMod_Active(void) | |||
764 | allocated for use as sound effects (loops through voices, skipping all active | 765 | allocated for use as sound effects (loops through voices, skipping all active |
765 | criticals). | 766 | criticals). |
766 | 767 | ||
767 | Returns the voice that the sound is being played on. */ | 768 | Returns the voice that the sound is being played on. */ |
768 | static SBYTE Sample_Play_internal(SAMPLE *s,ULONG start,UBYTE flags) | 769 | static SBYTE Sample_Play_internal(SAMPLE *s,ULONG start,UBYTE flags) |
769 | { | 770 | { |
770 | int orig=sfxpool;/* for cases where all channels are critical */ | 771 | int orig=sfxpool;/* for cases where all channels are critical */ |
@@ -825,12 +826,15 @@ MIKMODAPI long MikMod_GetVersion(void) | |||
825 | #ifdef HAVE_PTHREAD | 826 | #ifdef HAVE_PTHREAD |
826 | #define INIT_MUTEX(name) \ | 827 | #define INIT_MUTEX(name) \ |
827 | pthread_mutex_t _mm_mutex_##name=PTHREAD_MUTEX_INITIALIZER | 828 | pthread_mutex_t _mm_mutex_##name=PTHREAD_MUTEX_INITIALIZER |
829 | |||
828 | #elif defined(__OS2__)||defined(__EMX__) | 830 | #elif defined(__OS2__)||defined(__EMX__) |
829 | #define INIT_MUTEX(name) \ | 831 | #define INIT_MUTEX(name) \ |
830 | HMTX _mm_mutex_##name | 832 | HMTX _mm_mutex_##name |
831 | #elif defined(WIN32) | 833 | |
834 | #elif defined(_WIN32) | ||
832 | #define INIT_MUTEX(name) \ | 835 | #define INIT_MUTEX(name) \ |
833 | HANDLE _mm_mutex_##name | 836 | HANDLE _mm_mutex_##name |
837 | |||
834 | #else | 838 | #else |
835 | #define INIT_MUTEX(name) \ | 839 | #define INIT_MUTEX(name) \ |
836 | void *_mm_mutex_##name = NULL | 840 | void *_mm_mutex_##name = NULL |
@@ -842,8 +846,8 @@ INIT_MUTEX(lists); | |||
842 | MIKMODAPI int MikMod_InitThreads(void) | 846 | MIKMODAPI int MikMod_InitThreads(void) |
843 | { | 847 | { |
844 | static int firstcall=1; | 848 | static int firstcall=1; |
845 | static int result=0; | 849 | static int result = 0; |
846 | 850 | ||
847 | if (firstcall) { | 851 | if (firstcall) { |
848 | firstcall=0; | 852 | firstcall=0; |
849 | #ifdef HAVE_PTHREAD | 853 | #ifdef HAVE_PTHREAD |
@@ -855,9 +859,9 @@ MIKMODAPI int MikMod_InitThreads(void) | |||
855 | result=0; | 859 | result=0; |
856 | } else | 860 | } else |
857 | result=1; | 861 | result=1; |
858 | #elif defined(WIN32) | 862 | #elif defined(_WIN32) |
859 | if((!(_mm_mutex_lists=CreateMutex(NULL,FALSE,"libmikmod(lists)")))|| | 863 | if((!(_mm_mutex_lists=CreateMutex(NULL,FALSE,TEXT("libmikmod(lists)"))))|| |
860 | (!(_mm_mutex_vars=CreateMutex(NULL,FALSE,"libmikmod(vars)")))) | 864 | (!(_mm_mutex_vars=CreateMutex(NULL,FALSE,TEXT("libmikmod(vars)"))))) |
861 | result=0; | 865 | result=0; |
862 | else | 866 | else |
863 | result=1; | 867 | result=1; |
@@ -880,24 +884,24 @@ MIKMODAPI void MikMod_Lock(void) | |||
880 | 884 | ||
881 | /*========== Parameter extraction helper */ | 885 | /*========== Parameter extraction helper */ |
882 | 886 | ||
883 | CHAR *MD_GetAtom(CHAR *atomname,CHAR *cmdline,int implicit) | 887 | CHAR *MD_GetAtom(const CHAR *atomname, const CHAR *cmdline, int implicit) |
884 | { | 888 | { |
885 | CHAR *ret=NULL; | 889 | CHAR *ret=NULL; |
886 | 890 | ||
887 | if(cmdline) { | 891 | if(cmdline) { |
888 | CHAR *buf=strstr(cmdline,atomname); | 892 | const CHAR *buf=strstr(cmdline,atomname); |
889 | 893 | ||
890 | if((buf)&&((buf==cmdline)||(*(buf-1)==','))) { | 894 | if((buf)&&((buf==cmdline)||(*(buf-1)==','))) { |
891 | CHAR *ptr=buf+strlen(atomname); | 895 | const CHAR *ptr=buf+strlen(atomname); |
892 | 896 | ||
893 | if(*ptr=='=') { | 897 | if(*ptr=='=') { |
894 | for(buf=++ptr;(*ptr)&&((*ptr)!=',');ptr++); | 898 | for(buf=++ptr;(*ptr)&&((*ptr)!=',');ptr++); |
895 | ret=MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); | 899 | ret=(CHAR *)MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); |
896 | if(ret) | 900 | if(ret) |
897 | strncpy(ret,buf,ptr-buf); | 901 | strncpy(ret,buf,ptr-buf); |
898 | } else if((*ptr==',')||(!*ptr)) { | 902 | } else if((*ptr==',')||(!*ptr)) { |
899 | if(implicit) { | 903 | if(implicit) { |
900 | ret=MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); | 904 | ret=(CHAR *)MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); |
901 | if(ret) | 905 | if(ret) |
902 | strncpy(ret,buf,ptr-buf); | 906 | strncpy(ret,buf,ptr-buf); |
903 | } | 907 | } |
@@ -907,8 +911,7 @@ CHAR *MD_GetAtom(CHAR *atomname,CHAR *cmdline,int implicit) | |||
907 | return ret; | 911 | return ret; |
908 | } | 912 | } |
909 | 913 | ||
910 | #if 0 | 914 | #if (MIKMOD_UNIX) |
911 | #if defined unix || (defined __APPLE__ && defined __MACH__) | ||
912 | 915 | ||
913 | /*========== Posix helper functions */ | 916 | /*========== Posix helper functions */ |
914 | 917 | ||
@@ -917,7 +920,7 @@ CHAR *MD_GetAtom(CHAR *atomname,CHAR *cmdline,int implicit) | |||
917 | reasonable. Returns 1 if it is safe to rewrite the file, 0 otherwise. | 920 | reasonable. Returns 1 if it is safe to rewrite the file, 0 otherwise. |
918 | The goal is to prevent a setuid root libmikmod application from overriding | 921 | The goal is to prevent a setuid root libmikmod application from overriding |
919 | files like /etc/passwd with digital sound... */ | 922 | files like /etc/passwd with digital sound... */ |
920 | int MD_Access(CHAR *filename) | 923 | int MD_Access(const CHAR * filename) |
921 | { | 924 | { |
922 | struct stat buf; | 925 | struct stat buf; |
923 | 926 | ||
@@ -934,7 +937,7 @@ int MD_Access(CHAR *filename) | |||
934 | } else | 937 | } else |
935 | if(!(buf.st_mode&S_IWOTH)) return 0; | 938 | if(!(buf.st_mode&S_IWOTH)) return 0; |
936 | } | 939 | } |
937 | 940 | ||
938 | return 1; | 941 | return 1; |
939 | } | 942 | } |
940 | 943 | ||
@@ -961,5 +964,5 @@ int MD_DropPrivileges(void) | |||
961 | } | 964 | } |
962 | 965 | ||
963 | #endif | 966 | #endif |
964 | #endif | 967 | |
965 | /* ex:set ts=4: */ | 968 | /* ex:set ts=8: */ |