Quantcast

iterated sound file writing

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

iterated sound file writing

Andrea Valle
Dear all, 

I'm getting a bit crazy with this.

The idea is to split a file by providing an env, smoothing attack and release.

I have a func like this:

~applyEnv = {|array, startFrame, stopFrame, attD = 0.005, relD = 0.01|
var sus ;
attD = (attD*Server.local.sampleRate).trunc.asInteger ;
relD = (relD*Server.local.sampleRate).trunc.asInteger ;
sus = stopFrame-startFrame-attD-relD ;
Env.new([0,1,1,0], [attD, sus, relD], [-3,\linear,3])
.asSignal(stopFrame-startFrame).collect{|i| i}
*
array[startFrame..stopFrame]
}

Now, the following code works. 

(
~path = Platform.resourceDir +/+ "sounds/a11wlk01.wav";
// ~pt is dir where to write
~pt = "/Users/andrea/musica/regna/fossilia/compMine/erelerichnia/testSplit/" ;
~snd = SoundFile.openRead(~path) ; // a snd file
~arr = FloatArray.newClear(~snd.numFrames) ; // an array with same size
// filling ~ar with data from snd file
~snd.readData(~arr) ;
)

And here I'm taking a random chunk, it works

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 44100*1,  44100*2) // between 1 and 2 secs
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)

Here I'm taking all the content, fine

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 0,  ~snd.numFrames) 
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)


Here, on the contrary, I'm iterating on an array of slicing points.
Looks like I'm getting distorsion but not in all generated files.
I guess it might depend on data format, still I can't understand why it seems to work for the first files (and for a single file).

(
~att = [ 0, 15435, 90405, 97020, 125685 ] ; // slice points
~att[..~att.size-2].do{|which,i|
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, which, ~att[i+1]-which).as(FloatArray) ;
//data.plot ;
f.openWrite(~pt++i++".aiff") ;
f.writeData(data);
f.close ;
}
)

Probably it’s something stupid, and I’m burnt out.

Thanks a lot

Best

-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iterated sound file writing

TizianoT
Hello,

I've done tried this little debug on your last part of the program.

(
~att = [ 0, 15435, 90405, 97020, 125685 ] ; // slice points
~att[..~att.size-2].do{|which,i|
    ("---iteration_"++i.asString).postln;
    "startFrame".postln;
    which.postln;
    "stopFrame".postln;   
    (~att[i+1]-which).postln;
    //var data = ~applyEnv.(~arr, which, ~att[i+1]-which).as(FloatArray) ;
}
)

Here the output of the test,

//**************************************************
---iteration_0
startFrame
0
stopFrame
15435
---iteration_1
startFrame
15435
stopFrame
74970
---iteration_2
startFrame
90405
stopFrame
6615
---iteration_3
startFrame
97020
stopFrame
28665
**************************************************//
In the second and third iteration "stop frame" is less then "start frame" and I think that this is not good for the function ~applyEnv where you compute  " sus = stopFrame-startFrame-attD-relD";

Do you think that this can be the source of the problem?



2017-03-20 13:26 GMT+01:00 Andrea Valle <[hidden email]>:
Dear all, 

I'm getting a bit crazy with this.

The idea is to split a file by providing an env, smoothing attack and release.

I have a func like this:

~applyEnv = {|array, startFrame, stopFrame, attD = 0.005, relD = 0.01|
var sus ;
attD = (attD*Server.local.sampleRate).trunc.asInteger ;
relD = (relD*Server.local.sampleRate).trunc.asInteger ;
sus = stopFrame-startFrame-attD-relD ;
Env.new([0,1,1,0], [attD, sus, relD], [-3,\linear,3])
.asSignal(stopFrame-startFrame).collect{|i| i}
*
array[startFrame..stopFrame]
}

Now, the following code works. 

(
~path = Platform.resourceDir +/+ "sounds/a11wlk01.wav";
// ~pt is dir where to write
~pt = "/Users/andrea/musica/regna/fossilia/compMine/erelerichnia/testSplit/" ;
~snd = SoundFile.openRead(~path) ; // a snd file
~arr = FloatArray.newClear(~snd.numFrames) ; // an array with same size
// filling ~ar with data from snd file
~snd.readData(~arr) ;
)

And here I'm taking a random chunk, it works

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 44100*1,  44100*2) // between 1 and 2 secs
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)

Here I'm taking all the content, fine

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 0,  ~snd.numFrames) 
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)


Here, on the contrary, I'm iterating on an array of slicing points.
Looks like I'm getting distorsion but not in all generated files.
I guess it might depend on data format, still I can't understand why it seems to work for the first files (and for a single file).

(
~att = [ 0, 15435, 90405, 97020, 125685 ] ; // slice points
~att[..~att.size-2].do{|which,i|
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, which, ~att[i+1]-which).as(FloatArray) ;
//data.plot ;
f.openWrite(~pt++i++".aiff") ;
f.writeData(data);
f.close ;
}
)

Probably it’s something stupid, and I’m burnt out.

Thanks a lot

Best

-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: iterated sound file writing

Andrea Valle
Ahhhhh grazie Luca,

yes sure, I had recycled a piece of code and hadn’t realised that now I was just  in need of absolute indices, so subtraction is not needed anymore.

Thanks a lot for the hint

-a-

--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)

On 20 Mar 2017, at 13:58, Tiziano Tuccella <[hidden email]> wrote:

Hello,

I've done tried this little debug on your last part of the program.

(
~att = [ 0, 15435, 90405, 97020, 125685 ] ; // slice points
~att[..~att.size-2].do{|which,i|
    ("---iteration_"++i.asString).postln;
    "startFrame".postln;
    which.postln;
    "stopFrame".postln;   
    (~att[i+1]-which).postln;
    //var data = ~applyEnv.(~arr, which, ~att[i+1]-which).as(FloatArray) ;
}
)

Here the output of the test,

//**************************************************
---iteration_0
startFrame
0
stopFrame
15435
---iteration_1
startFrame
15435
stopFrame
74970
---iteration_2
startFrame
90405
stopFrame
6615
---iteration_3
startFrame
97020
stopFrame
28665
**************************************************//
In the second and third iteration "stop frame" is less then "start frame" and I think that this is not good for the function ~applyEnv where you compute  " sus = stopFrame-startFrame-attD-relD";

Do you think that this can be the source of the problem?



2017-03-20 13:26 GMT+01:00 Andrea Valle <[hidden email]>:
Dear all, 

I'm getting a bit crazy with this.

The idea is to split a file by providing an env, smoothing attack and release.

I have a func like this:

~applyEnv = {|array, startFrame, stopFrame, attD = 0.005, relD = 0.01|
var sus ;
attD = (attD*Server.local.sampleRate).trunc.asInteger ;
relD = (relD*Server.local.sampleRate).trunc.asInteger ;
sus = stopFrame-startFrame-attD-relD ;
Env.new([0,1,1,0], [attD, sus, relD], [-3,\linear,3])
.asSignal(stopFrame-startFrame).collect{|i| i}
*
array[startFrame..stopFrame]
}

Now, the following code works. 

(
~path = Platform.resourceDir +/+ "sounds/a11wlk01.wav";
// ~pt is dir where to write
~pt = "/Users/andrea/musica/regna/fossilia/compMine/erelerichnia/testSplit/" ;
~snd = SoundFile.openRead(~path) ; // a snd file
~arr = FloatArray.newClear(~snd.numFrames) ; // an array with same size
// filling ~ar with data from snd file
~snd.readData(~arr) ;
)

And here I'm taking a random chunk, it works

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 44100*1,  44100*2) // between 1 and 2 secs
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)

Here I'm taking all the content, fine

(
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, 0,  ~snd.numFrames) 
.as(FloatArray);
data.plot ;
f.openWrite(~pt++"0"++".aiff") ;
f.writeData(data);
f.close ;
)


Here, on the contrary, I'm iterating on an array of slicing points.
Looks like I'm getting distorsion but not in all generated files.
I guess it might depend on data format, still I can't understand why it seems to work for the first files (and for a single file).

(
~att = [ 0, 15435, 90405, 97020, 125685 ] ; // slice points
~att[..~att.size-2].do{|which,i|
var f = SoundFile.new.headerFormat_("AIFF")
.sampleFormat_("float").numChannels_(1) ;
var data = ~applyEnv.(~arr, which, ~att[i+1]-which).as(FloatArray) ;
//data.plot ;
f.openWrite(~pt++i++".aiff") ;
f.writeData(data);
f.close ;
}
)

Probably it’s something stupid, and I’m burnt out.

Thanks a lot

Best

-a-


--------------------------------------------------
Andrea Valle
--------------------------------------------------
CIRMA - StudiUm
Università degli Studi di Torino
--------------------------------------------------

"This is a very complicated case, Maude. You know, a lotta ins, a lotta outs, a lotta what-have-yous." 
(Jeffrey 'The Dude' Lebowski)



Loading...