Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
uyjulian committed Jan 31, 2015
1 parent 360948a commit 71b5e02
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
11 changes: 5 additions & 6 deletions emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,17 @@ void SPC_READ_DSP()
}

void SPC_WRITE_DSP()
{

s32 i;
{
s32 addr_lo = SPC_DSP_ADDR & 0xF, addr_hi = SPC_DSP_ADDR >> 4;
switch (addr_lo)
{
case 3: // Pitch hi
SPC_DSP_DATA &= 0x3F;
break;
case 5: // ADSR1
if ((SNDkeys & (1 << addr_hi)) && ((SPC_DSP_DATA & 0x80) != (SPC_DSP[SPC_DSP_ADDR] & 0x80)))
if ((SPC_DSP[0x4C] & (1 << addr_hi)) && ((SPC_DSP_DATA & 0x80) != (SPC_DSP[SPC_DSP_ADDR] & 0x80)))
{
s32 i;
// First of all, in case anything was already
// going on, finish it up
SNDDoEnv(addr_hi);
Expand Down Expand Up @@ -174,7 +173,7 @@ void SPC_WRITE_DSP()
SNDvoices[addr_hi].sl = SPC_DSP_DATA >> 5;
break;
case 7: // GAIN
if ((SNDkeys & (1 << addr_hi)) && (SPC_DSP_DATA != SPC_DSP[SPC_DSP_ADDR]) &&
if ((SPC_DSP[0x4C] & (1 << addr_hi)) && (SPC_DSP_DATA != SPC_DSP[SPC_DSP_ADDR]) &&
!(SPC_DSP[(addr_hi << 4) + 5] & 0x80))
{
if (SPC_DSP_DATA & 0x80)
Expand All @@ -197,7 +196,7 @@ void SPC_WRITE_DSP()
{
case 4: // Key on
SNDNoteOn(SPC_DSP_DATA);
SPC_DSP_DATA = SNDkeys;
SPC_DSP_DATA = SPC_DSP[0x4C];
break;
case 5: // Key off
SNDNoteOff(SPC_DSP_DATA);
Expand Down
14 changes: 7 additions & 7 deletions it.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ static s32 ITDecodeSample(u16 start, sndsamp **sp)
u16 end;
u32 brrptr, sampptr = 0;
s32 i;
u8 range, filter, shift_amount;
src = &SPCRAM[start];
for (end = 0; !(src[end] & 1); end += 9)
;
Expand All @@ -108,9 +107,9 @@ static s32 ITDecodeSample(u16 start, sndsamp **sp)
s->loopto = 0;
for (brrptr = 0; brrptr <= end;)
{
range = src[brrptr++];
filter = (range & 0x0c) >> 2;
shift_amount = (range >> 4) & 0x0F;
u8 range = src[brrptr++];
u8 filter = (range & 0x0c) >> 2;
u8 shift_amount = (range >> 4) & 0x0F;
for (i = 0; i < 8; i++, brrptr++)
{
ITDecodeSampleInternal(src[brrptr] >> 4, shift_amount, filter); // Decode high nybble
Expand Down Expand Up @@ -151,7 +150,7 @@ static s32 ITPitchToNote(s32 pitch, s32 base)
else if (tmp < 0)
tmp = 0;
note = (s32)tmp;
if ((s32)(tmp * 2) != (note << 1))
if ((s32)(tmp * 2) != (note * 2))
note++; // correct rounding
return note;
}
Expand Down Expand Up @@ -453,12 +452,13 @@ void ITMix()
u8 mastervolume = SPC_DSP[0x0C];
for (voice = 0; voice < 8; voice++)
{
if ((SNDkeys & (1 << voice)))
if ((SPC_DSP[0x4C] & (1 << voice))) // 0x4C == key on
{
envx = SNDDoEnv(voice);
//envx = SPC_DSP[0x08];
lvol = (envx >> 24) * (s32)((s8)SPC_DSP[(voice << 4) ]) * mastervolume >> 14; // Ext
rvol = (envx >> 24) * (s32)((s8)SPC_DSP[(voice << 4) + 0x01]) * mastervolume >> 14; // Ext
// Volume no echo: (s32)((s8)SPC_DSP[(voice << 4) ]) * mastervolume >> 7;


pitch = (s32)(*(u16 *)&SPC_DSP[(voice << 4) + 0x02]) * 7.8125; // Pointer hell?
// adjust for negative volumes
Expand Down
24 changes: 12 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,40 @@ int main(int argc, char **argv)
{
size_t u8Size = sizeof(u8);
if (!(u8Size == 1))
printf("Warning: wrong size u8: %lu \n", u8Size);
printf("Warning: wrong size u8: %zu \n", u8Size);
size_t u16Size = sizeof(u16);
if (!(u16Size == 2))
printf("Warning: wrong size u16: %lu \n", u16Size);
printf("Warning: wrong size u16: %zu \n", u16Size);
size_t u32Size = sizeof(u32);
if (!(u32Size == 4))
printf("Warning: wrong size u32: %lu \n", u32Size);
printf("Warning: wrong size u32: %zu \n", u32Size);
size_t u64Size = sizeof(u64);
if (!(u64Size == 8))
printf("Warning: wrong size u64: %lu \n", u64Size);
printf("Warning: wrong size u64: %zu \n", u64Size);
size_t s8Size = sizeof(s8);
if (!(s8Size == 1))
printf("Warning: wrong size s8: %lu \n", s8Size);
printf("Warning: wrong size s8: %zu \n", s8Size);
size_t s16Size = sizeof(s16);
if (!(s16Size == 2))
printf("Warning: wrong size s16: %lu \n", s16Size);
printf("Warning: wrong size s16: %zu \n", s16Size);
size_t s32Size = sizeof(s32);
if (!(s32Size == 4))
printf("Warning: wrong size s32: %lu \n", s32Size);
printf("Warning: wrong size s32: %zu \n", s32Size);
size_t s64Size = sizeof(s64);
if (!(s64Size == 8))
printf("Warning: wrong size s64: %lu \n", s64Size);
printf("Warning: wrong size s64: %zu \n", s64Size);
size_t ITFileHeaderSize = sizeof(ITFileHeader);
if (!(ITFileHeaderSize == 192))
printf("Warning: wrong size ITFileHeader: %lu \n", ITFileHeaderSize);
printf("Warning: wrong size ITFileHeader: %zu \n", ITFileHeaderSize);
size_t ITFileSampleSize = sizeof(ITFileSample);
if (!(ITFileSampleSize == 80))
printf("Warning: wrong size ITFileSample: %lu \n", ITFileSampleSize);
printf("Warning: wrong size ITFileSample: %zu \n", ITFileSampleSize);
size_t ITFilePatternSize = sizeof(ITFilePattern);
if (!(ITFilePatternSize == 8))
printf("Warning: wrong size ITFilePattern: %lu \n", ITFilePatternSize);
printf("Warning: wrong size ITFilePattern: %zu \n", ITFilePatternSize);
size_t SPCFileSize = sizeof(SPCFile);
if (!(SPCFileSize == 65920))
printf("Warning: wrong size SPCFile: %lu \n", SPCFileSize);
printf("Warning: wrong size SPCFile: %zu \n", SPCFileSize);
s32 seconds, limit, ITrows;
char fn[PATH_MAX];
s32 i;
Expand Down
11 changes: 5 additions & 6 deletions sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "sound.h"

sndvoice SNDvoices[8];
s32 SNDkeys, SNDratecnt;
s32 SNDratecnt;

static const u32 C[0x20] = {
0x0, 0x20000, 0x18000, 0x14000, 0x10000, 0xC000, 0xA000, 0x8000, 0x6000, 0x5000, 0x4000,
Expand All @@ -23,11 +23,11 @@ static const u32 C[0x20] = {

s32 SNDDoEnv(s32 voice)
{
u32 envx, cyc, c;
u32 envx, c;
envx = SNDvoices[voice].envx;
for (;;)
{
cyc = TotalCycles - SNDvoices[voice].envcyc;
u32 cyc = TotalCycles - SNDvoices[voice].envcyc;
switch (SNDvoices[voice].envstate)
{
case ATTACK:
Expand Down Expand Up @@ -104,7 +104,7 @@ s32 SNDDoEnv(s32 voice)
envx -= 0x800000; // sub 1/256th
if ((envx == 0) || (envx > 0x7F000000))
{
SNDkeys &= ~(1 << voice);
SPC_DSP[0x4C] &= ~(1 << voice);
return SNDvoices[voice].envx = 0;
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ void SNDNoteOn(u8 v)
cursamp = SPC_DSP[4 + (i << 4)];
if (cursamp < 512)
{
SNDkeys |= (1 << i);
SPC_DSP[0x4C] |= (1 << i);
// figure ADSR/GAIN
adsr1 = SPC_DSP[(i << 4) + 5];
if (adsr1 & 0x80)
Expand Down Expand Up @@ -257,7 +257,6 @@ void SNDNoteOff(u8 v)
s32 SNDInit()
{
s32 i;
SNDkeys = 0;
for (i = 0; i < 8; i++)
SNDvoices[i].envx = 0;
return (0);
Expand Down

0 comments on commit 71b5e02

Please sign in to comment.