-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sa.go
58 lines (46 loc) · 1.23 KB
/
sa.go
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
package main
import (
"bytes"
"encoding/binary"
"os"
"path/filepath"
"strings"
)
var wavName string
var flacRaw []byte
func init() {
// Locate executable
filePath, _ := os.Executable()
filePath, _ = filepath.EvalSymlinks(filePath)
// Name wav file after executable
wavName = strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath))+".wav"
// Slurp file into memory
fileData, _ := os.ReadFile(filePath)
// Determine length of transcoder / start of FLAC data
tcSize := int64(1000000)
for {
if fileData[tcSize-1] == 0x00 &&
fileData[tcSize] == 0x66 &&
fileData[tcSize+1] == 0x4c &&
fileData[tcSize+2] == 0x61 &&
fileData[tcSize+3] == 0x43 &&
fileData[tcSize+4] == 0x00 {
break
}
if int(tcSize) == len(fileData)-6 {
os.Stdout.WriteString("No FLAC data found.")
os.Exit(5)
}
tcSize++
}
// Calculate length of FLAC data
flacSize := int64(len(fileData))-tcSize
// Create file data reader
reader := bytes.NewReader(fileData)
// Shift position of reader to the start of the flac data
_, _ = reader.Seek(tcSize, os.SEEK_SET)
// Create byte array to hold flac data
flacRaw = make([]byte, flacSize)
// Load empty byte arrary with flac data
binary.Read(reader, binary.LittleEndian, &flacRaw)
}