Playing a Music File from Matlab

In summary, the conversation is discussing how to use the audioplayer function in MATLAB to play a song as an alert when a calculation has converged. The example provided is loading and playing Handel's "Hallelujah Chorus," but the person is unsure of how to apply it to their specific problem. They are open to suggestions for a song to play and mention the option to write their own music using MATLAB or use the pre-loaded Handel example.
  • #1
brydustin
205
0
I would like to run a calculation so that when it has converged, a song will play... to alert me from the other room (for example).

http://www.mathworks.co.uk/help/techdoc/ref/audioplayer.html

I found this but can't quite put it together? Their example was:

Examples

Load and play a sample audio file of Handel's "Hallelujah Chorus:"

load handel;
player = audioplayer(y, Fs);
play(player);

I'm not clear on this... Okay, so any explanations greatly appreciated; also, you are welcome to suggest a tune to play once convergence is met (its a non-linear least squares problem, maybe it will inspire the tune :O)
 
Physics news on Phys.org
  • #2
sound(y,Fs)

where y is the wavefile you want to play and Fs is the sample rate.

you can write your own music:
http://www.lifeorange.com/MATLAB/MATLAB_music.htm

or you can load the handel edxample that comes with matlab, which comes with its own "y" and "Fs"

load handel.mat;
sound(y, Fs);
 

Related to Playing a Music File from Matlab

1. How do I play a music file from Matlab?

To play a music file from Matlab, you can use the audioplayer function. First, you will need to read the audio file using the audioread function and store it in a variable. Then, you can create an audioplayer object with the audio data and use the play function to play the file.

2. Can I play multiple music files simultaneously in Matlab?

Yes, you can play multiple music files simultaneously in Matlab by creating separate audioplayer objects for each file and using the play function for each object.

3. How can I change the volume or speed of a music file in Matlab?

You can use the set function on the audioplayer object to change the volume or speed of a music file. For volume, you can use the Volume property and for speed, you can use the SampleRate property.

4. Is it possible to pause or resume playing a music file in Matlab?

Yes, you can use the pause and resume functions on the audioplayer object to pause or resume playing a music file in Matlab.

5. Can I play a specific section of a music file in Matlab?

Yes, you can use the audioplayer object's CurrentSample property to specify the starting point of the section you want to play and use the play function to start playing from that point. You can also use the TimerFcn property to specify a specific ending point for the section.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
48K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
7K
Back
Top