How to know how much audio has been played?
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 15/100
- Issue 类型
- 文档
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
调研方向
The issue is a usage question, not a reported defect, and it names no repository file. Start from the sample program's playback loop, which calls snd_pcm_delay and computes a played time from it, and check how that calculation relates to the ALSA delay semantics. Done means the question has a clear, verified answer, such as a documented way to get the playback position, reached with the maintainers' input. The thread has one comment and no reply in about 499 days.
由索引模型根据 Issue 内容生成。
描述
I tried to get an answer from AI, but the result has discrepancies.
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <thread>
#include <alsa/asoundlib.h>
#define SAMPLE_RATE 44100
#define FREQUENCY 440.0 // A4 note
#define DURATION 5.0 // seconds
using namespace std::chrono_literals;
int main() {
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;
unsigned int rate = SAMPLE_RATE;
int dir;
int pcm;
pcm = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
if (pcm < 0) {
std::cerr << "Unable to open PCM device: " << snd_strerror(pcm) << std::endl;
return 1;
}
snd_pcm_hw_params_alloca(¶ms);
snd_pcm_hw_params_any(handle, params);
snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir);
snd_pcm_hw_params_set_channels(handle, params, 1);
pcm = snd_pcm_hw_params(handle, params);
if (pcm < 0) {
std::cerr << "Unable to set HW parameters: " << snd_strerror(pcm) << std::endl;
return 1;
}
int samples = static_cast<int>(DURATION * SAMPLE_RATE);
int16_t *buffer = new int16_t[samples];
for (int i = 0; i < samples; ++i) {
buffer[i] = static_cast<int16_t>(32767 * sin(2 * M_PI * FREQUENCY * i / SAMPLE_RATE));
}
pcm = snd_pcm_writei(handle, buffer, samples);
if (pcm < 0) {
std::cerr << "Playback error: " << snd_strerror(pcm) << std::endl;
}
while (true) {
snd_pcm_sframes_t delay;
int rc = snd_pcm_delay(handle, &delay);
if (rc == 0) {
double played_sec = (samples - delay) / 44100.0f;
printf("Played: %.2f sec\n", played_sec);
} else {
std::cerr << snd_strerror(rc) << std::endl;
break;
}
}
snd_pcm_drain(handle);
delete[] buffer;
snd_pcm_close(handle);
return 0;
}
- 主要语言
- C
- 星标
- 501
- 派生
- 227
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
alsa-project/alsa-lib 的其他 Issue
-
USB-Audio: ASUS ROG Zenith II S/PDIF output mapped to wrong PCM device可能已有人在做 @byrcolin 于 49 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
alsa-project/alsa-lib#532 ·
-
难度 5/5 一周以上 新手友好度 12/100
alsa-project/alsa-lib#530 · 9 个 reaction ·
-
kernel driver
难度 5/5 一周以上 新手友好度 12/100
alsa-project/alsa-lib#529 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 55/100
alsa-project/alsa-lib#522 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 15/100
alsa-project/alsa-lib#519 ·
查看 alsa-project/alsa-lib 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
fastfetch-cli/fastfetch#2780 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
elliotchance/vsql#2079 ·
维护者通常 1 天内回复
-
category:port-update
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 2 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 61/100
维护者通常 13 天内回复