Vous êtes sur la page 1sur 9

MusicBoxGenerationfromMIDIs

6.S079FinalProjectReport
TiffanyLuandTrevorWalker

Motivation

Theproblemwearetacklingwithourfinalprojectisallowinguserstogeneratecustommusic
boxesbysimplyuploadingaMIDImusicfilecontainingthemelody.Thekeygoalsinthistask
aretodecreasethecosttotheuserofcreatingacustommusicboxandtomakeiteasierto
generateboxesbyallowingausertouploadthedesiredsonginsteadofhavingtomanually
inputeachnoteandtherhythmswhilestillmaintaininggoodsoundquality.

Thecustom3Dprintedmusicboxwassuggestedinclass,butthereweretwomainproblems
withit.First,inputtingthesongforthemusicboxwasveryclunkyandinvolvedmanually
specifyingeachnoteandwhenitshouldappearonthecylinder.Second,thefully3Dprinted
boxdidnotsoundverygoodduetotheplasticsthinsound.Weplantodesignanewsystem
thataccountsforboththeseproblemsbyallowinguserstouploadMIDIfilesinsteadof
manuallyinputtingthenotes,andbyproducingavectorfiletocutthecomboutofstainless
steelratherthanprintitinplastic,forbettersoundquality.

TechnicalApproach

Inordertogeneratethecustommusicboxes,webuiltaJavaScriptwebapplicationthat
allowstheusertouploadaMIDIfileandoutputs.STLand.DXFfilesfor3Dprintingandlaser
cutting.Therearefourmaincomponentstooursystem:theJavaScriptMIDIparser,the
cylindergeneration,thecombgeneration,andthephysicalboxassembly.Theweb
applicationprovidesaninterfacethatallowsuserstouploadaMIDIfileandthensubsequently
viewanddownloadthegeneratedfiles.

MIDIParser
TheroleoftheJavaScriptMIDIparseristoextracttherelevantnoteandtimingdatafromthe
MIDIfiletopasstoboththecylinderandcombmodules.Thewebapplicationprovidesan
inputfieldfortheusertouploadafile,andoncechosen,itisreadasabinarystringandfed
intoaJavaScriptMIDIparsercalledjasmid[1].Theparsersurfacesaheaderportionofthe
MIDIfile,whichcontainstheMIDIformat,numberoftracks,andthetiminginterval,aswellas
atracksportionofthefile,whichcontainstheactualnotedata.Thetracksproperty
containsalistofeventsforeachtrack.WeuseonlytheMIDInoteoneventtosignifywhena
noteshouldbeplayed,ignoringthenoteoffandothereventsbecauseamusicboxcannot
sustainnotesorchangemodes.

Togeneratethecomb,werequirealluniquenotesthatareplayedthroughthewholesong,so
weiteratethroughthenoteoneventstogathertheuniqueMIDInotenumbers.Togenerate
thecylinder,werequire[combtinenumber,timing]pairs.Weusethelistofuniquenotesto
getthecombtinenumbers,andtogetthetiming,eacheventalsohasadeltatimeproperty,
whichindicatesthetimebetweenthecurrenteventandthelast,sowebuildthe[combtooth
number,timing]pairsbyaccumulatingthosedifferences.Thesetwoarraysarepassedonto
theirrespectivemodules.

Comb
ThecombcomponentisaOpenJsCad[2]routinethattakesinthelistofuniquenotesinthe
songintheMIDInotenumberformatandoutputsa.DXFfileforlasercutting.Thelengthsof
theteethonthecombarecalculatedbytakingtheMIDInotenumbersandconvertingthemto
frequency,andusingthefollowingequationtocalculatethelength:

L =
0.162

a
f
Y
d

whereaisthickness,fisfrequency,YistheYoungsmodulus,disdensity,andListhe
length.Forthestainlesssteelthecombiscutoutof,theconstantsare:
a=0.036in
3
d=0.289lbs/in
7
Y=2.85x10 ksi

Cylinder
ThecylindercomponentisanotherOpenJsCad[2]routine,whichtakesinthe[combtooth,
timing]pairsasdescribedaboveandgeneratesa3Dprintablecylinder(.STL)withpinsinthe
correspondinglocations.Thespacingbetweenthepinsbothalongandaroundthecylinderis
variableanddependsonthelengthofthesongandthenumberofuniquenotesthesong
contains.

Wecalculatethespacingofthepinsaroundthecylinderusingthelengthofthesongandthe
circumferenceofthecylinder,andwecalculatethespacingofthepinsalongthecylinder
usingthenumberofuniquenotesthesongcontains.Toplacethepinsonthecylinder,we
iteratethroughthearrayofpairsandcalculatetheangleoffsetsaroundthecylinder
dependingonthetiming.

Thepseudocodeforthepinplacementaroundthecylindercanbeseenbelow.

notes=[[tinenumber,time],...]
hSpacing=2*PI*radius/songLength
//horizontalspacingpertimeunit
vSpacing=height/numNotes
//verticalspacingfordifferentnotes

function
placePins(){
pins=[]

for
(i=0i<notes.lengthi++){
tineNumber=notes[0]
time=notes[1]
angleOffset=hSpacing*time/radius
//calculatedusingarclength

//translatetoedgeofcylinder
x=cos
(angle)*radius
y=sin
(angle)*radius
z=tineNumber*vSpacing

//applytransformations
p=pin
()
p=p.rotateZ
(angle)
p=p.translate
([x,y,z])

pins.push(p)
}
return
pins
}

MusicBoxAssembly
TheboxcomponentisdesignedstaticallyasaCADfile,whichprovidesslotstoinsertthe
cylinderandcomb.Theboxusesawormdriveattachedtoacranktoturnthecylinder.Each
partisdesignedtobepressfittotheotherparts,sothatthepartsareabletoturn,andso
differentcylindersandcombscanbeinterchangedfordifferentsongs.

Tobuildthephysicalbox,thestaticboxpartsandthecylinderare3Dprinted,whilethecomb
islasercutfromstainlesssteel.

Results

ThewebapplicationallowsuserstodownloadthestaticmusicboxpartsinaZIP,andto
uploadaMIDIfiletogenerateadownloadableSTLandDXF.Screenshotscanbeseenin
Figure1,andtheactualapplicationishostedat
https://tweilu.scripts.mit.edu/musicbox
.

Figure1.Screenshotsofthewebapplicationscylinderandcombgeneration.

ArenderofthestaticmusicboxdesignisshowninFigure2,andanexamplegenerated
cylinderisshowninFigure3.


Figure2.Staticmusicboxrender.


Figure3.ParametricallygeneratedcylinderfortheHarryPottertheme.


Figure4.Final3Dprintedmusicboxwithlasercutsteelcomb.

ThefinalassembledmusicboxcanbeseeninFigure4.Thebox,boxmechanisms,and
cylinderwere3DprintedontheStratasysuPrintSE,andeachprintjobtookbetween3and
10hours.ThestainlesssteelcombwaslasercutandorderedfromPololu[3].However,the
1mmthicksteelwastoothickfortheplasticpinsonthecylindertopluckwithoutbreaking,so
we3DprintedcombsatthelastminuteforthedemoasseeninFigure5.


Figure5.3DprintedcombsfortheHarryPottertheme.

Avideoofthemusicboxinactionwiththeplasticcombcanbeviewedat
http://youtu.be/SXzM4Clmdk4 .Thevideoshowsthelackofpitchassociatedwiththeplastic
comb.Theplasticcombisalsoalotlessdurablethanthesteelcomb.Figure5showsafew
ofthetinesbrokeoff.

Despitethesteelthicknessissue,westilltestedthesteelcombspitchaccuracytoverifyour
combgenerationprocess.Werecordedthefrequencyofeachofthetinesandcompareditto
thedesiredfrequency.TheresultsfromthistestcanbeseeninTable1.Onceadjustedfor
theoctavedifference,theerrorbetweenthedesiredandmeasuredfrequenciesisextremely
lowasdemonstratedinbothTable1andFigure6.

Table1:Frequencyofcombteeth,comparedwithidealvalues
MIDI Fundamentalfrequency Measuredpeak Harmonicadjustederror
note Pianokey (Hz) frequency(Hz) (semitones)
41 F 87.30705786 1457 0.3204487125
43 G 97.998859 1697 0.3193795372
48 C 130.8127827 2122 0.2381907287
52 E 164.8137785 2578 0.391877982
55 G 195.997718 2115 0.3321926099
57 A 220 3646 0.4406845048
60 C 261.6255653 3662 0.003582717419
62 D 293.6647679 4870 0.4293979737
64 E 329.6275569 4922 0.0786564001
65 F 349.2282314 4919 0.1052164497
67 G 391.995436 5550 0.1946890465
69 A 440 5696 0.07279200839


Figure6.Plotofmeasuredfrequency(points)againstthedesiredfrequency(line).

Duetotimeconstraints,wewereunabletoproduceasecondrefinedversionofthemusic
box.The3DprintingtookmorethanaweekbecauseoffailedMakerBotjobsandbecause
ourpartswerefairlylarge.WeendedupprintingonthenewStratasysuPrint,whichwas
muchmorereliable,buteachjobstilltookbetween3and10hours.Additionally,becausewe
didnothaveaccesstoalasercutterthatcouldcutsteel,weorderedourcustomcombsfrom
Pololu[3],andtheytookaweektoarrive.Soafterwediscoveredthatthe1mmthicksteel,
whichworkswellwithtraditionalmusicboxes,wouldnotworkwithourprintedbox,therewas
notenoughtimetoorderanothersetofcombsonthinnersteel.

PotentialExtensions

Thereareanumberofpossibleextensionstothisprojecttoenhancetheuserexperience.
First,thesteelcombwouldbeinsteadcutoutof,perhaps,0.5mmsteel,sothattheplastic
pinsonthecylinderareabletopluckthemwithoutbreaking.Thiswouldbethebiggest
improvementforthemusicbox.

Second,themusicboxesarecurrentlylimitedtoapproximately30secondsofmusicbecause
ifthesongisanylonger,thepinsonthecylinderforfastrepeatednotesgettooclose
together.Thiscouldbepossiblysolvedintwowaystoallowforlongersongs.Theradiusof
thecylindercouldbeadjustedtofitthesonglengthsuchthatthedistancebetweennotesis
larger.Thiswouldrequiretheboxtobecomeparametricaswellasitwouldneedtoadjustto
thesizeofthecylinder.Theotheroptionistoaddinthepossibilityofhavingmorethanone
tineofthesamenoteonthecombsuchthatrepeatednotescouldbeplayedondifferent
tines,andthedistancebetweenthenoteswouldnolongerbeaproblem.Thesecondoption
wouldlikelybemorefavorableasitdoesnotrequirethemusicboxtochangesize.

Third,theprocessof3Dprintingthemusicboxesfordemonstrationwastheslowestpartof
theproject.Thepartswereprintedinseparatejobsoverthecourseof4to5days,some
takingupto10hours.Thiscouldpossiblybeavoidedbyusingalternativemanufacturing
processesforsomeofthecomponents.Forexample,thestaticboxmodelwasthelargest
piecetoprint.Theboxcouldinsteadbelasercutoutofacrylic,whichwouldgreatlyreduce
thetotalrequiredprintingtime.Thegearsandcylinderswouldstillneedtobe3Dprinted,but
thisalternativewoulddefinitelyspeeduptheactualmusicboxassembly.

Finally,itcouldbeinterestingtoprovidemoreoptionstotheuserforgeneratingand
assemblingtheircustommusicboxes.Whileourprojectwantedthemusicboxestousesteel
combsforincreasedsoundquality,someusersmaywanttojust3Dprintthewholething,so
thesystemcouldprovidetheoptionfortheusertochoosewhatmaterialeachcomponent
shouldbe.Thescripttogeneratetheplasticcombisalreadyimplementedbecauseofthe
issuewiththesteelcomb,sothisextensionwouldjustrequiremoreoptionsontheweb
interface.Moreunrelated,butstillinteresting,theapplicationcouldalsoprovidemoreinput
optionstothesystemforwhichpieceofmusictheboxshouldplay.Forexample,insteadof
requiringtheusertouploadasetlengthsong,theinterfacecouldprovidetheuserwithaway
tocutthesongbeforegeneration.Anotherideacouldbethattheusercouldplaynotesina
virtualkeyboard,andthesystemcouldoutputtheirowncustomsong.

Overall,thesystemcouldusesometweakstomakeitmorerobustandgivemoreflexibilityto
theuser.

Conclusion

Theresultingsystemprovidesuserswithaneasywaytodesigncustommusicboxesthat
theycanassemblethemselvesthoughtherearestillsomeinterestingoptionsavailablefor
givingtheusermoreflexibility.Theproducedphysicalmusicboxhaslowsoundqualitydueto
theplasticcomb,butbasedonouranalysisoftheoutputfrequenciesproducedbythesteel
comb,thesoundqualityoffutureiterationsoftheboxwouldlikelybecomparabletothatof
traditionalmusicboxes.

Tools&Packages

[1]Jasmid.https://github.com/gasman/jasmid .
[2]OpenJsCad. https://github.com/joostn/OpenJsCad
.
[3]Pololu.
https://www.pololu.com/ .

Vous aimerez peut-être aussi