Index: apps/plugins/rockboy/sound.c =================================================================== --- apps/plugins/rockboy/sound.c (revision 13720) +++ apps/plugins/rockboy/sound.c (working copy) @@ -52,6 +52,9 @@ #define S3 (snd.ch[2]) #define S4 (snd.ch[3]) +#define SOUND_MAGIC 0x60000000 +#define SOUND_MAGIC_2 0x30000000 + static void s1_freq_d(int d) { if (RATE > (d<<4)) S1.freq = 0; @@ -72,8 +75,8 @@ static void s3_freq(void) { - int d = 2048 - (((R_NR34&7)<<8) + R_NR33); - if (RATE > (d<<3)) S3.freq = 0; + int d = 2048 - (((R_NR34&7)<<8) | R_NR33); + if (RATE > d) S3.freq = 0; else S3.freq = (RATE << 21)/d; } @@ -110,9 +113,10 @@ void sound_off(void) { - memset(&snd, 0, sizeof snd); - if (pcm.hz) snd.rate = (1<<21) / pcm.hz; - else snd.rate = 0; + memset(&S1, 0, sizeof S1); + memset(&S2, 0, sizeof S2); + memset(&S3, 0, sizeof S3); + memset(&S4, 0, sizeof S4); R_NR10 = 0x80; R_NR11 = 0xBF; R_NR12 = 0xF3; @@ -122,7 +126,7 @@ R_NR24 = 0xBF; R_NR30 = 0x7F; R_NR31 = 0xFF; - R_NR32 = 0x9F; + R_NR32 = 0xBF; R_NR34 = 0xBF; R_NR41 = 0xFF; R_NR42 = 0x00; @@ -130,15 +134,18 @@ R_NR44 = 0xBF; R_NR50 = 0x77; R_NR51 = 0xF3; - R_NR52 = 0x70; -// for (i = 0; i < 16; i++) WAVE[i] = -(i&1); + R_NR52 = 0xF0; sound_dirty(); } void sound_reset() { memset(&snd, 0, sizeof snd); - if (pcm.hz) snd.rate = (1<<21) / pcm.hz; + if (pcm.hz) + { + snd.rate = (1<<21) / pcm.hz; + snd.quality=44100/pcm.hz; + } else snd.rate = 0; memcpy(WAVE, hw.cgb ? cgbwave : dmgwave, 16); memcpy(ram.hi+0x30, WAVE, 16); @@ -209,19 +216,41 @@ if (R_NR51 & 32) l += s; } - if (S3.on) + if (S3.on && S3.len) { - s = WAVE[(S3.pos>>22) & 15]; - if (S3.pos & (1<<21)) s &= 15; - else s >>= 4; + S3.pos += S3.skip*snd.quality; + S3.pos &= 0x1fffffff; + s=ram.hi[0x30 + (S3.pos>>25)]; + if (S3.pos & (1<<21)) + s &= 0x0f; + else + s >>= 4; + s -= 8; - S3.pos += S3.freq; + if ((R_NR34 & 64) && ((S3.cnt += RATE) >= S3.len)) S3.on = 0; if (R_NR32 & 96) s <<= (3 - ((R_NR32>>5)&3)); else s = 0; if (R_NR51 & 4) r += s; if (R_NR51 & 64) l += s; +/* + int value = sound3Last; + + if(sound3On && (sound3ATL || !sound3Continue)) { + sound3Index += soundQuality*sound3Skip; + sound3Index &= 0x1fffffff; + + value = gbMemory[0xff30 + (sound3Index>>25)]; + + if( (sound3Index & 0x01000000)) { + value &= 0x0f; + } else { + value >>= 4; + } + + value -= 8; +*/ } if (S4.on) @@ -335,110 +364,108 @@ if(!options.sound) return; if (!(R_NR52 & 128) && r != RI_NR52) return; - if ((r & 0xF0) == 0x30) - { - if (S3.on) sound_mix(); - if (!S3.on) - WAVE[r-0x30] = ram.hi[r] = b; - return; - } + ram.hi[r]=b; sound_mix(); + switch (r) { case RI_NR10: - R_NR10 = b; S1.swlen = ((R_NR10>>4) & 7) << 14; S1.swfreq = ((R_NR14&7)<<8) + R_NR13; break; case RI_NR11: - R_NR11 = b; S1.len = (64-(R_NR11&63)) << 13; break; case RI_NR12: - R_NR12 = b; S1.envol = R_NR12 >> 4; S1.endir = (R_NR12>>3) & 1; S1.endir |= S1.endir - 1; S1.enlen = (R_NR12 & 7) << 15; break; case RI_NR13: - R_NR13 = b; s1_freq(); break; case RI_NR14: - R_NR14 = b; s1_freq(); if (b & 128) s1_init(); break; case RI_NR21: - R_NR21 = b; S2.len = (64-(R_NR21&63)) << 13; break; case RI_NR22: - R_NR22 = b; S2.envol = R_NR22 >> 4; S2.endir = (R_NR22>>3) & 1; S2.endir |= S2.endir - 1; S2.enlen = (R_NR22 & 7) << 15; break; case RI_NR23: - R_NR23 = b; s2_freq(); break; case RI_NR24: - R_NR24 = b; s2_freq(); if (b & 128) s2_init(); break; case RI_NR30: - R_NR30 = b; - if (!(b & 128)) S3.on = 0; + if (!(b & 0x80)){ + R_NR52 &= 0xfb; + S3.on = 0; + } break; case RI_NR31: - R_NR31 = b; - S3.len = (256-R_NR31) << 13; + S3.len = (256-R_NR31) * 172; break; case RI_NR32: - R_NR32 = b; break; case RI_NR33: - R_NR33 = b; - s3_freq(); + S3.freq = 2048 - (((int)(R_NR34&7) << 8) | b); + if(S3.freq) + S3.skip = SOUND_MAGIC_2 / S3.freq; + else + S3.skip = 0; break; case RI_NR34: - R_NR34 = b; - s3_freq(); - if (b & 128) s3_init(); + S3.freq = 2048 - (((b&7)<<8) | R_NR33); + + if(S3.freq) + S3.skip = SOUND_MAGIC_2 / S3.freq; + else + S3.skip = 0; + + if((b & 0x80) && (R_NR30 & 0x80)) + { + R_NR52 |= 4; + S3.len = 172 * (256 - R_NR31); + S3.pos = 0; + S3.on = 1; + } break; case RI_NR41: - R_NR41 = b; S4.len = (64-(R_NR41&63)) << 13; break; case RI_NR42: - R_NR42 = b; S4.envol = R_NR42 >> 4; S4.endir = (R_NR42>>3) & 1; S4.endir |= S4.endir - 1; S4.enlen = (R_NR42 & 7) << 15; break; case RI_NR43: - R_NR43 = b; s4_freq(); break; case RI_NR44: - R_NR44 = b; if (b & 128) s4_init(); break; case RI_NR50: - R_NR50 = b; break; case RI_NR51: - R_NR51 = b; break; case RI_NR52: - R_NR52 = b; - if (!(R_NR52 & 128)) - sound_off(); + if (!(b & 0x80)) + { + S1.on=0; + S2.on=0; + S3.on=0; + S4.on=0; + } break; default: return; Index: apps/plugins/rockboy/sound.h =================================================================== --- apps/plugins/rockboy/sound.h (revision 13720) +++ apps/plugins/rockboy/sound.h (working copy) @@ -10,6 +10,7 @@ int cnt, encnt, swcnt; int len, enlen, swlen; int swfreq; + int skip; int freq; int envol, endir; }; @@ -17,6 +18,7 @@ struct snd { int rate; + int quality; struct sndchan ch[4]; }; Index: apps/plugins/rockboy/rbsound.c =================================================================== --- apps/plugins/rockboy/rbsound.c (revision 13720) +++ apps/plugins/rockboy/rbsound.c (working copy) @@ -12,13 +12,14 @@ bool doneplay=1; bool bufnum=0; -static unsigned short *buf=0; +static unsigned short *buf=0, *hwbuf=0; static bool newly_started; void get_more(unsigned char** start, size_t* size) { - *start = (unsigned char*)(&buf[pcm.len*doneplay]); + memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short)); + *start = (unsigned char*)(hwbuf); *size = BUF_SIZE*sizeof(short); doneplay=1; } @@ -29,14 +30,20 @@ return; newly_started = true; - + +#if defined(HW_HAVE_11) + pcm.hz = SAMPR_11; +#else pcm.hz = SAMPR_44; +#endif + pcm.stereo = 1; pcm.len = BUF_SIZE; if(!buf) { buf = my_malloc(pcm.len * N_BUFS *sizeof(short)); + hwbuf = my_malloc(pcm.len *sizeof(short)); pcm.buf = buf; pcm.pos = 0;