SuperCollider access sample rate in a synthdef - supercollider

how to find/get the samplerate number that SuperCollider is running into a patch as a variable?

Use the SampleRate.ir ugen, which always returns the current sample rate.
Note that using s.sampleRate is not the best answer - it gets you the sample rate at the time the synthdef is compiled, not the sample rate at the time the synth is running...

Related

How to prevent SD card from creating write delays during logging?

I've been working on an Arduino (ATMega328p) prototype that has to log data during certain events. An LSM6DS33 sensor is used to generate 6 values (2 bytes each) at a sample rate of 104 Hz. This data needs to be logged for a period of 500-20000ms.
In my code, I generate an interrupt every 1/104 sec using Timer1. When this interrupt occurs, data is read from the sensor, calibrated and then written to an SD card. Normally, this is not an issue. Reading the data from the sensor takes ~3350us, calibrating ~5us and writing ~550us. This means a total cycle takes ~4000us, whereas 9615us is available.
In order to save power, I wish to lower the voltage to 3.3V. According to the atmel datasheet, this also means that the clock frequency should be lowered to 8MHz. Assuming everything will go twice as slow, a measurement cycle would still be possible because ~8000us < 9615us.
After some testing (still 5V#16MHz), however, it occured to me that every now and then, a write cycle would take ~1880us instead of ~550us. I am using the library SdFat to write and test SD cards (RawWrite example). The following results came in when I tested the card:
Start raw write of 100000 KB
Target rate: 100 KB/sec
Target time: 100 seconds
Min block write time: 1244 micros
Max block write time: 12324 micros
Avg block write time: 1247 micros
As seen, the average time to write is fairly consistent, but sometimes a peak duration of 10x average occurs! According to the writer of the library, this is because the SD card needs some erase cycles in between x amount of write cycles. This causes a write delay (src:post#18&#22). This delay, however, pushes the time required for a cycle out of the available 9615us bracket, because the total measure cycle would be 10672us.
The data I am trying to write, is first put into a string using sprintf:
char buf[20] = "";
sprintf(buf,"%li\t%li\t%li\t%li\t%li\t%li",rawData[0],rawData[1],rawData[2],rawData[3],rawData[4],rawData[5]);
myLog.println(buf);
This writes the data to a txt file. But at my speed rate, only 21*104=2184 B/s would suffice. Lowering the speed of the RawWrite example to 6 KB/s, causes the SD card to write without getting an extended write delay. Yet my code still has them, even though less data is written.
My question is: how do I prevent this delay from occurring (if possible)? And if not possible, how can I work around it? It would help if I understood why exactly the delay occurs, because the interval is not always the same (every 10-15 writes).
Some additional info:
The sketch currently uses 69% of RAM (2kB) with variables. Creating two 512 byte buffers - like suggested in the same forum - is not possible for me.
Initially, I used two strings. Merging them into one, didn't affect the write speed with any significance.
I don't know how to work around the delay, but I experience a more stable and faster writing time, if I wrote to a binary file instead of a ".csv" or .txt" file.
The following link provide a fine script to write data as a binary struct to the SD card. (There are some small typo in his example, it is easily fixed)
https://hackingmajenkoblog.wordpress.com/2016/03/25/fast-efficient-data-storage-on-an-arduino/
This will not help you with the time variation, but it might minimize the writing time, and thus negleting the time issue.

Golang - What is the meaning of the seconds in CPU profiling graph?

For example, the data in the figure runtime.scanobject:
13.42s
runtime.scanobject 9.69s(4.51%) of 18.30s(8.52%).
5.33s
what is the meaning of the seconds and percent?
Thanks.
When CPU profiling is enabled, the Go program stops about 100 times per second and records a sample consisting of the program counters on the currently executing goroutine's stack.
That time and percentange is in reference to the sample.
Here is a nice reference for you to read more about it: https://blog.golang.org/profiling-go-programs

Time delay in simulink

I am working on my graduation project. It is a digital protection relay which trips if the measured value exceeds a specific value. It must trip after a time delay. We use texas instrument kit and simulink to build the program.
My problem is how to make a time delay so that i can delay the trip signal with predetermined time. The attached image shows aport of the program
thanks.
You can implement that by creating a counter (integrator). For example the counter increments (counter_value +=.001) by one each millisecond. Your trip delay is 1.54 s then you compare (>=) the value of the counter to your trip delay.
The counter is activated and reset by the boolean input signal that you want to delay.
I dont have Simulink installed. Therefore i cant give you a picture, and i think pseudocode would not help much either.

How to calculate the throughput in the "throughput" example of INET?

I am considering the idea of using Inet/omnet++ to evaluate a routing algorithm we are working on. Since I am using the tool for the first time, I was executing some examples and reading the source code.
Then I found an example, which is shipped with inet, /inet/examples/wireless/throughput.
The problem is that I don't get the same values.
In the README file one can read:
"Throughput is measured by the "sink" submodule of the AP. It is recorded
into the output scalar file, but can also be inspected during runtime.
The Excel sheet includes throughput measured by the simulation, and compares
it to the theoretical maximum which is roughly 5.12 Mbps (at 11 Mbps bitrate
and 1000-byte packets). The theoretical value and the simulation output
are very close, the difference being less than 1 kbps."
The same value is presented in Timing.xls
However, I obtain a different value when I execute the simulation: 846266 bit/sec
Do I need to perform some additional calculation to obtain the final value of throughput?
Is that a bug?
Is the value no longer valid due to some modification in INET?
The default value of bitrate for throughput example is 1 Mbps. So the value you obtained is correct.
To change the bitrate edit this line in omnetpp.ini in throughput directory:
**.wlan*.bitrate = 1Mbps

Bitrate Calculation

(Excuse for My english it's freak i´m from LA)
I'm trying to finish a trascoding process in VB6.0 , i'm working with ffmpeg , its a very good transcoder , to finish the project i want a progress bar for the trascoding process but it's so very hard , first i need to understand , how a program can calculate the time remaining to the process if i have the inputs
Average Bitrate
Frame rate
Start file Size.
I'm trying with : File size (KB) / Average Bitrate Kb/s.
In theory this must to work , but the calculated time it`s very small than the real time processed. Somebody have any idea about this , what is the formula (snipped) to calculate the time remaining in a trascoding process. in this wonderfull web i find many answer to mys projects..
The bitrate won't help you in calculating progress.
If you have the file length in seconds, and the frame rate, and ffmpeg outputs what frame its processing right now, you can calculate the approximate time.
The general solution for "time remaining," given:
A number total_units that represents the size, number of units, etc. to be processed
A number units_processed that represents how many M's have been processed so far
A number start_seconds that gives the time, in seconds since the operation started
is:
seconds_elapsed = current time - start time
seconds_per_unit = seconds_elapsed / units_processed
units_left = total_units - units_processed
seconds_remaining = unit_left / seconds_per_unit
This algorithm does best when the times to process each unit are nearly the same, or at least when the time/unit has little correlation with elapsed time. It stinks on ice if time/unit varies with elapsed time.

Resources