Hi all
I wrote a short program that displays an avi file. I need the program to get input from the keyboard while the movie is running (and not after it ends):
this is my code:
figure('MenuBar','none')
set(gcf,'Color', 'white')
set(gca,'Color','white');
set(gca,'XColor','white');
set(gca,'YColor','white');
m=aviread('c:/t1.avi')
a=30:1:100;
b=100:-1:30;
c=[a b a b a b a b a b] %to run the movie back and forth
movie(m,c) %runs the movie
Thank you for any help
Ariel
Maybe you can insert your video in an UIPanel (or another suitable GUI item) and use the KeyPressFcn callback.
Have a look on this : Callback Sequencing and Interruption (I don't know if it can works but it's probably worth trying).
As far as I know multi-threading or parallel processing capabilities in MATLAB are limited; however it appears as there are remedies. This article describes combining MATLAB and C++ code, with use of MEX files.
Now I have to admit that I have never tried this so I can't really claim that it would work in your case, but it would be a good place to start.
Unless movie() has been designed to watch for input I think you will have to multithread, which from one of the other answers sounds a bit complicated.
You could play a short section of the video, then run come code to check for inputs and then play the next bit of the video. I'm not sure if you can count on things that the user types whilst the video plays going into the input buffer though.
the solution is to use winopen('c:/filename.avi')
winopen('c:/filename.avi')
this command opens media player and runs following commands in the matlab script. it doesn't wait for the movie to end. it runs in the background.
thanks every one
ariel
Related
This question already has an answer here:
Synthesia plays well midi file without any note off event?
(1 answer)
Closed 5 years ago.
I made a system that takes MIDI files and creates a graphical representation of the music.
Every NoteOnEvent is when a single note starts, and every NoteOffEventwith the same note code is when it ends.
This works well for most MIDI files.
However, I am now encountering files that do not have NoteOffEvent events at all, and so I keep playing them.
What is the correct behavior when seeing for example:
midi.NoteOnEvent(tick=0, channel=0, data=[65, 127])
midi.NoteOnEvent(tick=240, channel=0, data=[65, 0])
I think if a note "on" event happens on the same note it should be like a toggle event, but I am not sure what if it is justified, or does this even happen for every midi file or just a subset that act like this?
EDIT:
I don't think this matters, but I am using python-midi to extract the tracks from midi files
It is common for a note on with 0 velocity to be interpreted as note off. I am not sure if it's part of the standard or not.
I have question about queueing buffers in OpenAL.
I have two wave files, let's say for an engine. The first is the sound of the engine starting and the second is the engine running.
What I'm looking for is a way to create a source that plays sound 1 once and then loops sound 2 until alSourceStop() is called.
Is something like this even possible?
Thanks for your help :)
Hans
Here is come code where I stream audio using OpenAL ... the salient line is
alSourcei(streaming_source[ii], AL_BUFFER, 0);
its written for linux so OSX may require a tweak to header file locations :
https://github.com/scottstensland/render-audio-openal
let me know if your need anything explained ... enjoy
Is there a way to limit the amount of time an evaluation is allowed to run? Or limit the amount of memory that MatLab is allowed to take up so it doesn't freeze my laptop?
Let's answer your questions one at a time:
Question #1 - Can I limit the amount of time MATLAB takes to execute a script?
As far as I know, this is not possible. If you want to do this, you would need a multi-threaded environment where one thread does the actual job while another thread keeps an eye on the timer... but even with that functionality, AFAIK, MATLAB does not have this supported. The only way to stop your script from running is if you punch Ctrl + C / Cmd + C. Depending on what is actually being executed... for example a MEX script or a LAPACK routine, or just a simple MATLAB script, it may work by just pushing it once... or you may have to mash the sequence like a maniac.
(Note: The above image was introduced to try and be funny. If you don't know where that image is from, it's from the movie Flashdance and one of the songs from the soundtrack is She's a maniac, where I've also provided a YouTube link to the song above.)
See this post for more details: How can I interrupt MATLAB when it gets really really busy?
Question #2 - Can we limit the amount of memory that MATLAB uses?
Yes you can. From what I have seen in your posts, you're using Windows. You can change this by changing the page size of the virtual memory that is used for your computer. Specifically, instead of allowing it to grow dynamically, you could set it to be a certain size and once MATLAB exhausts that, it'll give you an out-of-memory error rather than freezing your computer.
See this post from MathWorks forums for more insight:
http://www.mathworks.com/matlabcentral/answers/12695-put-a-limit-on-memory-matlab-uses
Also see this guide from MathWorks on how to handle out-of-memory errors:
http://www.mathworks.com/help/matlab/matlab_prog/resolving-out-of-memory-errors.html
Finally, take a look at this link on how to change / modify the page size of your computer via Windows:
http://windows.microsoft.com/en-ca/windows/change-virtual-memory-size#1TC=windows-7
I am modifying Apple's code from the AurioTouch2 example on their developer's site. Currently I am trying to fully understand the function of the App. I see that the App writes 0's to the buffers using the silenceData method when mute is on. However, it seems to me that the data has already been processed and when using the App I see no difference wether mute is on or off. What an I missing - what purpose does mute serve?
from the end of performThu method (the input callback)
if (THIS->mute == YES) { SilenceData(ioData); }
from aurioHelper.ccp
void SilenceData(AudioBufferList *inData)
{
for (UInt32 i=0; i < inData->mNumberBuffers; i++)
memset(inData->mBuffers[i].mData, 0, inData->mBuffers[i].mDataByteSize);
}
AurioTouch2 Sample Code
You are correct, all that's doing is zero-ing out the buffer. The reason it's important, is that it's possible for the mData member to be uninitialized (i.e. random), which would result in horribly loud buzzing noises if it was left alone. It's possible that it would make no difference, but you shouldn't really leave that to chance.
If you're ever in a situation where you'd like to produce silence, make sure you 0 your buffer (instead of just leaving it).
First, I found that the mute button does work. When I hold the phone up to my ear I can hear that the sound from the mic is being played through to the receiver. With mute off there is no sound. Before, I was expecting sound from the speaker (not the receiver). That part of the problem solved.
Second, the remote io unit puts the microphone input data in the ioData buffers. Before I was expecting that there would be another callback for the output to the speaker, but I think because there is not one the remote io unit just uses the same ioData and plays it out the receiver (speaker). Thus zeroing out the ioData (after processing the the microphone input data for use by the app) results in silence at the reciever(i.e. the mute function). Any confirmation or clarification is appreciated.
I am designing a music visualiser application for the iPhone.
I was thinking of doing this by picking up data via the iPhone's mic, running a Fourier Transform on it and then creating visualisations.
The best example I have been able to get of this is aurioTuch which produces a perfect graph based on FFT data. However I have been struggling to understand / replicate aurioTouch in my own project.
I am unable to understand where exactly aurioTouch picks up the data from the microphone before it does the FFT?
Also is there any other examples of code that I could use to do this in my project? Or any other tips?
Since I am planning myself to use the input of the mic, I thought your question is a good opportunity to get familiar with a relevant sample code.
I will trace back the steps of reading through the code:
Starting off in SpectrumAnalysis.cpp (since it is obvious the audio has to get to this class somehow), you can see that the class method SpectrumAnalysisProcess has a 2nd input argument const int32_t* inTimeSig --- sounds a promising starting point, since the input time signal is what we are looking for.
Using the right-click menu item Find in project on this method, you can see that except for the obvious definition & declaration, this method is used only inside the FFTBufferManager::ComputeFFT method, where it gets mAudioBuffer as its 2nd argument (the inTimeSig from step 1). Looking for this class data member gives more then 2 or 3 results, but most of them are again just definitions/memory alloc etc. The interesting search result is where mAudioBuffer is used as argument to memcopy, inside the method FFTBufferManager::GrabAudioData.
Again using the search option, we see that FFTBufferManager::GrabAudioData is called only once, inside a method called PerformThru. This method has an input argument called ioData (sounds promising) of type AudioBufferList.
Looking for PerformThru, we see it is used in the following line: inputProc.inputProc = PerformThru; - we're almost there:: it looks like registering a callback function. Looking for the type of inputProc, we indeed see it is AURenderCallbackStruct - that's it. The callback is called by the audio framework, who is responsible to feed it with samples.
You will probably have to read the documentation for AURenderCallbackStruct (or better off, the Audio Unit Hosting) to get a deeper understanding, but I hope this gave you a good starting point.