示例#1
0
 public Atrac9FormatBuilder(byte[][] audioData, Atrac9Config config, int sampleCount, int encoderDelay)
 {
     AudioData    = audioData ?? throw new ArgumentNullException(nameof(audioData));
     Config       = config ?? throw new ArgumentNullException(nameof(config));
     SampleRate   = config.SampleRate;
     SampleCount  = sampleCount;
     EncoderDelay = encoderDelay;
 }
示例#2
0
        public Frame(Atrac9Config config)
        {
            Config = config;
            Blocks = new Block[config.ChannelConfig.BlockCount];

            for (int i = 0; i < config.ChannelConfig.BlockCount; i++)
            {
                Blocks[i] = new Block(this, i);
            }
        }
示例#3
0
        public override void PrintSpecificMetadata(object metadata, StringBuilder builder)
        {
            var          at9Structure = metadata as At9Structure;
            Atrac9Config config       = at9Structure?.Config;

            if (at9Structure == null || config == null)
            {
                throw new InvalidDataException("Could not parse file metadata.");
            }

            builder.AppendLine();

            builder.AppendLine($"ATRAC9 version: {at9Structure.Version}");
            builder.AppendLine($"Superframe count: {at9Structure.SuperframeCount}");
            builder.AppendLine($"Superframe size: {config.SuperframeBytes} bytes");
            builder.AppendLine($"Frames per superframe: {config.FramesPerSuperframe}");
            builder.AppendLine($"Encoder delay: {at9Structure.EncoderDelay} samples");
        }
示例#4
0
        public override Common ToCommon(object metadata)
        {
            var          at9Structure = metadata as At9Structure;
            Atrac9Config config       = at9Structure?.Config;

            if (at9Structure == null || config == null)
            {
                throw new InvalidDataException("Could not parse file metadata.");
            }

            return(new Common
            {
                SampleCount = at9Structure.SampleCount,
                SampleRate = config.SampleRate,
                ChannelCount = config.ChannelCount,
                Format = AudioFormat.Atrac9,
                Looping = at9Structure.Looping,
                LoopStart = at9Structure.LoopStart,
                LoopEnd = at9Structure.LoopEnd
            });
        }
示例#5
0
        private short[][] Decode(CodecParameters parameters)
        {
            IProgressReport progress = parameters?.Progress;

            progress?.SetTotal(AudioData.Length);

            var decoder = new Atrac9Decoder();

            decoder.Initialize(Config.ConfigData);
            Atrac9Config config    = decoder.Config;
            var          pcmOut    = CreateJaggedArray <short[][]>(config.ChannelCount, SampleCount);
            var          pcmBuffer = CreateJaggedArray <short[][]>(config.ChannelCount, config.SuperframeSamples);

            for (int i = 0; i < AudioData.Length; i++)
            {
                decoder.Decode(AudioData[i], pcmBuffer);
                CopyBuffer(pcmBuffer, pcmOut, EncoderDelay, i);
                progress?.ReportAdd(1);
            }
            return(pcmOut);
        }
示例#6
0
        public At9DataChunk(RiffParser parser, BinaryReader reader) : base(reader)
        {
            // Do not trust the BlockAlign field in the fmt chunk to equal the superframe size.
            // Some AT9 files have an invalid number in there.
            // Calculate the size using the ATRAC9 DataConfig instead.

            At9WaveExtensible ext = parser.GetSubChunk <WaveFmtChunk>("fmt ")?.Ext as At9WaveExtensible ??
                                    throw new InvalidDataException("fmt chunk must come before data chunk");

            At9FactChunk fact = parser.GetSubChunk <At9FactChunk>("fact") ??
                                throw new InvalidDataException("fact chunk must come before data chunk");

            var config = new Atrac9Config(ext.ConfigData);

            FrameCount = (fact.SampleCount + fact.EncoderDelaySamples).DivideByRoundUp(config.SuperframeSamples);
            int dataSize = FrameCount * config.SuperframeBytes;

            if (dataSize > reader.BaseStream.Length - reader.BaseStream.Position)
            {
                throw new InvalidDataException("Required AT9 length is greater than the number of bytes remaining in the file.");
            }

            AudioData = reader.BaseStream.DeInterleave(dataSize, config.SuperframeBytes, FrameCount);
        }