Transpiled version (3062L) is out of date.
1 | lib 1400149 // java-lame |
2 | static LS _stickyLibs_StreamingMP3Encoder = ll(#1400149); |
3 | |
4 | import net.sourceforge.lame.lowlevel.*; |
5 | import net.sourceforge.lame.mp3.MPEGMode; |
6 | |
7 | sclass StreamingMP3Encoder implements AutoCloseable { |
8 | File mp3; |
9 | OutputStream out; |
10 | byte[] outBuffer; |
11 | LameEncoder encoder; |
12 | IVF3<byte[], Int, Int> onBytesWritten; |
13 | AudioFormat format; |
14 | int bitRate = 128; |
15 | int quality = LameEncoder.DEFAULT_QUALITY; |
16 | bool vbr; |
17 | |
18 | *() {} |
19 | |
20 | *(File mp3, float sampleRate) { |
21 | this(mp3, javaSound_pcmSignedLittleEndianMono(sampleRate)); |
22 | } |
23 | |
24 | *(File *mp3, AudioFormat *format) { |
25 | init(); |
26 | } |
27 | |
28 | void init ctex { |
29 | MPEGMode channelMode = format.getChannels() == 1 ? MPEGMode.MONO : MPEGMode.JOINT_STEREO; |
30 | encoder = new LameEncoder(format, |
31 | bitRate, |
32 | channelMode, quality, vbr); |
33 | outBuffer = new byte[encoder.getPCMBufferSize()]; |
34 | out = newFileOutputStream(mp3); |
35 | } |
36 | |
37 | public void close { encoder.close(); dispose out; } |
38 | |
39 | void addData(short[] samples) ctex { |
40 | byte[] pcm = byteArrayFromShorts_littleEndian(samples); |
41 | int bytesToTransfer = min(l(outBuffer), l(pcm)), bytesWritten; |
42 | int iPCM = 0; |
43 | while (0 < (bytesWritten = encoder.encodeBuffer(pcm, iPCM, bytesToTransfer, outBuffer))) { |
44 | iPCM += bytesToTransfer; |
45 | bytesToTransfer = min(l(outBuffer), l(pcm) - iPCM); |
46 | callF(onBytesWritten, outBuffer, 0, bytesWritten); |
47 | out.write(outBuffer, 0, bytesWritten); |
48 | } |
49 | } |
50 | } |
Began life as a copy of #1019665
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026967 |
Snippet name: | StreamingMP3Encoder (pure java version) |
Eternal ID of this version: | #1026967/27 |
Text MD5: | ec98deb7f383d7ce4c45a1b876819312 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-17 16:20:34 |
Source code size: | 1498 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 307 / 718 |
Version history: | 26 change(s) |
Referenced in: | [show references] |