Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Phase/Mscorlib/system/CsMath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CsMath
public static inline function Round_Single(a:Single) : Single return Math.round(a.ToHaxeFloat());
public static inline function Sin(a:Double) : Double return Math.sin(a.ToHaxeFloat());
public static inline function Cos(a:Double) : Double return Math.cos(a.ToHaxeFloat());
public static inline function Tan(a:Double) : Double return Math.tan(a.ToHaxeFloat());
public static inline function Pow(v:Double, exp:Double) : Double return Math.pow(v.ToHaxeFloat(), exp.ToHaxeFloat());
public static inline function Ceiling_Single(v:Single) : Single return Math.ceil(v.ToHaxeFloat());
public static inline function Ceiling_Double(v:Double) : Double return Math.ceil(v.ToHaxeFloat());
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ alphaTab can load music notation from various sources like Guitar Pro 3-5, Guita
<a href="https://www.browserstack.com" target="_blank"><img src="Images/BrowserStack.png?raw=true" width="400" align="center"/></a>
</p>

... to [Bernhard Schelling](https://github.com/schellingb/TinySoundFont) the author of TinySoundFont and [Steve Folta](https://github.com/stevefolta/SFZero) the author of SFZero for providing the core of the synthesis engine.

... to all you people using alphaTab providing new feature ideas and and bug reports.
64 changes: 0 additions & 64 deletions Source/AlphaTab.CSharp/Collections/SampleArray.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void SetChannelSolo(int channel, bool solo)
DispatchOnWorkerThread(() => { Player.SetChannelSolo(channel, solo); });
}

public void SetChannelVolume(int channel, double volume)
public void SetChannelVolume(int channel, float volume)
{
DispatchOnWorkerThread(() => { Player.SetChannelVolume(channel, volume); });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void Open()
Ready();
}

/// <inheritdoc />
public void Dispose()
{
Close();
Expand Down Expand Up @@ -85,7 +86,7 @@ public void SequencerFinished()
}

/// <inheritdoc />
public void AddSamples(SampleArray f)
public void AddSamples(float[] f)
{
_circularBuffer.Write(f, 0, f.Length);
}
Expand Down Expand Up @@ -122,7 +123,7 @@ public override int Read(float[] buffer, int offset, int count)
}
else
{
var read = new SampleArray(count);
var read = new float[count];
_circularBuffer.Read(read, 0, read.Length);

for (var i = 0; i < count; i++)
Expand Down
45 changes: 0 additions & 45 deletions Source/AlphaTab.JavaScript/Collections/SampleArray.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ public void SequencerFinished()
FlashOutput.AlphaSynthSequencerFinished();
}

public void AddSamples(SampleArray samples)
public void AddSamples(float[] samples)
{
var uint8 = new Uint8Array(samples.ToFloat32Array().Buffer);
Float32Array f32 = samples.As<Float32Array>();
var uint8 = new Uint8Array(f32.Buffer);
var b64 = Script.Write<string>(
"untyped __js__(\"window.btoa(String.fromCharCode.apply(null, {0}))\", uint8)");
FlashOutput.AlphaSynthAddSamples(b64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ internal class AlphaSynthWebAudioOutput : ISynthOutput
private CircularSampleBuffer _circularBuffer;

private bool _finished;
private double _contextTimeOnGenerate;
private int _samplesGenerated;

public int SampleRate => (int)_context.SampleRate;

public void Open()
Expand Down Expand Up @@ -142,7 +139,7 @@ public void SequencerFinished()
_finished = true;
}

public void AddSamples(SampleArray f)
public void AddSamples(float[] f)
{
_circularBuffer.Write(f, 0, f.Length);
}
Expand Down Expand Up @@ -180,10 +177,7 @@ private void GenerateSound(AudioProcessingEvent e)
}
else
{
_contextTimeOnGenerate = _context.CurrentTime;
_samplesGenerated = left.Length;

var buffer = new SampleArray(samples);
var buffer = new float[samples];
_circularBuffer.Read(buffer, 0, buffer.Length);

var s = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using AlphaTab.Audio.Synth;
using AlphaTab.Audio.Synth.Midi;
using AlphaTab.Audio.Synth.Synthesis;
using AlphaTab.Audio.Synth.Util;
using AlphaTab.Collections;
using AlphaTab.Haxe.Js.Html;
Expand Down Expand Up @@ -368,9 +367,9 @@ public void SetChannelSolo(int channel, bool solo)
}

/// <inheritdoc />
public void SetChannelVolume(int channel, double volume)
public void SetChannelVolume(int channel, float volume)
{
volume = SynthHelper.ClampD(volume, SynthConstants.MinVolume, SynthConstants.MaxVolume);
volume = SynthHelper.ClampF(volume, SynthConstants.MinVolume, SynthConstants.MaxVolume);
_synth.PostMessage(new
{
cmd = AlphaSynthWebWorker.CmdSetChannelVolume,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ internal class AlphaSynthWorkerSynthOutput : ISynthOutput
public const string CmdOutputSamplesPlayed = CmdOutputPrefix + "samplesPlayed";


// this value is initialized by the alphaSynth WebWorker wrapper
// that also includes the alphaSynth library into the worker.
// this value is initialized by the alphaSynth WebWorker wrapper
// that also includes the alphaSynth library into the worker.
public static int PreferredSampleRate { get; set; }

private DedicatedWorkerGlobalScope _worker;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void SequencerFinished()
});
}

public void AddSamples(SampleArray samples)
public void AddSamples(float[] samples)
{
_worker.PostMessage(new
{
Expand Down
7 changes: 7 additions & 0 deletions Source/AlphaTab.JavaScript/Platform/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ public static bool SupportsTextDecoder
[Inline] get => !!Lib.Global.TextDecoder;
}

[Inline]
public static void ArrayCopy(float[] src, int srcOffset, float[] dst, int dstOffset, int count)
{
Script.Write(
"untyped __js__(\"{2}.set({0}.subarray({1},{1}+{4}), {3})\", src, srcOffset, dst, dstOffset, count);");
}

[Inline]
public static void ArrayCopy(int[] src, int srcOffset, int[] dst, int dstOffset, int count)
{
Expand Down
8 changes: 4 additions & 4 deletions Source/AlphaTab.Test.Js/test/alphaTab.tests.specs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// <reference path="alphaTab.tests.js" />
describe("alphaTab.test.audio.AlphaSynthTests", function() {
var __instance = new alphaTab.test.audio.AlphaSynthTests();
it("TestLoadSf2PatchBank", function(done) {
alphaTab.test.TestPlatform.Done = done;
__instance.TestLoadSf2PatchBank();
});
it("TestPcmGeneration", function(done) {
alphaTab.test.TestPlatform.Done = done;
__instance.TestPcmGeneration();
});
});
describe("alphaTab.test.audio.MidiFileGeneratorTest", function() {
var __instance = new alphaTab.test.audio.MidiFileGeneratorTest();
it("TestFullSong", function(done) {
alphaTab.test.TestPlatform.Done = done;
__instance.TestFullSong();
});
it("TestCorrectMidiOrder", function(done) {
alphaTab.test.TestPlatform.Done = done;
__instance.TestCorrectMidiOrder();
Expand Down
51 changes: 2 additions & 49 deletions Source/AlphaTab.Test/Audio/AlphaSynthTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.IO;
using AlphaTab.Audio.Generator;
using AlphaTab.Audio.Synth;
using AlphaTab.Audio.Synth.Bank;
using AlphaTab.Audio.Synth.Ds;
using AlphaTab.Audio.Synth.Midi;
using AlphaTab.Audio.Synth.Util;
using AlphaTab.Audio.Synth.SoundFont;
using AlphaTab.Collections;
using AlphaTab.Importer;
using AlphaTab.IO;
Expand All @@ -16,50 +13,6 @@ namespace AlphaTab.Test.Audio
[TestClass]
public class AlphaSynthTests
{
[TestMethod, AsyncTestMethod]
public void TestLoadSf2PatchBank()
{
TestPlatform.LoadFile("TestFiles/Audio/default.sf2", data =>
{
var patchBank = new PatchBank();
var input = ByteBuffer.FromBuffer(data);
patchBank.LoadSf2(input);

Assert.AreEqual("GS sound set (16 bit)", patchBank.Name);
Assert.AreEqual("960920 ver. 1.00.16", patchBank.Comments);
Assert.AreEqual("0,1,2,3,4,5,6,7,8,9,16,24,32,128", string.Join(",", patchBank.LoadedBanks));

var gmBank = patchBank.GetBank(0);
var expectedPatches = new string[]
{
"Piano 1", "Piano 2", "Piano 3", "Honky-tonk", "E.Piano 1", "E.Piano 2", "Harpsichord", "Clav.",
"Celesta", "Glockenspiel", "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular-bell", "Santur", "Organ 1",
"Organ 2", "Organ 3", "Church Org.1", "Reed Organ", "Accordion Fr", "Harmonica", "Bandoneon",
"Nylon-str.Gt", "Steel-str.Gt", "Jazz Gt.", "Clean Gt.", "Muted Gt.", "Overdrive Gt", "DistortionGt", "Gt.Harmonics",
"Acoustic Bs.", "Fingered Bs.", "Picked Bs.", "Fretless Bs.", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1",
"Synth Bass 2", "Violin", "Viola", "Cello", "Contrabass", "Tremolo Str", "PizzicatoStr", "Harp", "Timpani", "Strings",
"Slow Strings", "Syn.Strings1", "Syn.Strings2", "Choir Aahs", "Voice Oohs", "SynVox", "OrchestraHit", "Trumpet", "Trombone", "Tuba",
"MutedTrumpet", "French Horns", "Brass 1", "Synth Brass1", "Synth Brass2", "Soprano Sax", "Alto Sax", "Tenor Sax", "Baritone Sax",
"Oboe", "English Horn", "Bassoon", "Clarinet", "Piccolo", "Flute", "Recorder", "Pan Flute", "Bottle Blow", "Shakuhachi", "Whistle",
"Ocarina", "Square Wave", "Saw Wave", "Syn.Calliope", "Chiffer Lead", "Charang", "Solo Vox", "5th Saw Wave",
"Bass & Lead", "Fantasia", "Warm Pad", "Polysynth", "Space Voice", "Bowed Glass", "Metal Pad", "Halo Pad", "Sweep Pad",
"Ice Rain", "Soundtrack", "Crystal", "Atmosphere", "Brightness", "Goblin", "Echo Drops", "Star Theme", "Sitar",
"Banjo", "Shamisen", "Koto", "Kalimba", "Bagpipe", "Fiddle", "Shanai", "Tinkle Bell", "Agogo", "Steel Drums", "Woodblock",
"Taiko", "Melo. Tom 1", "Synth Drum", "Reverse Cym.", "Gt.FretNoise", "Breath Noise", "Seashore", "Bird", "Telephone 1",
"Helicopter", "Applause", "Gun Shot"
};
var actualPatches = new FastList<string>();
foreach (var patch in gmBank)
{
if (patch != null)
{
actualPatches.Add(patch.Name);
}
}
Assert.AreEqual(string.Join(",", expectedPatches), string.Join(",", actualPatches));
});
}

[TestMethod, AsyncTestMethod]
public void TestPcmGeneration()
{
Expand Down Expand Up @@ -144,7 +97,7 @@ public void Pause()
{
}

public void AddSamples(SampleArray f)
public void AddSamples(float[] f)
{
for (var i = 0; i < f.Length; i++)
{
Expand Down
Loading