Testing
This commit is contained in:
parent
ed07022916
commit
39ab9d452f
22
dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt
Normal file
22
dialer/android/app/src/main/cpp/audio-hijack/CMakeLists.txt
Normal 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 TinyALSA’s CMakeLists.txt
|
||||
target_link_libraries(cap_pcm PRIVATE tinyalsa)
|
26
dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c
Normal file
26
dialer/android/app/src/main/cpp/audio-hijack/cap_pcm.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user