summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/test-resample.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-12-17 14:49:17 -0800
committerGlenn Kasten <gkasten@google.com>2013-12-17 16:00:51 -0800
commitf5293648b727fb3909cd2300a73377f032f8b050 (patch)
tree7bc4568fdd695d312d9ae6447ec69320bdcf2c62 /services/audioflinger/test-resample.cpp
parent9a1c785c019bdb25fefa7d1c0e50862ddc0e4e21 (diff)
downloadframeworks_av-f5293648b727fb3909cd2300a73377f032f8b050.zip
frameworks_av-f5293648b727fb3909cd2300a73377f032f8b050.tar.gz
frameworks_av-f5293648b727fb3909cd2300a73377f032f8b050.tar.bz2
Use libsndfile to write .wav files
This will reduce code duplication, and allow us take advantage of more advanced capabilities of libsndfile in the future. Change-Id: I25fa2b6d0c21e325aeaf05bda62cf7aab0c5deb4
Diffstat (limited to 'services/audioflinger/test-resample.cpp')
-rw-r--r--services/audioflinger/test-resample.cpp68
1 files changed, 23 insertions, 45 deletions
diff --git a/services/audioflinger/test-resample.cpp b/services/audioflinger/test-resample.cpp
index 39018b2..dcd00fc 100644
--- a/services/audioflinger/test-resample.cpp
+++ b/services/audioflinger/test-resample.cpp
@@ -26,43 +26,12 @@
#include <errno.h>
#include <time.h>
#include <math.h>
+#include <audio_utils/sndfile.h>
using namespace android;
bool gVerbose = false;
-struct HeaderWav {
- HeaderWav(size_t size, int nc, int sr, int bits) {
- strncpy(RIFF, "RIFF", 4);
- chunkSize = size + sizeof(HeaderWav);
- strncpy(WAVE, "WAVE", 4);
- strncpy(fmt, "fmt ", 4);
- fmtSize = 16;
- audioFormat = 1;
- numChannels = nc;
- samplesRate = sr;
- byteRate = sr * numChannels * (bits/8);
- align = nc*(bits/8);
- bitsPerSample = bits;
- strncpy(data, "data", 4);
- dataSize = size;
- }
-
- char RIFF[4]; // RIFF
- uint32_t chunkSize; // File size
- char WAVE[4]; // WAVE
- char fmt[4]; // fmt\0
- uint32_t fmtSize; // fmt size
- uint16_t audioFormat; // 1=PCM
- uint16_t numChannels; // num channels
- uint32_t samplesRate; // sample rate in hz
- uint32_t byteRate; // Bps
- uint16_t align; // 2=16-bit mono, 4=16-bit stereo
- uint16_t bitsPerSample; // bits per sample
- char data[4]; // "data"
- uint32_t dataSize; // size
-};
-
static int usage(const char* name) {
fprintf(stderr,"Usage: %s [-p] [-h] [-v] [-s] [-q {dq|lq|mq|hq|vhq}] [-i input-sample-rate] "
"[-o output-sample-rate] [<input-file>] <output-file>\n", name);
@@ -306,20 +275,29 @@ int main(int argc, char* argv[]) {
}
// write output to disk
- int output_fd = open(file_out, O_WRONLY | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (output_fd < 0) {
- fprintf(stderr, "open: %s\n", strerror(errno));
- return -1;
- }
-
if (writeHeader) {
- HeaderWav wav(out_frames * channels * sizeof(int16_t), channels, output_freq, 16);
- write(output_fd, &wav, sizeof(wav));
+ SF_INFO info;
+ info.frames = 0;
+ info.samplerate = output_freq;
+ info.channels = channels;
+ info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
+ SNDFILE *sf = sf_open(file_out, SFM_WRITE, &info);
+ if (sf == NULL) {
+ perror(file_out);
+ return EXIT_FAILURE;
+ }
+ (void) sf_writef_short(sf, convert, out_frames);
+ sf_close(sf);
+ } else {
+ int output_fd = open(file_out, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (output_fd < 0) {
+ perror(file_out);
+ return EXIT_FAILURE;
+ }
+ write(output_fd, convert, out_frames * channels * sizeof(int16_t));
+ close(output_fd);
}
- write(output_fd, convert, out_frames * channels * sizeof(int16_t));
- close(output_fd);
-
- return 0;
+ return EXIT_SUCCESS;
}