Add Tm Decoder

Update XM Decoder
This commit is contained in:
Emmm Monster
2020-12-26 04:54:59 +08:00
parent 0eb8ade0e9
commit 7c0d6604a2
2 changed files with 68 additions and 25 deletions

47
algo/tm/xm.go Normal file
View File

@@ -0,0 +1,47 @@
package tm
import (
"bytes"
"errors"
"github.com/umlock-music/cli/algo/common"
)
var magicHeader = []byte{0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70}
type Decoder struct {
file []byte
}
func (d *Decoder) GetCoverImage() []byte {
return nil
}
func (d *Decoder) GetAudioData() []byte {
return d.file[8:]
}
func (d *Decoder) GetAudioExt() string {
return ""
}
func (d *Decoder) GetMeta() common.Meta {
return nil
}
func NewDecoder(data []byte) *Decoder {
return &Decoder{file: data}
}
func (d *Decoder) Validate() error {
if len(d.file) < 8 {
return errors.New("invalid file size")
}
if !bytes.Equal(magicHeader, d.file[:8]) {
return errors.New("not a valid tm file")
}
return nil
}
func (d *Decoder) Decode() error {
return nil
}