本文整理汇总了C++中AudioPlayer类的典型用法代码示例。如果您正苦于以下问题:C++ AudioPlayer类的具体用法?C++ AudioPlayer怎么用?C++ AudioPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AudioPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clear
void AudioModel::load(const QVariantMap &homeData)
{
clear();
if (!homeData.contains("audio"))
{
qDebug() << "no audio entry";
return;
}
QVariantList players = homeData["audio"].toList();
QVariantList::iterator it = players.begin();
for (;it != players.end();it++)
{
QVariantMap r = it->toMap();
AudioPlayer *p = new AudioPlayer(connection);
p->load(r);
appendRow(p);
}
}
示例2: audioPlayerTest
void AudioEngine::audioPlayerTest(const int sleep) noexcept
{
int audioId = -1;
bool leftPlaying = false;
AudioPlayer *sound = nullptr;
std::string soundPath = "";
while (!_stopGc)
{
if (audioId != -1)
{
std::lock_guard<std::mutex> lock(_playersMutex);
const auto &it = _players.find(audioId);
if (it != _players.end())
{
it->second->stop();
audioId = -1;
}
}
if (!leftPlaying)
{
soundPath = "cse_dialog1.ogg";
}
else
{
soundPath = "cse_dialog2.ogg";
}
leftPlaying = !leftPlaying;
sound = createPlayerWithPath(soundPath, 1.f, true);
if (sound != nullptr)
{
sound->play();
audioId = sound->getPlayerId();
}
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
}
}
示例3: AudioPlayer
/**
* Factory to create *AudioPlayer and easily managed lifecycle of the objects
*/
AudioPlayer *AudioEngine::createPlayerWithPath(const std::string &fileFullPath, const float volume, const bool loop) noexcept
{
AudioPlayer *ret = nullptr;
if (initOpenSL() && _assetManager != nullptr)
{
ret = new AudioPlayer();
const bool init = ret->initWithEngine(_engineEngine, _outputMixObject, getAssetManager(), ++_audioIds, fileFullPath, volume, loop);
if (init)
{
std::lock_guard<std::mutex> lock(_playersMutex); // /!\ a thread (audioPlayerGc) in charge of deleting instances of AudioEngine is running
_players[_audioIds] = ret;
_condition.notify_one(); // to decrease cpu usage of the thread he can be in stasis
}
else
{ // If we are not able to create the AudioPlayer we clean the memory
delete ret;
ret = nullptr;
}
}
return ret;
}
示例4: locker
/**
Play a 44100Hz mono 16bit PCM sound
*/
void Audio::playMono16Sound(const QByteArray& data)
{
QMutexLocker locker(&d->audioLock);
if (!d->alOutDev)
d->initOutput(Settings::getInstance().getOutDev());
alSourcef(d->alMainSource, AL_GAIN, d->outputVolume);
AudioPlayer *player = new AudioPlayer(d->alMainSource, data);
connect(player, &AudioPlayer::finished, [=]() {
QMutexLocker locker(&d->audioLock);
if (d->outSources.isEmpty())
d->cleanupOutput();
else
qDebug("Audio output not closed -> there are pending subscriptions.");
});
player->start();
}
示例5: Java_com_prettysimple_audio_AudioPlayer_init
/**
* Init OpenSL to then interact with a sound (play/stop/pause/resume/setVolume/setParams)
* Implementation of the init method in AudioPlayer.java
*/
JNIEXPORT bool JNICALL Java_com_prettysimple_audio_AudioPlayer_init(JNIEnv *env, jobject thiz, jstring path, jfloat volume, jboolean loop)
{
bool ret = false;
const int audioId = getAudioId(env, thiz); // try to recover the audioIde from the AudioPlayer.java object
if (audioId < 0) {
const char *pathC = env->GetStringUTFChars(path, nullptr);
AudioPlayer *player = AudioEngine::getInstance()->createPlayerWithPath(pathC, (float) volume, (bool) loop); // Can return nullptr if the audio engine or the assemanager is not init correctly
env->ReleaseStringUTFChars(path, pathC);
if (player != nullptr)
{
setAudioId(env, thiz, player->getPlayerId()); // Set the audioId member of java class AudioPlayer.java
player->setJavaAudioPlayerObj( thiz); // Store the jobject in GlobalRef to be able to easily set the audioId back when you stop a sound
ret = true;
}
}
return ret;
}
示例6: audioPlayer
AudioPlayer::AudioMsg *AudioPlayerLoaders::checkLoader(AudioMsgId::Type type) {
AudioPlayer *voice = audioPlayer();
if (!voice) return 0;
auto data = voice->dataForType(type);
bool isGoodId = false;
AudioPlayerLoader *l = nullptr;
switch (type) {
case AudioMsgId::Type::Voice: l = _audioLoader.get(); isGoodId = (data->audio == _audio); break;
case AudioMsgId::Type::Song: l = _songLoader.get(); isGoodId = (data->audio == _song); break;
case AudioMsgId::Type::Video: l = _videoLoader.get(); isGoodId = (data->audio == _video); break;
}
if (!l || !data) return nullptr;
if (!isGoodId || !data->loading || !l->check(data->file, data->data)) {
LOG(("Audio Error: playing changed while loading"));
return nullptr;
}
return data;
}
示例7: json_object
void JsonApiHandlerHttp::processGetCover()
{
int pid;
Utils::from_string(jsonParam["player_id"], pid);
if (pid < 0 || pid >= AudioManager::Instance().get_size())
{
json_t *jret = json_object();
json_object_set_new(jret, "success", json_string("false"));
json_object_set_new(jret, "error_str", json_string("player_id not set"));
sendJson(jret);
return;
}
AudioPlayer *player = AudioManager::Instance().get_player(pid);
string w, h;
if (jsonParam.Exists("width"))
w = jsonParam["width"];
if (jsonParam.Exists("height"))
h = jsonParam["height"];
player->get_album_cover([=](AudioPlayerData data)
{
//do not start another exe if one is running already
if (data.svalue == "" || exe_thumb)
{
json_t *jret = json_object();
json_object_set_new(jret, "success", json_string("false"));
json_object_set_new(jret, "error_str", json_string("unable to get url"));
sendJson(jret);
return;
}
string cmd = "calaos_thumb \"" + data.svalue + "\" \"" + tempfname + "\"";
if (w.empty() || h.empty())
cmd += " " + w + "x" + h;
exe_thumb = ecore_exe_run(cmd.c_str(), nullptr);
});
}
示例8: AUTO_LOG
int
CPlayerClient::foundMediaFile(const char *path, sp<IMediaExtractor>& pExtractor_in)
{
AUTO_LOG();
CHECK_PTR_EXT(path, BAD_VALUE);
CHECK_PTR_EXT(pExtractor_in, BAD_VALUE);
CHECK_PTR_EXT(m_pSink, BAD_VALUE);
for (size_t i = 0; i < pExtractor_in->countTracks(); ++i) {
sp<MetaData> meta = pExtractor_in->getTrackMetaData(i);
CHECK_PTR_EXT(meta, BAD_VALUE);
const char *_mime;
CHECK(meta->findCString(kKeyMIMEType, &_mime));
CHECK_PTR_EXT(_mime, BAD_VALUE);
String8 mime = String8(_mime);
if (!strncasecmp(mime.string(), "audio/", 6)) {
AudioPlayer *player = new AudioPlayer(m_pSink);
CHECK_PTR_EXT(player, BAD_VALUE);
player->setSource(pExtractor_in->getTrack(i));
player->start(false /* sourceAlreadyStarted */);
//status_t finalStatus;
//while (!player->reachedEOS(&finalStatus)) {
// usleep(100000ll);
//}
delete player;
player = NULL;
}
}
RETURN(OK);
}
示例9: paintCell
void PlaylistComponent::paintCell( Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected )
{
AudioPlayer* player = AudioPlayer::getInstance();
std::shared_ptr<Playlist> playlist = player->getPlaylist();
std::shared_ptr<PlaylistEntry> playlistEntry = playlist->getEntry(rowNumber);
if(playlistEntry)
{
g.setColour(Colours::black);
std::shared_ptr<SongInfo> songInfo = playlistEntry->getSongInfo();
if(songInfo == player->getCurrentSong())
g.setFont(_boldfont);
else
g.setFont(_font);
switch(columnId)
{
case 1:
g.drawText(songInfo->getTitle(), 2, 0, width - 4, height, Justification::centredLeft, true);
break;
case 2:
g.drawText(songInfo->getArtist(), 2, 0, width - 4, height, Justification::centredLeft, true);
break;
case 3:
int seconds = songInfo->getLengthSeconds();
if(seconds > 0)
{
const String s = String::formatted("%d:%02d", (seconds / 60), (seconds % 60) );
g.drawText(s, 2, 0, width - 4, height, Justification::centredRight, true);
}
break;
}
}
//g.setColour (Colours::black.withAlpha (0.2f));
//g.fillRect (width - 1, 0, 1, height);
}
示例10: playASound
int playASound(const char* fn){
AudioPlayer* ap = AudioPlayer::file(fn);
if(!ap) {
std::cerr << "Error loading audio" << std::endl;
return 1;
}
ap->play();
char indic[] = { '|', '/', '-', '\\' };
int i = 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
std::cout << "\rPlaying.. " << indic[i];
double d = ap->progress();
double min = floor(d/60);
double sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
d = ap->duration();
min = floor(d/60);
sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
std::cout << std::flush;
if(ap->progress() > 5) {
ap->seek(rand()/(float(RAND_MAX))*ap->duration());
}
i = (i+1)%4;
} while (ap->isPlaying());
delete ap;
return 1;
}
示例11: update
void AudioEngineImpl::update(float dt)
{
AudioPlayer* player = nullptr;
auto itend = _audioPlayers.end();
for (auto iter = _audioPlayers.begin(); iter != itend; )
{
player = &(iter->second);
if (player->_delayTimeToRemove > 0.f)
{
player->_delayTimeToRemove -= dt;
if (player->_delayTimeToRemove < 0.f)
{
iter = _audioPlayers.erase(iter);
continue;
}
}
else if (player->_playOver)
{
if (player->_finishCallback)
player->_finishCallback(player->_audioID, *AudioEngine::_audioIDInfoMap[player->_audioID].filePath);
AudioEngine::remove(player->_audioID);
iter = _audioPlayers.erase(iter);
continue;
}
++iter;
}
if(_audioPlayers.empty()) {
_lazyInitLoop = true;
auto scheduler = Director::getInstance()->getScheduler();
scheduler->unschedule(schedule_selector(AudioEngineImpl::update), this);
}
}
示例12: main
int main(int ac, char **av)
{
if (ac == 3) {
AudioPlayer p;
try {
std::cout << "Playing " << av[1] << "..." << std::endl;
p.loadFile(av[1]);
p.play();
std::cout << "Playing " << av[1] << "..." << std::endl;
p.play();
std::cout << "Playing " << av[2] << "..." << std::endl;
p.loadFile(av[2]);
p.play();
p.destroySource();
}
catch (const AudioPlayer::Exception& e) {
std::cout << "AudioPlayer error: " << e.what() << std::endl;
p.cleanUp();
}
}
else
std::cout << "./audio FILE FILE" << std::endl;
}
示例13: playerCallback
void AudioPlayer::playerCallback(SLAndroidSimpleBufferQueueItf bufferQueue, void *context) {
AudioPlayer* audioPlayer = static_cast<AudioPlayer*>(context);
audioPlayer->playerCallback(bufferQueue);
}
示例14: main
int main() {
const char *fn = "WRECKINGBALL.wav";
AudioPlayer* ap = AudioPlayer::file(fn);
if(!ap) {
std::cerr << "Error loading audio" << std::endl;
return 1;
}
ap->play();
char indic[] = { '|', '/', '-', '\\' };
int i = 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
std::cout << "\rPlaying.. " << indic[i];
double d = ap->progress();
double min = floor(d/60);
double sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
d = ap->duration();
min = floor(d/60);
sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
std::cout << std::flush;
if(ap->progress() > 5) {
ap->seek(rand()/(float(RAND_MAX))*ap->duration());
}
i = (i+1)%4;
} while (ap->isPlaying());
delete ap;
#if 0
// std::cout << "dataformat " << aqData.mDataFormat << std::endl;
std::cout << "bufferbytesize " << aqData.bufferByteSize << std::endl;
std::cout << "numpacketstoread " << aqData.mNumPacketsToRead << std::endl;
std::cout << "maxpacketsz " << maxPacketSize << std::endl;
std::cout << "df bpp " << aqData.mDataFormat.mBytesPerPacket << std::endl;
std::cout << "df fpp " << aqData.mDataFormat.mFramesPerPacket << std::endl;
unsigned int running =0;
sz = 4;
status = AudioFileGetProperty ( // 9
aqData.mAudioFile, // 10
kAudioQueueProperty_IsRunning , // 11
&running, // 12
&sz // 13
);
std::cout << "Running: " << running << std::endl;
running =0;
sz = 4;
status = AudioFileGetProperty ( // 9
aqData.mAudioFile, // 10
kAudioQueueProperty_IsRunning , // 11
&running, // 12
&sz // 13
);
std::cout << "Running: " << running << std::endl;
return 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
} while (aqData.mIsRunning);
CFRunLoopRunInMode ( // 10
kCFRunLoopDefaultMode,
1,
//.........这里部分代码省略.........
示例15: ex_pitchdirection
void ex_pitchdirection () {
//general
ITheFramework *frame = Factory::GetFramework ();
Decorator *decorator = ssi_create (Decorator, 0, true);
frame->AddDecorator(decorator);
ITheEventBoard *board = Factory::GetEventBoard ();
ssi_pcast (TheEventBoard, board)->getOptions()->update = 250;
// audio sensor
#ifndef SIMULATE
Audio *audio = ssi_create (Audio, "audio", true);
audio->getOptions()->scale = true;
ITransformable *audio_p = frame->AddProvider(audio, SSI_AUDIO_PROVIDER_NAME);
#else
WavReader *audio = ssi_create (WavReader, 0, true);
audio->getOptions()->setPath("audio.wav");
audio->getOptions()->scale = true;
ITransformable *audio_p = frame->AddProvider(audio, SSI_WAVREADER_PROVIDER_NAME);
#endif
frame->AddSensor(audio);
OSPitchChain * pitch = ssi_create (OSPitchChain, "pitch", true);
pitch->getOSPitchSmoother()->getOptions()->F0final = true;
pitch->getOSPitchSmoother()->getOptions()->F0finalEnv = true;
double frameSize = audio_p->getSampleRate() * 0.01;
double deltaSize = audio_p->getSampleRate() * 0.04;
pitch->getOSTransformFFT()->getOptions()->nfft = smileMath_ceilToNextPowOf2(frameSize + deltaSize); //we set the FFT frame size so it's a power of 2 but can also fit all the samples
pitch->getOSPitchShs()->getOptions()->baseSr = audio_p->getSampleRate();
ssi::ITransformable *pitch_p = frame->AddTransformer(audio_p, pitch, "0.01s", "0.04s");
OSEnergy * energy = ssi_create (OSEnergy, 0, true);
energy->getOptions()->type = OSEnergy::TYPE::RMS;
ssi::ITransformable *energy_p = frame->AddTransformer(audio_p, energy, "0.01s");
OSPitchDirection * dir = ssi_create (OSPitchDirection, 0, true);
ssi::ITransformable * xtra_src[1] = {energy_p};
ssi::ITransformable *dir_p = frame->AddTransformer(pitch_p, 1, xtra_src, dir, "0.01s");
board->RegisterSender(*dir);
SignalPainter *audio_plot = ssi_create_id (SignalPainter, 0, "plot");
audio_plot->getOptions()->setTitle("audio");
audio_plot->getOptions()->size = 10.0;
audio_plot->getOptions()->type = PaintSignalType::AUDIO;
frame->AddConsumer(audio_p, audio_plot, "0.2s");
SignalPainter *pitch_plot = ssi_create_id (SignalPainter, 0, "plot");
pitch_plot->getOptions()->setTitle("pitch");
pitch_plot->getOptions()->size = 10.0;
pitch_plot->getOptions()->type = PaintSignalType::SIGNAL;
frame->AddConsumer(pitch_p, pitch_plot, "0.2s");
SignalPainter *energy_plot = ssi_create_id (SignalPainter, 0, "plot");
energy_plot->getOptions()->setTitle("energy");
energy_plot->getOptions()->size = 10.0;
energy_plot->getOptions()->type = PaintSignalType::SIGNAL;
frame->AddConsumer(energy_p, energy_plot, "0.2s");
SignalPainter *dir_plot = ssi_create_id (SignalPainter, 0, "plot");
dir_plot->getOptions()->setTitle("direction");
dir_plot->getOptions()->size = 10.0;
dir_plot->getOptions()->type = PaintSignalType::SIGNAL;
frame->AddConsumer(dir_p, dir_plot, "0.2s");
EventMonitor *monitor = ssi_create_id (EventMonitor, 0, "monitor");
board->RegisterListener(*monitor, dir->getEventAddress());
#ifdef SIMULATE
AudioPlayer *player = ssi_create (AudioPlayer, "player", true);
player->getOptions()->bufferSize = 0.2;
player->getOptions()->remember = true;
frame->AddConsumer(audio_p, player, "0.01s");
#endif
decorator->add("console", 0, 0, 650, 800);
decorator->add("plot*", 650, 0, 400, 400);
decorator->add("monitor*", 650, 400, 400, 400);
board->Start();
frame->Start();
frame->Wait();
frame->Stop();
board->Stop();
frame->Clear();
board->Clear();
}