コード例 #1
0
        public static void LoadAudio(AudioStream audioStream)
        {
            // abort if audio data already loaded
            if (audioStream.IsAudioLoaded())
            {
                return;
            }

            AudioDataHelper.LoadAudioData(audioStream);

            var channel = Bass.BASS_StreamCreateFile(audioStream.AudioData.DataPointer,
                                                     0,
                                                     audioStream.AudioData.Data.Length,
                                                     BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);

            audioStream.AddChannel(channel);

            if (audioStream.ChannelId == 0)
            {
                throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode());
            }

            // DebugHelper.WriteLine("Creating reverse FX stream " + audioStream.Description + "...");
            audioStream.AddChannel(BassFx.BASS_FX_ReverseCreate(audioStream.ChannelId, 1, BASSFlag.BASS_STREAM_DECODE));

            if (audioStream.ChannelId == 0)
            {
                throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode());
            }

            Bass.BASS_ChannelSetAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_REVERSE_DIR,
                                          (float)BASSFXReverse.BASS_FX_RVS_FORWARD);


            // DebugHelper.WriteLine("Creating tempo FX stream " + audioStream.Description + "...");

            audioStream.AddChannel(BassFx.BASS_FX_TempoCreate(audioStream.ChannelId,
                                                              BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE));

            if (audioStream.ChannelId == 0)
            {
                throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode());
            }

            // DebugHelper.WriteLine("Calculating track length " + audioStream.Description + "...");

            audioStream.Length            = Bass.BASS_ChannelGetLength(audioStream.ChannelId);
            audioStream.DefaultSampleRate = GetSampleRate(audioStream.ChannelId);

            SetReplayGain(audioStream);
            SetPosition(audioStream, 0);
        }