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

46
LINES

< > BotCompany Repo | #1032899 // Test Concentus (pure java Opus decoder) for decoding Opus stream (OK!)

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

Uses 1634K of libraries. Click here for Pure Java version (11252L/58K).

1  
!7
2  
3  
lib 1400511 // VorbisJava (to unpack ogg file)
4  
lib 1400502 // Concentus 1.0 (to decode OPUS audio in ogg file)
5  
6  
import org.gagravarr.opus.*;
7  
import org.concentus.*;
8  
9  
cm TestConcentus > DynSingleFunctionWithPrintLog {
10  
  S oggSnippetID = #1400517;
11  
  transient L<short[]> samples;
12  
  
13  
  @Override void doIt() ctex {
14  
    OpusDecoder decoder = new(48000, 1); // decode mono
15  
    
16  
    File f = loadLibrary(#1400517);
17  
    temp OpusFile opusFile = new(f);
18  
    
19  
    samples = new L;
20  
    short[] pcm = new[5760]; // max opus frame size (mono)
21  
    
22  
    OpusAudioData data;
23  
    while ((data = opusFile.getNextAudioPacket()) != null) {
24  
      byte[] bytes = data.getData();
25  
      if (empty(bytes)) continue;
26  
      print("Got compressed audio data: " + l(bytes));
27  
      
28  
      int nSamples = decoder.decode(bytes, 0, l(bytes), pcm, 0, l(pcm), false);
29  
      print("Got " + nSamples(nSamples));
30  
      samples.add(cloneSubShortArray(pcm, 0, nSamples));
31  
    }
32  
    print("Done");
33  
    
34  
    File wavFile = programFile("output.wav");
35  
    multiShortArraysToWAVE(samples, wavFile, format := javaSound_opusMono());
36  
    printFileInfo(wavFile);
37  
    
38  
    showGraph();
39  
  }
40  
  
41  
  void showGraph {
42  
    var pcm = random(samples);
43  
    print("Chose PCM: " + l(pcm));
44  
    dm_showImageAs("Decoded Audio Sample", shortArrayToGraph(pcm));
45  
  }
46  
}

Author comment

Began life as a copy of #1032896

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032899
Snippet name: Test Concentus (pure java Opus decoder) for decoding Opus stream (OK!)
Eternal ID of this version: #1032899/20
Text MD5: 25472a64ab7b23cce418957270721e2a
Transpilation MD5: a088b4f65dd4baabd5fd0f77b21eb503
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-10 17:52:48
Source code size: 1351 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 384 / 554
Version history: 19 change(s)
Referenced in: [show references]