News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

roger beep with pic

Started by Giuseppe, Aug 27, 2022, 04:56 PM

Previous topic - Next topic

Giuseppe

Hello everyone
I was going to make a roger beep with different effects with a micro 12f1822.
How is it possible to convert audio files to hex format and then save them in the pic?

Yasin

I hope I understood the question correctly. The audio file should be in 8-bit mono wav format. At what rate you send the bytes to the DAC is related to the sample rate of the file. You can open and read the wav file in any HEX editor. When you remove the header part, the rest is raw data.

trastikata

#2
Quote from: Giuseppe on Aug 27, 2022, 04:56 PMHello everyone
I was going to make a roger beep with different effects with a micro 12f1822.
How is it possible to convert audio files to hex format and then save them in the pic?

For an automatic GPS coordinate voice reporting, I used 1 bit audio stream wav converter with the BTc Sound Compression Algorithm  from Roman Black, more information and the conversion software can be found here:

http://romanblack.com/btc_alg.htm

In my case I put each word in a flash data table which was played when called to pronounce each digit.

RGV250

Hi,
Norm (Fineline IDE) had a wav player on the old forum, I might have it somewhere if he does not see this post.

bob


normnet

Quote from: RGV250 on Aug 27, 2022, 09:49 PMHi,
Norm (Fineline IDE) had a wav player on the old forum, I might have it somewhere if he does not see this post.

bob



You may wish to look at "freqout" in the manual for a simple tone.  Else I can post a copy of a PIC PWM audio output reading from an Ldata table.

Norm

top204

#5
For good quality audio output on a microcontroller that does not have a lot of RAM, it is better to use a double buffer method. So while the audio data is being read and manipulated, a second RAM buffer is outputting the audio via PWM or a DAC. Then vice versa. It makes the audio seemless and gives it a much higher quality.

I've done this several times in projects that read WAV data from flash or SD card or external flash memory. I'm sure I wrote an article about that on the old forum about 15 years ago, or so.

Also, WAV is much better quality audio that all the compressed stuff. The only lack of quality in it is when it is sampled using a low bit rate or low bit ADC, or played back with a low bit rate or low bit DAC. So my advice is to use as much flash as possible to hold the higher bit-rated sampled data and play it back as fast as possible to increase the bit rate. Even with 8-bits, higher bit rate can make it sound quite good with an active op-amp filter after it.

shantanu@india

Controlling a 2 doller MP3 SD card module with a PIC is cleaner & faster.I have made a lot of automated public announcement units in the past.

https://www.electronicscomp.com/mp3-tf-16p-mp3-sd-card-module-with-serial-port?gclid=CjwKCAjwpKyYBhB7EiwAU2Hn2X9Knb86iZI-HiMKxfpdcTPMm7N_2b6Vk8GVHR_TQcGUbSO0z3mADBoCa4UQAvD_BwE
Regards
Shantanu

top204

#7
QuoteControlling a 2 doller MP3 SD card module with a PIC is cleaner & faster.

But that takes the fun and creativity out of it! We can all use "third party" items that do the job for us, but then we may as well all use ready made items. :-)

For excellent quality audio, a single PIC microcontroller can be used with an SD card containing one or more 16-bit WAV files. Even the small and now out of date 64Mb or 256Mb MMC cards can be used for shorter audio passages, and they are virtually given away now.

Then combine two high frequency 8-bit PWM channels as one 16-bit PWM channel using a simple piece of firmware. It operates as an excellent 16-bit DAC! Then you get excellent quality 16-bit audio with a cheap microcontroller, a cheap SD or MMC card, an inexpensive op-amp low pass filter, and an amplifier. And, most of all, they are all replacable with other suitable components, because none of them have a dedicated task. Whereas the third party item may (will) stop being manufactured, or, as is happening now, become too expensive to buy. And it is fun to design and build, as well as inexpensive.

It also gives pride in saying to yourself: "Look what I have just designed and built from common components and ingenuity". :-)

Giuseppe

Top204 do you have an example of a listing for reading wav files from flash?
Or where can you see on the old forum?

normnet

18F26K20 PWM audio output from PIC Ldata table.

Attached is a txt file.  Please change the extension to .bas

I can also provide a wave to Ldata table utility app if interested.

2013-04-17v01 PIC PWM audio output from Ldata table.txt


Norm

normnet

#10
Wav to Ldata converter

Download is a txt file.  Please change the extension to .exe

Click Download button at 2012-05-17v01 Wav to table converter

Search online for wav editors and text to wav converters.

Norm

Maxi

Quote from: normnet on Aug 28, 2022, 05:04 PM18F26K20 PWM audio output from PIC Ldata table.

Attached is a txt file.  Please change the extension to .bas

I can also provide a wave to Ldata table utility app if interested.

2013-04-17v01 PIC PWM audio output from Ldata table.txt


Norm
hi norm,
could you attach a proteus schematic picture?
I want to try this but not hearing a useable sound

Giuseppe

I wanted to ask if there is a converter that gives me a table to put in Ldata. With the first parameter a word for the tone and for the second parameter a word for the duration of the tone?

A code example :LData As Word 1318,187,1760,187,1318,187,1975,187,1318,187,1568,187,1760,187,_
1318,187,2092,187,2349,187,1318,187,1975,187,2092,187,1318,187,1975,187,1318,_
187,1760,187,1318,187,1568,187,1760,187,1318,187,2092,187,1318,187,2349,187,_
1318,187,1975,187,2092,187,1975,187,1318,187,1760,187,1318,187,1975,187,1318,_
187,1568,187,1760,750,0,0

Thank you

normnet

#13
Quote from: Giuseppe on Sep 03, 2022, 10:43 AMI wanted to ask if there is a converter that gives me a table to put in Ldata. With the first parameter a word for the tone and for the second parameter a word for the duration of the tone?

A code example :
LData As Word 1318,187,1760,187,1318,187,1975,187,1318,187,1568,187,1760,187,_
1318,187,2092,187,2349,187,1318,187,1975,187,2092,187,1318,187,1975,187,1318,_
187,1760,187,1318,187,1568,187,1760,187,1318,187,2092,187,1318,187,2349,187,_
1318,187,1975,187,2092,187,1975,187,1318,187,1760,187,1318,187,1975,187,1318,_
187,1568,187,1760,750,0,0

Thank you

Each Ldata value is an audio sample as a digital (duty%) value of PWM output voltage. The example program I posted appears to read 8 bit samples.  The rate at which they occur is determined by the timer interrupt.  My posted program looks like its running at 22K samples per second.  For example CD quality for music is 16 bit samples at 44.1K per second.  Excuse the program comments as they may not of been updated. An inexpensive oscilloscope is excellent for viewing audio signals.  I'm guessing the Ldata table you posted may be reading stereo with only one channel in use.  You will need an 8 bit 22K mono wav file to convert to Ldata for my example program.  A wav file editor may be necessary.

Norm

normnet

#14
Quotehi norm,
could you attach a proteus schematic picture?
I want to try this but not hearing a useable sound

The following pdf schematic is from an earlier 2009 version of wav player on the old forum however should be of value for the audio amplification portion. 

Click Download button at PIC wav player mono 16bit 44k with GLCD schematic v1_0.pdf


Norm