Exemplo n.º 1
0
        private void WriteFooter()
        {
            var length = _outStream.Length - 12;

            _outStream.Seek(_dsdLengthPosition, SeekOrigin.Begin);
            DsdChunksContainer.WriteInt64(_outStream, _dsdDataLength);

            _outStream.Seek(4, SeekOrigin.Begin);
            DsdChunksContainer.WriteInt64(_outStream, length);
        }
Exemplo n.º 2
0
        private void WriteId3(Stream outStream)
        {
            var id3Source = GetChunkById(DsdChunk.IdType.ID3);

            if (id3Source != null && id3Source.ID3 != null)
            {
                DsdChunksContainer.WriteId(outStream, DsdChunk.IdType.ID3);
                DsdChunksContainer.WriteInt64(outStream, id3Source.ID3.Length);
                DsdChunksContainer.WriteBytes(outStream, id3Source.ID3);
            }
        }
Exemplo n.º 3
0
        private void WriteSuffixDiin(Stream outStream)
        {
            var diinSource = GetChunkById(DsdChunk.IdType.DIIN);

            if (diinSource != null)
            {
                // Write DIIN
                var diinChunk = new DsdChunksContainer(DsdChunk.IdType.DIIN);

                // > MARK property
                // Ignore at this moment

                // > DIAR property
                if (!string.IsNullOrEmpty(diinSource.ArtistText))
                {
                    if ((diinSource.ArtistText.Length % 2) != 0)
                    {
                        diinSource.ArtistText += " ";
                    }

                    var diarChunk = new DsdChunksContainer(DsdChunk.DiinChunk.DIAR);
                    diarChunk.WriteInt32(diinSource.ArtistText.TrimEnd().Length);
                    diarChunk.WriteIdString(diinSource.ArtistText, diinSource.ArtistText.Length);
                    diinChunk.WriteChunk(diarChunk);
                }

                // > DITI property
                if (!string.IsNullOrEmpty(diinSource.TitleText))
                {
                    if ((diinSource.TitleText.Length % 2) != 0)
                    {
                        diinSource.TitleText += " ";
                    }

                    var ditiChunk = new DsdChunksContainer(DsdChunk.DiinChunk.DITI);
                    ditiChunk.WriteInt32(diinSource.TitleText.TrimEnd().Length);
                    ditiChunk.WriteIdString(diinSource.TitleText, diinSource.TitleText.Length);
                    diinChunk.WriteChunk(ditiChunk);
                }

                // > EMID property
                if (!string.IsNullOrEmpty(diinSource.EMId))
                {
                    Console.WriteLine("EMID: " + diinSource.EMId + ", length: " + diinSource.EMId.Length);
                    Console.WriteLine("\n\n");
                    var emidChunk = new DsdChunksContainer(DsdChunk.DiinChunk.EMID);
                    emidChunk.WriteIdString(diinSource.EMId, diinSource.EMId.Length);
                    diinChunk.WriteChunk(emidChunk);
                }

                diinChunk.FlushToStream(outStream);
            }
        }
Exemplo n.º 4
0
        private void WriteSuffixComments(Stream outStream)
        {
            var comtChunk  = new DsdChunksContainer(DsdChunk.IdType.COMT);
            var comtSource = GetChunkById(DsdChunk.IdType.COMT);

            var numComments = 3;

            if (comtSource != null)
            {
                numComments += comtSource.Comments.Length;
            }

            comtChunk.WriteUInt16((ushort)numComments);

            PutCommentIntoChunk(comtChunk, new DsdChunk.DsdComment
            {
                Ref       = 0,
                Type      = 3,
                TimeStamp = DateTime.Now,
                Text      = "File was processed in DSDXOVER software crossover by dePhonica sound labs."
            });

            PutCommentIntoChunk(comtChunk, new DsdChunk.DsdComment
            {
                Ref       = 0,
                Type      = 3,
                TimeStamp = DateTime.Now,
                Text      = "(C) 2010-" + DateTime.Now.Year + " dePhonica sound labs."
            });

            PutCommentIntoChunk(comtChunk, new DsdChunk.DsdComment
            {
                Ref       = 0,
                Type      = 3,
                TimeStamp = DateTime.Now,
                Text      = "http://dephonica.com - dePhonica sound labs. official site"
            });

            if (comtSource != null)
            {
                foreach (var dsdComment in comtSource.Comments)
                {
                    PutCommentIntoChunk(comtChunk, dsdComment);
                }
            }

            comtChunk.FlushToStream(outStream);
        }
Exemplo n.º 5
0
        private void PutCommentIntoChunk(DsdChunksContainer comtChunk, DsdChunk.DsdComment comment)
        {
            DsdChunksContainer.WriteUInt16(comtChunk.GetStream(), (ushort)comment.TimeStamp.Year);
            DsdChunksContainer.WriteUInt8(comtChunk.GetStream(), (byte)comment.TimeStamp.Month);
            DsdChunksContainer.WriteUInt8(comtChunk.GetStream(), (byte)comment.TimeStamp.Day);
            DsdChunksContainer.WriteUInt8(comtChunk.GetStream(), (byte)comment.TimeStamp.Hour);
            DsdChunksContainer.WriteUInt8(comtChunk.GetStream(), (byte)comment.TimeStamp.Minute);

            DsdChunksContainer.WriteUInt16(comtChunk.GetStream(), comment.Type);
            DsdChunksContainer.WriteUInt16(comtChunk.GetStream(), comment.Ref);

            if ((comment.Text.Length % 2) != 0)
            {
                comment.Text += " ";
            }
            DsdChunksContainer.WriteInt32(comtChunk.GetStream(), comment.Text.Length);
            DsdChunksContainer.WriteIdString(comtChunk.GetStream(), comment.Text);
        }
Exemplo n.º 6
0
        private void WriteHeader()
        {
            // DSDIFF signature
            DsdChunksContainer.WriteId(_outStream, DsdChunk.IdType.FRM8);
            DsdChunksContainer.WriteInt64(_outStream, 0);  // Will write correct data size later
            DsdChunksContainer.WriteId(_outStream, DsdChunk.IdType.DSD);

            // File version
            DsdChunksContainer.WriteId(_outStream, DsdChunk.IdType.FVER);
            DsdChunksContainer.WriteInt64(_outStream, 4);
            DsdChunksContainer.WriteUInt32(_outStream, 0x01050000);

            // Properties composed chunk
            var propChunk = new DsdChunksContainer(DsdChunk.IdType.PROP);

            propChunk.WriteId(DsdChunk.IdType.SND);

            // > FS - frequency
            var fsChunk = new DsdChunksContainer(DsdChunk.PropChunk.FS);

            fsChunk.WriteUInt32(2822400);

            // > CHNL - channels
            var chnlChunk = new DsdChunksContainer(DsdChunk.PropChunk.CHNL);

            chnlChunk.WriteUInt16(_channelsCount);

            var chnlId = new[] { "SLFT", "SRGT", "MLFT", "MRGT", "LS", "RS", "C", "LFE",
                                 "C000", "C001", "C002", "C003", "C004", "C005", "C006", "C007", "C008", "C009" };

            for (var n = 0; n < _channelsCount; n++)
            {
                chnlChunk.WriteIdString(chnlId[n]);
            }

            // > CMPR - compression
            var cmprChunk = new DsdChunksContainer(DsdChunk.PropChunk.CMPR);

            cmprChunk.WriteIdString("DSD");

            const string compressorName = "not compressed ";

            cmprChunk.WriteUInt8((byte)compressorName.Length);
            cmprChunk.WriteIdString(compressorName);

            // > ABSS - absolute start time chunk
            var abssChunk = new DsdChunksContainer(DsdChunk.PropChunk.ABSS);

            abssChunk.WriteUInt16(0);
            abssChunk.WriteUInt8(0);
            abssChunk.WriteUInt8(0);
            abssChunk.WriteUInt32(0);

            // > LSCO - loudspeaker configuration
            var lscoChunk = new DsdChunksContainer(DsdChunk.PropChunk.LSCO);

            lscoChunk.WriteUInt16((ushort)(_channelsCount <= 2 ? 0 : 4));

            // << Write all property chunks info container
            propChunk.WriteChunk(fsChunk);
            propChunk.WriteChunk(chnlChunk);
            propChunk.WriteChunk(cmprChunk);
            //propChunk.WriteChunk(abssChunk);
            propChunk.WriteChunk(lscoChunk);

            // Write property chunk info the file
            propChunk.FlushToStream(_outStream);

            // Begin DSD section
            DsdChunksContainer.WriteId(_outStream, DsdChunk.IdType.DSD);
            _dsdLengthPosition = _outStream.Position;
            DsdChunksContainer.WriteInt64(_outStream, 0);
        }
Exemplo n.º 7
0
 public void WriteChunk(DsdChunksContainer chunk)
 {
     chunk.FlushToStream(_memStream);
 }