CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Choosing the right dsPIC for audio

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

Choosing the right dsPIC for audio
PostPosted: Thu Jun 04, 2015 11:55 pm     Reply with quote

Please help me choose the right dsPIC for a new project. I haven't had much experience in DSP with PICs.
I wish to store FIXED audio samples in an external serial flash and be able to mix up to 10 channels on the fly to create a 'musical instrument'. Quality is 16bit 22KHz (mono).
I intend to use the SST serial flash (64Mbit part). Does anyone have code to use it?
Next, the PIC needs to perform 220,000 16x16 (signed) multiplications per sec. Is this a challenge for a dsPIC with the CCS compiler? Which part could fit?
I would probably need some RAM to buffer the flash and the output buffer.

Is PWM good enough as a 16-bit D/A ? Other parts to do the job?

Thanks!
Guy
Ttelmah



Joined: 11 Mar 2010
Posts: 19455

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 2:54 am     Reply with quote

I doubt if that is going to be possible with a PIC.

220000 multiplications. OK. However problem is that while each multiplication takes one cycle, you have got to get two numbers from two different locations, and then put the results somewhere. Each of these takes probably half a dozen operations, and even if one of the three transfers involved can use DMA, you still have the other two. Ouch. Then the numbers are going to have to be scaled as well, so more operations.

Then the PWM. Problem is that to use this for a 16bit output at an audio frequency, the master PWM clock will have to be double the output frequency for every extra bit. Beyond anything practical. This is why a DAC will be much better, but try getting a genuine 16bit DAC, and you will find this is getting very expensive. The board layout will also need to be superb to give a genuine 16bit output (seriously don't get misled by people 'claiming' 18bit, or 20bit abilities - few systems achieve even a fraction of this for real).

Then remember that if you want a 20KHz signal ability you need to actually be using signals at least twice this rate (this is why 44KHz is common for sampling). For any competence your data rate has suddenly doubled...

Digitally mixing two signals does not multiply them. You need to sum, and scale to avoid clipping:
<http://www.vttoth.com/CMS/index.php/technical-notes/68>

You are into a _lot_ of computing and some serious electronics to produce anything worthwhile.
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 05, 2015 7:39 am     Reply with quote

Quote:
220000 multiplications. OK. However problem is that while each multiplication takes one cycle, you have got to get two numbers from two different locations, and then put the results somewhere. Each of these takes probably half a dozen operations, and even if one of the three transfers involved can use DMA, you still have the other two. Ouch. Then the numbers are going to have to be scaled as well, so more operations.

I thought the dsPICs can go up to 70MIPS? Theoretically gives 318 instructions per multiply or 3180 instructions per output sample. So you don't think it can handle it?
Quote:
Then the PWM. Problem is that to use this for a 16bit output at an audio frequency, the master PWM clock will have to be double the output frequency for every extra bit. Beyond anything practical. This is why a DAC will be much better, but try getting a genuine 16bit DAC, and you will find this is getting very expensive. The board layout will also need to be superb to give a genuine 16bit output (seriously don't get misled by people 'claiming' 18bit, or 20bit abilities - few systems achieve even a fraction of this for real).

You convinced me - external DAC. Data throughput would be ~400KHz which is reasonable. I could also settle on the actual sound quality and THD...
Quote:
Then remember that if you want a 20KHz signal ability you need to actually be using signals at least twice this rate (this is why 44KHz is common for sampling). For any competence your data rate has suddenly doubled...

I listened to audio at 22KHz and it's 'good enough' for me.
Quote:
Digitally mixing two signals does not multiply them. You need to sum, and scale to avoid clipping:
<http://www.vttoth.com/CMS/index.php/technical-notes/68>

RIGHT! I forgot about this as I haven't done these things for a while. I don't need multiplication! I need addition! For signed 16-bit numbers this is VERY quick, even for an 8-bit MCU. Since the audio samples are constant they could be scaled beforehand. I could also divide by 8 or 16 and round the result on the fly with bit-shifting.
I suppose I would take into account just one 16-bit multiply for volume or some audio effect but this simplifies everything I suppose..?
Quote:
You are into a _lot_ of computing and some serious electronics to produce anything worthwhile.

Sorry for not getting the hint and hearing the opposite Cool
jeremiah



Joined: 20 Jul 2010
Posts: 1340

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 8:08 am     Reply with quote

guy wrote:

I listened to audio at 22KHz and it's 'good enough' for me.


As a note he wasn't saying to listen to it at 44kHz, but that you must sample at least 2x the desired listening frequency (see Nyquist rate: http://en.wikipedia.org/wiki/Nyquist_rate ).

If you mean you are fine with 22kHz sampling, then you will be only getting an unaliased signal at 11kHz and at that point, you probably don't need to do the 16bit resolution.
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 05, 2015 8:24 am     Reply with quote

The sampling will be done at high quality (hopefully studio recording) and reduced to 22KHz samples. I tested 22KHz audio and it's ok for me. So I expect to maintain the theoretical 11KHz bandwidth. The 16-bit data is necessary when dividing/multiplying even if the audio signal chain gives lower quality.

SO... any tips for choosing a PIC and a D/A ? Libraries for SST flash anyone???
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 9:17 am     Reply with quote

The 'old school' cheat, er method, was to use a PC sound card. That offloads all the ugly super fast timing requirements.
It was easy 'back then' to take an 8 bit ISA sound card interface it to the 'new' PIC16F877 running at 20MHz.
I haven't checked but perhaps there's an 'audio interface' card you could let the PIC control ??

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19455

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 12:55 pm     Reply with quote

In all honesty, I'd simply use an embedded PC for this. Run Linux, and complete code libraries are available, and it'd cost _less_ than trying to layout any reasonable audio interface.

22KHz audio, needs 44K samples/second.

Then key problem you have to remember is that 70MIPS, is processor instructions not C instructions. Fetching just a single byte from an array, involves reading the index, multiplying this by the element size, loading this into the index register, then reading the word.
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 05, 2015 1:58 pm     Reply with quote

I totally agree with you dear Ttelmah, but due to size, power usage and no knowledge/wish to deal with Linux I wouldn't go with an embedded PC. I need a small portable gadget.
When I wrote 22KHz audio I meant 22K samples/sec. The highest frequency obtained would be 11KHz according to Nyquist's law. Got it.
The efficiency difference between the processor's hardware potential and CCS C compiler is also a known issue. If all else fails I would get my hands dirty with assembly for the low-level mixing routine. Not counting other tasks, to mix 10 channels I would need 10x 16-bit lookup & addition instructions (I can sum all values into a working register). Definitely doable within 3180 instructions (70 MIPS), right?
So if anyone is interested in supporting me, I'd love to hear from you.

I really appreciate your help throughout the years Ttelmah! I'd love to have you on my side. Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19455

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 11:36 pm     Reply with quote

Unfortunately, I think your target is not really practical with this hardware.

A look up table. Straight away you have to calculate the address to use. Load a value, multiply this by the element size, add this to the start of the table. Then load this value into the index register, then read. Just a single look up, is probably a dozen instructions. Repeat by ten. For each operation, you are then going to have to do the maths. Then simple things. Reading a byte from the memory. This is going to involve sending it the address and reading the value back. Multiple instructions. Even the act of sending the value to the DAC. Almost certainly involve clocking it out. Even with hardware SPI, _time_. Worse everything has to be done synchronously to the required rate, if the sound is not to be affected. With 10 channels, 3000 instructions is only 300 per channel, and suddenly does not look at all comfortable. The code is going to be a huge amount of work. Honestly _months_ of development, versus something that could be running in days using the PC.

Do a search for Tiny-LX. There are other similar products.

Also the PIC at 70MIPS and audio interface is going to draw a lot more power than you expect.

It's like coming and asking about trying to move several tons of equipment using a motorbike. Possible?. Yes. Sensible?. No. Much easier with a van....
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Sat Jun 06, 2015 12:09 am     Reply with quote

Ok, you convinced me. I won't do the project.
Ttelmah



Joined: 11 Mar 2010
Posts: 19455

View user's profile Send private message

PostPosted: Sat Jun 06, 2015 1:46 am     Reply with quote

Just use an embedded PC instead.

There was another thing being 'missed'. This is to do with audio processing. I suspect you have tried 22K samp/sec audio on a PC, and it sounds OK, so you think '22K samp/sec fed to DAC = same result'. Answer to this is a fervent 'no'. The PC audio codec chips have a lot more in them than simple DAC's. If you are running one using 22K samp/sec, then the chip will be automatically using it's internal DSP, to perform oversampling to the output, which will also have a digital filter, before the actual signal is fed to the outside world. The chips in a typical PC audio codec, have as much processing power as the PIC inside them!...
Most PC's (even the embedded chipsets) will have a codec that is compliant with AC97 _as the minimum_, so will actually be outputting 48K samp/sec, even when fed with 22K samples.
There is a lot of work involved in getting a 22K samp/sec stream to actually output acceptably.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group