matlab - Transform note to pitch and get the audio signal -
there pitch , duration , sample rate fs "pitch" vector of note pitch in semitones (with 0 indicating silence), "duration" vector of note duration in seconds, "fs" sample rate of output wave signals playback.
pitch= [55 55 55 55 57 55 0 57 60 0 ]; duration=[23 23 23 23 23 35 9 23 69 18 ]/64; fs=16000;
i want use above info return audio signal in matlab. can teach me?
thx
this requires thought , might take time write down before working.
personally, i'd split task multiple functions in mind involve:
1. semitone frequency 2. time sample number 3. frequency , sample number output waveform
and if possible should add array involves level further progress later on/ helps simplify problem stages.
as im not sure semitone scaling using have confirm need sort of converter/look table (formulas according physics of music website):
function [frequency] = semitone2frequency(semitone) %your input how many semitones above middle c note frequency = 440*((2^(1/12))^semitone); % 440 hz middle c end
this based on equal tempered scale. know frequency of notes generate sound, wait theres more....
now can calculate time of each sound in samples writing function...
function [nsamples] = time2samples(time, fs) dt = 1/fs; nsamples = time*dt; end
now have both of these values can generate audio signal!
frequency = semitone2frequency(55); %55 semitones above middle c nsamples = time2samples(2,16000); %how many samples need play 2 seconds %generate time array 0 how long want sound time = 0:1:nsamples; %starts @ 0 increases 1 sample each time until 2 seconds worth of samples %create output waveform! outputaudio = sin(2*pi*frequency.*time);
this create array play sound note 55 semitones greater middle c (not sure note is) 2 seconds. listen using:
sound(outputaudio, 16000);
you can build on create multiple sounds 1 after other (i recommend creating 1 master function lets pass arrays in , outputs 1 audio waveform), should enough create semitones given durations!
p.s. make level 0 @ time multiply outputaudio variable 0
outputaudio = outputaudio.*0; %the . in .* important!
or further control multiply level between 0 , 1 complete volume control.
i hope enough! luck.
Comments
Post a Comment