필터 지우기
필터 지우기

Saving .wav file

조회 수: 6 (최근 30일)
TAN KYE JYEN
TAN KYE JYEN 2021년 5월 9일
댓글: Rik 2021년 5월 10일
Hi everyone, recently I designed a song maker using GUIDE and was required to simple music notes into the song maker. I tried to save the notes into a .wav file but was having problem as the notes keep replacing existing notes, thus only one latest note was successfully saved. May I know how to save few notes into a single .wav file? Attached is the code I wrote for the note 'A' the audiowrite function was used. Thanks in advance :)
% --- Executes on button press in A1.
function A1_Callback(hObject, eventdata, handles)
Fs=8000;
Ts=1/Fs;
t=[0:Ts:3];
F_A=440;
A=sin(2*pi*F_A*t);
sound(A,Fs);
filename = ('C:\Users\Song.wav');
audiowrite(filename,A,Fs);
clear A Fs
% hObject handle to A1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

채택된 답변

Rik
Rik 2021년 5월 9일
You're overwriting the song every time this callback is triggered. You should probably store each note to a field of your guidata struct to be able to write your sequence of notes to a wav file.
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
You should also consider moving most of this code to a separate function. The only thing specific to this note is the frequency, so you should probably use a separate function that accepts the frequency and the handles struct as inputs. That will also allow you to change the path to which the file is written more easily.
  댓글 수: 2
TAN KYE JYEN
TAN KYE JYEN 2021년 5월 10일
Thanks. Btw how can I store each note to a field of a guidata struct?
Rik
Rik 2021년 5월 10일
Did my answer help you solve your problem? If so, please consider marking my answer as accepted answer.
What did you try? Do you understand how guidata works? Did you read the thread I linked?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by