SD/MMC Wav Player

Post here if you want to announce new wiki modules, projects or articles

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

SD/MMC Wav Player

Post by Steven » Mon Nov 13, 2006 1:32 pm

Dear All,

As a sample project, I have a produced a simple Wav player for files stored on Secure Digital (SD) or Multi Media Cards (MMC). The code reads from the card and writes to a circular buffer. An interrupt is then used to write bytes to PORTD. A R-2R digital to anlogue converter (DAC) is then used to produce the sound signal.

The project can be found on the Wiki at:

http://www.sfcompiler.co.uk/wiki/pmwiki ... CWavPlayer

I hope that this project is useful as a starting point for your own projects.

Regards,

Steven

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Mon Nov 13, 2006 6:24 pm

Here's another thought - I've tried it with several short files in succession. If I split a sentence such as "The time is six zero five and ten seconds" into short wav files for "The time is", "six", "zero", "five", "and", "ten" and "seconds", then play them back, they open, play and close fast enough in succession that it sounds like the original sentence. With a bit of work, it should not be too hard to record enough words to speak any time. The addition of a real-time clock should then turn this into quite a reasonable talking clock.

I might have a go!

lsb
Posts: 1
Joined: Wed Jan 03, 2007 7:00 pm
Location: Greece

Post by lsb » Wed Jan 03, 2007 7:30 pm

Hi Steven
I want to thank you for this project.
It is something I have been dreaming for, since I first heard about pics!
It is probably the main reason i accuired the compiler and a perfect way of learning more about using Swordfish.
Thank you again
LSB

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Wed Jan 03, 2007 7:35 pm

Lsb,

Welcome to the forum - it's good to know that you find the project interesting. I would be pleased to hear of your progress.

Regards,

Steven

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

wav player chips ?

Post by rubenpena » Tue Mar 27, 2007 12:32 am

Steven:
Hi... I saw your program and see you are using a 500 bytes circular buffer , It is that the reason you can only play 16khz files ?. By the way...
this implies you can use a 18f25J10 chip (has 1000 bytes of ram),it runs at 3.3v, so you not need the resistor dividers on the SD card.
Please comment...
Greetings...
Ruben de la Pena

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Tue Mar 27, 2007 6:01 am

You can actually get away with a significantly smaller buffer than 500 bytes. If you get too small though you will get glitches in the output as the buffer runs out when a new sector is read from the SD card. Don't forget that there is also an overhead of a 512 byte buffer and associated variables for the SD library. Still, by reducing the circular buffer, I would expect that you could get it within a total of 1000 bytes.
Running at 3.3V would also make life easier - you are right.
As for playing faster sample rate files, I think that you might struggle. The time taken to read from the card and the overhead of the interupts gives little slack time for the PIC. You might squeeze a little more out of it, but I don't think that you will get to 32kHz. The code is not as efficient as it could be as the SD library maintains it's own buffer, and data is read into a circular buffer. The SD library is easy to use and for many applications this is no problem. In this app, although the code for the wav player is relatively simple, speed gains could be achieved by writing a custom set of SD routines to read directly into a circular buffer.

Regards,

Steven

rubenpena
Registered User
Registered User
Posts: 32
Joined: Sun Mar 25, 2007 2:07 am
Location: Monterrey,Mexico

smaller buffer

Post by rubenpena » Tue Apr 10, 2007 4:34 am

Steven:
I reduce the buffer to 180 bytes,and it works OK. I run in on one 18F252 and I get the music and voices OK.
Then I compiled for the 18F25J10..,it compiled OK... but not runs... Any ideas...?
Thanks in advance...
Ruben de la Pena

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

SD WAV player output query

Post by blackcattech » Thu Jul 22, 2010 1:55 pm

I'm interested in making a simple sound effect player using the SD WAV code Steven developed. However, I wonder if anyone has used either the PWM output of the CCP module or an external DAC to get better sound quality? Is there enough throughput available in an PIC18 to handle reading and writing externally at the same time? I'm considering something like a 18F26K22 so can clock it higher then the 18F452 used in the example.

Ideally, I would even like to be able to play two channels simultaneously - is this likely to be possible or will there be too much overhead involved in switching between open files on the SD card? The 26K22 does have a fair chunk of RAM so I could use a larger buffer if this would help.

User avatar
octal
Registered User
Registered User
Posts: 584
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Thu Jul 22, 2010 2:56 pm

why not simply switch to use a dsPIC33. there are some of them that are 40Mips, 16Kb ram, 128K flash and have 2x16bit DACs, and the price is really not that higher than a PIC18Fxx ... for a single chip, you can got it arround 4.5 euros at Microchip direct (or as free sample) ... compared to a PIC18F at 2.5 euros, for 2 euro diff :shock:

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Thu Jul 22, 2010 3:16 pm

Simple answer is availablility of tools and knowledge of the core. SF seems to have the routines available to do this fairly easily and I'm familiar with the PIC18 core. Moving to a dsPIC for this would be a fairly major step for me and I wouldn't have use for those processors for any other of my projects.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Thu Jul 22, 2010 5:19 pm

It's now so long since I write the example that I can't remember the exact details. but I think that you could probably afford the overhead of writing to an external DAC (although I have to say that the sound quality using the R2R ladder isn't too bad). If you are trying to do 2 channels simultaneously, you may struggle as the reading demand from the SD card is then twice as fast and I don't think that you could easily cope with this and cope with writing to the DACs as well, but I could be wrong - it would be worth trying.
Switching between files might also be an issue. Although the example is straight forward, you could optimise it for doing what you want to do by modifying the SD library yourself, but this would obviously be more complex. With two big buffers you might just do it, so long as the sample rate of the files didn't need to be too high.

micromaster
Posts: 1
Joined: Thu Jun 16, 2011 3:35 am
Location: srilanka

sd cars seems to ahve a problem ??

Post by micromaster » Thu Jun 16, 2011 3:50 am

hi im new to this forum and ive been using sf compiler for a time.recently ive built a sd/mmc based wav player.but everytime i start the system,my lcd starts saying "please insert sd csrd". ive been using a kingston 128mb
sd card and still no results.ive changed everything including power deviding
resisters.my pic is pic 18f2550.is there any way to check the data transfer between pic and card??or has anyone has encounted this before?
Dileepa

Post Reply