Skip to content

Fix issue that caused the waveform to draw flat across 1/3 of the screen#1

Open
Pepsi1x1 wants to merge 5 commits intodr-skot:masterfrom
Pepsi1x1:master
Open

Fix issue that caused the waveform to draw flat across 1/3 of the screen#1
Pepsi1x1 wants to merge 5 commits intodr-skot:masterfrom
Pepsi1x1:master

Conversation

@Pepsi1x1
Copy link
Copy Markdown

The wScale variable was the cause of the the waveform not drawing correctly, I also updated the drawRect method to use the provided rect as bounds for drawing.

The waveform still doesn't draw to full width in landscape orientation though!

@Pepsi1x1 Pepsi1x1 closed this Nov 19, 2012
@Pepsi1x1 Pepsi1x1 reopened this Nov 19, 2012
@Pepsi1x1
Copy link
Copy Markdown
Author

Removed the status bar in IB and that fixes the waveform in landscape!

@dr-skot
Copy link
Copy Markdown
Owner

dr-skot commented Nov 20, 2012

Hey,

Thanks for working on this. I'm looking over your changes.

I don't think using rect instead of self.bounds is right. As I understand it, the rect parameter indicates what portion of your view needs to be redrawn. Typically this turns out to be the same as self.bounds, but in some cases the UI engine only needs to update a part of the screen, and lets you know so, in case you can get a performance gain by not redrawing everything. But most custom views ignore rect, because the performance gain if any is usually not worth the work required to actually calculate what needs to be drawn in the subrectangle. Anyway it's wrong to draw your whole image in rect, though in practice you'll rarely notice an error because rect usually == self.bounds.

Also I don't want to get rid of wScale. What wScale does is get all the data on the screen. Losing it does solve the 2/3 flatline problem, because we're now plotting one sound sample (frame) per pixel, and there are many more frames than pixels. But if we want the oscilloscope line to represent all the incoming audio, we have to squeeze _numFrames into w pixels.

Actually a while ago I discovered a memcpy bug that was screwing up the data array and causing the flatline problem, but somehow my git HEAD got detached and the fix didn't make it to github. I've uploaded it now and the repository should be up to date. Please give the new version a try.

There's still an issue. The oscilloscope is now drawing three cycles of sampling but the edges of the samples don't quite line up. If you play around with it you'll see there are discontinuities in the curve at around 1/3 and 2/3 of the way across.

Thanks again for your help.

S

@Pepsi1x1
Copy link
Copy Markdown
Author

Thanks for your swift reply, ill check out the new version and look at a solution that renders this correctly then!

If nothing else you should remove the status bar from the XIB used for the oscilloscope view though, since this will stop the waveform from drawing full screen in landscape orientations.

Cheers, David.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants