1. soundtouch介紹和相關資源
The SoundTouch Library Copyright © Olli Parviainen 2001-2014
SoundTouch is an open-source audio processing library for changing the Tempo, Pitch and Playback Rates of audio streams or audio files
- Tempo (time stretch): Changes the sound to play at faster or slower tempo than originally without affecting the sound pitch.
- Pitch (key) : Changes the sound pitch or key while keeping the original tempo (speed).
- Playback Rate : Changes both tempo and pitch together as if a vinyl disc was played at different RPM rate.
The SoundTouch library is intended for application developers writing sound processing tools that require tempo/pitch control functionality, or just for playing around with the sound effects.
resource:
1.soundtouch官網:http://www.surina.net/soundtouch/。這上面有soundtouch的介紹、源碼,封裝好的dll文件、使用方法、以及一些demo。這上面demo做的不好。
2.一個利用java的jni調用soundtouch非常短小精悍的java swing界面小程序:http://www.aplu.ch/home/apluhomex.jsp?site=44。
3.csdn suhetao做的soundtouch源碼分析:http://blog.csdn.net/suhetao/article/details/5843480。
4.關於聲音處理的一個理論網頁:http://www.surina.net/article/time-and-pitch-scaling.html。
5.其他資料:http://baosu.iteye.com/blog/1840054
http://baosu.iteye.com/blog/1843031
http://blog.csdn.net/leilu2008/article/details/6724354
2.對於soundtouch源碼的最簡明的解釋(參考)
1. 音頻采集
這點主要是通過Android設備的麥克風實時采集音頻,由於Android平台的MediaRecorder類錄制音頻到文件,雖然可以通過空設備回調獲得實時的音頻流,不過為了降低開發者的難度,Android開發網推薦使用正統的AudioRecord和AudioTrack,首先我們仍然需要加入android.permission.RECORD_AUDIO這個權限。
android.media.AudioRecord類的read方法主要有3種重載形式: int read(short[] audioData, int offsetInShorts, int sizeInShorts) //short在java中占用兩個字節 int read(byte[] audioData, int offsetInBytes, int sizeInBytes) //byte在java中占用一個字節 int read(ByteBuffer audioBuffer, int sizeInBytes) //基於NIO的ByteBuffer類型
我們可以看到從麥克風中獲取的音頻無需經過文件系統直接通過AudioRecord類的read方法讀入到我們預定的緩沖區中,這里需要注意的是采樣率的大小必須有足夠的緩沖區空間處理
2. 變聲處理
這點需要一些基本的音頻處理方式,比如移調、變速,Android開發網推薦大家參考Adobe Audition的早期Cool Editi泄露的代碼,當然音頻處理算法比較多,大家可以自己實現。
3. 播放原始音頻流
同樣,處理完后考慮到效率我們仍然直接從內存流中播放,最簡單的就是AudioTrack類,通過android.media.AudioTrack類的write方法,讓Android聲卡播放原始音頻流。兩種重載方法如下
int write(short[] audioData, int offsetInShorts, int sizeInShorts) int write(byte[] audioData, int offsetInBytes, int sizeInBytes)
3.soundtouch的代碼結構