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

37
LINES

< > BotCompany Repo | #1026861 // Audio Input with other sample rate / channels [dev.]

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

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

1  
!7
2  
3  
cmodule AudioInput > DynPrintLog {
4  
  switchable float sampleRate = 44100;
5  
  switchable int channels = 1;
6  
  int bufSize = 40960;
7  
  transient recordToAudioListeners_AudioLoop loop;
8  
  transient SimpleLiveValue<Float> lvVolume = floatLiveValue(); // in percent
9  
  transient L<VF1<short[]>> audioListeners = synchroList();
10  
  
11  
  visualize {
12  
    ret centerAndSouthWithMargins(super.visualize(),
13  
      jCenteredLine(jLiveValueLabel(mapLiveValue(func(float volume) -> S { "Volume: " + iround(volume) + " %" }, S, lvVolume))));
14  
  }
15  
16  
  start {
17  
    ownTimer(loop = recordToAudioListeners(audioListeners, bufSize, lvVolume, getAudioFormat()));
18  
    loop.start();
19  
    JComponent trayIcon = jMinWidth(16, jVerticalGreenBar(lvVolume, max := 100));
20  
    componentPopupMenuItem(trayIcon, "Audio Input", r { dm_showModule(module()) });
21  
    dm_setTrayIcon(trayIcon);
22  
  }
23  
  
24  
  // hold audio listeners during reload
25  
  
26  
  O _getReloadData() { ret audioListeners; }
27  
  void _setReloadData(L<VF1<short[]>> listeners) { addAll(audioListeners, listeners); }
28  
29  
  // API
30  
  
31  
  void addAudioListener(VF1<short[]> l) { audioListeners.add(l); }
32  
  void removeAudioListener(VF1<short[]> l) { audioListeners.remove(l); }
33  
  
34  
  AudioFormat getAudioFormat() { ret new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, 16, channels, channels*2, sampleRate, false); }
35  
  
36  
  float getVolume() { ret lvVolume!; }
37  
}

Author comment

Began life as a copy of #1017138

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: #1026861
Snippet name: Audio Input with other sample rate / channels [dev.]
Eternal ID of this version: #1026861/7
Text MD5: 9b234f86de6128263cfba803f59516cc
Transpilation MD5: ea283ba20647fb2a6cd4d0330c58916b
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-01-29 16:05:58
Source code size: 1412 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 161 / 287
Version history: 6 change(s)
Referenced in: [show references]