Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
Edward L
Berek8

posted on 2011/09/14 09:23:07 PM CEST

Audio & Speech

Audio recording with dsPIC & SD card!

Hello guys, anyone could give me a little help or ideas with this?

I'm at this moment using the dspic30F, with a sampling rate of 44.1 Khz, I would like to save the data of the ADC converter in the SD as a wav file (I already have the header btw), however I'm not really sure what should be the ideal way of doing it, maybe trying to save the data after X number of samples or after filling X number of sectors?

Thanks!!!!

USER Comments

Edward L
Berek8

posted on 2011/09/21 11:44:37 PM CEST

http://dl.dropbox.com/u/15639054/sound_files.rar

These are my test files, on the background you can hear me touching the mic and whistling. My guess is that probably the 44khz its just too much.

Edit:
If you can import the audio on Audacity or another sound editor, you will see that most of my data is in the range of 01000000 when it should be centered at 1000000 for no sound or near.

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 109 in "Audio recording with dsPIC & SD card!" request.

Edward L
Berek8

posted on 2011/09/21 02:44:20 PM CEST

Ok guys, after reading some of the code, and using the libs from mikroC i got this, I first make a new file with the WAV header and after that i append the data, however the problem is that after I check the sound file I just hear a lot of noise.

Any suggestions guys? thanks!

void int_ADC () org 0x2A
{
buffer1 = ADCBUF0;
buffer2 = buffer1 >> 2;
sndbuf1[samplecount++] = buffer2;
if (samplecount == 512) {
samplecount = 0;
}
IFS0bits.ADIF = 0; // Desactivar bandera de A/D

}

void int_T3 () org 0x22
{
if (DONE_bit){ // If ADC is not busy
SAMP_bit = 1; // Start new sample
}
IFS0bits.T3IF = 0;

void M_Open_File_Append() {

filename[7] = 'B';
Mmc_Fat_Assign(&filename2, 0);
Mmc_Fat_Set_File_Date(2011, 1, 23, 17, 22, 0);
Mmc_Fat_Append();
for(i=0; i<500; i++) {
Mmc_Fat_Write(sndbuf1, 512); // Write data to assigned file
}
// Prepare file for append

}
}

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 108 in "Audio recording with dsPIC & SD card!" request.

Edward L
Berek8

posted on 2011/09/19 01:00:51 AM CEST

Thanks Rahhou!!, I'll check it tomorrow, if I get any advances on this I'll update this topic.

See ya guys!!!

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 106 in "Audio recording with dsPIC & SD card!" request.

mr2010
MR2010

posted on 2011/09/16 09:52:51 AM CEST

Hi,
i used this function to record sound on Sd card it works well but RAW,

//############################### write sound to SD ##############################################
void WriteSD(void)
{
unsigned int r,i;

CS = 0;
ADCON1 = 0B11001110; // Fosc/16, ch1, ref=Vdd, right just.
ADCON0 = 0B011000000; // Fosc/16.
RecLED = 0;
r = Command(WRITE_MULTIPLE_BLOCKS,loc,0xFF); //read multi-sector
if(r != 0){errorLED = 1;
}else{
errorLED = 0;}
ADON_bit=1;

SPI(0xFF);
SPI(0xFF);
SPI(0xFF);

while(Stop)
{
SPI(0xFC); //multi sector token byte

RecLED = 1;

for(i=0;i<512;i++)
{

ADCON0.B2 = 1;


while(!TMR2IF_bit){} //20KHz clock


SPI(ADRESL);


//play while record
CCP1X_bit = (ADRESL & 1); //shift byte to get the required PWM duty cycle
CCPR1L = (ADRESL>>1);

TMR2IF_bit = 0;



}
SPI(0xFF); // CRC
SPI(0xFF); // CRC


if((r=SPI(0xFF) & 0x0F) == 0x05){ //data accepted = 0101
for(i=10000;i>0;i--){
if(r=SPI(0xFF)) break;
}
}
else{
errorLED = 1;
}
while(SPI(0xFF) != 0xFF){} // while busy
loc += 512;
}
SPI(0xFD); //stop transfer token byte

SPI(0xFF);
SPI(0xFF);
while(SPI(0xFF) != 0xFF) // while busy

CS = 1;
ADON_bit=0;
RecLED = 0;
}

works on PIC16-18 , anyway you can download my project wave player for PIC16 and include this function or migrant it to you dsPIC .hope this help,
enjoy.

  • Rating:
5
No Abuse Reported

Do you want to report abuse comment ID: 99 in "Audio recording with dsPIC & SD card!" request.

Edward L
Berek8

posted on 2011/09/15 06:55:29 PM CEST

You, my good sir, are a lifesaver. Its indeed a really interesting project, I'll analyze the code as soon as possible.

Thanks!!

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 95 in "Audio recording with dsPIC & SD card!" request.

Steven Goh
stevenindon

posted on 2011/09/14 11:00:56 PM CEST

Edware,

Interesting recording on PIC in youTube :

http://www.youtube.com/watch?v=Mn1VsM-i8QI

  • Rating:
5
No Abuse Reported

Do you want to report abuse comment ID: 92 in "Audio recording with dsPIC & SD card!" request.