Problem with TFM music replay - distorted sound
Moderator: BigEvilCorporation
Problem with TFM music replay - distorted sound
Hi guys, new member here!
I'm looking to write some demos for the Megadrive, but I'm more of a graphics-effect type of coder, so I'm looking for a kind of a plug-and-play solution for the music.
I found Shiru's TFM Music Maker, which seemed to be a good match, an editor, lots of example music and some nice source-code example for the replayer.
I got some stuff up and running, sounded wonderfully in emulator. But then I purchased a real Megadrive console and an Everdrive MD, and when I trid my ROM, the music sounded very distorted, almost like it is being heavily clipped.
And I don't think it is an isolated problem with my code, because I tried this ready-made replayer bin
viewtopic.php?t=691
the sound was equally distorted.
Then I noticed when running the Bassfish/Speckdrumm demo that they also had the same type of sound distortion. When reading the comments at Pouet (http://pouet.net/prod.php?which=50188) everyone who had run the demo on real hardware had the same problem.
Now I'm not sure if they used TFM music in that demo, but it seems to me that there is some kind of problem with replaying chip music on the YM2612 that gives these kind of problems. In the Pouet comments someone commented that "...Sounds like what you get when you configure the FM operator "Total Level" values incorrectly."
I'm not sure if that is a clue for anyone?
Anyway, I can also say that there is no hardware problem with my console, music in games sounds just fine.
So, anyone have any ideas on how to fix this problem, either by giving tips on how to make the TFM-replay sound correct, or have any tips of other music replay routines/trackers that I could use instead? Preferably not too CPU-hungry as well!
-edit-
I just found the following in the documentation for TFM Music Maker:
"Note: do not use too low (close to zero) values for TL of slots, it can cause to distortion of sound. Acceptable range of values is 5..25, depending from how much instruments sounds at once. "
I have no idea what what "TL of slots" mean however (I don't understand music/composing at all, I just want to play the tunes!)
I am doing my testing using the example tunes included with TFM Music Maker, perhaps most of them use low "TL of slots", so that's what causing it...?
I'm looking to write some demos for the Megadrive, but I'm more of a graphics-effect type of coder, so I'm looking for a kind of a plug-and-play solution for the music.
I found Shiru's TFM Music Maker, which seemed to be a good match, an editor, lots of example music and some nice source-code example for the replayer.
I got some stuff up and running, sounded wonderfully in emulator. But then I purchased a real Megadrive console and an Everdrive MD, and when I trid my ROM, the music sounded very distorted, almost like it is being heavily clipped.
And I don't think it is an isolated problem with my code, because I tried this ready-made replayer bin
viewtopic.php?t=691
the sound was equally distorted.
Then I noticed when running the Bassfish/Speckdrumm demo that they also had the same type of sound distortion. When reading the comments at Pouet (http://pouet.net/prod.php?which=50188) everyone who had run the demo on real hardware had the same problem.
Now I'm not sure if they used TFM music in that demo, but it seems to me that there is some kind of problem with replaying chip music on the YM2612 that gives these kind of problems. In the Pouet comments someone commented that "...Sounds like what you get when you configure the FM operator "Total Level" values incorrectly."
I'm not sure if that is a clue for anyone?
Anyway, I can also say that there is no hardware problem with my console, music in games sounds just fine.
So, anyone have any ideas on how to fix this problem, either by giving tips on how to make the TFM-replay sound correct, or have any tips of other music replay routines/trackers that I could use instead? Preferably not too CPU-hungry as well!
-edit-
I just found the following in the documentation for TFM Music Maker:
"Note: do not use too low (close to zero) values for TL of slots, it can cause to distortion of sound. Acceptable range of values is 5..25, depending from how much instruments sounds at once. "
I have no idea what what "TL of slots" mean however (I don't understand music/composing at all, I just want to play the tunes!)
I am doing my testing using the example tunes included with TFM Music Maker, perhaps most of them use low "TL of slots", so that's what causing it...?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
I remember there is a bug in the TFM player code you provided Shiru, it has already been discussed somewhere but i can't find out where... I fixed the problem in the SGDK version of the player, as far i remember it was due to the way you're writing th YM registers (not checking for busy flag before).
Here's the code I'm using (straight from Shiru's example):Stef wrote:I remember there is a bug in the TFM player code you provided Shiru, it has already been discussed somewhere but i can't find out where... I fixed the problem in the SGDK version of the player, as far i remember it was due to the way you're writing th YM registers (not checking for busy flag before).
Code: Select all
inline void ym2612wr(u8 reg,u8 val,u8 bank)
{
volatile u16 *pz;
volatile u8 *pw,*pa,*pd;
u8 rg;
pz=(u16*)Z80_HALT;
*pz=0x100;
pw=(u8*)YM2612_A0;
if(!bank)
{
pa=(u8*)YM2612_A0;
pd=(u8*)YM2612_D0;
}
else
{
pa=(u8*)YM2612_A1;
pd=(u8*)YM2612_D1;
}
while(*pw&0x80);
*pa=reg;
while(*pw&0x80);
*pd=val;
*pz=0;
}
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
I now remeber the problem with your code, you're taking Z80 bus but you don't check BUS is actually taken before writing the YM registers.Shiru wrote:The player works on real HW, it is tested few times. What's the problem then?
The hardware taken sometime to switch BUS..
Here's how i modified your ym2612wr(...) method to fix the problem :
I used sgdk methods but afaik it just lacks the bus acquisition test in your code.static void ym2612wr(u8 reg,u8 val,u8 bank)
{
Z80_requestBus(1);
YM2612_writeRegSafe(bank, reg, val);
Z80_releaseBus();
}
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Actually if that does cause the sound to be distorted on real hardware sometime (maybe on some genesis model only) then it can be a problem. And someone already reported me, but it was on a MSN talk (reason why i can't found it on the forum).Shiru wrote:The fact that no one in all these years reported me about the problem ensures me that no one actually care (alternatively, it is not that important, because it works anyway), and thus I'm lazy to fix it.
Thanks, adjusting the TL 10 steps made everything sound better, and I added the Z80 wait just to be safe.
That got me thinking, if you don't have any of your own code running on the Z80, is it really necessary to do the whole stop z80/write ym/start z80 thing, can't you just stop the z80 right at the start of your code and let it be stopped?
Right now atleast I tried optimizing the player a bit by just halting the z80 once per frame, do all YM writes and then restart again. Don't know if it gained me much cycles though.
I guess the best way to free up 68000 cycles is to use the Z80-only-replayer, but I still haven't figured out how to set up the z80 part (where to place it in ROM, how to get it running etc.), so that will be a future project!
-edit-
Oh, and this whole YM2612 clipping sound affair - how come none of the emulators I tried actually emulates this? Is so little known of the inner workings of that chip?
That got me thinking, if you don't have any of your own code running on the Z80, is it really necessary to do the whole stop z80/write ym/start z80 thing, can't you just stop the z80 right at the start of your code and let it be stopped?
Right now atleast I tried optimizing the player a bit by just halting the z80 once per frame, do all YM writes and then restart again. Don't know if it gained me much cycles though.
I guess the best way to free up 68000 cycles is to use the Z80-only-replayer, but I still haven't figured out how to set up the z80 part (where to place it in ROM, how to get it running etc.), so that will be a future project!
-edit-
Oh, and this whole YM2612 clipping sound affair - how come none of the emulators I tried actually emulates this? Is so little known of the inner workings of that chip?