| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
|
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
3
|
|
|
|
|
|
|
#include "perl.h" |
|
4
|
|
|
|
|
|
|
#include "XSUB.h" |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#define TSF_IMPLEMENTATION |
|
7
|
|
|
|
|
|
|
#define TSF_STATIC |
|
8
|
|
|
|
|
|
|
#include "TinySoundFont/tsf.h" |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
typedef tsf* Audio__TinySoundFont__XS; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#define SAMPLE_RATE 44100 |
|
13
|
|
|
|
|
|
|
|
|
14
|
331
|
|
|
|
|
|
static int atsf_perlio_read(PerlIO* f, void* ptr, unsigned int size) |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
|
|
|
|
|
|
dTHX; |
|
17
|
331
|
|
|
|
|
|
return (int)PerlIO_read(f, ptr, size); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
|
static int atsf_perlio_skip(PerlIO* f, unsigned int count) |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
|
|
|
|
|
|
dTHX; |
|
23
|
3
|
|
|
|
|
|
return !PerlIO_seek(f, count, SEEK_CUR); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
MODULE = Audio::TinySoundFont PACKAGE = Audio::TinySoundFont::XS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
BOOT: |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
8
|
|
|
|
|
|
HV *stash = gv_stashpv("Audio::TinySoundFont::XS", 0); |
|
31
|
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
|
newCONSTSUB(stash, "SAMPLE_RATE", newSViv(SAMPLE_RATE)); |
|
33
|
8
|
|
|
|
|
|
newCONSTSUB(stash, "MONO", newSViv(TSF_MONO)); |
|
34
|
8
|
|
|
|
|
|
newCONSTSUB(stash, "STEREO_INTERLEAVED", newSViv(TSF_STEREO_INTERLEAVED)); |
|
35
|
8
|
|
|
|
|
|
newCONSTSUB(stash, "STEREO_UNWEAVED", newSViv(TSF_STEREO_UNWEAVED)); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Audio::TinySoundFont::XS |
|
39
|
|
|
|
|
|
|
load_file(CLASS, filename) |
|
40
|
|
|
|
|
|
|
SV *CLASS = NO_INIT |
|
41
|
|
|
|
|
|
|
const char* filename |
|
42
|
|
|
|
|
|
|
CODE: |
|
43
|
11
|
|
|
|
|
|
RETVAL = tsf_load_filename(filename); |
|
44
|
11
|
100
|
|
|
|
|
if ( RETVAL == NULL ) |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
1
|
|
|
|
|
|
croak("Unable to load file: %s\n", filename); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
10
|
|
|
|
|
|
tsf_set_output(RETVAL, TSF_MONO, SAMPLE_RATE, -10); |
|
49
|
|
|
|
|
|
|
OUTPUT: |
|
50
|
|
|
|
|
|
|
RETVAL |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Audio::TinySoundFont::XS |
|
53
|
|
|
|
|
|
|
load_fh(CLASS, fh) |
|
54
|
|
|
|
|
|
|
SV *CLASS = NO_INIT |
|
55
|
|
|
|
|
|
|
PerlIO* fh |
|
56
|
|
|
|
|
|
|
CODE: |
|
57
|
4
|
|
|
|
|
|
struct tsf_stream stream = { |
|
58
|
|
|
|
|
|
|
fh, |
|
59
|
|
|
|
|
|
|
(int(*)(void*,void*,unsigned int))&atsf_perlio_read, |
|
60
|
|
|
|
|
|
|
(int(*)(void*,unsigned int))&atsf_perlio_skip |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
4
|
|
|
|
|
|
RETVAL = tsf_load(&stream); |
|
63
|
4
|
100
|
|
|
|
|
if ( RETVAL == NULL ) |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
1
|
|
|
|
|
|
croak("Unable to load: %p\n", fh); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
3
|
|
|
|
|
|
tsf_set_output(RETVAL, TSF_MONO, SAMPLE_RATE, -10); |
|
68
|
|
|
|
|
|
|
OUTPUT: |
|
69
|
|
|
|
|
|
|
RETVAL |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
int |
|
72
|
|
|
|
|
|
|
presetcount(self) |
|
73
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
74
|
|
|
|
|
|
|
CODE: |
|
75
|
12
|
|
|
|
|
|
RETVAL = tsf_get_presetcount(self); |
|
76
|
|
|
|
|
|
|
OUTPUT: |
|
77
|
|
|
|
|
|
|
RETVAL |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
const char* |
|
80
|
|
|
|
|
|
|
get_presetname(self, preset_idx) |
|
81
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
82
|
|
|
|
|
|
|
int preset_idx |
|
83
|
|
|
|
|
|
|
CODE: |
|
84
|
39
|
|
|
|
|
|
RETVAL = tsf_get_presetname(self, preset_idx); |
|
85
|
|
|
|
|
|
|
OUTPUT: |
|
86
|
|
|
|
|
|
|
RETVAL |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
int |
|
89
|
|
|
|
|
|
|
active_voices(self) |
|
90
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
91
|
|
|
|
|
|
|
CODE: |
|
92
|
121
|
|
|
|
|
|
RETVAL = tsf_active_voice_count(self); |
|
93
|
|
|
|
|
|
|
OUTPUT: |
|
94
|
|
|
|
|
|
|
RETVAL |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
void |
|
97
|
|
|
|
|
|
|
set_volume(self, global_gain); |
|
98
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
99
|
|
|
|
|
|
|
float global_gain |
|
100
|
|
|
|
|
|
|
CODE: |
|
101
|
57
|
|
|
|
|
|
global_gain = global_gain < 0 ? 0 |
|
102
|
112
|
100
|
|
|
|
|
: global_gain > 1 ? 1 |
|
103
|
55
|
100
|
|
|
|
|
: global_gain; |
|
104
|
57
|
|
|
|
|
|
tsf_set_volume(self, global_gain); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
void |
|
107
|
|
|
|
|
|
|
note_on(self, preset_idx, note, velocity) |
|
108
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
109
|
|
|
|
|
|
|
int preset_idx |
|
110
|
|
|
|
|
|
|
int note |
|
111
|
|
|
|
|
|
|
float velocity |
|
112
|
|
|
|
|
|
|
CODE: |
|
113
|
57
|
|
|
|
|
|
tsf_note_on(self, preset_idx, note, velocity); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
void |
|
116
|
|
|
|
|
|
|
note_off(self, preset_idx, note) |
|
117
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
118
|
|
|
|
|
|
|
int preset_idx |
|
119
|
|
|
|
|
|
|
int note |
|
120
|
|
|
|
|
|
|
CODE: |
|
121
|
55
|
|
|
|
|
|
tsf_note_off(self, preset_idx, note); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
SV * |
|
124
|
|
|
|
|
|
|
render(self, samples) |
|
125
|
|
|
|
|
|
|
Audio::TinySoundFont::XS self |
|
126
|
|
|
|
|
|
|
int samples |
|
127
|
|
|
|
|
|
|
CODE: |
|
128
|
100
|
|
|
|
|
|
int slen = samples * sizeof(short); |
|
129
|
100
|
100
|
|
|
|
|
if ( slen == 0 ) |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
10
|
|
|
|
|
|
XSRETURN_PV(""); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
90
|
|
|
|
|
|
RETVAL = newSV(slen); |
|
134
|
90
|
|
|
|
|
|
SvCUR_set(RETVAL, slen); |
|
135
|
90
|
|
|
|
|
|
SvPOK_only(RETVAL); |
|
136
|
|
|
|
|
|
|
STRLEN len; |
|
137
|
|
|
|
|
|
|
short* buffer; |
|
138
|
90
|
|
|
|
|
|
buffer = (short *)SvPVX(RETVAL); |
|
139
|
90
|
|
|
|
|
|
tsf_render_short(self, buffer, samples, 0); |
|
140
|
90
|
|
|
|
|
|
*(SvEND(RETVAL)) = '\0'; |
|
141
|
|
|
|
|
|
|
OUTPUT: |
|
142
|
|
|
|
|
|
|
RETVAL |