From 39ab9d452f17569f748dadd4b50a4f443d875098 Mon Sep 17 00:00:00 2001 From: stcb <21@stcb.cc> Date: Sat, 21 Jun 2025 12:12:11 +0200 Subject: [PATCH] Testing --- .../src/main/cpp/audio-hijack/CMakeLists.txt | 22 ++++++++++++++++ .../app/src/main/cpp/audio-hijack/cap_pcm.c | 26 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt create mode 100644 dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c diff --git a/dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt b/dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt new file mode 100644 index 0000000..5069963 --- /dev/null +++ b/dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt @@ -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 TinyALSA’s CMakeLists.txt +target_link_libraries(cap_pcm PRIVATE tinyalsa) diff --git a/dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c b/dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c new file mode 100644 index 0000000..b4706db --- /dev/null +++ b/dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c @@ -0,0 +1,26 @@ +#include +#include +#include + +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; +}