MATLAB Answers

ADSR envelope: Digital synthesizer

44 views (last 30 days)
Erdal Yegenaga
Erdal Yegenaga on 1 Nov 2020
Commented: Erdal Yegenaga on 5 Nov 2020
clear ;
close all;
fs=8500;
t=0:0.000117:3;
note_do= sin(2*pi*261.6*t);
note_re= sin(2*pi*293.7*t);
note_mi= sin(2*pi*329.6*t);
note_fa= sin(2*pi*349.2*t);
note_sol= sin(2*pi*392*t);
note_la= sin(2*pi*440*t);
note_si= sin(2*pi*493.9*t);
note_do1= sin(2*pi*523.5*t);
y=note_do;
A = linspace(0, 0.9, (length(y)*0.10)); %rise 35% of signal
D = linspace(0.9, 0.7,(length(y)*0.05)); %drop of 5% of signal
S = linspace(0.7, 0.7,(length(y)*0.40)); %delay of 40% of signal
R = linspace(0.7, 0,(length(y)*0.20)); %drop of 25% of signal
ADSR = [A D S R] ;
x = zeros(size(y));
x(1:length(ADSR)) = ADSR;
tone=y.* x;
sound(tone,fs);
I wrote this codes it successfully run but i want to assign notes to keys to each musical notes for my digital synthesizer project. Like in computer keyboard if user press A key its plays note_do etc. Can you help me this part i am new to matlab?

  0 Comments

Sign in to comment.

Answers (1)

Maadhav Akula
Maadhav Akula on 4 Nov 2020
Hi,
I believe you want to play note_do when user clicks on key A on their computer keyboard, in that case you can utilize the callback functions to capture the key pressed data from the user and write conditional statements using if-else statements or switch cases in your callback as per your requirements.
Have a look at this answer:
Hope this helps!

  1 Comment

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!