コード例 #1
0
        public void ProduceFullAudioClipData(FullAudioClipData fullAudioClipData)
        {
            string            ResourcesRootDirectory = BmsChartFolder;
            BmsAudioGenerator bmsAudioGenerator      = new BmsAudioGenerator(44100, 2);
            int TotalCount  = NativeBmsChart.Events.Count;
            int LoadedCount = 0;

            foreach (BMSEvent Event in NativeBmsChart.Events)
            {
                switch (Event.type)
                {
                case BMSEventType.LongNoteEnd:
                case BMSEventType.LongNoteStart:
                case BMSEventType.Note:
                case BMSEventType.WAV:
                    BMSResourceData resourceData = new BMSResourceData();
                    if (!NativeBmsChart.TryGetResourceData(ResourceType.wav, Event.data2, out resourceData))
                    {
                        continue;
                    }
                    string FileName        = Path.GetFileNameWithoutExtension(resourceData.dataPath);
                    string OggResourcePath = (ResourcesRootDirectory + "/" + FileName + ".ogg").Replace("\\", "/");
                    string WavResourcePath = (ResourcesRootDirectory + "/" + FileName + ".wav").Replace("\\", "/");
                    if (File.Exists(OggResourcePath))
                    {
                        NVorbis.VorbisReader vorbisReader = new NVorbis.VorbisReader(OggResourcePath);
                        float[] oggData = new float[vorbisReader.TotalSamples * vorbisReader.Channels];
                        vorbisReader.ReadSamples(oggData, 0, (int)(vorbisReader.TotalSamples * vorbisReader.Channels));
                        bmsAudioGenerator.PutAudioAt((float)Event.time.TotalSeconds, oggData);
                    }
                    else if (File.Exists(WavResourcePath))
                    {
                        List <float> wavData = new List <float>();
                        NAudio.Wave.WaveFileReader waveFileReader = new NAudio.Wave.WaveFileReader(WavResourcePath);
                        float[] wavFrame;
                        while (true)
                        {
                            wavFrame = waveFileReader.ReadNextSampleFrame();
                            if (wavFrame == null)
                            {
                                break;
                            }
                            wavData.AddRange(wavFrame);
                        }
                        bmsAudioGenerator.PutAudioAt((float)Event.time.TotalSeconds, wavData.ToArray());
                    }
                    break;
                }
                LoadedCount++;
                fullAudioClipData.Percent = 100f * LoadedCount / TotalCount;
            }
            fullAudioClipData.Data        = bmsAudioGenerator.Data;
            fullAudioClipData.IsCompleted = true;
        }
コード例 #2
0
 public Task ProduceFullAudioClipDataAsync(FullAudioClipData fullAudioClipData)
 {
     return(Task.Run(() => ProduceFullAudioClipData(fullAudioClipData)));
 }