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
150
151
152
153
154
|
/*
DeaDBeeF - ultimate music player for GNU/Linux systems with X11
Copyright (C) 2009 Alexey Yakovenko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mikmod.h>
#include <string.h>
#include "codec.h"
#include "cmod.h"
static char *mikmod_writepointer;
static int mikmod_writesize;
static MODULE *module;
// mikmod fe driver
static BOOL cmod_IsThere(void)
{
return 1;
}
static BOOL cmod_Init(void)
{
return VC_Init();
}
static void cmod_Exit(void)
{
VC_Exit();
}
static void cmod_Update(void)
{
for (;;) {
ULONG ret = VC_WriteBytes((SBYTE*)mikmod_writepointer,(ULONG)mikmod_writesize);
if (ret < mikmod_writesize)
{
if (ret <= 0) {
printf ("WARNING: mikmod VC_WriteBytes returned %d, trying rewind\n", ret);
Player_SetPosition (0);
break;
}
else {
mikmod_writesize -= ret;
mikmod_writepointer += ret;
}
}
else if (ret > mikmod_writesize) {
printf ("WARNING: mikmod VC_WriteBytes returned %d, trying rewind\n", ret);
Player_SetPosition (0);
}
break;
}
}
static void cmod_PlayStop(void)
{
fprintf (stderr, "mikmod called PlayStop\n");
VC_PlayStop();
}
static MDRIVER cmoddrv={
NULL,
(char*)"raboof",
(char*)"raboof mikmod audio driver v0.1",
0,255,
(char*)"cmoddrv",
NULL,
cmod_IsThere,
VC_SampleLoad,
VC_SampleUnload,
VC_SampleSpace,
VC_SampleLength,
cmod_Init,
cmod_Exit,
NULL,
VC_SetNumVoices,
VC_PlayStart,
cmod_PlayStop,
cmod_Update,
NULL,
VC_VoiceSetVolume,
VC_VoiceGetVolume,
VC_VoiceSetFrequency,
VC_VoiceGetFrequency,
VC_VoiceSetPanning,
VC_VoiceGetPanning,
VC_VoicePlay,
VC_VoiceStop,
VC_VoiceStopped,
VC_VoiceGetPosition,
VC_VoiceRealVolume
};
int
cmod_init (const char *fname, int track, float start, float end) {
// MikMod_RegisterAllDrivers();
memset (&cmod.info, 0, sizeof (fileinfo_t));
MikMod_RegisterAllLoaders();
MikMod_RegisterDriver (&cmoddrv);
int drv = MikMod_DriverFromAlias ((char*)"cmoddrv");
md_device = drv;
md_mode |= DMODE_HQMIXER;
MikMod_Init((char*)"");
module = Player_Load ((char*)fname, 64, 0);
module->wrap = 1;
module->loop = 0;
Player_Start(module);
Player_SetTempo (1200);
printf ("module info: songname %s\nmodtype %s\ncomment %s\nnumchannels %d\nnumsamples %d\nsongtime %d\n", module->songname, module->modtype, module->comment, module->numchn, module->numsmp, module->sngtime);
printf ("driver info: device %d\nmixfreq: %d\n16bit %d\nhqmixer %d\nstereo %d\n", md_device, md_mixfreq, (md_mode&DMODE_16BITS)?1:0, (md_mode&DMODE_HQMIXER)?1:0, (md_mode&DMODE_STEREO)?1:0);
cmod.info.bitsPerSample = (md_mode&DMODE_16BITS)? 16 : 8;
cmod.info.channels = (md_mode&DMODE_STEREO)?2:1;
cmod.info.samplesPerSecond = md_mixfreq;
return 0;
}
void
cmod_free (void) {
Player_SetPosition (0);
Player_Free(module);
module = NULL;
MikMod_Exit();
}
int
cmod_read (char *bytes, int size)
{
mikmod_writepointer = bytes;
mikmod_writesize = size;
if (Player_Active()) {
MikMod_Update();
}
return 0;
}
codec_t cmod = {
.init = cmod_init,
.free = cmod_free,
.read = cmod_read
};
|