SuperCollider Forum
May 21, 2013, 02:18:46 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The SuperCollider forum is currently experiencing a rash of spambot registrations. New user requests may not be approved quickly as a result -- and if your email address looks like spam, it might not be approved at all. We are working to improve the security of the registration process, and to provide alternate means to contact the administrators to get a new account. Thanks for your patience.
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Buffer.loadDialog & DiskIn problem  (Read 1935 times)
0 Members and 1 Guest are viewing this topic.
kanonas
Newbie
*

Karma: 0
Posts: 1


View Profile WWW
« on: August 30, 2008, 03:10:42 AM »

Hello everybody,
I want to make a 4 sample player. I tried to use DiskIn because i need long audiofiles to be loaded.
My problem is that i don't know how to use Buffer.loadDialog

b = Buffer.loadDialog(s);
x = { DiskIn.ar(2, b) }.play;

With this code i can't hear anything, neither with this::

b = Buffer.loadDialog(s, action: { arg buffer;
x = { DiskIn.ar(2, buffer, 1) }.play;          
});
Logged
dewdrop_world
AdminGroup
Full Member
*

Karma: 9
Posts: 193



View Profile WWW
« Reply #1 on: September 02, 2008, 08:46:56 PM »

I think the problem here is that DiskIn expects part of the sound file to be loaded into the buffer, and the file should be left open so that DiskIn can get more audio from disk as needed. Buffer:loadDialog doesn't do that -- it closes the file after filling the buffer from disk, and this is (most likely) causing DiskIn not to work.

Also, since your code doesn't specify a buffer size, it will load the entire file into server memory. In that case, DiskIn is superfluous because the whole point of that unit generator is to read audio incrementally into a smaller buffer.

I would suggest something like this. There is a bunch of stuff in here that I don't have time to explain tonight, but ask more questions and I'll be happy to fill in the blanks. Keeping track of the buffers and synths is not covered in this code but will be very important for handling multiple buffers and files.

James

Code:
(
CocoaGUI.dialog.getPaths({ |path|
var sf = SoundFile.openRead(path[0]), condition = Condition.new, defname;
if(sf.notNil and: { sf.isOpen }) {
protect {
fork {
defname = "diskin" ++ sf.numChannels;
SynthDef(defname, { |buffer, out, loop = 1|
Out.ar(out, DiskIn.ar(sf.numChannels, buffer, loop))
}).send(s);
b = Buffer.cueSoundFile(s, path[0],
startFrame: 0,
numChannels: sf.numChannels,
bufferSize: 131072);
s.sync(condition);
x = Synth(defname, [buffer: b]);
}
} {
sf !? { sf.close };
}
} {
"% is not a valid soundfile.".format(path[0]).die;
};
});
)


x.free;
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!