1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-01-27 07:17:20 +00:00

polygon spectogram stuff redo

This commit is contained in:
Cameron Taylor 2022-02-11 14:21:42 -05:00
parent ef67aacf86
commit 804e084668
5 changed files with 113 additions and 63 deletions

View file

@ -111,51 +111,47 @@ class InitState extends FlxTransitionableState
// FlxTransitionableState.skipNextTransOut = true;
FlxTransitionableState.skipNextTransIn = true;
#if song
var song = getSong();
var weeks =
[ ['bopeebo', 'fresh', 'dadbattle']
, ['spookeez', 'south', 'monster']
, ['spooky', 'spooky', 'monster']
, ['pico', 'philly', 'blammed']
, ['satin-panties', 'high', 'milf']
, ['cocoa', 'eggnog', 'winter-horrorland']
, ['senpai', 'roses', 'thorns']
, ['ugh', 'guns', 'stress']
];
var week = 0;
for (i in 0...weeks.length)
var song = getSong();
var weeks = [
['bopeebo', 'fresh', 'dadbattle'],
['spookeez', 'south', 'monster'],
['spooky', 'spooky', 'monster'],
['pico', 'philly', 'blammed'],
['satin-panties', 'high', 'milf'],
['cocoa', 'eggnog', 'winter-horrorland'],
['senpai', 'roses', 'thorns'],
['ugh', 'guns', 'stress']
];
var week = 0;
for (i in 0...weeks.length)
{
if (weeks[i].contains(song))
{
if (weeks[i].contains(song))
{
week = i + 1;
break;
}
week = i + 1;
break;
}
if (week == 0)
throw 'Invalid -D song=$song';
startSong(week, song, false);
}
if (week == 0)
throw 'Invalid -D song=$song';
startSong(week, song, false);
#elseif week
var week = getWeek();
var songs =
[ 'bopeebo', 'spookeez', 'spooky', 'pico'
, 'satin-panties', 'cocoa', 'senpai', 'ugh'
];
if (week <= 0 || week >= songs.length)
throw "invalid -D week=" + week;
startSong(week, songs[week - 1], true);
var week = getWeek();
var songs = [
'bopeebo', 'spookeez', 'spooky', 'pico',
'satin-panties', 'cocoa', 'senpai', 'ugh'
];
if (week <= 0 || week >= songs.length)
throw "invalid -D week=" + week;
startSong(week, songs[week - 1], true);
#elseif FREEPLAY
FlxG.switchState(new FreeplayState());
#elseif ANIMATE
@ -173,11 +169,11 @@ class InitState extends FlxTransitionableState
FlxG.switchState(new TitleState());
#end
}
function startSong(week, song, isStoryMode)
{
var dif = getDif();
PlayState.SONG = SongLoad.loadFromJson(song, song);
PlayState.isStoryMode = isStoryMode;
PlayState.storyDifficulty = dif;
@ -194,9 +190,14 @@ class InitState extends FlxTransitionableState
}
#end
function getWeek() return Std.parseInt(getDefine("week"));
function getSong() return getDefine("song");
function getDif() return Std.parseInt(getDefine("dif", "1"));
function getWeek()
return Std.parseInt(getDefine("week"));
function getSong()
return getDefine("song");
function getDif()
return Std.parseInt(getDefine("dif", "1"));
macro function getDefine(key:String, defaultValue:String = null):haxe.macro.Expr
{

View file

@ -13,6 +13,7 @@ class PolygonSpectogram extends MeshRender
var sampleRate:Int;
public var vis:VisShit;
public var visType:VISTYPE = UPDATED;
public var daHeight:Float = FlxG.height;
var numSamples:Int = 0;
@ -23,7 +24,7 @@ class PolygonSpectogram extends MeshRender
public function new(daSound:FlxSound, ?col:FlxColor = FlxColor.WHITE, ?height:Float = 720, ?detail:Float = 1)
{
super(0, 0);
super(0, 0, col);
vis = new VisShit(daSound);
@ -35,6 +36,20 @@ class PolygonSpectogram extends MeshRender
// col not in yet
}
override function update(elapsed:Float)
{
super.update(elapsed);
switch (visType)
{
case UPDATED:
realtimeVis();
default:
}
}
var prevAudioData:Int16Array;
/**
* Generates and draws a section of the audio data to a visual waveform
* @param start start of the song in milliseconds
@ -54,18 +69,25 @@ class PolygonSpectogram extends MeshRender
var prevPoint:FlxPoint = new FlxPoint();
for (i in 0...500)
var funnyPixels:Int = Std.int(daHeight); // sorta redundant but just need it for different var...
if (prevAudioData == audioData.subarray(startSample, startSample + samplesToGen))
return; // optimize / finish funciton here, no need to re-render
prevAudioData = audioData.subarray(startSample, samplesToGen);
for (i in 0...funnyPixels)
{
var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, 500, startSample, startSample + samplesToGen));
var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, funnyPixels, startSample, startSample + samplesToGen));
var curAud:CurAudioInfo = VisShit.getCurAud(audioData, sampleApprox);
var waveAmplitude:Int = 200;
var coolPoint:FlxPoint = new FlxPoint();
coolPoint.x = (curAud.balanced * waveAmplitude / 2 + waveAmplitude / 2);
coolPoint.y = (i / 500 * daHeight);
coolPoint.y = (i / funnyPixels * daHeight);
add_quad(prevPoint.x, prevPoint.y, prevPoint.x + 1, prevPoint.y, coolPoint.x, coolPoint.y, coolPoint.x + 1, coolPoint.y + 1);
add_quad(prevPoint.x, prevPoint.y, prevPoint.x + 2, prevPoint.y, coolPoint.x, coolPoint.y, coolPoint.x + 2, coolPoint.y + 2);
prevPoint.x = coolPoint.x;
prevPoint.y = coolPoint.y;
@ -73,6 +95,31 @@ class PolygonSpectogram extends MeshRender
}
}
var curTime:Float = 0;
function realtimeVis():Void
{
if (vis.snd != null)
{
if (curTime != vis.snd.time)
{
trace("DOIN SHIT" + FlxG.random.int(0, 200));
if (vis.snd.playing)
curTime = vis.snd.time;
else
{
if (Math.abs(curTime - vis.snd.time) > 10)
curTime = FlxMath.lerp(curTime, vis.snd.time, 0.5);
}
curTime = vis.snd.time;
generateSection(vis.snd.time, 0.2);
}
}
}
public function checkAndSetBuffer()
{
vis.checkAndSetBuffer();
@ -86,3 +133,10 @@ class PolygonSpectogram extends MeshRender
}
}
}
enum VISTYPE
{
STATIC;
UPDATED;
FREQUENCIES;
}

View file

@ -1,5 +1,6 @@
package audiovis;
import audiovis.PolygonSpectogram.VISTYPE;
import audiovis.VisShit.CurAudioInfo;
import audiovis.dsp.FFT;
import flixel.FlxSprite;
@ -298,10 +299,3 @@ class SpectogramSprite extends FlxTypedSpriteGroup<FlxSprite>
}
}
}
enum VISTYPE
{
STATIC;
UPDATED;
FREQUENCIES;
}

View file

@ -422,7 +422,7 @@ class ChartingState extends MusicBeatState
FlxG.sound.playMusic(Paths.inst(daSong), 0.6);
var musSpec:SpectogramSprite = new SpectogramSprite(FlxG.sound.music, FlxColor.RED, FlxG.height / 2, Math.floor(FlxG.height / 2));
var musSpec:PolygonSpectogram = new PolygonSpectogram(FlxG.sound.music, FlxColor.RED, FlxG.height / 2, Math.floor(FlxG.height / 2));
musSpec.x += 70;
musSpec.scrollFactor.set();
// musSpec.visType = FREQUENCIES;
@ -451,7 +451,7 @@ class ChartingState extends MusicBeatState
for (index => voc in vocals.members)
{
var vocalSpec:SpectogramSprite = new SpectogramSprite(voc, FlxG.random.color(0xFFAAAAAA, FlxColor.WHITE, 100), musSpec.daHeight,
var vocalSpec:PolygonSpectogram = new PolygonSpectogram(voc, FlxG.random.color(0xFFAAAAAA, FlxColor.WHITE, 100), musSpec.daHeight,
Math.floor(FlxG.height / 2));
vocalSpec.x = 70 - (50 * index);
// vocalSpec.visType = FREQUENCIES;
@ -467,7 +467,7 @@ class ChartingState extends MusicBeatState
if (index == 1)
staticVocal.x = gridBG.width;
// staticVocal.visType = STATIC;
staticVocal.visType = STATIC;
staticSpecGrp.add(staticVocal);
}

View file

@ -1,6 +1,7 @@
package rendering;
import flixel.FlxStrip;
import flixel.util.FlxColor;
/**
* Yoinked from AustinEast, thanks hopefully u dont mind me using some of ur good code
@ -13,10 +14,10 @@ class MeshRender extends FlxStrip
var tri_offset:Int = 0;
public function new(x, y)
public function new(x, y, ?col:FlxColor = FlxColor.WHITE)
{
super(x, y);
makeGraphic(1, 1);
makeGraphic(1, 1, col);
}
public inline function start()