Search Unity

UnitySynth - full Xplatform midi synth

Discussion in 'Editor & General Support' started by sonicviz, Mar 30, 2012.

  1. boogie77

    boogie77

    Joined:
    Oct 8, 2013
    Posts:
    8
    Hi all,

    Sorry for the noob question.

    I've imported CSharpSynth as a plugin into unity and can run UnitySynthTest.cs and everything.

    I'm now trying to access it from a js script instead of C#, cos I can't write C#

    Can someone tell me why the following is not working?
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. private var midiStreamSynthesizer : CSharpSynth.Synthesis.StreamSynthesizer;
    4. private var midiSequencer : CSharpSynth.Sequencer.MidiSequencer;
    5.  
    6.  
    7. function Start () {
    8. }
    9.  
    10. function Update () {
    11.     midiStreamSynthesizer = GetComponent(CSharpSynth.Synthesis.StreamSynthesizer);
    12.     midiSequencer = GetComponent(CSharpSynth.Sequencer.MidiSequencer);
    13.     midiSequencer.LoadMidi("Midis/Mary.mid", false);
    14.     print("test123");
    15.  
    16. }
    Warnings returned:
    Error returned:
     
  2. bhandy_4d

    bhandy_4d

    Joined:
    Jun 23, 2014
    Posts:
    2
    I'm pretty sure you can't use GetComponent that way. Without an object on the front, GetComponent defaults to this.GetComponent, and that's why it's asking for MonoBehaviour (all components' parent class) or Component.

    You should also know, GetComponent is a bit processor intensive - calling it once every update it generally a bad idea. Do it once at the start if you can. You also don't want to load midis every tick/update, so move that to Start() too.

    There's some way to instantiate your StreamSynthesizer and Sequencer, but it's not like that. JS might do it by default, I don't remember off the top of my head, but you'll probably need to load certain parameters at that time. Eg.

    Code (JavaScript):
    1. midiStreamSynthesizer = new CSharpSynth.Synthesis.StreamSynthesizer(4400, 2, bufferSize, 40);
    ...where bufferSize is some byte array/sampleBuffer of size synthesizer.RawBufferSize/BufferSize/etc. You'll have to poke around a bit, and I suggest looking at the original code in UnitySynthTest.cs and comparing it to what you have in JS, and seeing how to accomplish things like that. You may also consider looking at the more up to date CSynth library: http://csharpsynthproject.codeplex....udioSynthesis/Sources/Midi/Event/MidiEvent.cs

    Hope that helps!

    EDIT: Also, don't forget to check in Unity documentation on how to call C# code from JS. CSynth is all C#, so you'll have to make that jump eventually on your own.
     
  3. bhandy_4d

    bhandy_4d

    Joined:
    Jun 23, 2014
    Posts:
    2
    Double posting to address another concern that's not being addressed:

    I have also tried this with no luck. I went a step further and rewrote the float[] in float[] out version that sonicviz's plugin uses, and still didn't get any results. A step further than that, I put in a ton of log messages to find out what was/wasn't firing. FillMidiEventQueue was never being called, so I put a call to that in OnAudioFilterRead and it almost worked (although I think it skips through the entire song, since there's no controlling it with a sample size anymore).

    Either way, the most up to date build of CSynthSource (August 2013) does not work as a quick drag and drop in place of the old code in sonicviz's plugin, and requires more research/instruction. It's too bad since the function names are so much nicer, and it feels a lot more modular.

    In other news: I'm curious about Nicholas Vesely's plugin: http://nicholasvesely.weebly.com/sip.html

    He's got midi files loading without the .txt at the end, and playing with CSynth... although it looks like it's as old as sonicviz's implementation.
     
  4. jively

    jively

    Joined:
    Mar 28, 2014
    Posts:
    2
    This project is very cool. I am able to get the Unity project to play in Unity free.

    I am trying to write a program that plays a song that only uses piano, but will have a lot of overlapping tones. The WAV files that come with this are very short clips that loop and are compact. They don't take a lot of memory.

    However, the piano sounds are too thick for my songs, when each note sustains the way an organ would, and not the way a piano should.

    I found great-sounding piano samples in SFZ format from Mildon Studios (http://mildonstudios.com/static/acoustic_piano_sfz.html). It sounds great but the samples are very large compared to the rest of the GM library included here. When I try to modify GM.txt to point to Mildon, I get "out of memory" errors.

    I've tried reducing the sample library to just one velocity, and lowering the WAV files to 22K 16-bit mono, and am just struggling to get it to load and to play sounds that don't loop. (Does this synth even handle correctly playing SFZ files that don't loop?) Even if the Mildon.SFZ file points to just one non-looping WAV file it does not load and sound right.

    Any suggestions on what I can do?

    Thanks,

    -Tom
    --
    musician, freelance composer, saxophone player
    Hear sample music at http://www.tomsnively.com/
     
  5. jively

    jively

    Joined:
    Mar 28, 2014
    Posts:
    2
    In case you are interested, I am writing a program called Molecular Music Box based on the music-composing algorithm described in


    You can try my version at http://www.tomsnively.com/games/MolecularMusicBox.html

    If you just hit Play (on the default 4E3), you'll hear what I mean about the thickness on the sustained piano notes.

    -Tom
    --
    musician, freelance composer, saxophone player
    Hear sample music at http://www.tomsnively.com/
     
    GibTreaty and dakka like this.
  6. fryedrycestyle

    fryedrycestyle

    Joined:
    Jun 8, 2012
    Posts:
    19
    Hey guys,

    I've been trying to use the DeadNote MIDI stuff, but I seem to run into the issue of my first deltaTime (for the first Note On) event incorrect when using MidiEvent's deltaTime. I'm trying to make a music game, and need the MIDI notes to be at the correct positions for them to hit in time with the music - does anyone have any idea why the time would be wrong? For example, the first note in my song is meant to be at 7500 milliseconds but according to DeadNote the timestamp is 14640. Is it a different measurement of time? I'm honestly very confused about what the deal is. -.- If someone could shed some light on what they think the issue might be that would be wonderful!

    Thanks!
     
  7. 432qwerty

    432qwerty

    Joined:
    Jul 20, 2014
    Posts:
    1
    Hi everyone, this appears to be a great synth :) been messing around with the Unity test scene, just wondering does it have the capability of MIDI input (from a musical keyboard, not using a keyboard to emulate a musical one) in Unity, or could it be easily added? I've found a free asset on the Asset Store which I could use for this but it requires Unity Pro which I don't have.
     
  8. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    Is MIDI Synth on the asset store just a rip of this? I was having issues with it and ended up here and found my problem (iOS events) and the more I read it feels like its the same thing bundled up in a DLL...hmmmm
     
  9. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    Thank you! Big thank you! Works perfectly. Unfortunately I had already spent the money for MIDI Synth on the Asset Store who has completely ripped your code but did not update it for the iOS integration. You saved my bacon! Have a great day!
     
  10. smnerat

    smnerat

    Joined:
    Sep 23, 2012
    Posts:
    35
    So I've come back to this after leaving it alone for the summer. I am still trying to get the newest version of the CSharpSynthProject to work. I have it up and running in Unity, but it doesn't sound right at all. I get a high pitched squeal whenever I try play a note. I'm wondering if anyone else has this problem? I've inserted debug messages at a lot of points throughout the code to try and see whats happening. My first thought was the buffers were not lining up, but from the debug messages it looks like they're lengths match and are lining up correctly. Has anyone else had better luck?
     
  11. hkdtmer

    hkdtmer

    Joined:
    Apr 2, 2014
    Posts:
    35
    I downloaded the attached UnitySynth package and tried the sample project a bit. It performed correctly but just very CPU consuming. Playing a fairly complicated MIDI file with the default sfz GM bank with max polyphony (500) used 40+% CPU time on my i3 computer. On Lumia 520 I can only set polyphony to 8 otherwise crackling will occur. On a faster 4-core Android phone (Xiaomi Redmi 1s) I can use about 24 polyphony before crackling occur, which is still not ideal for complex compositions.

    Other than removing sample/bank loading Debug.Log lines in the source files I did not make any significant modifications when trying out the synth.

    If you can run it, can you post some benckmarks on your devices?
     
  12. Adam_Streck

    Adam_Streck

    Joined:
    Jul 31, 2013
    Posts:
    26
    [SOLVED] Bad sound quality on Nexus 5, Android 4.4.2:

    I was making an app for Android based on the package and even though it worked perfectly on the computer, the sound from the phone was just awful. I don't really understand the nature of the problem, but the quick fix was to use mono instead of stereo, the following update to the code did the trick:

    Code (CSharp):
    1. #if UNITY_ANDROID && !UNITY_EDITOR
    2.         midiStreamSynthesizer = new StreamSynthesizer(44100, 1, bufferSize, 40);
    3. #else
    4.         midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
    5. #endif
     
    everdark likes this.
  13. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    I am also having issues on droid. Check and see if adding the devices sampler frequency helps. Will let you know as soon as I have a fix.

    something like this maybe?
    new StreamSynthesizer (AudioSettings.outputSampleRate, 2, bufferSize, 40);
     
    Last edited: Oct 9, 2014
  14. dizzlebomb

    dizzlebomb

    Joined:
    Sep 21, 2009
    Posts:
    9
    I have this all working in Unity very well in the editor, but on iOS, the audio playback is very fast and sounds very wrong. Has anyone made positive changes here to make things work better on iOS?
     
  15. Aldo

    Aldo

    Joined:
    Aug 10, 2012
    Posts:
    173
    PunyOne I love you!!!

    I never thought about mono vs stereo

    Btw I heard that some devices might be stereo so this is what I did

    Code (CSharp):
    1. if(AudioSettings.driverCaps.ToString() == "Stereo")
    2.             midiStreamSynthesizer = new StreamSynthesizer(44100, 2, bufferSize, 40);
    3.         else
    4.             midiStreamSynthesizer = new StreamSynthesizer(44100, 1, bufferSize, 40);
     
    Last edited: Oct 18, 2014
  16. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    Here is a helper:
    Code (CSharp):
    1.     /// <summary>
    2.     /// General MIDI instrument, used in Program Change messages.
    3.     /// </summary>
    4.     /// <remarks>
    5.     /// <para>The MIDI protocol defines a Program Change message, which can be used to switch a
    6.     /// device among "presets".  The General MIDI specification further standardizes those presets
    7.     /// into the specific instruments in this enum.  General-MIDI-compliant devices will
    8.     /// have these particular instruments; non-GM devices may have other instruments.</para>
    9.     /// <para>MIDI instruments are one-indexed in the spec, but they're zero-indexed in code, so
    10.     /// we have them zero-indexed here.</para>
    11.     /// <para>This enum has extension methods, such as <see cref="InstrumentExtensionMethods.Name"/>
    12.     /// and <see cref="InstrumentExtensionMethods.IsValid"/>, defined in
    13.     /// <see cref="InstrumentExtensionMethods"/>.</para>
    14.     /// </remarks>
    15.     public enum Instrument
    16.     {
    17.         // Piano Family:
    18.        
    19.         /// <summary>General MIDI instrument 0 ("Acoustic Grand Piano").</summary>
    20.         AcousticGrandPiano = 0,
    21.         /// <summary>General MIDI instrument 1 ("Bright Acoustic Piano").</summary>
    22.         BrightAcousticPiano = 1,
    23.         /// <summary>General MIDI instrument 2 ("Electric Grand Piano").</summary>
    24.         ElectricGrandPiano = 2,
    25.         /// <summary>General MIDI instrument 3 ("Honky Tonk Piano").</summary>
    26.         HonkyTonkPiano = 3,
    27.         /// <summary>General MIDI instrument 4 ("Electric Piano 1").</summary>
    28.         ElectricPiano1 = 4,
    29.         /// <summary>General MIDI instrument 5 ("Electric Piano 2").</summary>
    30.         ElectricPiano2 = 5,
    31.         /// <summary>General MIDI instrument 6 ("Harpsichord").</summary>
    32.         Harpsichord = 6,
    33.         /// <summary>General MIDI instrument 7 ("Clavinet").</summary>
    34.         Clavinet = 7,
    35.        
    36.         // Chromatic Percussion Family:
    37.        
    38.         /// <summary>General MIDI instrument 8 ("Celesta").</summary>
    39.         Celesta = 8,
    40.         /// <summary>General MIDI instrument 9 ("Glockenspiel").</summary>
    41.         Glockenspiel = 9,
    42.         /// <summary>General MIDI instrument 10 ("Music Box").</summary>
    43.         MusicBox = 10,
    44.         /// <summary>General MIDI instrument 11 ("Vibraphone").</summary>
    45.         Vibraphone = 11,
    46.         /// <summary>General MIDI instrument 12 ("Marimba").</summary>
    47.         Marimba = 12,
    48.         /// <summary>General MIDI instrument 13 ("Xylophone").</summary>
    49.         Xylophone = 13,
    50.         /// <summary>General MIDI instrument 14 ("Tubular Bells").</summary>
    51.         TubularBells = 14,
    52.         /// <summary>General MIDI instrument 15 ("Dulcimer").</summary>
    53.         Dulcimer = 15,
    54.        
    55.         // Organ Family:
    56.        
    57.         /// <summary>General MIDI instrument 16 ("Drawbar Organ").</summary>
    58.         DrawbarOrgan = 16,
    59.         /// <summary>General MIDI instrument 17 ("Percussive Organ").</summary>
    60.         PercussiveOrgan = 17,
    61.         /// <summary>General MIDI instrument 18 ("Rock Organ").</summary>
    62.         RockOrgan = 18,
    63.         /// <summary>General MIDI instrument 19 ("Church Organ").</summary>
    64.         ChurchOrgan = 19,
    65.         /// <summary>General MIDI instrument 20 ("Reed Organ").</summary>
    66.         ReedOrgan = 20,
    67.         /// <summary>General MIDI instrument 21 ("Accordion").</summary>
    68.         Accordion = 21,
    69.         /// <summary>General MIDI instrument 22 ("Harmonica").</summary>
    70.         Harmonica = 22,
    71.         /// <summary>General MIDI instrument 23 ("Tango Accordion").</summary>
    72.         TangoAccordion = 23,
    73.        
    74.         // Guitar Family:
    75.        
    76.         /// <summary>General MIDI instrument 24 ("Acoustic Guitar (nylon)").</summary>
    77.         AcousticGuitarNylon = 24,
    78.         /// <summary>General MIDI instrument 25 ("Acoustic Guitar (steel)").</summary>
    79.         AcousticGuitarSteel = 25,
    80.         /// <summary>General MIDI instrument 26 ("Electric Guitar (jazz)").</summary>
    81.         ElectricGuitarJazz = 26,
    82.         /// <summary>General MIDI instrument 27 ("Electric Guitar (clean)").</summary>
    83.         ElectricGuitarClean = 27,
    84.         /// <summary>General MIDI instrument 28 ("Electric Guitar (muted)").</summary>
    85.         ElectricGuitarMuted = 28,
    86.         /// <summary>General MIDI instrument 29 ("Overdriven Guitar").</summary>
    87.         OverdrivenGuitar = 29,
    88.         /// <summary>General MIDI instrument 30 ("Distortion Guitar").</summary>
    89.         DistortionGuitar = 30,
    90.         /// <summary>General MIDI instrument 31 ("Guitar Harmonics").</summary>
    91.         GuitarHarmonics = 31,
    92.        
    93.         // Bass Family:
    94.        
    95.         /// <summary>General MIDI instrument 32 ("Acoustic Bass").</summary>
    96.         AcousticBass = 32,
    97.         /// <summary>General MIDI instrument 33 ("Electric Bass (finger)").</summary>
    98.         ElectricBassFinger = 33,
    99.         /// <summary>General MIDI instrument 34 ("Electric Bass (pick)").</summary>
    100.         ElectricBassPick = 34,
    101.         /// <summary>General MIDI instrument 35 ("Fretless Bass").</summary>
    102.         FretlessBass = 35,
    103.         /// <summary>General MIDI instrument 36 ("Slap Bass 1").</summary>
    104.         SlapBass1 = 36,
    105.         /// <summary>General MIDI instrument 37 ("Slap Bass 2").</summary>
    106.         SlapBass2 = 37,
    107.         /// <summary>General MIDI instrument 38 ("Synth Bass 1").</summary>
    108.         SynthBass1 = 38,
    109.         /// <summary>General MIDI instrument 39("Synth Bass 2").</summary>
    110.         SynthBass2 = 39,
    111.        
    112.         // Strings Family:
    113.        
    114.         /// <summary>General MIDI instrument 40 ("Violin").</summary>
    115.         Violin = 40,
    116.         /// <summary>General MIDI instrument 41 ("Viola").</summary>
    117.         Viola = 41,
    118.         /// <summary>General MIDI instrument 42 ("Cello").</summary>
    119.         Cello = 42,
    120.         /// <summary>General MIDI instrument 43 ("Contrabass").</summary>
    121.         Contrabass = 43,
    122.         /// <summary>General MIDI instrument 44 ("Tremolo Strings").</summary>
    123.         TremoloStrings = 44,
    124.         /// <summary>General MIDI instrument 45 ("Pizzicato Strings").</summary>
    125.         PizzicatoStrings = 45,
    126.         /// <summary>General MIDI instrument 46 ("Orchestral Harp").</summary>
    127.         OrchestralHarp = 46,
    128.         /// <summary>General MIDI instrument 47 ("Timpani").</summary>
    129.         Timpani = 47,
    130.        
    131.         // Ensemble Family:
    132.        
    133.         /// <summary>General MIDI instrument 48 ("String Ensemble 1").</summary>
    134.         StringEnsemble1 = 48,
    135.         /// <summary>General MIDI instrument 49 ("String Ensemble 2").</summary>
    136.         StringEnsemble2 = 49,
    137.         /// <summary>General MIDI instrument 50 ("Synth Strings 1").</summary>
    138.         SynthStrings1 = 50,
    139.         /// <summary>General MIDI instrument 51 ("Synth Strings 2").</summary>
    140.         SynthStrings2 = 51,
    141.         /// <summary>General MIDI instrument 52 ("Choir Aahs").</summary>
    142.         ChoirAahs = 52,
    143.         /// <summary>General MIDI instrument 53 ("Voice oohs").</summary>
    144.         VoiceOohs = 53,
    145.         /// <summary>General MIDI instrument 54 ("Synth Voice").</summary>
    146.         SynthVoice = 54,
    147.         /// <summary>General MIDI instrument 55 ("Orchestra Hit").</summary>
    148.         OrchestraHit = 55,
    149.        
    150.         // Brass Family:
    151.        
    152.         /// <summary>General MIDI instrument 56 ("Trumpet").</summary>
    153.         Trumpet = 56,
    154.         /// <summary>General MIDI instrument 57 ("Trombone").</summary>
    155.         Trombone = 57,
    156.         /// <summary>General MIDI instrument 58 ("Tuba").</summary>
    157.         Tuba = 58,
    158.         /// <summary>General MIDI instrument 59 ("Muted Trumpet").</summary>
    159.         MutedTrumpet = 59,
    160.         /// <summary>General MIDI instrument 60 ("French Horn").</summary>
    161.         FrenchHorn = 60,
    162.         /// <summary>General MIDI instrument 61 ("Brass Section").</summary>
    163.         BrassSection = 61,
    164.         /// <summary>General MIDI instrument 62 ("Synth Brass 1").</summary>
    165.         SynthBrass1 = 62,
    166.         /// <summary>General MIDI instrument 63 ("Synth Brass 2").</summary>
    167.         SynthBrass2 = 63,
    168.        
    169.         // Reed Family:
    170.        
    171.         /// <summary>General MIDI instrument 64 ("Soprano Sax").</summary>
    172.         SopranoSax = 64,
    173.         /// <summary>General MIDI instrument 65 ("Alto Sax").</summary>
    174.         AltoSax = 65,
    175.         /// <summary>General MIDI instrument 66 ("Tenor Sax").</summary>
    176.         TenorSax = 66,
    177.         /// <summary>General MIDI instrument 67 ("Baritone Sax").</summary>
    178.         BaritoneSax = 67,
    179.         /// <summary>General MIDI instrument 68 ("Oboe").</summary>
    180.         Oboe = 68,
    181.         /// <summary>General MIDI instrument 69 ("English Horn").</summary>
    182.         EnglishHorn = 69,
    183.         /// <summary>General MIDI instrument 70 ("Bassoon").</summary>
    184.         Bassoon = 70,
    185.         /// <summary>General MIDI instrument 71 ("Clarinet").</summary>
    186.         Clarinet = 71,
    187.        
    188.         // Pipe Family:
    189.        
    190.         /// <summary>General MIDI instrument 72 ("Piccolo").</summary>
    191.         Piccolo = 72,
    192.         /// <summary>General MIDI instrument 73 ("Flute").</summary>
    193.         Flute = 73,
    194.         /// <summary>General MIDI instrument 74 ("Recorder").</summary>
    195.         Recorder = 74,
    196.         /// <summary>General MIDI instrument 75 ("PanFlute").</summary>
    197.         PanFlute = 75,
    198.         /// <summary>General MIDI instrument 76 ("Blown Bottle").</summary>
    199.         BlownBottle = 76,
    200.         /// <summary>General MIDI instrument 77 ("Shakuhachi").</summary>
    201.         Shakuhachi = 77,
    202.         /// <summary>General MIDI instrument 78 ("Whistle").</summary>
    203.         Whistle = 78,
    204.         /// <summary>General MIDI instrument 79 ("Ocarina").</summary>
    205.         Ocarina = 79,
    206.        
    207.         // Synth Lead Family:
    208.        
    209.         /// <summary>General MIDI instrument 80 ("Lead 1 (square)").</summary>
    210.         Lead1Square = 80,
    211.         /// <summary>General MIDI instrument 81 ("Lead 2 (sawtooth)").</summary>
    212.         Lead2Sawtooth = 81,
    213.         /// <summary>General MIDI instrument 82 ("Lead 3 (calliope)").</summary>
    214.         Lead3Calliope = 82,
    215.         /// <summary>General MIDI instrument 83 ("Lead 4 (chiff)").</summary>
    216.         Lead4Chiff = 83,
    217.         /// <summary>General MIDI instrument 84 ("Lead 5 (charang)").</summary>
    218.         Lead5Charang = 84,
    219.         /// <summary>General MIDI instrument 85 ("Lead 6 (voice)").</summary>
    220.         Lead6Voice = 85,
    221.         /// <summary>General MIDI instrument 86 ("Lead 7 (fifths)").</summary>
    222.         Lead7Fifths = 86,
    223.         /// <summary>General MIDI instrument 87 ("Lead 8 (bass + lead)").</summary>
    224.         Lead8BassPlusLead = 87,
    225.        
    226.         // Synth Pad Family:
    227.        
    228.         /// <summary>General MIDI instrument 88 ("Pad 1 (new age)").</summary>
    229.         Pad1NewAge = 88,
    230.         /// <summary>General MIDI instrument 89 ("Pad 2 (warm)").</summary>
    231.         Pad2Warm = 89,
    232.         /// <summary>General MIDI instrument 90 ("Pad 3 (polysynth)").</summary>
    233.         Pad3Polysynth = 90,
    234.         /// <summary>General MIDI instrument 91 ("Pad 4 (choir)").</summary>
    235.         Pad4Choir = 91,
    236.         /// <summary>General MIDI instrument 92 ("Pad 5 (bowed)").</summary>
    237.         Pad5Bowed = 92,
    238.         /// <summary>General MIDI instrument 93 ("Pad 6 (metallic)").</summary>
    239.         Pad6Metallic = 93,
    240.         /// <summary>General MIDI instrument 94 ("Pad 7 (halo)").</summary>
    241.         Pad7Halo = 94,
    242.         /// <summary>General MIDI instrument 95 ("Pad 8 (sweep)").</summary>
    243.         Pad8Sweep = 95,
    244.        
    245.         // Synth Effects Family:
    246.        
    247.         /// <summary>General MIDI instrument 96 ("FX 1 (rain)").</summary>
    248.         FX1Rain = 96,
    249.         /// <summary>General MIDI instrument 97 ("FX 2 (soundtrack)").</summary>
    250.         FX2Soundtrack = 97,
    251.         /// <summary>General MIDI instrument 98 ("FX 3 (crystal)").</summary>
    252.         FX3Crystal = 98,
    253.         /// <summary>General MIDI instrument 99 ("FX 4 (atmosphere)").</summary>
    254.         FX4Atmosphere = 99,
    255.         /// <summary>General MIDI instrument 100 ("FX 5 (brightness)").</summary>
    256.         FX5Brightness = 100,
    257.         /// <summary>General MIDI instrument 101 ("FX 6 (goblins)").</summary>
    258.         FX6Goblins = 101,
    259.         /// <summary>General MIDI instrument 102 ("FX 7 (echoes)").</summary>
    260.         FX7Echoes = 102,
    261.         /// <summary>General MIDI instrument 103 ("FX 8 (sci-fi)").</summary>
    262.         FX8SciFi = 103,
    263.        
    264.         // Ethnic Family:
    265.        
    266.         /// <summary>General MIDI instrument 104 ("Sitar").</summary>
    267.         Sitar = 104,
    268.         /// <summary>General MIDI instrument 105 ("Banjo").</summary>
    269.         Banjo = 105,
    270.         /// <summary>General MIDI instrument 106 ("Shamisen").</summary>
    271.         Shamisen = 106,
    272.         /// <summary>General MIDI instrument 107 ("Koto").</summary>
    273.         Koto = 107,
    274.         /// <summary>General MIDI instrument 108 ("Kalimba").</summary>
    275.         Kalimba = 108,
    276.         /// <summary>General MIDI instrument 109 ("Bagpipe").</summary>
    277.         Bagpipe = 109,
    278.         /// <summary>General MIDI instrument 110 ("Fiddle").</summary>
    279.         Fiddle = 110,
    280.         /// <summary>General MIDI instrument 111 ("Shanai").</summary>
    281.         Shanai = 111,
    282.        
    283.         // Percussive Family:
    284.        
    285.         /// <summary>General MIDI instrument 112 ("Tinkle Bell").</summary>
    286.         TinkleBell = 112,
    287.         /// <summary>General MIDI instrument 113 (Agogo"").</summary>
    288.         Agogo = 113,
    289.         /// <summary>General MIDI instrument 114 ("Steel Drums").</summary>
    290.         SteelDrums = 114,
    291.         /// <summary>General MIDI instrument 115 ("Woodblock").</summary>
    292.         Woodblock = 115,
    293.         /// <summary>General MIDI instrument 116 ("Taiko Drum").</summary>
    294.         TaikoDrum = 116,
    295.         /// <summary>General MIDI instrument 117 ("Melodic Tom").</summary>
    296.         MelodicTom = 117,
    297.         /// <summary>General MIDI instrument 118 ("Synth Drum").</summary>
    298.         SynthDrum = 118,
    299.         /// <summary>General MIDI instrument 119 ("Reverse Cymbal").</summary>
    300.         ReverseCymbal = 119,
    301.        
    302.         // Sound Effects Family:
    303.        
    304.         /// <summary>General MIDI instrument 120 ("Guitar Fret Noise").</summary>
    305.         GuitarFretNoise = 120,
    306.         /// <summary>General MIDI instrument 121 ("Breath Noise").</summary>
    307.         BreathNoise = 121,
    308.         /// <summary>General MIDI instrument 122 ("Seashore").</summary>
    309.         Seashore = 122,
    310.         /// <summary>General MIDI instrument 123 ("Bird Tweet").</summary>
    311.         BirdTweet = 123,
    312.         /// <summary>General MIDI instrument 124 ("Telephone Ring").</summary>
    313.         TelephoneRing = 124,
    314.         /// <summary>General MIDI instrument 125 ("Helicopter").</summary>
    315.         Helicopter = 125,
    316.         /// <summary>General MIDI instrument 126 ("Applause").</summary>
    317.         Applause = 126,
    318.         /// <summary>General MIDI instrument 127 ("Gunshot").</summary>
    319.         Gunshot = 127
    320.     };
    321.  
     
    twobob likes this.
  17. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    Awesome. Can you confirm that it's a midi soundfont synthesizer, and that there is no possibility of DSP synthesis, making sine waves, for example 100 detuned sine waves is same as a gong :) I can actually make a C64 emulation program if i have an example of a 4 channel sine wave synthesis in Unity3d, I know the design, in terms of oscillator routing and CMOS filter emulation, but i don't know how to program a synth in Unity. some clues would be helpful.
     
  18. Doomlaser

    Doomlaser

    Joined:
    Dec 9, 2013
    Posts:
    24
    Anyone have any luck getting the attached code and project to build for the web player? It seems to work fine with the full .Net 2.0 API Compatibility level for standalone builds, but fails when I try to target the web.

    Any clue what's going on?

    Edit: Commented out all the InvalidDataException() calls in FMInstrument.cs and it appears to work. Cool!
     
    Last edited: Dec 12, 2014
  19. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    So, use 44100 as your frequency/sample rate BUT get the device audio buffer size from AudioSettings.

    public const int SAMPLE_RATE =44100;
    public const int CHANNELS =2;

    //***GetAudioSetting Data
    int xDSPBufferLength =-1;
    int xDSPBufferCount =-1;
    AudioSettings.GetDSPBufferSize(out xDSPBufferLength,out xDSPBufferCount);

    //***Make Synth
    synthesizer =new StreamSynthesizer(SAMPLE_RATE, CHANNELS, xDSPBufferLength,48);
     
  20. Stickworm

    Stickworm

    Joined:
    Apr 24, 2011
    Posts:
    67
    Hi is it possible to read the note data out without playing the midi file? So you could display a graph the notes to be played in advance? Otherwise I'll play the midi, record the notes as they go, then save them to a file to be graphed later but I thought there might be a cleaner, built in way? Cheers
     
  21. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    That's very cool Tom. I like that molecular music box approach.

    Are you doing anything more with this?
     
  22. Zild

    Zild

    Joined:
    Nov 30, 2012
    Posts:
    1
    I am trying to build an app that plays music written by the user in-app, and CSharpSynth seems the way to go about it - although possibly overkill.

    If anybody has any alternative suggestions I would love to hear them.

    If not - and assuming I make any progress at all - I might start another thread detailing the process and any issues involved, because I guess there has been some substantial development since this thread started.

    EDIT: First (probably really dumb) question:
    C# Synth Project targets .NET Compact Framework, and yet people seem to be using the Unity port here (and presumably the Unity port on the original project) to target iOS and Android devices - which I always presumed did not run .NET. Did I miss the part where Microsoft, Google and Apple all started playing nicely?! Or am I misunderstanding something fundamental here?

    (I am also a little concerned as I see no mention of Unity, iOS or Android on the C# Synth Project CodePlex site...)
     
    Last edited: Apr 15, 2015
  23. holomorfo

    holomorfo

    Joined:
    Jul 31, 2014
    Posts:
    1
    Hi sonicviz!

    I'm using your $UnitySynth.unitypackage. In my unity project, but there appears to be a problem with the instruments and banks that I cant figure out. I get the error
    NullReferenceException: Object reference not set to an instance of an object
    CSharpSynth.Synthesis.Voice.Start (Int32 channel, Int32 note, Int32 velocity)

    at
    attack = inst.getAttack(note);
    in CSharpSynth.Synthesis
    Voice

    I think the problem is at loading the Banks, could you give me some advice please?
     
  24. acorrow

    acorrow

    Joined:
    Jan 4, 2015
    Posts:
    32
    This is such a great asset. One question though. I seem to be having trouble finding other SFZ formatted instruments. Does anyone have any info on any quality ones that are free? I've been to every site out there with a million things listed, so I'm hoping for more than just a general site to go visit.

    I tried using sfZed to convert a SountFont instrument, however the resulting sfz file looks like it has letters for the hi/lo keys (c1 - f#1, etc etc). Makes sense, but I'm not entirely sure how to get them into the right format. Any thoughts on this? Thanks again!
     
  25. acorrow

    acorrow

    Joined:
    Jan 4, 2015
    Posts:
    32
    Here's another question now that I have found the SFZ files I want/like...

    Anyone have any idea how one would go about hooking up a listener to tell me what instrument is currently being loaded? It write to the Debug console, and I can see where that happens, but because of how they are loaded I don't see how you could get a listener from outside that class to get notified of the event. Any thoughts?

    Thanks
     
  26. Cuicui_Studios

    Cuicui_Studios

    Joined:
    May 3, 2014
    Posts:
    72
    Hi!!

    First thanks for all this work, it´s amazing!!! But I need to ask something.
    I´m using your plugin to read a midi file just NoteOn and NoteOff and the note itself. Diferent notes instantiate different objects, and every thing works fine on the computer. But iOS, reads the midi file too slowly. I set a timer to look for errors and I saw that the computer reads the midi file twice faster than the iPad.

    Does any one know why this happens?

    Thanks so much!!
     
  27. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    I know this is old thread but it works fine in Unity 5.1.1free1.

    What I want to do is for the midi event (note on and note off) to trigger an event.
    In this example, I simply make it to scale the cube to 10.
    And reset the size when the note off event.

    How I do it, I simply pass a value to global variable name, NoteOn.

    Then on the cube I make a script that read the change of the NoteOn in On Update.

    But it comes out like this.

     
  28. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    Hi, does your event create latency like what I experience in my video?
     
  29. Kluzowicz

    Kluzowicz

    Joined:
    Nov 26, 2014
    Posts:
    1

    Hi,

    I have this same problem. When I play midi on Mac or in Editor everything is ok. But when I build on iOS or Android then midi play very slow.

    Before that I has problem with sound quality on Android, but tempo was good

    Before I have:

    Code (CSharp):
    1.  
    2. midiStreamSynthesizer = newStreamSynthesizer (44100, 2, bufferSize, 40);
    3.  
    And now:

    Code (CSharp):
    1.  
    2.  
    3. publicconstintSAMPLE_RATE =44100;
    4. publicconstintCHANNELS =2;
    5.  
    6. intxDSPBufferLength =-1;
    7. intxDSPBufferCount =-1;
    8. AudioSettings.GetDSPBufferSize(outxDSPBufferLength,outxDSPBufferCount);
    9.  
    10. midiStreamSynthesizer = newStreamSynthesizer(SAMPLE_RATE, CHANNELS, xDSPBufferLength,48);
    11.  
    After that change quaility is good, but tempo is wrong.

    Anyone has an idea what's wrong?
     
  30. PaulForestTVO

    PaulForestTVO

    Joined:
    Dec 15, 2016
    Posts:
    1
    Hey all,

    Has anyone had luck changing tempo programmatically with any of these frameworks?

    I've tried this with several variations of UnitySynth, CSUnitySynth, CSharpSynth etc and the tempo change doesn't seem to have an impact. I suspect I'm calling something incorrectly. Or perhaps it hasn't come up as a use case yet.

    Here's what I have so far:

    Code (CSharp):
    1.             float tempo = 20;
    2.             MidiEvent tempoChange = new MidiEvent();
    3.             tempoChange.midiMetaEvent = MidiHelper.MidiMetaEvent.Tempo;
    4.             tempoChange.Parameters[0] = MidiHelper.MicroSecondsPerMinute / tempo;
    5.             tempoChange.Parameters[4] = 3; // magic MIDI format requirement, seems to always be present for tempo events
    6.             midiSequencer.ProcessMidiEvent(tempoChange);
    7.  
    Stepping through the code that is downstream of midiSequencer.ProcessMidiEvent(), the BeatsPerMinute property in the MidiFile instance gets called, but that doesn't seem to get used once playback has begun.

    So MidiSequencer.DeltaTimetoSamples() uses _MidiFile.BeatsPerMinute, but only in its LoadMidi() call.

    I'm thinking that in response to tempo changes the sequencing data's timing needs to get updated for all remaining events. Perhaps the remaining events in MidiTrack.MidiEvents should get updated.
     
  31. UDN_e7666fec-2cb5-4cfe-a678-e5e5ba6ec4ce

    UDN_e7666fec-2cb5-4cfe-a678-e5e5ba6ec4ce

    Joined:
    Jul 21, 2017
    Posts:
    8
    How to convert mid file to mid.txt file
     
  32. UDN_e7666fec-2cb5-4cfe-a678-e5e5ba6ec4ce

    UDN_e7666fec-2cb5-4cfe-a678-e5e5ba6ec4ce

    Joined:
    Jul 21, 2017
    Posts:
    8
    midi file problem, change the extension can be