Skip to content

Commit 5020247

Browse files
committed
Version 1.0.1
1 parent d02933c commit 5020247

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

Diff for: README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
The original version can be found [here](https://github.com/going-digital/Talkie)
88
A good explanation of the TMS5220 operation and the LPC frame format can be found [here](https://github.com/mamedev/mame/blob/master/src/devices/sound/tms5220.txt)
99

10-
Youtube Demonstration of Talkie Voltmeter example
10+
YouTube Demonstration of Talkie Voltmeter example
1111

1212
[![Demonstration of Talkie Voltmeter example](https://img.youtube.com/vi/6jXkugZTwCs/0.jpg)](https://www.youtube.com/watch?v=6jXkugZTwCs)
1313

@@ -25,25 +25,26 @@ Youtube Demonstration of Talkie Voltmeter example
2525
- **ARM0** (but not tested) as found on the **SAMD**, **Teensy** and **Particle** boards.
2626

2727
## Hints
28-
- Connect the speaker to digital pin 3 and 11 of Arduino. They are enabled as non inverted and inverted outputs by default to increase volume for direct attached piezo or speaker.
29-
- As speaker I use the speakers from old earphones or headphones, which have ca. 32 Ohm, directly without a series resistor. The headphone speaker tend to be much louder, especially when they stay in their original housings.
30-
- The Library uses Timer 1 and Timer 2, so libraries like Tone, Servo, analogWrite(), and some other libraries cannot be used while speaking.
28+
- **Connect the speaker between digital pin 3 and 11 of Arduino**. They are enabled as non inverted and inverted outputs by default to **increase volume** for direct attached piezo or speaker.
29+
- I use the speakers from old earphones or headphones, which have approximately 32 Ohm, directly without a series resistor. The headphone speaker tend to be much louder, especially when they stay in their original housings.
30+
- The library uses Timer 1 and Timer 2, so libraries like Tone, Servo, analogWrite(), and some other libraries cannot be used while speaking.
3131
- After a call to say... you can use tone() again.
3232
- To use Servo write() after a call to say... you must detach() and attach() the servo before first write() in order to initialize the timer again for Servo.
33+
- If you want to use SPI functions **while Talkie is speaking**, then disable Talkies usage of pin 11 by `Talkie Voice(true, false);` instead of `Talkie Voice;` **or** `Voice.doNotUseUseInvertedOutput();`.
3334
- Porting to ATtinys is not possible, since they lack the hardware multiplication. ( Believe me, I tried it! )
3435

3536
## Own vocabulary
3637
To create LPC data you can use [Qboxpro](http://ftp.whtech.com/pc%20utilities/qboxpro.zip), an unsupported old Windows application running under XP, which can produce Talkie compatible data streams. The missing BWCC.DLL (Borland Windows Custom Control Library) can be found e.g. [here](http://www.download-dll.com/dll-BWCC.dll.html).
3738
The process is described [here](http://furrtek.free.fr/index.php?a=speakandspell&ss=9&i=2) and goes like this:
38-
- Create a new project using the following project parameters : Byte / 8 Khz / 5220 coding table
39+
- Create a new project using the following project parameters : Byte / 8 KHz / 5220 coding table
3940
- Goto Project and add the audio file
4041
- Choose process using : medium bit rate and pressing OK
41-
- Edit concatenation : insert concatenation after by adding a name; then insert phrase and press ok
42+
- Edit concatenation : insert concatenation after by adding a name; then insert phrase and press OK
4243
- Format it by choosing the first line in the format menu : LPC 10V, 4UV
4344

44-
Another way to generate the LPC data is to use the pyton script at https://github.com/ptwz/python_wizard
45+
Another way to generate the LPC data is to use the python script at https://github.com/ptwz/python_wizard
4546

46-
### Schematic for voltmeter example
47+
## Schematic for voltmeter example
4748
![Fritzing schematic for voltmeter example](https://github.com/ArminJo/Talkie/blob/master/extras/TalkieVoltmeter_Steckplatine.png)
4849

4950
# Modifying library properties
@@ -53,10 +54,13 @@ The library files itself are located in the `src` sub-directory.<br/>
5354
If you did not yet store the example as your own sketch, then with Ctrl+K you are instantly in the right library folder.
5455

5556
# Revision History
57+
### Version 1.0.1
58+
- Added SPI compatibility by not resetting pin 11 to input if SPI is detected
59+
- Added new constructor Talkie(bool aUseNonInvertedOutputPin, bool aUseInvertedOutputPin);
5660
### Version 1.0.0
57-
Initial Arduino library version
61+
- Initial Arduino library version
5862

59-
## Travis CI
63+
# Travis CI
6064
The Talkie library examples are built on Travis CI for the following boards:
6165

6266
- Arduino Uno

Diff for: src/Talkie.cpp

+26-21
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@
6060
#define TIMING_PIN 12
6161
#endif
6262

63-
// If you do not use the Tone library, then activating can save up to 844 byte program size :-)
63+
// If you do not use the Tone library, then activating can save up to 844 bytes program size :-)
6464
//#define NO_COMPATIBILITY_FOR_TONE_LIB_NEEDED
6565

66-
// If you do not use a SPI library, then activating can save 8 byte program size
67-
//#define NO_COMPATIBILITY_FOR_SPI_NEEDED
68-
6966
/*
7067
* Use 8bit coefficients K1 and K2.
7168
* Saves 10 microseconds (40 instead of 50 us) for a 16 MHz ATmega
@@ -121,6 +118,19 @@ Talkie::Talkie() { // @suppress("Class members should be properly initialized")
121118
*/
122119
NonInvertedOutputPin = TALKIE_USE_PIN_FLAG;
123120
InvertedOutputPin = TALKIE_USE_PIN_FLAG;
121+
122+
isTalkingFlag = false;
123+
sPointerToTalkieForISR = this;
124+
}
125+
126+
Talkie::Talkie(bool aUseNonInvertedOutputPin, bool aUseInvertedOutputPin) { // @suppress("Class members should be properly initialized")
127+
if (aUseNonInvertedOutputPin) {
128+
NonInvertedOutputPin = TALKIE_USE_PIN_FLAG;
129+
}
130+
if (aUseInvertedOutputPin) {
131+
InvertedOutputPin = TALKIE_USE_PIN_FLAG;
132+
}
133+
124134
isTalkingFlag = false;
125135
sPointerToTalkieForISR = this;
126136
}
@@ -198,7 +208,7 @@ void Talkie::FIFOPushBack(const uint8_t *aAddress) {
198208
* returns next element from queue or 0
199209
*/
200210
const uint8_t * Talkie::FIFOPopFront() {
201-
// 56 byte compiled
211+
// 56 bytes compiled
202212
const uint8_t *addr = 0; // returns 0 if empty.
203213
if (free < FIFO_BUFFER_SIZE) {
204214
free++;
@@ -257,7 +267,7 @@ void Talkie::resetFIFO() {
257267
}
258268

259269
/*
260-
* On Arduino enables pin 11 as inverted PWM output to increase the volume
270+
* On Arduino disables/enables pin 11 as inverted PWM output ( in order to increase the volume, if speaker is attached between 3 and 11)
261271
*/
262272
void Talkie::doNotUseUseInvertedOutput(bool aDoNotUseInvertedOutput) {
263273
if (aDoNotUseInvertedOutput) {
@@ -268,11 +278,11 @@ void Talkie::doNotUseUseInvertedOutput(bool aDoNotUseInvertedOutput) {
268278
}
269279

270280
/*
271-
* On Arduino disables pin 3 (Talkie default) as PWM output
281+
* On Arduino disables/enables pin 3 (Talkie default) as PWM output
272282
*/
273283
void Talkie::doNotUseNonInvertedOutput(bool aDoNotUseNonInvertedOutput) {
274284
if (aDoNotUseNonInvertedOutput) {
275-
NonInvertedOutputPin = 0;
285+
NonInvertedOutputPin = TALKIE_DO_NOT_USE_PIN_FLAG;
276286
} else {
277287
NonInvertedOutputPin = TALKIE_USE_PIN_FLAG;
278288
}
@@ -285,7 +295,7 @@ void Talkie::initializeHardware() {
285295
#if defined(__AVR_ATmega32U4__) // Use Timer 4 instead of Timer 2
286296
#if defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_PROMICRO)
287297
// Adafruit Circuit Playground Classic or Sparkfun Pro Micro board. The first does not need inverted output, the latter does not connect it.
288-
// Cannot be used on plain Leonardos since inverted output is connected to internal led.
298+
// Cannot be used on plain Leonardos because inverted output is connected to internal led.
289299
NonInvertedOutputPin = 5;// D5 / PC6 / !OC4A
290300
InvertedOutputPin = 0;// disable InvertedOutputPin
291301
pinMode(NonInvertedOutputPin, OUTPUT);
@@ -428,24 +438,19 @@ void Talkie::terminateHardware() {
428438
* pinMode(3|11, INPUT) avoids the click at the end, if speaker is coupled by a capacitance.
429439
*/
430440
if (NonInvertedOutputPin) {
431-
432-
#ifndef NO_COMPATIBILITY_FOR_SPI_NEEDED
433-
// Reset pin 11 to input only if no active SPI detected - needs 8 byte Flash
434-
if (!(SPCR & _BV(SPE))) {
435-
#endif
436-
// force initializing of tone library, next time tone() is called.
441+
// Reset pin 11 to input only if no active SPI detected
442+
if (!(SPCR & _BV(SPE))) {
437443
#ifdef NO_COMPATIBILITY_FOR_TONE_LIB_NEEDED
438-
pinMode(NonInvertedOutputPin, INPUT); // tone needs this as output
444+
pinMode(NonInvertedOutputPin, INPUT); // As tone needs this as output, disconnect only if no compatibility needed
439445
#else
446+
// force initializing of tone library, next time tone() is called.
440447
noTone(NonInvertedOutputPin);
441448
#endif
442-
#ifndef NO_COMPATIBILITY_FOR_SPI_NEEDED
443449
}
444-
#endif
445450
}
446451
if (InvertedOutputPin) {
447452
#ifdef NO_COMPATIBILITY_FOR_TONE_LIB_NEEDED
448-
pinMode(InvertedOutputPin, INPUT); // tone needs this as output
453+
pinMode(InvertedOutputPin, INPUT); // As tone needs this as output, disconnect only if no compatibility needed
449454
#else
450455
noTone(InvertedOutputPin);
451456
#endif
@@ -468,7 +473,7 @@ int8_t Talkie::sayQ(const uint8_t * aWordDataAddress) {
468473
stop();
469474
} else {
470475
noInterrupts();
471-
// disable Interrupt since ptrAddr is also modified by ISR. This avoids race conditions.
476+
// disable Interrupt because ptrAddr is also modified by ISR. This avoids race conditions.
472477
if (isTalkingFlag) {
473478
/*
474479
* Word synthesizer still active -> queue this aWordDataAddress when there is room in FIFO
@@ -560,7 +565,7 @@ void timerInterrupt() {
560565
}
561566

562567
// Lattice filter forward path -> fill temporary variables
563-
// rescale by shifting >> 7 since we have signed values here (for unsigned it would need >> 8)
568+
// rescale by shifting >> 7 because we have signed values here (for unsigned it would need >> 8)
564569
u9 = u10 - (((int16_t) synthK10 * x9) >> 7);
565570
u8 = u9 - (((int16_t) synthK9 * x8) >> 7);
566571
u7 = u8 - (((int16_t) synthK8 * x7) >> 7);

Diff for: src/Talkie.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
#define FIFO_BUFFER_SIZE 24 // 24 sets of 4 bytes plus added queue indexes is about 100 added bytes.
4545

4646
#define TALKIE_USE_PIN_FLAG 0xFF // Flag to signal, that pin should be used as output, but pin number is not yet filled in, since it depends of board type.
47+
#define TALKIE_DO_NOT_USE_PIN_FLAG 0x00 // As pin number is initially != 0xFF, this is not really needed at startup
4748

4849
class Talkie {
4950
public:
5051
Talkie();
52+
Talkie(bool aUseNonInvertedOutputPin, bool aUseInvertedOutputPin);
5153
void say(const uint8_t * aWordDataAddress); // Blocking version
5254
int8_t sayQ(const uint8_t * aWordDataAddress); // Queuing version. Returns free space in FIFO
5355
void wait(); // wait for sayQ to end

0 commit comments

Comments
 (0)