This repository was archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfmod.c
More file actions
executable file
·149 lines (135 loc) · 3.53 KB
/
fmod.c
File metadata and controls
executable file
·149 lines (135 loc) · 3.53 KB
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
#ifdef USE_SOUND
/*===============================================================================================
These functions were derived from the FMOD library.
It is copyrighted material, but free for personal use.
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.
See other sample programs in the fmod /examples directory
===============================================================================================*/
//The following paths are consistent with the fmod download/example paths.
//They can be changed if you place the header and library files
//in another area.
//For instance, directories you already have established
//for your personal project.
//
//#include "../../api/inc/fmod.h"
//#include "../../api/inc/fmod_errors.h"
#include "definitions.h"
#include "./include/FMOD/fmod.h"
#include "./include/FMOD/fmod_errors.h"
#include "./include/FMOD/fmod_errors.h"
#include <stdio.h>
#include "fmod.h"
//local global variables are defined here
#define MAX_SOUNDS 64
FMOD_SYSTEM *xsystem;
FMOD_SOUND *sound[MAX_SOUNDS];
FMOD_CHANNEL *channel = 0;
static int nsounds=10;
int ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK) {
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
return 1;
}
return 0;
}
int fmod_init(void)
{
FMOD_RESULT result;
unsigned int version;
//printf("fmod_init()...\n");
result = FMOD_System_Create(&xsystem);
if (ERRCHECK(result)) return 1;
result = FMOD_System_GetVersion(xsystem, &version);
if (ERRCHECK(result)) return 1;
if (version < FMOD_VERSION) {
printf("Error! Old version of FMOD %08x.\n", version);
printf("This program requires %08x\n", FMOD_VERSION);
return 1;
}
result = FMOD_System_Init(xsystem, 32, FMOD_INIT_NORMAL, NULL);
if (ERRCHECK(result)) return 1;
return 0;
}
int fmod_createsound(char *fname, int i)
{
FMOD_RESULT result;
//printf("fmod_createsound(**%s**, %i)...\n",fname,i);
if (nsounds >= MAX_SOUNDS)
return 0;
result = FMOD_System_CreateSound(xsystem, fname, FMOD_SOFTWARE, 0, &sound[i]);
if (ERRCHECK(result)) {
printf("error fmod_createsound()\n");
return 1;
}
++nsounds;
return 0;
}
int fmod_playsound(int i)
{
FMOD_RESULT result;
//printf("fmod_playsound(%i)...\n",i);
result = FMOD_System_PlaySound(xsystem, FMOD_CHANNEL_FREE, sound[i], 0, &channel);
if (ERRCHECK(result)) {
printf("error fmod_playsound()\n");
return 1;
}
return 0;
}
int fmod_setmode(int i, int mode)
{
FMOD_RESULT result;
//printf("fmod_setmode()...\n");
//result = FMOD_Sound_SetMode(sound[i], FMOD_LOOP_OFF);
result = FMOD_Sound_SetMode(sound[i], mode);
if (ERRCHECK(result)) {
printf("error fmod_setmode()\n");
return 1;
}
return 0;
}
int fmod_getlength(int i, unsigned int *lenms)
{
FMOD_RESULT result;
result = FMOD_Sound_GetLength(sound[i], lenms, FMOD_TIMEUNIT_MS);
if (ERRCHECK(result)) {
printf("error fmod_getlength()\n");
return 1;
}
return 0;
}
int fmod_systemupdate(void)
{
FMOD_System_Update(xsystem);
return 0;
}
int fmod_getchannelsplaying(int *channelsplaying)
{
FMOD_System_GetChannelsPlaying(xsystem, channelsplaying);
return 0;
}
int fmod_cleanup(void)
{
int i;
FMOD_RESULT result;
for (i=0; i<nsounds; i++) {
result = FMOD_Sound_Release(sound[i]);
if (ERRCHECK(result))
return 1;
}
result = FMOD_System_Close(xsystem);
if (ERRCHECK(result)) return 1;
result = FMOD_System_Release(xsystem);
if (ERRCHECK(result)) return 1;
return 0;
}
int fmod_releasesound(int s) {
FMOD_Sound_Release(sound[s]);
nsounds--;
return 0;
}
int fmod_stopAll(void) {
FMOD_Channel_Stop(channel);
return 0;
}
#endif