Here you can see three functions which all playback the sound samples, just in different ways...
playback(); plays back a sample forwards.
playback_r(); plays the sample backwards.
playback_s(); plays the sample forward but at a reduced speed.
void playback(prog_uchar *sample_ptr, unsigned int length) {
unsigned char bite; int col; col = 0; int i;
for(i=0;i<length;i++){
bite = pgm_read_byte_near(sample_ptr + i);
unsigned char mask = 1; unsigned char copy = bite; int z;
for (z=0;z<8;z++) {
digitalWrite(SPK_PIN, copy & mask);
copy = copy >> 1;
delayMicroseconds(25);
}
}
}
void playback_r(prog_uchar *sample_ptr, unsigned int length) {
unsigned char bite; int col; col = 0; int i;
for(i=0;i<length;i++){
bite = pgm_read_byte_near(sample_ptr + length - i);
unsigned char mask = 1; unsigned char copy = bite; int z;
for (z=0;z<8;z++) {
digitalWrite(SPK_PIN, copy & mask);
copy = copy >> 1;
delayMicroseconds(25);
}
}
}
void playback_s(prog_uchar *sample_ptr, unsigned int length,unsigned int speed) {
unsigned char bite; int col; col = 0; int i;
for(i=0;i<length;i++){
bite = pgm_read_byte_near(sample_ptr + length - i);
unsigned char mask = 1; unsigned char copy = bite; int z;
for (z=0;z<8;z++) {
digitalWrite(SPK_PIN, copy & mask);
copy = copy >> 1;
delayMicroseconds(25*speed);
}
}
}
By mixing up and fooling around with chopping up the samples, I was able to create some interesting variations with just the 4 basic samples that I started with.
int z;
for (z = 0; z < 4; z++){
playback(onebitraw_1, BC_BYTE_COUNT_1 /4);
playback(onebitraw_2 + (BC_BYTE_COUNT_1 /4), BC_BYTE_COUNT_1 /4);
playback_r(onebitraw_3 + (BC_BYTE_COUNT_1 /2), BC_BYTE_COUNT_1 /4);
playback(onebitraw_2 + ((BC_BYTE_COUNT_1 /4) + (BC_BYTE_COUNT_1 /2)) , BC_BYTE_COUNT_1 /4);
}
That code block allowed me to cut up the samples, maintain quantization and make the pattern far more interesting.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.