<commit_before>import js.html.audio.AudioBufferSourceNode;
import js.html.audio.AudioContext;
import js.Browser;

class AudioManager {

	public var types:Map<String, String>;
	public var audioContext:AudioContext;
	public var bufferList:Map<String, Dynamic>;
	public var playingSounds:Map<String, Dynamic>;

	static var AudioContextClass:Dynamic;

	public function new() {
		bufferList = new Map();
		playingSounds = new Map();

		types = new Map();
		types.set("mp3", "audio/mpeg");
		types.set("ogg", "audio/ogg");
		types.set("wav", "audio/wav");
		types.set("aac", "audio/aac");
		types.set("m4a", "audio/x-m4a");
	}

	public function checkWebAudioAPISupport():Bool {
		if (Reflect.field(Browser.window, "AudioContext") != null) {
			AudioContextClass = Reflect.field(Browser.window, "AudioContext");
			return true;
		}
		else if (Reflect.field(Browser.window, "webkitAudioContext") != null) {
			AudioContextClass = Reflect.field(Browser.window, "webkitAudioContext");
			return true;
		}
		return false;
	}

	public function unlockAudio() {
		if (audioContext == null) return;
		var bfr = audioContext.createBuffer(1, 1, Waud.preferredSampleRate);
		var src:AudioBufferSourceNode = audioContext.createBufferSource();
		src.buffer = bfr;
		src.connect(audioContext.destination);
		src.start(0);
		if (src.onended != null) src.onended = _unlockCallback;
		else haxe.Timer.delay(_unlockCallback, 1);
	}

	inline function _unlockCallback() {
		if (Waud.__touchUnlockCallback != null) Waud.__touchUnlockCallback();
		Waud.dom.ontouchend = null;
	}

	public function createAudioContext() {
		if (audioContext == null) {
			try {
				if (AudioContextClass != null) audioContext = cast Type.createInstance(AudioContextClass, []);
			}
			catch(e:Dynamic) {
				audioContext = null;
			}
		}
	}

	public function destroyContext() {
		if (audioContext != null && untyped __js__("this.audioContext").close != null && untyped __js__("this.audioContext").close != "") {
			untyped __js__("this.audioContext").close();
		}
		audioContext = null;
	}

	public function suspendContext() {
		if (audioContext != null) {
			if (untyped __js__("this.audioContext").suspend != null) untyped __js__("this.audioContext").suspend();
		}
	}

	public function resumeContext() {
		if (audioContext != null) {
			if (untyped __js__("this.audioContext").resume != null) untyped __js__("this.audioContext").resume();
		}
	}
}<commit_msg>reset variables in destroy method<commit_after>import js.html.audio.AudioBufferSourceNode;
import js.html.audio.AudioContext;
import js.Browser;

class AudioManager {

	public var types:Map<String, String>;
	public var audioContext:AudioContext;
	public var bufferList:Map<String, Dynamic>;
	public var playingSounds:Map<String, Dynamic>;

	static var AudioContextClass:Dynamic;

	public function new() {
		bufferList = new Map();
		playingSounds = new Map();

		types = new Map();
		types.set("mp3", "audio/mpeg");
		types.set("ogg", "audio/ogg");
		types.set("wav", "audio/wav");
		types.set("aac", "audio/aac");
		types.set("m4a", "audio/x-m4a");
	}

	public function checkWebAudioAPISupport():Bool {
		if (Reflect.field(Browser.window, "AudioContext") != null) {
			AudioContextClass = Reflect.field(Browser.window, "AudioContext");
			return true;
		}
		else if (Reflect.field(Browser.window, "webkitAudioContext") != null) {
			AudioContextClass = Reflect.field(Browser.window, "webkitAudioContext");
			return true;
		}
		return false;
	}

	public function unlockAudio() {
		if (audioContext == null) return;
		var bfr = audioContext.createBuffer(1, 1, Waud.preferredSampleRate);
		var src:AudioBufferSourceNode = audioContext.createBufferSource();
		src.buffer = bfr;
		src.connect(audioContext.destination);
		src.start(0);
		if (src.onended != null) src.onended = _unlockCallback;
		else haxe.Timer.delay(_unlockCallback, 1);
	}

	inline function _unlockCallback() {
		if (Waud.__touchUnlockCallback != null) Waud.__touchUnlockCallback();
		Waud.dom.ontouchend = null;
	}

	public function createAudioContext() {
		if (audioContext == null) {
			try {
				if (AudioContextClass != null) audioContext = cast Type.createInstance(AudioContextClass, []);
			}
			catch(e:Dynamic) {
				audioContext = null;
			}
		}
	}

	public function destroyContext() {
		if (audioContext != null && untyped __js__("this.audioContext").close != null && untyped __js__("this.audioContext").close != "") {
			untyped __js__("this.audioContext").close();
		}
		audioContext = null;
		bufferList = null;
		playingSounds = null;
		types = null;
	}

	public function suspendContext() {
		if (audioContext != null) {
			if (untyped __js__("this.audioContext").suspend != null) untyped __js__("this.audioContext").suspend();
		}
	}

	public function resumeContext() {
		if (audioContext != null) {
			if (untyped __js__("this.audioContext").resume != null) untyped __js__("this.audioContext").resume();
		}
	}
}
{'fraction_non_alphanumeric': 0.14422489305357505, 'fraction_numerical': 0.002851904664901202, 'mean_word_length': 4.696055684454756, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6051012', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1583, 'n_words': 336}