Skip to content

Instantly share code, notes, and snippets.

@rebolek
Created November 25, 2015 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rebolek/80a93d56f6478f1fb0c5 to your computer and use it in GitHub Desktop.
Save rebolek/80a93d56f6478f1fb0c5 to your computer and use it in GitHub Desktop.
Red [
Title: "Sintezar PM-102 - Phase Manipulation Digital Sintesizer"
Name: 'PM-102
Version: 0.4.0
Needs: 'View
; Date: 25-11-2015
File: %pm-102.red
Author: "Boleslav Březovský"
; Email: rebolek@gmail.com
]
rate: 44100.0
osc: context [
pitch: 261.63
phase: 0.0
]
sine-osc: func [osc [object!]] [sine 360 * osc/phase]
inc-phase: func [
osc [object!]
step [float!]
] [
osc/phase: osc/phase + step
if osc/phase > 1.0 [osc/phase: osc/phase - 1.0]
osc/phase
]
make-sound: func [
osc [object!]
size [integer!]
/local
wave-length [float!]
sample-length [integer!]
freq [float!]
step [float!]
] [
wave-length: rate / osc/pitch
freq: rate / wave-length
sample: make vector! reduce ['float! 64 size]
step: osc/pitch / rate
repeat mark size [
sample/:mark: sine-osc osc
inc-phase osc step
]
sample
]
preview-sample: func [
sample [vector!]
/local
image [image!]
width [float!]
height [float!]
step [float!]
index [float!]
position [integer!]
] [
image: make image! 200x100
width: to float! image/size/x
height: to float! image/size/y
step: width / (length? sample)
index: 0.0
foreach value sample [
value: value + 1.0 / 2.0
position: 1 + to integer! (round height - 1 * value) * width + index
image/:position: white
index: index + step
]
image
]
img: preview-sample make-sound osc 100
pm-ui: [
title "Sintezar PM-102"
button "make sound" [
loop 100000 [
osc/pitch: osc/pitch * 1.0001
img: preview-sample make-sound osc 100
i/image: img
show i
]
]
i: image 200x100 img
]
view pm-ui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment