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

39
LINES

< > BotCompany Repo | #1032980 // StaticAudioSample - a sample that just exists in time

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6307L/37K).

1  
// The core integral 1D image.
2  
sclass StaticAudioSample implements IAudioSample {
3  
  int channels;
4  
  double sampleRate;
5  
  int length;
6  
  
7  
  // Here they are: the partial sums of the 16 bit audio samples
8  
  // in an array of 6-byte integers. Channels are stored interleaved.
9  
  HalfLongs data;
10  
  
11  
  public double sampleRate() { ret sampleRate; }
12  
  public int channels() { ret channels; }
13  
  public DoubleRange bounds() { ret DoubleRange(0, length); }
14  
  
15  
  // Get an entry of the sum table - allow for out-of-bounds
16  
  // requests (those just default to silence).
17  
  public double readSumTable(int channel, int i) {
18  
    if (i < 0) ret 0;
19  
    i = min(i, length-1);
20  
    ret data.get(i*channels+channel);
21  
  }
22  
  
23  
  // perform the integration of the raw audio data
24  
  *(L<short[]> samples, int *channels, double *sampleRate) {
25  
    length = lengthLevel2_shortArrays(samples);
26  
    data = new HalfLongs(length*channels);
27  
    long[] sums = new[channels];
28  
    int iSample = 0, iChunk = 0, iInArray = 0;
29  
    short[] chunk = null;
30  
    for i to length:
31  
      for c to channels: {
32  
        if (chunk == null || iInArray >= chunk.length) {
33  
          chunk = samples.get(iChunk++);
34  
          iInArray = 0;
35  
        }
36  
        data.set(iSample++, sums[c] += chunk[iInArray++]);
37  
      }
38  
  }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032980
Snippet name: StaticAudioSample - a sample that just exists in time
Eternal ID of this version: #1032980/6
Text MD5: 800ddc12dec404d1f512afc6a3a9fc71
Transpilation MD5: 23c23e1a161580285d18f6877cc8409d
Author: stefan
Category: javax / audio analysis
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-18 04:01:48
Source code size: 1299 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 170 / 296
Version history: 5 change(s)
Referenced in: [show references]