diff --git a/aeneas/cdtw/cint.c b/aeneas/cdtw/cint.c deleted file mode 120000 index 8e1c9dae..00000000 --- a/aeneas/cdtw/cint.c +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.c \ No newline at end of file diff --git a/aeneas/cdtw/cint.c b/aeneas/cdtw/cint.c new file mode 100644 index 00000000..99541bfc --- /dev/null +++ b/aeneas/cdtw/cint.c @@ -0,0 +1,111 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#include "cint.h" + +uint8_t le_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint8_t be_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint16_t le_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +uint16_t be_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +uint32_t le_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +uint32_t be_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +int8_t le_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int8_t be_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int16_t le_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +int16_t be_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +int32_t le_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +int32_t be_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +void cpu_to_le_u8(unsigned char *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_u8(uint8_t *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_u16(unsigned char *buf, uint16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_u16(uint8_t *buf, uint16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_u32(unsigned char *buf, uint32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_u32(uint8_t *buf, uint32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + +void cpu_to_le_s8(unsigned char *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_s8(uint8_t *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_s16(unsigned char *buf, int16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_s16(uint8_t *buf, int16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_s32(unsigned char *buf, int32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_s32(uint8_t *buf, int32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + diff --git a/aeneas/cdtw/cint.h b/aeneas/cdtw/cint.h deleted file mode 120000 index 27a6bb39..00000000 --- a/aeneas/cdtw/cint.h +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.h \ No newline at end of file diff --git a/aeneas/cdtw/cint.h b/aeneas/cdtw/cint.h new file mode 100644 index 00000000..a8abed0e --- /dev/null +++ b/aeneas/cdtw/cint.h @@ -0,0 +1,58 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#ifdef _MSC_VER +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include +#endif + +uint8_t le_u8_to_cpu(const unsigned char *buf); +uint8_t be_u8_to_cpu(const unsigned char *buf); +uint16_t le_u16_to_cpu(const unsigned char *buf); +uint16_t be_u16_to_cpu(const unsigned char *buf); +uint32_t le_u32_to_cpu(const unsigned char *buf); +uint32_t be_u32_to_cpu(const unsigned char *buf); + +int8_t le_s8_to_cpu(const unsigned char *buf); +int8_t be_s8_to_cpu(const unsigned char *buf); +int16_t le_s16_to_cpu(const unsigned char *buf); +int16_t be_s16_to_cpu(const unsigned char *buf); +int32_t le_s32_to_cpu(const unsigned char *buf); +int32_t be_s32_to_cpu(const unsigned char *buf); + +void cpu_to_le_u8(unsigned char *buf, uint8_t val); +void cpu_to_be_u8(unsigned char *buf, uint8_t val); +void cpu_to_le_u16(unsigned char *buf, uint16_t val); +void cpu_to_be_u16(unsigned char *buf, uint16_t val); +void cpu_to_le_u32(unsigned char *buf, uint32_t val); +void cpu_to_be_u32(unsigned char *buf, uint32_t val); + +void cpu_to_le_s8(unsigned char *buf, int8_t val); +void cpu_to_be_s8(unsigned char *buf, int8_t val); +void cpu_to_le_s16(unsigned char *buf, int16_t val); +void cpu_to_be_s16(unsigned char *buf, int16_t val); +void cpu_to_le_s32(unsigned char *buf, int32_t val); +void cpu_to_be_s32(unsigned char *buf, int32_t val); + diff --git a/aeneas/cmfcc/cint.c b/aeneas/cmfcc/cint.c deleted file mode 120000 index 8e1c9dae..00000000 --- a/aeneas/cmfcc/cint.c +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.c \ No newline at end of file diff --git a/aeneas/cmfcc/cint.c b/aeneas/cmfcc/cint.c new file mode 100644 index 00000000..99541bfc --- /dev/null +++ b/aeneas/cmfcc/cint.c @@ -0,0 +1,111 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#include "cint.h" + +uint8_t le_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint8_t be_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint16_t le_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +uint16_t be_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +uint32_t le_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +uint32_t be_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +int8_t le_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int8_t be_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int16_t le_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +int16_t be_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +int32_t le_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +int32_t be_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +void cpu_to_le_u8(unsigned char *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_u8(uint8_t *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_u16(unsigned char *buf, uint16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_u16(uint8_t *buf, uint16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_u32(unsigned char *buf, uint32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_u32(uint8_t *buf, uint32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + +void cpu_to_le_s8(unsigned char *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_s8(uint8_t *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_s16(unsigned char *buf, int16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_s16(uint8_t *buf, int16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_s32(unsigned char *buf, int32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_s32(uint8_t *buf, int32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + diff --git a/aeneas/cmfcc/cint.h b/aeneas/cmfcc/cint.h deleted file mode 120000 index 27a6bb39..00000000 --- a/aeneas/cmfcc/cint.h +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.h \ No newline at end of file diff --git a/aeneas/cmfcc/cint.h b/aeneas/cmfcc/cint.h new file mode 100644 index 00000000..a8abed0e --- /dev/null +++ b/aeneas/cmfcc/cint.h @@ -0,0 +1,58 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#ifdef _MSC_VER +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include +#endif + +uint8_t le_u8_to_cpu(const unsigned char *buf); +uint8_t be_u8_to_cpu(const unsigned char *buf); +uint16_t le_u16_to_cpu(const unsigned char *buf); +uint16_t be_u16_to_cpu(const unsigned char *buf); +uint32_t le_u32_to_cpu(const unsigned char *buf); +uint32_t be_u32_to_cpu(const unsigned char *buf); + +int8_t le_s8_to_cpu(const unsigned char *buf); +int8_t be_s8_to_cpu(const unsigned char *buf); +int16_t le_s16_to_cpu(const unsigned char *buf); +int16_t be_s16_to_cpu(const unsigned char *buf); +int32_t le_s32_to_cpu(const unsigned char *buf); +int32_t be_s32_to_cpu(const unsigned char *buf); + +void cpu_to_le_u8(unsigned char *buf, uint8_t val); +void cpu_to_be_u8(unsigned char *buf, uint8_t val); +void cpu_to_le_u16(unsigned char *buf, uint16_t val); +void cpu_to_be_u16(unsigned char *buf, uint16_t val); +void cpu_to_le_u32(unsigned char *buf, uint32_t val); +void cpu_to_be_u32(unsigned char *buf, uint32_t val); + +void cpu_to_le_s8(unsigned char *buf, int8_t val); +void cpu_to_be_s8(unsigned char *buf, int8_t val); +void cpu_to_le_s16(unsigned char *buf, int16_t val); +void cpu_to_be_s16(unsigned char *buf, int16_t val); +void cpu_to_le_s32(unsigned char *buf, int32_t val); +void cpu_to_be_s32(unsigned char *buf, int32_t val); + diff --git a/aeneas/cmfcc/cwave_func.c b/aeneas/cmfcc/cwave_func.c deleted file mode 120000 index 05111983..00000000 --- a/aeneas/cmfcc/cwave_func.c +++ /dev/null @@ -1 +0,0 @@ -../cwave/cwave_func.c \ No newline at end of file diff --git a/aeneas/cmfcc/cwave_func.c b/aeneas/cmfcc/cwave_func.c new file mode 100644 index 00000000..5e717e99 --- /dev/null +++ b/aeneas/cmfcc/cwave_func.c @@ -0,0 +1,268 @@ +/* + +Python C Extension for reading WAVE mono files. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#include +#include +#include + +#include "cwave_func.h" + +static const int CWAVE_BUFFER_SIZE = 4096; + +// convert a little-endian buffer to signed double +static double _le_to_double(unsigned char *buffer, const uint32_t length) { + if (length == 1) { + return ((double)le_s8_to_cpu(buffer)) / 128; + } + if (length == 2) { + return ((double)le_s16_to_cpu(buffer)) / 32768; + } + if (length == 4) { + return ((double)le_s32_to_cpu(buffer)) / 2147483648; + } + return 0.0; +} + +// read a little-endian u16 field +static int _read_le_u16_field(FILE *ptr, uint16_t *dest) { + unsigned char buffer[2]; + + if (fread(buffer, 2, 1, ptr) != 1) { + return CWAVE_FAILURE; + } + *dest = le_u16_to_cpu(buffer); + return CWAVE_SUCCESS; +} + +// read a little-endian u32 field +static int _read_le_u32_field(FILE *ptr, uint32_t *dest) { + unsigned char buffer[4]; + + if (fread(buffer, 4, 1, ptr) != 1) { + return CWAVE_FAILURE; + } + *dest = le_u32_to_cpu(buffer); + return CWAVE_SUCCESS; +} + +// read a big-endian field +static int _read_be_field(FILE *ptr, char *dest, const int length) { + if (fread(dest, length, 1, ptr) != 1) { + return CWAVE_FAILURE; + } + return CWAVE_SUCCESS; +} + +// find the "match" chunk, and store its size in "size" +static int _seek_to_chunk(FILE *ptr, struct WAVE_INFO *header, const char *match, uint32_t *size) { + char buffer4[4]; + uint32_t chunk_size; + const uint32_t max_pos = (*header).leChunkSize + 8; // max pos in file + + rewind(ptr); + chunk_size = 12; // skip first 12 bytes + while((ftell(ptr) >= 0) && (ftell(ptr) + chunk_size + 8 < max_pos)) { + // seek to the next chunk + if (fseek(ptr, chunk_size, SEEK_CUR) != 0) { + return CWAVE_FAILURE; + } + // read the chunk description + if (_read_be_field(ptr, buffer4, 4) != CWAVE_SUCCESS) { + return CWAVE_FAILURE; + } + // read the chunk size + if (_read_le_u32_field(ptr, &chunk_size) != CWAVE_SUCCESS) { + return CWAVE_FAILURE; + } + // compare the chunk description with the desired string + if (memcmp(buffer4, match, 4) == 0) { + *size = chunk_size; + return CWAVE_SUCCESS; + } + } + return CWAVE_FAILURE; +} + +// open a WAVE mono file and read header info +// the header is always initialized to zero +FILE *wave_open(const char *path, struct WAVE_INFO *header) { + FILE *ptr; + char buffer4[4]; + struct WAVE_INFO h; + + // initialize header + memset(header, 0, sizeof(*header)); + + // open file + if (path == NULL) { + //printf("Error: path is NULL\n"); + return NULL; + } + ptr = fopen(path, "rb"); + if (ptr == NULL) { + //printf("Error: unable to open input file %s\n", path); + return NULL; + } + + // read first 12 bytes: RIFF header.leChunkSize WAVE + rewind(ptr); + if (_read_be_field(ptr, buffer4, 4) != CWAVE_SUCCESS) { + //printf("Error: cannot read beChunkID\n"); + return NULL; + } + if (memcmp(buffer4, "RIFF", 4) != 0) { + //printf("Error: beChunkID is not RIFF\n"); + return NULL; + } + + if (_read_le_u32_field(ptr, &h.leChunkSize) != CWAVE_SUCCESS) { + //printf("Error: cannot read leChunkSize\n"); + return NULL; + } + + if (_read_be_field(ptr, buffer4, 4) != CWAVE_SUCCESS) { + //printf("Error: cannot read beFormat\n"); + return NULL; + } + if (memcmp(buffer4, "WAVE", 4) != 0) { + //printf("Error: beFormat is not WAVE\n"); + return NULL; + } + + // locate the fmt chunk + if (_seek_to_chunk(ptr, &h, "fmt ", &h.leSubchunkFmtSize) != CWAVE_SUCCESS) { + //printf("Error: cannot locate fmt chunk\n"); + return NULL; + } + if (h.leSubchunkFmtSize < 16) { + //printf("Error: fmt chunk has length < 16\n"); + return NULL; + } + + // read fields + if (_read_le_u16_field(ptr, &h.leAudioFormat) != CWAVE_SUCCESS) { + //printf("Error: cannot read leAudioFormat\n"); + return NULL; + } + // NOTE we fail here because we are only interested in PCM files! + if (h.leAudioFormat != WAVE_FORMAT_PCM) { + //printf("Error: leAudioFormat is not PCM\n"); + return NULL; + } + if (_read_le_u16_field(ptr, &h.leNumChannels) != CWAVE_SUCCESS) { + //printf("Error: cannot read leNumChannels\n"); + return NULL; + } + // NOTE we fail here because we are only interested in mono files! + if (h.leNumChannels != WAVE_CHANNELS_MONO) { + //printf("Error: leNumChannels is not 1\n"); + return NULL; + } + if (_read_le_u32_field(ptr, &h.leSampleRate) != CWAVE_SUCCESS) { + //printf("Error: cannot read leSampleRate\n"); + return NULL; + } + if (_read_le_u32_field(ptr, &h.leByteRate) != CWAVE_SUCCESS) { + //printf("Error: cannot read leByteRate\n"); + return NULL; + } + if (_read_le_u16_field(ptr, &h.leBlockAlign) != CWAVE_SUCCESS) { + //printf("Error: cannot read leBlockAlign\n"); + return NULL; + } + if (_read_le_u16_field(ptr, &h.leBitsPerSample) != CWAVE_SUCCESS) { + //printf("Error: cannot read leBitsPerSample\n"); + return NULL; + } + + // locate the data chunk + if (_seek_to_chunk(ptr, &h, "data", &h.leSubchunkDataSize) != CWAVE_SUCCESS) { + //printf("Error: cannot locate data chunk\n"); + return NULL; + } + if (h.leSubchunkDataSize == 0) { + //printf("Error: data chunk has length zero\n"); + return NULL; + } + // here ptr is at the beginnig of the data info + h.coSubchunkDataStart = (uint32_t)ftell(ptr); + // compute number of samples + h.coNumSamples = (h.leSubchunkDataSize / (h.leNumChannels * h.leBitsPerSample / 8)); + // compute number of bytes/sample (single channel) + h.coBytesPerSample = h.leBitsPerSample / 8; + // max byte position + h.coMaxDataPosition = h.coSubchunkDataStart + h.leSubchunkDataSize; + + // copy h into header and return the pointer to the audio file + *header = h; + return ptr; +} + +// close a WAVE mono file previously open +int wave_close(FILE *ptr) { + int ret; + + ret = fclose(ptr); + ptr = NULL; + return ret; +} + +// read samples from an open WAVE mono file +int wave_read_double( + FILE *ptr, + struct WAVE_INFO *header, + double *dest, + const uint32_t from_sample, + const uint32_t number_samples + ) { + unsigned char *buffer; + uint32_t target_pos; + const uint32_t bytes_per_sample = (*header).coBytesPerSample; + uint32_t i, j, read, remaining; + + if (from_sample + number_samples > (*header).coNumSamples) { + //printf("Error: attempted reading outside data\n"); + return CWAVE_FAILURE; + } + + target_pos = (*header).coSubchunkDataStart + bytes_per_sample * from_sample; + if (ftell(ptr) != target_pos) { + fseek(ptr, target_pos, SEEK_SET); + } + + buffer = (unsigned char *)calloc(CWAVE_BUFFER_SIZE, bytes_per_sample); + remaining = number_samples; + j = 0; + while (remaining > 0) { + if (remaining >= CWAVE_BUFFER_SIZE) { + read = fread(buffer, bytes_per_sample, CWAVE_BUFFER_SIZE, ptr); + } else { + read = fread(buffer, bytes_per_sample, remaining, ptr); + } + for (i = 0; i < read; ++i) { + dest[j++] = _le_to_double(buffer + i * bytes_per_sample, bytes_per_sample); + } + remaining -= read; + } + free((void *)buffer); + buffer = NULL; + + return CWAVE_SUCCESS; +} + + + diff --git a/aeneas/cmfcc/cwave_func.h b/aeneas/cmfcc/cwave_func.h deleted file mode 120000 index 4365b5b6..00000000 --- a/aeneas/cmfcc/cwave_func.h +++ /dev/null @@ -1 +0,0 @@ -../cwave/cwave_func.h \ No newline at end of file diff --git a/aeneas/cmfcc/cwave_func.h b/aeneas/cmfcc/cwave_func.h new file mode 100644 index 00000000..ae429924 --- /dev/null +++ b/aeneas/cmfcc/cwave_func.h @@ -0,0 +1,78 @@ +/* + +Python C Extension for reading WAVE mono files. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#include "cint.h" + +#define CWAVE_SUCCESS 0 +#define CWAVE_FAILURE 1 + +enum { + WAVE_FORMAT_PCM = 0x0001, // PCM + WAVE_FORMAT_IEEE_FLOAT = 0x0003, // IEEE float + WAVE_FORMAT_ALAW = 0x0006, // 8-bit ITU-T G.711 A-law + WAVE_FORMAT_MULAW = 0x0007, // 8-bit ITU-T G.711 mu-law + WAVE_FORMAT_EXTENSIBLE = 0xFFFE, // extensible format + + WAVE_CHANNELS_MONO = 0x0001, // mono + WAVE_CHANNELS_STERO = 0x0002 // stereo +}; + +struct WAVE_INFO { + // be = big endian in file => converted into cpu endianness + // le = little endian in file => converted into cpu endianness + // co = computed, always in cpu endianness + + // first 12 bytes + //uint32_t beChunkID; // string 'RIFF' + uint32_t leChunkSize; // (size of the whole file in bytes - 8) + //uint32_t beFormat; // string 'WAVE' + + // then, we have at least the SubchunkFmt and SubchunkData + // in any order, and other kinds of Subchunk can be present as well + uint32_t leSubchunkFmtSize; // (size of the subchunk 1 in bytes - 4) + uint16_t leAudioFormat; // one of the WAVE_FORMAT_* values + uint16_t leNumChannels; // number of channels (1 = mono, 2 = stereo) + uint32_t leSampleRate; // samples per second (e.g. 48000, 44100, 22050, 16000, 8000) + uint32_t leByteRate; // leSampleRate * leNumChannels * leBitsPerSample/8 => data bytes/s + uint16_t leBlockAlign; // leNumChannels * leBitsPerSample/8 => bytes/sample, including all channels + uint16_t leBitsPerSample; // number of bits per sample (e.g., 8, 16, 32) + uint32_t leSubchunkDataSize; // leNumSamples * leNumChannels * leBitsPerSample/8 => data bytes + + // computed + uint32_t coNumSamples; // number of samples + uint32_t coSubchunkDataStart; // byte at which the data chunk starts + uint32_t coBytesPerSample; // leBitsPerSample / 8 => bytes/sample (single channel) + uint32_t coMaxDataPosition; // coSubchunkDataStart + leSubchunkDataSize => max byte position of data +}; + +// open a WAVE mono file and read header info +FILE *wave_open(const char *path, struct WAVE_INFO *audio_info); + +// close an open WAVE mono file +int wave_close(FILE *audio_file_ptr); + +// read samples from an open WAVE mono file +int wave_read_double( + FILE *audio_file_ptr, + struct WAVE_INFO *audio_info, + double *dest, + const uint32_t from_sample, + const uint32_t number_samples +); + + + diff --git a/aeneas/cwave/cint.c b/aeneas/cwave/cint.c deleted file mode 120000 index 8e1c9dae..00000000 --- a/aeneas/cwave/cint.c +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.c \ No newline at end of file diff --git a/aeneas/cwave/cint.c b/aeneas/cwave/cint.c new file mode 100644 index 00000000..99541bfc --- /dev/null +++ b/aeneas/cwave/cint.c @@ -0,0 +1,111 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#include "cint.h" + +uint8_t le_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint8_t be_u8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +uint16_t le_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +uint16_t be_u16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +uint32_t le_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +uint32_t be_u32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +int8_t le_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int8_t be_s8_to_cpu(const unsigned char *buf) { + return (uint8_t)buf[0]; +} +int16_t le_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[0]) | (((uint16_t)buf[1]) << 8); +} +int16_t be_s16_to_cpu(const unsigned char *buf) { + return ((uint16_t)buf[1]) | (((uint16_t)buf[0]) << 8); +} +int32_t le_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[0]) | (((uint32_t)buf[1]) << 8) | (((uint32_t)buf[2]) << 16) | (((uint32_t)buf[3]) << 24); +} +int32_t be_s32_to_cpu(const unsigned char *buf) { + return ((uint32_t)buf[3]) | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); +} + +void cpu_to_le_u8(unsigned char *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_u8(uint8_t *buf, uint8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_u16(unsigned char *buf, uint16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_u16(uint8_t *buf, uint16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_u32(unsigned char *buf, uint32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_u32(uint8_t *buf, uint32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + +void cpu_to_le_s8(unsigned char *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_be_s8(uint8_t *buf, int8_t val) { + buf[0] = (val & 0xFF); +} +void cpu_to_le_s16(unsigned char *buf, int16_t val) { + buf[0] = (val & 0x00FF); + buf[1] = (val & 0xFF00) >> 8; +} +void cpu_to_be_s16(uint8_t *buf, int16_t val) { + buf[0] = (val & 0xFF00) >> 8; + buf[1] = (val & 0x00FF); +} +void cpu_to_le_s32(unsigned char *buf, int32_t val) { + buf[0] = (val & 0x000000FF); + buf[1] = (val & 0x0000FF00) >> 8; + buf[2] = (val & 0x00FF0000) >> 16; + buf[3] = (val & 0xFF000000) >> 24; +} +void cpu_to_be_s32(uint8_t *buf, int32_t val) { + buf[0] = (val & 0xFF000000) >> 24; + buf[1] = (val & 0x00FF0000) >> 16; + buf[2] = (val & 0x0000FF00) >> 8; + buf[3] = (val & 0x000000FF); +} + diff --git a/aeneas/cwave/cint.h b/aeneas/cwave/cint.h deleted file mode 120000 index 27a6bb39..00000000 --- a/aeneas/cwave/cint.h +++ /dev/null @@ -1 +0,0 @@ -../cint/cint.h \ No newline at end of file diff --git a/aeneas/cwave/cint.h b/aeneas/cwave/cint.h new file mode 100644 index 00000000..a8abed0e --- /dev/null +++ b/aeneas/cwave/cint.h @@ -0,0 +1,58 @@ +/* + +Portable fixed-size int definitions for the other Python C extensions. + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL v3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +*/ + +#ifdef _MSC_VER +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include +#endif + +uint8_t le_u8_to_cpu(const unsigned char *buf); +uint8_t be_u8_to_cpu(const unsigned char *buf); +uint16_t le_u16_to_cpu(const unsigned char *buf); +uint16_t be_u16_to_cpu(const unsigned char *buf); +uint32_t le_u32_to_cpu(const unsigned char *buf); +uint32_t be_u32_to_cpu(const unsigned char *buf); + +int8_t le_s8_to_cpu(const unsigned char *buf); +int8_t be_s8_to_cpu(const unsigned char *buf); +int16_t le_s16_to_cpu(const unsigned char *buf); +int16_t be_s16_to_cpu(const unsigned char *buf); +int32_t le_s32_to_cpu(const unsigned char *buf); +int32_t be_s32_to_cpu(const unsigned char *buf); + +void cpu_to_le_u8(unsigned char *buf, uint8_t val); +void cpu_to_be_u8(unsigned char *buf, uint8_t val); +void cpu_to_le_u16(unsigned char *buf, uint16_t val); +void cpu_to_be_u16(unsigned char *buf, uint16_t val); +void cpu_to_le_u32(unsigned char *buf, uint32_t val); +void cpu_to_be_u32(unsigned char *buf, uint32_t val); + +void cpu_to_le_s8(unsigned char *buf, int8_t val); +void cpu_to_be_s8(unsigned char *buf, int8_t val); +void cpu_to_le_s16(unsigned char *buf, int16_t val); +void cpu_to_be_s16(unsigned char *buf, int16_t val); +void cpu_to_le_s32(unsigned char *buf, int32_t val); +void cpu_to_be_s32(unsigned char *buf, int32_t val); + diff --git a/aeneas/nuancettsapiwrapper.py b/aeneas/nuancettsapiwrapper.py index bc86f473..a2d74776 100644 --- a/aeneas/nuancettsapiwrapper.py +++ b/aeneas/nuancettsapiwrapper.py @@ -53,7 +53,7 @@ class NuanceTTSAPIWrapper(TTSWrapper): To use this TTS engine, specify :: - "tts=nuance|nuance_tts_api_id=...|nuance_tts_api_key=..." + "tts=nuancettsapi|nuance_tts_api_id=...|nuance_tts_api_key=..." in the ``rconf`` object, substituting your Nuance Developer API ID and Key. diff --git a/check_dependencies.py b/check_dependencies.py deleted file mode 120000 index 8a4e2015..00000000 --- a/check_dependencies.py +++ /dev/null @@ -1 +0,0 @@ -aeneas_check_setup.py \ No newline at end of file diff --git a/check_dependencies.py b/check_dependencies.py new file mode 100644 index 00000000..613be41c --- /dev/null +++ b/check_dependencies.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# coding=utf-8 + +""" +Check whether the setup of aeneas was successful. + +Running this script makes sense only +if you git-cloned the original GitHub repository +and/or if you are interested in contributing to the +development of aeneas. +""" + +from __future__ import absolute_import +from __future__ import print_function +import os +import sys + +__author__ = "Alberto Pettarin" +__copyright__ = """ + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) + Copyright 2015-2016, Alberto Pettarin (www.albertopettarin.it) + """ +__license__ = "GNU AGPL 3" +__version__ = "1.5.0" +__email__ = "aeneas@readbeyond.it" +__status__ = "Production" + +ANSI_ERROR = u"\033[91m" +ANSI_OK = u"\033[92m" +ANSI_WARNING = u"\033[93m" +ANSI_END = u"\033[0m" + +def is_posix(): + return os.name == "posix" + +def print_error(msg): + if is_posix(): + print(u"%s[ERRO] %s%s" % (ANSI_ERROR, msg, ANSI_END)) + else: + print(u"[ERRO] %s" % (msg)) + +def print_info(msg): + print(u"[INFO] %s" % (msg)) + +def print_success(msg): + if is_posix(): + print(u"%s[INFO] %s%s" % (ANSI_OK, msg, ANSI_END)) + else: + print(u"[INFO] %s" % (msg)) + +def print_warning(msg): + if is_posix(): + print(u"%s[WARN] %s%s" % (ANSI_WARNING, msg, ANSI_END)) + else: + print(u"[WARN] %s" % (msg)) + +def check_import(): + try: + import aeneas + print_success(u"aeneas OK") + return False + except ImportError: + print_error(u"aeneas ERROR") + print_info(u" Unable to load the aeneas Python package") + print_info(u" This error is probably caused by:") + print_info(u" A. you did not download/git-clone the aeneas package properly; or") + print_info(u" B. you did not install the required Python packages:") + print_info(u" 1. BeautifulSoup4") + print_info(u" 2. lxml") + print_info(u" 3. numpy") + except Exception as e: + print_error(e) + return True + +def main(): + # first, check we can import aeneas module + if check_import(): + sys.exit(1) + + # then, run the built-in diagnostics + from aeneas.diagnostics import Diagnostics + errors, warnings, c_ext_warnings = Diagnostics.check_all() + if errors: + sys.exit(1) + if c_ext_warnings: + print_warning(u"All required dependencies are met but at least one available Python C extension is not compiled") + print_warning(u"You can still run aeneas but it will be slower") + print_warning(u"Enjoy running aeneas!") + sys.exit(2) + else: + print_success(u"All required dependencies are met and all available Python C extensions are compiled") + print_success(u"Enjoy running aeneas!") + sys.exit(0) + + + +if __name__ == '__main__': + main() + + + diff --git a/setup.py b/setup.py index 4c8a7505..1cb97122 100644 --- a/setup.py +++ b/setup.py @@ -86,7 +86,7 @@ "aeneas.extra": ["*.md"], "aeneas.tools": ["res/*", "*.md"] }, - version="1.5.0.0", + version="1.5.0.1", description=SHORT_DESCRIPTION, author="Alberto Pettarin", author_email="alberto@albertopettarin.it", @@ -129,9 +129,11 @@ "Mel-frequency cepstral coefficients", "ReadBeyond Sync", "ReadBeyond", + "SBV", "SMIL", "SRT", "SSV", + "SUB", "TSV", "TTML", "VTT",