I think I have overcome the problem.
the problem is the library, this is program to change volume in original library:
Code: Select all
#if DVOLUME
uint16_t tmp = (dh << 8) | dl;
tmp >>= playing->volume;
dh = tmp >> 8;
dl = tmp;
#endif //DVOLUME
the wave sound in my project is traditional instrument sound, and the data that i test if I'm not mistaken is in c note with 12 seconds duration. in analog domain we expected that the soundwave will sing in 0 value right?but in digital domain with tmp is declared with unsigned int, the wave will not swing in 0 value, So I modify the program like this
Code: Select all
#if DVOLUME
uint16_t tmp = (dh << 8) | dl;
tmp >>= playing->volume;
playing->tmp_x=tmp;
dh = tmp >> 8;
dl = tmp;
#endif //DVOLUME
I create variabel tmp_x so i can read the wave data value in serial monitor. and I set the wave.volume equal to 0
and finally the tmp_x value in serial monitor tell me that the data swing in 0x8000, its logical because 0x8000 is the half value of 65536 (16 bit).
the problem with the original program in library is when i want to decrease the volume, for example I change the wave.volume to 2, that means the sound data will not swing in 0x8000 anymore, but in 0x4000, so that's why the offset is exist.
And this is the modified program in waveHC.cpp to solve the offset, and now the annoying "pop" is gone :) :
Code: Select all
#if DVOLUME
uint16_t tmp = (dh << 8) | dl;
tmp= (tmp>>(playing->volume)) + 0x8000 - (0x8000>>(playing->volume));
playing->tmp_x=tmp;
dh = tmp >> 8;
dl = tmp;
#endif //DVOLUME
But theres still one problem: increasing wave.volume will make the frequency of wave sound increasing too. So to the original c note of my wave file, will not c anymore if i increase wave.volume.
Maybe you have any idea about this?
anyway, thanks for your reply.