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