Html5 web API AudioBufferSourceNode sound syncing - html

I have 4 wav files all designed to be played at the same time. I have created the 4 sound buffers and play them with the start function. All 4 sounds are played successfully but they are slightly out of sync with each other. I guess each call to start takes long enough for the subsequent call to be out of sync. Is there anyway I can force them to sync?
Thanks

Without seeing you code, these are the spontaneous ideas I have. Make sure to check the following:
Give the exact same start time to the start method (maybe save context.currentTime + a little bit in a var and pass it to the start method of each source node, don't pass context.currentTime to each source in a for loop or similar (the context time might update while that's executing, thus the time passed to each source is different)).
Make sure that the audio files are cut exactly the same in the beginning of the file. If you have 10 ms extra silence in one of the files, that file will always be 10ms off (unless you compensate for it in the code).
If none of that works/applies, please add some code to your question explaining what you're doing right now.

Related

Is there a way to implement true multi-threading within a puppeteer application?

This may be a really silly question. I admit I'm a bit naive to the chrome web engine, and JS v8 engine's capabilities.
But say, I'm running a puppeteer application which is scraping URL's from tags, and pushing them to an array called img2arr
Then, I have a local file var img1 = ./image.jpg (in quotes).
Last, I have a function compare(img1, img2arr) which takes in both of these as arguments, and using a library such as blink-diff, or Jimp, analyzes and compares img1 against each image in img2arr. This all happens in a .forEach() or .map loop which works, but can be slow as the image2arr grows.
Say it contains 500 image URL's - is there a way to use service workers, a specific Node.js library, or anything to ensure that my image looping and comparing logic all happen across multiple threads?
For instance 200 loops, comparing two 12KB images takes 7 seconds, but with my blazing fast 12 cores processor couldn't it take less than 1?
Sorry for my obvious naivety!
There is a few possible ways:
1. Use spawn to run separately your script on every core of your machine. Here is really nice article.
2. Use node.js worker threads here is you can find how it works with examples.
Not depending the way of implementation you decide, main part would be to collect all data, up to this point
Last, I have a function compare(img1, img2arr) which takes ....
Then, separate your array of img2arr to chunks. You can choose any method from this article
After separation, pass each chunk to separate process and wait for first process to find the similar image.
When the process finds out similar image, you can kill all other processes from your master process.
So, the full process would be:
1. Collect images to compare
2. Split images to compare into chunks.
3. Separate comparison logic to separate file and run a thread/process on this file.
3a. Send chunks to available process
3b. Wait for first success return from process and kill all other ones.

Is there a reliable way to learn if a video file is valid? VideoPlayer does not detect empty/small size files as invalid ones

I need to detect if video file is valid(and delete it if it is not). It is an air application.
For large files it can be accomplished by processing MediaPlayerState.PLAYBACK_ERROR state. No problems.
However, when there's an empty file like empty.mp4, it does not dispatch any PLAYBACK_ERROR.
Then I created a file singleChar.mp4 (with x letter inside), the behavior was exactly the same.
It goes through READY state without any problems. playing is true at that time (it is said in the documentation that it is true when it is playing or attempting to play, so this is also not reliable).
Then I suggested that it treats those files as valid ones with duration=0... No! Duration is not set, durationChange is not dispatched.
The best approach for now is to play() it, setTimeout for about 50ms and check duration when this timeout expires. At least it works in 50% cases. However, this is completely unreliable. Reliability may be improved by extending the delay, but I'd prefer to detect it quickly and handle silently before user will notice any problems.
Other possible approach is to check if the file is less than some size(maybe,100KB?), however, this is also another stupid unreliable approach.
So, is there a reliable way to detect if a file is a valid video file?

What's debug section in IDA Pro?

I try to analyze a dll file with my poor assembly skills, so forgive me if I couldn't achieve something very trivial. My problem is that, while debugging the application, I find the code I'm looking for only in debug session, after I stop the debugger, the address is gone. The dll doesn't look to be obfuscated, as many of the code is readable. Take a look at the screenshot. The code I'm looking for is located at address 07D1EBBF in debug376 section. BTW, where did I get this debug376 section?
So my question is, How can I find this function while not debugging?
Thanks
UPDATE
Ok, as I said, as soon as I stop the debugger, the code is vanished. I can't even find it via sequence of bytes (but I can in debug mode). When I start the debugger, the code is not disassembled imediately, I should add a hardware breakpoint at that place and only when the breakpoint will be hit, IDA will show disassembled code. take a look at this screenshot
You see the line of code I'm interested in, which is not visible if the program is not running in debug mode. I'm not sure, but I think it's something like unpacking the code at runtime, which is not visible at design time.
Anyway, any help would be appreciated. I want to know why that code is hidden, until breakpoint hit (it's shown as "db 8Bh" etc) and how to find that address without debugging if possible. BTW, could this be a code from a different module (dll)?
Thanks
UPDATE 2
I found out that debug376 is a segment created at runtime. So simple question: how can I find out where this segment came from :)
So you see the code in the Debugger Window once your program is running and as you seem not to find the verry same opcodes in the raw Hex-Dump once it's not running any more?
What might help you is taking a Memory Snapshot. Pause the program's execution near the instructions you're interested in to make sure they are there, then choose "Take memory snapshot" from the "Debugger" Menu. IDA will then ask you wether to copy only the Data found at the segments that are defined as "loder segments" (those the PE loader creates from the predefined table) or "all segments" that seem to currently belong to the debugged program (including such that might have been created by an unpacking routine, decryptor, whatever). Go for "All segments" and you should be fine seeing memory contents including your debug segments (a segment
created or recognized while debugging) in IDA when not debugging the application.
You can view the list of segements at any time by pressing Shift+F7 or by clicking "Segments" from View > Open subviews.
Keep in mind that the programm your trying to analyze might choose to create the segment some other place the next time it is loaded to make it harder to understand for you what's going on.
UPDATE to match your second Question
When a program is unpacking data from somewhere, it will have to copy stuff somewhere. Windows is a virtual machine that nowadays get's real nasty at you when trying to execute or write code at locations that you're not allowed to. So any program, as long as we're under windows will somehow
Register a Bunch of new memory or overwrite memory it already owns. This is usually done by calling something like malloc or so [Your code looks as if it could have been a verry pointer-intensive language... VB perhaps or something object oriented] it mostly boils down to a call to VirtualAlloc or VirtualAllocEx from Windows's kernel32.dll, see http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx for more detail on it's calling convention.
Perhaps set up Windows Exception handling on that and mark the memory range als executable if it wasn't already when calling VirtualAlloc. This would be done by calling VirtualProtect, again from kernel32.dll. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa366898(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/aa366786(v=vs.85).aspx for more info on that.
So now, you should take a step trough the programm, starting at its default Entrypoint (OEP) and look for calls tho one of those functions, possibly with the memory protection set to PAGE_EXECUTE or a descendant. After that will possibly come some sort of loop decrypting the memory contents, copying them to their new location. You might want to just step over it, depending on what your interest in the program is by justr placing the cursor after the loop (thick blue line in IDA usually) and clicking "Run to Cursor" from the menu that appears upon right clicking the assembler code.
If that fails, just try placing a Hardware Breakpoint on kernel32.dll's VirtualAlloc and see if you get anything interestin when stepping into the return statement so you end up wherever the execution chain will take you after the Alloc or Protect call.
You need to find the Relative Virtual Address of that code, this will allow you to find it again regardless of the load address (pretty handy with almost all systems using ASLR these days). the RVA is generally calculated as virtual address - base load address = RVA, however, you might also need to account for the section base as well.
The alternative is to use IDA's rebasing tool to rebase the dll to the same address everytime.

AS3 Error #1502

AS3
Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
Is there a way to temporarily suppress this on a specific block of code?
I am creating a HUGE dynamic 3d array of objects, 1000x1000x1000 and need the build to actually finish the initializing.
Your best bet would be to try and refactor your code. Perhaps you can make use of this tutorial which deals with the exact problem you are having.
http://www.senocular.com/flash/tutorials/asyncoperations/
Increasing the timeout is one option, however I would also suggest considering an approach that would build your arrays over multiple frames, that is splitting the work up into separate jobs. As long as you give control back to the Flash Player every once in a while, you will not get this exception.
I'm not certain of the specifics of your problem, however you will need to find a way to parallelize or just simply segment your calculations. If your algorithm centers around one major loop, then consider creating a function that takes all of the arguments necessary to record the context of a single iteration. Then, create a simple control loop that will call this function and determine when to wait until the next frame and when not to. Leveraging AS3 closures can also help with this.
Look for the script execution time limit in the "Publish Settings" (Flash). If you're using Flex, maybe this one can be useful: http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_14.html (check default-script-limits, max-recursion-depth, max-execution-time). Oh! It seems there's apparently no way to make it behave in a different way on a specific piece of code (it is a global setting).
I do not approve the increse timeout option. Because for all this time your appllication is just hangs the whole Flash player. And normaly user thinks it is down, and forses it to quit.
check this one out: How to show the current progressBar value of process within a loop in flex-as3?
And then you can even show the progress which would be really more confident for you and for user.

Problems loading a NetStream Video

I have been creating a custom video player for the web. On some machines that I run this on it will start loading the .flv file then no progress will be made for 30 seconds to one minute then show that the video is completely loaded. I am checking how much has been loaded using a bytesLoaded / bytesTotal in an Event.ENTER_FRAME. When traced separately what seems to be happening when it shows fully loaded the bytesTotal value changes to the current bytesLoaded value causing my video player to register that my load percentage to be 1. I have traced out the NetStatus event.code value and there is no update to show that there has been any sort of error. All I get are a NetStream.Play.Start NetStream.Buffer.Full and then it will wait and reset the bytes total value.
So what I am asking is if there a way to handle this problem?
There doesn't seem to be a specific answer to this problem. I have since made another attempt at the problem and there are two lessons that I have learned.
1) You can code around most shortcomings in the netstream class by not allowing it to attempt to seek past the loaded point using the bytesLoaded, bytesTotal and the bufferTime properties. This can allow you to make sure that you never allow the seek to be attempted to a time that could cause a problem.
2) Always allow the previous seek attempt to finish and handle it properly before attempting to send another.
Are you playing an mp4 whose moov atom (e.g. metadata) is at the end of the file? If so, Flash cannot play the file until the entire file loads and is able to read the metadata.
This tool should fix your video file:
http://renaun.com/blog/code/qtindexswapper/