How to know how much audio has been played?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 15/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Lĩnh vực
- audio-video-rtc
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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;
}
- Ngôn ngữ chính
- C
- Star
- 501
- Fork
- 227
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của alsa-project/alsa-lib
-
USB-Audio: ASUS ROG Zenith II S/PDIF output mapped to wrong PCM deviceCó thể đã có người làm @byrcolin đã nhận 49 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
alsa-project/alsa-lib#532 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
alsa-project/alsa-lib#530 · 9 reaction ·
-
kernel driver
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
alsa-project/alsa-lib#529 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
alsa-project/alsa-lib#522 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
alsa-project/alsa-lib#519 ·
Tất cả issue của alsa-project/alsa-lib
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
fastfetch-cli/fastfetch#2780 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
elliotchance/vsql#2079 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 61/100
Maintainer thường phản hồi trong vòng 13 ngày
-
threadpool: a failed `pthread_cond_wait` makes Mlucas hang instead of stoppingCó thể đã có người làm @leinardi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
primesearch/Mlucas#398 ·