PDA

View Full Version : Audio Encoding and playback in a PIC



Rob
- 23rd March 2005, 15:19
First off - has anyone used this program "Roman Black's Encoder.exe" ?

I am trying to play sound out of a PIC16F877A. First of all I downloaded the above mentioned program from http://www.romanblack.com/picsound.htm, which is used to encode audio into a binary bitstream and output the encoded information as an assembly file. It also outputs the binary values into their hex equivalents (in the assembly file).

I have encoded around twenty seperate words using this program and have extracted the hex codes only from each. I have then placed these codes into an external EEPROM as there are between 500 and 1000 bytes of hex per word (far too large to fit into the PICs EEPROM!).

I am reading the values back into the PIC and then outputting them using the SHIFTOUT command through an RC filter into an audio amplifier and then into a speaker. Unfortunately, the speech is completely garbled. I have read his page from top to bottom and feel that everything he has written is correct and that this program should work - maybe I have been fooled?

Oh, I should state that I have e-mailed him but have had no reply - maybe he has changed his e-mail address?

Any help is much appreciated

Rob

mister_e
- 23rd March 2005, 16:53
o.k so what about if you try HPWM instead of shiftout? Is the encoding is made in 8 bits, 10 bits 16 bits?? or what about if you output your data directly to a 8 bits port and do a simple d/a converter with resistor and a op-amp mixer???

let us know.

i'll have a look to your link later... i'm a bit curious on that.

Rob
- 23rd March 2005, 17:08
o.k so what about if you try HPWM instead of shiftout? Is the encoding is made in 8 bits, 10 bits 16 bits?? or what about if you output your data directly to a 8 bits port and do a simple d/a converter with resistor and a op-amp mixer???

let us know.

i'll have a look to your link later... i'm a bit curious on that.

The encoding was made in 8 bit format. Each output bit is used to charge, or allow to discharge, a capacitor. A 1 ouptut charging the capacitor and a 0 output allowing the capacitor to discharge. The 1's and 0's need to follow each other one after the other, to allow the capacitor to charge/discharge.
Unfortunately, the HPWM command won't work as the output from the encoded audio is just a binary bitstream and not any one particular frequency.

Check the link out when you get time - I think you will be very interested! ;-)

Thanks for your help

Rob

Jay
- 23rd March 2005, 18:10
Rob,

I too have both attempted to make Roman Black technique work and to contact him, without success.

I believe the way to go is HPWM but only know you need a sophiscated analog filter to get decent fidelity.

An example of a 4th Order Butterworth Low Pass Filter can be seen here:

http://www.freescale.com/files/32bit/doc/app_note/MC68EZ328PWM.pdf

As the math gets pretty hairy for active filter design, this package was recommend to me by an audio engineer:

http://www.schematica.com/filter_wiz_files/FWPRO.htm

He also recomended storing the audio file in LogPCM format into a Serial EEPROM (STTS4900) and using SPI to configure the HPWM registers.

I have some pieces of this puzzle, but have wide gaps in between.

My application is to generate a high quality ding-dong sound complete with the fade after the ding and the dong.

We have tried the low cost melody chips from Tiawan but the quality is not acceptable. ICD products are too expensive for this design.

Jay

srspinho
- 23rd March 2005, 19:04
Hi people,

have you ever seen the article written by Les Johnson on Proton´s users site ?

http://users.picbasic.org/projects/making_music/

may be it could haelp you or give some ideas.

Regards

Sérgio

Rob
- 23rd March 2005, 20:35
Rob,
I believe the way to go is HPWM but only know you need a sophiscated analog filter to get decent fidelity.
My application is to generate a high quality ding-dong sound complete with the fade after the ding and the dong.
Jay

Thanks for the info - I'm glad I'm not the only one who is struggling with this! Did you manage to get any sound from the design, if so was it very poor or did it vaguely resemble the sound you are after?

Have you started to create the filter circuit for your application yet?

Cheers

Rob

PS thanks also to SRSPINHO - I 'm going to have a detailed look at that page over the next few days.

Darrel Taylor
- 23rd March 2005, 23:41
Hi Rob,

I studied Roman's idea about a year or so ago. I was planning on using it, but never did get around to it.

But what I remember is that the "bit-stream" has to be put out at a continuous frequency that is dependant on the encoding of the audio signal.

If you are trying to send the "Stream" using SHIFTOUT, then it's going to send out 8-bits at an unknown bit-rate, and then there's going to be a big pause while you get the next byte from the EEPROM. I would imagine that your description of "garbled" is probably an understatement.

From what I see, you're going to have 2 problems to deal with. The first one is fairly easy, the bit-stream needs to be sent out using an ASM interrupt driven by a timer at a fixed frequency. This will give a continuous stream at a fixed bit-rate. It also frees up some time for the rest of the program to fetch data from the EEPROM.

The second problem may be getting the data from the external EEPROM fast enough to supply to interrupt routine with enough data so it doesn't miss a bit. With a 44khz audio stream, you'll need a new data byte every 181uS. Getting one byte at a time may not be fast enough, but if you created a buffer, and read from the EEPROM in blocks it might just work. If not, you may need to use the Hardware I2C (if your PIC has it).

Slower Audio encoding will also help if getting the data takes too long. If all you are playing back is speach, you can probably go much lower. But then that means recalculating the "Binary Time constant".

HTH,
   Darrel

Rob
- 24th March 2005, 07:56
Darrel,

Thanks for that information, that is gonna be really helpful. I should be able to grab the data fast enough as it was encoded at around 8Khz - figured this would be good enough quality for speech (for my application anyway). Now you've mentioned the interrupt, I will look into doing it that way.

I'll let everyone know if I have any success!

Thanks again

Rob

languer
- 24th March 2005, 08:56
I was also interested in this sometime back and did not converge on an answer. For reference, this has been covered here:
http://www.picbasic.org/forum/showthread.php?t=2448&highlight=roman+sound

I would also check the following, as it seemed a more elegant approach:
http://www.picbasic.org/forum/showthread.php?t=2528&highlight=ADPCM

Good luck.