Quantcast

DiskIn produces unstable sound

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

DiskIn produces unstable sound

prko
This post was updated on .
Hi,


I made a simple media player using SuperCollider. (I am attaching the whole
code at the end of this email.)

Firstly I had made it after the method in the help document in SC as
follows:
(
// method 1
fork{
var path, snds, buff;
path = Platform.resourceDir +/+ "sounds/";
snds = [ path++"a11wlk01-44_1.aiff", path++"a11wlk01.wav"];
buff = Buffer.cueSoundFile(s, snds[0], 0, 1);

x = {DiskIn.ar(1, buff.bufnum)}.play;
10.do{
|i|
5.wait;
buff.close; // Is this necessary? It does not change the sound quality even
if I remove it or not.
buff.cueSoundFile(snds[i+1%2], 0)
};
x.free;
buff.close;
buff.free;
}
)

However it produces often unstable sound.
Thus I have rewrote the code as follows, and it works well:

(
// method 2
fork{
var path, snds, buff;
path = Platform.resourceDir +/+ "sounds/";
snds = [ path++"a11wlk01-44_1.aiff", path++"a11wlk01.wav"];
10.do{
|i|
buff = Buffer.cueSoundFile(s, snds[i%2], 0, 1);
x = {DiskIn.ar(1, buff.bufnum)}.play;
5.wait;
x.free
};
"done".postln;
buff.close;
buff.free;
}
)

What is the problem in the first method?
The help document suggests the following method:
b = Buffer.cueSoundFile(s, Platform.resourceDir +/+
"sounds/a11wlk01-44_1.aiff", 0, 1);

x = { DiskIn.ar(1, b.bufnum) }.play;

b.close;

// again
// note the like named instance method, but different arguments
b.cueSoundFile(Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0);

x.free; b.close; b.free;

I manually repeated the following line(s):

b.cueSoundFile(Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0);

or

b.close;
b.cueSoundFile(Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff", 0);


It also produces often unstable sound.

What is the reason?


best,
prko

------------------------------
// SC sound file player
// All sound files in the folder of the variable 'files' must be stereo
format sound files.
// In order to play mono sound files, the channel number of the variable
'thisBuf' and 'x' must be 1.
(
fork{
var files, filesSorted, fileInfos, duration, numDo;
files= Platform.resourceDir +/+ "HelpSource/Tutorials/A Korean
Guide/examples/soundfiles/listening examples/Schaeffer, Pierre
(1910-1995)/cinq études de bruits (1948)/*";
filesSorted= files.pathMatch.sort;
fileInfos= filesSorted.collect {|sf| SoundFile.openRead(sf)};
duration= fileInfos.collect{|sf| sf.numFrames/sf.sampleRate};
fileInfos.do {|sf| sf.close};
numDo= fileInfos.size;
numDo.do{|i|
var thisBuf, timeInterval, time, composer, title, movement, runningInf;
("Playing Item: "++(i+1)++"/"++(numDo)).postln;
thisBuf= Buffer.cueSoundFile(s, filesSorted[i], 0, 2);
timeInterval= 2;
x= {DiskIn.ar(2, thisBuf.bufnum)}.play;
movement= PathName(thisBuf.path);
title= PathName(movement.parentPath);
composer= PathName(title.parentPath);
postf("%\n%\n%\nDuration: %\n",
composer.folderName,
title.folderName,
movement.fileName.replace(".aiff", ""),
duration[i].asTimeString);
runningInf= [
[" length ", "—", 5, 0, ""],
["current ", "—", 5, 5, ""],
["waiting ", "·", 0.2, 0.2, "\n"]
];
runningInf.do{
|item, idx|
time= 0;
item[0].post;
{time < (idx!=2).if{duration[i]} {timeInterval}}
.while{
time = time + item[2];
item[3].wait;
item[1].post
};
(idx==1).if{x.free; thisBuf.close; thisBuf.free};
item[4].postln;
}
};
"FINISHED.".postln
}
)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DiskIn produces unstable sound

ddw_music
prko wrote
I made a simple media player using SuperCollider. (I am attaching the whole
code at the end of this email.)

Firstly I had made it after the method in the help document in SC as
follows:

However it produces often unstable sound.
Thus I have rewrote the code as follows, and it works well:
I don't have time to review the long code example, but I can say this: I don't trust it, messing around with a buffer while running DiskIn on it.

I stick to this principle:

1. Cue the buffer.
2. Run the synth.
3. Wait for the synth node to end.
4. Close the buffer -- not one ms before #3!
   a. Do not recue the buffer while it's playing.
   b. Do not reuse the buffer for another synth while the first one is still running.
   c. Close and recue, don't just recue.

If I need overlapping cues, I use a second buffer for the second synth. You can switch between two buffers. IMO the helpfile should be revised to avoid demonstrating an ugly hack.

I'm attaching an example I wrote the other day. When you click in the soundfile view, playback jumps to that position.

hjh

soundfile-scrolling-player.scd
Loading...