Teensy 3.1 Voice Encryption

Status
Not open for further replies.

experion

Member
I am looking to have Teensy 3.1 encrypt microphone/voice input, using a simple algorithm:
teensyAudio - New Page.jpg
incoming = voiceData;

while(incomingAudio) {

r = incomingAudio % 10;

reverse = reverse* 10 + r; // used to reverse the encryption;

incomingAudio=incomingAudio/10;

}
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=200,69
AudioOutputI2S           i2s2;           //xy=365,94
AudioConnection          patchCord1(i2s1, 0, i2s2, 0);
AudioConnection          patchCord2(i2s1, 1, i2s2, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=302,184
// GUItool: end automatically generated code


const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;


void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);

  // Enable the audio shield, select input, and enable output
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(myInput);
  sgtl5000_1.volume(0.5);
}

elapsedMillis volmsec=0;

void loop() {
  // every 50 ms, adjust the volume
  if (volmsec > 50) {
    float vol = analogRead(15);
    vol = vol / 1023.0;
    //audioShield.volume(vol); // <-- uncomment if you have the optional
    volmsec = 0;               //     volume pot on your audio shield
  }
}

This code work well with the Teensy Audio shield.

I am relatively new to Teensy, so do not know how to access and manipulate the microphone/voice data. The data may come from using audio shield's LineIn (AUDIO_INPUT_LINEIN) when using stereo mode. This stereo mode allow for 2 channels and I have bee able to test it, using one for audio input from external source and the other for microphone.

Both sounds came through to my headphone, 1 for each ear.

So my problem is 3 fold, sorry for the complexity :(

1) Accessing and modifying the input voice/microphone data, so I can add encryption.
2) Routing the modified data to Teensy 3.1 DAC/A14 so it can be sent to external speaker
3)How to have 2 audio inputs and output them using 2 pins (like DAC/A14, Pin3, etc) as the image above indicates.

For me the preferred option is not to use the Teensy Audio shield as audio quality is not top priority. Which leads to the question of using 2 audio inputs.
I have gathered that it may be possible by using the ADC library. If so, I would greatly appreciate any example codes or pointers on how to do this.
 
I don't see how your encryption can possibly work.
If, for example, the incoming audio is from a 10-bit ADC, this statement:
Code:
r = incomingAudio % 10;
reduces a value in the range 0-1023 to one in the range 0-9. How are you going to get from 0-9 back to 0-1023?

Pete
 
I don't see how your encryption can possibly work.
If, for example, the incoming audio is from a 10-bit ADC, this statement:
Code:
r = incomingAudio % 10;
reduces a value in the range 0-1023 to one in the range 0-9. How are you going to get from 0-9 back to 0-1023?

Pete

The line of code: r = incomingAudio % 10;, give the remainder of the calculation of incomingAudio/10.

to obtain the original value, the reverse is done: reverse = reverse* 10 + r;
 
There are 2 approaches to make this work with the audio library.

#1: You can create your own audio library object. You can add it into the audio library, or just create your own library. It's easy to make objects that work with the audio lib. Details are here:

http://www.pjrc.com/teensy/td_libs_AudioNewObjects.html

In a nutshell, you'll probably copy and rename one of the existing objects. Pick one with both an input and an output, so you're starting with basically all the right code.

Then just rewrite the update() function, which is the code that actually does your audio processing work. You'll probably use receiveWritable() to get the incoming data. Then just do your encryption on the 128 samples, and use transmit() to send it.

The magic of the audio library is those simple receive and transmit function cause your object to communicate with whatever other objects are connected. You could even add lines in list.html to put your object into the GUI (if accessing it on your hard drive, use Firefox). If you need to encrypt multiple streams, you can just make 2 or more copies of your object and connect them to whatever sources and destinations you want.


#2: The other way is essentially the same, except you can use the two queue objects to receive and transmit the 128 sample blocks. This can be done entirely within your sketch, without creating any C++ object code. See File > Examples > Audio > Recorder for an example of how to use the queue to get access to the 128 sample buffers.
 
Thanks, greatly appreciate your pointers. Both approaches sound quite attractive. Will explore both options. Shall report back how it turns out.

May figure this out soon, however I have gone through the audio library output_dac,output_pwm files, still have not figured out where it designated the A14 pin for the DAC output.

what am I missing?
 
This: http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog

Just drag the "dac" object from the "output" section onto the canvas. Drag something else that creates a signal, and connect them!

Hi
Thanks for the reply.
I tried that out and got a code similar to the File > Examples > Audio >HardwareTesting>PassThroughMono file :

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// GUItool: begin automatically generated code
AudioInputAnalog adc1;
AudioInputAnalog adc2;
//xy=161,80
AudioOutputAnalog dac1; //xy=329,47
AudioOutputPWM pwm1; //xy=331,125
AudioConnection patchCord1(adc1, dac1);
AudioConnection patchCord2(adc1, pwm1);
// GUItool: end automatically generated code


The dac1 variable is routed to pin A14/DAC from the AudioConnection class, while pwm1 is routed to digital pin 3.
Both use adc1 variable as an input source. When I try to use a different input source for, say adc2 to be routed to pwm, it does not work.

I read somewhere that it may have something to do with ADC issue. They said something about the ADC library.

So have 2 questions:
1) Is there a way to get the AudioConnection to work with 2 different input source, like adc1 and adc2
2) Do you know how to used the ADC library ADC_1 to stream audio using pwm?
 
You can only use one AudioInputAnalog object.

The web design tool should not allow you to put more than one of these into the design. The fact that it does is a known limitation that's going to someday get fixed.

https://github.com/PaulStoffregen/Audio/issues/58

Today, there's no code to support more than one ADC input. That too is on the list of issues to improve in future versions.

https://github.com/PaulStoffregen/Audio/issues/94

Today, if you want more than 1 input, the audio board is the only way. It gives you stereo input. It can also work together with the ADC input, for a total of 3 possible inputs.
 
I agree. Hope the issue is sorted.

About 'It can also work together with the ADC input, for a total of 3 possible inputs';
Do you know how to use the ADC library accept audio signal using one of the ADC_1 pin and output it to pwm pin 3?
 
Paul: Above I think saw most of an answer to a question about analog input I have - to confirm: the audio board allows stereo input use of the audio library. Without that board you can use the full library - but only on a single analog input?

For my use I have a Sparkfun ADMP401 mic board and want to listen for a couple sounds - maybe FFT them into frequency pools for quick discrimination?: Loud noise, buzzer tone, talking. I'm still amazed seeing this 'Teensy Forest' and will be focusing more on finding the "trees" in coming days - starting today when some of OneHorse's [9dof/LiPo/nRF24] boards get delivered so I get a mounting plan - so I can start the tutorials.
 
Do you know how to use the ADC library accept audio signal using one of the ADC_1 pin

So far, no code has been written to use ADC1. That's why this issue is still open.

If anyone contributes this, I'll be happy to merge it. If not, eventually I'll do it. But right now I'm working on Teensy-LC, so the only work I'm doing on the audio library is answering questions, fixing small bugs, and creating issues on github for bigger issues... so they won't be forgotten when I do work on audio again.


... to confirm: the audio board allows stereo input use of the audio library. Without that board you can use the full library - but only on a single analog input?

Yes, more or less.

The audio library is designed to allow you to use any of its objects, interconnected in almost any way. But today, there are only 2 input objects, a mono ADC input and a stereo I2S (audio board) input.

Eventually, more types of inputs will become available. Another ADC1 input will eventually be added. Maybe someday a quad channel I2S input might happen... maybe? USB audio input and output also planned. Perhaps in some distant future, network streaming inputs and outputs might be added too.

In some glorious but distant future, the audio library will allow interconnecting any combination of those many inputs and output, routing the sound through effects & filters (which you can control from anything with an Arduino library and a little code in your sketch), to/from storage, into analysis objects that let your sketch control anything that can be interfaced or has an Arduino library (and a little glue code in your sketch).

That distant future will probably also feature far more powerful Cortex-M7 processing power and higher bandwidth memory interfaces like QSPI & SDIO. But even now, with only a small collection of I/O objects, SPI bandwidth to off-chip storage, and Cortex-M4, quite a lot can be done.

Later this year I'll do much more with the audio library, which will be a stepping stone to that distant future....
 
Status
Not open for further replies.
Back
Top