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

72
LINES

< > BotCompany Repo | #1026942 // Audio Clip [dev.]

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

Uses 911K of libraries. Click here for Pure Java version (5941L/30K).

1  
!7
2  
3  
cmodule AudioClip > DynSCP {
4  
  File audioFile;
5  
  double windowSize = 0.01; // seconds
6  
  
7  
  transient JAmplitudeGraph graph;
8  
  transient float[] volumeProfile;
9  
  transient short[] fullAudio; // stereo/44.1 KHz
10  
  
11  
  start {
12  
    afterVisualize2(r updateGraph);
13  
    graph = swingNu JAmplitudeGraph();
14  
  }
15  
  
16  
  void updateGraph enter {
17  
    if (!isFile(audioFile))
18  
      ret with setComponent(jcenteredbutton("Open audio file...", rThread openFile));
19  
      
20  
    setComponent(northCenterAndSouthWithMargin(
21  
      jCenteredSection("File", dm_centeredLabel audioFile()),
22  
      jCenteredSection("Volume Profile", graph),
23  
      withMargin(jrightalignedbuttons(
24  
        "Open...", rThread openFile,
25  
        "Play", rThread play,
26  
        "Normalize", rThread normalize
27  
      ))));
28  
    if (volumeProfile == null)
29  
      volumeProfile = decodeWAVToMonoSamples_floatVolumeProfile(audioFile, windowSize);
30  
    graph?.setValues(volumeProfile);
31  
  }
32  
  
33  
  void updateProfile enter {
34  
    volumeProfile = null;
35  
    updateGraph();
36  
  }
37  
  
38  
  void openFile enter {
39  
    File f = showFileChooser();
40  
    if (f != null) loadFile(f);
41  
  }
42  
  
43  
  void loadFile(File f) {
44  
    setFields(audioFile := f, fullAudio := null);
45  
    updateProfile();
46  
  }
47  
  
48  
  void loadFullAudio {
49  
    if (!isFile(audioFile)) ret;
50  
    fullAudio = convertSampleRate_stereoShortArray_simple(
51  
      decodeWAVToStereoSamples(audioFile),
52  
      wavSampleRate(audioFile), sampleRate());
53  
  }
54  
  
55  
  void play enter {
56  
    if (fullAudio == null) loadFullAudio();
57  
    dm_addShortArraySoundSource(fullAudio);
58  
  }
59  
  
60  
  void normalize enter {
61  
    loadFullAudio();
62  
    fullAudio = normalizeShortArray(fullAudio);
63  
    makeVolumeProfileFromMemory();
64  
  }
65  
  
66  
  void makeVolumeProfileFromMemory enter {
67  
    volumeProfile = floatVolumeProfileFromStereoShortArray(fullAudio, windowSize, sampleRate());
68  
    updateGraph();
69  
  }
70  
  
71  
  float sampleRate() { ret cdSampleRate(); }
72  
}

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: #1026942
Snippet name: Audio Clip [dev.]
Eternal ID of this version: #1026942/14
Text MD5: e96af6aa08b8478c06e3f9f200d14fd9
Transpilation MD5: 51fdc11d7fdb4c898656bcc968390fb1
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-03 14:11:14
Source code size: 1961 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 218 / 1443
Version history: 13 change(s)
Referenced in: [show references]