当前位置: 首页>>代码示例>>C++>>正文


C++ SoundPlayer::Play方法代码示例

本文整理汇总了C++中SoundPlayer::Play方法的典型用法代码示例。如果您正苦于以下问题:C++ SoundPlayer::Play方法的具体用法?C++ SoundPlayer::Play怎么用?C++ SoundPlayer::Play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SoundPlayer的用法示例。


在下文中一共展示了SoundPlayer::Play方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {

    SoundPlayer soundPlayer = SoundPlayer();
    Mp3Decoder mp3Decoder = Mp3Decoder();
    MicRecorder micRecorder = MicRecorder();

    unsigned char buffer[BUFSIZE*50] = {};
    unsigned char recBuffer[BUFSIZE*50] = {};

    // Put path to file here
    std::string path = "smw_coin.mp3";
    // TODO: Manage more than int16_t encoding format, mono and 44.1kHz
    Mp3Format mp3Format = mp3Decoder.Open(path);
    //std::cout << "encoding: " << mp3Format.encoding << std::endl;
    //std::cout << "channels: " << mp3Format.channels << std::endl;
    //std::cout << "rate: " << mp3Format.rate << std::endl;

    int decodeNumber = 0;

    int decodedQty = 0;
    while ((decodedQty = mp3Decoder.Decode(buffer+decodeNumber*BUFSIZE, BUFSIZE)) > 0) {

        soundPlayer.Play(buffer+decodeNumber*BUFSIZE, decodedQty);

        // Record some data in the buffer
        micRecorder.Record(recBuffer+decodeNumber*BUFSIZE, decodedQty);

        decodeNumber++;
    }
    unsigned int samplesQty = (decodeNumber-1)*BUFSIZE/sizeof(int16_t)+decodedQty;

    mp3Decoder.Close();

    // Process the signals as wanted here
    int delay = SignalProcessor::GetDelay((int16_t*)buffer, (int16_t*)recBuffer, samplesQty);
    SignalProcessor::Delay((int16_t*)buffer, samplesQty, delay);
    SignalProcessor::Scale((int16_t*)buffer, samplesQty, 1, 2);
    SignalProcessor::Subtract((int16_t*)recBuffer, (int16_t*)buffer, samplesQty);

    // Play back for more fun
    for (unsigned int i = 0; i < decodeNumber; i++) {

        soundPlayer.Play(recBuffer+i*BUFSIZE, BUFSIZE);

    }

    printToFile(samplesQty, {(int16_t*)buffer, (int16_t*)recBuffer});

}
开发者ID:CarlPoirier,项目名称:Example_of_Signal_Processing_on_Linux,代码行数:49,代码来源:main.cpp

示例2: PlaySound_

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void EffectNodeImplemented::PlaySound_(Instance& instance, SoundTag tag, Manager* manager)
{
	SoundPlayer* player = manager->GetSoundPlayer();
	if( player == NULL )
	{
		return;
	}

	if( Sound.WaveId >= 0 )
	{
		SoundPlayer::InstanceParameter parameter;
		parameter.Data = m_effect->GetWave( Sound.WaveId );
		parameter.Volume = Sound.Volume.getValue( *manager );
		parameter.Pitch = Sound.Pitch.getValue( *manager );
		parameter.Pan = Sound.Pan.getValue( *manager );
		
		parameter.Mode3D = (Sound.PanType == ParameterSoundPanType_3D);
		Vector3D::Transform( parameter.Position, 
			Vector3D(0.0f, 0.0f, 0.0f), instance.GetGlobalMatrix43() );
		parameter.Distance = Sound.Distance;

		player->Play( tag, parameter );
	}
}
开发者ID:AndrewFM,项目名称:Effekseer,代码行数:27,代码来源:Effekseer.EffectNode.cpp


注:本文中的SoundPlayer::Play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。