本文整理汇总了C++中CAudio类的典型用法代码示例。如果您正苦于以下问题:C++ CAudio类的具体用法?C++ CAudio怎么用?C++ CAudio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CAudio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reset
/* Toggle audio */
void CAudio::Reset (void)
{
#if !USE_OPENAL
audio.Shutdown ();
audio.Setup (1);
#endif
}
示例2: main
// 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();
}
示例3: _MEMBER_FUNCTION_IMPL
_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;
}
示例4: SetVolume
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
}
}
示例5: memset
//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);
}
示例6: Stop
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;
}
}
示例7: StopActiveSound
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);
}
示例8: UpdateData
// 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();
}
示例9: StopAllChannels
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 ();
}
示例10: fileDlg
// 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();
}
示例11: SetMaxChannels
//------------------------------------------------------------------------------
//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 ();
}
示例12: ThreadProc
DWORD CALLBACK CAudio::ThreadProc(LPVOID lp)
{
if (nullptr == lp)ThrowWin32Error(CAudio::ThreadProc, ERROR_BAD_ARGUMENTS);
CAudio * audio = static_cast<CAudio*>(lp);
return audio->AudioThreadProc();
}
示例13: WndProc_Hook
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);
}
示例14: Start
// 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)
//.........这里部分代码省略.........
示例15: Resample
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;
//.........这里部分代码省略.........