コード例 #1
0
ファイル: stella.cpp プロジェクト: CraigularB/Provenance
static void	Emulate (EmulateSpecStruct *espec)
{
    Fir_Resampler<8>* Resampler;
    //AUDIO PREP
    //Resampler::Init(espec, 34100.0);
    
    
    //INPUT
    //Update stella's event structure
    for(int i = 0; i != 2; i ++)
    {
        //Get the base event id for this port
        Event::Type baseEvent = (i == 0) ? Event::JoystickZeroUp : Event::JoystickOneUp;
        
        //Get the input data for this port and stuff it in the event structure
        //uint32_t inputState = Input::GetPort<3>(i);
        uint32_t inputState;
        for(int j = 0; j != 19; j ++, inputState >>= 1)
        {
            mdfnStella->GameConsole->event().set((Event::Type)(baseEvent + j), inputState & 1);
        }
    }
    
    uint16 butt_data = chee[0] | (chee[1] << 8);
    
    //mdfnStella->SetButtonData(butt_data);
    
    //Update the reset and select events
    //uint32_t inputState = Input::GetPort<0, 3>() >> 19;
    uint32_t inputState;
    mdfnStella->GameConsole->event().set(Event::ConsoleSelect, inputState & 1);
    mdfnStella->GameConsole->event().set(Event::ConsoleReset, inputState & 2);
    
    //Tell all input devices to read their state from the event structure
    mdfnStella->GameConsole->switches().update();
    mdfnStella->GameConsole->controller(Controller::Left).update();
    mdfnStella->GameConsole->controller(Controller::Right).update();
    
    //CHEATS
    MDFNMP_ApplyPeriodicCheats();
    
    //EMULATE
    mdfnStella->GameConsole->tia().update();
    
    //	if(myOSystem->eventHandler().frying())
    //		myOSystem->GameConsole().fry();
    
    //VIDEO: TODO: Support other color formats
    //Get the frame info from stella
    Int32 frameWidth = mdfnStella->GameConsole->tia().width();
    Int32 frameHeight = mdfnStella->GameConsole->tia().height();
    
    //printf("frameWidth %d\n", frameWidth);
    //printf("frameHeight %d\n", frameHeight);
    
    
    //Setup the output area for mednafen, never allow stella's size to excede mednafen's
    //Video::SetDisplayRect(espec, 0, 0, frameWidth, frameHeight);
    espec->DisplayRect.x = 0;
    espec->DisplayRect.y = 0;
    espec->DisplayRect.w = frameWidth;
    espec->DisplayRect.h = frameHeight;
    
    //Copy the frame from stella to mednafen
    //Video::BlitPalette<0xFF>(espec, mdfnStella->Palette, mdfnStella->GameConsole->tia().currentFrameBuffer(), frameWidth, frameHeight, frameWidth);
    //inline void __attribute((always_inline))                BlitPalette                                     (EmulateSpecStruct* espec, const pType* aPalette, const sType* aSource, uint32_t aWidth, uint32_t aHeight, uint32_t aPixelPitch)

        for(int i = 0; i != frameHeight; i ++)
        {
            for(int j = 0; j != frameWidth; j ++)
            {
                espec->surface->pixels[i * espec->surface->pitchinpix + j] = mdfnStella->Palette[mdfnStella->GameConsole->tia().currentFrameBuffer()[i * frameWidth + j] & 0xFF];
            }
        }
    
    //Player_Draw(espec->surface, &espec->DisplayRect, 0, espec->SoundBuf, espec->SoundBufSize);
    
    //AUDIO
    //Get the number of samples in a frame
    uint32_t soundFrameSize = 34100.0f / mdfnStella->GameConsole->getFramerate();
    
    //Process one frame of audio from stella
    uint8_t samplebuffer[2048];
    mdfnStella->Sound.processFragment(samplebuffer, soundFrameSize);
    
    //Convert and stash it in the resampler...
    for(int i = 0; i != soundFrameSize; i ++)
    {
        int16_t sample = (samplebuffer[i] << 8) - 32768;
        int16_t frame[2] = {sample, sample};
        //Resampler::Fill(frame, 2);
    }
    
    //Get the output
    //Resampler::Fetch(espec);
    assert(espec);
    if(Resampler && espec->SoundBuf && espec->SoundBufMaxSize)
    {
        uint32_t readsize = std::min(Resampler->avail() / 2, espec->SoundBufMaxSize);
        espec->SoundBufSize = Resampler->read(espec->SoundBuf, readsize) >> 1;
    }
コード例 #2
0
bool MDFNI_InitializeModules(const std::vector<MDFNGI *> &ExternalSystems)
{
    static MDFNGI *InternalSystems[] =
    {
#ifdef WANT_NES_EMU
        &EmulatedNES,
#endif

#ifdef WANT_SNES_EMU
        &EmulatedSNES,
#endif

#ifdef WANT_GB_EMU
        &EmulatedGB,
#endif

#ifdef WANT_GBA_EMU
        &EmulatedGBA,
#endif

#ifdef WANT_PCE_EMU
        &EmulatedPCE,
#endif

#ifdef WANT_PCE_FAST_EMU
        &EmulatedPCE_Fast,
#endif

#ifdef WANT_LYNX_EMU
        &EmulatedLynx,
#endif

#ifdef WANT_MD_EMU
        &EmulatedMD,
#endif

#ifdef WANT_PCFX_EMU
        &EmulatedPCFX,
#endif

#ifdef WANT_NGP_EMU
        &EmulatedNGP,
#endif

#ifdef WANT_PSX_EMU
        &EmulatedPSX,
#endif

#ifdef WANT_VB_EMU
        &EmulatedVB,
#endif

#ifdef WANT_WSWAN_EMU
        &EmulatedWSwan,
#endif

#ifdef WANT_SMS_EMU
        &EmulatedSMS,
        &EmulatedGG,
#endif

        &EmulatedCDPlay
    };
    std::string i_modules_string, e_modules_string;

    for(unsigned int i = 0; i < sizeof(InternalSystems) / sizeof(MDFNGI *); i++)
    {
        AddSystem(InternalSystems[i]);
        if(i)
            i_modules_string += " ";
        i_modules_string += std::string(InternalSystems[i]->shortname);
    }

    for(unsigned int i = 0; i < ExternalSystems.size(); i++)
    {
        AddSystem(ExternalSystems[i]);
        if(i)
            i_modules_string += " ";
        e_modules_string += std::string(ExternalSystems[i]->shortname);
    }

    MDFNI_printf(_("Internal emulation modules: %s\n"), i_modules_string.c_str());
    MDFNI_printf(_("External emulation modules: %s\n"), e_modules_string.c_str());


    for(unsigned int i = 0; i < MDFNSystems.size(); i++)
        MDFNSystemsPrio.push_back(MDFNSystems[i]);

    MDFNSystemsPrio.sort(MDFNSystemsPrio_CompareFunc);

#if 0
    std::string a_modules;

std::list<MDFNGI *>:
    iterator it;

    for(it = MDFNSystemsPrio.
             f
#endif

             CDUtility::CDUtility_Init();

            return(1);
}

int MDFNI_Initialize(const char *basedir, const std::vector<MDFNSetting> &DriverSettings)
{
    // FIXME static
    static std::vector<MDFNSetting> dynamic_settings;

    if(!MDFN_RunMathTests())
    {
        return(0);
    }


    memset(PortDataCache, 0, sizeof(PortDataCache));
    memset(PortDataLenCache, 0, sizeof(PortDataLenCache));
    memset(PortDeviceCache, 0, sizeof(PortDeviceCache));

    lzo_init();

    MDFNI_SetBaseDirectory(basedir);

    MDFN_InitFontData();

    // Generate dynamic settings
    for(unsigned int i = 0; i < MDFNSystems.size(); i++)
    {
        MDFNSetting setting;
        const char *sysname;

        sysname = (const char *)MDFNSystems[i]->shortname;

        if(!MDFNSystems[i]->soundchan)
            printf("0 sound channels for %s????\n", sysname);

        if(MDFNSystems[i]->soundchan == 2)
        {
            BuildDynamicSetting(&setting, sysname, "forcemono", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_SOUND, CSD_forcemono, MDFNST_BOOL, "0");
            dynamic_settings.push_back(setting);
        }

        BuildDynamicSetting(&setting, sysname, "enable", MDFNSF_COMMON_TEMPLATE, CSD_enable, MDFNST_BOOL, "1");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur, MDFNST_BOOL, "0");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur.accum", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur_accum, MDFNST_BOOL, "0");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur.accum.amount", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur_accum_amount, MDFNST_FLOAT, "50", "0", "100");
        dynamic_settings.push_back(setting);
    }

    if(DriverSettings.size())
        MDFN_MergeSettings(DriverSettings);

    // First merge all settable settings, then load the settings from the SETTINGS FILE OF DOOOOM
    MDFN_MergeSettings(MednafenSettings);
    MDFN_MergeSettings(dynamic_settings);
    MDFN_MergeSettings(MDFNMP_Settings);


    for(unsigned int x = 0; x < MDFNSystems.size(); x++)
    {
        if(MDFNSystems[x]->Settings)
            MDFN_MergeSettings(MDFNSystems[x]->Settings);
    }

    MDFN_MergeSettings(RenamedSettings);

    if(!MFDN_LoadSettings(basedir))
        return(0);

#ifdef WANT_DEBUGGER
    MDFNDBG_Init();
#endif

    return(1);
}

void MDFNI_Kill(void)
{
    MDFN_SaveSettings();
}

static double multiplier_save, volume_save;
static std::vector<int16> SoundBufPristine;

static void ProcessAudio(EmulateSpecStruct *espec)
{
    if(espec->SoundVolume != 1)
        volume_save = espec->SoundVolume;

    if(espec->soundmultiplier != 1)
        multiplier_save = espec->soundmultiplier;

    if(espec->SoundBuf && espec->SoundBufSize)
    {
        int16 *const SoundBuf = espec->SoundBuf + espec->SoundBufSizeALMS * MDFNGameInfo->soundchan;
        int32 SoundBufSize = espec->SoundBufSize - espec->SoundBufSizeALMS;
        const int32 SoundBufMaxSize = espec->SoundBufMaxSize - espec->SoundBufSizeALMS;


        if(qtrecorder && (volume_save != 1 || multiplier_save != 1))
        {
            int32 orig_size = SoundBufPristine.size();

            SoundBufPristine.resize(orig_size + SoundBufSize * MDFNGameInfo->soundchan);
            for(int i = 0; i < SoundBufSize * MDFNGameInfo->soundchan; i++)
                SoundBufPristine[orig_size + i] = SoundBuf[i];
        }

        if(espec->NeedSoundReverse)
        {
            int16 *yaybuf = SoundBuf;
            int32 slen = SoundBufSize;

            if(MDFNGameInfo->soundchan == 1)
            {
                for(int x = 0; x < (slen / 2); x++)
                {
                    int16 cha = yaybuf[slen - x - 1];
                    yaybuf[slen - x - 1] = yaybuf[x];
                    yaybuf[x] = cha;
                }
            }
            else if(MDFNGameInfo->soundchan == 2)
            {
                for(int x = 0; x < (slen * 2) / 2; x++)
                {
                    int16 cha = yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1];
                    yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1] = yaybuf[x];
                    yaybuf[x] = cha;
                }
            }
        }

        try
        {
            if(wavrecorder)
                wavrecorder->WriteSound(SoundBuf, SoundBufSize);
        }
        catch(std::exception &e)
        {
            MDFND_PrintError(e.what());
            delete wavrecorder;
            wavrecorder = NULL;
        }

        if(multiplier_save != LastSoundMultiplier)
        {
            ff_resampler.time_ratio(multiplier_save, 0.9965);
            LastSoundMultiplier = multiplier_save;
        }

        if(multiplier_save != 1)
        {
            if(FFDiscard)
            {
                if(SoundBufSize >= multiplier_save)
                    SoundBufSize /= multiplier_save;
            }
            else
            {
                if(MDFNGameInfo->soundchan == 2)
                {
                    assert(ff_resampler.max_write() >= SoundBufSize * 2);

                    for(int i = 0; i < SoundBufSize * 2; i++)
                        ff_resampler.buffer()[i] = SoundBuf[i];
                }
                else
                {
                    assert(ff_resampler.max_write() >= SoundBufSize * 2);

                    for(int i = 0; i < SoundBufSize; i++)
                    {
                        ff_resampler.buffer()[i * 2] = SoundBuf[i];
                        ff_resampler.buffer()[i * 2 + 1] = 0;
                    }
                }
                ff_resampler.write(SoundBufSize * 2);

                int avail = ff_resampler.avail();
                int real_read = std::min((int)(SoundBufMaxSize * MDFNGameInfo->soundchan), avail);

                if(MDFNGameInfo->soundchan == 2)
                    SoundBufSize = ff_resampler.read(SoundBuf, real_read ) >> 1;
                else
                    SoundBufSize = ff_resampler.read_mono_hack(SoundBuf, real_read );

                avail -= real_read;

                if(avail > 0)
                {
                    printf("ff_resampler.avail() > espec->SoundBufMaxSize * MDFNGameInfo->soundchan - %d\n", avail);
                    ff_resampler.clear();
                }
            }
        }

        if(volume_save != 1)
        {
            if(volume_save < 1)
            {
                int volume = (int)(16384 * volume_save);

                for(int i = 0; i < SoundBufSize * MDFNGameInfo->soundchan; i++)
                    SoundBuf[i] = (SoundBuf[i] * volume) >> 14;
            }
            else
            {
コード例 #3
0
ファイル: mednafen.cpp プロジェクト: BadyRaty/Mednafen-Core
static void ProcessAudio(EmulateSpecStruct *espec)
{
 if(espec->SoundVolume != 1)
  volume_save = espec->SoundVolume;

 if(espec->soundmultiplier != 1)
  multiplier_save = espec->soundmultiplier;

 if(espec->SoundBuf && espec->SoundBufSize)
 {
  int16 *const SoundBuf = espec->SoundBuf + espec->SoundBufSizeALMS * MDFNGameInfo->soundchan;
  int32 SoundBufSize = espec->SoundBufSize - espec->SoundBufSizeALMS;
  const int32 SoundBufMaxSize = espec->SoundBufMaxSize - espec->SoundBufSizeALMS;


  if(qtrecorder && (volume_save != 1 || multiplier_save != 1))
  {
   int32 orig_size = SoundBufPristine.size();

   SoundBufPristine.resize(orig_size + SoundBufSize * MDFNGameInfo->soundchan);
   for(int i = 0; i < SoundBufSize * MDFNGameInfo->soundchan; i++)
    SoundBufPristine[orig_size + i] = SoundBuf[i];
  }

#if 0
  //
  // Sine wave sweep for test purposes.
  //
  {
   static double phase = 0;
   static double phase_inc = 0.000;
   static double phase_inc_inc = 0.000003;
   static int32 scounter = 0;

   int16 *sbuf = SoundBuf;
   int32 slen = SoundBufSize;


   if(MDFNGameInfo->soundchan == 2)
   {
    for(int i = 0; i < slen; i++)
    {
     int16 tmp = 127 * 256 * sin(phase);

     tmp = (scounter & 8) ? 127 * 256 : -127 * 256;

     sbuf[i * 2 + 0] = tmp;
     sbuf[i * 2 + 1] = tmp;
     phase += phase_inc;
     phase_inc += phase_inc_inc;
     scounter++;
    }
   }
   else
   {
    for(int i = 0; i < slen; i++)
    {
     int16 tmp = 127 * 256 * sin(phase);

     tmp = (scounter & 8) ? 127 * 256 : -127 * 256;

     sbuf[i] = tmp;

     phase += phase_inc;
     phase_inc += phase_inc_inc;
     scounter++;
    }
   }
  }

#endif

  if(espec->NeedSoundReverse)
  {
   int16 *yaybuf = SoundBuf;
   int32 slen = SoundBufSize;

   if(MDFNGameInfo->soundchan == 1)
   {
    for(int x = 0; x < (slen / 2); x++)    
    {
     int16 cha = yaybuf[slen - x - 1];
     yaybuf[slen - x - 1] = yaybuf[x];
     yaybuf[x] = cha;
    }
   }
   else if(MDFNGameInfo->soundchan == 2)
   {
    for(int x = 0; x < (slen * 2) / 2; x++)
    {
     int16 cha = yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1];
     yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1] = yaybuf[x];
     yaybuf[x] = cha;
    }
   }
  }

  try
  {
   if(wavrecorder)
    wavrecorder->WriteSound(SoundBuf, SoundBufSize);
  }
  catch(std::exception &e)
  {
   MDFND_PrintError(e.what());
   delete wavrecorder;
   wavrecorder = NULL;
  }

  if(multiplier_save != LastSoundMultiplier)
  {
   ff_resampler.time_ratio(multiplier_save, 0.9965);
   LastSoundMultiplier = multiplier_save;
  }

  if(multiplier_save != 1)
  {
   if(FFDiscard)
   {
    if(SoundBufSize >= multiplier_save)
     SoundBufSize /= multiplier_save;
   }
   else
   {
    if(MDFNGameInfo->soundchan == 2)
    {
     assert(ff_resampler.max_write() >= SoundBufSize * 2);

     for(int i = 0; i < SoundBufSize * 2; i++)
      ff_resampler.buffer()[i] = SoundBuf[i];
    }
    else
    {
     assert(ff_resampler.max_write() >= SoundBufSize * 2);

     for(int i = 0; i < SoundBufSize; i++)
     {
      ff_resampler.buffer()[i * 2] = SoundBuf[i];
      ff_resampler.buffer()[i * 2 + 1] = 0;
     }
    }   
    ff_resampler.write(SoundBufSize * 2);

    int avail = ff_resampler.avail();
    int real_read = std::min((int)(SoundBufMaxSize * MDFNGameInfo->soundchan), avail);

    if(MDFNGameInfo->soundchan == 2)
     SoundBufSize = ff_resampler.read(SoundBuf, real_read ) >> 1;
    else
     SoundBufSize = ff_resampler.read_mono_hack(SoundBuf, real_read );

    avail -= real_read;

    if(avail > 0)
    {
     printf("ff_resampler.avail() > espec->SoundBufMaxSize * MDFNGameInfo->soundchan - %d\n", avail);
     ff_resampler.clear();
    }
   }
  }