我这样做了吗?我制作的代码改变了频率.
编辑:
我成功生成单音并将其存储在byte [] generatedSnd中
播放单声道(工作):
AudioTrack audioTrack = null; // Get audio track try { audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate,AudioFormat.CHANNEL_OUT_MONO,AudioFormat.ENCoding_PCM_16BIT,(int)numSamples*2,AudioTrack.MODE_STATIC); audioTrack.setStereoVolume(0f,1f); audioTrack.write(generatedSnd,generatedSnd.length); // Load the track audioTrack.play(); // Play the track } catch (Exception e){ }
转换为立体声:
int monoByteArrayLength = generatedSnd.length; byte [] stereoGeneratedSnd = new byte[monoByteArrayLength * 2]; stereoGeneratedSnd[0] = generatedSnd[0]; stereoGeneratedSnd[2] = generatedSnd[0]; for (int x=1; x<monoByteArrayLength; x+=2) { stereoGeneratedSnd[x*2-1] = generatedSnd[x]; stereoGeneratedSnd[x*2+1] = generatedSnd[x]; if (x+1 < monoByteArrayLength) { stereoGeneratedSnd[x*2] = generatedSnd[x+1]; stereoGeneratedSnd[x*2+2] = generatedSnd[x+1]; } } AudioTrack audioTrack = null; // Get audio track try { audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,AudioFormat.CHANNEL_OUT_STEREO,1f); audioTrack.write(stereoGeneratedSnd,stereoGeneratedSnd.length); // Load the track audioTrack.play(); // Play the track } catch (Exception e){ }
我想要做的是从一个频道播放声音
解决方法 双倍算法的输出为0,1,2,3,4,5,5.更简单(和更正确)的加倍方式是:
for (int i = 0; i < monoByteArrayLength; i += 2) { stereoGeneratedSnd[i*2+0] = generatedSnd[i]; stereoGeneratedSnd[i*2+1] = generatedSnd[i+1]; stereoGeneratedSnd[i*2+2] = generatedSnd[i]; stereoGeneratedSnd[i*2+3] = generatedSnd[i+1];}
输出:0,5
总结以上是内存溢出为你收集整理的android – 将单声道转换为立体声全部内容,希望文章能够帮你解决android – 将单声道转换为立体声所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)