1 | sclass MonoSamplesForwarder extends AbstractOutputStream {
|
2 | int halfSample = -1; |
3 | O f; // voidfunc(float[]) |
4 | |
5 | static bool debug; |
6 | |
7 | *() {}
|
8 | *(O *f) {}
|
9 | |
10 | public void write(byte[] b, int ofs, int len) {
|
11 | int n = (len+(halfSample >= 0 ? 1 : 0))/2; |
12 | float[] out = new float[n]; |
13 | int iOut = 0; |
14 | if (debug) print(bytesToHex(subArray(b, ofs, ofs+min(8, len)))); |
15 | for (int i = ofs; i < ofs+len; i++) {
|
16 | if (halfSample < 0) |
17 | halfSample = ((int) b[i]) & 0x255; |
18 | else {
|
19 | out[iOut++] = (halfSample | (((int) b[i]) << 8))/32768f; |
20 | halfSample = -1; |
21 | } |
22 | } |
23 | if (n != 0) callF(f, out); |
24 | } |
25 | } |
Began life as a copy of #1009775
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009776 |
| Snippet name: | MonoSamplesForwarder - 16 bit PCM stream to mono float samples (-1 to 1) |
| Eternal ID of this version: | #1009776/7 |
| Text MD5: | 73310466169d6e55cf72857cdeb7e250 |
| Author: | stefan |
| Category: | javax / audio |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-08-16 17:55:01 |
| Source code size: | 662 bytes / 25 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 759 / 1354 |
| Version history: | 6 change(s) |
| Referenced in: | [show references] |