Lidnariq's simple music format visualizations

Discussion of development of software for any "obsolete" computer or video game system.
Post Reply
lidnariq
Posts: 9034
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Lidnariq's simple music format visualizations

Post by lidnariq » Wed Feb 05, 2020 9:48 pm

This is first just going to be a set of screen shots. If I get some interest I'll clean up and share the source. At the very least, gbsplay needs some kind of under-the-hood fixes if I've going to share my version.

All of these are terminal-only.

For these three, I've highlighted my changes relative to the original UI in red:
NSF: (modified nosefart-2.9)
nosefart-ss5b-or-vrc6.png
nosefart-ss5b-or-vrc6.png (3.18 KiB) Viewed 645 times
GBS: (modified gbsplay-0.0.93)
gbsplay-mm2.png
gbsplay-mm2.png (1.79 KiB) Viewed 645 times
GSF: (modified playgsf-0.7.1)
playgsf-cvhod.png
playgsf-cvhod.png (2.35 KiB) Viewed 645 times
2SF: (modified vio2play-4)
YEAE-0002.png
YEAE-0002.png (3.05 KiB) Viewed 645 times
My current prototype abuses unicode to be able to draw things more precisely than the character cell (U+2588 through U+258F). Red and green bars are instantaneous left/right linear volume, cyan square is pitch, although for samples it's only a relative indication instead of absolute. PSG duty is drawn using U+2580, U+2584, and U+259E. Play and stop icons are U+25B6 and U+25A0, instead of the preferred code points (U+23F5 and U+23F9) because my terminal didn't draw those correctly.

User avatar
Memblers
Site Admin
Posts: 3786
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Lidnariq's simple music format visualizations

Post by Memblers » Fri Feb 07, 2020 2:19 am

I would be interested in the NSF visualization, I'm assuming this is C/stdio. It's a feature I want in my (remote streaming) NSF player, but coding the visualizations is too much of a side-quest for me, at this point. So that's kind of awesome, if it could work for that.

lidnariq
Posts: 9034
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Lidnariq's simple music format visualizations

Post by lidnariq » Fri Feb 07, 2020 7:47 pm

The majority of the visualization for the NSF/GBS/GSF players is this code:

Code: Select all

void PERIOD_TO_NOTATION(unsigned period) {
	const char notenames[12][3]={"C-","C#","D-","D#","E-","F-","F#","G-","G#","A-","A#","B-"};
	double pitch = 1200*log(39375000.0 / 44 / period / 440 )/log(2); // assume A4 = A440.
	int semitones = floor( (pitch + 50) / 100);
	int cents = pitch - (semitones * 100);
	int octave = (semitones + 60 - 3) / 12;
	int notenameindex = (semitones + 120 - 3) % 12;

	if (octave > 9) {
		fprintf(stdout," -high-");
	} else if (octave < 0) {
		fprintf(stdout," -low- ");
	} else {
		fprintf(stdout," %2s%1d%+03d",notenames[notenameindex],octave,cents);
	}
                                          }
Important things to change for other playback engines and/or systems:
* If you don't want 12TET A440=A4, change "440"(pitch), "60"(octave), and "-3" (octave and notenameindex). E.g. C5=C512 would change those numbers to "512", "60" and "+0".
* If you're working with a different hardware that's not an NTSC NES, change 39375000.0 / 44. (e.g. 2SF PSG sounds are (float)(1<<22))

Nosefart is a terrible playback engine, with aliasing, no support for multi-expansion sound, and a slew of other more subtle problems. But it's the one I found a decade ago with a CLI version, so it's what I hacked.

I just wanted to get this code fragment out more nearly quickly; I'll still release two patches against nosefart-2.9-mls to add (crappy, square wave only) YM2149 support and my visualizations.

User avatar
Memblers
Site Admin
Posts: 3786
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Lidnariq's simple music format visualizations

Post by Memblers » Sat Feb 08, 2020 6:30 am

Thanks! I was able to get it working. It's pretty neat having the cents displayed. I had try Drac's Night Out, that always sounded weirdly off, like a tape player with dying batteries. Most of the notes are 40 cents off.
Attachments
remote-nsf2.gif

lidnariq
Posts: 9034
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Lidnariq's simple music format visualizations

Post by lidnariq » Sat Feb 08, 2020 11:17 am

Memblers wrote:
Sat Feb 08, 2020 6:30 am
Drac's Night Out, that always sounded weirdly off, like a tape player with dying batteries. Most of the notes are 40 cents off.
Worse than that, any given note is all over the place from 20 cents detuned up to 60. Almost makes me wonder if it's not written for 12TET at all.
[screenshot:
Pulse 0 -low- #####
Pulse 1 -low- #####
Triangle A-7+01###############
Noise 3
Those look ... off? Shouldn't be possible for the pulse channels to sound below A-1, nevermind C-0.
Nosefart stores the raw period values as 16.16 fixed point in the "freq" element in the struct, so I have
PERIOD_TO_NOTATION(apu->rectangle[ii].freq >> 13);
and
PERIOD_TO_NOTATION(apu->triangle.freq >> 12);
elsewhere in my code.

User avatar
Memblers
Site Admin
Posts: 3786
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Lidnariq's simple music format visualizations

Post by Memblers » Sat Feb 08, 2020 4:46 pm

I think -low- showing up there is specific to Capcom stuff, setting the frequency to zero to silence the channel. The octaves do seem to be 3 higher than expected, compared to what I had in my NES/SNES visualizer (and assuming that was correct). So I started left-shifting the period 3 times (after recording the image I posted).

edit: Genghis Khan is another game with a lot of interesting tuning, it's a really good soundtrack too.

lidnariq
Posts: 9034
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Lidnariq's simple music format visualizations

Post by lidnariq » Sat Feb 08, 2020 6:31 pm

But nosefart's "freq" isn't a frequency, it's the period times 65536. "high" should show up, not "low", if the 2A03 wrote 0.

A-0 and A-1 should show up in triangle and pulse channels in the emulated 2A03 wrote $7FF.

User avatar
Memblers
Site Admin
Posts: 3786
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Lidnariq's simple music format visualizations

Post by Memblers » Sat Feb 08, 2020 7:28 pm

When I pass it $7FF for the pulse channel, it prints A-4. Giving it $7FF << 3 has it print A-1. As long as there's no side-effect to doing that, it seems good.

lidnariq
Posts: 9034
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Lidnariq's simple music format visualizations

Post by lidnariq » Sat Feb 08, 2020 8:31 pm

Yeah, that's right. My code fragment assumes the default APU base clock (895kHz), so pulse periods need to multiplied by 8, and triangle by 16 so that the math works out.

Post Reply