diff options
author | HyungKyu Song <hk76.song@samsung.com> | 2013-02-14 21:41:52 +0900 |
---|---|---|
committer | HyungKyu Song <hk76.song@samsung.com> | 2013-02-14 21:41:52 +0900 |
commit | 35a7f22fe17b35478b206cd0e675caaae14a7c3b (patch) | |
tree | 3e9da8eb6a913278403e100d0bbe0b9231a4b6ac /test/wav.cpp | |
parent | 54f90e8fa8d02c96e2c6d0a5bd71603dc016cf70 (diff) | |
download | opencore-amr-35a7f22fe17b35478b206cd0e675caaae14a7c3b.tar.gz opencore-amr-35a7f22fe17b35478b206cd0e675caaae14a7c3b.tar.bz2 opencore-amr-35a7f22fe17b35478b206cd0e675caaae14a7c3b.zip |
Tizen 2.0 Release2.0_release
Diffstat (limited to 'test/wav.cpp')
-rw-r--r-- | test/wav.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/wav.cpp b/test/wav.cpp new file mode 100644 index 0000000..fb3f015 --- /dev/null +++ b/test/wav.cpp @@ -0,0 +1,87 @@ +/* ------------------------------------------------------------------ + * Copyright (C) 2009 Martin Storsjo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + * ------------------------------------------------------------------- + */ + +#include "wav.h" + +void WavWriter::writeString(const char *str) { + fputc(str[0], wav); + fputc(str[1], wav); + fputc(str[2], wav); + fputc(str[3], wav); +} + +void WavWriter::writeInt32(int value) { + fputc((value >> 0) & 0xff, wav); + fputc((value >> 8) & 0xff, wav); + fputc((value >> 16) & 0xff, wav); + fputc((value >> 24) & 0xff, wav); +} + +void WavWriter::writeInt16(int value) { + fputc((value >> 0) & 0xff, wav); + fputc((value >> 8) & 0xff, wav); +} + +void WavWriter::writeHeader(int length) { + writeString("RIFF"); + writeInt32(4 + 8 + 16 + 8 + length); + writeString("WAVE"); + + writeString("fmt "); + writeInt32(16); + + int bytesPerFrame = bitsPerSample/8*channels; + int bytesPerSec = bytesPerFrame*sampleRate; + writeInt16(1); // Format + writeInt16(channels); // Channels + writeInt32(sampleRate); // Samplerate + writeInt32(bytesPerSec); // Bytes per sec + writeInt16(bytesPerFrame); // Bytes per frame + writeInt16(bitsPerSample); // Bits per sample + + writeString("data"); + writeInt32(length); +} + +WavWriter::WavWriter(const char *filename, int sampleRate, int bitsPerSample, int channels) { + wav = fopen(filename, "wb"); + if (wav == NULL) + return; + dataLength = 0; + this->sampleRate = sampleRate; + this->bitsPerSample = bitsPerSample; + this->channels = channels; + + writeHeader(dataLength); +} + +WavWriter::~WavWriter() { + if (wav == NULL) + return; + fseek(wav, 0, SEEK_SET); + writeHeader(dataLength); + fclose(wav); +} + +void WavWriter::writeData(const unsigned char* data, int length) { + if (wav == NULL) + return; + fwrite(data, length, 1, wav); + dataLength += length; +} + |