hello,
I'm a little stuck with how to talk to the DAC of the wave shield. specifically, i've been trying to expand the wave.hc library by a bitshift function a la setSampleRate, like so:
//------------------------------------------------------------------------------
/** Set bit rate.
*
* \param[in] bits. The nr of bits to be shifted.
*/
void WaveHC::setBitShift(uint8_t bits)
{
cli();
while (TCNT0 != 0);
if (bits > 12) {bitShift = 12; }
else {bitShift = bits;}
sei();
}
//
where bitShift is a global variable. there's a few lines in WaveHC.cpp where it talks to the DAC, which I tried to modify to shift by the value of that bitShift variable:
uint8_t dh, dl, shiftHIGH, shiftLOW;
if (playing->BitsPerSample == 16) {
if (bitShift > 4) {
shiftLOW = 8; shiftHIGH = bitShift - 4;
}
else {
shiftLOW = bitShift + 4; shiftHIGH = 0;
}
// 16-bit is signed
dh = 0X80 ^ playpos[1];
dh = dh >> shiftHIGH << shiftHIGH;
dl = playpos[0];
dl = dl >> shiftLOW << shiftLOW;
playpos += 2;
}
else {
// 8-bit is unsigned
dh = playpos[0];
dh = dh >> bitShift << bitShift;
dl = 0;
playpos++;
}
this seems to work alright (for 16 bit files), but only for values of bitShift up to 7. I guess I'm not really understanding how the low/high bit coding scheme actually works. I was assuming that if you wanted to bitshift playpos by, say, 10 bits, you'd have to shift the high bits by 8 (dh), and then the low bits by 2 (dl), so that you'd still send two bits to the DAC, but this isn't what's happening, the DAC just turns silent.
anyone has got an understanding of this?
many thanks

