Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate Sine Wave between 10 and 20000Hz using SoundPool
    primarykey
    data
    text
    <p>I attempted to generate a Sine Wave using AudioTrack initially. The result was not satisfactory. I then moved to the Soundpool class. I used Audacity to create audiofiles of 1 second and then modified the playback speed (.5 - 2.0) to get the desired frequencies. (Arrays, as there are also saw and triangle wavefiles)</p> <pre><code> sig10000[0]=soundPool01.load(context,R.raw.sine10000,1); sig2500[0]=soundPool01.load(context,R.raw.sine2500,1); sig625[0]=soundPool01.load(context,R.raw.sine625,1); sig157[0]=soundPool01.load(context,R.raw.sine156,1); sig40[0]=soundPool01.load(context,R.raw.sine40,1); </code></pre> <p>I then, depending on the chosen frequency, play the audio:</p> <pre><code> public void play(){ Signal s=null; float factor; for(int i=0;i&lt;this.size();i++){ s=this.get(i); if(s.getFreq()&gt;4999){ factor = s.getFreq()/10000f; s.setStreamID(soundPool01.play(sig10000[s.getWaveType()],.99f,.99f,0,-1,factor)); }else if(s.getFreq()&gt;1249){ factor = s.getFreq()/2500f; s.setStreamID(soundPool01.play(sig2500[s.getWaveType()],.99f,.99f,0,-1,factor)); }else if(s.getFreq()&gt;312){ factor = s.getFreq()/625f; s.setStreamID(soundPool01.play(sig625[s.getWaveType()],.99f,.99f,0,-1,factor)); }else if(s.getFreq()&gt;77){ factor = s.getFreq()/156f; s.setStreamID(soundPool01.play(sig157[s.getWaveType()],.99f,.99f,0,-1,factor)); }else { factor = s.getFreq()/40f; s.setStreamID(soundPool01.play(sig40[s.getWaveType()],.99f,.99f,0,-1,factor)); } } } </code></pre> <p>Now as I see it, the method works fine except for the range 5000-20000 Hz. I'm breaking my head over this, not sure why its not working and I can't find any patterns to the problem.</p> <p>Is there some fundamental problem with this method? </p> <p>Thanking you in advance</p> <p><strong>Edit: "not working explained"</strong> When I play sine waves in the range 5000-20000 Hz it is very obvious that the frequency is inaccurate. This means the pitch is way off. E.g. 19000 Hz is too low and easily detectable by ear. What I can say is that 10000 Hz (as does 5000Hz- my mistake), so normal playback rate, is correct. <strong>At around 14kHz the signal pitch is no longer correct.</strong></p> <p><strong>Thoughts/Possible Causes(?):</strong> <em>(A)</em> How many steps are there for the playbackspeed (SoundPool)? The documentation says 0.5-2.0 is it possible that this means there is 15 different playbackspeeds? <em>(B)</em> I used Audacity to generate the .ogg files. When I zoom in on the 10000Hz sine I can see it is not too smooth (sample rate 44100) and the wave does not precisely start and end at 0. Could this superposition unwanted signals? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload