Record a 60fps movie (with sound) using Uzem

The Uzebox now have a fully functional emulator! Download and discuss it here.
User avatar
uze6666
Site Admin
Posts: 4449
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by uze6666 » Thu Oct 01, 2015 1:06 am

I saw your comment about not merging too late and tried to revert and I don't really understand the state now. Asked to create another pull request... :?:

User avatar
Artcfox
Posts: 944
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by Artcfox » Thu Oct 01, 2015 2:18 am

uze6666 wrote:I saw your comment about not merging too late and tried to revert and I don't really understand the state now. Asked to create another pull request... :?:
Sorry! It looks like you created another branch based off the previous commit, rather than reverting the change. The change is still inside the uzem140 branch, so I can just create another pull request that can go on top of that, because it may end up being mostly the same, just with some constants changed.

I'm still trying to wrap my head around how to get the synchronization perfect. It's just a pain to test things, because each test lasts 25 minutes while I wait for the entire video to be recorded.

User avatar
uze6666
Site Admin
Posts: 4449
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by uze6666 » Thu Oct 01, 2015 2:37 am

Artcfox wrote: I'm still trying to wrap my head around how to get the synchronization perfect. It's just a pain to test things, because each test lasts 25 minutes while I wait for the entire video to be recorded.
Since you have a fast PC, try commenting out these lines:

Code: Select all

		if (enableSound && TCCR2B)
		{
			// raw pcm sample at 15.7khz
			//while (audioRing.isFull())SDL_Delay(1);
			//SDL_LockAudio();
			//audioRing.push(value);
			//SDL_UnlockAudio();
That's what is controlling the emulation speed. Without it, emulation should run much faster!

User avatar
Artcfox
Posts: 944
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by Artcfox » Thu Oct 01, 2015 3:27 am

Cool! I'll try that after the current recording in progress has finished.

But if that's the case, then what keeps the emulation speed limited when you run it with the -n flag to disable sound?

User avatar
uze6666
Site Admin
Posts: 4449
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by uze6666 » Thu Oct 01, 2015 4:28 am

Artcfox wrote:Cool! I'll try that after the current recording in progress has finished.

But if that's the case, then what keeps the emulation speed limited when you run it with the -n flag to disable sound?
Good point, I never use this flag. Does the speed remain constant??

User avatar
Artcfox
Posts: 944
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by Artcfox » Thu Oct 01, 2015 4:38 am

uze6666 wrote:
Artcfox wrote:Cool! I'll try that after the current recording in progress has finished.

But if that's the case, then what keeps the emulation speed limited when you run it with the -n flag to disable sound?
Good point, I never use this flag. Does the speed remain constant??
I didn't use that flag, because then it would disable audio recording, but when I commented those lines like you suggested, along with these:

Code: Select all

					// SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
					// SDL_RenderClear(renderer);
					// SDL_RenderCopy(renderer, texture, NULL, NULL);
					// SDL_RenderPresent(renderer);
to make it so it doesn't even waste time drawing to the window, I'm getting 42 MHz emulation speed on my old laptop. Well that's after I also changed the ffmpeg encoding settings to:

Code: Select all

"ffmpeg -y -f rawvideo -s 640x240 -pix_fmt rgba -r 59.94 -i - -vf scale=960:720 -sws_flags neighbor -an -preset ultrafast -qp 0 -tune animation uzemtemp.mp4"
which makes the encoding process happen wicked fast.

What a great tip! Thank you, this will save me much time!

I'm thinking that another flag called fastRecording would be a good idea. That would disable both sound and video playback in the window and let the rendering of both proceed as fast as the CPU will allow. I'm going to have to get this up and running on my fast desktop, just to see how many MHz I can push the emulation up to! ;)

User avatar
Artcfox
Posts: 944
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by Artcfox » Thu Oct 01, 2015 8:27 am

I just tried it on my desktop, and it can run Uzem in recording mode (including the video scaling) without local audio/video display at around 90 MHz +/- 4 MHz, depending on how complex the video frames it's recording are. Without the recording flag (and with no sound or video) the emulator itself will run at a solid 97 MHz. :shock:

And to answer your question about the -n flag, if I put everything back so it displays the video and plays the audio, but then run it with the -n option to not play sound, it runs at over 70 MHz, and it was really tricky for me to even beat the first level of BUGZ. :lol:

I also submitted another pull request (to be merged into your uzem140 branch) with the proper a/v sync code. It is meant to be applied on top of my previous patch, so you should probably delete the revert-33-uzem140 branch, since that's just cruft now, and you'll also want to close (without merging) the pull request you made to yourself to merge the revert-33-uzem140 branch into uzem140 since that would just screw things up if that got merged at this point.

According to this stackoverflow post, assuming the name of your github remote is "origin", you would do:

Code: Select all

git push origin --delete revert-33-uzem140
git branch -D revert-33-uzem140
git branch --delete --remotes origin/revert-33-uzem140
Full disclaimer: I have not tried those commands myself with a Github remote, so only run them after you fully understand them, and at your own risk.

Code: Select all

git help push
git help branch
will explain what each of those options do.

User avatar
Artcfox
Posts: 944
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Record a 60fps movie (with sound) using Uzem

Post by Artcfox » Fri Oct 02, 2015 12:57 am

uze6666 wrote:
Artcfox wrote:Cool! I'll try that after the current recording in progress has finished.

But if that's the case, then what keeps the emulation speed limited when you run it with the -n flag to disable sound?
Good point, I never use this flag. Does the speed remain constant??
Replying again, since I get different results depending on which flags I use when I create the window.

With the

Code: Select all

SDL_RENDERER_PRESENTVSYNC
flag set, then it locks the frame rate to my monitor's refresh rate, so even with sound disabled, the call to:

Code: Select all

SDL_RenderPresent(renderer);
will block and limit the speed of the emulator automatically.

I tried to remove the call to SDL_Delay(1) from this line of code:

Code: Select all

while (audioRing.isFull())SDL_Delay(1);
but that causes the emulator to hang, because the ringBuffer isn't coded to handle threads properly.

At the very least size and avail of the ringBuffer class need to be declared volatile, since they are being accessed simultaneously by multiple threads, and each thread needs to fetch the latest value.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest