</svg></div>
[julialang.org](http://julialang.org)
{jiahao,kfischer}@csail.mit.edu
In [1]:
using AudioIO, SIUnits, SIUnits.ShortUnits #Load some Julia packages
immutable note{T<:Real} #A user-defined data type
pitch::quantity(T, Hz) #This field has units of Hz
duration::quantity(T, s)
timbre::Function #This field is a function
end
#Generate a time-domain sample of a sound wave
function waveform{T<:Real}(A::note{T}; samplingrate::quantity(T, Hz)=44100.0Hz)
Float32[A.timbre(2π*A.pitch*t) for t in 0s:1/samplingrate:A.duration]
end
Out[1]:
In [3]:
#AudioIO knows how to play a waveform using libportaudio
import AudioIO.play
#Now we define what it means to play a note
play(A::note)=play(waveform(A))
play(note(440.0Hz, 2.0s, x->sin(x)+0.1*sin(2x)+0.01*sin(4x)))
Out[3]:
In [38]:
phase{T}(pitch::quantity(T, Hz), duration::quantity(T, s)) = pitch*duration
code_native(phase, (quantity(Float32, Hz), quantity(Float32, s)))
In [15]:
#This calls libc's getenv() to query the SHELL environment variable
myshell = ccall((:getenv, "libc"), Ptr{Uint8}, (Ptr{Uint8},), "SHELL")
Out[15]:
In [16]:
bytestring(myshell) #C string -> Julia string
Out[16]:
Others have built upon ccall to provide further interoperability with