Searching \ for '[PIC]: Playing WAV files on a PIC' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Playing WAV files on a PIC'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Playing WAV files on a PIC'
2000\08\26@134818 by Nicholas Irias

flavicon
face
I am planning to use a PIC to play a few WAV files for sound effects.  My
current plan is to store the WAV file data block in EPROM, use the PIC to
pull sequential data samples, and use one of the PWMs to generate an analog
output for each sample.

My question has to do with mixing two or more WAVs so they can be output on
a single PWM.  Assuming that the sample rates are identical, is this just as
simple as adding one sample point from each data stream and using the sum
for an output?  Or is there some greater trickery involved?  The question
arises because I have only two PWM outputs on the PIC and I might have three
or more sounds superimposed.

By the way, if it sounds like I am approaching this problem the hard way,
please let me know.

-Nicholas

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2000\08\26@172053 by Bob Ammerman

picon face
Yes, you can pretty much just add the samples, but you have to look out for
overflow conditions.

You might want to add, then rotate the answer right to divide by two while
shifting in the carry bit.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2000\08\26@180503 by Olin Lathrop

flavicon
face
> I am planning to use a PIC to play a few WAV files for sound effects.  My
> current plan is to store the WAV file data block in EPROM, use the PIC to
> pull sequential data samples, and use one of the PWMs to generate an
analog
> output for each sample.
>
> My question has to do with mixing two or more WAVs so they can be output
on
> a single PWM.  Assuming that the sample rates are identical, is this just
as
> simple as adding one sample point from each data stream and using the sum
> for an output?  Or is there some greater trickery involved?  The question
> arises because I have only two PWM outputs on the PIC and I might have
three
> or more sounds superimposed.

Yes, "superimposing" sounds can be done by instantaneously adding the
multiple analog signals.  Note that if you want to perserve the overall
volume, then this should really be an average instead of just a straight add
operation.

And, yes, this averaging can be done with the analog signals or the digital
numbers before they are turned into analog.  Given just the brief
information you supplied above, my clear preferance would be to mix the
various audio signals digitally and then use that to drive a single PWM
output.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, spam_OUTolinTakeThisOuTspamcognivis.com, http://www.cognivis.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2000\08\28@113522 by Don Hyde

flavicon
face
As others have noted, mixing sounds is just adding.  The gotcha is that if
you add, say, two 8-bit numbers, you will get a 9-bit number.

The trick to getting it to sound good is in the editing of the stored
waveforms.  To make the most of limited output resolution, you want to
carefully control the amplitude of the stored waveforms.  If you do this
properly, then your PIC code can safely ignore overflows because you will
have taken care of them in advance.  It would also be wise to filter the
waveforms before storing them to get rid of aliasing.

The output of a PWM is harder to filter than the output of a DAC.  When
outputting silence, a DAC will output DC at the center voltage.  When
outputting silence, a PWM will output a rail-to-rail square wave at the PWM
frequency.  Make your PWM frequency as high as you can and it will be easier
to filter.

> {Original Message removed}

2000\08\28@131550 by Olin Lathrop

flavicon
face
> As others have noted, mixing sounds is just adding.  The gotcha is that if
> you add, say, two 8-bit numbers, you will get a 9-bit number.
>
> The trick to getting it to sound good is in the editing of the stored
> waveforms.  To make the most of limited output resolution, you want to
> carefully control the amplitude of the stored waveforms.  If you do this
> properly, then your PIC code can safely ignore overflows because you will
> have taken care of them in advance.  It would also be wise to filter the
> waveforms before storing them to get rid of aliasing.

What you are suggesting is theoretically correct, but will lead to more
quantization noise than storing each input at full amplitude.  Suppose you
want to mix N channels, all at the same gain.  Storing each channel with a
maximum amplitude of 1/N and adding them is NOT the same as storing each
channel at maximum amplitude, adding them, THEN dividing by N.  Of course
the latter method requires doing addition with more bits than the stored
values, but this is trivial.  If N is is kept to a power of two, then the
divide is just a shift.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, .....olinKILLspamspam@spam@cognivis.com, http://www.cognivis.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservspamKILLspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\08\29@013733 by Javier Grijalba

flavicon
face
There is an AN from Atmel, that describes how to do it !!
Bye
Javier

----- Original Message -----
From: Nicholas Irias <.....niriasKILLspamspam.....PACBELL.NET>
To: <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU>
Sent: Saturday, August 26, 2000 2:47 PM
Subject: [PIC]: Playing WAV files on a PIC


> I am planning to use a PIC to play a few WAV files for sound effects.  My
> current plan is to store the WAV file data block in EPROM, use the PIC to
> pull sequential data samples, and use one of the PWMs to generate an
analog
> output for each sample.
>
> My question has to do with mixing two or more WAVs so they can be output
on
> a single PWM.  Assuming that the sample rates are identical, is this just
as
> simple as adding one sample point from each data stream and using the sum
> for an output?  Or is there some greater trickery involved?  The question
> arises because I have only two PWM outputs on the PIC and I might have
three
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu>

2000\08\29@045102 by Kevin Blain

flavicon
face
Isn't the PIC PWM 10 bit anyway - so why worry about a 9 bit result?
----- Original Message -----
From: Olin Lathrop <@spam@olin_piclistKILLspamspamCOGNIVIS.COM>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Monday, August 28, 2000 6:12 PM
Subject: Re: [PIC]: Playing WAV files on a PIC


> > As others have noted, mixing sounds is just adding.  The gotcha is that
if
> > you add, say, two 8-bit numbers, you will get a 9-bit number.
> >
> > The trick to getting it to sound good is in the editing of the stored
> > waveforms.  To make the most of limited output resolution, you want to
> > carefully control the amplitude of the stored waveforms.  If you do this
> > properly, then your PIC code can safely ignore overflows because you
will
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu>

2000\08\29@051159 by Michael Rigby-Jones

flavicon
face
The PWM resolution depends on the frequency you configure the CCPR for.  At
higher frequencies (which you'd need for decent audio) the resolution will
only be 8 bits.  The frequency is pretty low for 10 bit resolution
(depending on crystal frequency of course)

Mike

> {Original Message removed}

2000\08\29@080535 by Olin Lathrop

flavicon
face
> > What you are suggesting is theoretically correct, but will lead to more
> > quantization noise than storing each input at full amplitude.  Suppose
you
> > want to mix N channels, all at the same gain.  Storing each channel with
a
> > maximum amplitude of 1/N and adding them is NOT the same as storing each
> > channel at maximum amplitude, adding them, THEN dividing by N.  Of
course
> > the latter method requires doing addition with more bits than the stored
> > values, but this is trivial.  If N is is kept to a power of two, then
the
> > divide is just a shift.
>
> Isn't the PIC PWM 10 bit anyway - so why worry about a 9 bit result?

Yes, the PIC PWM can be UP TO 10 bits.  The actual maximum value depends on
the clock and the PWM frequency.  If you set things up just right with the
right choice of N, you could just add and write to the PWM directly.  You
still have to do the add with 16 bits though.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, RemoveMEolinspamTakeThisOuTcognivis.com, http://www.cognivis.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu>

2000\08\29@100330 by Nicholas Irias

flavicon
face
If anyone is interested, the AN is at
http://www.atmel.com/atmel/acrobat/doc1456.pdf  It is an example of mimicing
an ISDxxxx record-playback chip using samples from an analog input to record
and using a PWM to playback, with a FLASH for storage.




{Original Message removed}

2000\08\29@100939 by Walter Banks

picon face
There is an app note with C sources on our WEB site to play
.WAV files through a small micros PWM.

http://www.bytecraft.com

Walter Banks

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspammitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...