Timer in Java for noise generation
I am actually working on Android Call block App. however my part of code requires Java to generate obstacle/noise in the phone call.
I want to generate mute and unmute signals in a loop with varying intervals between them. Let me show with Pseudo Code in order to quickly explain logic.
array Tmute=[1,1,1,3,1,1,1,1,1]; //time in seconds to mute microphone
array TunMute=[3,1,2,4,1,2,1,2,4]; //time in seconds to unmute m开发者_StackOverflowicrophone
int i=0;
runThisLoop for (UserDefinedTime t)
{
MuteTheMicroPhone();
thread.sleep(Tmute[i]);
UnMuteTheMicroPhone();
thread.sleep(TunMute[i]);
i++;
}
DropCall();
I will take care of array out of bounds.
My Question : Is there a better way to generate the specific Tmute and TunMute which matches my pattern of noise generation, my pattern is shown in Array. Since I am using Android Device memory, I was concerned about efficient programming. Please comment and let me know if this question is not clear.
Is there a better way to generate the specific Tmute and TunMute which matches my pattern of noise generation.
Hard to answer without knowing why you think your current approach is poor. It looks OK to me; it is simple, it (apparently) does the job, what is the problem?
Since I am using Android Device memory, I was concerned about efficient programming.
I don't see any direct memory usage efficiency issues here. Unless perhaps turning the microphone on/off generates garbage.
But I'd be a bit concerned that turning the microphone on and off repeatedly might damage the hardware. If you are doing this simply to create a source of audio noise, surely there must be a technically better way to achieve that. Like a simple noise generator algorithm driven off a pseudo-random number generator.
And I'd also be a bit concerned about whether you have the real interests of the user of your app at heart. What are you really trying to do here?
精彩评论