- Home /
Question by
WoozyBytes · Feb 04, 2017 at 11:40 PM ·
javascriptaudioaudiosourceaudioclip
Why does the audio sound different than the original ?
Hi ! i have the following code :
var testClip :AudioClip;
var aS :AudioSource;
function Start () {
// Create a new audio clip
var newClip : AudioClip = AudioClip.Create("Test",testClip.samples * 8,testClip.channels,testClip.frequency,false);
// Create a float array to hold the new clip data
var loopData : float [] = new float[testClip.samples * 8];
// Create a float array to hold the new test clip data
var testClipData : float[] = new float [testClip.samples];
// Load the test clip data
if( testClip.LoadAudioData() == true){
// Get the test clip data
testClip.GetData(testClipData,0);
var nextSamplePosition : int = 0;
var sampleI : int;
// Add test clip data to the new clip
for( var sN = 0 ; sN < loopData.Length ; sN ++) {
if( sN >= nextSamplePosition ) {
if(sampleI < testClipData.Length) {
loopData[sN] = testClipData[sampleI];
sampleI ++;
}else{
nextSamplePosition += testClip.samples *2;
sampleI = 0;
}
}
}
// Set new clip data
newClip.SetData(loopData,0);
aS.clip = newClip;
Debug.Log("Ready");
}
}
So basically i created a audio clip 8 times larger than the test clip , then i added the test clip to this new clip in a sequence just as a test , when i play the new clip it sounds different than the test clip , it plays at a slightly higher frequency , only noticeable on lower frequency sounds like a kick drum. The question is why ? Hope someone can help , thanks in advance.
Comment
Not sure about an answer but you can change the pitch of a sound from the audio source component so you can get it back to where you want it
Thanks for the comment ! I know but that's not an option as it will also change the speed , i need it to stay the same. Regards