Hello-
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?
Thanks!
Nora
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?
Thanks!
Nora
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.
Sheldon
#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() {
digit=0;
val = analogRead(analogPin);
Serial.print("Analog input: ");
Serial.println(val);
sprintf(cval,"%d",val);
valLen=4;
if (val<1000)valLen=3;
if (val<100) valLen=2;
if (val<10) valLen=1;
while (digit<valLen)
{
char c = cval[digit++];
Serial.print(c);
speaknum(c);
delay(10);
}
delay(3000);
}
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 {
return;
}
if (i != 0) {
filename = '.';
filename[i+1] = 'W';
filename[i+2] = 'A';
filename[i+3] = 'V';
filename[i+4] = 0;
playcomplete(filename);
}
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying);
card.close_file(f);
}
void playfile(char *name) {
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
card.close_file(f);
}
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!
wave.play();
}
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.
Sheldon
#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() {
digit=0;
val = analogRead(analogPin);
Serial.print("Analog input: ");
Serial.println(val);
sprintf(cval,"%d",val);
valLen=4;
if (val<1000)valLen=3;
if (val<100) valLen=2;
if (val<10) valLen=1;
while (digit<valLen)
{
char c = cval[digit++];
Serial.print(c);
speaknum(c);
delay(10);
}
delay(3000);
}
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 {
return;
}
if (i != 0) {
filename = '.';
filename[i+1] = 'W';
filename[i+2] = 'A';
filename[i+3] = 'V';
filename[i+4] = 0;
playcomplete(filename);
}
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying);
card.close_file(f);
}
void playfile(char *name) {
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
card.close_file(f);
}
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!
wave.play();
}
Thanks!!
So the SD card automatically rewinds? What do you use to hold the SD card?
Clearly I'm clueless...so 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.
So the SD card automatically rewinds? What do you use to hold the SD card?
Clearly I'm clueless...so 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.
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.
Sheldon
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.
Sheldon
Sheldon,
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!
Nora
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!
Nora
- Status
- Not open for further replies.