示例#1
0
  long __declspec(dllexport) DLL_LoadGYM(const char *szFileName)
  {    
    GYMSong* result = new GYMSong;
    FILE* f = fopen(szFileName,"rb");
    int iResult = 0;
    if (f)
    {
      WaitForSingleObject(hMutex,INFINITE);
      fseek(f,0,SEEK_END);
      result->gymSize = ftell(f);
      fseek(f,0,SEEK_SET);
      result->gym = (unsigned char*)malloc(result->gymSize*sizeof(unsigned char));
      unsigned int iRead = 0;
      result->gymPos = result->gym;
      while (iRead < result->gymSize)
      {
        fread(result->gym,1,result->gymSize,f);
        int iCurrRead = fread(result->gymPos,1,16384,f);
        if (iCurrRead > 0)
        {
          iRead += iCurrRead;
          ReleaseMutex(hMutex);
          Sleep(10); // prevent starving pap during xfade
          WaitForSingleObject(hMutex,INFINITE);
        }
        else
          break;
      }

      fclose(f);
      result->gymTag = (GYMSong::GYMTAG*)result->gym;
      if (strncmp(((GYMSong::GYMTAG*)result->gym)->gym_id, "GYMX", 4) == 0)
      {
        result->gymStart = result->gymPos = result->gym+sizeof(GYMSong::GYMTAG);
        result->gymSize -= sizeof(GYMSong::GYMTAG);
        result->iLength = calc_gym_time_length(result);
      }
      else
      {
        result->gymStart = result->gymPos = result->gym;
        result->gymTag = NULL;
      }

      
      result->YM2612 = YM2612;
      result->PSG = PSG;
      Start_Play_GYM(48000);
      iResult = (long)result;
      ReleaseMutex(hMutex);
    }

    return (int)iResult;
  }
示例#2
0
文件: gym.cpp 项目: wally4000/code
		char input_gym::open(CFILE * r, SONGINFO * info, unsigned int flags)	//multiinstance safety ?
		{
			if (!open_file(r,info,flags)) return 0;
//			if (!(flags & OPEN_FLAG_DECODE)) return 1;

			char failed = false;
	//		g_decoder_sync.enter();
			if (g_decoder == 0) g_decoder = this;
			else if (g_decoder!=this) failed = true;
	//		g_decoder_sync.leave();
			if (failed)
			{
				oslDebug("GYM decoder does not support multiple instances; please stop other decoding processes and try again");
				return 0;
			}

			void *gymFile = gym_backup.get_ptr();

			if (!gym_loaded)
			{
				if (gym_tag)
				{
					if (gym_tag -> compressed)
					{
						if (memcmp((char *)((int)gymFile + sizeof(GYMTAG)), "EZPK", 4) == 0)
						{
							// EZPK-compressed
							if (!load_ezpk_gym(gymFile)) return 0;
						}
						else
						{
							// standard zlib-compressed
							if (!load_zlib_gym(gymFile)) return 0;
						}
					}
					else
					{
						// not compressed
						gym_start = (unsigned char *)gymFile + sizeof(GYMTAG);
						gym_size = gym_backup.get_size() - sizeof(GYMTAG);
					}
				}
				else
				{
					// no tag, assume not compressed
					gym_start = (unsigned char *)gymFile;
					gym_size = gym_backup.get_size();
				}

				gym_loaded = true;
			}
				
			gym_pos = gym_start;

			YM2612_Enable = cfg_ym2612_enable;
			YM2612_Improv = cfg_ym2612_interp;

			Chan_Enable[0] = cfg_chan1_enable;
			Chan_Enable[1] = cfg_chan2_enable;
			Chan_Enable[2] = cfg_chan3_enable;
			Chan_Enable[3] = cfg_chan4_enable;
			Chan_Enable[4] = cfg_chan5_enable;
			Chan_Enable[5] = cfg_chan6_enable;
			DAC_Enable = cfg_dac_enable;

			PSG_Enable = cfg_psg_enable;
			PSG_Improv = cfg_psg_interp;

			PSG_Chan_Enable[0] = cfg_psg_chan1_enable;
			PSG_Chan_Enable[1] = cfg_psg_chan2_enable;
			PSG_Chan_Enable[2] = cfg_psg_chan3_enable;
			PSG_Chan_Enable[3] = cfg_psg_chan4_enable;

			playingSampleRate = cfg_samplerate;

			Start_Play_GYM(playingSampleRate);

//			sample_buffer.check_size(Seg_Lenght << 2);
			sample_buffer.new_block(Seg_Lenght << 2);

			return 1;
		}