예제 #1
0
        public sidPlayAudioCore(byte[] sidFileBytes, int sampleRate = 44100, int channels = 2)
        {
            try
            {
                sidTune = new SidTune(new MemoryStream(sidFileBytes));
                sidTune.selectSong(0);
            }
            catch (Exception ex)
            {
                throw new AudioEngineException(0, "[sidPlayAudioCore] Exception when loading the tune...", ex);
            }

            player = new sidPlayer();

            Title     = sidTune.Info.InfoString1;
            Author    = sidTune.Info.InfoString2;
            Copyright = sidTune.Info.InfoString3;

            var tmpTuneLoaded = player.load(sidTune);

            IsTuneLoaded = tmpTuneLoaded == 0;
            IsTuneFaulty = tmpTuneLoaded == -2;

            var sidCfg = player.config();

            sidCfg.clockForced  = false;
            sidCfg.clockSpeed   = SID2Types.sid2_clock_t.SID2_CLOCK_CORRECT;
            sidCfg.clockDefault = SID2Types.sid2_clock_t.SID2_CLOCK_CORRECT;
            sidCfg.frequency    = sampleRate;
            sidCfg.playback     =
                channels != 1 ? SID2Types.sid2_playback_t.sid2_stereo : SID2Types.sid2_playback_t.sid2_mono;
            sidCfg.precision = 16;

            sidCfg.sidModel      = SID2Types.sid2_model_t.SID2_MODEL_CORRECT;
            sidCfg.sidDefault    = SID2Types.sid2_model_t.SID2_MODEL_CORRECT;
            sidCfg.sidSamples    = true;
            sidCfg.environment   = SID2Types.sid2_env_t.sid2_envR;
            sidCfg.forceDualSids = false;
            sidCfg.optimisation  = 2;

            if (player.config(sidCfg) != 0)
            {
                Dispose();
                return;
            }

            try
            {
                wavePlayer = new WaveOut();
                wavePlayer.Init(new sidWaveOut(sampleRate, channels, player));
            }
            catch (NAudio.MmException ex)
            {
                throw new AudioEngineException(0, "[sidPlayAudioCore] NAudio initialization exception!", ex);
            }

            IsPlaying = false;
            IsPaused  = false;
        }
예제 #2
0
파일: sid.cs 프로젝트: hiroshica/MDPlayer
        private void SidInit(byte[] vgmBuf)
        {
            sidemu.output.OUTPUTBUFFERSIZE = setting.sid.OutputBufferSize;

            byte[] aryKernal    = null;
            byte[] aryBasic     = null;
            byte[] aryCharacter = null;
            if (File.Exists(setting.sid.RomKernalPath))
            {
                using (FileStream fs = new FileStream(setting.sid.RomKernalPath, FileMode.Open, FileAccess.Read))
                {
                    aryKernal = new byte[fs.Length];
                    fs.Read(aryKernal, 0, aryKernal.Length);
                }
            }
            if (File.Exists(setting.sid.RomBasicPath))
            {
                using (FileStream fs = new FileStream(setting.sid.RomBasicPath, FileMode.Open, FileAccess.Read))
                {
                    aryBasic = new byte[fs.Length];
                    fs.Read(aryBasic, 0, aryBasic.Length);
                }
            }
            if (File.Exists(setting.sid.RomCharacterPath))
            {
                using (FileStream fs = new FileStream(setting.sid.RomCharacterPath, FileMode.Open, FileAccess.Read))
                {
                    aryCharacter = new byte[fs.Length];
                    fs.Read(aryCharacter, 0, aryCharacter.Length);
                }
            }

            m_engine = new sidplayfp();
            m_engine.debug(false, null);
            m_engine.setRoms(aryKernal, aryBasic, aryCharacter);

            ReSIDBuilder rs = new ReSIDBuilder("ReSID");

            uint maxsids = (m_engine.info()).maxsids();

            rs.create(maxsids);

            SidTune tune = new SidTune(vgmBuf, (uint)vgmBuf.Length);

            tune.selectSong((uint)song);

            if (!m_engine.load(tune))
            {
                System.Console.WriteLine("Error: " + m_engine.error());
                return;
            }

            // Get tune details
            global::Driver.libsidplayfp.sidplayfp.SidTuneInfo tuneInfo = tune.getInfo();
            //if (!m_track.single)
            //    m_track.songs = (UInt16)tuneInfo.songs();
            //if (!createOutput(m_driver.output, tuneInfo))
            //    return false;
            //if (!createSidEmu(m_driver.sid))
            //    return false;

            SidConfig cfg = new SidConfig();

            cfg.frequency      = (uint)common.SampleRate;
            cfg.samplingMethod = (setting.sid.Quality & 2) == 0 ? SidConfig.sampling_method_t.INTERPOLATE : SidConfig.sampling_method_t.RESAMPLE_INTERPOLATE;
            cfg.fastSampling   = (setting.sid.Quality & 1) == 0;
            cfg.playback       = SidConfig.playback_t.STEREO;
            cfg.sidEmulation   = rs;

            if (!m_engine.config(ref cfg))
            {
                System.Console.WriteLine("Error: " + m_engine.error());
                return;
            }
        }