Compare commits

...

1 Commits

Author SHA1 Message Date
39ab9d452f Testing
All checks were successful
/ build (push) Successful in 10m14s
/ build-stealth (push) Successful in 10m15s
/ mirror (push) Successful in 5s
2025-06-21 12:12:11 +02:00
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.22)
project(cap_pcm C)
# Fetch TinyALSA from GitHub
include(FetchContent)
FetchContent_Declare(
tinyalsa
GIT_REPOSITORY https://github.com/tinyalsa/tinyalsa.git
GIT_TAG v2.0.0
)
FetchContent_MakeAvailable(tinyalsa)
# Your executable
add_executable(cap_pcm cap_pcm.c)
# Tell the compiler where to find the headers
target_include_directories(cap_pcm PRIVATE
${tinyalsa_SOURCE_DIR}/include
)
# Link against the library target defined by TinyALSAs CMakeLists.txt
target_link_libraries(cap_pcm PRIVATE tinyalsa)

View File

@ -0,0 +1,26 @@
#include <tinyalsa/asoundlib.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
unsigned rate = (argc > 1) ? atoi(argv[1]) : 8000;
struct pcm_config cfg = {
.channels = 1,
.rate = rate,
.format = PCM_FORMAT_S16_LE,
.period_size = 160, // 20 ms @ 8 kHz
.period_count = 4,
};
struct pcm *pcm = pcm_open(0, 0, PCM_IN, &cfg); // card 0, device 0, CAPTURE
if (!pcm || !pcm_is_ready(pcm)) return 1;
unsigned char buf[320]; // 160 samples * 2 bytes
while (1) {
if (pcm_read(pcm, buf, sizeof(buf)) == 0)
fwrite(buf, 1, sizeof(buf), stdout); // stream to pipe
else
break;
}
pcm_close(pcm);
return 0;
}