Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1026970 // Concurrent MP3 Encoding [still only works with mono audio input]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1258K of libraries. Click here for Pure Java version (5582L/28K).

1  
!7
2  
3  
cmodule ConcurrentMP3 > DynPrintLogAndEnabled {
4  
  transient StreamingMP3Encoder encoder;
5  
  switchable int bitRate = 64;
6  
7  
  start {
8  
    dm_vmBus_onMessage_q startedRecording((IVF1<File>) lambda1 started);
9  
    dm_vmBus_onMessage_q recordedChunk((IVF1<short[]>) lambda1 gotChunk);
10  
    dm_vmBus_onMessage_q doneRecording(r done);
11  
  }
12  
  
13  
  void cleanMeUp { dispose encoder; }
14  
  
15  
  void started(File wavFileBeingMade) {
16  
    if (!enabled) ret;
17  
    File mp3 = changeExtension(wavFileBeingMade, ".live.mp3");
18  
    float sampleRate = dm_audioInputSampleRate();
19  
    int channels = dm_audioInputChannels();
20  
    print("started MP3 encoding: " + mp3 + " at " + sampleRate + " Hz" + " (" + nChannels(channels) + ")");
21  
    encoder = new StreamingMP3Encoder;
22  
    encoder.mp3 = mp3;
23  
    encoder.format = javaSound_pcmSignedLittleEndian(sampleRate, channels);
24  
    encoder.bitRate = bitRate;
25  
    encoder.init();
26  
    vmBus_send startedRecordingMP3(mp3);
27  
    encoder.onBytesWritten = (array, i, j) -> vmBus_send wroteMP3Chunk(mp3, array, i, j);
28  
  }
29  
  
30  
  void gotChunk(short[] samples) {
31  
    //print("got " + nSamples(samples));
32  
    if (enabled && encoder != null) encoder.addData(samples);
33  
  }
34  
  
35  
  void done {
36  
    if (encoder == null) ret;
37  
    File mp3 = encoder.mp3;
38  
    dispose encoder;
39  
    vmBus_send newMP3Recording(mp3);
40  
    print("Wrote " + fileInfo(mp3));
41  
  }
42  
}

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: #1026970
Snippet name: Concurrent MP3 Encoding [still only works with mono audio input]
Eternal ID of this version: #1026970/23
Text MD5: b52d8c0001743a4465e5a48f6e98ce04
Transpilation MD5: 7182c087febfa5b52bdcc221ffc9eb9d
Author: stefan
Category: javax / audio
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-17 16:26:39
Source code size: 1391 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 305 / 13393
Version history: 22 change(s)
Referenced in: [show references]