File size: 1,834 Bytes
b0bfea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { BasicSample } from "../basic_soundfont/basic_sample.js";

export class DLSSample extends BasicSample
{
    /**
     * in decibels of attenuation, WITHOUT EMU CORRECTION
     * @type {number}
     */
    sampleDbAttenuation;
    /**
     * @type {Float32Array}
     */
    sampleData;
    
    /**
     * @param name {string}
     * @param rate {number}
     * @param pitch {number}
     * @param pitchCorrection {number}
     * @param loopStart {number} sample data points
     * @param loopEnd {number} sample data points
     * @param data {Float32Array}
     * @param sampleDbAttenuation {number} in db
     */
    constructor(
        name,
        rate,
        pitch,
        pitchCorrection,
        loopStart,
        loopEnd,
        data,
        sampleDbAttenuation
    )
    {
        super(
            name,
            rate,
            pitch,
            pitchCorrection,
            0,
            1,
            loopStart,
            loopEnd
        );
        this.sampleData = data;
        this.sampleDbAttenuation = sampleDbAttenuation;
    }
    
    getAudioData()
    {
        return this.sampleData;
    }
    
    getRawData()
    {
        if (this.isCompressed)
        {
            if (!this.compressedData)
            {
                throw new Error("Compressed but no data?? This shouldn't happen!!");
            }
            return this.compressedData;
        }
        return super.getRawData();
        // const uint8 = new Uint8Array(this.sampleData.length * 2);
        // for (let i = 0; i < this.sampleData.length; i++)
        // {
        //     const sample = Math.floor(this.sampleData[i] * 32768);
        //     uint8[i * 2] = sample & 0xFF; // lower byte
        //     uint8[i * 2 + 1] = (sample >> 8) & 0xFF; // upper byte
        // }
        // return uint8;
    }
}