From a262f99421d835096a0d782c69683de318d581c8 Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 2 Jan 2024 11:31:09 -0600 Subject: [PATCH] episode 891 --- publisher/docker-compose.yml | 2 +- .../vendor/github.com/tcolgate/mp3/header.go | 166 +++++++++--------- 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/publisher/docker-compose.yml b/publisher/docker-compose.yml index db6d8a9c..e920bd57 100644 --- a/publisher/docker-compose.yml +++ b/publisher/docker-compose.yml @@ -12,7 +12,7 @@ services: max-size: "10m" max-file: "5" environment: - - RT_NEWS_ADMIN + - NEWS_PASSWD=${RT_NEWS_ADMIN} volumes: - ../:/srv/ - /Volumes/Podcasts/radio-t:/Volumes/Podcasts/radio-t diff --git a/publisher/vendor/github.com/tcolgate/mp3/header.go b/publisher/vendor/github.com/tcolgate/mp3/header.go index 4bb8dd68..e0b37ea6 100644 --- a/publisher/vendor/github.com/tcolgate/mp3/header.go +++ b/publisher/vendor/github.com/tcolgate/mp3/header.go @@ -1,83 +1,83 @@ -package mp3 - -/* -func (this *FrameHeader) Parse(bs []byte) error { - this.Size = 0 - this.Samples = 0 - this.Duration = 0 - - if len(bs) < 4 { - return fmt.Errorf("not enough bytes") - } - if bs[0] != 0xFF || (bs[1]&0xE0) != 0xE0 { - return fmt.Errorf("missing sync word, got: %x, %x", bs[0], bs[1]) - } - this.Version = Version((bs[1] >> 3) & 0x03) - if this.Version == MPEGReserved { - return fmt.Errorf("reserved mpeg version") - } - - this.Layer = Layer(((bs[1] >> 1) & 0x03)) - if this.Layer == LayerReserved { - return fmt.Errorf("reserved layer") - } - - this.Protection = (bs[1] & 0x01) != 0x01 - - bitrateIdx := (bs[2] >> 4) & 0x0F - if bitrateIdx == 0x0F { - return fmt.Errorf("invalid bitrate: %v", bitrateIdx) - } - this.Bitrate = bitrates[this.Version][this.Layer][bitrateIdx] * 1000 - if this.Bitrate == 0 { - return fmt.Errorf("invalid bitrate: %v", bitrateIdx) - } - - sampleRateIdx := (bs[2] >> 2) & 0x03 - if sampleRateIdx == 0x03 { - return fmt.Errorf("invalid sample rate: %v", sampleRateIdx) - } - this.SampleRate = sampleRates[this.Version][sampleRateIdx] - - this.Pad = ((bs[2] >> 1) & 0x01) == 0x01 - - this.Private = (bs[2] & 0x01) == 0x01 - - this.ChannelMode = ChannelMode(bs[3]>>6) & 0x03 - - // todo: mode extension - - this.CopyRight = (bs[3]>>3)&0x01 == 0x01 - - this.Original = (bs[3]>>2)&0x01 == 0x01 - - this.Emphasis = Emphasis(bs[3] & 0x03) - if this.Emphasis == EmphReserved { - return fmt.Errorf("reserved emphasis") - } - - this.Size = this.size() - this.Samples = this.samples() - this.Duration = this.duration() - - return nil -} - -func (this *FrameHeader) samples() int { - return samplesPerFrame[this.Version][this.Layer] -} - -func (this *FrameHeader) size() int64 { - bps := float64(this.samples()) / 8 - fsize := (bps * float64(this.Bitrate)) / float64(this.SampleRate) - if this.Pad { - fsize += float64(slotSize[this.Layer]) - } - return int64(fsize) -} - -func (this *FrameHeader) duration() time.Duration { - ms := (1000 / float64(this.SampleRate)) * float64(this.samples()) - return time.Duration(time.Duration(float64(time.Millisecond) * ms)) -} -*/ +package mp3 + +/* +func (this *FrameHeader) Parse(bs []byte) error { + this.Size = 0 + this.Samples = 0 + this.Duration = 0 + + if len(bs) < 4 { + return fmt.Errorf("not enough bytes") + } + if bs[0] != 0xFF || (bs[1]&0xE0) != 0xE0 { + return fmt.Errorf("missing sync word, got: %x, %x", bs[0], bs[1]) + } + this.Version = Version((bs[1] >> 3) & 0x03) + if this.Version == MPEGReserved { + return fmt.Errorf("reserved mpeg version") + } + + this.Layer = Layer(((bs[1] >> 1) & 0x03)) + if this.Layer == LayerReserved { + return fmt.Errorf("reserved layer") + } + + this.Protection = (bs[1] & 0x01) != 0x01 + + bitrateIdx := (bs[2] >> 4) & 0x0F + if bitrateIdx == 0x0F { + return fmt.Errorf("invalid bitrate: %v", bitrateIdx) + } + this.Bitrate = bitrates[this.Version][this.Layer][bitrateIdx] * 1000 + if this.Bitrate == 0 { + return fmt.Errorf("invalid bitrate: %v", bitrateIdx) + } + + sampleRateIdx := (bs[2] >> 2) & 0x03 + if sampleRateIdx == 0x03 { + return fmt.Errorf("invalid sample rate: %v", sampleRateIdx) + } + this.SampleRate = sampleRates[this.Version][sampleRateIdx] + + this.Pad = ((bs[2] >> 1) & 0x01) == 0x01 + + this.Private = (bs[2] & 0x01) == 0x01 + + this.ChannelMode = ChannelMode(bs[3]>>6) & 0x03 + + // todo: mode extension + + this.CopyRight = (bs[3]>>3)&0x01 == 0x01 + + this.Original = (bs[3]>>2)&0x01 == 0x01 + + this.Emphasis = Emphasis(bs[3] & 0x03) + if this.Emphasis == EmphReserved { + return fmt.Errorf("reserved emphasis") + } + + this.Size = this.size() + this.Samples = this.samples() + this.Duration = this.duration() + + return nil +} + +func (this *FrameHeader) samples() int { + return samplesPerFrame[this.Version][this.Layer] +} + +func (this *FrameHeader) size() int64 { + bps := float64(this.samples()) / 8 + fsize := (bps * float64(this.Bitrate)) / float64(this.SampleRate) + if this.Pad { + fsize += float64(slotSize[this.Layer]) + } + return int64(fsize) +} + +func (this *FrameHeader) duration() time.Duration { + ms := (1000 / float64(this.SampleRate)) * float64(this.samples()) + return time.Duration(time.Duration(float64(time.Millisecond) * ms)) +} +*/