forked from LeenkxTeam/LNXSDK
Update Kha/Backends/Krom/kha/audio2/Audio.hx
This commit is contained in:
@ -1,57 +1,56 @@
|
|||||||
package kha.audio2;
|
package kha.audio2;
|
||||||
|
|
||||||
import kha.Sound;
|
import kha.Sound;
|
||||||
import kha.internal.IntBox;
|
import kha.internal.IntBox;
|
||||||
|
|
||||||
class Audio {
|
class Audio {
|
||||||
public static var disableGcInteractions = false;
|
public static var disableGcInteractions = false;
|
||||||
static var intBox: IntBox = new IntBox(0);
|
static var intBox: IntBox = new IntBox(0);
|
||||||
static var buffer: Buffer;
|
static var buffer: Buffer;
|
||||||
|
|
||||||
public static function _init() {
|
public static function _init() {
|
||||||
var bufferSize = 1024 * 2;
|
var bufferSize = 1024 * 2;
|
||||||
buffer = new Buffer(bufferSize * 4, 2, 44100);
|
buffer = new Buffer(bufferSize * 4, 2, samplesPerSecond);
|
||||||
Audio.samplesPerSecond = 44100;
|
}
|
||||||
}
|
|
||||||
|
public static function _callCallback(samples: Int): Void {
|
||||||
public static function _callCallback(samples: Int): Void {
|
if (buffer == null)
|
||||||
if (buffer == null)
|
return;
|
||||||
return;
|
if (audioCallback != null) {
|
||||||
if (audioCallback != null) {
|
intBox.value = samples;
|
||||||
intBox.value = samples;
|
audioCallback(intBox, buffer);
|
||||||
audioCallback(intBox, buffer);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
for (i in 0...samples) {
|
||||||
for (i in 0...samples) {
|
buffer.data.set(buffer.writeLocation, 0);
|
||||||
buffer.data.set(buffer.writeLocation, 0);
|
buffer.writeLocation += 1;
|
||||||
buffer.writeLocation += 1;
|
if (buffer.writeLocation >= buffer.size) {
|
||||||
if (buffer.writeLocation >= buffer.size) {
|
buffer.writeLocation = 0;
|
||||||
buffer.writeLocation = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static function _readSample(): Float {
|
||||||
public static function _readSample(): Float {
|
if (buffer == null)
|
||||||
if (buffer == null)
|
return 0;
|
||||||
return 0;
|
var value = buffer.data.get(buffer.readLocation);
|
||||||
var value = buffer.data.get(buffer.readLocation);
|
buffer.readLocation += 1;
|
||||||
buffer.readLocation += 1;
|
if (buffer.readLocation >= buffer.size) {
|
||||||
if (buffer.readLocation >= buffer.size) {
|
buffer.readLocation = 0;
|
||||||
buffer.readLocation = 0;
|
}
|
||||||
}
|
return value;
|
||||||
return value;
|
}
|
||||||
}
|
|
||||||
|
public static var samplesPerSecond: Int;
|
||||||
public static var samplesPerSecond: Int;
|
|
||||||
|
public static var audioCallback: IntBox->Buffer->Void;
|
||||||
public static var audioCallback: IntBox->Buffer->Void;
|
|
||||||
|
public static function play(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||||
public static function play(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||||
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user