From 11673c30c1ece8169e81ae602833ba04d6aed191 Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 10 Sep 2018 18:27:25 +0200 Subject: [PATCH 1/2] a little test for registering new codec with flac --- flac/decoder_test.go | 26 +++++++++++++++++++++++++- flac/register.go | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 flac/register.go diff --git a/flac/decoder_test.go b/flac/decoder_test.go index 36660fb..22751b1 100644 --- a/flac/decoder_test.go +++ b/flac/decoder_test.go @@ -3,7 +3,31 @@ package flac -import "zikichombo.org/sound" +import ( + "os" + "testing" + + "zikichombo.org/codec" + "zikichombo.org/sio" + "zikichombo.org/sound" +) // Assert that flac.Decoder implements the sound.Source interface. var _ sound.Source = (*Decoder)(nil) + +func TestRegister(t *testing.T) { + co, err := codec.CodecFor(".flac", nil) + if err != nil { + t.Fatal(err) + } + f, err := os.Open("0.flac") + if err != nil { + t.Fatal(err) + } + dec, _, err := co.Decoder(f) + if err != nil { + t.Fatal(err) + } + defer dec.Close() + sio.Play(dec) +} diff --git a/flac/register.go b/flac/register.go new file mode 100644 index 0000000..de71826 --- /dev/null +++ b/flac/register.go @@ -0,0 +1,26 @@ +package flac + +import ( + "io" + + "zikichombo.org/codec" + "zikichombo.org/sound" + "zikichombo.org/sound/sample" +) + +type flacCodec struct { + codec.NullCodec +} + +func (f *flacCodec) Extensions() []string { + return []string{".flc", ".flac"} +} + +func (f *flacCodec) Decoder(rc io.ReadCloser) (sound.Source, sample.Codec, error) { + dec, err := NewDecoder(rc) + return dec, codec.AnySampleCodec, err +} + +func init() { + codec.RegisterCodec(&flacCodec{}) +} From 5e6e7b0e6caa29d7010ca719909bb8bb82f8bf7e Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 10 Sep 2018 18:29:32 +0200 Subject: [PATCH 2/2] fix license headers --- doc.go | 2 +- flac/decoder.go | 2 +- flac/decoder_test.go | 2 +- flac/doc.go | 2 +- flac/register.go | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/doc.go b/doc.go index 81a5829..b03a5be 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ -// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source +// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source // code is governed by a license that can be found in the License file. // Package ext houses zc collaboration with external imports. diff --git a/flac/decoder.go b/flac/decoder.go index 03dfb1b..642c3ad 100644 --- a/flac/decoder.go +++ b/flac/decoder.go @@ -1,4 +1,4 @@ -// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source +// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source // code is governed by a license that can be found in the License file. // TODO: add seek support; only enabled in the dev branch of mewkiz/flac. diff --git a/flac/decoder_test.go b/flac/decoder_test.go index 22751b1..81aedbc 100644 --- a/flac/decoder_test.go +++ b/flac/decoder_test.go @@ -1,4 +1,4 @@ -// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source +// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source // code is governed by a license that can be found in the License file. package flac diff --git a/flac/doc.go b/flac/doc.go index e1b26f7..7ff4748 100644 --- a/flac/doc.go +++ b/flac/doc.go @@ -1,4 +1,4 @@ -// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source +// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source // code is governed by a license that can be found in the License file. // Package flac provides decoding of FLAC audio streams. diff --git a/flac/register.go b/flac/register.go index de71826..2fa0035 100644 --- a/flac/register.go +++ b/flac/register.go @@ -1,3 +1,6 @@ +// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source +// code is governed by a license that can be found in the License file. + package flac import (