| 60 | this.private.volume = Math.round(it * 256); |
| 61 | } |
| 62 | constructor(it) { |
| 63 | if (Array.isArray(it)) { |
| 64 | this.tones = it; |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | let archive = it.archive; |
| 69 | let path = it.path; |
| 70 | if (!path) |
| 71 | throw new URIError("Sound: no path!"); |
| 72 | if (!path.endsWith(".wav")) |
| 73 | throw new URIError("Sound: not .wav!"); |
| 74 | path = path.slice(0, -4) + ".maud"; |
| 75 | if (!Resource.exists(path, archive)) |
| 76 | throw new URIError("Sound: " + it.path + " not found!"); |
| 77 | this.buffer = new Resource(path, archive); |
| 78 | this.offset = it.offset ?? 0; |
| 79 | this.size = it.size ?? -1; |
| 80 | } |
| 81 | play(stream = 0, repeat = 1, callback) { |
| 82 | const audioOut = Sound.private.audioOut ?? Sound.open(); |
| 83 | audioOut.enqueue(stream, AudioOut.Flush); |