Exemplo n.º 1
0
        public SoundclusterDls(RiffDls_Riff aDls_Riff)
        {
            BankDictionary = new Dictionary <int, ABank>();

            RiffDls_Riff dls_Riff = aDls_Riff;

            List <WaveformReaderPcm> lWaveformList = new List <WaveformReaderPcm>();

            try
            {
                Logger.Error(dls_Riff.GetChunk("LIST").GetType().ToString());
                RiffChunkList        lRiffChunkList = ( RiffChunkList )dls_Riff.GetChunk("LIST");
                List <RiffChunkList> wvplListList   = lRiffChunkList.GetChunkListList("LIST", RiffChunkListWvpl.TYPE);
                //RiffChunkListWvpl wvplList = ( RiffChunkListWvpl )dls_Riff.wvplListList;

                List <RiffChunkList> waveListList = wvplListList[0].GetChunkListList("LIST", RiffChunkListWave.TYPE);

                for (int i = 0; i < waveListList.Count; i++)
                {
                    RiffChunkListWave lWaveList = ( RiffChunkListWave )waveListList[i];

                    lWaveformList.Add(new WaveformReaderPcm(lWaveList, dls_Riff.name));
                }

                RiffChunkListLins linsList = ( RiffChunkListLins )dls_Riff.linsListList;

                Logger.Warning("linsList.ins_ListList.Count:" + linsList.ins_ListList.Count);

                for (int i = 0; i < linsList.ins_ListList.Count; i++)
                {
                    RiffChunkListIns_ ins_List = ( RiffChunkListIns_ )linsList.ins_ListList[i];

                    RiffDls_Insh inshChunk = ( RiffDls_Insh )ins_List.inshChunk;

                    int bank = ( int )inshChunk.midiLocal.bank;

                    if (( uint )bank == 0x80000000)
                    {
                        Logger.Warning("Change Bank:" + bank.ToString("X8"));

                        bank = 0x7F00;
                    }

                    if (BankDictionary.ContainsKey(bank) == false)
                    {
                        Logger.Warning("Bank:" + bank.ToString("X8"));
                        BankDictionary.Add(bank, new BankDls());
                    }

                    BankDls lDlsBank = ( BankDls )BankDictionary[bank];
                    lDlsBank.AddInstrument(ins_List, lWaveformList);
                }
            }
            catch (Exception aExpection)
            {
                Logger.Error("Expection at RIFF Read:" + aExpection.ToString());
            }
        }
Exemplo n.º 2
0
        public SoundclusterDls(RiffFile aRiffFile)
            : base()
        {
            RiffChunkListDls_ dls_Riff = ( RiffChunkListDls_ )aRiffFile.riffChunkList;

            List <WaveformBase> lWaveformList = new List <WaveformBase>();

            try
            {
                RiffChunkListWvpl wvplList = ( RiffChunkListWvpl )dls_Riff.wvplListList;

                for (int i = 0; i < wvplList.waveListList.Count; i++)
                {
                    RiffChunkListWave lWaveList = ( RiffChunkListWave )wvplList.waveListList[i];

                    lWaveformList.Add(new WaveformDls(lWaveList, aRiffFile.name));
                }

                RiffChunkListLins linsList = ( RiffChunkListLins )dls_Riff.linsListList;

                Logger.LogWarning("linsList.ins_ListList.Count:" + linsList.ins_ListList.Count);

                for (int i = 0; i < linsList.ins_ListList.Count; i++)
                {
                    RiffChunkListIns_ ins_List = ( RiffChunkListIns_ )linsList.ins_ListList[i];

                    RiffChunkInsh inshChunk = ( RiffChunkInsh )ins_List.inshChunk;

                    int bank = ( int )inshChunk.midiLocal.bank;

                    if (( uint )bank == 0x80000000)
                    {
                        Logger.LogWarning("Change Bank:" + bank.ToString("X8"));

                        bank = 0x7F00;
                    }

                    if (bankDictionary.ContainsKey(bank) == false)
                    {
                        Logger.LogWarning("Bank:" + bank.ToString("X8"));
                        bankDictionary.Add(bank, new BankDls());
                    }

                    BankDls lDlsBank = ( BankDls )bankDictionary[bank];
                    lDlsBank.AddInstrument(ins_List, lWaveformList);
                }
            }
            catch (Exception aExpection)
            {
                Logger.LogError("Expection at RIFF Read:" + aExpection.ToString());
            }
        }
Exemplo n.º 3
0
        public WaveformWave(RiffFile aRiffFile)
            : base()
        {
            RiffChunkListWave lWaveList = ( RiffChunkListWave )aRiffFile.riffChunkList;

            int lPosition = ( int )lWaveList.dataChunk.position;
            int lLength   = ( int )lWaveList.dataChunk.size;

            int lChannels   = lWaveList.fmt_Chunk.channels;
            int lSampleRate = ( int )lWaveList.fmt_Chunk.samplesPerSec;
            int lSampleBits = lWaveList.fmt_Chunk.bitsPerSample;
            int lSamples    = lLength / (lSampleBits / 8) / lChannels;

            format = new FormatWaweform(lChannels, lSamples, lSampleRate, lSampleBits);
            data   = new WaveformData(format, null, aRiffFile.name, lPosition);
        }
Exemplo n.º 4
0
        public WaveformDls(RiffChunkListWave aWaveList, string aName)
            : base()
        {
            RiffChunkFmt_ fmt_Chunk = aWaveList.fmt_Chunk;
            RiffChunkData dataChunk = aWaveList.dataChunk;

            int position = ( int )dataChunk.position;
            int length   = ( int )dataChunk.size;

            int channels   = fmt_Chunk.channles;
            int sampleRate = ( int )fmt_Chunk.samplesPerSec;
            int sampleBits = ( int )fmt_Chunk.bitsPerSample;
            int samples    = length / (sampleBits / 8) / channels;

            format = new FormatWaweform(channels, samples, sampleRate, sampleBits);
            data   = new WaveformData(format, null, aName, position);
        }
Exemplo n.º 5
0
        public WaveformReaderPcm(RiffChunkListWave aWaveList, string aName)
            : base()
        {
            RiffDls_Fmt_ fmt_Chunk = aWaveList.fmt_Chunk;
            RiffDls_Data dataChunk = aWaveList.dataChunk;

            int position = ( int )dataChunk.position;
            int length   = ( int )dataChunk.Size;

            int channels   = fmt_Chunk.channles;
            int sampleRate = ( int )fmt_Chunk.samplesPerSec;
            int sampleBits = ( int )fmt_Chunk.bitsPerSample;
            int samples    = length / (sampleBits / 8) / channels;

            format = new WaweformFormat(channels, samples, sampleRate, sampleBits);
            reader = new WaveformReader(format, aName, position, true, AByteArray.Endian.Little);
        }
Exemplo n.º 6
0
        public static void Execute(FileInfo aFileInput, string aFilePathOutput, List <double> aProgressList, int aIndex)
        {
            RiffFile          lRiffFile          = ( RiffFile )PoolCollection.poolWav.Get(aFileInput.FullName);
            RiffChunkListWave lRiffChunkListWave = ( RiffChunkListWave )lRiffFile.riffChunkList;

            WaveformBase waveform = LoaderWaveform.Load(aFileInput.FullName);

            SByte[] lSampleArray = new SByte[waveform.format.samples];

            for (int i = 0; i < waveform.format.samples; i++)
            {
                lSampleArray[i] = ( SByte )(waveform.data.GetSampleData(0, i) >> 8);
            }

            List <LoopInformation> lLoopList = null;

            try
            {
                lLoopList = LoopSearchTool.Execute(lSampleArray, aProgressList, aIndex);
            }
            catch (Exception aExpection)
            {
                UnityEngine.Debug.Log(aExpection.ToString() + ":LoopTool Exception");
            }

            //for( int i = 0; i < lLoopList.Count; i++ )
            if (lLoopList.Count >= 1)
            {
                //lRiffChunkListWave.AddCuePoint( ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
                //lRiffChunkListWave.AddSampleLoop( ( int )lLoopList[i].start.sample, ( int )lLoopList[i].end.sample );
                lRiffChunkListWave.AddCuePoint(( int )lLoopList[0].start.sample, ( int )lLoopList[0].end.sample);
                lRiffChunkListWave.AddSampleLoop(( int )lLoopList[0].start.sample, ( int )lLoopList[0].end.sample);
            }

            Byte[] lDataArrayRead = null;

            using (FileStream u = new FileStream(lRiffFile.name, FileMode.Open, FileAccess.Read))
            {
                ByteArray l = new ByteArrayLittle(u);

                int bytePosition = ( int )lRiffChunkListWave.dataChunk.position;

                l.SetPosition(bytePosition);

                lDataArrayRead = l.ReadBytes(lRiffChunkListWave.dataChunk.size);
            }

            Byte[] lDataArrayWrite = lDataArrayRead;

            if (IsCutLast == true)
            {
                lDataArrayWrite = new Byte[(( int )lLoopList[0].end.sample + 1) * 4];

                for (int i = 0; i < (lLoopList[0].end.sample + 1) * 4; i++)
                {
                    lDataArrayWrite[i] = lDataArrayRead[i];
                }
            }

            for (int i = 0; i < 64; i++)
            {
                Logger.LogDebug(i.ToString() + ":" + lDataArrayWrite[i]);
            }

            lRiffChunkListWave.SetDataArray(lDataArrayWrite);

            MemoryStream    lMemoryStreamWrite = new MemoryStream(( int )lRiffChunkListWave.size + 8);
            ByteArrayLittle lByteArray         = new ByteArrayLittle(lMemoryStreamWrite);

            //lByteArrayRead.Open();
            lRiffFile.WriteByteArray(null, lByteArray);
            //lByteArrayRead.Close();

            using (FileStream u = new FileStream(aFilePathOutput, FileMode.Create, FileAccess.Write))
            {
                u.Write(lMemoryStreamWrite.GetBuffer(), 0, ( int )lMemoryStreamWrite.Length);
            }
        }
Exemplo n.º 7
0
        public MusicWave(RiffFile aRiffFile)
        {
            RiffChunkListWave lWaveRiff = ( RiffChunkListWave )aRiffFile.riffChunkList;

            nameFile     = aRiffFile.name;
            bytePosition = ( int )lWaveRiff.dataChunk.position;
            byteSize     = ( int )lWaveRiff.dataChunk.size;

            Channels     = lWaveRiff.fmt_Chunk.channels;
            SampleRate   = ( int )lWaveRiff.fmt_Chunk.samplesPerSec;
            sampleBits   = lWaveRiff.fmt_Chunk.bitsPerSample;
            SampleLength = ( int )(byteSize / (sampleBits / 8) / Channels);

            sampleArray = new float[Channels][];

            if (LENGTH_BUFFER == 0)
            {
                lengthBuffer = SampleLength;
            }
            else
            {
                lengthBuffer = LENGTH_BUFFER;
            }

            for (int i = 0; i < Channels; i++)
            {
                sampleArray[i] = new float[lengthBuffer];
            }

            startPosition = 0x7FFFFFFF;

            if (lWaveRiff.smplChunk != null)
            {
                Loop = new List <List <LoopInformation> >();

                int lIndex      = -1;
                int lLoopLength = -1;

                for (int i = 0; i < lWaveRiff.smplChunk.sampleLoops; i++)
                {
                    SampleLoop lLoop = lWaveRiff.smplChunk.sampleLoopList[i];

                    if (( int )(lLoop.end - lLoop.start) == lLoopLength)
                    {
                    }
                    else
                    {
                        Loop.Add(new List <LoopInformation>());
                        lLoopLength = ( int )(lLoop.end - lLoop.start);
                        lIndex++;
                    }

                    Loop[lIndex].Add(new LoopInformation(SampleRate, ( int )lLoop.start, ( int )lLoop.end));
                }
            }
            else
            {
                Loop = new List <List <LoopInformation> >();
                Loop.Add(new List <LoopInformation>());
                Loop[0].Add(new LoopInformation(SampleRate, 0, 0));
            }
        }