Discussion:
Basic program won't play sound loaded in buffer
amundsen
2011-07-28 19:26:07 UTC
Permalink
Hello,

The very basic program below is just intended to load a sound when pressing
one button and to play it when pressing a second one. I cannot hear any
sound however.

What's wrong ?

Roald Baudoux


(
var but1;
var but2;
var soundChosen;
var buf1;
var soundPlayer;

//Buffer creation to store a sound
buf1 = Buffer.new(s);

//sound playback synthDef and Synth creation
SynthDef(\simpleReader, {| out = 0, bufnum = 0 |
Out.ar(out, Pan2.ar(PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum),
doneAction:2), 0.0, 1.0));
}).send(s);
soundPlayer = Synth.new(\simpleReader);

//draw main window
w = Window.new("Sound playback");
w.bounds = Rect(50, 300, 200, 200);
w.front;

// remembers if a sound has been chosen
soundChosen = 0;
//button to choose a sound
but1 = Button(w, Rect(40,20,120,30))
.states_([
["Choose a sound", Color.black, Color.red]
])
.action_({
CocoaDialog.getPaths({ arg paths;
paths.do({ arg p;
p.postln;
buf1.read(s, p);
soundChosen = 1;
})
},{
"No file chosen !".postln;
});
});


//button to play sound
but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer.postln;
soundPlayer.play(s, [\bufnum, buf1]);
},{"Choose a sound first !".postln;
}
);
});

)

-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6631010.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Josh Parmenter
2011-07-28 19:30:48 UTC
Permalink
Couple things I see that might cause a problem… first - are all your sounds mono? You are using 1 channel for you SynthDef, and more channels may cause PlayBuf not to play.

Second - this:

soundPlayer = Synth.new(\simpleReader);

starts the note immediately, and if there is no buffer loaded and sent into the Synth, it will finish (since you use doneAction: 2). Try playing the Synth when the soundfile is chosen to be played:

but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer = Synth.new(\simpleReader, [\bufnun, buf1]);
},{"Choose a sound first !".postln;
}
);
});

Hope that helps.

Josh
Post by amundsen
Hello,
The very basic program below is just intended to load a sound when pressing
one button and to play it when pressing a second one. I cannot hear any
sound however.
What's wrong ?
Roald Baudoux
(
var but1;
var but2;
var soundChosen;
var buf1;
var soundPlayer;
//Buffer creation to store a sound
buf1 = Buffer.new(s);
//sound playback synthDef and Synth creation
SynthDef(\simpleReader, {| out = 0, bufnum = 0 |
Out.ar(out, Pan2.ar(PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum),
doneAction:2), 0.0, 1.0));
}).send(s);
soundPlayer = Synth.new(\simpleReader);
//draw main window
w = Window.new("Sound playback");
w.bounds = Rect(50, 300, 200, 200);
w.front;
// remembers if a sound has been chosen
soundChosen = 0;
//button to choose a sound
but1 = Button(w, Rect(40,20,120,30))
.states_([
["Choose a sound", Color.black, Color.red]
])
.action_({
CocoaDialog.getPaths({ arg paths;
paths.do({ arg p;
p.postln;
buf1.read(s, p);
soundChosen = 1;
})
},{
"No file chosen !".postln;
});
});
//button to play sound
but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer.postln;
soundPlayer.play(s, [\bufnum, buf1]);
},{"Choose a sound first !".postln;
}
);
});
)
-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6631010.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
amundsen
2011-07-28 19:56:49 UTC
Permalink
Post by Josh Parmenter
Couple things I see that might cause a problem… first - are all your
sounds mono? You are using 1 channel for you SynthDef, and more channels
may cause PlayBuf not to play.
Well, I'd be happy if I could play both mono and stereo sounds hence the
Pan2.ar but it doesn't seem to work even with mono files.
Post by Josh Parmenter
soundPlayer = Synth.new(\simpleReader);
starts the note immediately, and if there is no buffer loaded and sent
into the Synth, it will finish (since you use doneAction: 2). Try playing
but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer =
Synth.new(\simpleReader, [\bufnun, buf1]);
},{"Choose a sound first !".postln;
}
);
});
I understand the problem. Thank you for the solution but I still cannot hear
any sound with the modified program however.

(
var but1;
var but2;
var soundChosen;
var buf1;
var soundPlayer;

//Buffer creation to store a sound
buf1 = Buffer.new(s);

//sound playback synthDef
SynthDef(\simpleReader, {| out = 0, bufnum = 0 |
Out.ar(out, Pan2.ar(PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum),
doneAction:2), 0.0, 1.0));
}).send(s);

//draw main window
w = Window.new("Sound playback");
w.bounds = Rect(50, 300, 200, 200);
w.front;

// remembers if a sound has been chosen
soundChosen = 0;
//button to choose a sound
but1 = Button(w, Rect(40,20,120,30))
.states_([
["Choose a sound", Color.black, Color.red]
])
.action_({
CocoaDialog.getPaths({ arg paths;
paths.do({ arg p;
p.postln;
buf1.read(s, p);
soundChosen = 1;
})
},{
"No file chosen !".postln;
});
});

//button to create synth and hence play sound
but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer.postln;
soundPlayer = Synth.new(\simpleReader, [\bufnum, buf1]);
},{"Choose a sound first !".postln;
}
);
});

)

RB

-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6631127.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
amundsen
2011-07-28 21:03:59 UTC
Permalink
No idea anyone ?

-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6631347.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
James Harkins
2011-07-28 21:34:40 UTC
Permalink
At Thu, 28 Jul 2011 14:03:59 -0700 (PDT),
Post by amundsen
No idea anyone ?
There are two problems here. One is your mistake, the other isn't.

1- The 'read' method of Buffer incorrectly tries to send a Boolean object in the OSC message. All the other read-related methods call 'binaryValue' on the leaveOpen flag, except this one. I'll check in the fix soon.

2- You should be using allocRead instead of just read. Buffer.new only reserves a buffer number on the language side. It doesn't send any messages to the server to allocate memory for the buffer. Then, the 'read' method assumes that you've already allocated memory. As noted in Buffer help:

"Note that if the number of frames in the file is greater than the number of frames in the buffer, it will be truncated."

Before calling 'read', the number of frames allocated in the server for that buffer is 0. 'read' doesn't increase that number -- so after trying to read, the buffer still has zero frames.

I think it's better not to use Buffer.new -- instead:

Dialog.getPaths({ arg paths;
paths[0].postln;
buf1.free;
buf1 = Buffer.read(s, p);
soundChosen = 1;
});

hjh


--
James Harkins /// dewdrop world
jamshark70-***@public.gmane.org
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
James Harkins
2011-07-28 21:45:02 UTC
Permalink
At Thu, 28 Jul 2011 17:34:40 -0400,
Post by James Harkins
1- The 'read' method of Buffer incorrectly tries to send a Boolean object in the OSC message. All the other read-related methods call 'binaryValue' on the leaveOpen flag, except this one. I'll check in the fix soon.
Actually, no, I was wrong about that. 'read' gets the OSC message content from 'readMsg', which does call binaryValue correctly.

So the issue in your code was just the alloc thing.
hjh


--
James Harkins /// dewdrop world
jamshark70-***@public.gmane.org
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
amundsen
2011-07-28 22:58:09 UTC
Permalink
I have integrated your modification James but now I have this error message
when loading a sound:
/FAILURE /b_allocRead wrong argument type/

Below is the latest code.

RB

(
var but1;
var but2;
var soundChosen;
var buf1;
var soundPlayer;

//sound playback synthDef
SynthDef(\simpleReader, {| out = 0, bufnum = 0 |
Out.ar(out, Pan2.ar(PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum),
doneAction:2), 0.0, 1.0));
}).send(s);

//draw main window
w = Window.new("Sound playback");
w.bounds = Rect(50, 300, 200, 200);
w.front;

// remembers if a sound has been chosen
soundChosen = 0;
//button to choose a sound
but1 = Button(w, Rect(40,20,120,30))
.states_([
["Choose a sound", Color.black, Color.red]
])
.action_({
Dialog.getPaths({ arg paths;
        paths[0].postln;
        buf1.free;
        buf1 = Buffer.read(s, p);
        soundChosen = 1;
});
},{
"No file chosen !".postln;
});

//button to create synth and hence play sound
but2 = Button(w, Rect(40,80,120,30))
.states_([
["Play chosen sound", Color.black, Color.red]
])
.action_({
if (soundChosen == 1,
{
"Sound playback".postln;
"buf1 :".post;
buf1.postln;
soundPlayer.postln;
soundPlayer = Synth.new(\simpleReader, [\bufnum, buf1]);
},{"Choose a sound first !".postln;
}
);
});

)

-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6631657.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
James Harkins
2011-07-29 01:50:08 UTC
Permalink
At Thu, 28 Jul 2011 15:58:09 -0700 (PDT),
Post by amundsen
I have integrated your modification James but now I have this error message
/FAILURE /b_allocRead wrong argument type/
Well, I made a mistake. I left a 'p' in Buffer.read(s, p) where it should have been Buffer.read(s, paths[0]).

Anyway, the point was freeing the buffer and then 'read'ing a new Buffer object -- maybe next time, I should write pseudocode so that the ideas become more important than the letter-by-letter code.

hjh


--
James Harkins /// dewdrop world
jamshark70-***@public.gmane.org
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal." -- Whitman

blog: http://www.dewdrop-world.net/words
audio clips: http://www.dewdrop-world.net/audio
more audio: http://soundcloud.com/dewdrop_world/tracks

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
amundsen
2011-07-29 08:11:03 UTC
Permalink
Thanks for the correction James. Now everything's OK!

RB

-----
----------------------------------------------------------------------------
If it sounds good, it's probably good music.
If it sounds bad, whatever is behind - algorithms, recordings, microphones, software, computer, or even huge work - it's bad music.
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Basic-program-won-t-play-sound-loaded-in-buffer-tp6631010p6632706.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Loading...