-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwavefile.ts
83 lines (67 loc) · 2.2 KB
/
wavefile.ts
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
76
77
78
79
80
81
82
83
import {ipcMain, app} from 'electron';
import * as path from 'path';
import * as fs from 'fs-extra'
import * as autobahn from 'autobahn';
function fnv32a( str:string ) :number
{
var FNV1_32A_INIT = 0x811c9dc5;
var hval = FNV1_32A_INIT;
for ( var i = 0; i < str.length; ++i )
{
hval ^= str.charCodeAt(i);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
}
// export interface WriteWaveFileArg {
// filename: string;
// data: string;
// }
const tempDir = path.join(app.getPath('temp'),'WwiseLauncher', 'Sfxr');
function writeWaveFile(filename, data) {
fs.ensureDirSync(tempDir);
let writePath = path.join(tempDir, filename + '_' + fnv32a(data.dataURI) + '.wav');
if(fs.existsSync(writePath))
fs.unlinkSync(writePath);
;
fs.writeFileSync(writePath, new Buffer(data.wav));
// Connect to waapi through autobahn
let connection = new autobahn.Connection({
url: 'ws://localhost:8080/waapi',
realm: 'realm1',
protocols: ['wamp.2.json']
});
connection.onopen = function(session) {
let importArgs = {
importOperation: "createNew",
default: {},
imports: [{
importLanguage: "SFX",
audioFile: writePath,
objectPath: "\\Actor-Mixer Hierarchy\\Default Work Unit\\<Sound SFX>" + filename + '_00'
}]
};
// Use waapi to import file by absolute path
session.call('ak.wwise.core.audio.import', [], importArgs).then(
(result) => {
console.info("Successfully imported SFX into Wwise!");
connection.close();
},
(error) => {
console.error(`An error occurred while importing the SFX into Wwise: ${JSON.stringify(error,null,4)}`);
connection.close();
}
);
};
connection.onclose = function (reason, details): boolean {
return true;
};
connection.open();
}
export function init() {
ipcMain.on('send-to-wwise', (event, args) => {
setTimeout(()=>{
writeWaveFile(args.filename, args.data);
});
});
}