sample playback

11 views
Skip to first unread message

Curtis Ullerich

unread,
Aug 21, 2022, 11:55:21 PM8/21/22
to js...@googlegroups.com
I have some code that loops a sample. I'm hearing some clicks and stutters that I don't expect. I can hear a little something at the loop point, but I hear significant clicks that are not near the loop point either. This is when my computer is otherwise idle.

Here is some sample code that exhibits the problem (wav file here). I used PlaySampleCrossfade.java as my template for queueing the loop. Maybe I'm doing something wrong? Maybe it's my system? Thanks for any advice.
import com.jsyn.JSyn
import com.jsyn.data.SequentialData
import com.jsyn.ports.UnitDataQueuePort
import com.jsyn.ports.UnitOutputPort
import com.jsyn.unitgen.*
import com.jsyn.util.SampleLoader
import kotlin.io.path.Path

private fun main() {
val synth = JSyn.createSynthesizer()
val lineout = LineOut()
val hum = SampleLooper("/tmp/hum.wav")
synth.add(hum)
synth.add(lineout)
hum.output.connect(lineout.input)
lineout.start()
synth.start()
}

class SampleLooper(filename: String) : Circuit() {
private val reader: VariableRateDataReader
private val mixer: MixerMonoRamped
val output: UnitOutputPort

init {
val sample = SampleLoader.loadFloatSample(Path(filename).toUri().toURL())
when (sample.channelsPerFrame) {
1 -> {
mixer = MixerMonoRamped(1)
reader = VariableRateMonoReader().apply { output.connect(0, mixer.input, 0) }
}

2 -> {
mixer = MixerMonoRamped(2)
reader = VariableRateStereoReader().apply {
output.connect(0, mixer.input, 0)
output.connect(1, mixer.input, 1)
}
}

else -> error("Can only play mono or stereo samples.")
}
reader.rate.set(sample.frameRate)
queueLoop(reader.dataQueue, sample)
add(reader)
add(mixer)
output = mixer.output
addPort(output)
}

private fun queueLoop(dataQueue: UnitDataQueuePort, queueableData: SequentialData) {
val loopCommand = dataQueue.createQueueDataCommand(queueableData, 3000, queueableData.numFrames - 6000).apply {
numLoops = -1
crossFadeIn = 3000 // arbitrary
}
dataQueue.queueCommand(loopCommand)
}
}

Phil Burk

unread,
Sep 18, 2022, 2:56:37 PM9/18/22
to jsyn
Hello Curtis,

Sorry for the slow response.
Thanks for providing the source. I installed IntelliJ IDEA CE so I could run Kotlin.
I changed the file path and the code ran. I did not hear any glitches or crackling.

On Sunday, August 21, 2022 at 8:55:21 PM UTC-7 curtisu...@gmail.com wrote:
 I hear significant clicks that are not near the loop point either.

If you are getting random crackling then I suspect it may be related to an old bug in JavaSound on Mac.
What version of JDK are you using. I am using JDK 14.
If it is a JavaSound issue then JPortAudio might fix it.

> I can hear a little something at the loop point, but

That sounds like a possible JSyn issue. I am not hearing it but I will listen to it again on louder speakers.

Phil Burk


Curtis Ullerich

unread,
Sep 19, 2022, 12:05:41 PM9/19/22
to Phil Burk, jsyn
Hi Phil,

Thanks for trying the example. I'm using JDK 16 and observing this behavior on both Fedora 36 and OS X 10.12.6 (all our macbooks are running old versions of OS X, with JDK 16 which is the most recent version that will work on all of them).

Curtis

--
You received this message because you are subscribed to the Google Groups "jsyn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsyn+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsyn/405c4c7b-e94f-4877-ae6c-3fb8b80edab7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages