How to change SampleRate

I find myself always googling this and it takes forever to find the answer. I don’t know how to change the sample rate of Supercollider.

The help file for ServerOptions clearly has:

.sampleRate

.samplerRate = value

The preferred sample rate. If non-nil the server app will attempt to set the sample rate of the hardware. The hardware has to support the sample rate that you choose.

Yet when I enter

ServerOptions.sampleRate

I get:

ERROR: Message 'sampleRate' not understood.

How do I do this? And how do I remember how to do this? It happens every few months and I go crazy trying to figure it out.

Thanks everyone,
Brian

1 Like

Hi Brian,
I’m not sure how I can help you to remember it, but I use
s.options.sampleRate = 48000 before boot

I think the error is because ServerOptions.sampleRate is calling a function on … nothing?
ServerOptions.new.sampleRate = 48000 would work (since it creates an object with .new), but doesn’t set the ServerOptions of the default server (can be done with s.options = ServerOptions.new.sampleRate…).
Anyway, I think someone on the forum can elaborate on this, but for now I hope my suggested line will do the job.

1 Like

ServerOptions.sampleRate returns an error and that’s normal.
When doing this, you are invoking a class method. And the ServerOptions class as no such class method. If you look carefully the documentation you’ll see that samplerate is an instance method.
So first, you’ve got to retrieve a ServerOptions instance.
If you want to change the current config you need to retrieve the current set of options with s.options.

So to set sample rate you should do:

s.options.sampleRate = 44100

And reboot the server
As per documentation of the Server class:

.options
.options = value
Get or set this Server’s ServerOptions object. Changes to options only take effect when the server is rebooted.

3 Likes

Hey there!

Still a bit confused, although I was able to use the code to achieve my desired result.

As a recap I wasn’t sure why

ServerOptions.sampleRate

wasn’t allowing me to change sample rate, but I instead needed

s.options.sampleRate

Okay, so I thought I had understood, however, very intuitively, when I went to change my in and output devices, I followed the same logic:

s.options.devices

Of course, now the situation is different and I don’t know why? I this time need:

ServerOptions.devices

So for changing sample rate

s.options.sampleRate //and not
 ServerOptions.sampleRate

but for in and output devices it’s the opposite,

ServerOptions.devices //and not 
s.options.devices?

Not quite.
s.options.device = "name" is how you set the device (also note “device”, and not “devices”).

ServerOptions.devices is a method to retrieve the list of devices available in your system.

ah ok! thanks!
It’s really hard for me to understand how all this works.
Trying my best :slight_smile:

Theres a distinction between a class “ServerOptions” and an instance “a ServerOptions”.

To change the options for the server stored in s you send messages to that Server’s Server options instance (s.options). It can be convenient to store the instance in another variable (o=s.options). Interpret o.dump to see all the options. Reboot the server after changing.

You can query the options of remote servers too, for example by sending messages to their ServerOptions instances.

ServerOptions.devices sends the message \devices to the class ServerOptions not any particular Server’s ServerOptions instance.

1 Like

note: being able to communicate with multiple servers from one sclang session is incredibly cool.