how to store sound

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello I am playing around with sound, the set up is atmega 16 pin A0 connected to a microphone. I would like to record few seconds of sound and store it on the microcontroller. I tried creating a large array but the compiler (codevisionavr) gives me the following error "Linker error: global RAM variables size: 10002 bytes is too large". What is the best way to record and store sound ?? Also how fast should the ADC run so I can store few seconds and then play it back using PWM at audible quality?

Thank you in advance for your help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.atmel.com/dyn/resourc...

I would follow that application note and use a dataflash to store the sound. I tried using that application note and found that the LM324 filters did not work (never found out why...) and the LM324 is not a good amplifier to drive a speaker.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be honest, before you get the filter/amplifier worked out I found that simply hanging an 8ohm speaker off the OC1A pin was enough to hear something sensible. It's true that using V=IR or rather I=V/R suggests that it's far too much current for an AVR port pin - but for a prototype where you don't mind damaging the AVR chip it works. Put a plastic cup over the speaker to make a resonant chamber which will "amplify" things greatly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a mega1280 with 8k of ram. That will give you one second of recording time. Enough to say "Hello!" in the mic.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been able to play notes using PWM and a small speaker i found in my pile of junk, its 30 ohm, the avr pin is fine. I am new to external memory. Would an nv sram DS1230 256k work to store sound? 32,768 words by 8 bits, so sampling 16000 times a second 8 bit resolution would only give me 2 seconds right?. How many times a second should the adc run for audible quality, and is it better to use 16bit?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Speech/Phone quality is 4khz bandwidth, 8khz sample rate. The minimum for music might be 12khz bw, 24khz sample rate, 10 or 12 bit samples. This isnt as good as cd quality, which uses 22khz bw, 44.1khz sample rate, 16bit samples, and 2 channels. That's 10 megabytes per minute. I record a bunch of words on the pc, then convert to 8khz 8 bit, and run a utility to convert the wav file to a c array. Then you can compile a couple dozen words into a flash rom. Makes a talking clock or meter of some sort.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've played some Frank Sinatra using an 8bit, 7.2kHz sample rate. Seemed perfectly acceptable to these tired old ears but then I don't claim to be a bat!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you listen to muzak over the phone, you dont get anything above 4khz because of the codecs etc, so a jazz trio with piano, bass, and sizzler cymbal might not get much cymbal... its all above 4k. I claim speech is tough at 8 bits without some automatic gain control before the a/d. I usually record at 10 bits then normalize to 8 bits. If 1% of the samples or so are banging into full scale without wrapping around, it still doesnt sound too bad.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is not a secret can you tell me what utility you use to convert wav into an array. I will try just playing audible sound first, once i get some external memory ill get to recording.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Luco wrote:
If it is not a secret can you tell me what utility you use to convert wav into an array. I will try just playing audible sound first, once i get some external memory ill get to recording.

I really like sox for converting to/from different audio formats.
http://sox.sourceforge.net/

To convert a binary image to a c-style array try using
xxd -i (part of the vim distribution) Learned that nice tip from clawson.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't laugh.

//file pcm2c.c

#include 
#include 
#include 
#include 

FILE * ifil;
FILE * ofil;
char ofilnam[20];
char ifilnam[20];

//-----------------------
void main (int argc, char * argv[]){
unsigned char b,n;

  printf("pcm2c  read 8 bit pcm, write to c   June 1 07 Bob G\n");
  if(argc != 3){
    printf("usage: pcm2c foo.pcm foo.c\n");
    exit(1);
  }
  strcpy(ifilnam,argv[1]);
  ifil=fopen(ifilnam,"rb");

  strcpy(ofilnam,argv[2]);
  ofil=fopen(ofilnam,"w");

  fprintf(ofil,"const char dat[]={\n");
  while(1){
    for(n=0; n<16; n++){
      fread(&b,1,sizeof(b),ifil);
      fprintf(ofil,"0x%02x,",b);
      if(feof(ifil)) break;
    }
    fprintf(ofil,"\n");
    if(feof(ifil)) break;
  }
  fprintf(ofil,"\n};\n");
  fclose(ifil);
  fclose(ofil);
}
//------eof------------


Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

To convert a binary image to a c-style array try using
xxd -i (part of the vim distribution) Learned that nice tip from clawson.

xxd (in the win32 .exe form) is a utility that ships as part of the Vim package - you can get it here:

http://www.vim.org/download.php#pc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all :)

So here is what I did, converted wav to wav rate 8000, 1 channel, 8 bits. Used bobgardner's code (THANK YOU) to convert it into an array. Google a lot, tried connecting PWM directly to speaker got screechy noise. Realized I dont have any parts. Used a simulator and R-2R design.

Attached is the circuit and the output waveform from the simulator. The first half of the waveform is "CLAP CLAP clap CLAPCLAP" and the second is "AAAAAAAAAA".

With the claping and aaaaing i've filled up 73.9% of flash. So i think 3 seconds of sound will fit.

I am wondering about the parts I should order.
I don't know anything about speakers or how to pick one out. The Op-AMP in the simulator is ideal. If any places give away free samples that would be great :).

Attachment(s):