nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -2
- data/.gitmodules +3 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +17 -2
- data/LICENSE +21 -0
- data/README.md +115 -44
- data/Rakefile +2 -6
- data/bytecode/{Commands.md → _docs/commands.md} +0 -0
- data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
- data/bytecode/_docs/grammar.pdf +0 -0
- data/bytecode/{src → _original}/README.md +0 -0
- data/bytecode/{src → _original}/lib/arp.mtl +0 -0
- data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
- data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
- data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
- data/bytecode/{src → _original}/lib/dns.mtl +0 -0
- data/bytecode/{src → _original}/lib/http.mtl +0 -0
- data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
- data/bytecode/{src → _original}/lib/udp.mtl +0 -0
- data/bytecode/{src → _original}/lib/util.mtl +0 -0
- data/bytecode/{src → _original}/lib/var.mtl +0 -0
- data/bytecode/{src → _original}/lib/wav.mtl +0 -0
- data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
- data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
- data/bytecode/main.mtl +11 -11
- data/bytecode/test/test.mtl +8 -8
- data/examples/basic/Gemfile +1 -3
- data/examples/basic/config.ru +14 -4
- data/examples/record/Gemfile +0 -5
- data/examples/record/{config.ru.example → config.ru} +2 -2
- data/examples/record/server.rb +0 -2
- data/ext/Makefile +10 -0
- data/ext/bin/mtl_comp +29 -0
- data/{bytecode → ext}/bin/mtl_merge +0 -0
- data/ext/bin/mtl_simu +29 -0
- data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
- data/ext/mtl_linux/.gitignore +7 -0
- data/ext/mtl_linux/LICENSE +21 -0
- data/ext/mtl_linux/Makefile +116 -0
- data/ext/mtl_linux/MetalC.project +196 -0
- data/ext/mtl_linux/conf.bin +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
- data/ext/mtl_linux/inc/log.h +21 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
- data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
- data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
- data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
- data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
- data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
- data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
- data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
- data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
- data/ext/mtl_linux/nominal.mtl +3959 -0
- data/ext/mtl_linux/src/comp/main.cpp +123 -0
- data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
- data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
- data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
- data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
- data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
- data/ext/mtl_linux/src/simu/log.c +340 -0
- data/ext/mtl_linux/src/simu/properties.c +368 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
- data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
- data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
- data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
- data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
- data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
- data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
- data/ext/mtl_linux/src/simu/win/simu.c +819 -0
- data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
- data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
- data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
- data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
- data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
- data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
- data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
- data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
- data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
- data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
- data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
- data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
- data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
- data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
- data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
- data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
- data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
- data/ext/mtl_linux/src/vm/vaudio.c +830 -0
- data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
- data/ext/mtl_linux/src/vm/vloader.c +139 -0
- data/ext/mtl_linux/src/vm/vlog.c +782 -0
- data/ext/mtl_linux/src/vm/vmem.c +461 -0
- data/ext/mtl_linux/src/vm/vnet.c +298 -0
- data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
- data/lib/nabaztag_hack_kit/server.rb +4 -7
- data/lib/nabaztag_hack_kit/version.rb +1 -1
- data/lib/nabaztag_hack_kit.rb +2 -2
- data/nabaztag_hack_kit.gemspec +10 -11
- data/spec/integration/server_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/message_spec.rb +12 -18
- data/spec/unit/server_spec.rb +13 -10
- metadata +145 -137
- data/bytecode/bin/mtl_comp +0 -50
- data/bytecode/bin/mtl_simu +0 -49
- data/bytecode/src/mtl/Makefile +0 -42
- data/bytecode/src/mtl/README.md +0 -13
- data/bytecode/src/mtl/bc.cpp +0 -1891
- data/bytecode/src/mtl/dumpbc.c +0 -2566
- data/bytecode/src/mtl/linux_simu.c +0 -271
- data/bytecode/src/mtl/linux_simuaudio.c +0 -16
- data/bytecode/src/mtl/linux_simunet.c +0 -620
- data/bytecode/src/mtl/log.c +0 -297
- data/bytecode/src/mtl/log.h +0 -20
- data/bytecode/src/mtl/main_compiler.cpp +0 -104
- data/bytecode/src/mtl/main_simu.cpp +0 -221
- data/bytecode/src/mtl/mp3/common.c +0 -265
- data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
- data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
- data/bytecode/src/mtl/mp3/huffman.h +0 -332
- data/bytecode/src/mtl/mp3/interface.c +0 -258
- data/bytecode/src/mtl/mp3/mpglib.h +0 -44
- data/bytecode/src/mtl/properties.c +0 -293
- data/bytecode/src/mtl/simu.c +0 -750
- data/bytecode/src/mtl/simuaudio.c +0 -662
- data/bytecode/src/mtl/simunet.c +0 -400
- data/bytecode/src/mtl/vaudio.c +0 -677
- data/bytecode/src/mtl/vbc_str.h +0 -166
- data/bytecode/src/mtl/vcomp/Makefile +0 -29
- data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
- data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
- data/bytecode/src/mtl/vcomp/compiler.h +0 -200
- data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
- data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
- data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
- data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
- data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
- data/bytecode/src/mtl/vcomp/file.cpp +0 -79
- data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
- data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
- data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
- data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
- data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
- data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
- data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
- data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
- data/bytecode/src/mtl/vinterp.c +0 -1349
- data/bytecode/src/mtl/vloader.c +0 -127
- data/bytecode/src/mtl/vlog.c +0 -589
- data/bytecode/src/mtl/vmem.c +0 -424
- data/bytecode/src/mtl/vnet.c +0 -255
- data/examples/basic/Procfile +0 -2
- data/examples/basic/server.rb +0 -14
@@ -1,662 +0,0 @@
|
|
1
|
-
// Librairie Sound
|
2
|
-
|
3
|
-
#include<stdio.h>
|
4
|
-
#include<stdlib.h>
|
5
|
-
#include<string.h>
|
6
|
-
#include<time.h>
|
7
|
-
|
8
|
-
#include <commctrl.h>
|
9
|
-
#include <commdlg.h>
|
10
|
-
#include <mmsystem.h>
|
11
|
-
|
12
|
-
#include "mp3/mpg123.h"
|
13
|
-
#include "mp3/mpglib.h"
|
14
|
-
|
15
|
-
|
16
|
-
#include "simuaudio.h"
|
17
|
-
#include "vaudio.h"
|
18
|
-
|
19
|
-
HWAVEOUT hWaveOut;
|
20
|
-
HWAVEIN hWaveIn;
|
21
|
-
|
22
|
-
int nPlayBuffers;
|
23
|
-
WaveOutBuffer* WaveOutBuf;
|
24
|
-
int PlayState;
|
25
|
-
int PlayStateEof;
|
26
|
-
int PlayType;
|
27
|
-
|
28
|
-
int nRecBuffers;
|
29
|
-
WaveInBuffer* WaveInBuf;
|
30
|
-
int SendInBuffers;
|
31
|
-
BOOL StopRecord;
|
32
|
-
BOOL RecordInitialised;
|
33
|
-
|
34
|
-
#define PLAYST_IDLE 0
|
35
|
-
#define PLAYST_START 1
|
36
|
-
#define PLAYST_PLAY 2
|
37
|
-
|
38
|
-
#define PLAYTYPE_MP3 0
|
39
|
-
#define PLAYTYPE_WAV 1
|
40
|
-
#define PLAYTYPE_ADPCM 2
|
41
|
-
|
42
|
-
struct mpstr mp;
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#define BUFMP3OUT_LENGTH 65536
|
47
|
-
#define BUFMP3IN_LENGTH 65536
|
48
|
-
|
49
|
-
char bufplayout[BUFMP3OUT_LENGTH];
|
50
|
-
int bufplayout_i;
|
51
|
-
char bufplayin[BUFMP3IN_LENGTH];
|
52
|
-
int bufplaystart;
|
53
|
-
|
54
|
-
void mp3simuinit()
|
55
|
-
{
|
56
|
-
InitMP3(&mp);
|
57
|
-
bufplayout_i=0;
|
58
|
-
bufplaystart=0;
|
59
|
-
}
|
60
|
-
|
61
|
-
char bufmp3[4608];
|
62
|
-
|
63
|
-
// mono : a b -> aaaa bbbb
|
64
|
-
// stereo : a b -> abababab
|
65
|
-
|
66
|
-
void mp3scale(short *src,int len,short *dst,int freq,int lsf,int stereo,int dstlen)
|
67
|
-
{
|
68
|
-
if (stereo==2)
|
69
|
-
{
|
70
|
-
if (len==dstlen) memcpy((char*)dst,(char*)src,len);
|
71
|
-
}
|
72
|
-
if (stereo==1)
|
73
|
-
{
|
74
|
-
int i;
|
75
|
-
// int k=dstlen/len;
|
76
|
-
dstlen/=2;
|
77
|
-
len/=2;
|
78
|
-
for(i=0;i<len;i++)
|
79
|
-
{
|
80
|
-
int j;
|
81
|
-
int k=(i+1)*dstlen/len;
|
82
|
-
for(j=i*dstlen/len;j<k;j++) *(dst++)=*src;
|
83
|
-
src++;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
void wavscale(short *src,int len,short *dst)
|
89
|
-
{
|
90
|
-
int i;
|
91
|
-
len/=2;
|
92
|
-
for(i=0;i<len;i++)
|
93
|
-
{
|
94
|
-
int j;
|
95
|
-
for(j=0;j<10;j++) *(dst++)=*src;
|
96
|
-
src++;
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
int getmp3len(int freq)
|
101
|
-
{
|
102
|
-
if (freq==16000) return 4608*44100/32000;
|
103
|
-
return 4608;
|
104
|
-
}
|
105
|
-
|
106
|
-
void simuFetchMP3(int ask)
|
107
|
-
{
|
108
|
-
int dstlen;
|
109
|
-
int len;
|
110
|
-
int ret;
|
111
|
-
int loop=1;
|
112
|
-
|
113
|
-
while((loop)&&(bufplayout_i<ask))
|
114
|
-
{
|
115
|
-
ret = decodeMP3(&mp,NULL,0,bufmp3,4608,&len);
|
116
|
-
if (ret==MP3_OK)
|
117
|
-
{
|
118
|
-
|
119
|
-
// printf("freq=%d lsf=%d stereo=%d -> %d\n",freqs[mp.fr.sampling_frequency],mp.fr.lsf,mp.fr.stereo,len);
|
120
|
-
dstlen=getmp3len(freqs[mp.fr.sampling_frequency]);
|
121
|
-
mp3scale((short*)bufmp3,len,bufplayout+bufplayout_i,freqs[mp.fr.sampling_frequency],mp.fr.lsf,mp.fr.stereo,dstlen);
|
122
|
-
bufplayout_i+=dstlen;
|
123
|
-
}
|
124
|
-
else
|
125
|
-
{
|
126
|
-
len=audioPlayFetch(bufplayin+bufplaystart,BUFMP3IN_LENGTH-bufplaystart);
|
127
|
-
len+=bufplaystart;
|
128
|
-
// printf("simuFetchWav get=%d\n",len);
|
129
|
-
if (len)
|
130
|
-
{
|
131
|
-
bufplaystart=0;
|
132
|
-
ret = decodeMP3(&mp,bufplayin,len,bufmp3,4608,&len);
|
133
|
-
if (ret==MP3_OK)
|
134
|
-
{
|
135
|
-
// printf("freq=%d lsf=%d stereo=%d -> %d\n",freqs[mp.fr.sampling_frequency],mp.fr.lsf,mp.fr.stereo,len);
|
136
|
-
dstlen=getmp3len(freqs[mp.fr.sampling_frequency]);
|
137
|
-
mp3scale(bufmp3,len,bufplayout+bufplayout_i,freqs[mp.fr.sampling_frequency],mp.fr.lsf,mp.fr.stereo,dstlen);
|
138
|
-
bufplayout_i+=dstlen;
|
139
|
-
}
|
140
|
-
}
|
141
|
-
else loop=0;
|
142
|
-
}
|
143
|
-
};
|
144
|
-
}
|
145
|
-
|
146
|
-
void simuFetchWav(int ask)
|
147
|
-
{
|
148
|
-
int len;
|
149
|
-
int loop=1;
|
150
|
-
int askwav=2+(((ask-bufplayout_i)/10)&(-2));
|
151
|
-
|
152
|
-
while((loop)&&(bufplaystart<askwav))
|
153
|
-
{
|
154
|
-
len=audioPlayFetch(bufplayin+bufplaystart,askwav-bufplaystart);
|
155
|
-
printf("simuFetchWav get=%d\n",len);
|
156
|
-
if (len) bufplaystart+=len;
|
157
|
-
else loop=0;
|
158
|
-
}
|
159
|
-
|
160
|
-
len=bufplaystart&(-2);
|
161
|
-
if (len>=askwav) len=askwav;
|
162
|
-
|
163
|
-
wavscale(bufplayin,len,bufplayout+bufplayout_i);
|
164
|
-
bufplayout_i+=len*10;
|
165
|
-
if (bufplaystart!=len)
|
166
|
-
{
|
167
|
-
memcpy(bufplayin,bufplayin+len,bufplaystart-len);
|
168
|
-
bufplaystart-=len;
|
169
|
-
}
|
170
|
-
else bufplaystart=0;
|
171
|
-
}
|
172
|
-
|
173
|
-
void simuFetchAdpcm(int ask)
|
174
|
-
{
|
175
|
-
printf("simuFetchAdpcm %d\n",ask);
|
176
|
-
while(bufplayout_i<ask)
|
177
|
-
{
|
178
|
-
if (bufplaystart<256) bufplaystart+=audioPlayFetch(bufplayin+bufplaystart,256-bufplaystart);
|
179
|
-
if (bufplaystart<256) return;
|
180
|
-
|
181
|
-
adpcmdecode(bufplayin,bufmp3);
|
182
|
-
wavscale(bufmp3,1010,bufplayout+bufplayout_i);
|
183
|
-
bufplayout_i+=1010*10;
|
184
|
-
bufplaystart-=256;
|
185
|
-
memcpy(bufplayin,bufplayin+256,bufplaystart);
|
186
|
-
}
|
187
|
-
}
|
188
|
-
|
189
|
-
int simuFetchPlay(char* dst,int ask)
|
190
|
-
{
|
191
|
-
// printf("simuFetchPlay %d\n",PlayType);
|
192
|
-
|
193
|
-
if (PlayType==PLAYTYPE_MP3)simuFetchMP3(ask);
|
194
|
-
if (PlayType==PLAYTYPE_WAV)simuFetchWav(ask);
|
195
|
-
if (PlayType==PLAYTYPE_ADPCM)simuFetchAdpcm(ask);
|
196
|
-
// printf("bufplayout_i=%d\n",bufplayout_i);
|
197
|
-
if (bufplayout_i<ask) ask=bufplayout_i;
|
198
|
-
if ((PlayStateEof)&&(!bufplayout_i)) PlayState=PLAYST_IDLE;
|
199
|
-
if (!ask) return 0;
|
200
|
-
|
201
|
-
memcpy(dst,bufplayout,ask);
|
202
|
-
memcpy(bufplayout,bufplayout+ask,bufplayout_i-ask);
|
203
|
-
bufplayout_i-=ask;
|
204
|
-
return ask;
|
205
|
-
}
|
206
|
-
|
207
|
-
void simuFetchStart()
|
208
|
-
{
|
209
|
-
while(1)
|
210
|
-
{
|
211
|
-
int len=BUFMP3IN_LENGTH-bufplaystart;
|
212
|
-
if (len) len=audioPlayFetch(bufplayin+bufplaystart,len);
|
213
|
-
printf("simuFetchStart get=%d\n",len);
|
214
|
-
|
215
|
-
if (!len)
|
216
|
-
{
|
217
|
-
if (PlayStateEof) PlayState=PLAYST_IDLE;
|
218
|
-
return;
|
219
|
-
}
|
220
|
-
bufplaystart+=len;
|
221
|
-
|
222
|
-
if (1)//(((bufplaystart>=2)&&(bufplayin[0]=='I')&&(bufplayin[1]=='D')&&(bufplayin[2]=='3')) ||((bufplayin[0]&255)==255))
|
223
|
-
{
|
224
|
-
int i=0;
|
225
|
-
int head=0;
|
226
|
-
PlayType=PLAYTYPE_MP3;
|
227
|
-
printf("detect MP3\n");
|
228
|
-
PlayState=PLAYST_PLAY;
|
229
|
-
return;
|
230
|
-
|
231
|
-
/* while((i<bufplaystart)&&(!checkmp3header(head)))
|
232
|
-
{
|
233
|
-
head=(head<<8)+(bufplayin[i++]&255);
|
234
|
-
}
|
235
|
-
if (i<bufplaystart)
|
236
|
-
{
|
237
|
-
int j;
|
238
|
-
printf("detect start at %d\n",i);
|
239
|
-
i-=4;
|
240
|
-
len=bufplaystart-i;
|
241
|
-
for(j=0;j<len;j++) bufplayin[j]=bufplayin[j+i];
|
242
|
-
bufplaystart=len;
|
243
|
-
PlayState=PLAYST_PLAY;
|
244
|
-
return;
|
245
|
-
}
|
246
|
-
*/ }
|
247
|
-
else if ((bufplaystart>20)&&(bufplayin[0]=='R')&&(bufplayin[1]=='I')&&(bufplayin[2]=='F'))
|
248
|
-
{
|
249
|
-
int i;
|
250
|
-
printf("detect wav bufplaystart=%d\n",bufplaystart);
|
251
|
-
PlayType=(bufplayin[20]==0x11)?PLAYTYPE_ADPCM:PLAYTYPE_WAV;
|
252
|
-
for(i=0;i<bufplaystart-8;i++) if (!strncmp(bufplayin+i,"data",4))
|
253
|
-
{
|
254
|
-
int j;
|
255
|
-
i+=8;
|
256
|
-
len=bufplaystart-i;
|
257
|
-
for(j=0;j<len;j++) bufplayin[j]=bufplayin[j+i];
|
258
|
-
bufplaystart=len;
|
259
|
-
PlayState=PLAYST_PLAY;
|
260
|
-
return;
|
261
|
-
}
|
262
|
-
}
|
263
|
-
}
|
264
|
-
}
|
265
|
-
|
266
|
-
int simuFetch(char* dst,int ask)
|
267
|
-
{
|
268
|
-
// printf("simuFetch %d\n",PlayState);
|
269
|
-
if (PlayState==PLAYST_IDLE) return 0;
|
270
|
-
if (PlayState==PLAYST_START) simuFetchStart();
|
271
|
-
if (PlayState==PLAYST_PLAY) return simuFetchPlay(dst,ask);
|
272
|
-
return 0;
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
extern HWND mainwin;
|
277
|
-
|
278
|
-
int OutFillBuffer(int i)
|
279
|
-
{
|
280
|
-
int k,len;
|
281
|
-
|
282
|
-
if (WaveOutBuf[i].lpData==NULL) return 0;
|
283
|
-
k=simuFetch(WaveOutBuf[i].lpData,WaveOutBuf[i].dwDataSize);
|
284
|
-
// printf("#outfill\n");
|
285
|
-
len=WaveOutBuf[i].dwDataSize-k;
|
286
|
-
if (len>0) memset(WaveOutBuf[i].lpData+k,0,len);
|
287
|
-
|
288
|
-
return 0;
|
289
|
-
}
|
290
|
-
int InFillBuffer(int i)
|
291
|
-
{
|
292
|
-
char *p;
|
293
|
-
|
294
|
-
if (WaveInBuf[i].lpData==NULL) return 0;
|
295
|
-
|
296
|
-
p=audioRecFeed_begin(256);
|
297
|
-
adpcmencode(WaveInBuf[i].lpData,p);
|
298
|
-
/* p=audioRecFeed_begin(WaveInBuf[i].dwDataSize);
|
299
|
-
memcpy(p,WaveInBuf[i].lpData,WaveInBuf[i].dwDataSize);
|
300
|
-
*/ audioRecFeed_end();
|
301
|
-
|
302
|
-
return 0;
|
303
|
-
}
|
304
|
-
|
305
|
-
void WaveOutFreeAll()
|
306
|
-
{
|
307
|
-
int i;
|
308
|
-
for (i=0;i<nPlayBuffers;i++)
|
309
|
-
{
|
310
|
-
waveOutUnprepareHeader(hWaveOut,WaveOutBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
311
|
-
|
312
|
-
if (WaveOutBuf[i].lpData != NULL)
|
313
|
-
GlobalUnlock(WaveOutBuf[i].hData);
|
314
|
-
if (WaveOutBuf[i].hData)
|
315
|
-
GlobalFree(WaveOutBuf[i].hData);
|
316
|
-
|
317
|
-
if (WaveOutBuf[i].lpWaveHdr != NULL)
|
318
|
-
GlobalUnlock(WaveOutBuf[i].hWaveHdr);
|
319
|
-
if (WaveOutBuf[i].hWaveHdr)
|
320
|
-
GlobalFree(WaveOutBuf[i].hWaveHdr);
|
321
|
-
}
|
322
|
-
memset(WaveOutBuf,0,nPlayBuffers*sizeof(WaveOutBuffer));
|
323
|
-
}
|
324
|
-
void WaveInFreeAll()
|
325
|
-
{
|
326
|
-
int i;
|
327
|
-
for (i=0;i<nRecBuffers;i++)
|
328
|
-
{
|
329
|
-
waveInUnprepareHeader(hWaveIn,WaveInBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
330
|
-
|
331
|
-
if (WaveInBuf[i].lpData != NULL)
|
332
|
-
GlobalUnlock(WaveInBuf[i].hData);
|
333
|
-
if (WaveInBuf[i].hData)
|
334
|
-
GlobalFree(WaveInBuf[i].hData);
|
335
|
-
|
336
|
-
if (WaveInBuf[i].lpWaveHdr != NULL)
|
337
|
-
GlobalUnlock(WaveInBuf[i].hWaveHdr);
|
338
|
-
if (WaveInBuf[i].hWaveHdr)
|
339
|
-
GlobalFree(WaveInBuf[i].hWaveHdr);
|
340
|
-
}
|
341
|
-
memset(WaveInBuf,0,nRecBuffers*sizeof(WaveInBuffer));
|
342
|
-
RecordInitialised=FALSE;
|
343
|
-
SendInBuffers=0;
|
344
|
-
}
|
345
|
-
|
346
|
-
|
347
|
-
int PlayInit(int rate,int ChannelSize,int nbBuffers)
|
348
|
-
{
|
349
|
-
UINT wResult;
|
350
|
-
PCMWAVEFORMAT pcmWaveFormat;
|
351
|
-
int i;
|
352
|
-
|
353
|
-
// Open a waveform device for output using window callback.
|
354
|
-
int nChannels=2;
|
355
|
-
int BitsPerSample=16;
|
356
|
-
|
357
|
-
pcmWaveFormat.wf.wFormatTag=WAVE_FORMAT_PCM;
|
358
|
-
pcmWaveFormat.wf.nChannels=nChannels;
|
359
|
-
pcmWaveFormat.wf.nSamplesPerSec=rate;
|
360
|
-
pcmWaveFormat.wf.nAvgBytesPerSec=rate*nChannels*(BitsPerSample/8);
|
361
|
-
pcmWaveFormat.wf.nBlockAlign=(nChannels*BitsPerSample)/8;
|
362
|
-
pcmWaveFormat.wBitsPerSample=BitsPerSample;
|
363
|
-
|
364
|
-
wResult=waveOutOpen((LPHWAVEOUT)&hWaveOut, WAVE_MAPPER,
|
365
|
-
(LPWAVEFORMATEX)&pcmWaveFormat,
|
366
|
-
(LONG)mainwin, 0L, CALLBACK_WINDOW);
|
367
|
-
if (wResult != 0) return 0;
|
368
|
-
|
369
|
-
nPlayBuffers=nbBuffers;
|
370
|
-
if (WaveOutBuf) free(WaveOutBuf);
|
371
|
-
WaveOutBuf=(WaveOutBuffer*)malloc(sizeof(WaveOutBuffer)*nPlayBuffers);
|
372
|
-
|
373
|
-
|
374
|
-
for (i=0;i<nPlayBuffers;i++)
|
375
|
-
{
|
376
|
-
WaveOutBuf[i].nChannels=nChannels;
|
377
|
-
WaveOutBuf[i].Rate=rate;
|
378
|
-
WaveOutBuf[i].Resolution=BitsPerSample;
|
379
|
-
WaveOutBuf[i].hwnd=mainwin;
|
380
|
-
WaveOutBuf[i].dwDataSize=ChannelSize;
|
381
|
-
|
382
|
-
// Allocate and lock memory for the waveform data.
|
383
|
-
WaveOutBuf[i].hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, WaveOutBuf[i].dwDataSize );
|
384
|
-
if (!WaveOutBuf[i].hData) return 0;
|
385
|
-
if ((WaveOutBuf[i].lpData = (char*)GlobalLock(WaveOutBuf[i].hData)) == NULL) {
|
386
|
-
WaveOutFreeAll();
|
387
|
-
return 0;
|
388
|
-
}
|
389
|
-
|
390
|
-
// Allocate and lock memory for the header.
|
391
|
-
WaveOutBuf[i].hWaveHdr = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,(DWORD) sizeof(WAVEHDR));
|
392
|
-
if (WaveOutBuf[i].hWaveHdr == NULL)
|
393
|
-
{
|
394
|
-
WaveOutFreeAll();
|
395
|
-
return 0;
|
396
|
-
}
|
397
|
-
|
398
|
-
WaveOutBuf[i].lpWaveHdr = (LPWAVEHDR) GlobalLock(WaveOutBuf[i].hWaveHdr);
|
399
|
-
if (WaveOutBuf[i].lpWaveHdr == NULL)
|
400
|
-
{
|
401
|
-
WaveOutFreeAll();
|
402
|
-
return 0;
|
403
|
-
}
|
404
|
-
|
405
|
-
// After allocation, set up and prepare header.
|
406
|
-
|
407
|
-
WaveOutBuf[i].lpWaveHdr->lpData = WaveOutBuf[i].lpData;
|
408
|
-
WaveOutBuf[i].lpWaveHdr->dwBufferLength = WaveOutBuf[i].dwDataSize;
|
409
|
-
WaveOutBuf[i].lpWaveHdr->dwUser = i;
|
410
|
-
WaveOutBuf[i].lpWaveHdr->dwFlags = 0L;
|
411
|
-
WaveOutBuf[i].lpWaveHdr->dwLoops = 1L;
|
412
|
-
wResult = waveOutPrepareHeader(hWaveOut,WaveOutBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
413
|
-
if (wResult != 0)
|
414
|
-
{
|
415
|
-
wResult=waveOutClose(hWaveOut);
|
416
|
-
WaveOutFreeAll();
|
417
|
-
return 0;
|
418
|
-
}
|
419
|
-
memset(WaveOutBuf[i].lpData,0,WaveOutBuf[i].dwDataSize);
|
420
|
-
}
|
421
|
-
|
422
|
-
for (i=0;i<nPlayBuffers;i++)
|
423
|
-
{
|
424
|
-
// Now the data block can be sent to the output device. The
|
425
|
-
// waveOutWrite function returns immediately and waveform
|
426
|
-
// data is sent to the output device in the background.
|
427
|
-
wResult = waveOutWrite(hWaveOut,WaveOutBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
428
|
-
if (wResult != 0)
|
429
|
-
{
|
430
|
-
wResult=waveOutReset(hWaveOut);
|
431
|
-
wResult=waveOutClose(hWaveOut);
|
432
|
-
WaveOutFreeAll();
|
433
|
-
return 0;
|
434
|
-
}
|
435
|
-
}
|
436
|
-
return 1;
|
437
|
-
}
|
438
|
-
|
439
|
-
int RecStart(int rate,int ChannelSize,int nbBuffers)
|
440
|
-
{
|
441
|
-
UINT wResult;
|
442
|
-
PCMWAVEFORMAT pcmWaveFormat;
|
443
|
-
int r,i;
|
444
|
-
int BitsPerSample=16;
|
445
|
-
int nChannels=1;
|
446
|
-
if (RecordInitialised) return 0;
|
447
|
-
nRecBuffers=nbBuffers;
|
448
|
-
if (WaveInBuf) free(WaveInBuf);
|
449
|
-
WaveInBuf=(WaveInBuffer*)malloc(sizeof(WaveInBuffer)*nRecBuffers);
|
450
|
-
// memset(WaveInBuf,0,nRecBuffers*sizeof(WaveInBuffer));
|
451
|
-
// Open a waveform device for output using window callback.
|
452
|
-
|
453
|
-
if (BitsPerSample>8) BitsPerSample=16;
|
454
|
-
pcmWaveFormat.wf.wFormatTag=WAVE_FORMAT_PCM;
|
455
|
-
pcmWaveFormat.wf.nChannels=nChannels;
|
456
|
-
pcmWaveFormat.wf.nSamplesPerSec=rate;
|
457
|
-
pcmWaveFormat.wf.nAvgBytesPerSec=rate*nChannels*(BitsPerSample/8);
|
458
|
-
pcmWaveFormat.wf.nBlockAlign=(nChannels*BitsPerSample)/8;
|
459
|
-
pcmWaveFormat.wBitsPerSample=BitsPerSample;
|
460
|
-
|
461
|
-
if (r=waveInOpen((LPHWAVEIN)&hWaveIn, WAVE_MAPPER,
|
462
|
-
(LPWAVEFORMATEX)&pcmWaveFormat,
|
463
|
-
(LONG)mainwin, 0L, CALLBACK_WINDOW))
|
464
|
-
{
|
465
|
-
// MMechostr(MSKDEBUG,"Record: Unable to Open Device\n");
|
466
|
-
switch (r)
|
467
|
-
{
|
468
|
-
case MMSYSERR_ALLOCATED : printf("Device allready allocated\n"); break;
|
469
|
-
case MMSYSERR_BADDEVICEID : printf("Bad device ID\n"); break;
|
470
|
-
case MMSYSERR_NODRIVER : printf("No driver\n"); break;
|
471
|
-
case WAVERR_BADFORMAT : printf("Bad Format\n"); break;
|
472
|
-
case MMSYSERR_NOMEM : printf("No memory\n"); break;
|
473
|
-
}
|
474
|
-
return 0;
|
475
|
-
}
|
476
|
-
|
477
|
-
for (i=0;i<nRecBuffers;i++)
|
478
|
-
{
|
479
|
-
WaveInBuf[i].nChannels=nChannels;
|
480
|
-
WaveInBuf[i].Rate=rate;
|
481
|
-
WaveInBuf[i].Resolution=BitsPerSample;
|
482
|
-
WaveInBuf[i].dwDataSize=nChannels*(BitsPerSample/8)*ChannelSize;
|
483
|
-
WaveInBuf[i].hwnd=mainwin;
|
484
|
-
// Allocate and lock memory for the waveform data.
|
485
|
-
WaveInBuf[i].hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, WaveInBuf[i].dwDataSize );
|
486
|
-
if (!WaveInBuf[i].hData)
|
487
|
-
{
|
488
|
-
// MMechostr(MSKDEBUG,"Record: Unable to Allocate memory\n");
|
489
|
-
return 0;
|
490
|
-
}
|
491
|
-
if ((WaveInBuf[i].lpData = (char*)GlobalLock(WaveInBuf[i].hData)) == NULL) {
|
492
|
-
// MMechostr(MSKDEBUG,"Record: Unable to Lock Memory\n");
|
493
|
-
WaveInFreeAll();
|
494
|
-
return 0;
|
495
|
-
}
|
496
|
-
|
497
|
-
// Allocate and lock memory for the header.
|
498
|
-
WaveInBuf[i].hWaveHdr = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
|
499
|
-
(DWORD) sizeof(WAVEHDR));
|
500
|
-
if (WaveInBuf[i].hWaveHdr == NULL)
|
501
|
-
{
|
502
|
-
WaveInFreeAll();
|
503
|
-
// MMechostr(MSKDEBUG,"Record: Unable to allocate wave header\n");
|
504
|
-
return 0;
|
505
|
-
}
|
506
|
-
|
507
|
-
WaveInBuf[i].lpWaveHdr = (LPWAVEHDR) GlobalLock(WaveInBuf[i].hWaveHdr);
|
508
|
-
if (WaveInBuf[i].lpWaveHdr == NULL)
|
509
|
-
{
|
510
|
-
WaveInFreeAll();
|
511
|
-
// MMechostr(MSKDEBUG,"Record: Unable to Lock wave header memory\n");
|
512
|
-
return 0;
|
513
|
-
}
|
514
|
-
|
515
|
-
// After allocation, set up and prepare header.
|
516
|
-
|
517
|
-
WaveInBuf[i].lpWaveHdr->lpData = WaveInBuf[i].lpData;
|
518
|
-
WaveInBuf[i].lpWaveHdr->dwBufferLength = WaveInBuf[i].dwDataSize;
|
519
|
-
WaveInBuf[i].lpWaveHdr->dwUser = i;
|
520
|
-
WaveInBuf[i].lpWaveHdr->dwFlags = 0L;
|
521
|
-
WaveInBuf[i].lpWaveHdr->dwLoops = 0L;
|
522
|
-
wResult=waveInPrepareHeader(hWaveIn,WaveInBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
523
|
-
if (wResult != 0)
|
524
|
-
{
|
525
|
-
char buf[MAXERRORLENGTH];
|
526
|
-
WaveInFreeAll();
|
527
|
-
// MMechostr(MSKDEBUG,"PrepareRecBuf: Unable to write block to the device\n");
|
528
|
-
waveOutGetErrorText(wResult,buf,MAXERRORLENGTH);
|
529
|
-
// MMechostr(MSKDEBUG,buf);
|
530
|
-
// MMechostr(MSKDEBUG,"\n");
|
531
|
-
return 0;
|
532
|
-
}
|
533
|
-
|
534
|
-
}
|
535
|
-
|
536
|
-
for (i=0;i<nRecBuffers;i++)
|
537
|
-
{
|
538
|
-
// Now the data block can be sent to the input device. The
|
539
|
-
// waveOutWrite function returns immediately and waveform
|
540
|
-
// data is sent to the output device in the background.
|
541
|
-
wResult = waveInAddBuffer(hWaveIn,WaveInBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
542
|
-
if (wResult != 0)
|
543
|
-
{
|
544
|
-
WaveInFreeAll();
|
545
|
-
// MMechostr(MSKDEBUG,"Record: Unable to write block to the device\n");
|
546
|
-
return 0;
|
547
|
-
}
|
548
|
-
SendInBuffers++;
|
549
|
-
}
|
550
|
-
waveInStart(hWaveIn);
|
551
|
-
StopRecord=FALSE;
|
552
|
-
RecordInitialised=TRUE;
|
553
|
-
|
554
|
-
return 1;
|
555
|
-
}
|
556
|
-
|
557
|
-
int PlayStart()
|
558
|
-
{
|
559
|
-
PlayState=PLAYST_START;
|
560
|
-
PlayStateEof=0;
|
561
|
-
mp3simuinit();
|
562
|
-
return 0;
|
563
|
-
}
|
564
|
-
|
565
|
-
int PlayStop()
|
566
|
-
{
|
567
|
-
PlayState=PLAYST_IDLE;
|
568
|
-
return 0;
|
569
|
-
}
|
570
|
-
|
571
|
-
int PlayEof()
|
572
|
-
{
|
573
|
-
PlayStateEof=1;
|
574
|
-
return 0;
|
575
|
-
}
|
576
|
-
|
577
|
-
int RecStop()
|
578
|
-
{
|
579
|
-
// waveInReset(hWaveIn);
|
580
|
-
// waveInClose(hWaveIn);
|
581
|
-
StopRecord=TRUE;
|
582
|
-
return 0;
|
583
|
-
}
|
584
|
-
|
585
|
-
int PlayData(int i)
|
586
|
-
{
|
587
|
-
WORD wResult;
|
588
|
-
|
589
|
-
OutFillBuffer(i);
|
590
|
-
wResult = waveOutWrite(hWaveOut,WaveOutBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
591
|
-
if (wResult != 0)
|
592
|
-
{
|
593
|
-
WaveOutFreeAll();
|
594
|
-
return 0;
|
595
|
-
}
|
596
|
-
return 1;
|
597
|
-
}
|
598
|
-
|
599
|
-
int RecData(int i)
|
600
|
-
{
|
601
|
-
WORD wResult;
|
602
|
-
|
603
|
-
SendInBuffers--;
|
604
|
-
if (!StopRecord)
|
605
|
-
{
|
606
|
-
InFillBuffer(i);
|
607
|
-
wResult = waveInAddBuffer(hWaveIn,WaveInBuf[i].lpWaveHdr,sizeof(WAVEHDR));
|
608
|
-
if (wResult != 0)
|
609
|
-
{
|
610
|
-
WaveInFreeAll();
|
611
|
-
return 0;
|
612
|
-
}
|
613
|
-
SendInBuffers++;
|
614
|
-
}
|
615
|
-
else
|
616
|
-
{
|
617
|
-
if (!SendInBuffers)
|
618
|
-
{
|
619
|
-
WaveInFreeAll();
|
620
|
-
StopRecord=FALSE;
|
621
|
-
waveInClose(hWaveIn);
|
622
|
-
}
|
623
|
-
}
|
624
|
-
return 1;
|
625
|
-
}
|
626
|
-
|
627
|
-
int audioEventPlayData(int eventId, int wParam, int lParam)
|
628
|
-
{
|
629
|
-
// printf("###play cb\n");
|
630
|
-
PlayData(((LPWAVEHDR)lParam)->dwUser);
|
631
|
-
return 0;
|
632
|
-
}
|
633
|
-
|
634
|
-
int audioEventRecData(int eventId, int wParam, int lParam)
|
635
|
-
{
|
636
|
-
// printf("###rec cb\n");
|
637
|
-
RecData(((LPWAVEHDR)lParam)->dwUser);
|
638
|
-
return 0;
|
639
|
-
}
|
640
|
-
|
641
|
-
void audioSetVolume(int vol)
|
642
|
-
{
|
643
|
-
vol&=255;
|
644
|
-
waveOutSetVolume(hWaveOut,(vol<<24)+(vol<<8));
|
645
|
-
}
|
646
|
-
|
647
|
-
int simuaudioinit()
|
648
|
-
{
|
649
|
-
nPlayBuffers=0;
|
650
|
-
PlayState=PLAYST_IDLE;
|
651
|
-
|
652
|
-
nRecBuffers=0;
|
653
|
-
SendInBuffers=0;
|
654
|
-
StopRecord=FALSE;
|
655
|
-
RecordInitialised=FALSE;
|
656
|
-
|
657
|
-
PlayInit(44100,10000 //22050
|
658
|
-
,8);
|
659
|
-
|
660
|
-
return 0;
|
661
|
-
}
|
662
|
-
|