mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-03-30 22:35:04 +00:00
more cool spectogram shit
This commit is contained in:
parent
4212e59937
commit
2eedd1a20f
|
@ -98,10 +98,6 @@ class ChartingState extends MusicBeatState
|
||||||
|
|
||||||
// trace(audioBuf.sampleRate);
|
// trace(audioBuf.sampleRate);
|
||||||
|
|
||||||
var spec:SpectogramSprite = new SpectogramSprite();
|
|
||||||
spec.scrollFactor.set();
|
|
||||||
add(spec);
|
|
||||||
|
|
||||||
gridBG = FlxGridOverlay.create(GRID_SIZE, GRID_SIZE, GRID_SIZE * 8, GRID_SIZE * 16);
|
gridBG = FlxGridOverlay.create(GRID_SIZE, GRID_SIZE, GRID_SIZE * 8, GRID_SIZE * 16);
|
||||||
add(gridBG);
|
add(gridBG);
|
||||||
|
|
||||||
|
@ -393,43 +389,23 @@ class ChartingState extends MusicBeatState
|
||||||
|
|
||||||
FlxG.sound.playMusic(Paths.inst(daSong), 0.6);
|
FlxG.sound.playMusic(Paths.inst(daSong), 0.6);
|
||||||
|
|
||||||
@:privateAccess
|
var musSpec:SpectogramSprite = new SpectogramSprite(FlxG.sound.music, FlxColor.RED);
|
||||||
var audioData:Int16Array = FlxG.sound.music._channel.__source.buffer.data;
|
musSpec.scrollFactor.set();
|
||||||
|
add(musSpec);
|
||||||
|
|
||||||
// trace(audioBuf.data.length);
|
// trace(audioBuf.data.length);
|
||||||
playheadTest = new FlxSprite(0, 0).makeGraphic(2, 255, FlxColor.RED);
|
playheadTest = new FlxSprite(0, 0).makeGraphic(2, 255, FlxColor.RED);
|
||||||
playheadTest.scrollFactor.set();
|
playheadTest.scrollFactor.set();
|
||||||
add(playheadTest);
|
add(playheadTest);
|
||||||
|
|
||||||
var sampleLength:Int = Std.int(audioData.length / 2);
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
var wavHeight:Int = FlxG.height;
|
|
||||||
var funnyShit:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, wavHeight, FlxColor.TRANSPARENT);
|
|
||||||
funnyShit.scrollFactor.set();
|
|
||||||
// add(funnyShit);
|
|
||||||
|
|
||||||
var prevLine:FlxPoint = new FlxPoint();
|
|
||||||
|
|
||||||
for (sampleShit in 0...FlxG.width)
|
|
||||||
{
|
|
||||||
// thnx mike welsh fo dis
|
|
||||||
var left = audioData[i] / 32767; // 16-bit audio samples are from -32767 to 32767, convert to -1.0 to 1.0
|
|
||||||
var right = audioData[i + 1] / 32767;
|
|
||||||
|
|
||||||
var adjusted:Int = Std.int(sampleLength / FlxG.width);
|
|
||||||
|
|
||||||
i += 2 * adjusted;
|
|
||||||
|
|
||||||
funnyShit.drawLine(prevLine.x, prevLine.y, FlxG.width * sampleShit / FlxG.width, left * wavHeight / 2 + wavHeight / 2);
|
|
||||||
prevLine.x = FlxG.width * sampleShit / FlxG.width;
|
|
||||||
prevLine.y = left * wavHeight / 2 + wavHeight / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER
|
// WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER
|
||||||
vocals = new FlxSound().loadEmbedded(Paths.voices(daSong));
|
vocals = new FlxSound().loadEmbedded(Paths.voices(daSong));
|
||||||
FlxG.sound.list.add(vocals);
|
FlxG.sound.list.add(vocals);
|
||||||
|
|
||||||
|
var spec:SpectogramSprite = new SpectogramSprite(vocals);
|
||||||
|
spec.scrollFactor.set();
|
||||||
|
add(spec);
|
||||||
|
|
||||||
FlxG.sound.music.pause();
|
FlxG.sound.music.pause();
|
||||||
vocals.pause();
|
vocals.pause();
|
||||||
|
|
||||||
|
@ -707,6 +683,9 @@ class ChartingState extends MusicBeatState
|
||||||
|
|
||||||
var daTime:Float = 700 * FlxG.elapsed;
|
var daTime:Float = 700 * FlxG.elapsed;
|
||||||
|
|
||||||
|
if (FlxG.keys.pressed.CONTROL)
|
||||||
|
daTime *= 0.2;
|
||||||
|
|
||||||
if (FlxG.keys.pressed.W)
|
if (FlxG.keys.pressed.W)
|
||||||
{
|
{
|
||||||
FlxG.sound.music.time -= daTime;
|
FlxG.sound.music.time -= daTime;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import flixel.group.FlxGroup;
|
||||||
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
||||||
import flixel.math.FlxMath;
|
import flixel.math.FlxMath;
|
||||||
import flixel.math.FlxPoint;
|
import flixel.math.FlxPoint;
|
||||||
|
import flixel.system.FlxSound;
|
||||||
import flixel.util.FlxColor;
|
import flixel.util.FlxColor;
|
||||||
import lime.utils.Int16Array;
|
import lime.utils.Int16Array;
|
||||||
|
|
||||||
|
@ -12,55 +13,79 @@ using flixel.util.FlxSpriteUtil;
|
||||||
|
|
||||||
class SpectogramSprite extends FlxTypedSpriteGroup<FlxSprite>
|
class SpectogramSprite extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
{
|
{
|
||||||
public function new()
|
var lengthOfShit:Int = 500;
|
||||||
|
|
||||||
|
var daSound:FlxSound;
|
||||||
|
|
||||||
|
public function new(daSound:FlxSound, ?col:FlxColor = FlxColor.WHITE)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
for (i in 0...256)
|
this.daSound = daSound;
|
||||||
|
|
||||||
|
for (i in 0...lengthOfShit)
|
||||||
{
|
{
|
||||||
var lineShit:FlxSprite = new FlxSprite(100, i / 256 * FlxG.height).makeGraphic(1, 1);
|
var lineShit:FlxSprite = new FlxSprite(100, i / lengthOfShit * FlxG.height).makeGraphic(1, 1, col);
|
||||||
// lineShit.origin.set();
|
lineShit.active = false;
|
||||||
|
|
||||||
// var xClip = lineShit.clipRect;
|
|
||||||
// xClip.width = 1;
|
|
||||||
|
|
||||||
// lineShit.clipRect = xClip;
|
|
||||||
add(lineShit);
|
add(lineShit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeGraphic(200, 200, FlxColor.BLACK);
|
// makeGraphic(200, 200, FlxColor.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var setBuffer:Bool = false;
|
||||||
|
var audioData:Int16Array;
|
||||||
|
var numSamples:Int = 0;
|
||||||
|
|
||||||
override function update(elapsed:Float)
|
override function update(elapsed:Float)
|
||||||
{
|
{
|
||||||
if (FlxG.sound.music != null)
|
if (daSound != null)
|
||||||
{
|
{
|
||||||
if (FlxG.sound.music.playing)
|
var remappedShit:Int = 0;
|
||||||
|
|
||||||
|
if (daSound.playing)
|
||||||
{
|
{
|
||||||
// FlxSpriteUtil.drawRect(this, 0, 0, width, height, 0x45000000);
|
if (!setBuffer)
|
||||||
|
{
|
||||||
|
@:privateAccess
|
||||||
|
audioData = cast daSound._channel.__source.buffer.data; // jank and hacky lol!
|
||||||
|
setBuffer = true;
|
||||||
|
numSamples = Std.int(audioData.length / 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remappedShit = Std.int(FlxMath.remapToRange(daSound.time, 0, daSound.length, 0, numSamples));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (setBuffer)
|
||||||
|
remappedShit = Std.int(FlxMath.remapToRange(Conductor.songPosition, 0, daSound.length, 0, numSamples));
|
||||||
|
}
|
||||||
|
|
||||||
@:privateAccess
|
if (setBuffer)
|
||||||
var audioData:Int16Array = FlxG.sound.music._channel.__source.buffer.data; // jank and hacky lol!
|
{
|
||||||
|
|
||||||
var numSamples:Int = Std.int(audioData.length / 2);
|
|
||||||
var remappedShit:Int = Std.int(FlxMath.remapToRange(FlxG.sound.music.time, 0, FlxG.sound.music.length, 0, numSamples));
|
|
||||||
var i = remappedShit;
|
var i = remappedShit;
|
||||||
var prevLine:FlxPoint = new FlxPoint();
|
var prevLine:FlxPoint = new FlxPoint();
|
||||||
|
|
||||||
var swagheight:Int = 200;
|
var swagheight:Int = 200;
|
||||||
|
|
||||||
for (sample in remappedShit...remappedShit + 256)
|
for (sample in remappedShit...remappedShit + lengthOfShit)
|
||||||
{
|
{
|
||||||
var left = audioData[i] / 32767;
|
var left = audioData[i] / 32767;
|
||||||
|
var right = audioData[i + 1] / 32767;
|
||||||
|
|
||||||
|
var balanced = (left + right) / 2;
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
|
|
||||||
var remappedSample:Float = FlxMath.remapToRange(sample, remappedShit, remappedShit + 256, 0, 255);
|
var remappedSample:Float = FlxMath.remapToRange(sample, remappedShit, remappedShit + lengthOfShit, 0, lengthOfShit - 1);
|
||||||
|
|
||||||
group.members[Std.int(remappedSample)].x = prevLine.x;
|
group.members[Std.int(remappedSample)].x = prevLine.x;
|
||||||
// group.members[0].y = prevLine.y;
|
// group.members[0].y = prevLine.y;
|
||||||
|
|
||||||
// FlxSpriteUtil.drawLine(this, prevLine.x, prevLine.y, width * remappedSample, left * height / 2 + height / 2);
|
// FlxSpriteUtil.drawLine(this, prevLine.x, prevLine.y, width * remappedSample, left * height / 2 + height / 2);
|
||||||
prevLine.x = left * swagheight / 2 + swagheight / 2;
|
prevLine.x = balanced * swagheight / 2 + swagheight / 2;
|
||||||
// width * (remappedSample / 255);
|
// width * (remappedSample / 255);
|
||||||
// prevLine.y = left * swagheight / 2 + swagheight / 2;
|
// prevLine.y = left * swagheight / 2 + swagheight / 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue