sandydo
Joined: Mar 15, 2017 Posts: 1 Location: Berlin
|
Posted: Wed Mar 15, 2017 8:40 am Post subject:
ma |
|
|
Hello Chuck programmer,
I have a special wish in working with audio files in Chuck and since I'm new to the language I'm not sure how to succeed.
In particular, I want to interpolate two audio files in the way, that when I have two files, e.g. "violin.wav" and "trumpet.wav" both of the same length let's say. Then I want to create or play a third audio file which is a mixture of both, so that the sample starts as "violin.wav" and end as "trumpet.wav" and in between it should be continuously interpolated...
My idea for this is if we had the two buffer as arrays like:
"violin.wav" -> violinArray =[34,3,43,56,23,67,23,67,54,78,23,54]
"trumpet.wav" -> trumpetArray [32,4,65,65,65,34,65,23,6,76,5,4]
Then I want to create something like.
Code: |
int N = violinArray.length;
new array mixtureArray[N];
for (i = 0; i< N; i++)
{
mixtureArray[i] = i*violinArray[i] + (N -(i+1))*trumpetArray[i];
}
|
But the difficulty for me is to get the data of "violin.wav" and "trumpet.wav" as an array or something similar... Is it even possible to view the real data of a sound buffer??
I fancy every commentary or contribution.
Cheers,
Thomas |
|
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Apr 26, 2017 7:52 am Post subject:
|
|
|
While I think it's possible to get an audio file into an array (I can see if I can find an old post on the subject if you like), I would just stream the two files and set envelopes over them.
My ChucK is a bit rusty, and I can't compile and check this, so this will probably riddled with syntax errors and wrong function names, but something like this pseudo code:
Code: | SndBuf trumpet (...);
SndBuf violin(...);
trumpet => Envelope trumpetEnvelope => dac;
violin => Envelope violinEnvelope => dac;
0 => trumpetEnvelope.value;
1 => trumpetEnvelope.target;
10::seconds => trumpetEnvelope.time; // assuming each sound lasts for 10 seconds
1 => violinEnvelope.value;
0 => violinEnvelope.target;
10::seconds => violinEnvelope.time; // assuming each sound lasts for 10 seconds
// start the SndBufs
|
This should make the violin fade into the trumpet. Once they have started you can (if you want to) look at the actual values on each sound using .last():
Code: | now + 10::seconds => time waitUntil;
while (now < waitUntil) {
<<< "The values are ", trumpet.last(), violin.last() >>>;
1::samp => now;
}
|
There are also ways of generating new sound files in ChucK, you should be able to find information about this in the documentation.
Hope that helps in any way :) _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|