本文整理汇总了C++中CAudio::Format方法的典型用法代码示例。如果您正苦于以下问题:C++ CAudio::Format方法的具体用法?C++ CAudio::Format怎么用?C++ CAudio::Format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAudio
的用法示例。
在下文中一共展示了CAudio::Format方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetupWAVInfo
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;
}
示例2: 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;
//.........这里部分代码省略.........