Queuing and looping buffers in OpenAL - openal

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

Related

Does Exoplayer download a chunk completely before processing (decoding) it

Does Exoplayer download a chunk completely before processing (decrypting, decoding) it. Is there a way to override this and start decoding / playback before the chunk is completely downloaded.The content is an MPEG-DASH content with a 6 second chunk size.
I am on the latest version of Exoplayer. I am trying to improve the Video Start Time and hence this query. Also, will smaller chunk sizes impact the Video start time ?
I think you mean a dash segment when you say chunk - the terminology is important because DASH segments can contain subsegments, and each of these may be decodable, but it is also confusing as the term chunks and segments are both used in the ExoPlayer code.
Its useful when discussing this area to remember that the video download is actually a series of requests and responses, rather than a constant stream of media.
To start decoding earlier you typically have to request smaller 'pieces' (trying to avoid tripping over terminology...) of the video.
To be decodable, and video piece usually needs to start with a frame which does not reference any previous frames - an IDR frame or Stream Access Point (SAP).
Looking at ExoPlayer itself, you can set the number of segments you can download per chunk (Exoplayer terminology for the bit of the video you download) - take a look at the 'maxSegmentsPerLoad' attribute in the 'DefaultDashChunkSource': https://github.com/google/ExoPlayer/blob/bd54394391b0527893f382c9d641b8a55ffca765/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashChunkSource.java
However, I think this is the opposite of what you are looking for - you would like to request a smaller piece of video - e.g. subsegments rather than the whole segments.
For that you most likely want to look at the new low latency mechanisms introduced for DASH and for HLS - ExoPlayer has added support for these and there is a public design document which provides a very good explanation of the background and the approach here (link correct at the time of writing - original ExoPlauer git issue also for reference - https://github.com/google/ExoPlayer/issues/4904):
https://docs.google.com/document/d/1z9qwuP7ff9sf3DZboXnhEF9hzW3Ng5rfJVqlGn8N38k/edit#
The diagrams in this document explain it well, but the short answer to your question is that yes, this approach does allow smaller 'pieces' of video be downloaded and played back and it does indeed help with video start time.

Finding main_data_begin in a MP3 file

I want to decode a MP3 file. I manage to find the 32 bits in the header (sync word, ID, Layer, Bitrate, etc). The problem is I have no idea on how to find the starting (the position) of main_data_begin (side information). I am using MATLAB in this case.
I know it may be a simple question, but I really need your help. Please.
Thank you.
MPEG1/2 Layer III uses main_data_begin as a kind of pseudo-VBR over the granule headers & data. The simplest way to do it is to implement a circular buffer that receives all the physical frame data after the side info and throws-away the unused bytes at the beginning of the buffer (as indicated by main_data_begin) before starting frame decode.
Your best bet is to read an existing decoder's source. The spec is also really good for this, but main_data_begin is mis-documented in publicly-available versions (as best as I can find).

What does the "Mute" Button Do in Apple's AurioTouch2 sample code?

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.

replacement for alutLoadWAVFile

The following function calls are deprecated in OpenAL 1.1, what is a proper replacement?? THe only answer i found in google was "write your own function!!" ;-)
alutLoadWAVFile
alutUnloadWAV
There are 8 file loading functions in ALUT (not including the three deprecated functions alutLoadWAVFile, alutLoadWAVMemory, and alutUnloadWAV).
The prefix of the function determines where the data is going; four of them start alutCreateBuffer (create a new buffer and put the sound data into it), and the other four start alutLoadMemory (allocate a new memory region and put the sound data into it).
The suffix of the function determines where the data comes from. Your options are FromFile (from a file!), FromFileImage (from a memory region), HelloWorld (fixed internal data of someone saying "Hello, world!"), and Waveform (generate a waveform).
I believe the correct replacement for alutLoadWAVFile would therefore be alutCreateBufferFromFile.
However, I would not use this blindly - it's suitable for short sound clips, but for e.g. a music track you probably want to load it in chunks and queue up multiple buffers, to ease the memory load.
These functions are all covered in the alut documentation, by the way.
"write your own" is pretty much the correct answer.
You can usually get away with using the deprecated functions since most implementations still include the WAV file handling functions, with one notable exception being iOS, for which you'd need to use audio file services.
I'd suggest making a standard prototype for "load wav file" and then depending on the OS, use a different loading routine. You can just stub it with a call to alutLoadWAVFile for systems known to still support it.

get input from keyboard while displaying an avi with matlab

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