Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to work with ESP IDF, without Arduino.h #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
build/
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
sdkconfig
.vscode/
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello_world)
15 changes: 15 additions & 0 deletions components/ESPIDF-SAM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(PROJECT_SOURCE_DIR src)

set(include_dirs
${PROJECT_SOURCE_DIR}
)

file(GLOB SOURCE_FILES
"${PROJECT_SOURCE_DIR}/*.c"
"${PROJECT_SOURCE_DIR}/*.cpp"
)

idf_component_register(SRCS "${SOURCE_FILES}"
INCLUDE_DIRS "${include_dirs}")

component_compile_options(-Wno-error=format= -Wno-format)
7 changes: 7 additions & 0 deletions components/ESPIDF-SAM/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := .

# If your component requires any specific libraries, you can add them here
# COMPONENT_REQUIRES :=

include $(IDF_PATH)/make/component.mk
28 changes: 15 additions & 13 deletions src/ESP8266SAM.cpp → components/ESPIDF-SAM/src/ESP8266SAM.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
ESP8266SAM
Port of SAM to the ESP8266

Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -15,14 +15,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>

#include <Arduino.h>
#include <ESP8266SAM.h>

#include "reciter.h"
#include "sam.h"
#include "SamData.h"

#ifndef ESP8266
static void yield() { /* NOOP */ }
#endif

SamData* samdata;

// Thunk from C to C++ with a this-> pointer
Expand All @@ -35,14 +42,16 @@ void ESP8266SAM::OutputByteCallback(void *cbdata, unsigned char b)
void ESP8266SAM::OutputByte(unsigned char b)
{
// Xvert unsigned 8 to signed 16...
int16_t s16 = b;// s16 -= 128; //s16 *= 128;
int16_t s16 = b;
s16 -= 128;
s16 *= 128;
int16_t sample[2];
sample[0] = s16;
sample[1] = s16;
while (!output->ConsumeSample(sample)) yield();
while (!output_cb((void*)(0), sample)) yield();
}
bool ESP8266SAM::Say(AudioOutput *out, const char *str)

bool ESP8266SAM::Say(const char *str)
{
if (!str || strlen(str)>254) return false; // Only can speak up to 1 page worth of data...
samdata = new SamData;
Expand All @@ -51,12 +60,6 @@ bool ESP8266SAM::Say(AudioOutput *out, const char *str)
// allocation failed!
return false;
}

// These are fixed by the synthesis routines
out->SetRate(22050);
out->SetBitsPerSample(8);
out->SetChannels(1);
out->begin();

// SAM settings
EnableSingmode(singmode);
Expand All @@ -80,7 +83,6 @@ bool ESP8266SAM::Say(AudioOutput *out, const char *str)
}

// Say it!
output = out;
SetInput(input);
SAMMain(OutputByteCallback, (void*)this);
delete samdata;
Expand Down
20 changes: 5 additions & 15 deletions src/ESP8266SAM.h → components/ESPIDF-SAM/src/ESP8266SAM.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
ESP8266SAM
Port of SAM to the ESP8266

Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -18,23 +18,19 @@
#ifndef _ESP8266SAM_H
#define _ESP8266SAM_H

#include <Arduino.h>
#include <AudioOutput.h>

class ESP8266SAM {

public:
ESP8266SAM()
ESP8266SAM(bool output_cb(void *cbdata, int16_t* b)) : output_cb(output_cb)
{
singmode = false;
phonetic = false;
pitch = 0;
mouth = 0;
throat = 0;
speed = 0;
output = NULL;
};

~ESP8266SAM()
{
}
Expand All @@ -49,13 +45,8 @@ class ESP8266SAM {
void SetThroat(uint8_t val) { throat = val; }
void SetSpeed(uint8_t val) { speed = val; }

bool Say(AudioOutput *out, const char *str);
bool Say_P(AudioOutput *out, const char *str) {
char ram[256];
strncpy_P(ram, str, 256);
ram[255] = 0;
return Say(out, ram);
};
bool Say(const char *str);
bool(*output_cb)(void *cbdata, int16_t* b);

private:
static void OutputByteCallback(void *cbdata, unsigned char b);
Expand All @@ -66,7 +57,6 @@ class ESP8266SAM {
int speed;
int mouth;
int throat;
AudioOutput *output;
};

#endif
Expand Down
12 changes: 6 additions & 6 deletions src/ReciterTabs.h → components/ESPIDF-SAM/src/ReciterTabs.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef RECITERTABS_H
#define RECITERTABS_H

#include <pgmspace.h>
// #include <pgmspace.h>
#include "esp8266sam_debug.h"
#if DEBUG_ESP8266SAM_LIB
#define PROGMEM
#endif

//some flags
const unsigned char tab36376[] PROGMEM =
const unsigned char tab36376[] =
{
0, 0, 0, 0, 0, 0, 0, 0, // 0-7
0, 0, 0, 0, 0, 0, 0, 0, // 8-15
Expand All @@ -26,7 +26,7 @@ const unsigned char tab36376[] PROGMEM =
163, 76, 138, 142
};

const char rules[] PROGMEM =
const char rules[] =
{
']','A'|0x80,
' ','(','A','.',')', '=','E','H','4','Y','.',' '|0x80,
Expand Down Expand Up @@ -484,7 +484,7 @@ const char rules[] PROGMEM =
'j'|0x80
};

const char rules2[] PROGMEM =
const char rules2[] =
{
'(','A',')', '='|0x80,
'(','!',')', '=','.'|0x80,
Expand Down Expand Up @@ -533,15 +533,15 @@ const char rules2[] PROGMEM =

//26 items. From 'A' to 'Z'
// positions for mem62 and mem63 for each character
const unsigned char tab37489[] PROGMEM =
const unsigned char tab37489[] =
{
0, 149, 247, 162, 57, 197, 6, 126,
199, 38, 55, 78, 145, 241, 85, 161,
254, 36, 69, 45, 167, 54, 83, 46,
71, 218
};

const unsigned char tab37515[] PROGMEM =
const unsigned char tab37515[] =
{
125, 126, 126, 127, 128, 129, 130, 130,
130, 132, 132, 132, 132, 132, 133, 135,
Expand Down
27 changes: 13 additions & 14 deletions src/RenderTabs.h → components/ESPIDF-SAM/src/RenderTabs.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
#ifndef RENDERTABS_H
#define RENDERTABS_H

#include <pgmspace.h>
#include "esp8266sam_debug.h"
#if DEBUG_ESP8266SAM_LIB
#define PROGMEM
#endif

const unsigned char tab48426[5] PROGMEM = { 0x18, 0x1A, 0x17, 0x17, 0x17 };
const unsigned char tab48426[5] = { 0x18, 0x1A, 0x17, 0x17, 0x17 };

const unsigned char tab47492[] PROGMEM =
const unsigned char tab47492[] =
{
0 , 0 , 0xE0 , 0xE6 , 0xEC , 0xF3 , 0xF9 , 0 ,
6 , 0xC , 6
};


const unsigned char amplitudeRescale[] PROGMEM =
const unsigned char amplitudeRescale[] =
{
0 , 1 , 2 , 2 , 2 , 3 , 3 , 4 ,
4 , 5 , 6 , 8 , 9 ,0xB ,0xD ,0xF, 0 //17 elements?
};

// Used to decide which phoneme's blend lengths. The candidate with the lower score is selected.
// tab45856
const unsigned char blendRank[] PROGMEM =
const unsigned char blendRank[] =
{
0 , 0x1F , 0x1F , 0x1F , 0x1F , 2 , 2 , 2 ,
2 , 2 , 2 , 2 , 2 , 2 , 5 , 5 ,
Expand All @@ -41,7 +40,7 @@ const unsigned char blendRank[] PROGMEM =

// Number of frames at the end of a phoneme devoted to interpolating to next phoneme's final value
//tab45696
const unsigned char outBlendLength[] PROGMEM =
const unsigned char outBlendLength[] =
{
0 , 2 , 2 , 2 , 2 , 4 , 4 , 4 ,
4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 ,
Expand All @@ -58,7 +57,7 @@ const unsigned char outBlendLength[] PROGMEM =

// Number of frames at beginning of a phoneme devoted to interpolating to phoneme's final value
// tab45776
const unsigned char inBlendLength[] PROGMEM =
const unsigned char inBlendLength[] =
{
0 , 2 , 2 , 2 , 2 , 4 , 4 , 4 ,
4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 ,
Expand Down Expand Up @@ -91,7 +90,7 @@ const unsigned char inBlendLength[] PROGMEM =
// 67: ** 27 00011011
// 70: ** 25 00011001
// tab45936
const unsigned char sampledConsonantFlags[] PROGMEM =
const unsigned char sampledConsonantFlags[] =
{
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
Expand Down Expand Up @@ -151,7 +150,7 @@ unsigned char freq3data[]=
0x65 , 0x65 , 0x70 , 0x5E , 0x5E , 0x5E , 0x08 , 0x01
};

const unsigned char ampl1data[] PROGMEM =
const unsigned char ampl1data[] =
{
0 , 0 , 0 , 0 , 0 ,0xD ,0xD ,0xE ,
0xF ,0xF ,0xF ,0xF ,0xF ,0xC ,0xD ,0xC ,
Expand All @@ -165,7 +164,7 @@ const unsigned char ampl1data[] PROGMEM =
0 ,0xC , 0 , 0 , 0 , 0 ,0xF ,0xF
};

const unsigned char ampl2data[] PROGMEM =
const unsigned char ampl2data[] =
{
0 , 0 , 0 , 0 , 0 ,0xA ,0xB ,0xD ,
0xE ,0xD ,0xC ,0xC ,0xB , 9 ,0xB ,0xB ,
Expand All @@ -179,7 +178,7 @@ const unsigned char ampl2data[] PROGMEM =
0 ,0xA , 0 , 0 ,0xA , 0 , 0 , 0
};

const unsigned char ampl3data[] PROGMEM =
const unsigned char ampl3data[] =
{
0 , 0 , 0 , 0 , 0 , 8 , 7 , 8 ,
8 , 1 , 1 , 0 , 1 , 0 , 7 , 5 ,
Expand All @@ -196,10 +195,10 @@ const unsigned char ampl3data[] PROGMEM =


//tab42240
const signed char sinus[256] PROGMEM = {0,3,6,9,12,16,19,22,25,28,31,34,37,40,43,46,49,51,54,57,60,63,65,68,71,73,76,78,81,83,85,88,90,92,94,96,98,100,102,104,106,107,109,111,112,113,115,116,117,118,120,121,122,122,123,124,125,125,126,126,126,127,127,127,127,127,127,127,126,126,126,125,125,124,123,122,122,121,120,118,117,116,115,113,112,111,109,107,106,104,102,100,98,96,94,92,90,88,85,83,81,78,76,73,71,68,65,63,60,57,54,51,49,46,43,40,37,34,31,28,25,22,19,16,12,9,6,3,0,-3,-6,-9,-12,-16,-19,-22,-25,-28,-31,-34,-37,-40,-43,-46,-49,-51,-54,-57,-60,-63,-65,-68,-71,-73,-76,-78,-81,-83,-85,-88,-90,-92,-94,-96,-98,-100,-102,-104,-106,-107,-109,-111,-112,-113,-115,-116,-117,-118,-120,-121,-122,-122,-123,-124,-125,-125,-126,-126,-126,-127,-127,-127,-127,-127,-127,-127,-126,-126,-126,-125,-125,-124,-123,-122,-122,-121,-120,-118,-117,-116,-115,-113,-112,-111,-109,-107,-106,-104,-102,-100,-98,-96,-94,-92,-90,-88,-85,-83,-81,-78,-76,-73,-71,-68,-65,-63,-60,-57,-54,-51,-49,-46,-43,-40,-37,-34,-31,-28,-25,-22,-19,-16,-12,-9,-6,-3};
const signed char sinus[256] = {0,3,6,9,12,16,19,22,25,28,31,34,37,40,43,46,49,51,54,57,60,63,65,68,71,73,76,78,81,83,85,88,90,92,94,96,98,100,102,104,106,107,109,111,112,113,115,116,117,118,120,121,122,122,123,124,125,125,126,126,126,127,127,127,127,127,127,127,126,126,126,125,125,124,123,122,122,121,120,118,117,116,115,113,112,111,109,107,106,104,102,100,98,96,94,92,90,88,85,83,81,78,76,73,71,68,65,63,60,57,54,51,49,46,43,40,37,34,31,28,25,22,19,16,12,9,6,3,0,-3,-6,-9,-12,-16,-19,-22,-25,-28,-31,-34,-37,-40,-43,-46,-49,-51,-54,-57,-60,-63,-65,-68,-71,-73,-76,-78,-81,-83,-85,-88,-90,-92,-94,-96,-98,-100,-102,-104,-106,-107,-109,-111,-112,-113,-115,-116,-117,-118,-120,-121,-122,-122,-123,-124,-125,-125,-126,-126,-126,-127,-127,-127,-127,-127,-127,-127,-126,-126,-126,-125,-125,-124,-123,-122,-122,-121,-120,-118,-117,-116,-115,-113,-112,-111,-109,-107,-106,-104,-102,-100,-98,-96,-94,-92,-90,-88,-85,-83,-81,-78,-76,-73,-71,-68,-65,-63,-60,-57,-54,-51,-49,-46,-43,-40,-37,-34,-31,-28,-25,-22,-19,-16,-12,-9,-6,-3};

//tab42496
const unsigned char rectangle[] PROGMEM =
const unsigned char rectangle[] =
{
0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 ,
0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 ,
Expand Down Expand Up @@ -238,7 +237,7 @@ const unsigned char rectangle[] PROGMEM =


//random data ?
const unsigned char sampleTable[0x500] PROGMEM =
const unsigned char sampleTable[0x500] =
{
//00

Expand Down
File renamed without changes.
Loading