Saving .wav file
7 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!