Need storage source for 1 sec sound - diyAudio
Go Back   Home > Forums > Source & Line > Digital Source
Home Forums Rules Articles diyAudio Store Gallery Wiki Blogs Register Donations FAQ Calendar Search Today's Posts Mark Forums Read

Digital Source Digital Players and Recorders: CD , SACD , Tape, Memory Card, etc.

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Thread Tools Search this Thread
Old 23rd June 2011, 08:59 PM   #1
Nora is offline Nora  United States
diyAudio Member
Join Date: Jan 2006
Location: New York
Default Need storage source for 1 sec sound

I am running a bass heartbeat noise through a self-contained amplifier/subwoofer. The speed of the heartbeat sound is directly related to the person whom the heartbeat belongs to.
I want to store "lub-dub" and play it back faster or slower.
To me, this means that the lub-dub noise needs to play then instantly rewind, then play again. In addition, the output needs to be in the 2-5V range.
I have been working with Birthday card type recordable sound cards, but the output is too quiet and quality is not good.

The control system/electronics are an embedded board which I am designing.
Does anyone have any recommendations or advice?
  Reply With Quote
Old 23rd June 2011, 09:16 PM   #2
diyAudio Member
stokessd's Avatar
Join Date: Nov 2002
Location: Grantham, NH
I've done what you want to do with an arduino an SD card and a simple I2C dac chip. My little code speaks the value of the analog input. I pre-recorded the sounds for the numbers 0-9 and ".", and then the program just sends them out one at a time. The only logic is selecting the correct file to spit based on each digit of the reading. What you want to do is similar, but you'd change the delay rather than which file is being sent.

The arduino is overkill for what you want to do. I bet you could do the whole thing with a pic micro including a PWM DAC output.


#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#include <Stdio.h>

AF_Wave card;
File f;
Wavefile wave; // only one!

int valLen= 0;
int digit = 0;
int val = 0;
int analogPin = 0;
char cval[4];

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Analog Input speaker");

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;

void loop() {

val = analogRead(analogPin);

Serial.print("Analog input: ");


if (val<1000)valLen=3;
if (val<100) valLen=2;
if (val<10) valLen=1;

while (digit<valLen)

char c = cval[digit++];





char filename[13];
void speaknum(char c) {
uint8_t i=0;

if (c <= '9' && c >= '0') {
// single digit
filename[0] = c;
i = 1;
} else if (c == '.') {
filename[0] = 'P';
i = 1;
} else {

if (i != 0) {
filename[i] = '.';
filename[i+1] = 'W';
filename[i+2] = 'A';
filename[i+3] = 'V';
filename[i+4] = 0;


void playcomplete(char *name) {
while (wave.isplaying);

void playfile(char *name) {
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
f = card.open_file(name);
if (!f) {
putstring("Couldn't open file "); Serial.print(name); return;
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
// ok time to play!;
  Reply With Quote
Old 23rd June 2011, 09:24 PM   #3
Nora is offline Nora  United States
diyAudio Member
Join Date: Jan 2006
Location: New York
So the SD card automatically rewinds? What do you use to hold the SD card?
Clearly I'm details are appreciated!!
I'm going to use a PIC, there's a bunch of other stuff in this circuit and I'm not so used to Arduino.
  Reply With Quote
Old 23rd June 2011, 09:29 PM   #4
diyAudio Member
stokessd's Avatar
Join Date: Nov 2002
Location: Grantham, NH
Arduino is just a bootloader for one line of the atmega uC's. IT provides an easy means of noodling around with them. It's aimed at less technical folks what normally work in the embedded world.

It's been a long time since I worked with Pic's. But I thought that there was some eeprom type memory that you could fill with your waveform. If you are doing low frequency stuff, you can sample slowly (like 500 Hz or so), and then use your code to read a sample from memory and set the output PWM duty cycle. Rince repeat until you reach the end of your beat. Then you wait and repeat. The routine that reads and outputs the beat would always start at the beginning of the memory space where you stuck the samples, and output "N" samples. So your program would play a beat, pause for your input duration, then repeat.

  Reply With Quote
Old 24th June 2011, 10:33 AM   #5
Nora is offline Nora  United States
diyAudio Member
Join Date: Jan 2006
Location: New York
That is a really good idea. I did a project once where I stored the sound in an external eeprom and played it back through a external DAC. It would be great to store in internal eeprom and play back through PWM.
Thank you!
  Reply With Quote


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sound point-source models - theory Dave Jones Software Tools 6 29th November 2010 11:15 PM
Sound card as source, two different monoblock amps. beerman Chip Amps 4 17th March 2007 07:05 PM
Analog sound from Digital source. Possible? Extreme_Boky Digital Source 36 9th August 2005 07:24 AM
Best sec.voltage for my GC? gorko1 Chip Amps 0 31st January 2004 09:38 AM

New To Site? Need Help?

All times are GMT. The time now is 04:27 PM.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Copyright 1999-2017 diyAudio

Content Relevant URLs by vBSEO 3.3.2