spotify会话回调get

spotify会话回调get

本文介绍了spotify会话回调get_audio_buffer_stats的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Spotify中制作一个程序来收集音频数据.我在API中看到有一个回调get_audio_buffer_stats,其中包含断断续续和示例.我尝试将其添加到程序中(我只是在修改自动点唱机示例),但是即使关闭wifi并等待歌曲停止播放,它也只能打印0来表示口吃和采样.通过添加代码,我的意思是我为其创建了一个回调函数,并将其添加到会话回调中.我想念什么吗?谁能帮助我使此回调正常工作?谢谢!我的代码如下:

I'm trying to make a program in Spotify that collects the audio data. I saw in the API that there is a callback get_audio_buffer_stats, which has stutter and samples. I tried adding that to the program (I am just modifying the jukebox example), but it only ever prints 0 for stutter and samples, even when I turn off the wifi and wait for the song to stop playing. And by adding the code, I mean that I made a callback function for it, and I added it to the session callbacks. Am I missing something? Can anyone help me to get this callback to work? Thanks! My code is below:

static void get_audio_buffer_stats(sp_session *sess, sp_audio_buffer_stats *stats)
{
pthread_mutex_lock(&g_notify_mutex);

//log session data
stuttervariable = stats->stutter;
samplesvariable = stats->samples;

printf("stutter, %d\n", stuttervariable);
printf("samples, %d\n", samplesvariable);

pthread_cond_signal(&g_notify_cond);
pthread_mutex_unlock(&g_notify_mutex);

}

/**
 * The session callbacks
 */
static sp_session_callbacks session_callbacks = {
.logged_in = &logged_in,
.notify_main_thread = &notify_main_thread,
.music_delivery = &music_delivery,
.metadata_updated = &metadata_updated,
.play_token_lost = &play_token_lost,
.log_message = NULL,
.end_of_track = &end_of_track,
.get_audio_buffer_stats = &get_audio_buffer_stats,
};

推荐答案

我认为get_audio_buffer_stats的想法是 you 应该告诉 libspotify 发生了口吃,并且您的缓冲区中剩余了多少样本.当它调用get_audio_buffer_stats时,它将传递一个指向您应该填充的结构的指针.大概,如果您告诉libspotify遭受口吃,它将尝试向您发送更多数据,以使缓冲区更满.通过告诉libspotify缓冲区有多满,它可以适应时钟的漂移,使您消耗音频的速度比预期的快或慢.

I think the idea with get_audio_buffer_stats is that you are supposed to tell libspotify if you've suffered stuttering and how many samples are left in your buffer. When it calls get_audio_buffer_stats, it passes a pointer to a struct that you are supposed to fill in. Presumably if you tell libspotify that you're suffering stutter it will try to send you a bit more data to keep your buffer more full. By telling libspotify how full your buffer is, it can accommodate for drift in your clock causing you to consume audio slightly faster or slower than it expects.

这篇关于spotify会话回调get_audio_buffer_stats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 06:08