diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4df21..b4c0408 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ set(COMPONENT_SRCS speech_command_recognition/mn_process_commands.c - esp-tts/esp_tts_wav/wav_decoder.c - esp-tts/esp_tts_wav/wav_encoder.c ) set(COMPONENT_ADD_INCLUDEDIRS @@ -10,7 +8,6 @@ set(COMPONENT_ADD_INCLUDEDIRS speech_command_recognition/include acoustic_algorithm/include esp-tts/esp_tts_chinese/include - esp-tts/esp_tts_wav/ ) diff --git a/esp-tts/CMakeLists.txt b/esp-tts/CMakeLists.txt index 2a8b4cd..0ba316d 100644 --- a/esp-tts/CMakeLists.txt +++ b/esp-tts/CMakeLists.txt @@ -1,14 +1,8 @@ -set(COMPONENT_SRCS - ./esp_tts_wav/wav_decoder.c - ./esp_tts_wav/wav_encoder.c - ) set(COMPONENT_ADD_INCLUDEDIRS ./esp_tts_chinese/include - ./esp_tts_wav/ ) - register_component() target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp_tts_chinese") diff --git a/esp-tts/esp_tts_wav/component.mk b/esp-tts/esp_tts_wav/component.mk deleted file mode 100644 index 5b26281..0000000 --- a/esp-tts/esp_tts_wav/component.mk +++ /dev/null @@ -1,13 +0,0 @@ -# -# Component Makefile -# -# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default, -# this will take the sources in the src/ directory, compile them and link them into -# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, -# please read the SDK documents if you need to do this. -# - -COMPONENT_ADD_INCLUDEDIRS := . - -COMPONENT_SRCDIRS := . - diff --git a/esp-tts/esp_tts_wav/wav_decoder.c b/esp-tts/esp_tts_wav/wav_decoder.c deleted file mode 100644 index 118e572..0000000 --- a/esp-tts/esp_tts_wav/wav_decoder.c +++ /dev/null @@ -1,162 +0,0 @@ -/* ------------------------------------------------------------------ - * 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_decoder.h" -#include -#include -#include -#include - -#define TAG(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) - -struct wav_decoder { - FILE *wav; - uint32_t data_length; - - int format; - int sample_rate; - int bits_per_sample; - int channels; - int byte_rate; - int block_align; -}; - -static uint32_t read_tag(struct wav_decoder* wr) { - uint32_t tag = 0; - tag = (tag << 8) | fgetc(wr->wav); - tag = (tag << 8) | fgetc(wr->wav); - tag = (tag << 8) | fgetc(wr->wav); - tag = (tag << 8) | fgetc(wr->wav); - return tag; -} - -static uint32_t read_int32(struct wav_decoder* wr) { - uint32_t value = 0; - value |= fgetc(wr->wav) << 0; - value |= fgetc(wr->wav) << 8; - value |= fgetc(wr->wav) << 16; - value |= fgetc(wr->wav) << 24; - return value; -} - -static uint16_t read_int16(struct wav_decoder* wr) { - uint16_t value = 0; - value |= fgetc(wr->wav) << 0; - value |= fgetc(wr->wav) << 8; - return value; -} - -void* wav_decoder_open(const char *filename) { - struct wav_decoder* wr = (struct wav_decoder*) malloc(sizeof(*wr)); - long data_pos = 0; - memset(wr, 0, sizeof(*wr)); - - wr->wav = fopen(filename, "rb"); - if (wr->wav == NULL) { - free(wr); - return NULL; - } - - while (1) { - uint32_t tag, tag2, length; - tag = read_tag(wr); - if (feof(wr->wav)) - break; - length = read_int32(wr); - if (tag != TAG('R', 'I', 'F', 'F') || length < 4) { - fseek(wr->wav, length, SEEK_CUR); - continue; - } - tag2 = read_tag(wr); - length -= 4; - if (tag2 != TAG('W', 'A', 'V', 'E')) { - fseek(wr->wav, length, SEEK_CUR); - continue; - } - // RIFF chunk found, iterate through it - while (length >= 8) { - uint32_t subtag, sublength; - subtag = read_tag(wr); - if (feof(wr->wav)) - break; - sublength = read_int32(wr); - length -= 8; - if (length < sublength) - break; - if (subtag == TAG('f', 'm', 't', ' ')) { - if (sublength < 16) { - // Insufficient data for 'fmt ' - break; - } - wr->format = read_int16(wr); - wr->channels = read_int16(wr); - wr->sample_rate = read_int32(wr); - wr->byte_rate = read_int32(wr); - wr->block_align = read_int16(wr); - wr->bits_per_sample = read_int16(wr); - } else if (subtag == TAG('d', 'a', 't', 'a')) { - data_pos = ftell(wr->wav); - wr->data_length = sublength; - fseek(wr->wav, sublength, SEEK_CUR); - } else { - fseek(wr->wav, sublength, SEEK_CUR); - } - length -= sublength; - } - if (length > 0) { - // Bad chunk? - fseek(wr->wav, length, SEEK_CUR); - } - } - fseek(wr->wav, data_pos, SEEK_SET); - return wr; -} - -void wav_decoder_close(void* obj) { - struct wav_decoder* wr = (struct wav_decoder*) obj; - fclose(wr->wav); - free(wr); -} - -int wav_decoder_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length) { - struct wav_decoder* wr = (struct wav_decoder*) obj; - if (format) - *format = wr->format; - if (channels) - *channels = wr->channels; - if (sample_rate) - *sample_rate = wr->sample_rate; - if (bits_per_sample) - *bits_per_sample = wr->bits_per_sample; - if (data_length) - *data_length = wr->data_length; - return wr->format && wr->sample_rate; -} - -int wav_decoder_run(void* obj, unsigned char* data, unsigned int length) { - struct wav_decoder* wr = (struct wav_decoder*) obj; - int n; - if (wr->wav == NULL) - return -1; - if (length > wr->data_length) - length = wr->data_length; - n = fread(data, 1, length, wr->wav); - wr->data_length -= length; - return n; -} - diff --git a/esp-tts/esp_tts_wav/wav_decoder.h b/esp-tts/esp_tts_wav/wav_decoder.h deleted file mode 100644 index c243788..0000000 --- a/esp-tts/esp_tts_wav/wav_decoder.h +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------------------------------ - * 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. - * ------------------------------------------------------------------- - */ - -#ifndef WAV_DECODER_H -#define WAV_DECODER_H - -#ifdef __cplusplus -extern "C" { -#endif - -void* wav_decoder_open(const char *filename); -void wav_decoder_close(void* obj); -int wav_decoder_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length); -int wav_decoder_run(void* obj, unsigned char* data, unsigned int length); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/esp-tts/esp_tts_wav/wav_encoder.c b/esp-tts/esp_tts_wav/wav_encoder.c deleted file mode 100644 index aab8f55..0000000 --- a/esp-tts/esp_tts_wav/wav_encoder.c +++ /dev/null @@ -1,111 +0,0 @@ -/* ------------------------------------------------------------------ - * 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_encoder.h" -#include -#include -#include -#include - -struct wav_encoder { - FILE *wav; - int data_length; - - int sample_rate; - int bits_per_sample; - int channels; -}; - -static void write_string(struct wav_encoder* ww, const char *str) { - fputc(str[0], ww->wav); - fputc(str[1], ww->wav); - fputc(str[2], ww->wav); - fputc(str[3], ww->wav); -} - -static void write_int32(struct wav_encoder* ww, int value) { - fputc((value >> 0) & 0xff, ww->wav); - fputc((value >> 8) & 0xff, ww->wav); - fputc((value >> 16) & 0xff, ww->wav); - fputc((value >> 24) & 0xff, ww->wav); -} - -static void write_int16(struct wav_encoder* ww, int value) { - fputc((value >> 0) & 0xff, ww->wav); - fputc((value >> 8) & 0xff, ww->wav); -} - -static void write_header(struct wav_encoder* ww, int length) { - int bytes_per_frame, bytes_per_sec; - write_string(ww, "RIFF"); - write_int32(ww, 4 + 8 + 16 + 8 + length); - write_string(ww, "WAVE"); - - write_string(ww, "fmt "); - write_int32(ww, 16); - - bytes_per_frame = ww->bits_per_sample/8*ww->channels; - bytes_per_sec = bytes_per_frame*ww->sample_rate; - write_int16(ww, 1); // Format - write_int16(ww, ww->channels); // Channels - write_int32(ww, ww->sample_rate); // Samplerate - write_int32(ww, bytes_per_sec); // Bytes per sec - write_int16(ww, bytes_per_frame); // Bytes per frame - write_int16(ww, ww->bits_per_sample); // Bits per sample - - write_string(ww, "data"); - write_int32(ww, length); -} - -void* wav_encoder_open(const char *filename, int sample_rate, int bits_per_sample, int channels) { - struct wav_encoder* ww = (struct wav_encoder*) malloc(sizeof(*ww)); - memset(ww, 0, sizeof(*ww)); - ww->wav = fopen(filename, "wb"); - if (ww->wav == NULL) { - free(ww); - return NULL; - } - ww->data_length = 0; - ww->sample_rate = sample_rate; - ww->bits_per_sample = bits_per_sample; - ww->channels = channels; - - write_header(ww, ww->data_length); - return ww; -} - -void wav_encoder_close(void* obj) { - struct wav_encoder* ww = (struct wav_encoder*) obj; - if (ww->wav == NULL) { - free(ww); - return; - } - fseek(ww->wav, 0, SEEK_SET); - write_header(ww, ww->data_length); - fclose(ww->wav); - free(ww); -} - -void wav_encoder_run(void* obj, const unsigned char* data, int length) { - struct wav_encoder* ww = (struct wav_encoder*) obj; - if (ww->wav == NULL) - return; - fwrite(data, length, 1, ww->wav); - ww->data_length += length; -} - diff --git a/esp-tts/esp_tts_wav/wav_encoder.h b/esp-tts/esp_tts_wav/wav_encoder.h deleted file mode 100644 index 4fafd27..0000000 --- a/esp-tts/esp_tts_wav/wav_encoder.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ------------------------------------------------------------------ - * 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. - * ------------------------------------------------------------------- - */ - -#ifndef WAV_ENCODER_H -#define WAV_ENCODER_H - -#ifdef __cplusplus -extern "C" { -#endif - -void* wav_encoder_open(const char *filename, int sample_rate, int bits_per_sample, int channels); -void wav_encoder_close(void* obj); -void wav_encoder_run(void* obj, const unsigned char* data, int length); - -#ifdef __cplusplus -} -#endif - -#endif -