Fix TTA decoding
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-02-27 15:56:45 +01:00
parent ed7bb2d16a
commit 9c27f76805
5 changed files with 88 additions and 39 deletions

View file

@ -23,6 +23,7 @@ var TestSampleLocations = []string{
const TestSingleSample24 = "resources/samples/cYsmix - Haunted House/11. The Great Rigid Desert.flac"
const TestSingleSample16 = "resources/samples/Babbe Music - RADIANT DANCEFLOOR/01. ENTER.flac"
const TestSingleSample16TTA = "resources/samples/Babbe Music - RADIANT DANCEFLOOR/01. ENTER.tta"
func doTest(format format.Format, ext string, t *testing.T) {
for _, location := range TestSampleLocations {
@ -108,6 +109,7 @@ func TestHasher24(t *testing.T) {
}
}
func TestHasher16(t *testing.T) {
t.Parallel()
@ -168,6 +170,66 @@ func TestHasher16(t *testing.T) {
}
func TestHasher16TTA(t *testing.T) {
t.Parallel()
fp, err := os.Open(TestSingleSample16TTA)
if err != nil {
t.Error(err)
return
}
defer fp.Close()
source, analyzerChannel, err := tta.NewFormat().OpenAnalyzer(fp)
if err != nil {
t.Error(err)
return
}
channels := analyzerChannel.Split(4)
cueToolsCrc32 := hasher.NewHasher(channels[0].SkipStartSamples(hasher.Int16SamplesPerSector*10), hasher.HashtypeCrc32)
arChannels := channels[1].SkipStartSamples(hasher.Int16SamplesPerSector*5 - 1).Split(2)
accurateRipV1 := hasher.NewHasher(arChannels[0], hasher.HashtypeAccurateRipV1Start)
accurateRipV2 := hasher.NewHasher(arChannels[1], hasher.HashtypeAccurateRipV2Start)
crc32 := hasher.NewHasher(channels[2], hasher.HashtypeCrc32)
sha256 := hasher.NewHasher(channels[3], hasher.HashtypeSha256)
//Decode
for range source.Blocks {
}
cueToolsCrc32.Wait()
accurateRipV1.Wait()
accurateRipV2.Wait()
crc32.Wait()
sha256.Wait()
expectCueToolsCrc32, _ := hex.DecodeString("18701E02")
if bytes.Compare(cueToolsCrc32.GetResult(), expectCueToolsCrc32) != 0 {
t.Errorf("Wrong CTDB CRC32 %08X != %08X", cueToolsCrc32.GetResult(), expectCueToolsCrc32)
}
expectAccurateRipV1, _ := hex.DecodeString("5593DA89")
if bytes.Compare(accurateRipV1.GetResult(), expectAccurateRipV1) != 0 {
t.Errorf("Wrong AccurateRip V1 %08X != %08X", accurateRipV1.GetResult(), expectAccurateRipV1)
}
expectAccurateRipV2, _ := hex.DecodeString("DAA40E75")
if bytes.Compare(accurateRipV2.GetResult(), expectAccurateRipV2) != 0 {
t.Errorf("Wrong AccurateRip V2 %08X != %08X", accurateRipV2.GetResult(), expectAccurateRipV2)
}
expectCrc32, _ := hex.DecodeString("50CE5057")
if bytes.Compare(crc32.GetResult(), expectCrc32) != 0 {
t.Errorf("Wrong CRC32 %08X != %08X", crc32.GetResult(), expectCrc32)
}
expectSha256, _ := hex.DecodeString("FEDF080D500D1A49DF8366BE619918D2A5D00413B7C7613A39DC00659FA25AC6")
if bytes.Compare(sha256.GetResult(), expectSha256) != 0 {
t.Errorf("Wrong SHA256 %X != %X", sha256.GetResult(), expectSha256)
}
}
func TestFilterChain(t *testing.T) {
t.Parallel()
fp, err := os.Open(TestSingleSample24)

View file

@ -10,7 +10,7 @@ import (
"errors"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
libtta "github.com/dsonck92/tta"
libtta "git.gammaspectra.live/S.O.N.G/go-tta"
"io"
"unsafe"
)
@ -129,6 +129,7 @@ func (f Format) OpenAnalyzer(r io.ReadSeekCloser) (audio.Source, format.Analyzer
go func() {
defer close(newChannel)
defer close(analyzerChannel)
smpSize := int(info.Nch) * ((int(info.Bps) + 7) / 8)
buffer := make([]byte, BlockSize*smpSize)

View file

@ -83,7 +83,6 @@ __attribute__((weak)) void audio_multiple_channels_to_stereo(float* buffer, size
__attribute__((weak)) void audio_bytes_to_int32(int8_t* restrict data, size_t data_len, int32_t* restrict buffer, int bitDepth){
int32_t sample;
switch(bitDepth) {
case 8:
for (int i = 0; i < data_len; i++){
@ -91,18 +90,21 @@ __attribute__((weak)) void audio_bytes_to_int32(int8_t* restrict data, size_t da
}
break;
case 16:
for (int i = 0; i < data_len; i += 2){
sample = data[i];
sample += ((int32_t) data[i+1]) << 8;
buffer[i/2] = sample;
for (int i = 0; i < data_len/2; i++){
buffer[i] = ((int16_t*)data)[i];
}
break;
case 24:
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((int32_t) data[i+1]) << 8;
sample += ((int32_t) data[i+2]) << 16;
buffer[i/3] = sample;
{
uint32_t sample;
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((uint32_t) data[i+1]) << 8;
sample += ((uint32_t) data[i+2]) << 16;
//sign extend
buffer[i/3] = (int32_t)(sample << 8) >> 8;
}
}
break;
case 32:
@ -132,31 +134,15 @@ __attribute__((weak)) void audio_int32_to_float32(int32_t* restrict data, size_t
//special case
__attribute__((weak)) void audio_int24_to_float32(int8_t* restrict data, size_t data_len, float* restrict buffer, int bitDepth){
int sample;
switch(bitDepth) {
case 16:
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((int) data[i+1]) << 8;
sample += ((int) data[i+2]) << 16;
buffer[i/3] = ((float)sample) / BITS_TO_DIV(16);
}
break;
case 24:
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((int) data[i+1]) << 8;
sample += ((int) data[i+2]) << 16;
buffer[i/3] = ((float)sample) / BITS_TO_DIV(24);
}
break;
default:
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((int) data[i+1]) << 8;
sample += ((int) data[i+2]) << 16;
buffer[i/3] = ((float)sample) / BITS_TO_DIV(bitDepth);
}
uint32_t sample;
for (int i = 0; i < data_len; i += 3){
sample = data[i];
sample += ((int) data[i+1]) << 8;
sample += ((int) data[i+2]) << 16;
//sign extend
buffer[i/3] = ((float)((int32_t)(sample << 8) >> 8)) / BITS_TO_DIV(bitDepth);
}
}

2
go.mod
View file

@ -4,9 +4,9 @@ go 1.18
require (
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f
github.com/dh1tw/gosamplerate v0.1.2
github.com/dsonck92/tta v0.2.0
github.com/kvark128/minimp3 v0.0.0-20211109174940-101188771a65
)

4
go.sum
View file

@ -1,12 +1,12 @@
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a h1:LxrTp9gf4w5KnFHRPFLXYfoxC58GCSEmZrHI6Ogtrm0=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220130003320-c9b07c6bec7a/go.mod h1:vkoHSHVM9p6vAUmXAik0gvaLcIfiQYrD6bQqVpOulUk=
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6 h1:ITVVisbHPnUclp3PBkCbXFeBhOCBcOjPdgjJ9wRH3TI=
git.gammaspectra.live/S.O.N.G/go-tta v0.2.1-0.20220226150007-096de1072bd6/go.mod h1:cobkT8u8vq/+ngLy+feKS2M2ZT2HoCec5riA/0Cex3Q=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f h1:4Dkx1l5Ex7pG/Xbs57L4IQd7mBgd6TO5rhP0BKP9PiI=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220223152921-827e6c3f729f/go.mod h1:/po1QgOh3xynbvi4sxdY6Iw8m5WPJfGGmry2boZD8fs=
github.com/cocoonlife/testify v0.0.0-20160218172820-792cc1faeb64 h1:LjPYdzoFSAJ5Tr/ElL8kzTJghXgpnOjJVbgd1UvZB1o=
github.com/dh1tw/gosamplerate v0.1.2 h1:oyqtZk67xB9B4l+vIZCZ3F0RYV/z66W58VOah11/ktI=
github.com/dh1tw/gosamplerate v0.1.2/go.mod h1:zooTyHpoR7hE+FLfdE3yjLHb2QA2NpMusNfuaZqEACM=
github.com/dsonck92/tta v0.2.0 h1:S0icGZIqhQpdOD67sA4FZPlrv88aLjDsUaE7cN03Kf0=
github.com/dsonck92/tta v0.2.0/go.mod h1:/rFZ5C7w59HcjMgASJbwrwgDBK/AqYZ83C63lXlVsAU=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/kvark128/minimp3 v0.0.0-20211109174940-101188771a65 h1:8qfVQv7MSACDXadEwl1yjUKJ68yC9B7nR4cioEoCfH0=