요즘들어 특히 의공학 어플 개발에 힘쓰고 있다.
개발을 진행하다 보면 구현 과정에서 걸림돌이 수 없이 나오는데,
그중 가장 오랫동안 고민을 했던 속도 부분의 문제를 해결하기 위해 StackOverflow
사이트에 질문을 올려놓았었다.
문제에 대해 간단히 설명하면, thread에서 그래프를 갱신하기
위해 performSelectorOnMainThread 를 이용하였는데, 그래프가 정상적으로 그려지지 않은것. 매 초마다 1000개의 샘플 데이터를 받아오기 때문에 UI를 매 초마다 1000번 갱신하는 것을 아이폰 4S와 아이패드2가 따라가지 못한 것이다.
사실 이 문제를 해결하기 위한 해답은 너무 나도 SIMPLE했다.
혹시 다른 분들이 도움이 될까 해서 자문자답한 글을 올린다.
I wanna show the amplitude of real time sound on a UIView by graph.
I set sound sample rate as 1000 in a second.
And, To Update Graph, I did like this. this is called in every millisecond.
[Audio performSelectorOnMainThread:@selector(updateGraph) withObject:nil waitUntilDone:NO];
and inside of updateGraph is like this.
- (void) updateGraph{
[graphview setNeedsDisplay];
}
(I guess) it is because of the "waitUntilDone:NO".
iphone 4S and also iPad2 couldn't catch up the rate of 1000.
I also tried "YES" for "waitUntilDone". It draws rightly,
but also, the devices couldn't catch up with the rate of 1000,
so in this way, graphing speed was slow.
is there a way to fix the graph better?
I'm really stock here that i couldn't even find good solution any more.
I Just Got a Answer on my own!
I was getting sound input in every millisecond,
and within' it I also updated graph in every millisecond too.
that means I updated every fixel of 480 in a millisecond.
I thought i should update graph immediately when i get sound input,
to show graph smoothly.
But I was wrong. That was not necessary to update every fixel.
Because It really takes a lot of process.
So I changed the code to update UI not in every millisecond. and it works really well.