summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/test-resample.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-12-17 15:22:08 -0800
committerGlenn Kasten <gkasten@google.com>2013-12-17 16:04:29 -0800
commitbd72d22097f78f5bd668b223bc8c94e351311e31 (patch)
tree2d6acf288135eeb1149e1d631db3e8fd2ef4626e /services/audioflinger/test-resample.cpp
parentf5293648b727fb3909cd2300a73377f032f8b050 (diff)
downloadframeworks_av-bd72d22097f78f5bd668b223bc8c94e351311e31.zip
frameworks_av-bd72d22097f78f5bd668b223bc8c94e351311e31.tar.gz
frameworks_av-bd72d22097f78f5bd668b223bc8c94e351311e31.tar.bz2
Add ability to read .wav files to test-resample
Previously test-resample could only read .raw files, and the input sample rate had to be specified. Now the input sample rate is derived from the input file. This also allows us to read 8-bit PCM files, and other formats such as floating-point in the future. However, the ability to read raw files is lost. A workaround is to use sox or equivalent on the host. Change-Id: Icd06b4d02482b3ad07bf03979f46860e68d38ad9
Diffstat (limited to 'services/audioflinger/test-resample.cpp')
-rw-r--r--services/audioflinger/test-resample.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/services/audioflinger/test-resample.cpp b/services/audioflinger/test-resample.cpp
index dcd00fc..0d00a0f 100644
--- a/services/audioflinger/test-resample.cpp
+++ b/services/audioflinger/test-resample.cpp
@@ -38,14 +38,14 @@ static int usage(const char* name) {
fprintf(stderr," -p enable profiling\n");
fprintf(stderr," -h create wav file\n");
fprintf(stderr," -v verbose : log buffer provider calls\n");
- fprintf(stderr," -s stereo\n");
+ fprintf(stderr," -s stereo (ignored if input file is specified)\n");
fprintf(stderr," -q resampler quality\n");
fprintf(stderr," dq : default quality\n");
fprintf(stderr," lq : low quality\n");
fprintf(stderr," mq : medium quality\n");
fprintf(stderr," hq : high quality\n");
fprintf(stderr," vhq : very high quality\n");
- fprintf(stderr," -i input file sample rate\n");
+ fprintf(stderr," -i input file sample rate (ignored if input file is specified)\n");
fprintf(stderr," -o output file sample rate\n");
return -1;
}
@@ -123,24 +123,19 @@ int main(int argc, char* argv[]) {
size_t input_size;
void* input_vaddr;
if (argc == 2) {
- struct stat st;
- if (stat(file_in, &st) < 0) {
- fprintf(stderr, "stat: %s\n", strerror(errno));
- return -1;
- }
-
- int input_fd = open(file_in, O_RDONLY);
- if (input_fd < 0) {
- fprintf(stderr, "open: %s\n", strerror(errno));
- return -1;
- }
-
- input_size = st.st_size;
- input_vaddr = mmap(0, input_size, PROT_READ, MAP_PRIVATE, input_fd, 0);
- if (input_vaddr == MAP_FAILED ) {
- fprintf(stderr, "mmap: %s\n", strerror(errno));
- return -1;
+ SF_INFO info;
+ info.format = 0;
+ SNDFILE *sf = sf_open(file_in, SFM_READ, &info);
+ if (sf == NULL) {
+ perror(file_in);
+ return EXIT_FAILURE;
}
+ input_size = info.frames * info.channels * sizeof(short);
+ input_vaddr = malloc(input_size);
+ (void) sf_readf_short(sf, (short *) input_vaddr, info.frames);
+ sf_close(sf);
+ channels = info.channels;
+ input_freq = info.samplerate;
} else {
double k = 1000; // Hz / s
double time = (input_freq / 2) / k;