Go Down

Topic: costom audio format.(that plays on any arduino) IDEA (Read 1 time) previous topic - next topic

brenden_nerd_

Oct 11, 2016, 04:02 am Last Edit: Oct 11, 2016, 04:10 am by brenden_nerd_
I am currently building a arduino smartwatch that i want to have the ability to play audio files. Im using a arduino micro for the watch and an arduino uno, for prototyping. Ive run into the problem that the arduino wav player library only works on the arduino duo and i then came up with a idea. A costom audio format that is unique to the arduino platform. The idea i have for this format is the idea of outputing audio though pwm. My idea is that if we can record data via analog output, we could then save that data on a sd card for later play back (of course this makes piracy a easy task as well) heres my idea for it. The arduino takes in a analog signal which is attached to a audio sourse. The audio is divided by the range of pwm output (i think its 255) then it is save to the sd card.When the time comes for play back the arduino would have a speaker connected to two of the arduinos pwm pins. (Each pin alternates between outputing audio and being a ground pin, therefore increasing volume) im unsure how practical this idea os but im sure it can be done. My idea for saving audio to the sd card consists of saving a single byte of audio per line.

156
157
158
Etc.

Only one problem. Im grounded  and im posting this off my phone. I cant test my ideas nor can i attempt them unless i somehow program my arduino with out a computer. If you have any contribution to this project please leave a comment. Audio quality is not a problem im worried about. Just so long as clear speach remains understandable.
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

DVDdoug

PWM isn't great for audio unless you have a very high frequency (which the Arduino does not), and the Arduino's PWM is only 8-bits.

Quote
My idea is that if we can record data via analog output, we could then save that data on a sd card for later play back.
I assume you mean the Arduino's analog input  and I think you're describing normal digital sampling.    The Audacity website has a good introduction to digital audio.

The Arduino's ADC can't read negative voltages so in order to read the negative half of the AC audio waveform the input has to be biased.   Then, you can subtract-out the bias in software.    Although...  It turns out that 8-bit WAV files contain only positive integers and are biased so the bias is subtracted-out when the file is read.  (16-bit and higher WAV files do contain negative numbers.)

But, it's probably easier to record the audio with your computer and save it to an SD Card.   As long as your computer can write to the card, a program like Audacity can write a WAV file or raw PCM data.

Quote
The audio is divided by the range of pwm output (i think its 255)
Yes, the PWM is 8-bits and the ADC is 10 bits so you can divide by 4 to scale it down.

Quote
...A costom audio format that is unique to the arduino platform...

...My idea for saving audio to the sd card consists of saving a single byte of audio per line.
There's no reason to invent a new format.   There are no "lines" in a normal audio file.   It's just a series of sample values (bytes or 16-bit words, etc.).    The only difference in a WAV file and a "raw" audio file is that the WAV file has a header that gives the bit-depth, sample rate, number of channels, etc., so it's a lot easier to play back without knowing those details.  (I believe the WAV header is 44 bytes so it doesn't take much space.)

brenden_nerd_

#2
Oct 11, 2016, 06:30 am Last Edit: Oct 11, 2016, 06:34 am by brenden_nerd_
From the test i have done i get one result from using the the audacity method. When i use audacity to convert a file into a 8 bit mono track the arduino normally response trough the speaker by playing a short beep and then static. This only happens when it trys to read the audio file. The library i used to get that result is the arduino wav library  (not actual name.)... however i have yet to find any tutorials that when i repeat them actually work.

  From the observing i noticed in audacity the negative section of wave form seems to be the same as the positive except mirrored horizontally. Which i can asume means that the speaker is reversing its positive and ground.  And im not quite sure what you ment by your first statement about pwm, does pwm not do well with high frequencys or low frequencys?
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

Grumpy_Mike

#3
Oct 11, 2016, 10:57 pm Last Edit: Oct 11, 2016, 10:59 pm by Grumpy_Mike
Quote
From the observing i noticed in audacity the negative section of wave form seems to be the same as the positive except mirrored horizontally.
It may look like that but it isn't.

This is the speech quality you can get through a 8 bit PWM sample. https://youtu.be/WShVFcrFpwU

Quote
does pwm not do well with high frequencys or low frequencys?
The PWM frequency must be at least twice the sample rate, if not higher. Low frequencies are fine.

jremington

Another example of 8-bit PWM voice synthesis, using the Talkie library for Arduino (no extra hardware).

brenden_nerd_

It may look like that but it isn't.

This is the speech quality you can get through a 8 bit PWM sample. https://youtu.be/WShVFcrFpwU
The PWM frequency must be at least twice the sample rate, if not higher. Low frequencies are fine.
i think your video perfectly demonstrates that the arduino uno can indeed play audio that is understandable. Now would it be possible to take the hexideimal input that the talkie library uses and have the library read it from a sd card? And then my second question is how the heck do i convert a audio file to hex? I have no idea and have dont searching in the past on it but came up empty. Keep in my i use win 10 but i have dual boot Linux. As well i have a win xp laptop.
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

Grumpy_Mike

Quote
Now would it be possible to take the hexideimal input that the talkie library uses and have the library read it from a sd card?
Yes.

Quote
And then my second question is how the heck do i convert a audio file to hex?
No need it is already in hex. Hex is just a convention for writing down a binary bit pattern. If you save an eight bit sample in Audacity it is in effect hex.

In order to maximise the quality of those samples I made the dynamic range cover the full 0 to 255 range of 8 bits. To do this I recorded and saved a 16 bit sample in Audacity. Then I wrote a program in the Processing language that scanned the sample file to find the maximum and minimum values in the sample and apply a scaling factor to turn it into a 8 bit value and generate a file suitable suitable for including in an Arduino sketch.

Code to do this is avaliable and a full explanation is in my book.
http://www.apress.com/9781484217207

brenden_nerd_

Thanks grumpy ^-^ . So the last thing is for reading the hex then. If im using the talkie library would i simply just put down

VoidLoop () {
voice.say((uint8_t*)sd.read);
}

//of course im discluding the part where i pick what file im reading.

 
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

Grumpy_Mike

Quote
If im using the talkie library
Which one is that then? Can you post a link please.
You need to feed the PWM timer at a constant rate, the sample rate of the audio.

brenden_nerd_

crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

Grumpy_Mike

That library is not designed to take in samples that you create. It is an emulation of a linear predictive encoder chip. These used fixed samples which were then processed to give the samples to play. I know of no software that will give you an encoded sample from a linear sample so you would have to write your own. You certainly can not do it in Audacity and your results are what I would expect.

I thought the quality of this was well below the quality of the origional chip it was trying to emulate as I remember it from the BBC computer that had this chip built in. You could also get extra vocabulary chips which were just ROMs with samples in.

pjrc

You should really consider stepping up to more powerful processor.

By now you're probably getting a feeling for the limited, fairly low quality sound possible with these old 8 bit AVR chips.  The other huge problem is even mediocre sound consumes nearly all the available CPU time, which will make implementing any other smart watch features extremely difficult while the sound is playing or recording.

I've spent the last couple years working on a powerful audio library for 32 bit Teensy.  You should check out this tutorial video to get an idea of what's possible.  Even if you don't use Teensy, you'll be doing yourself a huge favor to step up to pretty much any of the 32 bit ARM-based boards.  The extra memory and performance will really help for this sort of project.

brenden_nerd_

The teensy seems like a good option. Except 1 that wont fit in my enclosure and 2 is it possible to read say text documents at the same time as you play audio (and do i have to use that weird click and drag programming system?) And last where can i buy one. As well, are there any combo boards you make containing the audio driver and the teensy? That would be more compact.
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

brenden_nerd_

Well right now its starting to look like using a raspberry pi for this project is a better idea. Then again i would have to learn python.
crater of focs os http://petitcomputer.wikia.com/wiki/Focs_operating_system

Grumpy_Mike


Go Up