[SCM] opencore-amr packaging branch, master, updated. upstream/0.1.2-10-g7bf1e45
ceros-guest at users.alioth.debian.org
ceros-guest at users.alioth.debian.org
Fri Sep 18 20:48:41 UTC 2009
The following commit has been merged in the master branch:
commit ea5a7633ab4a437b7e77e857b5337dea2c71a93c
Author: Martin Storsjo <martin at martin.st>
Date: Tue May 19 13:50:33 2009 +0200
Added a few test applications
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..b465d2f
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,23 @@
+CFLAGS = -Wall -pedantic
+CXXFLAGS = $(CFLAGS)
+LDFLAGS =
+
+all: amrnb-dec amrnb-enc amrwb-dec
+
+amrnb-dec: amrnb-dec.o wav.o
+ $(CXX) -o $@ $+ $(LDFLAGS) -lopencore-amrnb
+
+amrnb-enc: amrnb-enc.o
+ $(CC) -o $@ $+ $(LDFLAGS) -lm -lopencore-amrnb
+
+amrwb-dec: amrwb-dec.o wav.o
+ $(CXX) -o $@ $+ $(LDFLAGS) -lopencore-amrwb
+
+# To check that both libraries can be linked in statically at the same
+# time without duplicate symbols
+linkboth: linkboth.o
+ $(CC) -static -o $@ $+ $(LDFLAGS) -lopencore-amrnb -lopencore-amrwb
+
+clean:
+ rm -f amrnb-dec amrnb-enc amrwb-dec linkboth *.o out.wav out.amr
+
diff --git a/test/amrnb-dec.cpp b/test/amrnb-dec.cpp
new file mode 100644
index 0000000..86922b5
--- /dev/null
+++ b/test/amrnb-dec.cpp
@@ -0,0 +1,83 @@
+/* ------------------------------------------------------------------
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "wav.h"
+extern "C" {
+#include <opencore-amrnb/interf_dec.h>
+}
+
+/* From WmfDecBytesPerFrame in dec_input_format_tab.cpp */
+const int sizes[] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5, 0, 0, 0, 0 };
+
+
+int main(int argc, char *argv[]) {
+ if (argc < 2) {
+ fprintf(stderr, "%s in.amr\n", argv[0]);
+ return 1;
+ }
+
+ FILE* in = fopen(argv[1], "rb");
+ if (!in) {
+ perror(argv[1]);
+ return 1;
+ }
+ char header[6];
+ int n = fread(header, 1, 6, in);
+ if (n != 6 || memcmp(header, "#!AMR\n", 6)) {
+ fprintf(stderr, "Bad header\n");
+ return 1;
+ }
+
+ WavWriter wav("out.wav", 8000, 16, 1);
+
+ void* amr = Decoder_Interface_init();
+ while (true) {
+ uint8_t buffer[500];
+ /* Read the mode byte */
+ n = fread(buffer, 1, 1, in);
+ if (n <= 0)
+ break;
+ /* Find the packet size */
+ int size = sizes[(buffer[0] >> 3) & 0x0f];
+ if (size <= 0)
+ break;
+ n = fread(buffer + 1, 1, size, in);
+ if (n != size)
+ break;
+
+ /* Decode the packet */
+ int16_t outbuffer[160];
+ Decoder_Interface_Decode(amr, buffer, outbuffer, 0);
+
+ /* Convert to little endian and write to wav */
+ uint8_t littleendian[320];
+ uint8_t* ptr = littleendian;
+ for (int i = 0; i < 160; i++) {
+ *ptr++ = (outbuffer[i] >> 0) & 0xff;
+ *ptr++ = (outbuffer[i] >> 8) & 0xff;
+ }
+ wav.writeData(littleendian, 320);
+ }
+ fclose(in);
+ Decoder_Interface_exit(amr);
+ return 0;
+}
+
diff --git a/amrwb/if_rom.h b/test/amrnb-enc.c
similarity index 56%
copy from amrwb/if_rom.h
copy to test/amrnb-enc.c
index 8977e03..2889a74 100644
--- a/amrwb/if_rom.h
+++ b/test/amrnb-enc.c
@@ -16,18 +16,35 @@
* -------------------------------------------------------------------
*/
-#ifndef OPENCORE_AMRWB_IF_ROM_H
-#define OPENCORE_AMRWB_IF_ROM_H
+#include <stdio.h>
+#include <stdint.h>
+#include <math.h>
+#include <opencore-amrnb/interf_enc.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+int main(int argc, char *argv[]) {
+ int i, j;
+ void* amr;
+ FILE* out;
+ int sample_pos = 0;
-#include <stdint.h>
-typedef int16_t Word16;
+ amr = Encoder_Interface_init(0);
+ out = fopen("out.amr", "wb");
+
+ fwrite("#!AMR\n", 1, 6, out);
+ for (i = 0; i < 1000; i++) {
+ short buf[160];
+ uint8_t outbuf[500];
+ int n;
+ for (j = 0; j < 160; j++) {
+ buf[j] = 32767*sin(440*2*3.141592654*sample_pos/8000);
+ sample_pos++;
+ }
+ n = Encoder_Interface_Encode(amr, MR475, buf, outbuf, 0);
+ fwrite(outbuf, 1, n, out);
+ }
+ fclose(out);
+ Encoder_Interface_exit(amr);
-#ifdef __cplusplus
+ return 0;
}
-#endif
-#endif
diff --git a/test/amrwb-dec.cpp b/test/amrwb-dec.cpp
new file mode 100644
index 0000000..22bc9e7
--- /dev/null
+++ b/test/amrwb-dec.cpp
@@ -0,0 +1,81 @@
+/* ------------------------------------------------------------------
+ * 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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "wav.h"
+extern "C" {
+#include <opencore-amrwb/dec_if.h>
+}
+
+/* From pvamrwbdecoder_api.h, by dividing by 8 and rounding up */
+const int sizes[] = { 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, -1, -1, -1, -1, -1, -1 };
+
+int main(int argc, char *argv[]) {
+ if (argc < 2) {
+ fprintf(stderr, "%s in.amr\n", argv[0]);
+ return 1;
+ }
+
+ FILE* in = fopen(argv[1], "rb");
+ if (!in) {
+ perror(argv[1]);
+ return 1;
+ }
+ char header[9];
+ int n = fread(header, 1, 9, in);
+ if (n != 9 || memcmp(header, "#!AMR-WB\n", 9)) {
+ fprintf(stderr, "Bad header\n");
+ return 1;
+ }
+
+ WavWriter wav("out.wav", 16000, 16, 1);
+ void* amr = D_IF_init();
+ while (true) {
+ uint8_t buffer[500];
+ /* Read the mode byte */
+ n = fread(buffer, 1, 1, in);
+ if (n <= 0)
+ break;
+ /* Find the packet size */
+ int size = sizes[(buffer[0] >> 3) & 0x0f];
+ if (size <= 0)
+ break;
+ n = fread(buffer + 1, 1, size, in);
+ if (n != size)
+ break;
+
+ /* Decode the packet */
+ int16_t outbuffer[320];
+ D_IF_decode(amr, buffer, outbuffer, 0);
+
+ /* Convert to little endian and write to wav */
+ uint8_t littleendian[640];
+ uint8_t* ptr = littleendian;
+ for (int i = 0; i < 320; i++) {
+ *ptr++ = (outbuffer[i] >> 0) & 0xff;
+ *ptr++ = (outbuffer[i] >> 8) & 0xff;
+ }
+ wav.writeData(littleendian, 640);
+ }
+ fclose(in);
+ D_IF_exit(amr);
+ return 0;
+}
+
diff --git a/oscl/oscl_mem.h b/test/linkboth.c
similarity index 65%
copy from oscl/oscl_mem.h
copy to test/linkboth.c
index 476b3b3..4a9cf3f 100644
--- a/oscl/oscl_mem.h
+++ b/test/linkboth.c
@@ -16,23 +16,20 @@
* -------------------------------------------------------------------
*/
-#ifndef OSCL_MEM_H
-#define OSCL_MEM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
#include <string.h>
-#define oscl_malloc malloc
-#define oscl_free free
-#define oscl_memset memset
-#define oscl_memmove memmove
-#define oscl_memcpy memcpy
+#include <opencore-amrnb/interf_dec.h>
+#include <opencore-amrnb/interf_enc.h>
+#include <opencore-amrwb/dec_if.h>
-#ifdef __cplusplus
+int main(int argc, char *argv[]) {
+ void* amrnb = Decoder_Interface_init();
+ void* amrnb_enc = Encoder_Interface_init(0);
+ void* amrwb = D_IF_init();
+ Decoder_Interface_exit(amrnb);
+ Encoder_Interface_exit(amrnb_enc);
+ D_IF_exit(amrwb);
+ return 0;
}
-#endif
-#endif
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;
+}
+
diff --git a/amrwb/dec_if.h b/test/wav.h
similarity index 62%
copy from amrwb/dec_if.h
copy to test/wav.h
index 56acdaa..ae77383 100644
--- a/amrwb/dec_if.h
+++ b/test/wav.h
@@ -16,21 +16,32 @@
* -------------------------------------------------------------------
*/
-#ifndef OPENCORE_AMRWB_DEC_IF_H
-#define OPENCORE_AMRWB_DEC_IF_H
+#ifndef WAV_H
+#define WAV_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <stdio.h>
-#define _good_frame 0
+class WavWriter {
+public:
+ WavWriter(const char *filename, int sampleRate, int bitsPerSample, int channels);
+ ~WavWriter();
-void* D_IF_init(void);
-void D_IF_decode(void* state, const unsigned char* bits, short* synth, int bfi);
-void D_IF_exit(void* state);
+ void writeData(const unsigned char* data, int length);
-#ifdef __cplusplus
-}
-#endif
+private:
+ void writeString(const char *str);
+ void writeInt32(int value);
+ void writeInt16(int value);
+
+ void writeHeader(int length);
+
+ FILE *wav;
+ int dataLength;
+
+ int sampleRate;
+ int bitsPerSample;
+ int channels;
+};
#endif
+
--
opencore-amr packaging
More information about the pkg-multimedia-commits
mailing list