Exemple #1
0
/* Toggle audio */
void CAudio::Reset (void) 
{
#if !USE_OPENAL
audio.Shutdown ();
audio.Setup (1);
#endif
}
Exemple #2
0
// Layer 2 test
int main(int argc, char* args []) {
    auto window = Graphics::Window("Window", Vector2<int>(800, 600));

    FileSystem fileIO;

    auto file = fileIO.getFile("text.bmp");
    auto audiof = fileIO.getFile("test.wav");

    CAudio audio;
    auto buffer = audio.loadAudio(AUDIO_FORMAT::WAV, &audiof);
    auto source = audio.createSource(buffer);
    source.play();

    auto tex = TextureLoader::loadTexture(&file);

    //Graphics::Sprite sprite(tex);


    while (true) {
        window.startFrame();
        source.play();
        window.endFrame();
    }
    //batch.push(&sprite, Vector4(0, 0, 0, 1));
    //batch.flush();
}
_MEMBER_FUNCTION_IMPL(Audio, constructor)
{
	bool sqbIsOnlineStream;
	script_getbool(pVM, -3, &sqbIsOnlineStream);
	bool bIsOnlineStream = (sqbIsOnlineStream != 0);

	bool sqbReplay;
	script_getbool(pVM, -2, &sqbReplay);
	bool bReplay = (sqbReplay != 0);

	const char * szSoundName;
	script_getstring(pVM, -1, &szSoundName);

	CAudio * pAudio = new CAudio(szSoundName, bReplay, bIsOnlineStream);

	///SQ metatable = null
	if(!pAudio || !pAudio->Load() || script_setinstance(pVM, pAudio, &_CLASS_DECL(Audio)) != 0)
	{
		CLogFile::Printf("Failed to load audio from file %s",szSoundName);
		SAFE_DELETE(pAudio);
		script_pushnull(pVM);
		return 1;
	}

	g_pClient->GetAudioManager()->Add(pAudio);
	//script_pushbool(pVM, true);
	return 1;
}
_MEMBER_FUNCTION_IMPL(Audio, pause)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	pAudio->Pause();
	script_pushbool(pVM, true);
	return 1;
}
_MEMBER_FUNCTION_IMPL(Audio, restoreVolume)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);

	pAudio->Unmute( );

	script_pushbool ( pVM, true );
	return 1;
}
_MEMBER_FUNCTION_IMPL(Audio, clearPosition)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);

	pAudio->SetUsePosition(false);

	script_pushbool(pVM, true);
	return 1;
}
Exemple #7
0
void CAudioChannel::SetVolume (int nVolume)
{
if (m_info.bPlaying) {
	m_info.nVolume = FixMulDiv (nVolume, audio.Volume (), I2X (1));
#if USE_SDL_MIXER
	if (gameOpts->sound.bUseSDLMixer)
		Mix_VolPan (this - audio.Channel (), m_info.nVolume, -1);
#endif
	}
}
Exemple #8
0
//changed on 980905 by adb to cleanup, add nPan support and optimize mixer
void _CDECL_ CAudio::MixCallback (void* userdata, Uint8* stream, int len)
{
if (!audio.Available ())
	return;
memset (stream, 0x80, len); // fix "static" sound bug on Mac OS X

CAudioChannel*	channelP = audio.m_channels.Buffer ();

for (int i = audio.MaxChannels (); i; i--, channelP++)
	channelP->Mix (reinterpret_cast<ubyte*> (stream), len);
}
_MEMBER_FUNCTION_IMPL(Audio, setVolume)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	float fVolume;
	script_getfloat ( pVM, 1, &fVolume );
	
	pAudio->SetVolume(fVolume);

	script_pushbool ( pVM, true );
	return 1;
}
Exemple #10
0
_MEMBER_FUNCTION_IMPL(Audio, usePositionSystem)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	bool bGet;
	script_getbool(pVM, -1, &bGet );
	bool bToggle = (bGet != 0);
	
	pAudio->SetUsePosition(bToggle);

	script_pushbool ( pVM, true );
	return 1;
}
Exemple #11
0
_MEMBER_FUNCTION_IMPL(Audio, setPosition)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);

	float fX, fY, fZ, fR;

	script_getfloat ( pVM, 1, &fX );
	script_getfloat ( pVM, 2, &fY );
	script_getfloat ( pVM, 3, &fZ );
	script_getfloat ( pVM, 4, &fR );

	pAudio->SetPosition (CVector3(fX, fY, fZ), fR );

	script_pushbool(pVM, true);
	return 1;
}
Exemple #12
0
void CAudioChannel::Stop (void)
{
m_info.bPlaying = 0;
m_info.nSoundObj = -1;
m_info.bPersistent = 0;
#if USE_OPENAL
if (gameOpts->sound.bUseOpenAL) {
	if (m_info.source != 0xFFFFFFFF)
		alSourceStop (m_info.source);
	}
#endif
#if USE_SDL_MIXER
if (audio.Available () && gameOpts->sound.bUseSDLMixer) {
	if (m_info.mixChunkP) {
		Mix_HaltChannel (m_info.nChannel);
		if (m_info.bBuiltIn)
			m_info.bBuiltIn = 0;
		else
			Mix_FreeChunk (m_info.mixChunkP);
		m_info.mixChunkP = NULL;
		}
	//Mix_FadeOutChannel (nChannel, 500);
	}
#endif
if (m_info.bResampled) {
	m_info.sample.Destroy ();
	m_info.bResampled = 0;
	}
}
Exemple #13
0
void Mix_VolPan (int nChannel, int nVolume, int nPan)
{
#if USE_SDL_MIXER
if (!audio.Available ()) 
	return;
if (gameOpts->sound.bUseSDLMixer && (nChannel >= 0)) {
	if (nVolume) {
		nVolume = (FixMul (nVolume, audio.Volume ()) + (SOUND_MAX_VOLUME / MIX_MAX_VOLUME) / 2) / (SOUND_MAX_VOLUME / MIX_MAX_VOLUME);
		if (!nVolume)
			nVolume = 1;
		Mix_Volume (nChannel, nVolume);
		if (nPan >= 0) {
			nPan /= (32767 / 127);
			Mix_SetPanning (nChannel, (ubyte) nPan, (ubyte) (254 - nPan));
			}
		}
	}
#endif
}
Exemple #14
0
void CAudio::StopActiveSound (int nChannel)
{
if (!gameStates.app.bUseSound)
	return;
if (!m_info.bAvailable)
	return;
if (!audio.m_channels [nChannel].Playing ())
	return;
audio.StopSound (nChannel);
}
// MP3の選択:MP3コーデックが使用できない場合(Vista)のチェック
void CSettingPubTab::OnRdoMp3() 
{
	UpdateData(TRUE);	// DDX更新

	/// MP3コーデックを選択
	CString str = m_aryCodecName.GetAt(m_idxCodecName);
	str.MakeUpper();

	/// MP3フォーマットリストを更新
	int intCnt = m_oAcmMgr.GetFormatList(m_aryFormatName, &m_wfx);
	if (intCnt == 0 && str.Find(ACM_CODEC_MP3) >= 0) {
		//// FraunHoffer MP3コーデックが使用できない場合(Vista)
		CAudio *pAudio = CAudio::Instance();
		pAudio->MP3CodecRegistry();
	}

	UpdateData(FALSE);	// DDX更新

	/// 適用ボタンの有効化
	OnChgForm();
}
Exemple #16
0
void CAudio::StopAllChannels (void)
{
#if 1
StopLoopingSound ();
StopObjectSounds ();
#endif
for (int i = 0; i < MAX_SOUND_CHANNELS; i++)
	audio.StopSound (i);
gameData.multiplayer.bMoving = -1;
gameData.weapons.firing [0].bSound = 0;
soundQueue.Init ();
}
// MP3コーデックの変更→フォーマットリスト更新
void CSettingPubTab::OnCmbCodec() 
{
	UpdateData(TRUE);	// DDX更新

	int i;

	/// MP3コーデックを選択
	CString str = m_aryCodecName.GetAt(m_idxCodecName);
	str.MakeUpper();
	if (str.Find(ACM_CODEC_MP3_LAME) >= 0) {
		m_oAcmMgr.FindDriver(CAcmMgr::WAV_MP3_LAME, str);
	} else {
		m_oAcmMgr.FindDriver(CAcmMgr::WAV_MP3, str);
	}

	/// MP3フォーマットリストを更新
	int intCnt = m_oAcmMgr.GetFormatList(m_aryFormatName, &m_wfx);
	if (intCnt == 0 && str.Find(ACM_CODEC_MP3) >= 0) {
		//// FraunHoffer MP3コーデックが使用できない場合(Vista)
		CAudio *pAudio = CAudio::Instance();
		pAudio->MP3CodecRegistry();
	}

	/// MP3フォーマットコンボボックスを更新
	CComboBox *pcmb = (CComboBox*)GetDlgItem(IDC_CMB_FORMAT);
	pcmb->ResetContent();
	for(i = 0; i < intCnt; i++) {
		pcmb->AddString(m_aryFormatName.GetAt(i));
	}
 	/// MP3フォーマットコンボボックスを選択
	m_idxFormatName = 0;

	UpdateData(FALSE);	// DDX更新

	/// 適用ボタンの有効化
	OnChgForm();
}
// BEEP音の更新
void CSettingPubTab::OnBtnBeepFile() 
{
	CString str;
	CString strFile;

	/// BEEP音声ファイル参照
	CFileDialog fileDlg(TRUE, _T("wave"), _T("*.wav"), OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, 
		_T("wave(*.wav)|*.wav|all(*.*)|*.*||"));
	if (fileDlg.DoModal() != IDOK) return;
	strFile = fileDlg.GetPathName();

	str.LoadString(IDS_MSGBOX60);
	if (AfxMessageBox(str, MB_YESNO | MB_APPLMODAL | MB_ICONQUESTION ) != IDYES) return;

	CFileSpec fs(strFile);
	if (!fs.Exist()) {
		str.LoadString(IDS_MSGBOX69);
		AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION);
		return;
	}

	/// ファイルのフォーマットチェック
	CAudio *pAudio = CAudio::Instance();
	pAudio->m_PlayFile = strFile;
	BOOL blRet = pAudio->ChkPlayFile();
	if (!blRet) {
		str.LoadString(IDS_MSGBOX63);
		AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION);
		return;
	}

	m_strBeepFile = strFile;

	/// 適用ボタンの有効化
	OnChgForm();
}
Exemple #19
0
//------------------------------------------------------------------------------
//added on 980905 by adb to make sound nChannel setting work
void CAudio::SetMaxChannels (int nChannels) 
{ 
if (!gameStates.app.bUseSound)
	return;
if (m_info.nMaxChannels	== nChannels)
	return;
m_info.nMaxChannels = nChannels;
if (m_info.nMaxChannels < 1) 
	m_info.nMaxChannels = 1;
if (m_info.nMaxChannels > MAX_SOUND_CHANNELS) 
	m_info.nMaxChannels = MAX_SOUND_CHANNELS;
gameStates.sound.audio.nMaxChannels = m_info.nMaxChannels;
if (!m_info.bAvailable) 
	return;
audio.StopAllChannels ();
}
Exemple #20
0
void SetupWAVInfo (ubyte* buffer, int nLength)
{
	tWAVInfo*	infoP = reinterpret_cast<tWAVInfo*> (buffer);

memcpy (infoP->header.chunkID, "RIFF", 4);
infoP->header.chunkSize = nLength + sizeof (tWAVInfo) - 8;
memcpy (infoP->header.riffType, "WAVE", 4);

memcpy (infoP->format.chunkID, "fmt ", 4);
infoP->format.chunkSize = sizeof (tWAVFormat) - sizeof (infoP->format.chunkID) - sizeof (infoP->format.chunkSize);
infoP->format.format = 1; //PCM
infoP->format.channels = 2;
infoP->format.sampleRate = SAMPLE_RATE_22K;
infoP->format.bitsPerSample = (audio.Format () == AUDIO_U8) ? 8 : 16;
infoP->format.blockAlign = infoP->format.channels * (infoP->format.bitsPerSample / 8);
infoP->format.avgBytesPerSec = infoP->format.sampleRate * infoP->format.blockAlign;

memcpy (infoP->data.chunkID, "data", 4);
infoP->data.chunkSize = nLength;
}
Exemple #21
0
DWORD CALLBACK CAudio::ThreadProc(LPVOID lp)
{
    if (nullptr == lp)ThrowWin32Error(CAudio::ThreadProc, ERROR_BAD_ARGUMENTS);
    CAudio * audio = static_cast<CAudio*>(lp);
    return audio->AudioThreadProc();
}
//
//  機能     : レジストリへ保存
//  
//  機能説明 : 
//  
//  返り値   : BOOL
//  
//  備考     : 
//  
void CSettingPubTab::Save() 
{
	// TODO: この位置にその他の検証用のコードを追加してください
	CString str;

	UpdateData(TRUE);	// DDX更新

	/// BEEP音声ファイルのコピー
	if (!m_strBeepFile.IsEmpty()) {
		/// 現在のBEEP音声ファイルのバックアップ
		CTPsetup tps(theApp.m_strDataFolder);
		CString strFile = tps.RsfBeepFileName();
		CString strTmpFile = tps.RsfTmpFileName(_T("wav"));
		CFileSpec fs(strFile);
		fs.FileCopy(strTmpFile, TRUE);
		/// BEEP音声ファイルのコピー(16KHzフォーマットへ変換)
		AUDIO_FORMAT fmt;
		fmt.nBits = 16;
		fmt.nChannels = 1;
		fmt.nFrequency = 16000;
		CAudio *pAudio = CAudio::Instance();
		if (pAudio->ChgWaveFormat(m_strBeepFile, strFile, fmt, 1)) {
			str = tps.RsfBeepFileName(_T("1"));
			fs.FileCopy(str, TRUE);
			str = tps.RsfBeepFileName(_T("2"));
			fs.FileCopy(str, TRUE);
		} else {
			str.LoadString(IDS_MSGBOX69);
			AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION);
			//// バックアップファイルを戻す
			fs.SetFullSpec(strTmpFile);
			if (fs.Exist()) {
				fs.FileCopy(strFile, TRUE);
			}
		}
	}

	// レジストリ更新
	//// Startup
	if (m_blStartup) {
		// tapmgr.exeをスタートアップレジストリに登録
		CFileSpec fs(FS_APPDIR);
		fs.SetFileName(_T("tapmgr.exe"));
		m_rgStartup = fs.GetFullSpec();
	} else {
		// スタートアップレジストリを削除
		m_rgStartup.removeValue();
	}
	//// 起動時無効
	m_rgDisable = (m_blDisable) ? 1 : 0;
	//// 待機時間
	str = m_aryWaitAnswer.GetAt(m_idxWaitAnswer);
	m_rgWaitAnswer = (DWORD)_ttoi(str);
 	//// 録音時間
	str = m_aryMaxRecord .GetAt(m_idxMaxRecord);
	DWORD dw = (DWORD)_ttoi(str);
	dw *= 60;	// min -> sec
	m_rgMaxRecord = dw;
 	//// WAV or MP3
	CButton *rd_mp3 = (CButton *)GetDlgItem(IDC_RDO_MP3);
	if (rd_mp3->GetCheck()) {
		m_rgFormatType = 1;
	} else {
		m_rgFormatType = 0;
	}
 	//// MP3コーデック
	if (m_aryCodecName.GetCount() > 0) {
		str = m_aryCodecName.GetAt(m_idxCodecName);
		m_rgCodecName = str;
	}
 	//// MP3フォーマット
	if (m_aryFormatName.GetCount() > 0) {
		str = m_aryFormatName.GetAt(m_idxFormatName);
		m_rgFormatName = str;
	}
/*
	//// ショートカット
	m_rgShortCutTapur = (m_blShortCutTapur) ? 1 : 0;
	m_rgShortCutSkype = (m_blShortCutSkype) ? 1 : 0;
*/
}
Exemple #23
0
LRESULT APIENTRY WndProc_Hook(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    bool bFocused = (GetForegroundWindow() == hWnd);

	// Update HWND state..
	if(bFocused != g_pCore->GetGame()->IsFocused())
		g_pCore->GetGame()->SetFocused(bFocused);

    // Are we focused?
    if(bFocused)
    {
		if (g_pCore->GetGraphics()->GetGUI())
			g_pCore->GetGraphics()->GetGUI()->HandleUserInput(uMsg, wParam);

		if(uMsg == WM_KILLFOCUS || (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE))
		{
			return true;
		}

		if(uMsg == WM_KEYUP)
		{
			switch(wParam)
			{
				case VK_F7:
				{
					const char *szSoundName = "test.mp3";
					szSoundName = SharedUtility::GetAbsolutePath("resources\\%s", szSoundName);

					CAudio  *pAudio = new CAudio(szSoundName, false, false);
					
					if (pAudio && pAudio->Load())
					{
						g_pCore->GetAudioManager()->Add(pAudio);
						pAudio->Play();
					}
					break;
				}
				case VK_ESCAPE: // Our own main menu
				{
					g_pCore->GetGraphics()->GetMainMenu()->SetVisible(!g_pCore->GetGraphics()->GetMainMenu()->IsMainMenuVisible());	

					if (g_pCore->GetGraphics()->GetMainMenu()->IsMainMenuVisible()) {
						g_pCore->GetGame()->GetLocalPlayer()->SetPlayerControlAdvanced(false, false);
					}
					else {
						g_pCore->GetGame()->GetLocalPlayer()->SetPlayerControlAdvanced(true, true);
					}

					break;
				}
				case VK_F8:
				{
					// Take a screen shot
					if(!CSnapShot::Take())
					{
						g_pCore->GetGraphics()->GetChat()->Print(CString("Screen shot capture failed (%s).", CSnapShot::GetError().Get()));
						CSnapShot::Reset();
					}
					break;
				}
			}
		}

		if(g_pCore->GetGraphics()->GetChat())
			 g_pCore->GetGraphics()->GetChat()->HandleUserInput(uMsg, wParam);
    }

    return CallWindowProc(m_wWndProc, hWnd, uMsg, wParam, lParam);
}
Exemple #24
0
// Volume 0-I2X (1)
int CAudioChannel::Start (short nSound, int nSoundClass, fix nVolume, int nPan, int bLooping, 
								  int nLoopStart, int nLoopEnd, int nSoundObj, int nSpeed, 
								  const char *pszWAV, CFixVector* vPos)
{
	CSoundSample*	soundP = NULL;
	int			bPersistent = (nSoundObj > -1) || bLooping || (nVolume > I2X (1));

if (!(pszWAV && *pszWAV && gameOpts->sound.bUseSDLMixer)) {
	if (nSound < 0)
		return -1;
	if (!gameData.pig.sound.nSoundFiles [gameStates.sound.bD1Sound])
		return -1;
	soundP = gameData.pig.sound.sounds [gameStates.sound.bD1Sound] + nSound % gameData.pig.sound.nSoundFiles [gameStates.sound.bD1Sound];
	if (!(soundP->data [soundP->bCustom].Buffer () && soundP->nLength [soundP->bCustom]))
		return -1;
	}
if (m_info.bPlaying) {
	m_info.bPlaying = 0;
	if (m_info.nSoundObj > -1)
		audio.EndSoundObject (m_info.nSoundObj);
	if (soundQueue.Channel () == audio.FreeChannel ())
		soundQueue.End ();
	}
#if USE_OPENAL
if (m_info.source == 0xFFFFFFFF) {
	CFloatVector	fPos;

	DigiALError ();
	alGenSources (1, &m_info.source);
	if (DigiALError ())
		return -1;
	alSourcei (m_info.source, AL_BUFFER, soundP->buffer);
	if (DigiALError ())
		return -1;
	alSourcef (m_info.source, AL_GAIN, ((nVolume < I2X (1)) ? X2F (nVolume) : 1) * 2 * X2F (m_info.nVolume));
	alSourcei (m_info.source, AL_LOOPING, (ALuint) ((nSoundObj > -1) || bLooping || (nVolume > I2X (1))));
	fPos.Assign (vPos ? *vPos : OBJECTS [LOCALPLAYER.nObject].nPosition.vPos);
	alSourcefv (m_info.source, AL_POSITION, reinterpret_cast<ALfloat*> (fPos));
	alSource3f (m_info.source, AL_VELOCITY, 0, 0, 0);
	alSource3f (m_info.source, AL_DIRECTION, 0, 0, 0);
	if (DigiALError ())
		return -1;
	alSourcePlay (m_info.source);
	if (DigiALError ())
		return -1;
	}
#endif
#if USE_SDL_MIXER
if (gameOpts->sound.bUseSDLMixer) {
	if (m_info.mixChunkP) {
		Mix_HaltChannel (m_info.nChannel);
		if (m_info.bBuiltIn)
			m_info.bBuiltIn = 0;
		else
			Mix_FreeChunk (m_info.mixChunkP);
		m_info.mixChunkP = NULL;
		}
	}
#endif
if (m_info.bResampled) {
	m_info.sample.Destroy ();
	m_info.bResampled = 0;
	}
#if USE_SDL_MIXER
if (gameOpts->sound.bUseSDLMixer) {
	//resample to two channels
	m_info.nChannel = audio.FreeChannel ();
	if (pszWAV && *pszWAV) {
		if (!(m_info.mixChunkP = LoadAddonSound (pszWAV, &m_info.bBuiltIn)))
			return -1;
		}
	else {
		int l;
		if (soundP->bHires) {
			l = soundP->nLength [soundP->bCustom];
			m_info.sample.SetBuffer (soundP->data [soundP->bCustom].Buffer (), 1, l);
			m_info.mixChunkP = Mix_QuickLoad_WAV (reinterpret_cast<Uint8*> (m_info.sample.Buffer ()));
			}
		else {
			if (gameOpts->sound.bHires [0])
				return -1;	//cannot mix hires and standard sounds
			l = Resample (soundP, gameStates.sound.bD1Sound && (gameOpts->sound.digiSampleRate != SAMPLE_RATE_11K), songManager.MP3 ());
			if (l <= 0)
				return -1;
			if (nSpeed < I2X (1))
				l = Speedup (soundP, nSpeed);
#if MAKE_WAV
			m_info.mixChunkP = Mix_QuickLoad_WAV (reinterpret_cast<Uint8*> (m_info.sample.Buffer ()));
#else
			m_info.mixChunkP = Mix_QuickLoad_RAW (reinterpret_cast<Uint8*> (m_info.sample.Buffer ()), l);
#endif
			}
		}
	Mix_VolPan (m_info.nChannel, nVolume, nPan);
	Mix_PlayChannel (m_info.nChannel, m_info.mixChunkP, bLooping ? -1 : nLoopEnd - nLoopStart);
	}
else 
#else
if (pszWAV && *pszWAV)
	return -1;
#endif
 {
	if (gameStates.sound.bD1Sound && (gameOpts->sound.digiSampleRate != SAMPLE_RATE_11K)) {
		int l = Resample (soundP, 0, 0);
		if (l <= 0)
			return -1;
		m_info.nLength = l;
		}
	else {
		m_info.sample.SetBuffer (soundP->data [soundP->bCustom].Buffer (), 1, m_info.nLength = soundP->nLength [soundP->bCustom]);
		}
	if (nSpeed < I2X (1))
		Speedup (soundP, nSpeed);
	}
m_info.nVolume = FixMul (audio.Volume (), nVolume);
m_info.nPan = nPan;
m_info.nPosition = 0;
m_info.nSoundObj = nSoundObj;
m_info.nSoundClass = nSoundClass;
m_info.bLooped = bLooping;
#if USE_OPENAL
m_info.loops = bLooping ? -1 : nLoopEnd - nLoopStart + 1;
#endif
m_info.nSound = nSound;
m_info.bPersistent = 0;
m_info.bPlaying = 1;
m_info.bPersistent = bPersistent;
return audio.FreeChannel ();
}
Exemple #25
0
int CAudioChannel::Resample (CSoundSample *soundP, int bD1Sound, int bMP3)
{
	int		h, i, k, l, nFormat = audio.Format ();
	float		fFade;
	ushort*	ps, * ph, nSound, nPrevSound;
	ubyte*	dataP = soundP->data [soundP->bCustom].Buffer ();

#if DBG
if (soundP->bCustom)
	soundP->bCustom = soundP->bCustom;
#endif
h = i = soundP->nLength [soundP->bCustom];
l = 2 * i;
if (bD1Sound) {
	if (gameOpts->sound.bUseSDLMixer)
		l *= 2;
	else
		bD1Sound = 0;
	}
if (bMP3) 
	l = (l * 32) / 11;	//sample up to approx. 32 kHz
else if (nFormat == AUDIO_S16LSB)
	l *= 2;
if (!m_info.sample.Create (l + WAVINFO_SIZE))
	return -1;
m_info.bResampled = 1;
ps = reinterpret_cast<ushort*> (m_info.sample.Buffer () + WAVINFO_SIZE);
ph = reinterpret_cast<ushort*> (m_info.sample.Buffer () + WAVINFO_SIZE + l);
;
for (i = k = 0; i < h; i++) {
	nSound = ushort (dataP [i]);
	if (bMP3) { //get as close to 32.000 Hz as possible
		if (k < 700)
			nSound <<= k / 100;
		else if (i < 700)
			nSound <<= i / 100;
		else
			nSound = (nSound - 1) << 8;
		*ps++ = nSound;
		if (ps >= ph)
			break;
		*ps++ = nSound;
		if (ps >= ph)
			break;
		if (++k % 11) {
			*ps++ = nSound;
			if (ps >= ph)
				break;
			}
		}
	else {
		if (nFormat == AUDIO_S16LSB) {
			fFade = float (i) / 500.0f;
			if (fFade > 1)
				fFade = float (h - i) / 500.0f;
			if (fFade > 1)
				fFade = 1.0f;
			nSound = ushort (32767.0f / 255.0f * float (nSound) * fFade);
#if 1		// interpolate every 2nd sample
			*ps = nSound;
			if (i)
				*(ps - 1) = ushort ((uint (nSound) + uint (nPrevSound)) / 2);
			nPrevSound = nSound;
			ps += 2;
#else
			*ps++ = nSound;
			*ps++ = nSound;
#endif
			}
		else {
			nSound |= (nSound << 8);
			*ps++ = nSound;
			}
		}
	if (bD1Sound) {
		if (bMP3) {
			*ps++ = nSound;
			if (ps >= ph)
				break;
			*ps++ = nSound;
			if (ps >= ph)
				break;
			if (k % 11) {
				*ps++ = nSound;
				if (ps >= ph)
					break;
				}
			}
		else {
			*ps++ = nSound;
			if (nFormat == AUDIO_S16LSB)
				*ps++ = nSound;
			}
		}
	}
Assert (ps == ph);
#if MAKE_WAV
SetupWAVInfo (m_info.sample.Buffer (), l);
#endif
return m_info.nLength = l;
}
Exemple #26
0
_MEMBER_FUNCTION_IMPL(Audio, isStalled)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	script_pushbool( pVM, pAudio->IsStalled() );
	return 1;
}
Exemple #27
0
_MEMBER_FUNCTION_IMPL(Audio, getVolume)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	script_pushfloat ( pVM, pAudio->GetVolume( ) );
	return 1;
}
Exemple #28
0
_MEMBER_FUNCTION_IMPL(Audio, play)
{
	CAudio * pAudio = script_getinstance<CAudio *>(pVM);
	script_pushbool(pVM, pAudio->Play());
	return 1;
}
Exemple #29
0
void SDLCALL Mix_FinishChannel (int nChannel)
{
audio.Channel (nChannel)->SetPlaying (0);
}
//
//  機能     : 画面の更新
//  
//  機能説明 : 
//  
//  返り値   : BOOL
//  
//  備考     : 
//  
BOOL CRsfSimpleForm::UpdateForm() 
{
	/// カレントレコード
	if (theApp.m_lngRsflId <= 0) return FALSE;

	/// 再生中のファイルを停止する
//	PlayStop();

	// StatusBarのクリア
	CMainFrame *pFrame = (CMainFrame*)::AfxGetMainWnd();
	pFrame->SetStatusText(_T(""), 0);
	pFrame->SetStatusText(_T(""), 1);

	// ラジオボタンの参照定義(DDXは扱いにくいので)
	// (クラスメンバーで宣言すると正常に動作しない)
	CButton *rd_rec = (CButton *)GetDlgItem(IDC_RDO_REC);
	CButton *rd_vrec = (CButton *)GetDlgItem(IDC_RDO_VREC);
	CButton *rd_discon = (CButton *)GetDlgItem(IDC_RDO_DISCONNECT);

	/// 初期設定
	m_blAudio = FALSE;
    m_blChat = FALSE;
    m_blVideo = FALSE;
    m_blImg = FALSE;
	m_blBeep = FALSE;
	m_blPrg = FALSE;
	rd_rec->SetCheck(0);
	rd_vrec->SetCheck(0);
	rd_discon->SetCheck(1);

	/// 応答設定テーブルを選択
	CTblRsfl tbl(theApp.m_strDBPath);
	CString strWhere;
	_TCHAR buf[64];
	strWhere.Empty();
	_ltot_s(theApp.m_lngRsflId, buf, sizeof(buf)/sizeof(buf[0]), 10);
	strWhere = strWhere + _T("ID") + _T("=") + buf;
	_ltot_s(RESPBASE_TYPE_SIMPLE, buf, sizeof(buf)/sizeof(buf[0]), 10);
	strWhere = strWhere + _T(" and ") + _T("lngRespType") + _T("=") + buf;
	if (tbl.SelectRec(strWhere) <= 0) {
		return FALSE;
	}

	/// 選択された応答設定RSFをロード
	CTPsetup tps(theApp.m_strDataFolder);
	if (tbl.lngDefaultFlag == 1) {
		m_strSenderId = _T("0");	// default setting
	} else {
		m_strSenderId = tbl.strSenderId;
	}
	tps.SetCallerId(m_strSenderId);
	UST_RSF *pst = tps.LoadRSF();
	if (pst == NULL) return FALSE;

	/// 選択された応答設定RSFを参照
	UST_RSF_RESP *pst_resp;
	for (int i = 0; i < pst->resp_cnt; i++) {
		pst_resp = pst->resp + i;
		//// BEEPのON/OFF
		if (pst_resp->beep > 0) {
			m_blBeep = TRUE;
		}
		switch(pst_resp->type) {
		case RESP_TYPE_PLAY:
			//// 再生内容のON/OFF
			if (pst_resp->play_type & RESP_PLAY_TYPE_AUDIO) {
				m_blAudio = TRUE;
			}
			if (pst_resp->play_type & RESP_PLAY_TYPE_VIDEO) {
				m_blVideo = TRUE;
			}
			if (pst_resp->play_type & RESP_PLAY_TYPE_IMAGE) {
				m_blImg = TRUE;
			}
			if (pst_resp->play_type & RESP_PLAY_TYPE_CHAT) {
				m_blChat = TRUE;
			}
			break;
		//// 録音内容のON/OFF
		case RESP_TYPE_RECORD:
			rd_rec->SetCheck(1);
			rd_vrec->SetCheck(0);
			rd_discon->SetCheck(0);
			break;
		case RESP_TYPE_VRECORD:
			rd_rec->SetCheck(0);
			rd_vrec->SetCheck(1);
			rd_discon->SetCheck(0);
			break;
		case RESP_TYPE_DISCONNECT:
			// 全ての設定で使用されるので、設定すべきことはない
			break;
		//// プログラム連携のON/OFF
		case RESP_TYPE_EXEC:
			m_blPrg = TRUE;
			break;
		default:
			break;
		}
	}

	/// 応答音声ファイルの時間表示
	CString strPlayFile;
	CString strSize;
	CFileSpec fs;
	strSize = _T("[ 00:00 ]");
	strPlayFile = tps.RsfAudioFileName(_T("$"));
	fs.SetFullSpec(strPlayFile);
	if (fs.Exist()) {
		CMainFrame *pFrame = (CMainFrame*)::AfxGetMainWnd();
		CAudio *pAudio = pFrame->m_pAudio;
		pAudio->m_PlayFile = strPlayFile;
		float fTime = pAudio->GetPlaySize();
		if (fTime > 0.0) {
			long lngTime = (long)(fTime+1);
			strSize.Format(_T("[ %02i:%02i ]"), (lngTime/60), (lngTime%60));
		}
	}
	m_lblAudioSize.SetText((LPCTSTR)strSize);

	/// 応答ビデオファイルの時間表示
	strSize = _T("[ 00:00 ]");
	strPlayFile = tps.RsfVideoFileName(_T("$"));
	fs.SetFullSpec(strPlayFile);
	if (fs.Exist()) {
		CMainFrame *pFrame = (CMainFrame*)::AfxGetMainWnd();
		CVideo *pVideo = pFrame->m_pVideo;
		pVideo->SetPlayFile(strPlayFile);
		float fTime = pVideo->GetPlaySize();
		if (fTime > 0.0) {
			long lngTime = (long)(fTime+1);
			strSize.Format(_T("[ %02i:%02i ]"), (lngTime/60), (lngTime%60));
		}
	}
	m_lblVideoSize.SetText((LPCTSTR)strSize);

	/// 画像ファイルのサイズ表示
	strSize = _T("[ 0 Kbytes ]");
	strPlayFile = tps.FindRsfImgFile(_T("$"));
	fs.SetFullSpec(strPlayFile);
	if (fs.Exist()) {
		strSize.Format(_T("[ %d Kbytes ]"), fs.FileSize()/1024);
	}
	m_lblImgSize.SetText((LPCTSTR)strSize);

	/// チャットテキストファイルのサイズ表示
	strSize = _T("[ 0 bytes ]");
	strPlayFile = tps.RsfChatFileName(_T("$"));
	fs.SetFullSpec(strPlayFile);
	if (fs.Exist()) {
		strSize.Format(_T("[ %d bytes ]"), fs.FileSize());
	}
	m_lblChatSize.SetText((LPCTSTR)strSize);

 	/// 連携プログラムコンボボックスを選択
	CString str, strPrgId;
	strPrgId.Format(_T("%d"), pst_resp->exec_id);
	int idx = 0;
	for(int i = 0; i <  m_aryPrgId.GetSize(); i++) {
		str = m_aryPrgId.GetAt(i);
		if (strPrgId == str) {
			idx = i;
			break;
		}
	}
	m_idxPrg = idx;

	/// 連携プログラムCSVファイルが存在しない場合、テンプレートCSVフォルダからコピー
	CString strBinDir, strFile;
	fs.SetFullSpec(FS_APPDIR);
	strBinDir = fs.GetFullSpec() + _T("bin");	// テンプレートCSVフォルダ
	for(int i = 0; i <  m_aryPrgId.GetSize(); i++) {
		strPrgId = m_aryPrgId.GetAt(i);
		strFile = tps.RsfPrgFileName(_T("$$$$"), strPrgId);	// 連携プログラムCSVファイル
		fs.SetFullSpec(strFile);
		if (!fs.Exist()) {
			fs.SetFullSpec(strBinDir + "\\" + strPrgId + ".csv");
			if (fs.Exist()) {
				fs.FileCopy(strFile, FALSE);	// 上書きはしない
			}
		}
	}

	UpdateData(FALSE);	// DDX更新

	return TRUE;
}