Пример #1
0
        static long GetRiffValue(FileStream fs, string chunk, string offset)
        {
            long ret = DEFAULT_LOOP_VALUE;

            // riff values
            RiffCalculatingOffsetDescription riffCalculatingOffset = new RiffCalculatingOffsetDescription();

            riffCalculatingOffset.RelativeLocationToRiffChunkString = RiffCalculatingOffsetDescription.START_OF_STRING;
            riffCalculatingOffset.OffsetSize      = "4";
            riffCalculatingOffset.OffsetByteOrder = Constants.LittleEndianByteOrder;

            try
            {
                riffCalculatingOffset.RiffChunkString = chunk;
                riffCalculatingOffset.OffsetValue     = offset;

                ret = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, riffCalculatingOffset, true);
            }
            catch (IndexOutOfRangeException iorEx)
            {
                // Console.WriteLine(String.Format("Error processing RIFF item for <{0}>: {1}", Path.GetFileName(fs.Name), iorEx.Message));
            }

            return(ret);
        }
Пример #2
0
        public static long GetSampleCountForRiffHeaderedFile(string path)
        {
            long sampleCount = -1;

            ushort channelCount;
            uint   dataSize;

            RiffCalculatingOffsetDescription riffValue = new RiffCalculatingOffsetDescription();

            // get values from file
            using (FileStream fs = File.OpenRead(path))
            {
                // over kill, but i don't feel like recoding it
                riffValue.CalculationString = String.Empty;
                riffValue.OffsetByteOrder   = Constants.LittleEndianByteOrder;
                riffValue.OffsetSize        = "2";
                riffValue.OffsetValue       = "10";
                riffValue.RelativeLocationToRiffChunkString = RiffCalculatingOffsetDescription.START_OF_STRING;
                riffValue.RiffChunkString = "fmt ";

                channelCount = (ushort)ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, riffValue, true);

                riffValue.CalculationString = String.Empty;
                riffValue.OffsetByteOrder   = Constants.LittleEndianByteOrder;
                riffValue.OffsetSize        = "4";
                riffValue.OffsetValue       = "4";
                riffValue.RelativeLocationToRiffChunkString = RiffCalculatingOffsetDescription.START_OF_STRING;
                riffValue.RiffChunkString = "data";

                dataSize = (uint)ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, riffValue, true);

                sampleCount = (long)dataSize / 2 / (long)channelCount;
            } // using (FileStream fs = File.OpenRead(path))

            return(sampleCount);
        }
Пример #3
0
        // DoTaskForFile
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPosFileCreatorStruct,
                                              DoWorkEventArgs e)
        {
            PosFileCreatorStruct posStruct = (PosFileCreatorStruct)pPosFileCreatorStruct;

            WorkingItemStruct currentItem = new WorkingItemStruct();

            long loopStartValue = DEFAULT_LOOP_VALUE;
            long loopEndValue   = DEFAULT_LOOP_VALUE;

            string outputFileMask;

            string[] outputFileList;

            outputFileMask = posStruct.OutputFileMask.Replace(FILEMASK_BASE_NAME, Path.GetFileNameWithoutExtension(pPath));
            outputFileMask = outputFileMask.Replace(FILEMASK_EXTENSION, Path.GetExtension(pPath).Remove(0, 1));

            #region LOOP POINTS
            using (FileStream fs = File.OpenRead(pPath))
            {
                currentItem.Initialize();

                try
                {
                    //----------------
                    // Get Loop Start
                    //----------------
                    if (posStruct.DoLoopStartStatic)
                    {
                        loopStartValue = ByteConversion.GetLongValueFromString(posStruct.LoopStartStaticValue);
                    }
                    else if (posStruct.DoLoopStartOffset)
                    {
                        loopStartValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartCalculatingOffset, true);
                    }
                    else if (posStruct.DoLoopStartRiffOffset)
                    {
                        try
                        {
                            loopStartValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartRiffCalculatingOffset, true);
                        }
                        catch (IndexOutOfRangeException iorEx)
                        {
                            this.progressStruct.Clear();
                            this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop Start for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine);
                            ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);
                        }
                    }
                    else if (posStruct.DoLoopStartByteStringOffset)
                    {
                        loopStartValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartByteSearchCalculatingOffset, true);
                    }

                    if ((loopStartValue != DEFAULT_LOOP_VALUE) && ((int)loopStartValue >= 0))
                    {
                        //----------------
                        // Get Loop End
                        //----------------
                        if (posStruct.DoLoopEndStatic)
                        {
                            loopEndValue = ByteConversion.GetLongValueFromString(posStruct.LoopEndStaticValue);
                        }
                        else if (posStruct.DoLoopEndOffset)
                        {
                            loopEndValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndCalculatingOffset, true);
                        }
                        else if (posStruct.DoLoopEndRiffOffset)
                        {
                            try
                            {
                                loopEndValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndRiffCalculatingOffset, true);
                            }
                            catch (IndexOutOfRangeException iorEx)
                            {
                                this.progressStruct.Clear();
                                this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop End for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine);
                                ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);
                            }
                        }
                        else if (posStruct.DoLoopEndByteStringOffset)
                        {
                            loopEndValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndByteSearchCalculatingOffset, true);
                        }

                        if ((loopEndValue != DEFAULT_LOOP_VALUE) && (loopEndValue >= 0))
                        {
                            // Calculate Loop End if Needed
                            if (posStruct.LoopEndIsLoopLength)
                            {
                                loopEndValue += loopStartValue;
                            }

                            if (loopStartValue < loopEndValue)
                            {
                                // update working item
                                currentItem.LoopStart = loopStartValue;
                                currentItem.LoopEnd   = loopEndValue;
                            }
                            else
                            {
                                throw new Exception(String.Format("Loop Start Value greater than or equal Loop End Value: {0}", pPath));
                            }
                        }
                        else
                        {
                            throw new IndexOutOfRangeException(String.Format("Loop End Value not Found or Loop End is Less than 0: {0}", pPath));
                        }
                    }
                    else
                    {
                        throw new IndexOutOfRangeException(String.Format("Loop Start Value not Found or Loop Start is Less than 0: {0}", pPath));
                    }
                }
                catch (Exception ex)
                {
                    this.progressStruct.Clear();
                    this.progressStruct.GenericMessage = String.Format("Cannot find loop points for <{0}>: {1}{2}", Path.GetFileName(pPath), ex.Message, Environment.NewLine);
                    ReportProgress(Constants.ProgressMessageOnly, this.progressStruct);
                }
            }
            #endregion

            #region LOOP SHIFT

            // get list of matching WAV files
            outputFileList = Directory.GetFiles(Path.GetDirectoryName(pPath), outputFileMask, SearchOption.TopDirectoryOnly);

            // loop over list and add each item to the dictionary
            foreach (string outputFile in outputFileList)
            {
                // only shift valid values
                if ((loopStartValue != DEFAULT_LOOP_VALUE) && (loopEndValue != DEFAULT_LOOP_VALUE))
                {
                    // Static Loop Shift
                    if (posStruct.DoStaticLoopShift)
                    {
                        // update shift
                        currentItem.LoopShift = ByteConversion.GetLongValueFromString(posStruct.StaticLoopShiftValue);
                    }
                    else if (posStruct.DoLoopShiftWavCompare) // Wav Compare
                    {
                        // get samplecount for this file
                        currentItem.WavSamples       = GetSampleCountForRiffHeaderedFile(outputFile);
                        currentItem.SampleDifference = currentItem.WavSamples - currentItem.LoopEnd;

                        // update shift
                        currentItem.LoopShift = currentItem.SampleDifference;
                    }
                }

                this.WorkingList.Add(outputFile, currentItem);
            }

            #endregion
        }